[PATCH 31/32] s390/bpf: Simplify exception table entry handling
From: Heiko Carstens
Date: Thu Oct 01 2026 - 06:42:52 EST
With exception table lookup always pointing to the faulting instruction,
only a single exception table entry per probe instruction is needed.
Remove the second exception table entry, the extra nop instruction
emitted between/after probe instructions, and simplify probe handling
in the BPF JIT.
Signed-off-by: Heiko Carstens <hca@xxxxxxxxxxxxx>
---
arch/s390/net/bpf_jit_comp.c | 78 ++++++++++--------------------------
1 file changed, 21 insertions(+), 57 deletions(-)
diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
index c4b47070bb59..9f1632e068e1 100644
--- a/arch/s390/net/bpf_jit_comp.c
+++ b/arch/s390/net/bpf_jit_comp.c
@@ -723,7 +723,6 @@ bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs)
*/
struct bpf_jit_probe {
int prg; /* JITed instruction offset */
- int nop_prg; /* JITed nop offset */
int reg; /* Register to clear on exception */
int arena_reg; /* Register to use for arena addressing */
};
@@ -731,29 +730,10 @@ struct bpf_jit_probe {
static void bpf_jit_probe_init(struct bpf_jit_probe *probe)
{
probe->prg = -1;
- probe->nop_prg = -1;
probe->reg = -1;
probe->arena_reg = REG_0;
}
-/*
- * Handlers of certain exceptions leave psw.addr pointing to the instruction
- * directly after the failing one. Therefore, create two exception table
- * entries and also add a nop in case two probing instructions come directly
- * after each other.
- */
-static void bpf_jit_probe_emit_nop(struct bpf_jit *jit,
- struct bpf_jit_probe *probe)
-{
- if (probe->prg == -1 || probe->nop_prg != -1)
- /* The probe is not armed or nop is already emitted. */
- return;
-
- probe->nop_prg = jit->prg;
- /* bcr 0,%0 */
- _EMIT2(0x0700);
-}
-
static void bpf_jit_probe_load_pre(struct bpf_jit *jit, struct bpf_insn *insn,
struct bpf_jit_probe *probe)
{
@@ -815,47 +795,36 @@ static int bpf_jit_probe_post(struct bpf_jit *jit, struct bpf_prog *fp,
struct bpf_jit_probe *probe)
{
struct exception_table_entry *ex;
- int i, prg;
s64 delta;
- u8 *insn;
if (probe->prg == -1)
/* The probe is not armed. */
return 0;
- bpf_jit_probe_emit_nop(jit, probe);
if (!fp->aux->extable)
/* Do nothing during early JIT passes. */
return 0;
- insn = jit->prg_buf + probe->prg;
- if (WARN_ON_ONCE(probe->prg + insn_length(*insn) != probe->nop_prg))
- /* JIT bug - gap between probe and nop instructions. */
+ if (WARN_ON_ONCE(jit->excnt >= fp->aux->num_exentries))
+ /* Verifier bug - not enough entries. */
return -1;
- for (i = 0; i < 2; i++) {
- if (WARN_ON_ONCE(jit->excnt >= fp->aux->num_exentries))
- /* Verifier bug - not enough entries. */
- return -1;
- ex = &fp->aux->extable[jit->excnt];
- /* Add extable entries for probe and nop instructions. */
- prg = i == 0 ? probe->prg : probe->nop_prg;
- delta = jit->prg_buf + prg - (u8 *)&ex->insn;
- if (WARN_ON_ONCE(delta < INT_MIN || delta > INT_MAX))
- /* JIT bug - code and extable must be close. */
- return -1;
- ex->insn = delta;
- /*
- * Land on the current instruction. Note that the extable
- * infrastructure ignores the fixup field; it is handled by
- * ex_handler_bpf().
- */
- delta = jit->prg_buf + jit->prg - (u8 *)&ex->fixup;
- if (WARN_ON_ONCE(delta < INT_MIN || delta > INT_MAX))
- /* JIT bug - landing pad and extable must be close. */
- return -1;
- ex->fixup = delta;
- ex->type = EX_TYPE_BPF;
- ex->data = probe->reg;
- jit->excnt++;
- }
+ ex = &fp->aux->extable[jit->excnt];
+ delta = jit->prg_buf + probe->prg - (u8 *)&ex->insn;
+ if (WARN_ON_ONCE(delta < INT_MIN || delta > INT_MAX))
+ /* JIT bug - code and extable must be close. */
+ return -1;
+ ex->insn = delta;
+ /*
+ * Land on the current instruction. Note that the extable
+ * infrastructure ignores the fixup field; it is handled by
+ * ex_handler_bpf().
+ */
+ delta = jit->prg_buf + jit->prg - (u8 *)&ex->fixup;
+ if (WARN_ON_ONCE(delta < INT_MIN || delta > INT_MAX))
+ /* JIT bug - landing pad and extable must be close. */
+ return -1;
+ ex->fixup = delta;
+ ex->type = EX_TYPE_BPF;
+ ex->data = probe->reg;
+ jit->excnt++;
return 0;
}
@@ -1705,7 +1674,6 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
EMIT6_DISP_LH(0xe3000000,
is32 ? 0x0058 : 0x0004, REG_W0, REG_0,
load_probe.arena_reg, off);
- bpf_jit_probe_emit_nop(jit, &load_probe);
/* Reuse {ly|lg}'s arena_reg for {csy|csg}. */
if (load_probe.prg != -1) {
probe.prg = jit->prg;
@@ -1716,7 +1684,6 @@ static noinline int bpf_jit_insn(struct bpf_jit *jit, struct bpf_prog *fp,
/* 0: {csy|csg} %w0,%src,off(%arena) */
EMIT6_DISP_LH(0xeb000000, is32 ? 0x0014 : 0x0030,
REG_W0, src_reg, probe.arena_reg, off);
- bpf_jit_probe_emit_nop(jit, &probe);
/* brc 4,0b */
EMIT4_PCREL_RIC(0xa7040000, 4, loop_start);
/* {llgfr|lgr} %src,%w0 */
@@ -2364,9 +2331,6 @@ static struct bpf_binary_header *bpf_jit_alloc(struct bpf_jit *jit,
*/
fp->aux->num_exentries += 1;
}
- /* We need two entries per insn. */
- fp->aux->num_exentries *= 2;
-
code_size = roundup(jit->size,
__alignof__(struct exception_table_entry));
extable_size = fp->aux->num_exentries *
--
2.53.0