Skip to content

Commit 7e0cf7e

Browse files
bbrezillonrobherring
authored andcommitted
drm/panfrost: Make sure the shrinker does not reclaim referenced BOs
Userspace might tag a BO purgeable while it's still referenced by GPU jobs. We need to make sure the shrinker does not purge such BOs until all jobs referencing it are finished. Fixes: 013b651 ("drm/panfrost: Add madvise and shrinker support") Cc: <[email protected]> Signed-off-by: Boris Brezillon <[email protected]> Reviewed-by: Steven Price <[email protected]> Signed-off-by: Rob Herring <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 8ccb5bf commit 7e0cf7e

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

drivers/gpu/drm/panfrost/panfrost_drv.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ panfrost_lookup_bos(struct drm_device *dev,
166166
break;
167167
}
168168

169+
atomic_inc(&bo->gpu_usecount);
169170
job->mappings[i] = mapping;
170171
}
171172

drivers/gpu/drm/panfrost/panfrost_gem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ struct panfrost_gem_object {
3030
struct mutex lock;
3131
} mappings;
3232

33+
/*
34+
* Count the number of jobs referencing this BO so we don't let the
35+
* shrinker reclaim this object prematurely.
36+
*/
37+
atomic_t gpu_usecount;
38+
3339
bool noexec :1;
3440
bool is_heap :1;
3541
};

drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ static bool panfrost_gem_purge(struct drm_gem_object *obj)
4141
struct drm_gem_shmem_object *shmem = to_drm_gem_shmem_obj(obj);
4242
struct panfrost_gem_object *bo = to_panfrost_bo(obj);
4343

44+
if (atomic_read(&bo->gpu_usecount))
45+
return false;
46+
4447
if (!mutex_trylock(&shmem->pages_lock))
4548
return false;
4649

drivers/gpu/drm/panfrost/panfrost_job.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,13 @@ static void panfrost_job_cleanup(struct kref *ref)
269269
dma_fence_put(job->render_done_fence);
270270

271271
if (job->mappings) {
272-
for (i = 0; i < job->bo_count; i++)
272+
for (i = 0; i < job->bo_count; i++) {
273+
if (!job->mappings[i])
274+
break;
275+
276+
atomic_dec(&job->mappings[i]->obj->gpu_usecount);
273277
panfrost_gem_mapping_put(job->mappings[i]);
278+
}
274279
kvfree(job->mappings);
275280
}
276281

0 commit comments

Comments
 (0)