* [PATCH] drm/amdgpu: Fix eviction fence worker race during fd close @ 2025-05-15 7:06 Jesse.Zhang 2025-05-15 8:58 ` Christian König 2025-05-15 13:19 ` Liang, Prike 0 siblings, 2 replies; 4+ messages in thread From: Jesse.Zhang @ 2025-05-15 7:06 UTC (permalink / raw) To: amd-gfx; +Cc: Alexander.Deucher, Christian Koenig, Jesse.Zhang The current cleanup order during file descriptor close can lead to a race condition where the eviction fence worker attempts to access a destroyed mutex from the user queue manager: [ 517.294055] DEBUG_LOCKS_WARN_ON(lock->magic != lock) [ 517.294060] WARNING: CPU: 8 PID: 2030 at kernel/locking/mutex.c:564 [ 517.294094] Workqueue: events amdgpu_eviction_fence_suspend_worker [amdgpu] The issue occurs because: 1. We destroy the user queue manager (including its mutex) first 2. Then try to destroy eviction fences which may have pending work 3. The eviction fence worker may try to access the already-destroyed mutex Fix this by reordering the cleanup to: 1. First mark the fd as closing and destroy eviction fences, which flushes any pending work 2. Then safely destroy the user queue manager after we're certain no more fence work will be executed Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com> --- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c index 4ddd08ce8885..4db92e0a60da 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c @@ -2913,8 +2913,8 @@ static int amdgpu_drm_release(struct inode *inode, struct file *filp) if (fpriv) { fpriv->evf_mgr.fd_closing = true; - amdgpu_userq_mgr_fini(&fpriv->userq_mgr); amdgpu_eviction_fence_destroy(&fpriv->evf_mgr); + amdgpu_userq_mgr_fini(&fpriv->userq_mgr); } return drm_release(inode, filp); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c index 9fbb04aee97b..1fec3713fbf2 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c @@ -1504,8 +1504,8 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev, if (!fpriv->evf_mgr.fd_closing) { fpriv->evf_mgr.fd_closing = true; - amdgpu_userq_mgr_fini(&fpriv->userq_mgr); amdgpu_eviction_fence_destroy(&fpriv->evf_mgr); + amdgpu_userq_mgr_fini(&fpriv->userq_mgr); } amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr); amdgpu_vm_fini(adev, &fpriv->vm); -- 2.49.0 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/amdgpu: Fix eviction fence worker race during fd close 2025-05-15 7:06 [PATCH] drm/amdgpu: Fix eviction fence worker race during fd close Jesse.Zhang @ 2025-05-15 8:58 ` Christian König 2025-05-15 13:19 ` Liang, Prike 1 sibling, 0 replies; 4+ messages in thread From: Christian König @ 2025-05-15 8:58 UTC (permalink / raw) To: Jesse.Zhang, amd-gfx; +Cc: Alexander.Deucher On 5/15/25 09:06, Jesse.Zhang wrote: > The current cleanup order during file descriptor close can lead to > a race condition where the eviction fence worker attempts to access > a destroyed mutex from the user queue manager: > > [ 517.294055] DEBUG_LOCKS_WARN_ON(lock->magic != lock) > [ 517.294060] WARNING: CPU: 8 PID: 2030 at kernel/locking/mutex.c:564 > [ 517.294094] Workqueue: events amdgpu_eviction_fence_suspend_worker [amdgpu] > > The issue occurs because: > 1. We destroy the user queue manager (including its mutex) first > 2. Then try to destroy eviction fences which may have pending work > 3. The eviction fence worker may try to access the already-destroyed mutex > > Fix this by reordering the cleanup to: > 1. First mark the fd as closing and destroy eviction fences, > which flushes any pending work > 2. Then safely destroy the user queue manager after we're certain > no more fence work will be executed > > Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com> > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +- > drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c > index 4ddd08ce8885..4db92e0a60da 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c > @@ -2913,8 +2913,8 @@ static int amdgpu_drm_release(struct inode *inode, struct file *filp) > > if (fpriv) { > fpriv->evf_mgr.fd_closing = true; > - amdgpu_userq_mgr_fini(&fpriv->userq_mgr); > amdgpu_eviction_fence_destroy(&fpriv->evf_mgr); > + amdgpu_userq_mgr_fini(&fpriv->userq_mgr); > } > > return drm_release(inode, filp); > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c > index 9fbb04aee97b..1fec3713fbf2 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c > @@ -1504,8 +1504,8 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev, > > if (!fpriv->evf_mgr.fd_closing) { > fpriv->evf_mgr.fd_closing = true; > - amdgpu_userq_mgr_fini(&fpriv->userq_mgr); > amdgpu_eviction_fence_destroy(&fpriv->evf_mgr); > + amdgpu_userq_mgr_fini(&fpriv->userq_mgr); > } That we have duplicated the code in both amdgpu_drm_release() and amdgpu_driver_postclose_kms() is a bug. The copy in amdgpu_driver_postclose_kms() needs to be removed. Apart from that looks good to me, Christian. > amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr); > amdgpu_vm_fini(adev, &fpriv->vm); ^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH] drm/amdgpu: Fix eviction fence worker race during fd close 2025-05-15 7:06 [PATCH] drm/amdgpu: Fix eviction fence worker race during fd close Jesse.Zhang 2025-05-15 8:58 ` Christian König @ 2025-05-15 13:19 ` Liang, Prike 2025-05-15 14:08 ` Yadav, Arvind 1 sibling, 1 reply; 4+ messages in thread From: Liang, Prike @ 2025-05-15 13:19 UTC (permalink / raw) To: Zhang, Jesse(Jie), amd-gfx@lists.freedesktop.org Cc: Deucher, Alexander, Koenig, Christian, Zhang, Jesse(Jie) [Public] I haven't cleaned up the userq resource destroy at postclose callback in my last patch, so here please remove the duplicated useq destroy. With that, the change in the patch is Reviewed-by: Prike Liang <Prike.Liang@amd.com> Regards, Prike > -----Original Message----- > From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of > Jesse.Zhang > Sent: Thursday, May 15, 2025 3:07 PM > To: amd-gfx@lists.freedesktop.org > Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian > <Christian.Koenig@amd.com>; Zhang, Jesse(Jie) <Jesse.Zhang@amd.com> > Subject: [PATCH] drm/amdgpu: Fix eviction fence worker race during fd close > > The current cleanup order during file descriptor close can lead to a race condition > where the eviction fence worker attempts to access a destroyed mutex from the > user queue manager: > > [ 517.294055] DEBUG_LOCKS_WARN_ON(lock->magic != lock) [ 517.294060] > WARNING: CPU: 8 PID: 2030 at kernel/locking/mutex.c:564 [ 517.294094] > Workqueue: events amdgpu_eviction_fence_suspend_worker [amdgpu] > > The issue occurs because: > 1. We destroy the user queue manager (including its mutex) first 2. Then try to > destroy eviction fences which may have pending work 3. The eviction fence worker > may try to access the already-destroyed mutex > > Fix this by reordering the cleanup to: > 1. First mark the fd as closing and destroy eviction fences, > which flushes any pending work > 2. Then safely destroy the user queue manager after we're certain > no more fence work will be executed > > Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com> > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +- > drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c > index 4ddd08ce8885..4db92e0a60da 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c > @@ -2913,8 +2913,8 @@ static int amdgpu_drm_release(struct inode *inode, > struct file *filp) > > if (fpriv) { > fpriv->evf_mgr.fd_closing = true; > - amdgpu_userq_mgr_fini(&fpriv->userq_mgr); > amdgpu_eviction_fence_destroy(&fpriv->evf_mgr); > + amdgpu_userq_mgr_fini(&fpriv->userq_mgr); > } > > return drm_release(inode, filp); > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c > index 9fbb04aee97b..1fec3713fbf2 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c > @@ -1504,8 +1504,8 @@ void amdgpu_driver_postclose_kms(struct drm_device > *dev, > > if (!fpriv->evf_mgr.fd_closing) { > fpriv->evf_mgr.fd_closing = true; > - amdgpu_userq_mgr_fini(&fpriv->userq_mgr); > amdgpu_eviction_fence_destroy(&fpriv->evf_mgr); > + amdgpu_userq_mgr_fini(&fpriv->userq_mgr); > } > amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr); > amdgpu_vm_fini(adev, &fpriv->vm); > -- > 2.49.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/amdgpu: Fix eviction fence worker race during fd close 2025-05-15 13:19 ` Liang, Prike @ 2025-05-15 14:08 ` Yadav, Arvind 0 siblings, 0 replies; 4+ messages in thread From: Yadav, Arvind @ 2025-05-15 14:08 UTC (permalink / raw) To: Liang, Prike, Zhang, Jesse(Jie), amd-gfx@lists.freedesktop.org Cc: Deucher, Alexander, Koenig, Christian Reviewed-by: Arvind Yadav <Arvind.Yadav@amd.com> On 5/15/2025 6:49 PM, Liang, Prike wrote: > [Public] > > [Public] > > I haven't cleaned up the userq resource destroy at postclose callback in my last patch, so here please remove the duplicated useq destroy. With that, the change in the patch is > Reviewed-by: Prike Liang <Prike.Liang@amd.com> > > Regards, > Prike > >> -----Original Message----- >> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of >> Jesse.Zhang >> Sent: Thursday, May 15, 2025 3:07 PM >> To: amd-gfx@lists.freedesktop.org >> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian >> <Christian.Koenig@amd.com>; Zhang, Jesse(Jie) <Jesse.Zhang@amd.com> >> Subject: [PATCH] drm/amdgpu: Fix eviction fence worker race during fd close >> >> The current cleanup order during file descriptor close can lead to a race condition >> where the eviction fence worker attempts to access a destroyed mutex from the >> user queue manager: >> >> [ 517.294055] DEBUG_LOCKS_WARN_ON(lock->magic != lock) [ 517.294060] >> WARNING: CPU: 8 PID: 2030 at kernel/locking/mutex.c:564 [ 517.294094] >> Workqueue: events amdgpu_eviction_fence_suspend_worker [amdgpu] >> >> The issue occurs because: >> 1. We destroy the user queue manager (including its mutex) first 2. Then try to >> destroy eviction fences which may have pending work 3. The eviction fence worker >> may try to access the already-destroyed mutex >> >> Fix this by reordering the cleanup to: >> 1. First mark the fd as closing and destroy eviction fences, >> which flushes any pending work >> 2. Then safely destroy the user queue manager after we're certain >> no more fence work will be executed >> >> Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com> >> --- >> drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +- >> drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 2 +- >> 2 files changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c >> b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c >> index 4ddd08ce8885..4db92e0a60da 100644 >> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c >> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c >> @@ -2913,8 +2913,8 @@ static int amdgpu_drm_release(struct inode *inode, >> struct file *filp) >> >> if (fpriv) { >> fpriv->evf_mgr.fd_closing = true; >> - amdgpu_userq_mgr_fini(&fpriv->userq_mgr); >> amdgpu_eviction_fence_destroy(&fpriv->evf_mgr); >> + amdgpu_userq_mgr_fini(&fpriv->userq_mgr); >> } >> >> return drm_release(inode, filp); >> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c >> b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c >> index 9fbb04aee97b..1fec3713fbf2 100644 >> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c >> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c >> @@ -1504,8 +1504,8 @@ void amdgpu_driver_postclose_kms(struct drm_device >> *dev, >> >> if (!fpriv->evf_mgr.fd_closing) { >> fpriv->evf_mgr.fd_closing = true; >> - amdgpu_userq_mgr_fini(&fpriv->userq_mgr); >> amdgpu_eviction_fence_destroy(&fpriv->evf_mgr); >> + amdgpu_userq_mgr_fini(&fpriv->userq_mgr); >> } >> amdgpu_ctx_mgr_fini(&fpriv->ctx_mgr); >> amdgpu_vm_fini(adev, &fpriv->vm); >> -- >> 2.49.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-05-15 14:08 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-05-15 7:06 [PATCH] drm/amdgpu: Fix eviction fence worker race during fd close Jesse.Zhang 2025-05-15 8:58 ` Christian König 2025-05-15 13:19 ` Liang, Prike 2025-05-15 14:08 ` Yadav, Arvind
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.