* [PATCH v2 0/5] Improvements and fixes on SpinLockIrq patch series
@ 2026-10-01 8:25 Boqun Feng
2026-10-01 8:25 ` [PATCH v2 1/5] irq: Make refcount_interrupt kunit test selectable Boqun Feng
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Boqun Feng @ 2026-10-01 8:25 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, Gary Guo,
Alice Ryhl, Lyude Paul, Daniel Almeida, Onur Özkan,
Miguel Ojeda, Danilo Krummrich, Thomas Gleixner, linux-kernel,
rust-for-linux
Hi Peter,
I realized that v1 [1] was left on the list so I just want to respin it.
Just to refresh the memory, v1 was requested [2] as separate patches for
changes between v4 and v5 in the main series. I also include the
refcount_interrupt kunit test Kconfig change in this version as well.
Based on v7.3-rc5.
Please take a look. Thanks!
[1]: https://lore.kernel.org/rust-for-linux/20260811041714.27679-1-boqun@kernel.org/
[2]: https://lore.kernel.org/rust-for-linux/20260810085255.GE1642880@noisy.programming.kicks-ass.net/
Regards,
Boqun
Boqun Feng (4):
irq: Add {over,under}flow detection for
local_interrupt_{enable,disable}
selftests/bpf: Use the new NMI_BITS definition
irq: Explain better on NMI_MASK overflow condition
irq: Add max local_interrupt_disable() nesting level kunit test case
Kuan-Wei Chiu (1):
irq: Make refcount_interrupt kunit test selectable
include/linux/hardirq.h | 2 +-
include/linux/interrupt_rc.h | 13 +++++++++++
kernel/irq/Kconfig | 12 ++++++++++
kernel/irq/Makefile | 2 +-
kernel/irq/refcount_interrupt_test.c | 22 +++++++++++++++++++
.../testing/selftests/bpf/bpf_experimental.h | 2 +-
6 files changed, 50 insertions(+), 3 deletions(-)
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 1/5] irq: Make refcount_interrupt kunit test selectable
2026-10-01 8:25 [PATCH v2 0/5] Improvements and fixes on SpinLockIrq patch series Boqun Feng
@ 2026-10-01 8:25 ` Boqun Feng
2026-10-01 8:25 ` [PATCH v2 2/5] irq: Add {over,under}flow detection for local_interrupt_{enable,disable} Boqun Feng
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Boqun Feng @ 2026-10-01 8:25 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, Gary Guo,
Alice Ryhl, Lyude Paul, Daniel Almeida, Onur Özkan,
Miguel Ojeda, Danilo Krummrich, Thomas Gleixner, linux-kernel,
rust-for-linux, Kuan-Wei Chiu, Radu Rendec
From: Kuan-Wei Chiu <visitorckw@gmail.com>
Currently, refcount_interrupt_test is built unconditionally when
CONFIG_KUNIT is enabled, causing it to run unexpectedly during boot.
Fix this by introducing CONFIG_REFCOUNT_INTERRUPT_KUNIT_TEST so the
test can be configured independently, following standard kunit
practices.
Fixes: 07a88e2bcd5b ("irq: Add KUnit test for refcounted interrupt enable/disable")
Signed-off-by: Kuan-Wei Chiu <visitorckw@gmail.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Reviewed-by: Radu Rendec <radu@rendec.net>
Reviewed-by: Boqun Feng <boqun@kernel.org>
---
kernel/irq/Kconfig | 12 ++++++++++++
kernel/irq/Makefile | 2 +-
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/kernel/irq/Kconfig b/kernel/irq/Kconfig
index 05cba4e16dad..6923f37eaab4 100644
--- a/kernel/irq/Kconfig
+++ b/kernel/irq/Kconfig
@@ -150,6 +150,18 @@ config IRQ_KUNIT_TEST
If unsure, say N.
+config REFCOUNT_INTERRUPT_KUNIT_TEST
+ tristate "Test refcounted interrupt enable/disable" if !KUNIT_ALL_TESTS
+ depends on KUNIT
+ default KUNIT_ALL_TESTS
+ help
+ This builds the kunit tests for the refcounted interrupt
+ infrastructure. It verifies the correctness of single, nested,
+ and multiple interrupt enable/disable state changes and ensures
+ that the underlying reference counting mechanisms work as expected.
+
+ If unsure, say N.
+
endmenu
config GENERIC_IRQ_MULTI_HANDLER
diff --git a/kernel/irq/Makefile b/kernel/irq/Makefile
index 44c4d6fc502a..0e5df962a149 100644
--- a/kernel/irq/Makefile
+++ b/kernel/irq/Makefile
@@ -16,4 +16,4 @@ obj-$(CONFIG_SMP) += affinity.o
obj-$(CONFIG_GENERIC_IRQ_DEBUGFS) += debugfs.o
obj-$(CONFIG_GENERIC_IRQ_MATRIX_ALLOCATOR) += matrix.o
obj-$(CONFIG_IRQ_KUNIT_TEST) += irq_test.o
-obj-$(CONFIG_KUNIT) += refcount_interrupt_test.o
+obj-$(CONFIG_REFCOUNT_INTERRUPT_KUNIT_TEST) += refcount_interrupt_test.o
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 2/5] irq: Add {over,under}flow detection for local_interrupt_{enable,disable}
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
2026-10-01 8:25 ` [PATCH v2 3/5] selftests/bpf: Use the new NMI_BITS definition Boqun Feng
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Boqun Feng @ 2026-10-01 8:25 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, Gary Guo,
Alice Ryhl, Lyude Paul, Daniel Almeida, Onur Özkan,
Miguel Ojeda, Danilo Krummrich, Thomas Gleixner, linux-kernel,
rust-for-linux, Shrikanth Hegde
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 3/5] selftests/bpf: Use the new NMI_BITS definition
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 ` [PATCH v2 2/5] irq: Add {over,under}flow detection for local_interrupt_{enable,disable} Boqun Feng
@ 2026-10-01 8:25 ` 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
4 siblings, 1 reply; 7+ messages in thread
From: Boqun Feng @ 2026-10-01 8:25 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, Gary Guo,
Alice Ryhl, Lyude Paul, Daniel Almeida, Onur Özkan,
Miguel Ojeda, Danilo Krummrich, Thomas Gleixner, linux-kernel,
rust-for-linux, Shrikanth Hegde
The definition of NMI_BITS was out of sync after the introduction of
HAS_SEPARATE_PREEMPT_RESCHED_BITS, hence adjust it.
Reported-by: Shrikanth Hegde <sshegde@linux.ibm.com>
Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com>
Signed-off-by: Boqun Feng <boqun@kernel.org>
---
tools/testing/selftests/bpf/bpf_experimental.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
index 2893bf06ff25..4bf7390994bf 100644
--- a/tools/testing/selftests/bpf/bpf_experimental.h
+++ b/tools/testing/selftests/bpf/bpf_experimental.h
@@ -371,7 +371,7 @@ extern int bpf_sock_read_xattr(struct socket *sock, const char *name__str,
#define SOFTIRQ_BITS 8
#define HARDIRQ_DISABLE_BITS 8
#define HARDIRQ_BITS 4
-#define NMI_BITS 1
+#define NMI_BITS (1 + 3*IS_ENABLED(CONFIG_HAS_SEPARATE_PREEMPT_RESCHED_BITS))
#define PREEMPT_SHIFT 0
#define SOFTIRQ_SHIFT (PREEMPT_SHIFT + PREEMPT_BITS)
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 4/5] irq: Explain better on NMI_MASK overflow condition
2026-10-01 8:25 [PATCH v2 0/5] Improvements and fixes on SpinLockIrq patch series Boqun Feng
` (2 preceding siblings ...)
2026-10-01 8:25 ` [PATCH v2 3/5] selftests/bpf: Use the new NMI_BITS definition Boqun Feng
@ 2026-10-01 8:25 ` Boqun Feng
2026-10-01 8:25 ` [PATCH v2 5/5] irq: Add max local_interrupt_disable() nesting level kunit test case Boqun Feng
4 siblings, 0 replies; 7+ messages in thread
From: Boqun Feng @ 2026-10-01 8:25 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, Gary Guo,
Alice Ryhl, Lyude Paul, Daniel Almeida, Onur Özkan,
Miguel Ojeda, Danilo Krummrich, Thomas Gleixner, linux-kernel,
rust-for-linux, Shrikanth Hegde
Currently __preempt_count_nmi_enter() uses 15 as the maximum NMI nesting
level, and it's because 4 bits are used to represent the nesting level
of NMI. Replace the tautological comment with a more direct mention to
the 4 bits limitation to help readers understand this condition.
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/hardirq.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/hardirq.h b/include/linux/hardirq.h
index 73b48dd9f135..2648c49cd8f6 100644
--- a/include/linux/hardirq.h
+++ b/include/linux/hardirq.h
@@ -108,7 +108,7 @@ DECLARE_PER_CPU(unsigned int, nmi_nesting);
#define __preempt_count_nmi_enter() \
do { \
__preempt_count_add(HARDIRQ_OFFSET); \
- /* Maximum NMI nesting is 15. */ \
+ /* NMI nesting is represented in 4 bits. */ \
BUG_ON(__this_cpu_read(nmi_nesting) >= 15); \
__this_cpu_inc(nmi_nesting); \
preempt_count_set(preempt_count() | NMI_MASK); \
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 5/5] irq: Add max local_interrupt_disable() nesting level kunit test case
2026-10-01 8:25 [PATCH v2 0/5] Improvements and fixes on SpinLockIrq patch series Boqun Feng
` (3 preceding siblings ...)
2026-10-01 8:25 ` [PATCH v2 4/5] irq: Explain better on NMI_MASK overflow condition Boqun Feng
@ 2026-10-01 8:25 ` Boqun Feng
4 siblings, 0 replies; 7+ messages in thread
From: Boqun Feng @ 2026-10-01 8:25 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Boqun Feng, Waiman Long, Gary Guo,
Alice Ryhl, Lyude Paul, Daniel Almeida, Onur Özkan,
Miguel Ojeda, Danilo Krummrich, Thomas Gleixner, linux-kernel,
rust-for-linux, Shrikanth Hegde
To confirm the max nesting level of local_interrupt_disable() works, a
kunit test is added to the whole test suite.
Note that when DEBUG_PREEMPT=y, it'll generate a warning which is
expected.
Suggested-by: Shrikanth Hegde <sshegde@linux.ibm.com>
Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com>
Signed-off-by: Boqun Feng <boqun@kernel.org>
---
kernel/irq/refcount_interrupt_test.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/kernel/irq/refcount_interrupt_test.c b/kernel/irq/refcount_interrupt_test.c
index ca904dba24b9..38dfccbaa4d4 100644
--- a/kernel/irq/refcount_interrupt_test.c
+++ b/kernel/irq/refcount_interrupt_test.c
@@ -52,6 +52,27 @@ static void test_multiple_irq_change(struct kunit *test)
TEST_IRQ_ON();
}
+static void test_max_nesting_irq_change(struct kunit *test)
+{
+ for (int i = 0; i < __IRQ_MASK(HARDIRQ_DISABLE_BITS); i++) {
+ local_interrupt_disable();
+ TEST_IRQ_OFF();
+ }
+
+
+ for (int i = 0; i < __IRQ_MASK(HARDIRQ_DISABLE_BITS); i++) {
+ TEST_IRQ_OFF();
+ local_interrupt_enable();
+ }
+
+ TEST_IRQ_ON();
+
+ local_interrupt_disable();
+ TEST_IRQ_OFF();
+ local_interrupt_enable();
+ TEST_IRQ_ON();
+}
+
static void test_irq_save(struct kunit *test)
{
unsigned long flags;
@@ -79,6 +100,7 @@ static struct kunit_case test_cases[] = {
KUNIT_CASE(test_single_irq_change),
KUNIT_CASE(test_nested_irq_change),
KUNIT_CASE(test_multiple_irq_change),
+ KUNIT_CASE(test_max_nesting_irq_change),
KUNIT_CASE(test_irq_save),
{},
};
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 3/5] selftests/bpf: Use the new NMI_BITS definition
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
0 siblings, 0 replies; 7+ messages in thread
From: Boqun Feng @ 2026-10-01 13:13 UTC (permalink / raw)
To: Peter Zijlstra
Cc: Ingo Molnar, Will Deacon, Waiman Long, Gary Guo, Alice Ryhl,
Lyude Paul, Daniel Almeida, Onur Özkan, Miguel Ojeda,
Danilo Krummrich, Thomas Gleixner, linux-kernel, rust-for-linux,
Shrikanth Hegde, Leon Hwang, Alexei Starovoitov
On Thu, Oct 01, 2026 at 10:25:17AM +0200, Boqun Feng wrote:
> The definition of NMI_BITS was out of sync after the introduction of
> HAS_SEPARATE_PREEMPT_RESCHED_BITS, hence adjust it.
>
> Reported-by: Shrikanth Hegde <sshegde@linux.ibm.com>
> Reviewed-by: Shrikanth Hegde <sshegde@linux.ibm.com>
> Signed-off-by: Boqun Feng <boqun@kernel.org>
> ---
> tools/testing/selftests/bpf/bpf_experimental.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
> index 2893bf06ff25..4bf7390994bf 100644
> --- a/tools/testing/selftests/bpf/bpf_experimental.h
> +++ b/tools/testing/selftests/bpf/bpf_experimental.h
Per sashiko's report, seems I need the following to make it work:
diff --git a/tools/testing/selftests/bpf/bpf_experimental.h b/tools/testing/selftests/bpf/bpf_experimental.h
index 4bf7390994bf..94143cf0ab0d 100644
--- a/tools/testing/selftests/bpf/bpf_experimental.h
+++ b/tools/testing/selftests/bpf/bpf_experimental.h
@@ -367,6 +367,9 @@ extern int bpf_cgroup_read_xattr(struct cgroup *cgroup, const char *name__str,
extern int bpf_sock_read_xattr(struct socket *sock, const char *name__str,
struct bpf_dynptr *value_p) __weak __ksym;
+extern bool CONFIG_HAS_SEPARATE_PREEMPT_RESCHED_BITS __kconfig __weak;
+#define IS_ENABLED(cfg) (cfg)
+
#define PREEMPT_BITS 8
#define SOFTIRQ_BITS 8
#define HARDIRQ_DISABLE_BITS 8
?
[Cc Leon and Alexi]
Regards,
Boqun
> @@ -371,7 +371,7 @@ extern int bpf_sock_read_xattr(struct socket *sock, const char *name__str,
> #define SOFTIRQ_BITS 8
> #define HARDIRQ_DISABLE_BITS 8
> #define HARDIRQ_BITS 4
> -#define NMI_BITS 1
> +#define NMI_BITS (1 + 3*IS_ENABLED(CONFIG_HAS_SEPARATE_PREEMPT_RESCHED_BITS))
>
> #define PREEMPT_SHIFT 0
> #define SOFTIRQ_SHIFT (PREEMPT_SHIFT + PREEMPT_BITS)
> --
> 2.51.0
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-10-01 13:13 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v2 2/5] irq: Add {over,under}flow detection for local_interrupt_{enable,disable} Boqun Feng
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
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®