mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] softirq: Limit the BH count warning to RT BH lock users
@ 2026-11-23 17:42 Yiyang Chen
  0 siblings, 0 replies; only message in thread
From: Yiyang Chen @ 2026-11-23 17:42 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: Clark Williams, Steven Rostedt, Thomas Gleixner, Xin Zhao,
	linux-rt-devel, linux-kernel, Yiyang Chen

__local_bh_disable_ip() warns if a non-preemptible task first disables
BHs while the per-CPU BH count is nonzero. Without the RT BH lock,
this check can turn off lock debugging on a valid call sequence.

With CONFIG_PREEMPT_RT_NEEDS_BH_LOCK=n, task A calls local_bh_disable()
from preemptible context. Task B preempts A on the same CPU, disables
preemption, and then calls local_bh_disable(). B therefore reaches the
warning while the per-CPU count still includes A's BH-disabled section.

  Task A          Task B
  ------          ------
  local_bh_disable()
    softirq_ctrl.cnt += SOFTIRQ_DISABLE_OFFSET
    current->softirq_disable_cnt += SOFTIRQ_DISABLE_OFFSET
  <preempted by B>
                  preempt_disable()
                  local_bh_disable()
                    B's softirq_disable_cnt is zero
                    preemptible() is false
                    WARN on nonzero softirq_ctrl.cnt
                    softirq_ctrl.cnt += SOFTIRQ_DISABLE_OFFSET
                    current->softirq_disable_cnt += SOFTIRQ_DISABLE_OFFSET
                  local_bh_enable()
                  preempt_enable()
  <resumes>
  local_bh_enable()

The warning relies on the per-CPU BH lock serializing BH-disabled
sections on the same CPU. With CONFIG_PREEMPT_RT_NEEDS_BH_LOCK=y, A
still holds that lock when B runs. Since B is non-preemptible, it skips
the lock acquisition. The nonzero count then exposes B entering the
section while A holds the lock.

With CONFIG_PREEMPT_RT_NEEDS_BH_LOCK=n, there is no BH lock for B to
bypass. The same nonzero count simply records A's active BH-disabled
section, which may legitimately overlap B's.

Guard the warning with CONFIG_PREEMPT_RT_NEEDS_BH_LOCK for as long as
the lock is optional. If the lock is removed, as discussed earlier,
the check can go away with it.

Fixes: 3253cb49cbad ("softirq: Allow to drop the softirq-BKL lock on PREEMPT_RT")
Link: https://lore.kernel.org/lkml/20260310115534.3477871-1-jackzxcui1989@163.com
Signed-off-by: Yiyang Chen <cyyzero16@gmail.com>
---
Changes in v2:
- Clarify the description of the timing diagram.
- Add the Fixes tag.

v1: https://lore.kernel.org/r/d9554bee441d2c763ef8d61e966a7a471915bbee.1795372382.git.cyyzero16@gmail.com

 kernel/softirq.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/softirq.c b/kernel/softirq.c
index 7fc2200392cd..f64f6b594951 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -195,7 +195,7 @@ void __local_bh_disable_ip(unsigned long ip, unsigned int cnt)
 
 			/* Required to meet the RCU bottomhalf requirements. */
 			rcu_read_lock();
-		} else {
+		} else if (IS_ENABLED(CONFIG_PREEMPT_RT_NEEDS_BH_LOCK)) {
 			DEBUG_LOCKS_WARN_ON(this_cpu_read(softirq_ctrl.cnt));
 		}
 	}
-- 
2.43.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-23 17:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 17:42 [PATCH v2] softirq: Limit the BH count warning to RT BH lock users Yiyang Chen

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

all inboxes | Powered by JetHome®