]> git.itanic.dy.fi Git - linux-stable/commitdiff
drm/amdgpu: add a missing lock for AMDGPU_SCHED
authorChia-I Wu <olvaffe@gmail.com>
Wed, 26 Apr 2023 22:54:55 +0000 (15:54 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 17 May 2023 09:50:19 +0000 (11:50 +0200)
[ Upstream commit 2397e3d8d2e120355201a8310b61929f5a8bd2c0 ]

mgr->ctx_handles should be protected by mgr->lock.

v2: improve commit message
v3: add a Fixes tag

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Fixes: 52c6a62c64fa ("drm/amdgpu: add interface for editing a foreign process's priority v3")
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/amd/amdgpu/amdgpu_sched.c

index b7d861ed528493d61e51507cf588095b176cc522..88f986a61c93a99fcac0944e53823e50c24420b1 100644 (file)
@@ -66,6 +66,7 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
 {
        struct fd f = fdget(fd);
        struct amdgpu_fpriv *fpriv;
+       struct amdgpu_ctx_mgr *mgr;
        struct amdgpu_ctx *ctx;
        uint32_t id;
        int r;
@@ -79,8 +80,11 @@ static int amdgpu_sched_process_priority_override(struct amdgpu_device *adev,
                return r;
        }
 
-       idr_for_each_entry(&fpriv->ctx_mgr.ctx_handles, ctx, id)
+       mgr = &fpriv->ctx_mgr;
+       mutex_lock(&mgr->lock);
+       idr_for_each_entry(&mgr->ctx_handles, ctx, id)
                amdgpu_ctx_priority_override(ctx, priority);
+       mutex_unlock(&mgr->lock);
 
        fdput(f);
        return 0;