Skip to contentSkip to conversation

selftests/bpf: Use the new NMI_BITS definition

PATCH In review Boqun Feng 2 participants 3 messages Oct 2 – Oct 19

Subsystems (4)
lore
Share & tools
lore

Boqun Feng

author reviewer
#0 lore raw

PATCH v3 1/1 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.

Fixes 3b0e2a22d408 ("preempt: Introduce HAS_SEPARATE_PREEMPT_RESCHED_BITS")
Cc Leon Hwang <[email protected]>
Cc Alexei Starovoitov <[email protected]>

---
v2: https://lore.kernel.org/lkml/[email protected]/
v2 -> v3:

* Add Fixes tag.
* Add CONFIG_HAS_SEPARATE_PREEMPT_RESCHED_BITS weak symbol because CONFIG_* is not available in bpf programs.

 tools/testing/selftests/bpf/bpf_experimental.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/bpf_experimental.h +6 -1
index 2893bf06ff25..a09448347966 100644
@@ -367,11 +367,16 @@ 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;
+
+/* A trivial macro to make NMI_BITS exactly the same as in <linux/preempt.h> */
+#define IS_ENABLED(cfg)	(cfg)
+
 #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*IS_ENABLED(CONFIG_HAS_SEPARATE_PREEMPT_RESCHED_BITS))
 
 #define PREEMPT_SHIFT	0
 #define SOFTIRQ_SHIFT	(PREEMPT_SHIFT + PREEMPT_BITS)
Signature · 1 line
2.51.0
Acked-by on v3 1/1
#1 lore raw
Quoted 9 lines · Boqun Feng

The definition of NMI_BITS was out of sync after the introduction of HAS_SEPARATE_PREEMPT_RESCHED_BITS, hence adjust it.

Fixes 3b0e2a22d408 ("preempt: Introduce HAS_SEPARATE_PREEMPT_RESCHED_BITS")
Cc Leon Hwang <[email protected]>
Cc Alexei Starovoitov <[email protected]>

lgtm,

One nit below.

Quoted 17 lines

---
v2: https://lore.kernel.org/lkml/[email protected]/
v2 -> v3:

* Add Fixes tag.
* Add CONFIG_HAS_SEPARATE_PREEMPT_RESCHED_BITS weak symbol because CONFIG_* is not available in bpf programs.

 tools/testing/selftests/bpf/bpf_experimental.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/bpf_experimental.h +0 -0
index 2893bf06ff25..a09448347966 100644

tools/testing/selftests/bpf/bpf_experimental.h extern int bpf_cgroup_read_xattr(struct cgroup *cgroup, const char *name__str, · line 373

Quoted 7 lines
tools/testing/selftests/bpf/bpf_experimental.h +4 -0
@@ -367,11 +367,16 @@ 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;
+
+/* A trivial macro to make NMI_BITS exactly the same as in <linux/preempt.h> */
+#define IS_ENABLED(cfg)	(cfg)

NIT: change this to ((cfg) ? 1 : 0) to match IS_ENABLED() semantics.

Thanks,
Leon

Quoted 10 lines
tools/testing/selftests/bpf/bpf_experimental.h +2 -1
+
 #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*IS_ENABLED(CONFIG_HAS_SEPARATE_PREEMPT_RESCHED_BITS))
 
 #define PREEMPT_SHIFT	0
 #define SOFTIRQ_SHIFT	(PREEMPT_SHIFT + PREEMPT_BITS)
author reviewer
#2 lore raw
Quoted 37 lines · Leon Hwang
Quoted 9 lines · Boqun Feng

The definition of NMI_BITS was out of sync after the introduction of HAS_SEPARATE_PREEMPT_RESCHED_BITS, hence adjust it.

Fixes 3b0e2a22d408 ("preempt: Introduce HAS_SEPARATE_PREEMPT_RESCHED_BITS")
Cc Leon Hwang <[email protected]>
Cc Alexei Starovoitov <[email protected]>

lgtm,

One nit below.

Quoted 20 lines

---
v2: https://lore.kernel.org/lkml/[email protected]/
v2 -> v3:

* Add Fixes tag.
* Add CONFIG_HAS_SEPARATE_PREEMPT_RESCHED_BITS weak symbol because CONFIG_* is not available in bpf programs.

 tools/testing/selftests/bpf/bpf_experimental.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tools/testing/selftests/bpf/bpf_experimental.h +0 -0
index 2893bf06ff25..a09448347966 100644
@@ -367,11 +367,16 @@ 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;
 
Quoted 7 lines

tools/testing/selftests/bpf/bpf_experimental.h extern int bpf_cgroup_read_xattr(struct cgroup *cgroup, const char *name__str, · line 373

Quoted 4 lines
tools/testing/selftests/bpf/bpf_experimental.h +4 -0
+extern bool CONFIG_HAS_SEPARATE_PREEMPT_RESCHED_BITS __kconfig __weak;
+
+/* A trivial macro to make NMI_BITS exactly the same as in <linux/preempt.h> */
+#define IS_ENABLED(cfg)	(cfg)

NIT: change this to ((cfg) ? 1 : 0) to match IS_ENABLED() semantics.

Seems reasonable.

Regards,
Boqun

Quoted 14 lines

Thanks,
Leon

Quoted 10 lines
tools/testing/selftests/bpf/bpf_experimental.h +2 -1
+
 #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*IS_ENABLED(CONFIG_HAS_SEPARATE_PREEMPT_RESCHED_BITS))
 
 #define PREEMPT_SHIFT	0
 #define SOFTIRQ_SHIFT	(PREEMPT_SHIFT + PREEMPT_BITS)