RE: [PATCH 09/11] md: add atomic mode switching when removing disk

From: tada keisuke
Date: Fri Apr 05 2024 - 02:47:37 EST


> kern :err : [ 118.926307] BUG: sleeping function called from invalid context at lib/percpu-refcount.c:331
> kern :err : [ 118.935427] in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 55, name: kworker/6:0
> kern :err : [ 118.944338] preempt_count: 0, expected: 0
> kern :err : [ 118.949122] RCU nest depth: 1, expected: 0
> kern :warn : [ 118.954016] CPU: 6 PID: 55 Comm: kworker/6:0 Tainted: G S
> 6.8.0-rc3-00236-gff944d1be0fa #1
> kern :warn : [ 118.964389] Hardware name: Gigabyte Technology Co., Ltd Z97X-UD5H/Z97X-UD5H, BIOS F9
> 04/21/2015
> kern :warn : [ 118.973916] Workqueue: md_misc md_start_sync
> kern :warn : [ 118.978937] Call Trace:
> kern :warn : [ 118.982115] <TASK>
> kern :warn : [ 118.984943] dump_stack_lvl (lib/dump_stack.c:107 (discriminator 1))
> kern :warn : [ 118.989337] __might_resched (kernel/sched/core.c:10190)
> kern :warn : [ 118.993989] ? _raw_spin_lock_irqsave (arch/x86/include/asm/atomic.h:115
> include/linux/atomic/atomic-arch-fallback.h:2164 include/linux/atomic/atomic-instrumented.h:1296
> include/asm-generic/qspinlock.h:111 include/linux/spinlock.h:187 include/linux/spinlock_api_smp.h:111
> kernel/locking/spinlock.c:162)
> kern :warn : [ 118.999243] ? preempt_notifier_dec (kernel/sched/core.c:10144)
> kern :warn : [ 119.004321] percpu_ref_switch_to_atomic_sync (include/linux/kernel.h:107 lib/percpu-refcount.c:331)
> kern :warn : [ 119.010353] ? percpu_ref_reinit (lib/percpu-refcount.c:329)
> kern :warn : [ 119.015351] ? _raw_spin_lock_irqsave (arch/x86/include/asm/atomic.h:115
> include/linux/atomic/atomic-arch-fallback.h:2164 include/linux/atomic/atomic-instrumented.h:1296
> include/asm-generic/qspinlock.h:111 include/linux/spinlock.h:187 include/linux/spinlock_api_smp.h:111
> kernel/locking/spinlock.c:162)
> kern :warn : [ 119.020596] ? _raw_read_unlock_irqrestore (kernel/locking/spinlock.c:161)
> kern :warn : [ 119.026282] ? finish_task_switch+0x158/0x730
> kern :warn : [ 119.031969] ? __switch_to (arch/x86/include/asm/bitops.h:55
> include/asm-generic/bitops/instrumented-atomic.h:29 include/linux/thread_info.h:89
> arch/x86/include/asm/fpu/sched.h:66 arch/x86/kernel/process_64.c:626)
> kern :warn : [ 119.036435] rdev_removeable (drivers/md/md.c:9282)
> kern :warn : [ 119.041083] md_start_sync (drivers/md/md.c:9339 drivers/md/md.c:9449)
> kern :warn : [ 119.045462] ? mddev_unlock (drivers/md/md.c:9444)
> kern :warn : [ 119.050021] ? _raw_spin_lock_irq (arch/x86/include/asm/atomic.h:115
> include/linux/atomic/atomic-arch-fallback.h:2164 include/linux/atomic/atomic-instrumented.h:1296
> include/asm-generic/qspinlock.h:111 include/linux/spinlock.h:187 include/linux/spinlock_api_smp.h:120
> kernel/locking/spinlock.c:170)
> kern :warn : [ 119.054928] ? _raw_spin_lock_bh (kernel/locking/spinlock.c:169)
> kern :warn : [ 119.059739] process_one_work (kernel/workqueue.c:2638)
> kern :warn : [ 119.064476] worker_thread (kernel/workqueue.c:2700 kernel/workqueue.c:2787)
> kern :warn : [ 119.068943] ? process_one_work (kernel/workqueue.c:2733)
> kern :warn : [ 119.073864] kthread (kernel/kthread.c:388)
> kern :warn : [ 119.077815] ? kthread_complete_and_exit (kernel/kthread.c:341)
> kern :warn : [ 119.083321] ret_from_fork (arch/x86/kernel/process.c:153)
> kern :warn : [ 119.087627] ? kthread_complete_and_exit (kernel/kthread.c:341)
> kern :warn : [ 119.093140] ret_from_fork_asm (arch/x86/entry/entry_64.S:250)
> kern :warn : [ 119.097786] </TASK>

Thanks for reporting.
I need to execute percpu_ref_switch_to_atomic_sync() when RCU is unlocked.
I will fix this problem and submit v2.

Thanks,
Keisuke