pinctrl_mcp23s08_i2c: mutex used in irq_bus_lock causes 'scheduling while atomic' with matrix_keypad
Hi all,
I'm encountering a "BUG: scheduling while atomic" when using the MCP23017 GPIO expander with the matrix_keypad driver in IRQ mode on Linux v6.12.20
Hardware setup:
- MCP23017 connected via I2C
- 4x4 matrix keypad hooked to MCP23017 GPIOs
- SoC: Allwinner V3s SoC
- Using devicetree-overlay configuration for microchip,mcp23017 and gpio- matrix-keypad
When I press buttons on the keypad, after some amount of presses I get the following error from the Kernel:
[ 92.820159] BUG: scheduling while atomic: kworker/0:2/46/0x00000002 [ 92.826577] Modules linked in: bluetooth ecdh_generic ecc cfg80211 rfkill
ipv6 af_packet evdev mcp251xfd can_dev matrix_keypad matrix_keymap gpio_pcf857x pinctrl_mcp23s08_i2c pinctrl_mcp23s08 hd44780 hd44780_common charlcd sun4i_ss libdes sun4i_codec sun8i_codec_analog sun8i_adda_pr_regmap snd_soc_core snd_pcm_dmaengine snd_pcm snd_timer snd soundcore uio_pdrv_genirq uio [last unloaded: esp32_sdio(O)]
[ 92.862336] CPU: 0 UID: 0 PID: 46 Comm: kworker/0:2 Tainted: G O 6.12.20 #1 [ 92.862362] Tainted: [O]=OOT_MODULE [ 92.862368] Hardware name: Allwinner sun8i Family [ 92.862378] Workqueue: events matrix_keypad_scan [matrix_keypad] [ 92.862415] Call trace: [ 92.862429] unwind_backtrace from show_stack+0x18/0x1c [ 92.862469] show_stack from dump_stack_lvl+0x68/0x74 [ 92.862490] dump_stack_lvl from __schedule_bug+0x5c/0x70 [ 92.862518] __schedule_bug from __schedule+0xab4/0xc94 [ 92.862541] __schedule from schedule+0x34/0x14c [ 92.862560] schedule from schedule_preempt_disabled+0x24/0x34 [ 92.862580] schedule_preempt_disabled from __mutex_lock.constprop. 0+0x2e4/0x940 [ 92.862605] __mutex_lock.constprop.0 from mcp23s08_irq_bus_lock+0x20/0x30 [pinctrl_mcp23s08] [ 92.862650] mcp23s08_irq_bus_lock [pinctrl_mcp23s08] from __irq_get_desc_lock+0x84/0xa8 [ 92.862682] __irq_get_desc_lock from enable_irq+0x38/0xa8 [ 92.862710] enable_irq from matrix_keypad_scan+0x2e0/0x324 [matrix_keypad] [ 92.862738] matrix_keypad_scan [matrix_keypad] from process_one_work+0x160/0x410 [ 92.862763] process_one_work from worker_thread+0x258/0x3f8 [ 92.862782] worker_thread from kthread+0x118/0x134 [ 92.862801] kthread from ret_from_fork+0x14/0x38 [ 92.862817] Exception stack(0xc4989fb0 to 0xc4989ff8) [ 92.862829] 9fa0: 00000000 00000000 00000000 00000000 [ 92.862840] 9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 92.862849] 9fe0: 00000000 00000000 00000000 00000000 00000013 00000000 [ 93.007968] BUG: workqueue leaked atomic, lock or RCU: kworker/0:2[46] [ 93.007968] preempt=0xffffffff lock=0->0 RCU=0->0 workfn=matrix_keypad_scan [matrix_keypad] [ 93.008051] CPU: 0 UID: 0 PID: 46 Comm: kworker/0:2 Tainted: G W O 6.12.20 #1 [ 93.008071] Tainted: [W]=WARN, [O]=OOT_MODULE [ 93.008076] Hardware name: Allwinner sun8i Family [ 93.008085] Workqueue: events matrix_keypad_scan [matrix_keypad] [ 93.008108] Call trace: [ 93.008121] unwind_backtrace from show_stack+0x18/0x1c [ 93.008158] show_stack from dump_stack_lvl+0x68/0x74 [ 93.008179] dump_stack_lvl from process_one_work+0x40c/0x410 [ 93.008202] process_one_work from worker_thread+0x258/0x3f8 [ 93.008221] worker_thread from kthread+0x118/0x134 [ 93.008240] kthread from ret_from_fork+0x14/0x38 [ 93.008256] Exception stack(0xc4989fb0 to 0xc4989ff8) [ 93.008267] 9fa0: 00000000 00000000 00000000 00000000 [ 93.008277] 9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 93.008286] 9fe0: 00000000 00000000 00000000 00000000 00000013 00000000 [ 93.008300] BUG: scheduling while atomic: kworker/0:2/46/0x00000000 [ 93.115583] Modules linked in: bluetooth ecdh_generic ecc cfg80211 rfkill
ipv6 af_packet evdev mcp251xfd can_dev matrix_keypad matrix_keymap gpio_pcf857x pinctrl_mcp23s08_i2c pinctrl_mcp23s08 hd44780 hd44780_common charlcd sun4i_ss libdes sun4i_codec sun8i_codec_analog sun8i_adda_pr_regmap snd_soc_core snd_pcm_dmaengine snd_pcm snd_timer snd soundcore uio_pdrv_genirq uio [last unloaded: esp32_sdio(O)]
[ 93.151453] CPU: 0 UID: 0 PID: 46 Comm: kworker/0:2 Tainted: G W O 6.12.20 #1 [ 93.151483] Tainted: [W]=WARN, [O]=OOT_MODULE [ 93.151488] Hardware name: Allwinner sun8i Family [ 93.151496] Workqueue: 0x0 (events) [ 93.151525] Call trace: [ 93.151537] unwind_backtrace from show_stack+0x18/0x1c [ 93.151570] show_stack from dump_stack_lvl+0x68/0x74 [ 93.151589] dump_stack_lvl from __schedule_bug+0x5c/0x70 [ 93.151615] __schedule_bug from __schedule+0xab4/0xc94 [ 93.151640] __schedule from schedule+0x34/0x14c [ 93.151659] schedule from worker_thread+0x1c8/0x3f8 [ 93.151681] worker_thread from kthread+0x118/0x134 [ 93.151698] kthread from ret_from_fork+0x14/0x38 [ 93.151713] Exception stack(0xc4989fb0 to 0xc4989ff8) [ 93.151725] 9fa0: 00000000 00000000 00000000 00000000 [ 93.151736] 9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [ 93.151746] 9fe0: 00000000 00000000 00000000 00000000 00000013 00000000
Happy to test patches or provide further debugging info.
Best regards,
Lukas Schmid
Quoted 2 lines · Lukas Schmid
I'm encountering a "BUG: scheduling while atomic" when using the MCP23017 GPIO expander with the
matrix_keypaddriver in IRQ mode on Linux v6.12.20
Apply this commit from the upstream kernel:
commit a37eecb705f33726f1fb7cd2a67e514a15dfe693 (tag: pinctrl-v6.13-2)
Author: Evgenii Shatokhin <[email protected]> Date: Mon Dec 9 10:46:59 2024 +0300
pinctrl: mcp23s08: Fix sleeping in atomic context due to regmap locking
If a device uses MCP23xxx IO expander to receive IRQs, the following
bug can happen:
BUG: sleeping function called from invalid context
at kernel/locking/mutex.c:283
in_atomic(): 1, irqs_disabled(): 1, non_block: 0, ...
preempt_count: 1, expected: 0
...
Call Trace:
...
__might_resched+0x104/0x10e
__might_sleep+0x3e/0x62
mutex_lock+0x20/0x4c
regmap_lock_mutex+0x10/0x18
regmap_update_bits_base+0x2c/0x66
mcp23s08_irq_set_type+0x1ae/0x1d6
__irq_set_trigger+0x56/0x172
__setup_irq+0x1e6/0x646
request_threaded_irq+0xb6/0x160
...Yours,
Linus Walleij