powerpc/imc-pmu: Fix IMC PMU code of using mutex in IRQs disabled section
PATCH 1/1 powerpc/imc-pmu: Fix IMC PMU code of using mutex in IRQs disabled section
Current imc-pmu code triggers a WARNING with CONFIG_DEBUG_ATOMIC_SLEEP and CONFIG_PROVE_LOCKING enabled, while running a thread_imc event.
Command to trigger the warning:
[command]# perf stat -e thread_imc/CPM_CS_FROM_L4_MEM_X_DPTEG/ sleep 5
Performance counter stats for 'sleep 5':
0 thread_imc/CPM_CS_FROM_L4_MEM_X_DPTEG/
5.002117947 seconds time elapsed
0.000131000 seconds user
0.001063000 seconds sysBelow is snippet of the warning in dmesg:
[ 196.520838] BUG: sleeping function called from invalid context at kernel/locking/mutex.c:580
[ 196.521126] in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 2869, name: perf-exec
[ 196.521136] preempt_count: 2, expected: 0
[ 196.521143] 4 locks held by perf-exec/2869:
[ 196.521151] #0: c00000004325c540 (&sig->cred_guard_mutex){+.+.}-{3:3}, at: bprm_execve+0x64/0xa90
[ 196.521173] #1: c00000004325c5d8 (&sig->exec_update_lock){++++}-{3:3}, at: begin_new_exec+0x460/0xef0
[ 196.521192] #2: c0000003fa99d4e0 (&cpuctx_lock){-...}-{2:2}, at: perf_event_exec+0x290/0x510
[ 196.521212] #3: c000000017ab8418 (&ctx->lock){....}-{2:2}, at: perf_event_exec+0x29c/0x510
[ 196.521230] irq event stamp: 4806
[ 196.521237] hardirqs last enabled at (4805): [<c000000000f65b94>] _raw_spin_unlock_irqrestore+0x94/0xd0
[ 196.521248] hardirqs last disabled at (4806): [<c0000000003fae44>] perf_event_exec+0x394/0x510
[ 196.521260] softirqs last enabled at (0): [<c00000000013c404>] copy_process+0xc34/0x1ff0
[ 196.521270] softirqs last disabled at (0): [<0000000000000000>] 0x0
[ 196.521281] CPU: 36 PID: 2869 Comm: perf-exec Not tainted 6.2.0-rc2-00011-g1247637727f2 #61
[ 196.521291] Hardware name: 8375-42A POWER9 0x4e1202 opal:v7.0-16-g9b85f7d961 PowerNV
[ 196.521300] Call Trace:
[ 196.521306] [c00000004d213560] [c000000000f20c74] dump_stack_lvl+0x98/0xe0 (unreliable)
[ 196.521321] [c00000004d2135a0] [c000000000194968] __might_resched+0x2f8/0x310
[ 196.521332] [c00000004d213620] [c000000000f5a5dc] __mutex_lock+0x6c/0x13f0
[ 196.521344] [c00000004d213740] [c000000000127a44] thread_imc_event_add+0xf4/0x1b0
[ 196.521357] [c00000004d2137c0] [c0000000003ec930] event_sched_in+0xe0/0x210
[ 196.521369] [c00000004d213810] [c0000000003ed940] merge_sched_in+0x1f0/0x600
[ 196.521380] [c00000004d213860] [c0000000003ee00c] visit_groups_merge.isra.92.constprop.166+0x2bc/0x6c0
[ 196.521393] [c00000004d213920] [c0000000003ee4dc] ctx_flexible_sched_in+0xcc/0x140
[ 196.521405] [c00000004d213980] [c0000000003ee75c] ctx_sched_in+0x20c/0x2a0
[ 196.521416] [c00000004d2139f0] [c0000000003ee974] ctx_resched+0x104/0x1c0
[ 196.521427] [c00000004d213a50] [c0000000003fadf0] perf_event_exec+0x340/0x510
[ 196.521440] [c00000004d213ac0] [c00000000054a570] begin_new_exec+0x730/0xef0
[ 196.521451] [c00000004d213b70] [c0000000005dd7f8] load_elf_binary+0x3f8/0x1e10
-------
[ 196.522551] do not call blocking ops when !TASK_RUNNING; state=2001 set at [<00000000fd63e7cf>] do_nanosleep+0x60/0x1a0
[ 196.522566] WARNING: CPU: 36 PID: 2869 at kernel/sched/core.c:9912 __might_sleep+0x9c/0xb0
[ 196.522575] Modules linked in: kvm_hv kvm vmx_crypto leds_powernv powernv_op_panel led_class gf128mul crc32c_vpmsum fuse autofs4
[ 196.522594] CPU: 36 PID: 2869 Comm: sleep Tainted: G W 6.2.0-rc2-00011-g1247637727f2 #61
[ 196.522602] Hardware name: 8375-42A POWER9 0x4e1202 opal:v7.0-16-g9b85f7d961 PowerNV
[ 196.522609] NIP: c000000000194a1c LR: c000000000194a18 CTR: c000000000a78670
[ 196.522616] REGS: c00000004d2134e0 TRAP: 0700 Tainted: G W (6.2.0-rc2-00011-g1247637727f2)
[ 196.522624] MSR: 9000000000021033 <SF,HV,ME,IR,DR,RI,LE> CR: 48002824 XER: 00000000
[ 196.522639] CFAR: c00000000013fb64 IRQMASK: 1
[ 196.522639] GPR00: c000000000194a18 c00000004d213780 c0000000013c1700 000000000000006b
[ 196.522639] GPR04: 00000000fffeffff c00000004d213540 c00000004d213538 0000000000000027 -------
The above warning triggered because current imc-pmu code uses mutex lock in interrupt disabled sections. The function mutex_lock internally calls "__might_resched" function, which will check if irq is disabled or not and incase irq is disabled, it will trigger the warning. Patch fix this issue by changing the mutex lock to spinlock.
--- arch/powerpc/include/asm/imc-pmu.h | 2 +- arch/powerpc/perf/imc-pmu.c | 109 +++++++++++++++-------------- 2 files changed, 56 insertions(+), 55 deletions(-)
arch/powerpc/include/asm/imc-pmu.h +1 -1
@@ -137,7 +137,7 @@ struct imc_pmu {* are inited. */ struct imc_pmu_ref { -struct mutex lock; +spinlock_t lock;unsigned int id;int refc; };
arch/powerpc/perf/imc-pmu.c +55 -54
398 lines not on this page · raw message
Signature · 1 line
2.31.1
Michael Ellerman
AppliedQuoted 9 lines · Kajol Jain
Current imc-pmu code triggers a WARNING with
CONFIG_DEBUG_ATOMIC_SLEEPandCONFIG_PROVE_LOCKINGenabled, while running athread_imcevent.Command to trigger the warning:
[command]# perf stat -e thread_imc/CPM_CS_FROM_L4_MEM_X_DPTEG/ sleep 5Performance counter stats for 'sleep 5':
[...]
Applied to powerpc/fixes.
[1/1] powerpc/imc-pmu: Fix IMC PMU code of using mutex in IRQs disabled section
https://git.kernel.org/powerpc/c/76d588dddc459fefa1da96e0a081a397c5c8e216
cheers