mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [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
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ 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] 12+ 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-02  9:44   ` [tip: locking/urgent] " tip-bot2 for Kuan-Wei Chiu
  2026-10-01  8:25 ` [PATCH v2 2/5] irq: Add {over,under}flow detection for local_interrupt_{enable,disable} Boqun Feng
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 12+ 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] 12+ 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
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 12+ 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] 12+ 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
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 12+ 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] 12+ 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
  2026-10-02  9:42 ` [PATCH v2 0/5] Improvements and fixes on SpinLockIrq patch series Peter Zijlstra
  5 siblings, 0 replies; 12+ 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] 12+ 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
  2026-10-02  9:42 ` [PATCH v2 0/5] Improvements and fixes on SpinLockIrq patch series Peter Zijlstra
  5 siblings, 0 replies; 12+ 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] 12+ 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
  2026-10-02  6:24     ` Leon Hwang
  0 siblings, 1 reply; 12+ 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] 12+ messages in thread

* Re: [PATCH v2 3/5] selftests/bpf: Use the new NMI_BITS definition
  2026-10-01 13:13   ` Boqun Feng
@ 2026-10-02  6:24     ` Leon Hwang
  2026-10-02  6:41       ` Boqun Feng
  0 siblings, 1 reply; 12+ messages in thread
From: Leon Hwang @ 2026-10-02  6:24 UTC (permalink / raw)
  To: Boqun Feng, 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, Alexei Starovoitov

On 1/10/26 21:13, Boqun Feng wrote:
> 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:

Sashiko is correct.

BPF compilation context is different from kernel compilation context. It
cannot directly use
IS_ENABLED(CONFIG_HAS_SEPARATE_PREEMPT_RESCHED_BITS)) when compiling BPF
objects.

> 
> 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)

Correct.

IS_ENABLED is unnecessary here.

The below patch passed the BPF ci [1].

[1] https://github.com/kernel-patches/bpf/pull/14197

> +
>  #define PREEMPT_BITS   8
>  #define SOFTIRQ_BITS   8
>  #define HARDIRQ_DISABLE_BITS   8
> 
> ?
> 
> [Cc Leon and Alexi]

Please cc BPF list, BPF maintainers, and me when respinning.

Thanks,
Leon

> 
> Regards,
> Boqun
> 
---

From 4c1b9a6f6404aa25d1d300465dba4bee9a139668 Mon Sep 17 00:00:00 2001
From: Boqun Feng <boqun@kernel.org>
Date: Thu, 1 Oct 2026 10:25:17 +0200
Subject: [PATCH 1/3] selftests/bpf: Use the new NMI_BITS definition

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 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/bpf/bpf_experimental.h
b/tools/testing/selftests/bpf/bpf_experimental.h
index 2893bf06ff25..b567a48f1dce 100644
--- a/tools/testing/selftests/bpf/bpf_experimental.h
+++ b/tools/testing/selftests/bpf/bpf_experimental.h
@@ -367,11 +367,13 @@ 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 __weak __kconfig;
+
 #define PREEMPT_BITS	8
 #define SOFTIRQ_BITS	8
 #define HARDIRQ_DISABLE_BITS	8
 #define HARDIRQ_BITS	4
-#define NMI_BITS	1
+#define NMI_BITS	(1 + 3*CONFIG_HAS_SEPARATE_PREEMPT_RESCHED_BITS)

 #define PREEMPT_SHIFT	0
 #define SOFTIRQ_SHIFT	(PREEMPT_SHIFT + PREEMPT_BITS)
-- 
2.55.0



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 3/5] selftests/bpf: Use the new NMI_BITS definition
  2026-10-02  6:24     ` Leon Hwang
@ 2026-10-02  6:41       ` Boqun Feng
  0 siblings, 0 replies; 12+ messages in thread
From: Boqun Feng @ 2026-10-02  6:41 UTC (permalink / raw)
  To: Leon Hwang
  Cc: Peter Zijlstra, 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, Alexei Starovoitov

On Fri, Oct 02, 2026 at 02:24:11PM +0800, Leon Hwang wrote:
> On 1/10/26 21:13, Boqun Feng wrote:
> > 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:
> 
> Sashiko is correct.
> 
> BPF compilation context is different from kernel compilation context. It
> cannot directly use
> IS_ENABLED(CONFIG_HAS_SEPARATE_PREEMPT_RESCHED_BITS)) when compiling BPF
> objects.
> 
> > 
> > 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)
> 
> Correct.
> 
> IS_ENABLED is unnecessary here.
> 
> The below patch passed the BPF ci [1].
> 
> [1] https://github.com/kernel-patches/bpf/pull/14197
> 

Thanks for the testing. I know that IS_ENABLED is not unnecessary, but I
put it there to make NMI_BITS definition stay the same as
include/linux/preempt.h.

> > +
> >  #define PREEMPT_BITS   8
> >  #define SOFTIRQ_BITS   8
> >  #define HARDIRQ_DISABLE_BITS   8
> > 
> > ?
> > 
> > [Cc Leon and Alexi]
> 
> Please cc BPF list, BPF maintainers, and me when respinning.
> 

Sure, will do.

Regards,
Boqun

