drm/amdgpu: Fix Illegal opcode in command stream Error
Subsystems (2)
PATCH v2 1/1 drm/amdgpu: Fix Illegal opcode in command stream Error
When applications closes, it triggers the drm_file_free function which subsequently releases all allocated buffer objects. Concurrently, the resume_worker thread will attempt to map the usermode queue. However, since the wptr buffer object has already been deallocated, this will result in an Illegal opcode error being raised in the command stream.
Now replacing drm_release() with a new function amdgpu_drm_release(). This function will set the flag to prevent the scheduling of any new queue resume/map, stop all queues and then call drm_release().
V2:
- Replace drm_release with amdgpu_drm_release(Christian).
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 16 +++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 ---- 2 files changed, 15 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +15 -1
@@ -2794,6 +2794,20 @@ static int amdgpu_pmops_runtime_idle(struct device *dev)return ret; } +static int amdgpu_drm_release (struct inode *inode,struct file *filp) +{ +struct drm_file *file_priv = filp->private_data; +struct amdgpu_fpriv *fpriv = file_priv->driver_priv; + +if (fpriv) { + fpriv->evf_mgr.fd_closing = true; +amdgpu_userq_mgr_fini (&fpriv->userq_mgr); +amdgpu_eviction_fence_destroy (&fpriv->evf_mgr); + } + +return drm_release (inode, filp); +} +long amdgpu_drm_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) {
@@ -2845,7 +2859,7 @@ static const struct file_operations amdgpu_driver_kms_fops = { .owner = THIS_MODULE, .open = drm_open, .flush = amdgpu_flush, - .release = drm_release, + .release = amdgpu_drm_release, .unlocked_ioctl = amdgpu_drm_ioctl, .mmap = drm_gem_mmap, .poll = drm_poll,
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -4
@@ -1478,10 +1478,6 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,amdgpu_bo_unreserve (pd); } - fpriv->evf_mgr.fd_closing = true; -amdgpu_userq_mgr_fini (&fpriv->userq_mgr); -amdgpu_eviction_fence_destroy (&fpriv->evf_mgr); -amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr);amdgpu_vm_fini (adev, &fpriv->vm);
Signature · 1 line
2.34.1
[AMD Official Use Only - AMD Internal Distribution Only]
Please feel free to use:
Regards
Shashank
________________________________
From: Yadav, Arvind <[email protected]>
Sent: Monday, December 23, 2024 4:34 PM
To: Koenig, Christian <[email protected]>; Sharma, Shashank <[email protected]>; Deucher, Alexander <[email protected]>
Cc: [email protected] <[email protected]>; Yadav, Arvind <[email protected]>; Koenig, Christian <[email protected]>; Yadav, Arvind <[email protected]>
Subject: [PATCH v2] drm/amdgpu: Fix Illegal opcode in command stream Error
When applications closes, it triggers the drm_file_free function which subsequently releases all allocated buffer objects. Concurrently, the resume_worker thread will attempt to map the usermode queue. However, since the wptr buffer object has already been deallocated, this will result in an Illegal opcode error being raised in the command stream.
Now replacing drm_release() with a new function amdgpu_drm_release(). This function will set the flag to prevent the scheduling of any new queue resume/map, stop all queues and then call drm_release().
V2:
- Replace drm_release with amdgpu_drm_release(Christian).
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 16 +++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 ---- 2 files changed, 15 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +15 -1
@@ -2794,6 +2794,20 @@ static int amdgpu_pmops_runtime_idle(struct device *dev)return ret; } +static int amdgpu_drm_release (struct inode *inode,struct file *filp) +{ +struct drm_file *file_priv = filp->private_data; +struct amdgpu_fpriv *fpriv = file_priv->driver_priv; + +if (fpriv) { + fpriv->evf_mgr.fd_closing = true; +amdgpu_userq_mgr_fini (&fpriv->userq_mgr); +amdgpu_eviction_fence_destroy (&fpriv->evf_mgr); + } + +return drm_release (inode, filp); +} +long amdgpu_drm_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) {
@@ -2845,7 +2859,7 @@ static const struct file_operations amdgpu_driver_kms_fops = { .owner = THIS_MODULE, .open = drm_open, .flush = amdgpu_flush, - .release = drm_release, + .release = amdgpu_drm_release, .unlocked_ioctl = amdgpu_drm_ioctl, .mmap = drm_gem_mmap, .poll = drm_poll,
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0 -4
@@ -1478,10 +1478,6 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,amdgpu_bo_unreserve (pd); } - fpriv->evf_mgr.fd_closing = true; -amdgpu_userq_mgr_fini (&fpriv->userq_mgr); -amdgpu_eviction_fence_destroy (&fpriv->evf_mgr); -amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr);amdgpu_vm_fini (adev, &fpriv->vm);
--
2.34.1
Christian König
maintainerAm 23.12.24 um 16:34 schrieb Arvind Yadav:
Quoted 36 lines
When applications closes, it triggers the
drm_file_freefunction which subsequently releases all allocated buffer objects. Concurrently, theresume_workerthread will attempt to map the usermode queue. However, since the wptr buffer object has already been deallocated, this will result in an Illegal opcode error being raised in the command stream.Now replacing
drm_release()with a new functionamdgpu_drm_release(). This function will set the flag to prevent the scheduling of any new queue resume/map, stop all queues and then calldrm_release().V2:
- Replacedrm_releasewithamdgpu_drm_release(Christian).Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Cc Shashank Sharma <[email protected]>Signed-off-by Arvind Yadav <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 16 +++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 4 ---- 2 files changed, 15 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +4
-0@@ -2794,6 +2794,20 @@ static int amdgpu_pmops_runtime_idle(struct device *dev)return ret; } +static int amdgpu_drm_release (struct inode *inode,struct file *filp) +{ +struct drm_file *file_priv = filp->private_data; +struct amdgpu_fpriv *fpriv = file_priv->driver_priv;
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c static int amdgpu_pmops_runtime_idle(struct device *dev) · line 2810
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +10
-0+ +if (fpriv) { + fpriv->evf_mgr.fd_closing = true; +amdgpu_userq_mgr_fini (&fpriv->userq_mgr); +amdgpu_eviction_fence_destroy (&fpriv->evf_mgr); + } + +return drm_release (inode, filp); +} +
For now the patch is Reviewed-by: Christian König <[email protected]>.
But unrelated to this patch we should probably clean up all the DRM callback functions and move them into a separate file.
Somebody should probably setup a confluence page for small cleanup ideas.
Regards,
Christian.
Quoted 27 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-1long amdgpu_drm_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) {@@ -2845,7 +2859,7 @@ static const struct file_operations amdgpu_driver_kms_fops = { .owner = THIS_MODULE, .open = drm_open, .flush = amdgpu_flush, - .release = drm_release, + .release = amdgpu_drm_release, .unlocked_ioctl = amdgpu_drm_ioctl, .mmap = drm_gem_mmap, .poll = drm_poll,drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +0
-4@@ -1478,10 +1478,6 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,amdgpu_bo_unreserve (pd); } - fpriv->evf_mgr.fd_closing = true; -amdgpu_userq_mgr_fini (&fpriv->userq_mgr); -amdgpu_eviction_fence_destroy (&fpriv->evf_mgr); -amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr);amdgpu_vm_fini (adev, &fpriv->vm);