Re: [PATCH v4] softirq: Preserve interrupt context during IRQ exit

From: Sebastian Andrzej Siewior

Date: Mon Sep 28 2026 - 04:29:51 EST


On 2026-09-26 16:35:05 [+0200], Karl Mehltretter wrote:
> On the return from interrupt path, __irq_exit_rcu() removes
> HARDIRQ_OFFSET from the preemption counter at the very top of the
…
> Suggested-by: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Link: https://lore.kernel.org/r/20260813130826.GW687043@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Assisted-by: LLM
> Signed-off-by: Karl Mehltretter <kmehltretter@xxxxxxxxx>
> Reviewed-by: Bradley Morgan <brads@xxxxxxxxxxxxxx>
> ---

Reviewed-by: Sebastian Andrzej Siewior <bigeasy@xxxxxxxxxxxxx>

but…
> --- a/kernel/softirq.c
> +++ b/kernel/softirq.c
> @@ -758,10 +788,21 @@ static inline void __irq_exit_rcu(void)
> invoke_softirq();
> }
>
> + /*
> + * Wake the timer thread even if the interrupt hit a softirq or a
> + * section with BHs disabled. Only nested interrupts and NMIs are
> + * excluded.
> + */
> if (IS_ENABLED(CONFIG_IRQ_FORCED_THREADING) && force_irqthreads() &&
> - local_timers_pending_force_th() && !(in_nmi() | in_hardirq()))
> + local_timers_pending_force_th() &&
> + !in_nmi() && hardirq_count() == HARDIRQ_OFFSET)

could you please do
(in_nmi() | hardirq_count()) == HARDIRQ_OFFSET)
instead? This will merge NMI check into the hardirq check, dropping one
conditional jump away.

> wake_timersd();
>
> + /*
> + * tick_irq_exit() relies on in_hardirq() being false for the
> + * outermost interrupt.
> + */
> + preempt_count_sub(HARDIRQ_OFFSET);
> tick_irq_exit();
> }

Sebastian