drm/amdkfd: Fix named barrier restore in gfx12.1 trap handler
Subsystems (3)
PATCH 1/1 drm/amdkfd: Fix named barrier restore in gfx12.1 trap handler
Barrier state layout has non-zero fields above the signal count. Mask these off to restore the correct signal count.
--- .../gpu/drm/amd/amdkfd/cwsr_trap_handler.h | 150 +++++++++--------- .../amd/amdkfd/cwsr_trap_handler_gfx12.asm | 2 +- 2 files changed, 77 insertions(+), 75 deletions(-)
drivers/gpu/drm/amd/amdkfd/cwsr_trap_handler.h +76 -74
@@ -3929,7 +3929,7 @@ static const uint32_t cwsr_trap_gfx12_hex[] = {0x00030000 ,0x807d847d ,0x8070ff70 ,0x00000400 ,0xbf0a7b7d ,0xbfa2ffe9 , -0xbfa0014c ,0xbef4007e , +0xbfa0014d ,0xbef4007e ,0x8b75ff7f ,0x0000ffff ,0xbef1007f ,0xb8f20742 , 0x84729972, 0x8b6eff7f,
@@ -4070,36 +4070,36 @@ static const uint32_t cwsr_trap_gfx12_hex[] = {0xb96ef812 ,0xf4601bbb ,0xf8000030 ,0xbf8a0000 ,0xb96ef813 ,0x8b6eff7f , -0x04000000 ,0xbfa1000b , +0x04000000 ,0xbfa1000c ,0xf4601bbb ,0xf8000038 ,0xbf8a0000 ,0xbf0d806e , -0xbfa10006 ,0x856e906e , -0x8b6e6e6e ,0xbfa10003 , -0xbe804ec1 ,0x816ec16e , -0xbfa0fffb ,0xbefd006f , -0xbefe0070 ,0xbeff0071 , -0xb97b2011 ,0x857b867b , -0xb97b0191 ,0x857b827b , -0xb97bba11 ,0xb973f801 , -0xb8ee3b05 ,0x806e816e , -0xbf0d9972 ,0xbfa20002 , -0x846e896e ,0xbfa00001 , -0x846e8a6e ,0x806eff6e , -0x00000240 ,0x806e746e , -0x826f8075 ,0xf4605c37 , -0xf8000010 ,0xf4605d37 , -0xf8000020 ,0xf4601e77 , -0xf8000034 ,0xbf8a0000 , -0x8b6dff6d ,0x0000ffff , -0x8bfe7e7e ,0x8bea6a6a , -0x936eff77 ,0x0002001a , -0xb96ef81a ,0xb97af804 , +0xbfa10007 ,0x936eff6e , +0x00070010 ,0x8b6e6e6e , +0xbfa10003 ,0xbe804ec1 , +0x816ec16e ,0xbfa0fffb , +0xbefd006f ,0xbefe0070 , +0xbeff0071 ,0xb97b2011 , +0x857b867b ,0xb97b0191 , +0x857b827b ,0xb97bba11 , +0xb973f801 ,0xb8ee3b05 , +0x806e816e ,0xbf0d9972 , +0xbfa20002 ,0x846e896e , +0xbfa00001 ,0x846e8a6e , +0x806eff6e ,0x00000240 , +0x806e746e ,0x826f8075 , +0xf4605c37 ,0xf8000010 , +0xf4605d37 ,0xf8000020 , +0xf4601e77 ,0xf8000034 , +0xbf8a0000 ,0x8b6dff6d , +0x0000ffff ,0x8bfe7e7e , +0x8bea6a6a ,0x936eff77 , +0x0002001a ,0xb96ef81a , +0xb97af804 ,0xbe804ec2 , +0xbf94fffe ,0xbe804a6c ,0xbe804ec2 ,0xbf94fffe , -0xbe804a6c ,0xbe804ec2 , -0xbf94fffe ,0xbfb10000 , +0xbfb10000 ,0xbf9f0000 ,0xbf9f0000 ,0xbf9f0000 , 0xbf9f0000, 0xbf9f0000, - 0xbf9f0000, 0x00000000, }; static const uint32_t cwsr_trap_gfx9_5_0_hex[] = {
@@ -5066,7 +5066,7 @@ static const uint32_t cwsr_trap_gfx12_1_0_hex[] = {0x018c0000 ,0x00030000 ,0x807d847d ,0x8070ff70 ,0x00000400 ,0xbf0a7b7d , -0xbfa2ffe9 ,0xbfa00184 , +0xbfa2ffe9 ,0xbfa00187 ,0xbef4007e ,0x8b75ff7f ,0x01ffffff ,0xbef1007f , 0xb8f20742, 0x84729972,
@@ -5208,64 +5208,66 @@ static const uint32_t cwsr_trap_gfx12_1_0_hex[] = {0xf4601bbb ,0xf8000030 ,0xbf8a0000 ,0xb96ef813 ,0x8b6eff7f ,0x04000000 , -0xbfa10022 ,0xf4601bbb , +0xbfa10024 ,0xf4601bbb ,0xf8000038 ,0xbf8a0000 , -0xbf0d806e ,0xbfa1001d , -0x856e906e ,0x8b6e6e6e , -0xbfa10003 ,0xbe804ec1 , -0x816ec16e ,0xbfa0fffb , -0xbef800ff ,0x00000080 , -0xbefd0081 ,0xf4601bbb , -0xf0000000 ,0xbfc70000 , -0x80788478 ,0x937eff6e , -0x00070004 ,0x847e907e , -0x8c7d7e7d ,0xbe80517d , -0x917dff7d ,0x007f0000 , -0x856e906e ,0x8b6e6e6e , +0xbf0d806e ,0xbfa1001f , +0x936eff6e ,0x00070010 , +0x8b6e6e6e ,0xbfa10003 , +0xbe804ec1 ,0x816ec16e , +0xbfa0fffb ,0xbef800ff , +0x00000080 ,0xbefd0081 , +0xf4601bbb ,0xf0000000 , +0xbfc70000 ,0x80788478 , +0x937eff6e ,0x00070004 , +0x847e907e ,0x8c7d7e7d , +0xbe80517d ,0x917dff7d , +0x007f0000 ,0x936eff6e , +0x00070010 ,0x8b6e6e6e ,0xbfa10003 ,0xbe804e7d ,0x816ec16e ,0xbfa0fffb ,0x807d817d ,0xbf08907d , -0xbfa1ffec ,0xf4601bbb , +0xbfa1ffeb ,0xf4601bbb ,0xf800003c ,0xbfc70000 , -0xbf0d806e ,0xbfa1000c , +0xbf0d806e ,0xbfa1000d ,0xbf0d9a7f ,0xbfa10002 ,0xbf068180 ,0xbe804fc4 , -0xbf94fffc ,0xbfa10006 , -0x856e906e ,0x8b6e6e6e , -0xbfa10003 ,0xbe804ec3 , -0x816ec16e ,0xbfa0fffb , -0xf4601bbb ,0xf8000040 , -0xbfc70000 ,0xb96ef81a , -0xbefd006f ,0xbefe0070 , -0xbeff0071 ,0xb979f822 , -0xb97b2011 ,0x857b867b , -0xb97b0191 ,0x857b827b , -0xb97bba11 ,0xb973f801 , -0xb8ee3b05 ,0x806e816e , -0xbf0d9972 ,0xbfa20002 , -0x846e896e ,0xbfa00001 , -0x846e8a6e ,0x806eff6e , -0x000001c0 ,0x806e746e , -0x826f8075 ,0xf4605c37 , -0xf8000010 ,0xf4605d37 , -0xf8000020 ,0xf4601e77 , -0xf8000034 ,0xbf8a0000 , -0x856e9677 ,0xb96e04a1 , -0x856e9577 ,0xb96e0421 , -0x856e8e77 ,0xb96e3021 , -0x8b6dff6d ,0x01ffffff , -0x8bfe7e7e ,0x8bea6a6a , -0xb97af804 ,0xb8eef802 , -0xbf0c8b6e ,0xbfa20003 , -0xbe804fc2 ,0xbf94fffe , -0xbfa10001 ,0xbe804ec4 , -0xbf94fffc ,0x857a897a , -0xb97a0244 ,0xbe804a6c , +0xbf94fffc ,0xbfa10007 , +0x936eff6e ,0x00070010 , +0x8b6e6e6e ,0xbfa10003 , +0xbe804ec3 ,0x816ec16e , +0xbfa0fffb ,0xf4601bbb , +0xf8000040 ,0xbfc70000 , +0xb96ef81a ,0xbefd006f , +0xbefe0070 ,0xbeff0071 , +0xb979f822 ,0xb97b2011 , +0x857b867b ,0xb97b0191 , +0x857b827b ,0xb97bba11 , +0xb973f801 ,0xb8ee3b05 , +0x806e816e ,0xbf0d9972 , +0xbfa20002 ,0x846e896e , +0xbfa00001 ,0x846e8a6e , +0x806eff6e ,0x000001c0 , +0x806e746e ,0x826f8075 , +0xf4605c37 ,0xf8000010 , +0xf4605d37 ,0xf8000020 , +0xf4601e77 ,0xf8000034 , +0xbf8a0000 ,0x856e9677 , +0xb96e04a1 ,0x856e9577 , +0xb96e0421 ,0x856e8e77 , +0xb96e3021 ,0x8b6dff6d , +0x01ffffff ,0x8bfe7e7e , +0x8bea6a6a ,0xb97af804 ,0xb8eef802 ,0xbf0c8b6e ,0xbfa20003 ,0xbe804fc2 ,0xbf94fffe ,0xbfa10001 ,0xbe804ec4 ,0xbf94fffc , -0xbfb10000 ,0xbf9f0000 , +0x857a897a ,0xb97a0244 , +0xbe804a6c ,0xb8eef802 , +0xbf0c8b6e ,0xbfa20003 , +0xbe804fc2 ,0xbf94fffe , +0xbfa10001 ,0xbe804ec4 , +0xbf94fffc ,0xbfb10000 ,0xbf9f0000 ,0xbf9f0000 ,0xbf9f0000 ,0xbf9f0000 , + 0xbf9f0000, 0x00000000, };
drivers/gpu/drm/amd/amdkfd/cwsr_trap_handler_gfx12.asm +1 -1
@@ -1387,7 +1387,7 @@ end function restore_barrier_signal_count(barrier_id) // extract the saved signal count from s_restore_tmp - s_lshr_b32 s_restore_tmp, s_restore_tmp, BARRIER_STATE_SIGNAL_OFFSET + s_bfe_u32 s_restore_tmp, s_restore_tmp, (BARRIER_STATE_SIGNAL_OFFSET | (BARRIER_STATE_SIGNAL_SIZE << 0x10)) // We need to call s_barrier_signal repeatedly to restore the signal count // of the group/cluster barrier. The member count is already initialized.
Signature · 1 line
2.34.1
AMD General
Hi Jay,
Thanks for the patch!
The bug and fix are correct. S_GET_BARRIER_STATE returns:
{ 5'b0, NBC[2:0], 1'b0, signalCnt[6:0], 5'b0, memberCnt[6:0], 3'b0, valid } where NBC (bits [26:24]) sits immediately above signalCnt (bits [22:16]). An s_lshr_b32 by 22 shifts both down together, so the extracted value is (NBC << 2 | signalCnt) — inflated whenever named barriers are allocated (NBC > 0), causing the restore loop to over-signal the barrier.
s_bfe_u32 with offset=22, size=8 masks NBC out precisely, leaving only the 7-bit signal count in the destination.
One note: BARRIER_STATE_SIGNAL_SIZE is defined as 8, but the signalCnt field is 7 bits wide ([22:16]). Bit 29 is always 0 in practice (it's reserved above NBC), so this is harmless and the extraction is still correct. A comment (or a corrected constant value 7) would make the intent clearer, but it's not a blocker.
Best regards,
Vladimir
________________________________
From: Cornwall, Jay <[email protected]>
Sent: Tuesday, July 7, 2026 12:00 AM
To: [email protected] <[email protected]>
Cc: Cornwall, Jay <[email protected]>; Six, Lancelot <[email protected]>; Indic, Vladimir <[email protected]>; Araz, Tishko <[email protected]>; Erenberg, Max <[email protected]>
Subject: [PATCH] drm/amdkfd: Fix named barrier restore in gfx12.1 trap handler
Barrier state layout has non-zero fields above the signal count. Mask these off to restore the correct signal count.
--- .../gpu/drm/amd/amdkfd/cwsr_trap_handler.h | 150 +++++++++--------- .../amd/amdkfd/cwsr_trap_handler_gfx12.asm | 2 +- 2 files changed, 77 insertions(+), 75 deletions(-)
drivers/gpu/drm/amd/amdkfd/cwsr_trap_handler.h +76 -74
@@ -3929,7 +3929,7 @@ static const uint32_t cwsr_trap_gfx12_hex[] = {0x00030000 ,0x807d847d ,0x8070ff70 ,0x00000400 ,0xbf0a7b7d ,0xbfa2ffe9 , -0xbfa0014c ,0xbef4007e , +0xbfa0014d ,0xbef4007e ,0x8b75ff7f ,0x0000ffff ,0xbef1007f ,0xb8f20742 , 0x84729972, 0x8b6eff7f,
@@ -4070,36 +4070,36 @@ static const uint32_t cwsr_trap_gfx12_hex[] = {0xb96ef812 ,0xf4601bbb ,0xf8000030 ,0xbf8a0000 ,0xb96ef813 ,0x8b6eff7f , -0x04000000 ,0xbfa1000b , +0x04000000 ,0xbfa1000c ,0xf4601bbb ,0xf8000038 ,0xbf8a0000 ,0xbf0d806e , -0xbfa10006 ,0x856e906e , -0x8b6e6e6e ,0xbfa10003 , -0xbe804ec1 ,0x816ec16e , -0xbfa0fffb ,0xbefd006f , -0xbefe0070 ,0xbeff0071 , -0xb97b2011 ,0x857b867b , -0xb97b0191 ,0x857b827b , -0xb97bba11 ,0xb973f801 , -0xb8ee3b05 ,0x806e816e , -0xbf0d9972 ,0xbfa20002 , -0x846e896e ,0xbfa00001 , -0x846e8a6e ,0x806eff6e , -0x00000240 ,0x806e746e , -0x826f8075 ,0xf4605c37 , -0xf8000010 ,0xf4605d37 , -0xf8000020 ,0xf4601e77 , -0xf8000034 ,0xbf8a0000 , -0x8b6dff6d ,0x0000ffff , -0x8bfe7e7e ,0x8bea6a6a , -0x936eff77 ,0x0002001a , -0xb96ef81a ,0xb97af804 , +0xbfa10007 ,0x936eff6e , +0x00070010 ,0x8b6e6e6e , +0xbfa10003 ,0xbe804ec1 , +0x816ec16e ,0xbfa0fffb , +0xbefd006f ,0xbefe0070 , +0xbeff0071 ,0xb97b2011 , +0x857b867b ,0xb97b0191 , +0x857b827b ,0xb97bba11 , +0xb973f801 ,0xb8ee3b05 , +0x806e816e ,0xbf0d9972 , +0xbfa20002 ,0x846e896e , +0xbfa00001 ,0x846e8a6e , +0x806eff6e ,0x00000240 , +0x806e746e ,0x826f8075 , +0xf4605c37 ,0xf8000010 , +0xf4605d37 ,0xf8000020 , +0xf4601e77 ,0xf8000034 , +0xbf8a0000 ,0x8b6dff6d , +0x0000ffff ,0x8bfe7e7e , +0x8bea6a6a ,0x936eff77 , +0x0002001a ,0xb96ef81a , +0xb97af804 ,0xbe804ec2 , +0xbf94fffe ,0xbe804a6c ,0xbe804ec2 ,0xbf94fffe , -0xbe804a6c ,0xbe804ec2 , -0xbf94fffe ,0xbfb10000 , +0xbfb10000 ,0xbf9f0000 ,0xbf9f0000 ,0xbf9f0000 , 0xbf9f0000, 0xbf9f0000, - 0xbf9f0000, 0x00000000, }; static const uint32_t cwsr_trap_gfx9_5_0_hex[] = {
@@ -5066,7 +5066,7 @@ static const uint32_t cwsr_trap_gfx12_1_0_hex[] = {0x018c0000 ,0x00030000 ,0x807d847d ,0x8070ff70 ,0x00000400 ,0xbf0a7b7d , -0xbfa2ffe9 ,0xbfa00184 , +0xbfa2ffe9 ,0xbfa00187 ,0xbef4007e ,0x8b75ff7f ,0x01ffffff ,0xbef1007f , 0xb8f20742, 0x84729972,
@@ -5208,64 +5208,66 @@ static const uint32_t cwsr_trap_gfx12_1_0_hex[] = {0xf4601bbb ,0xf8000030 ,0xbf8a0000 ,0xb96ef813 ,0x8b6eff7f ,0x04000000 , -0xbfa10022 ,0xf4601bbb , +0xbfa10024 ,0xf4601bbb ,0xf8000038 ,0xbf8a0000 , -0xbf0d806e ,0xbfa1001d , -0x856e906e ,0x8b6e6e6e , -0xbfa10003 ,0xbe804ec1 , -0x816ec16e ,0xbfa0fffb , -0xbef800ff ,0x00000080 , -0xbefd0081 ,0xf4601bbb , -0xf0000000 ,0xbfc70000 , -0x80788478 ,0x937eff6e , -0x00070004 ,0x847e907e , -0x8c7d7e7d ,0xbe80517d , -0x917dff7d ,0x007f0000 , -0x856e906e ,0x8b6e6e6e , +0xbf0d806e ,0xbfa1001f , +0x936eff6e ,0x00070010 , +0x8b6e6e6e ,0xbfa10003 , +0xbe804ec1 ,0x816ec16e , +0xbfa0fffb ,0xbef800ff , +0x00000080 ,0xbefd0081 , +0xf4601bbb ,0xf0000000 , +0xbfc70000 ,0x80788478 , +0x937eff6e ,0x00070004 , +0x847e907e ,0x8c7d7e7d , +0xbe80517d ,0x917dff7d , +0x007f0000 ,0x936eff6e , +0x00070010 ,0x8b6e6e6e ,0xbfa10003 ,0xbe804e7d ,0x816ec16e ,0xbfa0fffb ,0x807d817d ,0xbf08907d , -0xbfa1ffec ,0xf4601bbb , +0xbfa1ffeb ,0xf4601bbb ,0xf800003c ,0xbfc70000 , -0xbf0d806e ,0xbfa1000c , +0xbf0d806e ,0xbfa1000d ,0xbf0d9a7f ,0xbfa10002 ,0xbf068180 ,0xbe804fc4 , -0xbf94fffc ,0xbfa10006 , -0x856e906e ,0x8b6e6e6e , -0xbfa10003 ,0xbe804ec3 , -0x816ec16e ,0xbfa0fffb , -0xf4601bbb ,0xf8000040 , -0xbfc70000 ,0xb96ef81a , -0xbefd006f ,0xbefe0070 , -0xbeff0071 ,0xb979f822 , -0xb97b2011 ,0x857b867b , -0xb97b0191 ,0x857b827b , -0xb97bba11 ,0xb973f801 , -0xb8ee3b05 ,0x806e816e , -0xbf0d9972 ,0xbfa20002 , -0x846e896e ,0xbfa00001 , -0x846e8a6e ,0x806eff6e , -0x000001c0 ,0x806e746e , -0x826f8075 ,0xf4605c37 , -0xf8000010 ,0xf4605d37 , -0xf8000020 ,0xf4601e77 , -0xf8000034 ,0xbf8a0000 , -0x856e9677 ,0xb96e04a1 , -0x856e9577 ,0xb96e0421 , -0x856e8e77 ,0xb96e3021 , -0x8b6dff6d ,0x01ffffff , -0x8bfe7e7e ,0x8bea6a6a , -0xb97af804 ,0xb8eef802 , -0xbf0c8b6e ,0xbfa20003 , -0xbe804fc2 ,0xbf94fffe , -0xbfa10001 ,0xbe804ec4 , -0xbf94fffc ,0x857a897a , -0xb97a0244 ,0xbe804a6c , +0xbf94fffc ,0xbfa10007 , +0x936eff6e ,0x00070010 , +0x8b6e6e6e ,0xbfa10003 , +0xbe804ec3 ,0x816ec16e , +0xbfa0fffb ,0xf4601bbb , +0xf8000040 ,0xbfc70000 , +0xb96ef81a ,0xbefd006f , +0xbefe0070 ,0xbeff0071 , +0xb979f822 ,0xb97b2011 , +0x857b867b ,0xb97b0191 , +0x857b827b ,0xb97bba11 , +0xb973f801 ,0xb8ee3b05 , +0x806e816e ,0xbf0d9972 , +0xbfa20002 ,0x846e896e , +0xbfa00001 ,0x846e8a6e , +0x806eff6e ,0x000001c0 , +0x806e746e ,0x826f8075 , +0xf4605c37 ,0xf8000010 , +0xf4605d37 ,0xf8000020 , +0xf4601e77 ,0xf8000034 , +0xbf8a0000 ,0x856e9677 , +0xb96e04a1 ,0x856e9577 , +0xb96e0421 ,0x856e8e77 , +0xb96e3021 ,0x8b6dff6d , +0x01ffffff ,0x8bfe7e7e , +0x8bea6a6a ,0xb97af804 ,0xb8eef802 ,0xbf0c8b6e ,0xbfa20003 ,0xbe804fc2 ,0xbf94fffe ,0xbfa10001 ,0xbe804ec4 ,0xbf94fffc , -0xbfb10000 ,0xbf9f0000 , +0x857a897a ,0xb97a0244 , +0xbe804a6c ,0xb8eef802 , +0xbf0c8b6e ,0xbfa20003 , +0xbe804fc2 ,0xbf94fffe , +0xbfa10001 ,0xbe804ec4 , +0xbf94fffc ,0xbfb10000 ,0xbf9f0000 ,0xbf9f0000 ,0xbf9f0000 ,0xbf9f0000 , + 0xbf9f0000, 0x00000000, };
drivers/gpu/drm/amd/amdkfd/cwsr_trap_handler_gfx12.asm +1 -1
@@ -1387,7 +1387,7 @@ end function restore_barrier_signal_count(barrier_id) // extract the saved signal count from s_restore_tmp - s_lshr_b32 s_restore_tmp, s_restore_tmp, BARRIER_STATE_SIGNAL_OFFSET + s_bfe_u32 s_restore_tmp, s_restore_tmp, (BARRIER_STATE_SIGNAL_OFFSET | (BARRIER_STATE_SIGNAL_SIZE << 0x10)) // We need to call s_barrier_signal repeatedly to restore the signal count // of the group/cluster barrier. The member count is already initialized.
--
2.34.1