[PATCH] mailbox: mailbox-test: Fix __might_sleep() warning in mbox_test_message_read()
Junhui Liu
junhui.liu at pigmoral.tech
Mon May 19 23:41:50 PDT 2025
The following warning was observed when calling mbox_test_message_read()
for the first time:
[ 69.246375] do not call blocking ops when !TASK_RUNNING; state=1 set at [<(____ptrval____)>] mbox_test_message_read+0xba/0x23e
[ 69.258608] WARNING: CPU: 0 PID: 62 at kernel/sched/core.c:8741 __might_sleep+0x62/0x66
This is triggered because simple_read_from_buffer() called in
mbox_test_message_read() may sleep. As a result, the kernel warns about
blocking operations when the task state is not TASK_RUNNING.
Fix this by ensuring __set_current_state(TASK_RUNNING) is called before
executing code paths that may sleep.
Fixes: d597580d3737 ("generic ...copy_..._user primitives")
Signed-off-by: Junhui Liu <junhui.liu at pigmoral.tech>
---
Full message:
/sys/kernel/debug/soc:mailbox-test # cat message
[ 69.241175] ------------[ cut here ]------------
[ 69.246375] do not call blocking ops when !TASK_RUNNING; state=1 set at [<(____ptrval____)>] mbox_test_message_read+0xba/0x23e
[ 69.258608] WARNING: CPU: 0 PID: 62 at kernel/sched/core.c:8741 __might_sleep+0x62/0x66
[ 69.258746] Modules linked in:
[ 69.258781] CPU: 0 UID: 0 PID: 62 Comm: cat Not tainted 6.15.0-rc6-00349-gde4124a71fa8-dirty #2 NONE
[ 69.258820] Hardware name: Milk-V Duo (DT)
[ 69.258831] epc : __might_sleep+0x62/0x66
[ 69.258866] ra : __might_sleep+0x62/0x66
[ 69.258892] epc : ffffffff8004e548 ra : ffffffff8004e548 sp : ffffffc60022bc40
[ 69.258913] gp : ffffffff81717250 tp : ffffffd6023b8c80 t0 : 6100000000000000
[ 69.258931] t1 : 0000000000000064 t2 : 616320746f6e206f s0 : ffffffc60022bc60
[ 69.258950] s1 : ffffffff812001b0 a0 : 0000000000000072 a1 : ffffffff81688a60
[ 69.258970] a2 : 0000000000000010 a3 : 00000000000000c1 a4 : 0000000000000000
[ 69.258989] a5 : 0000000000000000 a6 : ffffffff8172ba60 a7 : 0000000000000038
[ 69.259012] s2 : 00000000000000c0 s3 : ffffffd602275400 s4 : ffffffd60226d180
[ 69.259032] s5 : 0000000200000022 s6 : ffffffd602275610 s7 : ffffffd602275400
[ 69.259054] s8 : ffffffd602239640 s9 : 0000000000001000 s10: 0000000000000001
[ 69.259074] s11: ffffffd6022396d8 t3 : ffffffff8172ba6f t4 : ffffffff8172ba6f
[ 69.259097] t5 : ffffffff8172ba70 t6 : ffffffc60022ba58
[ 69.259114] status: 0000000200000120 badaddr: 0000000000000000 cause: 0000000000000003
[ 69.259139] [<ffffffff8004e548>] __might_sleep+0x62/0x66
[ 69.259180] [<ffffffff801998da>] __might_fault+0x1c/0x24
[ 69.259253] [<ffffffff80430824>] _copy_to_user+0x28/0x90
[ 69.259295] [<ffffffff8022facc>] simple_read_from_buffer+0x48/0x72
[ 69.259356] [<ffffffff807e8c20>] mbox_test_message_read+0x1da/0x23e
[ 69.259396] [<ffffffff80367c32>] full_proxy_read+0x48/0x88
[ 69.259477] [<ffffffff801fdea8>] vfs_read+0xb2/0x288
[ 69.259508] [<ffffffff801fe896>] ksys_read+0x56/0xc0
[ 69.259535] [<ffffffff801fe914>] __riscv_sys_read+0x14/0x1c
[ 69.259563] [<ffffffff80a083f6>] do_trap_ecall_u+0x186/0x206
[ 69.259622] [<ffffffff80a12be2>] handle_exception+0x146/0x152
[ 69.259688] ---[ end trace 0000000000000000 ]---
---
drivers/mailbox/mailbox-test.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/mailbox/mailbox-test.c b/drivers/mailbox/mailbox-test.c
index c9dd8c42c0cdf9e4ff96da012d7fbdcb4c6bc130..2540808d550d34a8d5af523043e59dce9a0e0e10 100644
--- a/drivers/mailbox/mailbox-test.c
+++ b/drivers/mailbox/mailbox-test.c
@@ -200,11 +200,13 @@ static ssize_t mbox_test_message_read(struct file *filp, char __user *userbuf,
if (filp->f_flags & O_NONBLOCK) {
ret = -EAGAIN;
+ __set_current_state(TASK_RUNNING);
goto waitq_err;
}
if (signal_pending(current)) {
ret = -ERESTARTSYS;
+ __set_current_state(TASK_RUNNING);
goto waitq_err;
}
schedule();
@@ -231,9 +233,9 @@ static ssize_t mbox_test_message_read(struct file *filp, char __user *userbuf,
spin_unlock_irqrestore(&tdev->lock, flags);
+ __set_current_state(TASK_RUNNING);
ret = simple_read_from_buffer(userbuf, count, ppos, touser, MBOX_HEXDUMP_MAX_LEN);
waitq_err:
- __set_current_state(TASK_RUNNING);
remove_wait_queue(&tdev->waitq, &wait);
kfree_err:
kfree(touser);
---
base-commit: a5806cd506af5a7c19bcd596e4708b5c464bfd21
change-id: 20250518-fix-mailbox-test-warn-81fd373303b8
Best regards,
--
Junhui Liu <junhui.liu at pigmoral.tech>
More information about the linux-riscv
mailing list