From: Boqun Feng <boqun@kernel.org>
To: bot+bpf-ci@kernel.org
Cc: peterz@infradead.org, catalin.marinas@arm.com, will@kernel.org,
jonas@southpole.se, stefan.kristiansson@saunalahti.fi,
shorne@gmail.com, hca@linux.ibm.com, gor@linux.ibm.com,
agordeev@linux.ibm.com, borntraeger@linux.ibm.com,
svens@linux.ibm.com, tglx@kernel.org, mingo@redhat.com,
bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org,
hpa@zytor.com, arnd@arndb.de, juri.lelli@redhat.com,
vincent.guittot@linaro.org, dietmar.eggemann@arm.com,
rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de,
vschneid@redhat.com, kprateek.nayak@amd.com, longman@redhat.com,
akpm@linux-foundation.org, andrii@kernel.org, eddyz87@gmail.com,
ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev,
memxor@gmail.com, song@kernel.org, yonghong.song@linux.dev,
jolsa@kernel.org, shuah@kernel.org, ojeda@kernel.org,
gary@garyguo.net, bjorn3_gh@protonmail.com, lossin@kernel.org,
a.hindborg@kernel.org, aliceryhl@google.com, tmgross@umich.edu,
dakr@kernel.org, ruanjinjie@huawei.com, lyude@redhat.com,
thuth@redhat.com, sohil.mehta@intel.com,
pawan.kumar.gupta@linux.intel.com, seanjc@google.com,
nikunj@amd.com, xin@zytor.com, joelagnelf@nvidia.com,
andriy.shevchenko@linux.intel.com, rdunlap@infradead.org,
ynorov@nvidia.com, bigeasy@linutronix.de,
linux-kernel@vger.kernel.org, linux-openrisc@vger.kernel.org,
linux-s390@vger.kernel.org, linux-arch@vger.kernel.org,
bpf@vger.kernel.org, linux-kselftest@vger.kernel.org,
rust-for-linux@vger.kernel.org, boqun.feng@gmail.com,
martin.lau@kernel.org, clm@meta.com, ihor.solodrai@linux.dev
Subject: Re: [PATCH v3 05/13] irq & spin_lock: Add counted interrupt disabling/enabling
Date: Thu, 4 Jun 2026 23:40:00 -0700 [thread overview]
Message-ID: <aiJvQIiDiXvu5x01@tardis-2.local> (raw)
In-Reply-To: <cc4b5fb3f63b8b508334edd883765bf81c9ab1d2045f414a74c8712c6cc705e9@mail.kernel.org>
On Fri, Jun 05, 2026 at 06:30:16AM +0000, bot+bpf-ci@kernel.org wrote:
> > diff --git a/include/linux/interrupt_rc.h b/include/linux/interrupt_rc.h
> > new file mode 100644
> > index 000000000000..dd4444c61330
> > --- /dev/null
> > +++ b/include/linux/interrupt_rc.h
> > @@ -0,0 +1,67 @@
> > +/* SPDX-License-Identifier: GPL-2.0 */
> > +/*
> > + * include/linux/interrupt_rc.h - refcounted local processor interrupt
> > + * management.
> > + *
> > + * Since the implementation of this API currently depends on
> > + * local_irq_save()/local_irq_restore(), we split this into it's own header to
> > + * make it easier to include without hitting circular header dependencies.
> > + */
> > +
> > +#ifndef __LINUX_INTERRUPT_RC_H
> > +#define __LINUX_INTERRUPT_RC_H
> > +
> > +#include <linux/irqflags.h>
> > +#include <asm/processor.h>
> > +#ifdef CONFIG_SMP
> > +#include <asm/smp.h>
> > +#endif
> > +
> > +/* Per-cpu interrupt disabling state for local_interrupt_{disable,enable}() */
> > +struct interrupt_disable_state {
> > + unsigned long flags;
> > +};
> > +
> > +DECLARE_PER_CPU(struct interrupt_disable_state, local_interrupt_disable_state);
> > +
> > +static inline void local_interrupt_disable(void)
> > +{
> > + unsigned long flags;
> > + int new_count;
> > +
> > + WARN_ON_ONCE(in_nmi());
> > +
> > + 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_irq_save(flags);
> > + raw_cpu_write(local_interrupt_disable_state.flags, flags);
> > + }
> > +}
> > +
> > +static inline void local_interrupt_enable(void)
> > +{
> > + int new_count;
> > +
> > + new_count = hardirq_disable_exit();
> > +
> > + if ((new_count & HARDIRQ_DISABLE_MASK) == 0) {
> > + unsigned long flags;
> > +
> > + flags = raw_cpu_read(local_interrupt_disable_state.flags);
> > + local_irq_restore(flags);
>
> Could this lead to indefinite softirq starvation? When __irq_exit_rcu()
Yes and no. There is no behavioral difference between here and
local_irq_enable(), neither will trigger softirqs.
> skips invoke_softirq() due to hardirq_disable_count() > 0, any scheduled
> softirqs (timers, RCU callbacks, networking) remain pending. When the
> outermost critical section ends and local_interrupt_enable() restores
> hardware interrupts, it doesn't check local_softirq_pending() to flush
> these deferred softirqs.
>
> Will these pending softirqs stall until another unrelated hardware
> interrupt fires? In low-activity periods, this could potentially cause
> RCU stalls or network hangs. This concern was raised by the sashiko bot in
> both v2 and v3 but remains unaddressed:
>
> https://lore.kernel.org/all/20260526175409.7CFCC1F000E9@smtp.kernel.org/
>
> > + /*
> > + * TODO: re-read preempt count can be avoided, but it needs
> > + * should_resched() taking another parameter as the current
> > + * preempt count
> > + */
> > +#ifdef CONFIG_PREEMPTION
> > + if (should_resched(0))
> > + __preempt_schedule();
>
> Peter Zijlstra suggested in v2 replacing should_resched(0) with a direct
> check of new_count for preemption. His suggestion was "can't you simply
> write: if (!new_count) __preempt_schedule();" The author acknowledged this
> in discussion but hasn't implemented it in v3:
>
> https://lore.kernel.org/all/20260528104322.GF343181@noisy.programming.kicks-ass.net/
>
> Is there a reason to keep the more complex should_resched(0) approach, or
> would the direct check be more appropriate here?
>
I have an optimization/cleanup patch in patch #13.
Regards,
Boqun
> > +#endif
> > + }
> > +}
> > +
> > +#endif /* !__LINUX_INTERRUPT_RC_H */
>
> [ ... ]
>
> > diff --git a/kernel/softirq.c b/kernel/softirq.c
> > index 10af5ed859e7..d1ab1799794c 100644
> > --- a/kernel/softirq.c
> > +++ b/kernel/softirq.c
> > @@ -88,6 +88,9 @@ EXPORT_PER_CPU_SYMBOL_GPL(hardirqs_enabled);
> > EXPORT_PER_CPU_SYMBOL_GPL(hardirq_context);
> > #endif
> >
> > +DEFINE_PER_CPU(struct interrupt_disable_state, local_interrupt_disable_state);
> > +EXPORT_PER_CPU_SYMBOL_GPL(local_interrupt_disable_state);
> > +
> > DEFINE_PER_CPU(unsigned int, nmi_nesting);
> >
> > /*
> > @@ -728,7 +731,16 @@ static inline void __irq_exit_rcu(void)
> > #endif
> > account_hardirq_exit(current);
> > preempt_count_sub(HARDIRQ_OFFSET);
> > - if (!in_interrupt() && local_softirq_pending()) {
> > + /*
> > + * Interrupts may happen between hardirq_disable_enter() and
> > + * local_irq_save() in local_interrupt_disable(), if irq_exit() invokes
> > + * softirq here, we may have a softirq handler calling
> > + * local_interrupt_disable() but it won't disable the irq because
> > + * hardirq disabling count is already 1, hence we need to prevent
> > + * invoking softirq when a local_interrupt_disable() is ongoing.
> > + */
> > + if (!in_interrupt() && !hardirq_disable_count() &&
> > + local_softirq_pending()) {
> > /*
> > * If we left hrtimers unarmed, make sure to arm them now,
> > * before enabling interrupts to run SoftIRQ.
>
>
> ---
> AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
> See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
>
> CI run summary: https://github.com/kernel-patches/bpf/actions/runs/26998319662
next prev parent reply other threads:[~2026-06-05 6:40 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-05 5:41 [PATCH v3 00/13] Refcounted interrupt disable and SpinLockIrq for rust (Part 1) Boqun Feng
2026-06-05 5:41 ` [PATCH v3 01/13] preempt: Track NMI nesting to separate per-CPU counter Boqun Feng
2026-06-05 5:41 ` [PATCH v3 02/13] preempt: Introduce HARDIRQ_DISABLE_BITS Boqun Feng
2026-06-05 5:41 ` [PATCH v3 03/13] preempt: Introduce __preempt_count_{sub, add}_return() Boqun Feng
2026-06-05 6:30 ` bot+bpf-ci
2026-06-05 6:45 ` Boqun Feng
2026-06-05 5:41 ` [PATCH v3 04/13] openrisc: Include <linux/cpumask.h> in smp.h Boqun Feng
2026-06-05 5:41 ` [PATCH v3 05/13] irq & spin_lock: Add counted interrupt disabling/enabling Boqun Feng
2026-06-05 6:30 ` bot+bpf-ci
2026-06-05 6:40 ` Boqun Feng [this message]
2026-06-05 5:41 ` [PATCH v3 06/13] irq: Add KUnit test for refcounted interrupt enable/disable Boqun Feng
2026-06-05 5:41 ` [PATCH v3 07/13] locking: Switch to _irq_{disable,enable}() variants in cleanup guards Boqun Feng
2026-06-05 5:41 ` [PATCH v3 08/13] sched: Remove the unused preempt_offset parameter of __cant_sleep() Boqun Feng
2026-06-05 5:41 ` [PATCH v3 09/13] sched: Avoid signed comparison of preempt_count() in __cant_migrate() Boqun Feng
2026-06-05 5:41 ` [PATCH v3 10/13] preempt: Introduce HAS_SEPARATE_PREEMPT_RESCHED_BITS Boqun Feng
2026-06-05 6:30 ` bot+bpf-ci
2026-06-05 5:41 ` [PATCH v3 11/13] arm64: sched/preempt: Enable HAS_SEPARATE_PREEMPT_RESCHED_BITS Boqun Feng
2026-06-05 5:41 ` [PATCH v3 12/13] s390/preempt: " Boqun Feng
2026-06-05 5:41 ` [PATCH v3 13/13] irq: Optimize reschedule check in local_interrupt_enable() Boqun Feng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aiJvQIiDiXvu5x01@tardis-2.local \
--to=boqun@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=aliceryhl@google.com \
--cc=andrii@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=arnd@arndb.de \
--cc=ast@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=borntraeger@linux.ibm.com \
--cc=bot+bpf-ci@kernel.org \
--cc=bp@alien8.de \
--cc=bpf@vger.kernel.org \
--cc=bsegall@google.com \
--cc=catalin.marinas@arm.com \
--cc=clm@meta.com \
--cc=dakr@kernel.org \
--cc=daniel@iogearbox.net \
--cc=dave.hansen@linux.intel.com \
--cc=dietmar.eggemann@arm.com \
--cc=eddyz87@gmail.com \
--cc=gary@garyguo.net \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=hpa@zytor.com \
--cc=ihor.solodrai@linux.dev \
--cc=joelagnelf@nvidia.com \
--cc=jolsa@kernel.org \
--cc=jonas@southpole.se \
--cc=juri.lelli@redhat.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-openrisc@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=longman@redhat.com \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=martin.lau@kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=nikunj@amd.com \
--cc=ojeda@kernel.org \
--cc=pawan.kumar.gupta@linux.intel.com \
--cc=peterz@infradead.org \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=ruanjinjie@huawei.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=seanjc@google.com \
--cc=shorne@gmail.com \
--cc=shuah@kernel.org \
--cc=sohil.mehta@intel.com \
--cc=song@kernel.org \
--cc=stefan.kristiansson@saunalahti.fi \
--cc=svens@linux.ibm.com \
--cc=tglx@kernel.org \
--cc=thuth@redhat.com \
--cc=tmgross@umich.edu \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=will@kernel.org \
--cc=x86@kernel.org \
--cc=xin@zytor.com \
--cc=ynorov@nvidia.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox