From: Heiko Carstens <hca@linux.ibm.com>
To: Stefan Schulze Frielinghaus <stefansf@linux.ibm.com>,
Juergen Christ <jchrist@linux.ibm.com>,
Ilya Leoshkevich <iii@linux.ibm.com>,
Dominik Steenken <dost@de.ibm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Sven Schnelle <svens@linux.ibm.com>,
Vasily Gorbik <gor@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Maxim Khmelevskii <max@linux.ibm.com>,
Jens Remus <jremus@linux.ibm.com>,
Sami Tolvanen <samitolvanen@google.com>,
Kees Cook <kees@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Eduard Zingerman <eddyz87@gmail.com>,
Kumar Kartikeya Dwivedi <memxor@gmail.com>
Cc: llvm@lists.linux.dev, bpf@vger.kernel.org,
linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 6/6] s390/bpf: Add kCFI support
Date: Fri, 24 Jul 2026 16:13:18 +0200 [thread overview]
Message-ID: <20260724141318.1037434-7-hca@linux.ibm.com> (raw)
In-Reply-To: <20260724141318.1037434-1-hca@linux.ibm.com>
This is the s390 variant of commit 710618c760c0 ("arm64/cfi,bpf: Support
kCFI + BPF on arm64").
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
arch/s390/include/asm/cfi.h | 7 +++++++
arch/s390/net/bpf_jit_comp.c | 26 ++++++++++++++++++++++----
2 files changed, 29 insertions(+), 4 deletions(-)
create mode 100644 arch/s390/include/asm/cfi.h
diff --git a/arch/s390/include/asm/cfi.h b/arch/s390/include/asm/cfi.h
new file mode 100644
index 000000000000..9af2c7cb70ca
--- /dev/null
+++ b/arch/s390/include/asm/cfi.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _ASM_S390_CFI_H
+#define _ASM_S390_CFI_H
+
+#define __bpfcall
+
+#endif /* _ASM_S390_CFI_H */
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
index 31749c0362ca..74642e0b4ee1 100644
--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -21,6 +21,7 @@
#include <linux/filter.h>
#include <linux/init.h>
#include <linux/bpf.h>
+#include <linux/cfi.h>
#include <linux/mm.h>
#include <linux/kernel.h>
#include <asm/cacheflush.h>
@@ -356,6 +357,19 @@ static void emit6_pcrel_rilc(struct bpf_jit *jit, u32 op, u8 mask, s64 pcrel)
} \
})
+static inline void emit_u32_data(const u32 data, struct bpf_jit *jit)
+{
+ if (jit->prg_buf)
+ *(u32 *)(jit->prg_buf + jit->prg) = data;
+ jit->prg += 4;
+}
+
+static inline void emit_kcfi(u32 hash, struct bpf_jit *jit)
+{
+ if (IS_ENABLED(CONFIG_CFI))
+ emit_u32_data(hash, jit);
+}
+
/*
* Return whether this is the first pass. The first pass is special, since we
* don't know any sizes yet, and thus must be conservative.
@@ -597,6 +611,8 @@ static void bpf_jit_prologue(struct bpf_jit *jit, struct bpf_prog *fp)
{
BUILD_BUG_ON(sizeof(struct prog_frame) != STACK_FRAME_OVERHEAD);
+ emit_kcfi(bpf_is_subprog(fp) ? cfi_bpf_subprog_hash : cfi_bpf_hash, jit);
+
/* No-op for hotpatching */
/* brcl 0,prologue_plt */
EMIT6_PCREL_RILC(0xc0040000, 0, jit->prologue_plt);
@@ -616,7 +632,7 @@ static void bpf_jit_prologue(struct bpf_jit *jit, struct bpf_prog *fp)
bpf_skip(jit, 6);
}
/* Tail calls have to skip above initialization */
- jit->tail_call_start = jit->prg;
+ jit->tail_call_start = jit->prg - cfi_get_offset();
if (fp->aux->exception_cb) {
/*
* Switch stack, the new address is in the 2nd parameter.
@@ -2401,9 +2417,9 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_verifier_env *env, struct bpf_pr
jit_data->ctx = jit;
jit_data->pass = pass;
}
- fp->bpf_func = (void *) jit.prg_buf;
+ fp->bpf_func = (void *)jit.prg_buf + cfi_get_offset();
fp->jited = 1;
- fp->jited_len = jit.size;
+ fp->jited_len = jit.size - cfi_get_offset();
if (!fp->is_func || extra_pass) {
bpf_prog_fill_jited_linfo(fp, jit.addrs + 1);
@@ -2671,8 +2687,10 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
return -ENOTSUPP;
/* Return to %r14 in the struct_ops case. */
- if (flags & BPF_TRAMP_F_INDIRECT)
+ if (flags & BPF_TRAMP_F_INDIRECT) {
flags |= BPF_TRAMP_F_SKIP_FRAME;
+ emit_kcfi(cfi_get_func_hash(func_addr), jit);
+ }
/*
* Compute how many arguments we need to pass to BPF programs.
--
2.53.0
next prev parent reply other threads:[~2026-07-24 14:13 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-24 14:13 [PATCH 0/6] s390: Add kCFI support Heiko Carstens
2026-07-24 14:13 ` [PATCH 1/6] s390/tools: Pass symbol name to do_relocs() Heiko Carstens
2026-07-24 14:23 ` sashiko-bot
2026-07-24 15:14 ` bot+bpf-ci
2026-07-24 14:13 ` [PATCH 2/6] s390/tools/relocs: Ignore __kcfi_typeid_ relocations Heiko Carstens
2026-07-24 14:30 ` sashiko-bot
2026-07-24 14:13 ` [PATCH 3/6] s390: Add ftrace_stub_graph Heiko Carstens
2026-07-24 14:21 ` sashiko-bot
2026-07-24 15:14 ` bot+bpf-ci
2026-07-24 14:13 ` [PATCH 4/6] s390/diag: Generate CFI type information for assembly functions Heiko Carstens
2026-07-24 14:26 ` sashiko-bot
2026-07-24 14:13 ` [PATCH 5/6] s390/Kconfig: Select ARCH_SUPPORTS_CFI Heiko Carstens
2026-07-24 14:37 ` sashiko-bot
2026-07-24 14:13 ` Heiko Carstens [this message]
2026-07-24 14:34 ` [PATCH 6/6] s390/bpf: Add kCFI support sashiko-bot
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=20260724141318.1037434-7-hca@linux.ibm.com \
--to=hca@linux.ibm.com \
--cc=agordeev@linux.ibm.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=borntraeger@linux.ibm.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dost@de.ibm.com \
--cc=eddyz87@gmail.com \
--cc=gor@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=jchrist@linux.ibm.com \
--cc=jremus@linux.ibm.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=max@linux.ibm.com \
--cc=memxor@gmail.com \
--cc=nathan@kernel.org \
--cc=samitolvanen@google.com \
--cc=stefansf@linux.ibm.com \
--cc=svens@linux.ibm.com \
/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