]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
s390: Introduce bpf_get_lowcore() kfunc
authorIlya Leoshkevich <iii@linux.ibm.com>
Tue, 17 Feb 2026 16:05:08 +0000 (17:05 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 3 Mar 2026 16:35:07 +0000 (08:35 -0800)
Implementing BPF version of preempt_count() requires accessing lowcore
from BPF. Since lowcore can be relocated, open-coding
(struct lowcore *)0 does not work, so add a kfunc.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Link: https://lore.kernel.org/r/20260217160813.100855-2-iii@linux.ibm.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
arch/s390/kernel/Makefile
arch/s390/kernel/bpf.c [new file with mode: 0644]
kernel/bpf/helpers.c
tools/testing/selftests/bpf/bpf_experimental.h

index 42c83d60d6faef79c75f8faddb5a2eaf9ab2ebc6..b522c6649fccbbbeef54a0e8da64a7a4f11ff02e 100644 (file)
@@ -80,5 +80,7 @@ obj-$(CONFIG_PERF_EVENTS)     += perf_pai.o
 
 obj-$(CONFIG_TRACEPOINTS)      += trace.o
 
+obj-$(CONFIG_BPF_SYSCALL)      += bpf.o
+
 # vdso
 obj-y                          += vdso/
diff --git a/arch/s390/kernel/bpf.c b/arch/s390/kernel/bpf.c
new file mode 100644 (file)
index 0000000..713337f
--- /dev/null
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <asm/lowcore.h>
+#include <linux/btf.h>
+
+__bpf_kfunc_start_defs();
+
+__bpf_kfunc struct lowcore *bpf_get_lowcore(void)
+{
+       return get_lowcore();
+}
+
+__bpf_kfunc_end_defs();
index 6eb6c82ed2ee1ae959defff887bd20c1e05ffa3c..cb6d242bd0936969cc65c951d4215d39a16aabda 100644 (file)
@@ -4578,6 +4578,9 @@ BTF_ID_FLAGS(func, bpf_key_put, KF_RELEASE)
 BTF_ID_FLAGS(func, bpf_verify_pkcs7_signature, KF_SLEEPABLE)
 #endif
 #endif
+#ifdef CONFIG_S390
+BTF_ID_FLAGS(func, bpf_get_lowcore)
+#endif
 BTF_KFUNCS_END(generic_btf_ids)
 
 static const struct btf_kfunc_id_set generic_kfunc_set = {
index 9df77e59d4f5d3b65c85347e177017de1b97c92b..4453ad27b2ef71b081a1e8b8814fc4a4fde0f5ae 100644 (file)
@@ -627,6 +627,10 @@ struct task_struct___preempt_rt {
        int softirq_disable_cnt;
 } __attribute__((preserve_access_index));
 
+#ifdef bpf_target_s390
+extern struct lowcore *bpf_get_lowcore(void) __weak __ksym;
+#endif
+
 static inline int get_preempt_count(void)
 {
 #if defined(bpf_target_x86)