From: Boqun Feng <boqun@kernel.org>
To: Peter Zijlstra <peterz@infradead.org>
Cc: "Ingo Molnar" <mingo@kernel.org>, "Will Deacon" <will@kernel.org>,
"Boqun Feng" <boqun@kernel.org>,
"Waiman Long" <longman@redhat.com>, "Gary Guo" <gary@garyguo.net>,
"Alice Ryhl" <aliceryhl@google.com>,
"Lyude Paul" <lyude@redhat.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Onur Özkan" <work@onurozkan.dev>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Danilo Krummrich" <dakr@kernel.org>,
"Thomas Gleixner" <tglx@kernel.org>,
linux-kernel@vger.kernel.org, rust-for-linux@vger.kernel.org,
"Shrikanth Hegde" <sshegde@linux.ibm.com>
Subject: [PATCH v2 2/5] irq: Add {over,under}flow detection for local_interrupt_{enable,disable}
Date: Thu, 1 Oct 2026 10:25:16 +0200 [thread overview]
Message-ID: <20261001082519.16195-3-boqun@kernel.org> (raw)
In-Reply-To: <20261001082519.16195-1-boqun@kernel.org>
Currently there is no way to detect overflow and underflow inside the
HARDIRQ_DISABLE_MASK part of preempt_count. Add these detection guarded
by DEBUG_PREEMPT similar to the detection for PREEMPT_MASK
{over,under}flow.
Suggested-by: Shrikanth Hegde <sshegde@linux.ibm.com>
Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com>
Signed-off-by: Boqun Feng <boqun@kernel.org>
---
include/linux/interrupt_rc.h | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/include/linux/interrupt_rc.h b/include/linux/interrupt_rc.h
index a9ed937a80e7..d385ab05a2b6 100644
--- a/include/linux/interrupt_rc.h
+++ b/include/linux/interrupt_rc.h
@@ -11,6 +11,7 @@
* make it easier to include without hitting circular header dependencies.
*/
+#include <linux/debug_locks.h>
#include <linux/irqflags.h>
#include <linux/preempt.h>
#include <linux/processor.h>
@@ -65,6 +66,13 @@ static inline void local_interrupt_disable(void)
local_irq_save(flags);
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))
+ return;
+
if ((new_count & HARDIRQ_DISABLE_MASK) == HARDIRQ_DISABLE_OFFSET)
_local_interrupt_save_state(flags);
}
@@ -73,6 +81,11 @@ static inline void local_interrupt_enable(void)
{
int new_count;
+ /* Unpaired local_interrupt_enable()? Warn and abort. */
+ if (IS_ENABLED(CONFIG_DEBUG_PREEMPT) &&
+ DEBUG_LOCKS_WARN_ON((preempt_count() & HARDIRQ_DISABLE_MASK) == 0))
+ return;
+
new_count = hardirq_disable_exit();
if ((new_count & HARDIRQ_DISABLE_MASK) == 0)
--
2.51.0
next prev parent reply other threads:[~2026-10-01 8:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 8:25 [PATCH v2 0/5] Improvements and fixes on SpinLockIrq patch series Boqun Feng
2026-10-01 8:25 ` [PATCH v2 1/5] irq: Make refcount_interrupt kunit test selectable Boqun Feng
2026-10-01 8:25 ` Boqun Feng [this message]
2026-10-01 8:25 ` [PATCH v2 3/5] selftests/bpf: Use the new NMI_BITS definition Boqun Feng
2026-10-01 13:13 ` Boqun Feng
2026-10-01 8:25 ` [PATCH v2 4/5] irq: Explain better on NMI_MASK overflow condition Boqun Feng
2026-10-01 8:25 ` [PATCH v2 5/5] irq: Add max local_interrupt_disable() nesting level kunit test case 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=20261001082519.16195-3-boqun@kernel.org \
--to=boqun@kernel.org \
--cc=aliceryhl@google.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=gary@garyguo.net \
--cc=linux-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=lyude@redhat.com \
--cc=mingo@kernel.org \
--cc=ojeda@kernel.org \
--cc=peterz@infradead.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sshegde@linux.ibm.com \
--cc=tglx@kernel.org \
--cc=will@kernel.org \
--cc=work@onurozkan.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
all inboxes | Powered by JetHome®