summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorBoqun Feng <boqun@kernel.org>2026-08-29 14:34:12 -0700
committerThomas Gleixner <tglx@kernel.org>2026-08-30 08:39:04 +0200
commita155ac8f0c523bd53f412196dcbb104ad1f4595f (patch)
tree165adb6c3af60b5f4d4cf3e3f0fef25f6b942611 /include
parent46094a7708b7945cb7eba9eb887e3ea9757440a7 (diff)
downloadlinux-stable-a155ac8f0c523bd53f412196dcbb104ad1f4595f.tar.gz
linux-stable-a155ac8f0c523bd53f412196dcbb104ad1f4595f.zip
interrupt: Disable interrupt before modifying hardirq_disable counter
Currently a softirq may be pending longer then expected if the triggering interrupt happens in-between hardirq_disable_enter() and _local_interrupt_disable() in local_interrupt_disable(): local_interrupt_disable(): hardirq_disable_enter(); <interrupt> ... __irq_exit_rcu(): // false because hardirq_disable_count() is not 0 if (.. && !hardirq_disable_count() && ..) { invoke_softirq(); } _local_interrupt_disable(); , it'll defer the softirq to the next interrupt which can be forever. The order between hardirq_disable_enter() and _local_interrupt_disable() is to optimize re-disabling interrupts if they are already disabled, but as 1) local_interrupt_disable() is not widely used yet and 2) the proper way to achieve this optimization may need fixing up the counter at entry/exit time [1], so reverse the order for now to avoid the softirq pending issue. Because of this fix, the part of saving the current state is separated from irq disabling, and the logic of local_interrupt_disable() becomes: local_irq_save(flags); if (counter++ == 0) { this_cpu(local_interrupt_disable_state) = flags; } Therefore change the helper function _local_interrupt_disable() to _local_interrupt_save_state() which only saves the current irqflags (when interrupts get disabled the first time). Fixes: e901c1510e24 ("irq,spin_lock: Add counted interrupt disabling/enabling") Reported-by: Thomas Gleixner <tglx@kernel.org> Signed-off-by: Boqun Feng <boqun@kernel.org> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Reviewed-by: Bradley Morgan <brads@mainlining.org> Link: https://patch.msgid.link/20260829213412.14303-1-boqun@kernel.org Link: https://lore.kernel.org/lkml/87v78wezid.ffs@fw13/ [1] Closes: https://lore.kernel.org/lkml/87jypbfu1t.ffs@fw13/
Diffstat (limited to 'include')
-rw-r--r--include/linux/interrupt_rc.h19
1 files changed, 8 insertions, 11 deletions
diff --git a/include/linux/interrupt_rc.h b/include/linux/interrupt_rc.h
index b9a7f05ec..e68e1bedb 100644
--- a/include/linux/interrupt_rc.h
+++ b/include/linux/interrupt_rc.h
@@ -20,11 +20,8 @@
/* Per-CPU interrupt disabling state for local_interrupt_{disable,enable}(). */
DECLARE_PER_CPU(unsigned long, local_interrupt_disable_state);
-static __always_inline void __local_interrupt_disable(void)
+static __always_inline void __local_interrupt_save_state(unsigned long flags)
{
- unsigned long flags;
-
- local_irq_save(flags);
raw_cpu_write(local_interrupt_disable_state, flags);
}
@@ -36,9 +33,9 @@ static __always_inline void __local_interrupt_enable(void)
}
#ifndef INSTANTIATE_EXPORTED_INTERRUPT_DISABLE
-static __always_inline void _local_interrupt_disable(void)
+static __always_inline void _local_interrupt_save_state(unsigned long flags)
{
- __local_interrupt_disable();
+ __local_interrupt_save_state(flags);
}
static __always_inline void _local_interrupt_enable(void)
@@ -46,27 +43,27 @@ static __always_inline void _local_interrupt_enable(void)
__local_interrupt_enable();
}
#else
-extern void _local_interrupt_disable(void);
+extern void _local_interrupt_save_state(unsigned long flags);
extern void _local_interrupt_enable(void);
#endif
#else /* !MODULE */
-extern void _local_interrupt_disable(void);
+extern void _local_interrupt_save_state(unsigned long flags);
extern void _local_interrupt_enable(void);
#endif /* !MODULE */
static inline void local_interrupt_disable(void)
{
int new_count;
+ unsigned long flags;
WARN_ON_ONCE(in_nmi());
+ local_irq_save(flags);
new_count = hardirq_disable_enter();
- /* Interrupts can happen here, but it's OK, see __irq_exit_rcu(). */
-
if ((new_count & HARDIRQ_DISABLE_MASK) == HARDIRQ_DISABLE_OFFSET)
- _local_interrupt_disable();
+ _local_interrupt_save_state(flags);
}
static inline void local_interrupt_enable(void)