Skip to content

Commit cac0757

Browse files
drm/panthor: Fix race when converting group handle to group object
XArray provides it's own internal lock which protects the internal array when entries are being simultaneously added and removed. However there is still a race between retrieving the pointer from the XArray and incrementing the reference count. To avoid this race simply hold the internal XArray lock when incrementing the reference count, this ensures there cannot be a racing call to xa_erase(). Fixes: de85488 ("drm/panthor: Add the scheduler logical block") Signed-off-by: Steven Price <steven.price@arm.com> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com> Reviewed-by: Liviu Dudau <liviu.dudau@arm.com> Link: https://patchwork.freedesktop.org/patch/msgid/20240923103406.2509906-1-steven.price@arm.com
1 parent d92b90f commit cac0757

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

drivers/gpu/drm/panthor/panthor_sched.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,6 +3242,18 @@ int panthor_group_destroy(struct panthor_file *pfile, u32 group_handle)
32423242
return 0;
32433243
}
32443244

3245+
static struct panthor_group *group_from_handle(struct panthor_group_pool *pool,
3246+
u32 group_handle)
3247+
{
3248+
struct panthor_group *group;
3249+
3250+
xa_lock(&pool->xa);
3251+
group = group_get(xa_load(&pool->xa, group_handle));
3252+
xa_unlock(&pool->xa);
3253+
3254+
return group;
3255+
}
3256+
32453257
int panthor_group_get_state(struct panthor_file *pfile,
32463258
struct drm_panthor_group_get_state *get_state)
32473259
{
@@ -3253,7 +3265,7 @@ int panthor_group_get_state(struct panthor_file *pfile,
32533265
if (get_state->pad)
32543266
return -EINVAL;
32553267

3256-
group = group_get(xa_load(&gpool->xa, get_state->group_handle));
3268+
group = group_from_handle(gpool, get_state->group_handle);
32573269
if (!group)
32583270
return -EINVAL;
32593271

@@ -3384,7 +3396,7 @@ panthor_job_create(struct panthor_file *pfile,
33843396
job->call_info.latest_flush = qsubmit->latest_flush;
33853397
INIT_LIST_HEAD(&job->node);
33863398

3387-
job->group = group_get(xa_load(&gpool->xa, group_handle));
3399+
job->group = group_from_handle(gpool, group_handle);
33883400
if (!job->group) {
33893401
ret = -EINVAL;
33903402
goto err_put_job;

0 commit comments

Comments
 (0)