Re: [PATCH v4 05/17] irq & spin_lock: Add counted interrupt disabling/enabling
From: Boqun Feng
Date: Wed Aug 05 2026 - 14:07:51 EST
On Wed, Aug 05, 2026 at 08:26:49PM +0530, Shrikanth Hegde wrote:
>
>
> On 8/5/26 7:50 PM, Boqun Feng wrote:
> > On Wed, Aug 05, 2026 at 07:40:18PM +0530, Shrikanth Hegde wrote:
> > >
> > > 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?
> > >
> >
> > DEBUG_LOCKS_WARN_ON() uses debug_locks_off() to avoid this, so we won't
> > see it 10 times. The reason not using return here, because we would
> > introduce unpaired local_interrupt_disable() if we returned:
>
> Yes, it could be a weird case if the overflow actually happens.
> So just warning maybe enough to catch such callers.
>
> Maybe your kunit test can actually help test the behavior with the loop
> count.
>
I'm sure that we can have more tests, but this is a good start, thank
you!
Regards,
Boqun
------------->8
Subject: [PATCH] irq: Add max local_interrupt_disable() nesting level kunit
test case
To confirm the max nesting level of local_interrupt_disable() works, a
kunit test is added to the whole test suite.
Note that when DEBUG_PREEMPT=y, it'll generate a warning which is
expected.
Suggested-by: Shrikanth Hegde <sshegde@xxxxxxxxxxxxx>
Signed-off-by: Boqun Feng <boqun@xxxxxxxxxx>
---
kernel/irq/refcount_interrupt_test.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/kernel/irq/refcount_interrupt_test.c b/kernel/irq/refcount_interrupt_test.c
index ca904dba24b9..38dfccbaa4d4 100644
--- a/kernel/irq/refcount_interrupt_test.c
+++ b/kernel/irq/refcount_interrupt_test.c
@@ -52,6 +52,27 @@ static void test_multiple_irq_change(struct kunit *test)
TEST_IRQ_ON();
}
+static void test_max_nesting_irq_change(struct kunit *test)
+{
+ for (int i = 0; i < __IRQ_MASK(HARDIRQ_DISABLE_BITS); i++) {
+ local_interrupt_disable();
+ TEST_IRQ_OFF();
+ }
+
+
+ for (int i = 0; i < __IRQ_MASK(HARDIRQ_DISABLE_BITS); i++) {
+ TEST_IRQ_OFF();
+ local_interrupt_enable();
+ }
+
+ TEST_IRQ_ON();
+
+ local_interrupt_disable();
+ TEST_IRQ_OFF();
+ local_interrupt_enable();
+ TEST_IRQ_ON();
+}
+
static void test_irq_save(struct kunit *test)
{
unsigned long flags;
@@ -79,6 +100,7 @@ static struct kunit_case test_cases[] = {
KUNIT_CASE(test_single_irq_change),
KUNIT_CASE(test_nested_irq_change),
KUNIT_CASE(test_multiple_irq_change),
+ KUNIT_CASE(test_max_nesting_irq_change),
KUNIT_CASE(test_irq_save),
{},
};
--
2.50.1 (Apple Git-155)