public inbox for linux-rt-devel@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] softirq: WARN_ON !preemptible() not check softirq cnt in bh disable on RT
@ 2026-03-10 11:55 Xin Zhao
  2026-03-11  9:33 ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 10+ messages in thread
From: Xin Zhao @ 2026-03-10 11:55 UTC (permalink / raw)
  To: peterz, mingo, will, boqun, longman, bigeasy, clrkwllms, rostedt,
	kuba
  Cc: linux-kernel, linux-rt-devel, Xin Zhao

In RT-Linux, when enabling CONFIG_PREEMPT_RT_NEEDS_BH_LOCK, calling
__local_bh_disable_ip() when !preemptible() is illegal because it uses
local_lock, which might sleep. The only exception is during the
cgroup_init() logic in start_kernel() while preemption is disabled,
cgroup_init() calls cgroup_idr_alloc(), which calls spin_lock_bh().
It is sufficient to only exclude the system startup phase in macro
DEBUG_LOCKS_WARN_ON.

Although the original check of this_cpu_read(softirq_ctrl.cnt) can also
prevent the WARN_ON print during the boot process, it may hide some issues
that should be exposed immediately. Because softirq_ctrl.cnt maybe 0 when
__local_bh_disabled_ip() is called in !preemptible() context.

In RT-Linux, __local_bh_disable_ip() will be used by numerous _bh variants
locks and local_bh_disable(). Since locks call __might_resched() check, we
analyze the scenario of using local_bh_disable() in !preemptible() context.

If CONFIG_PREEMPT_RT_NEEDS_BH_LOCK is not enabled, __local_bh_disable_ip()
does not enter the local_lock lock and thus using local_bh_disable() in
!preemptible() context does not lead to might sleep problem, but using
local_bh_disable() in !preemptible() state is not meaningful in RT-Linux.

In non RT-Linux, we use local_irq_save() followed by local_bh_disable() to
keep soft interrupts disabled after restoring interrupts. However, in
RT-Linux, when CONFIG_PREEMPT_RT_NEEDS_BH_LOCK is not enabled,
local_bh_disable() merely increments the softirq_ctrl.cnt counter without
actually disabling the soft interrupt behavior, because other tasks on the
CPU can preempt the task that wants to disable soft interrupts and execute
soft interrupt-related logic.
Consider the sequence diagram below:
Task A                        Task B
                              __local_bh_enable_ip()
                                __do_softirq()
                                  handle_softirqs()
                                    ...
                                    local_irq_enable();
                                    ...
local_irq_save()
local_bh_disable()
local_irq_restore()
                                    h->action(); -- it is serving softirq
local_bh_enable()

Signed-off-by: Xin Zhao <jackzxcui1989@163.com>
---
 kernel/softirq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/softirq.c b/kernel/softirq.c
index 77198911b..320a52583 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -173,7 +173,7 @@ void __local_bh_disable_ip(unsigned long ip, unsigned int cnt)
 			/* Required to meet the RCU bottomhalf requirements. */
 			rcu_read_lock();
 		} else {
-			DEBUG_LOCKS_WARN_ON(this_cpu_read(softirq_ctrl.cnt));
+			DEBUG_LOCKS_WARN_ON(system_state != SYSTEM_BOOTING);
 		}
 	}
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-03-13  8:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-10 11:55 [PATCH] softirq: WARN_ON !preemptible() not check softirq cnt in bh disable on RT Xin Zhao
2026-03-11  9:33 ` Sebastian Andrzej Siewior
2026-03-11 10:40   ` Xin Zhao
2026-03-11 14:51     ` Sebastian Andrzej Siewior
2026-03-11 15:34       ` Xin Zhao
2026-03-11 16:09         ` Sebastian Andrzej Siewior
2026-03-11 17:01           ` Xin Zhao
2026-03-12 10:05             ` Sebastian Andrzej Siewior
2026-03-12 12:47               ` Xin Zhao
2026-03-13  8:14                 ` Sebastian Andrzej Siewior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox