Skip to contentSkip to conversation

riscv, bpf: Optimize stack usage of trampoline

PATCH Applied Puranjay Mohan 4 participants 4 messages Jul 8, 2024 – Jul 23, 2024

Subsystems (3)
lore
Share & tools
lore

Puranjay Mohan

author reviewer
#0 lore raw

PATCH 1/1 riscv, bpf: Optimize stack usage of trampoline

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.

---
 arch/riscv/net/bpf_jit_comp64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/net/bpf_jit_comp64.c +1 -1
index 685c7389ae7e..0795efdd3519 100644
@@ -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);
Signature · 1 line
2.40.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 17 lines · Puranjay Mohan

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.

---
  arch/riscv/net/bpf_jit_comp64.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/net/bpf_jit_comp64.c +0 -0
index 685c7389ae7e..0795efdd3519 100644

arch/riscv/net/bpf_jit_comp64.c static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, · line 898

Quoted 8 lines
arch/riscv/net/bpf_jit_comp64.c +1 -1
@@ -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!

#2 lore raw
In reply to Puranjay Mohan
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:

Quoted 8 lines · 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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#3 lore raw
In reply to Puranjay Mohan
This patch was applied to riscv/linux.git (for-next) by Daniel Borkmann <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (for-next) by Daniel Borkmann <[email protected]>:

Quoted 8 lines · 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!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html