Skip to content

Commit

Permalink
drm/panfrost: Make sure a BO is only unmapped when appropriate
Browse files Browse the repository at this point in the history
mmu_ops->unmap() will fail when called on a BO that has not been
previously mapped, and the error path in panfrost_ioctl_create_bo()
can call drm_gem_object_put_unlocked() (which in turn calls
panfrost_mmu_unmap()) on a BO that has not been mapped yet.

Keep track of the mapped/unmapped state to avoid such issues.

Fixes: f3ba912 ("drm/panfrost: Add initial panfrost driver")
Cc: <stable@vger.kernel.org>
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Rob Herring <robh@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190618081343.16927-1-boris.brezillon@collabora.com
  • Loading branch information
Boris Brezillon authored and Rob Herring committed Jun 18, 2019
1 parent 48eaeb7 commit 9870dc3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion drivers/gpu/drm/panfrost/panfrost_gem.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ static void panfrost_gem_free_object(struct drm_gem_object *obj)
struct panfrost_gem_object *bo = to_panfrost_bo(obj);
struct panfrost_device *pfdev = obj->dev->dev_private;

panfrost_mmu_unmap(bo);
if (bo->is_mapped)
panfrost_mmu_unmap(bo);

spin_lock(&pfdev->mm_lock);
drm_mm_remove_node(&bo->node);
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/panfrost/panfrost_gem.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct panfrost_gem_object {
struct drm_gem_shmem_object base;

struct drm_mm_node node;
bool is_mapped;
};

static inline
Expand Down
8 changes: 8 additions & 0 deletions drivers/gpu/drm/panfrost/panfrost_mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ int panfrost_mmu_map(struct panfrost_gem_object *bo)
struct sg_table *sgt;
int ret;

if (WARN_ON(bo->is_mapped))
return 0;

sgt = drm_gem_shmem_get_pages_sgt(obj);
if (WARN_ON(IS_ERR(sgt)))
return PTR_ERR(sgt);
Expand Down Expand Up @@ -189,6 +192,7 @@ int panfrost_mmu_map(struct panfrost_gem_object *bo)

pm_runtime_mark_last_busy(pfdev->dev);
pm_runtime_put_autosuspend(pfdev->dev);
bo->is_mapped = true;

return 0;
}
Expand All @@ -203,6 +207,9 @@ void panfrost_mmu_unmap(struct panfrost_gem_object *bo)
size_t unmapped_len = 0;
int ret;

if (WARN_ON(!bo->is_mapped))
return;

dev_dbg(pfdev->dev, "unmap: iova=%llx, len=%zx", iova, len);

ret = pm_runtime_get_sync(pfdev->dev);
Expand Down Expand Up @@ -230,6 +237,7 @@ void panfrost_mmu_unmap(struct panfrost_gem_object *bo)

pm_runtime_mark_last_busy(pfdev->dev);
pm_runtime_put_autosuspend(pfdev->dev);
bo->is_mapped = false;
}

static void mmu_tlb_inv_context_s1(void *cookie)
Expand Down

0 comments on commit 9870dc3

Please sign in to comment.