]> git.baikalelectronics.ru Git - kernel.git/commitdiff
powerpc/bpf: Always reallocate BPF_REG_5, BPF_REG_AX and TMP_REG when possible
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Mon, 10 Jan 2022 12:29:42 +0000 (12:29 +0000)
committerMichael Ellerman <mpe@ellerman.id.au>
Sat, 12 Feb 2022 11:47:42 +0000 (22:47 +1100)
BPF_REG_5, BPF_REG_AX and TMP_REG are mapped on non volatile registers
because there are not enough volatile registers, but they don't need
to be preserved on function calls.

So when some volatile registers become available, those registers can
always be reallocated regardless of whether SEEN_FUNC is set or not.

Suggested-by: Naveen N. Rao <naveen.n.rao@linux.ibm.com>
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Reviewed-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/b04c246874b716911139c04bc004b3b14eed07ef.1641817763.git.christophe.leroy@csgroup.eu
arch/powerpc/net/bpf_jit.h
arch/powerpc/net/bpf_jit_comp32.c

index b20a2a83a6e75be330ef97f9ea65e785629bb1ca..b75507fc8f6b0b08024febb0bf1b17c68507257e 100644 (file)
 #define SEEN_FUNC      0x20000000 /* might call external helpers */
 #define SEEN_TAILCALL  0x40000000 /* uses tail calls */
 
-#define SEEN_VREG_MASK 0x1ff80000 /* Volatile registers r3-r12 */
-#define SEEN_NVREG_MASK        0x0003ffff /* Non volatile registers r14-r31 */
-
 #ifdef CONFIG_PPC64
 extern const int b2p[MAX_BPF_JIT_REG + 2];
 #else
index cf8dd8aea386c4bb8d5366f51015102731bba82d..43643f1c1034deddb97edf981af4f2d589ddc48d 100644 (file)
@@ -77,14 +77,22 @@ static int bpf_jit_stack_offsetof(struct codegen_context *ctx, int reg)
        return BPF_PPC_STACKFRAME(ctx) - 4;
 }
 
+#define SEEN_VREG_MASK         0x1ff80000 /* Volatile registers r3-r12 */
+#define SEEN_NVREG_FULL_MASK   0x0003ffff /* Non volatile registers r14-r31 */
+#define SEEN_NVREG_TEMP_MASK   0x00001e01 /* BPF_REG_5, BPF_REG_AX, TMP_REG */
+
 void bpf_jit_realloc_regs(struct codegen_context *ctx)
 {
+       unsigned int nvreg_mask;
+
        if (ctx->seen & SEEN_FUNC)
-               return;
+               nvreg_mask = SEEN_NVREG_TEMP_MASK;
+       else
+               nvreg_mask = SEEN_NVREG_FULL_MASK;
 
-       while (ctx->seen & SEEN_NVREG_MASK &&
+       while (ctx->seen & nvreg_mask &&
              (ctx->seen & SEEN_VREG_MASK) != SEEN_VREG_MASK) {
-               int old = 32 - fls(ctx->seen & (SEEN_NVREG_MASK & 0xaaaaaaab));
+               int old = 32 - fls(ctx->seen & (nvreg_mask & 0xaaaaaaab));
                int new = 32 - fls(~ctx->seen & (SEEN_VREG_MASK & 0xaaaaaaaa));
                int i;