From: Frederic Weisbecker <frederic@kernel.org>
To: Karl Mehltretter <kmehltretter@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@kernel.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
Clark Williams <clrkwllms@kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Boqun Feng <boqun@kernel.org>, Lyude Paul <lyude@redhat.com>,
Joel Fernandes <joelagnelf@nvidia.com>,
Alexander Potapenko <glider@google.com>,
Marco Elver <elver@google.com>, Jonathan Corbet <corbet@lwn.net>,
Bradley Morgan <brads@mainlining.org>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-rt-devel@lists.linux.dev
Subject: Re: [PATCH v5] softirq: Preserve interrupt context during IRQ exit
Date: Tue, 6 Oct 2026 12:00:51 +0200 [thread overview]
Message-ID: <asTG09Me93-zP3aG@localhost.localdomain> (raw)
In-Reply-To: <20260930191432.62760-1-kmehltretter@gmail.com>
Hi Karl,
Le Wed, Sep 30, 2026 at 09:14:32PM +0200, Karl Mehltretter a écrit :
> +static inline bool softirq_handle_begin(void)
> {
> - __local_bh_disable_ip(_RET_IP_, SOFTIRQ_OFFSET);
> + bool from_irq_exit = in_hardirq();
> +
> + if (!from_irq_exit) {
Is this variable necessary?
> + __local_bh_disable_ip(_RET_IP_, SOFTIRQ_OFFSET);
> + return false;
> + }
> +
> + /*
> + * Only reached from irq_exit(), with HARDIRQ_OFFSET still set.
> + * Replace it with SOFTIRQ_OFFSET before handle_softirqs() enables
> + * interrupts. Use the raw operation to preserve the preemption
> + * disable location recorded by irq_enter_rcu(), and update lockdep
> + * directly.
> + */
> + __preempt_count_sub(HARDIRQ_OFFSET - SOFTIRQ_OFFSET);
> + lockdep_softirqs_off(_RET_IP_);
> + WARN_ON_ONCE(irq_count() != SOFTIRQ_OFFSET);
> +
> + return true;
> }
>
> -static inline void softirq_handle_end(void)
> +static inline void softirq_handle_end(bool from_irq_exit)
> {
> - __local_bh_enable(SOFTIRQ_OFFSET);
> - WARN_ON_ONCE(in_interrupt());
> + if (!from_irq_exit) {
> + __local_bh_enable(SOFTIRQ_OFFSET);
> + WARN_ON_ONCE(in_interrupt());
> + return;
> + }
> +
> + lockdep_softirqs_on(_RET_IP_);
> + __preempt_count_add(HARDIRQ_OFFSET - SOFTIRQ_OFFSET);
> + WARN_ON_ONCE(irq_count() != HARDIRQ_OFFSET);
> }
>
> static inline void ksoftirqd_run_begin(void)
> @@ -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)
NMIs shouldn't ever take this path, right?
> wake_timersd();
>
> + /*
> + * tick_irq_exit() relies on in_hardirq() being false for the
> + * outermost interrupt.
> + */
> + preempt_count_sub(HARDIRQ_OFFSET);
> tick_irq_exit();
Can we also extend the HARDIRQ_OFFSET context coverage to tick_irq_exit() ?
From a quick look I haven't found anything that would prevent from that. You just need
to turn the "if (!in_hardirq())" test to "if hardirq_count()) == HARDIRQ_OFFSET"
Thanks.
--
Frederic Weisbecker
SUSE Labs
prev parent reply other threads:[~2026-10-06 10:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-30 19:14 Karl Mehltretter
2026-10-01 7:39 ` Sebastian Andrzej Siewior
2026-10-03 0:50 ` Joel Fernandes
2026-10-06 10:00 ` Frederic Weisbecker [this message]
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=asTG09Me93-zP3aG@localhost.localdomain \
--to=frederic@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=boqun@kernel.org \
--cc=brads@mainlining.org \
--cc=clrkwllms@kernel.org \
--cc=corbet@lwn.net \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=joelagnelf@nvidia.com \
--cc=kmehltretter@gmail.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=lyude@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@kernel.org \
/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
all inboxes | Powered by JetHome®