FAILED: patch "[PATCH] drm/amdgpu: copy debugfs register data outside the GRBM/SRBM" failed to apply to 5.15-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 16c64495859f13f75602f439588883f2a4a4d6a6
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026101230-expedited-brewing-2f54@gregkh' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 16c64495859f13f75602f439588883f2a4a4d6a6 Mon Sep 17 00:00:00 2001
From: Mikhail Gavrilov <[email protected]>
Date: Thu, 1 Oct 2026 21:13:07 +0500
Subject: [PATCH] drm/amdgpu: copy debugfs register data outside the GRBM/SRBM
locks
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Reading or writing a register through the amdgpu_regs2 debugfs file with GRBM bank selection, which umr does for every banked access (a single "umr -b x x x -r <reg>" is enough, as is the wave dump with "-O halt_waves"), makes lockdep report a circular locking dependency, after which lockdep stays off until reboot:
WARNING: possible circular locking dependency detected
umr/63306 is trying to acquire lock:
ffff8882cf4b8350 (&mm->mmap_lock){++++}-{4:4}, at: __might_fault+0x9b/0x140
but task is already holding lock:
ffff8881aec010d0 (&amdgpu_grbm_lock_key){+.+.}-{4:4}, at: amdgpu_debugfs_regs2_op.isra.0+0x20d/0xd00 [amdgpu]
...
Chain exists of:
&mm->mmap_lock --> &amdgpu_srbm_lock_key --> &amdgpu_grbm_lock_key
...
__might_fault+0xc5/0x140
amdgpu_debugfs_regs2_op.isra.0+0x441/0xd00 [amdgpu]
full_proxy_write+0x10e/0x1d0
vfs_write+0x1d0/0xf50
ksys_write+0x116/0x250amdgpu_debugfs_regs2_op() and amdgpu_debugfs_process_reg_op() call get_user()/put_user() for every dword while holding grbm_idx_mutex or srbm_mutex, and pm.mutex if requested, so a fault there takes mmap_lock inside those locks. The lock hierarchy in amdgpu_lockdep.c puts srbm_mutex and grbm_idx_mutex below notifier_lock, which amdgpu_cs_submit() takes with the BO reservations held, and dma_resv_lockdep() orders the reservations inside mmap_lock. So mmap_lock is outside grbm_idx_mutex and srbm_mutex, and these two debugfs paths nest it the other way round. The copies under the locks are as old as the bank selection in both files; commit 1d0f5838b126 ("drm/amdgpu: Add lockdep annotations for lock ordering validation") only made them visible to lockdep.
Copy the user buffer in before any of the locks is taken and the result out after all of them are dropped, as amdgpu_debugfs_wave_read(), amdgpu_debugfs_gpr_read() and amdgpu_debugfs_gprwave_read() already do. The buffer is sized by the count passed to read() or write(), so an access larger than PAGE_SIZE is now rejected with -EINVAL; umr reads and writes one register at a time. A fault on the user buffer of a write now fails with -EFAULT before any register is written, instead of after a partial write.
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +46 -31
@@ -121,6 +121,20 @@ static int amdgpu_debugfs_process_reg_op(bool read, struct file *f, *pos &= (1UL <<22 ) -1 ; +if (size >PAGE_SIZE ) +return -EINVAL ; + +/* +* Access the user buffer only while none of the locks below are held: +* a fault takes mmap_lock, and grbm_idx_mutex and srbm_mutex nest +* inside it. +*/ + u32 *data __free(kfree) = kmalloc(size, GFP_KERNEL); +if (!data) +return -ENOMEM ; +if (!read &©_from_user (data, buf, size)) +return -EFAULT ; + r =pm_runtime_get_sync (adev_to_drm (adev)->dev);if (r <0 ) {pm_runtime_put_autosuspend (adev_to_drm (adev)->dev);
@@ -152,28 +166,16 @@ static int amdgpu_debugfs_process_reg_op(bool read, struct file *f,mutex_lock (&adev->pm.mutex);while (size) { -uint32_t value; - -if (read) { - value =RREG32 (*pos >>2 ); - r =put_user (value, (uint32_t *)buf); - }else { - r =get_user (value, (uint32_t *)buf); -if (!r) -amdgpu_mm_wreg_mmio_rlc (adev, *pos >>2 , value,0 ); - } -if (r) { - result = r; - goto end; - } +if (read) + data[result >>2 ] =RREG32 (*pos >>2 ); +else +amdgpu_mm_wreg_mmio_rlc (adev, *pos >>2 , data[result >>2 ],0 ); result +=4 ; - buf +=4 ; *pos +=4 ; size -=4 ; } -end:if (use_bank) {amdgpu_gfx_select_se_sh (adev,0xffffffff ,0xffffffff ,0xffffffff ,0 );mutex_unlock (&adev->grbm_idx_mutex);
@@ -188,6 +190,10 @@ static int amdgpu_debugfs_process_reg_op(bool read, struct file *f,pm_runtime_put_autosuspend (adev_to_drm (adev)->dev);amdgpu_virt_disable_access_debugfs (adev); + +if (read &©_to_user (buf, data, result)) +return -EFAULT ; +return result; }
@@ -238,11 +244,24 @@ static ssize_t amdgpu_debugfs_regs2_op(struct file *f, char __user *buf, u32 offstruct amdgpu_device *adev = rd->adev;ssize_t result =0 ;int r; -uint32_t value;if (size &0x3 || offset &0x3 )return -EINVAL ; +if (size >PAGE_SIZE ) +return -EINVAL ; + +/* +* Access the user buffer only while none of the locks below are held: +* a fault takes mmap_lock, and grbm_idx_mutex and srbm_mutex nest +* inside it. +*/ + u32 *data __free(kfree) = kmalloc(size, GFP_KERNEL); +if (!data) +return -ENOMEM ; +if (write_en &©_from_user (data, buf, size)) +return -EFAULT ; + r =pm_runtime_get_sync (adev_to_drm (adev)->dev);if (r <0 ) {pm_runtime_put_autosuspend (adev_to_drm (adev)->dev);
@@ -281,24 +300,16 @@ static ssize_t amdgpu_debugfs_regs2_op(struct file *f, char __user *buf, u32 offmutex_lock (&adev->pm.mutex);while (size) { -if (!write_en) { - value =RREG32 (offset >>2 ); - r =put_user (value, (uint32_t *)buf); - }else { - r =get_user (value, (uint32_t *)buf); -if (!r) -amdgpu_mm_wreg_mmio_rlc (adev, offset >>2 , value, rd->id.xcc_id); - } -if (r) { - result = r; - goto end; - } +if (!write_en) + data[result >>2 ] =RREG32 (offset >>2 ); +else +amdgpu_mm_wreg_mmio_rlc (adev, offset >>2 , data[result >>2 ], + rd->id.xcc_id); offset +=4 ; size -=4 ; result +=4 ; - buf +=4 ; } -end: +if (rd->id.use_grbm) {amdgpu_gfx_select_se_sh (adev,0xffffffff ,0xffffffff ,0xffffffff , rd->id.xcc_id);mutex_unlock (&adev->grbm_idx_mutex);
@@ -317,6 +328,10 @@ static ssize_t amdgpu_debugfs_regs2_op(struct file *f, char __user *buf, u32 offpm_runtime_put_autosuspend (adev_to_drm (adev)->dev);amdgpu_virt_disable_access_debugfs (adev); + +if (!write_en &©_to_user (buf, data, result)) +return -EFAULT ; +return result; }
Sasha Levin
maintainerPATCH 1/1 drm/amdgpu: copy debugfs register data outside the GRBM/SRBM locks
From: Mikhail Gavrilov <[email protected]>
[ Upstream commit 16c64495859f13f75602f439588883f2a4a4d6a6 ]
Reading or writing a register through the amdgpu_regs2 debugfs file with GRBM bank selection, which umr does for every banked access (a single "umr -b x x x -r <reg>" is enough, as is the wave dump with "-O halt_waves"), makes lockdep report a circular locking dependency, after which lockdep stays off until reboot:
WARNING: possible circular locking dependency detected
umr/63306 is trying to acquire lock:
ffff8882cf4b8350 (&mm->mmap_lock){++++}-{4:4}, at: __might_fault+0x9b/0x140
but task is already holding lock:
ffff8881aec010d0 (&amdgpu_grbm_lock_key){+.+.}-{4:4}, at: amdgpu_debugfs_regs2_op.isra.0+0x20d/0xd00 [amdgpu]
...
Chain exists of:
&mm->mmap_lock --> &amdgpu_srbm_lock_key --> &amdgpu_grbm_lock_key
...
__might_fault+0xc5/0x140
amdgpu_debugfs_regs2_op.isra.0+0x441/0xd00 [amdgpu]
full_proxy_write+0x10e/0x1d0
vfs_write+0x1d0/0xf50
ksys_write+0x116/0x250amdgpu_debugfs_regs2_op() and amdgpu_debugfs_process_reg_op() call get_user()/put_user() for every dword while holding grbm_idx_mutex or srbm_mutex, and pm.mutex if requested, so a fault there takes mmap_lock inside those locks. The lock hierarchy in amdgpu_lockdep.c puts srbm_mutex and grbm_idx_mutex below notifier_lock, which amdgpu_cs_submit() takes with the BO reservations held, and dma_resv_lockdep() orders the reservations inside mmap_lock. So mmap_lock is outside grbm_idx_mutex and srbm_mutex, and these two debugfs paths nest it the other way round. The copies under the locks are as old as the bank selection in both files; commit 1d0f5838b126 ("drm/amdgpu: Add lockdep annotations for lock ordering validation") only made them visible to lockdep.
Copy the user buffer in before any of the locks is taken and the result out after all of them are dropped, as amdgpu_debugfs_wave_read(), amdgpu_debugfs_gpr_read() and amdgpu_debugfs_gprwave_read() already do. The buffer is sized by the count passed to read() or write(), so an access larger than PAGE_SIZE is now rejected with -EINVAL; umr reads and writes one register at a time. A fault on the user buffer of a write now fails with -EFAULT before any register is written, instead of after a partial write.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 39 ++++++++++++--------- 1 file changed, 23 insertions(+), 16 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +23 -16
@@ -73,6 +73,7 @@ static int amdgpu_debugfs_process_reg_op(bool read, struct file *f,int r;bool pm_pg_lock, use_bank, use_ring;unsigned instance_bank, sh_bank, se_bank, me, pipe, queue, vmid; + u32 *data __free(kfree) = NULL; pm_pg_lock = use_bank = use_ring = false; instance_bank = sh_bank = se_bank = me = pipe = queue = vmid =0 ;
@@ -110,6 +111,20 @@ static int amdgpu_debugfs_process_reg_op(bool read, struct file *f, *pos &= (1UL <<22 ) -1 ; +if (size >PAGE_SIZE ) +return -EINVAL ; + +/* +* Access the user buffer only while none of the locks below are held: +* a fault takes mmap_lock, and grbm_idx_mutex and srbm_mutex nest +* inside it. +*/ + data =kmalloc (size,GFP_KERNEL ); +if (!data) +return -ENOMEM ; +if (!read &©_from_user (data, buf, size)) +return -EFAULT ; + r =pm_runtime_get_sync (adev_to_drm (adev)->dev);if (r <0 ) {pm_runtime_put_autosuspend (adev_to_drm (adev)->dev);
@@ -142,28 +157,16 @@ static int amdgpu_debugfs_process_reg_op(bool read, struct file *f,mutex_lock (&adev->pm.mutex);while (size) { -uint32_t value; - -if (read) { - value =RREG32 (*pos >>2 ); - r =put_user (value, (uint32_t *)buf); - }else { - r =get_user (value, (uint32_t *)buf); -if (!r) -amdgpu_mm_wreg_mmio_rlc (adev, *pos >>2 , value); - } -if (r) { - result = r; - goto end; - } +if (read) + data[result >>2 ] =RREG32 (*pos >>2 ); +else +amdgpu_mm_wreg_mmio_rlc (adev, *pos >>2 , data[result >>2 ]); result +=4 ; - buf +=4 ; *pos +=4 ; size -=4 ; } -end:if (use_bank) {amdgpu_gfx_select_se_sh (adev,0xffffffff ,0xffffffff ,0xffffffff );mutex_unlock (&adev->grbm_idx_mutex);
@@ -179,6 +182,10 @@ static int amdgpu_debugfs_process_reg_op(bool read, struct file *f,pm_runtime_put_autosuspend (adev_to_drm (adev)->dev);amdgpu_virt_disable_access_debugfs (adev); + +if (read &©_to_user (buf, data, result)) +return -EFAULT ; +return result; }
Signature · 1 line
2.53.0