]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
riscv, bpf: Optimize stack usage of trampoline
authorPuranjay Mohan <puranjay@kernel.org>
Mon, 8 Jul 2024 11:47:58 +0000 (11:47 +0000)
committerDaniel Borkmann <daniel@iogearbox.net>
Mon, 8 Jul 2024 13:44:08 +0000 (15:44 +0200)
When BPF_TRAMP_F_CALL_ORIG is not set, stack space for passing arguments
on stack doesn't need to be reserved because the original function is
not called.

Only reserve space for stacked arguments when BPF_TRAMP_F_CALL_ORIG is
set.

Signed-off-by: Puranjay Mohan <puranjay@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Pu Lehui <pulehui@huawei.com>
Link: https://lore.kernel.org/bpf/20240708114758.64414-1-puranjay@kernel.org
arch/riscv/net/bpf_jit_comp64.c

index 685c7389ae7ebb94397d544ec1713e8c45f18484..0795efdd351928a4e964c42132196a11a79fd56f 100644 (file)
@@ -892,7 +892,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
        stack_size += 8;
        sreg_off = stack_size;
 
-       if (nr_arg_slots - RV_MAX_REG_ARGS > 0)
+       if ((flags & BPF_TRAMP_F_CALL_ORIG) && (nr_arg_slots - RV_MAX_REG_ARGS > 0))
                stack_size += (nr_arg_slots - RV_MAX_REG_ARGS) * 8;
 
        stack_size = round_up(stack_size, STACK_ALIGN);