> Thanks,
> Leon
> 
> > 
> > Regards,
> > Boqun
> > 
> ---
> 
> From 4c1b9a6f6404aa25d1d300465dba4bee9a139668 Mon Sep 17 00:00:00 2001
> From: Boqun Feng <boqun@kernel.org>
> Date: Thu, 1 Oct 2026 10:25:17 +0200
> Subject: [PATCH 1/3] selftests/bpf: Use the new NMI_BITS definition
> 
> 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 | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/testing/selftests/bpf/bpf_experimental.h
> b/tools/testing/selftests/bpf/bpf_experimental.h
> index 2893bf06ff25..b567a48f1dce 100644
> --- a/tools/testing/selftests/bpf/bpf_experimental.h
> +++ b/tools/testing/selftests/bpf/bpf_experimental.h
> @@ -367,11 +367,13 @@ 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 __weak __kconfig;
> +
>  #define PREEMPT_BITS	8
>  #define SOFTIRQ_BITS	8
>  #define HARDIRQ_DISABLE_BITS	8
>  #define HARDIRQ_BITS	4
> -#define NMI_BITS	1
> +#define NMI_BITS	(1 + 3*CONFIG_HAS_SEPARATE_PREEMPT_RESCHED_BITS)
> 
>  #define PREEMPT_SHIFT	0
>  #define SOFTIRQ_SHIFT	(PREEMPT_SHIFT + PREEMPT_BITS)
> -- 
> 2.55.0
> 
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 0/5] Improvements and fixes on SpinLockIrq patch series
  2026-10-01  8:25 [PATCH v2 0/5] Improvements and fixes on SpinLockIrq patch series Boqun Feng
                   ` (4 preceding siblings ...)
  2026-10-01  8:25 ` [PATCH v2 5/5] irq: Add max local_interrupt_disable() nesting level kunit test case Boqun Feng
@ 2026-10-02  9:42 ` Peter Zijlstra
  2026-10-02 10:30   ` Boqun Feng
  5 siblings, 1 reply; 12+ messages in thread
From: Peter Zijlstra @ 2026-10-02  9:42 UTC (permalink / raw)
  To: Boqun Feng
  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

On Thu, Oct 01, 2026 at 10:25:14AM +0200, Boqun Feng wrote:
> 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.

The first should now be in tip/locking/urgent, while all but the BPF one
are in queue/locking/core, which will be promoted to tip/locking/core
after the robot had a go at it.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [tip: locking/urgent] irq: Make refcount_interrupt kunit test selectable
  2026-10-01  8:25 ` [PATCH v2 1/5] irq: Make refcount_interrupt kunit test selectable Boqun Feng
@ 2026-10-02  9:44   ` tip-bot2 for Kuan-Wei Chiu
  0 siblings, 0 replies; 12+ messages in thread
From: tip-bot2 for Kuan-Wei Chiu @ 2026-10-02  9:44 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Kuan-Wei Chiu, Peter Zijlstra (Intel),
	Lyude Paul, Radu Rendec, Boqun Feng, x86, linux-kernel

The following commit has been merged into the locking/urgent branch of tip:

Commit-ID:     26f6b6357b1b06e6aaa9b8d796989cca785d8e1d
Gitweb:        https://git.kernel.org/tip/26f6b6357b1b06e6aaa9b8d796989cca785d8e1d
Author:        Kuan-Wei Chiu <visitorckw@gmail.com>
AuthorDate:    Thu, 01 Oct 2026 10:25:15 +02:00
Committer:     Peter Zijlstra <peterz@infradead.org>
CommitterDate: Fri, 02 Oct 2026 11:40:12 +02:00

irq: Make refcount_interrupt kunit test selectable

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>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Reviewed-by: Radu Rendec <radu@rendec.net>
Reviewed-by: Boqun Feng <boqun@kernel.org>
Link: https://patch.msgid.link/20261001082519.16195-2-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 05cba4e..6923f37 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 44c4d6f..0e5df96 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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2 0/5] Improvements and fixes on SpinLockIrq patch series
  2026-10-02  9:42 ` [PATCH v2 0/5] Improvements and fixes on SpinLockIrq patch series Peter Zijlstra
@ 2026-10-02 10:30   ` Boqun Feng
  0 siblings, 0 replies; 12+ messages in thread
From: Boqun Feng @ 2026-10-02 10:30 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

On Fri, Oct 02, 2026 at 11:42:44AM +0200, Peter Zijlstra wrote:
> On Thu, Oct 01, 2026 at 10:25:14AM +0200, Boqun Feng wrote:
> > 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.
> 
> The first should now be in tip/locking/urgent, while all but the BPF one
> are in queue/locking/core, which will be promoted to tip/locking/core
> after the robot had a go at it.

Thanks! I resend the bpf fix v3:

* https://lore.kernel.org/lkml/20261001082519.16195-4-boqun@kernel.org/

Regards,
Boqun

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-10-02 10:30 UTC | newest]

Thread overview: 12+ 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-02  9:44   ` [tip: locking/urgent] " tip-bot2 for Kuan-Wei Chiu
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-02  6:24     ` Leon Hwang
2026-10-02  6:41       ` 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
2026-10-02  9:42 ` [PATCH v2 0/5] Improvements and fixes on SpinLockIrq patch series Peter Zijlstra
2026-10-02 10:30   ` 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®