Re: [PATCH v4 05/17] irq & spin_lock: Add counted interrupt disabling/enabling

From: Shrikanth Hegde

Date: Wed Aug 05 2026 - 10:10:58 EST



Hi Boqun,


Something as below? Going to send it to kernel build bot and see if it
works for all configs.

----------------->8
diff --git a/include/linux/interrupt_rc.h b/include/linux/interrupt_rc.h
index b9a7f05ecf42..39f30bc65548 100644
--- a/include/linux/interrupt_rc.h
+++ b/include/linux/interrupt_rc.h
@@ -12,6 +12,7 @@
*/

#include <linux/irqflags.h>
+#include <linux/debug_locks.h>
#include <linux/preempt.h>
#include <linux/processor.h>
#include <linux/smp.h>
@@ -63,6 +64,12 @@ static inline void local_interrupt_disable(void)

new_count = hardirq_disable_enter();

+ /* Is hardirq disable count overflow soon? */
+ if (IS_ENABLED(CONFIG_DEBUG_PREEMPT))
+ DEBUG_LOCKS_WARN_ON((new_count & HARDIRQ_DISABLE_MASK) +
+ (10 << HARDIRQ_DISABLE_SHIFT) >
+ HARDIRQ_DISABLE_MASK);
+

This needs a return here right? Else we will see warning for 10 times
and then overflow happens and we will call _local_interrupt_disable. No?

Not sure, if below is any better? (Igore whitespace mangling)

if (IS_ENABLED(CONFIG_DEBUG_PREEMPT) &&
DEBUG_LOCKS_WARN_ON((preempt_count() & HARDIRQ_DISABLE_MASK) >=
HARDIRQ_DISABLE_MASK - (10 << HARDIRQ_DISABLE_SHIFT)))
return;

/* Interrupts can happen here, but it's OK, see __irq_exit_rcu(). */

if ((new_count & HARDIRQ_DISABLE_MASK) == HARDIRQ_DISABLE_OFFSET)
@@ -73,6 +80,11 @@ static inline void local_interrupt_enable(void)
{
int new_count;

+ /* Unpaired local_interrupt_enable()? Warn and abort. */
+ if (IS_ENABLED(CONFIG_DEBUG_PREEMPT) &&
+ DEBUG_LOCKS_WARN_ON((preempt_count() & HARDIRQ_DISABLE_MASK) == 0))
+ return;
+
new_count = hardirq_disable_exit();

if ((new_count & HARDIRQ_DISABLE_MASK) == 0) >