diff mbox series

drm/omap: fix dma_addr refcounting

Message ID 20191114080343.30704-1-tomi.valkeinen@ti.com
State Accepted
Commit d9c148cfaf0a99296ad7c92fb8b65952196053ec
Headers show
Series drm/omap: fix dma_addr refcounting | expand

Commit Message

Tomi Valkeinen Nov. 14, 2019, 8:03 a.m. UTC
cec4fa7511ef7a73eb635834e9d85b25a5b47a98 ("drm/omap: use refcount API to
track the number of users of dma_addr") changed omap_gem.c to use
refcounting API to track dma_addr uses.  However, the driver only tracks
the refcounts for non-contiguous buffers, and the patch didn't fully
take this in account.

After the patch, the driver always decreased refcount in omap_gem_unpin,
instead of decreasing the refcount only for non-contiguous buffers. This
leads to refcounting mismatch.

As for the contiguous cases the refcount is never increased, fix this
issue by returning from omap_gem_unpin if the buffer being unpinned is
contiguous.

Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
---
 drivers/gpu/drm/omapdrm/omap_gem.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Laurent Pinchart Dec. 2, 2019, 12:36 p.m. UTC | #1
Hi Tomi,

Thank you for the patch.

On Thu, Nov 14, 2019 at 10:03:43AM +0200, Tomi Valkeinen wrote:
> cec4fa7511ef7a73eb635834e9d85b25a5b47a98 ("drm/omap: use refcount API to
> track the number of users of dma_addr") changed omap_gem.c to use
> refcounting API to track dma_addr uses.  However, the driver only tracks
> the refcounts for non-contiguous buffers, and the patch didn't fully
> take this in account.
> 
> After the patch, the driver always decreased refcount in omap_gem_unpin,
> instead of decreasing the refcount only for non-contiguous buffers. This
> leads to refcounting mismatch.
> 
> As for the contiguous cases the refcount is never increased, fix this
> issue by returning from omap_gem_unpin if the buffer being unpinned is
> contiguous.

How about adding a Fixes line ?

Fixes: cec4fa7511ef ("drm/omap: use refcount API to track the number of users of dma_addr")

> Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  drivers/gpu/drm/omapdrm/omap_gem.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c b/drivers/gpu/drm/omapdrm/omap_gem.c
> index e518d93ca6df..d08ae95ecc0a 100644
> --- a/drivers/gpu/drm/omapdrm/omap_gem.c
> +++ b/drivers/gpu/drm/omapdrm/omap_gem.c
> @@ -843,9 +843,13 @@ int omap_gem_pin(struct drm_gem_object *obj, dma_addr_t *dma_addr)
>   */
>  static void omap_gem_unpin_locked(struct drm_gem_object *obj)
>  {
> +	struct omap_drm_private *priv = obj->dev->dev_private;
>  	struct omap_gem_object *omap_obj = to_omap_bo(obj);
>  	int ret;
>  
> +	if (omap_gem_is_contiguous(omap_obj) || !priv->has_dmm)
> +		return;
> +
>  	if (refcount_dec_and_test(&omap_obj->dma_addr_cnt)) {
>  		ret = tiler_unpin(omap_obj->block);
>  		if (ret) {
Tomi Valkeinen Dec. 4, 2019, 5:13 p.m. UTC | #2
On 02/12/2019 14:36, Laurent Pinchart wrote:
> Hi Tomi,
> 
> Thank you for the patch.
> 
> On Thu, Nov 14, 2019 at 10:03:43AM +0200, Tomi Valkeinen wrote:
>> cec4fa7511ef7a73eb635834e9d85b25a5b47a98 ("drm/omap: use refcount API to
>> track the number of users of dma_addr") changed omap_gem.c to use
>> refcounting API to track dma_addr uses.  However, the driver only tracks
>> the refcounts for non-contiguous buffers, and the patch didn't fully
>> take this in account.
>>
>> After the patch, the driver always decreased refcount in omap_gem_unpin,
>> instead of decreasing the refcount only for non-contiguous buffers. This
>> leads to refcounting mismatch.
>>
>> As for the contiguous cases the refcount is never increased, fix this
>> issue by returning from omap_gem_unpin if the buffer being unpinned is
>> contiguous.
> 
> How about adding a Fixes line ?
> 
> Fixes: cec4fa7511ef ("drm/omap: use refcount API to track the number of users of dma_addr")

Thanks! I'll add the fixes line.

  Tomi
diff mbox series

Patch

diff --git a/drivers/gpu/drm/omapdrm/omap_gem.c b/drivers/gpu/drm/omapdrm/omap_gem.c
index e518d93ca6df..d08ae95ecc0a 100644
--- a/drivers/gpu/drm/omapdrm/omap_gem.c
+++ b/drivers/gpu/drm/omapdrm/omap_gem.c
@@ -843,9 +843,13 @@  int omap_gem_pin(struct drm_gem_object *obj, dma_addr_t *dma_addr)
  */
 static void omap_gem_unpin_locked(struct drm_gem_object *obj)
 {
+	struct omap_drm_private *priv = obj->dev->dev_private;
 	struct omap_gem_object *omap_obj = to_omap_bo(obj);
 	int ret;
 
+	if (omap_gem_is_contiguous(omap_obj) || !priv->has_dmm)
+		return;
+
 	if (refcount_dec_and_test(&omap_obj->dma_addr_cnt)) {
 		ret = tiler_unpin(omap_obj->block);
 		if (ret) {