s390/bpf: encode register within extable entry
authorHeiko Carstens <hca@linux.ibm.com>
Sun, 27 Feb 2022 20:32:54 +0000 (21:32 +0100)
committerVasily Gorbik <gor@linux.ibm.com>
Mon, 7 Mar 2022 23:33:00 +0000 (00:33 +0100)
Instead of decoding the instruction that faulted to get the register
which needs to be zeroed, simply encode its number into the extable
entries during code generation. This allows to get rid of a bit of
code, and is also what other architectures are doing.

Acked-by: Alexander Gordeev <agordeev@linux.ibm.com>
Reviewed-by: Ilya Leoshkevich <iii@linux.ibm.com>
Tested-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
arch/s390/net/bpf_jit_comp.c

index a1a3a10..e1e57a3 100644 (file)
@@ -624,16 +624,8 @@ static int get_probe_mem_regno(const u8 *insn)
 
 bool ex_handler_bpf(const struct exception_table_entry *x, struct pt_regs *regs)
 {
-       int regno;
-       u8 *insn;
-
        regs->psw.addr = extable_fixup(x);
-       insn = (u8 *)__rewind_psw(regs->psw, regs->int_code >> 16);
-       regno = get_probe_mem_regno(insn);
-       if (WARN_ON_ONCE(regno < 0))
-               /* JIT bug - unexpected instruction. */
-               return false;
-       regs->gprs[regno] = 0;
+       regs->gprs[x->data] = 0;
        return true;
 }
 
@@ -641,16 +633,17 @@ static int bpf_jit_probe_mem(struct bpf_jit *jit, struct bpf_prog *fp,
                             int probe_prg, int nop_prg)
 {
        struct exception_table_entry *ex;
+       int reg, prg;
        s64 delta;
        u8 *insn;
-       int prg;
        int i;
 
        if (!fp->aux->extable)
                /* Do nothing during early JIT passes. */
                return 0;
        insn = jit->prg_buf + probe_prg;
-       if (WARN_ON_ONCE(get_probe_mem_regno(insn) < 0))
+       reg = get_probe_mem_regno(insn);
+       if (WARN_ON_ONCE(reg < 0))
                /* JIT bug - unexpected probe instruction. */
                return -1;
        if (WARN_ON_ONCE(probe_prg + insn_length(*insn) != nop_prg))
@@ -678,6 +671,7 @@ static int bpf_jit_probe_mem(struct bpf_jit *jit, struct bpf_prog *fp,
                        return -1;
                ex->fixup = delta;
                ex->type = EX_TYPE_BPF;
+               ex->data = reg;
                jit->excnt++;
        }
        return 0;