diff mbox series

[bpf-next] riscv, bpf: Optimize stack usage of trampoline

Message ID 20240708114758.64414-1-puranjay@kernel.org (mailing list archive)
State Accepted
Commit a5912c37faf723c0812a6a2c9dd18ffbd34a233b
Headers show
Series [bpf-next] riscv, bpf: Optimize stack usage of trampoline | expand

Checks

Context Check Description
conchuod/vmtest-fixes-PR fail merge-conflict

Commit Message

Puranjay Mohan July 8, 2024, 11:47 a.m. UTC
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>
---
 arch/riscv/net/bpf_jit_comp64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Pu Lehui July 8, 2024, 12:02 p.m. UTC | #1
On 2024/7/8 19:47, Puranjay Mohan wrote:
> 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>
> ---
>   arch/riscv/net/bpf_jit_comp64.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
> index 685c7389ae7e..0795efdd3519 100644
> --- a/arch/riscv/net/bpf_jit_comp64.c
> +++ b/arch/riscv/net/bpf_jit_comp64.c
> @@ -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);

Thanks!

Acked-by: Pu Lehui <pulehui@huawei.com>
patchwork-bot+netdevbpf@kernel.org July 8, 2024, 1:50 p.m. UTC | #2
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Mon,  8 Jul 2024 11:47:58 +0000 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [bpf-next] riscv, bpf: Optimize stack usage of trampoline
    https://git.kernel.org/bpf/bpf-next/c/a5912c37faf7

You are awesome, thank you!
patchwork-bot+linux-riscv@kernel.org July 23, 2024, 12:58 p.m. UTC | #3
Hello:

This patch was applied to riscv/linux.git (for-next)
by Daniel Borkmann <daniel@iogearbox.net>:

On Mon,  8 Jul 2024 11:47:58 +0000 you wrote:
> 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.
> 
> [...]

Here is the summary with links:
  - [bpf-next] riscv, bpf: Optimize stack usage of trampoline
    https://git.kernel.org/riscv/c/a5912c37faf7

You are awesome, thank you!
diff mbox series

Patch

diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index 685c7389ae7e..0795efdd3519 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -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);