[PATCH bpf-next v3 3/6] bpf: fix the usage of BPF_TRAMP_F_SKIP_FRAME

Menglong Dong posted 6 patches 2 months, 3 weeks ago
[PATCH bpf-next v3 3/6] bpf: fix the usage of BPF_TRAMP_F_SKIP_FRAME
Posted by Menglong Dong 2 months, 3 weeks ago
Some places calculate the origin_call by checking if
BPF_TRAMP_F_SKIP_FRAME is set. However, it should use
BPF_TRAMP_F_ORIG_STACK for this propose. Just fix them.

Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
Acked-by: Alexei Starovoitov <ast@kernel.org>
---
 arch/riscv/net/bpf_jit_comp64.c | 2 +-
 arch/x86/net/bpf_jit_comp.c     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index 45cbc7c6fe49..21c70ae3296b 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -1131,7 +1131,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
 	store_args(nr_arg_slots, args_off, ctx);
 
 	/* skip to actual body of traced function */
-	if (flags & BPF_TRAMP_F_SKIP_FRAME)
+	if (flags & BPF_TRAMP_F_ORIG_STACK)
 		orig_call += RV_FENTRY_NINSNS * 4;
 
 	if (flags & BPF_TRAMP_F_CALL_ORIG) {
diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
index 36a0d4db9f68..808d4343f6cf 100644
--- a/arch/x86/net/bpf_jit_comp.c
+++ b/arch/x86/net/bpf_jit_comp.c
@@ -3289,7 +3289,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im, void *rw_im
 
 	arg_stack_off = stack_size;
 
-	if (flags & BPF_TRAMP_F_SKIP_FRAME) {
+	if (flags & BPF_TRAMP_F_CALL_ORIG) {
 		/* skip patched call instruction and point orig_call to actual
 		 * body of the kernel function.
 		 */
-- 
2.51.2
Re: [PATCH bpf-next v3 3/6] bpf: fix the usage of BPF_TRAMP_F_SKIP_FRAME
Posted by Andreas Schwab 1 month, 3 weeks ago
On Nov 18 2025, Menglong Dong wrote:

> Some places calculate the origin_call by checking if
> BPF_TRAMP_F_SKIP_FRAME is set. However, it should use
> BPF_TRAMP_F_ORIG_STACK for this propose. Just fix them.
>
> Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
> Acked-by: Alexei Starovoitov <ast@kernel.org>

This breaks RISC-V:

[    8.584381][    T1] systemd[1]: bpf-restrict-fs: LSM BPF program attached
[    8.588359][    T1] Insufficient stack space to handle exception!
[    8.588823][    T1] Task stack:     [0xff20000000010000..0xff20000000014000]
[    8.589219][    T1] Overflow stack: [0xff600000ffdad070..0xff600000ffdae070]
[    8.590133][    T1] CPU: 1 UID: 0 PID: 1 Comm: systemd Not tainted 6.18.0-rc5+ #15 PREEMPT(voluntary)  c900881ed1c1988ec5cf3e914d0edeb1b4d83ca3
[    8.590898][    T1] Hardware name: riscv-virtio qemu/qemu, BIOS 2025.10 10/01/2025
[    8.591494][    T1] epc : copy_from_kernel_nofault+0xa/0x198
[    8.592292][    T1]  ra : bpf_probe_read_kernel+0x20/0x60
[    8.592658][    T1] epc : ffffffff802b732a ra : ffffffff801e6070 sp : ff2000000000ffe0
[    8.593121][    T1]  gp : ffffffff82262ed0 tp : 0000000000000000 t0 : ffffffff80022320
[    8.593566][    T1]  t1 : ffffffff801e6056 t2 : 0000000000000000 s0 : ff20000000010040
[    8.593997][    T1]  s1 : 0000000000000008 a0 : ff20000000010050 a1 : ff60000083b3d320
[    8.594446][    T1]  a2 : 0000000000000008 a3 : 0000000000000097 a4 : 0000000000000000
[    8.594940][    T1]  a5 : 0000000000000000 a6 : 0000000000000021 a7 : 0000000000000003
[    8.595396][    T1]  s2 : ff20000000010050 s3 : ff6000008459fc18 s4 : ff60000083b3d340
[    8.595831][    T1]  s5 : ff20000000010060 s6 : 0000000000000000 s7 : ff20000000013aa8
[    8.596215][    T1]  s8 : 0000000000000000 s9 : 0000000000008000 s10: 000000000058dcb0
[    8.596641][    T1]  s11: 000000000058dca7 t3 : 000000006925116d t4 : ff6000008090f026
[    8.597065][    T1]  t5 : 00007fff9b0cbaa8 t6 : 0000000000000016
[    8.597363][    T1] status: 0000000200000120 badaddr: 0000000000000000 cause: 8000000000000005
[    8.598033][    T1] Kernel panic - not syncing: Kernel stack overflow
[    8.598597][    T1] CPU: 1 UID: 0 PID: 1 Comm: systemd Not tainted 6.18.0-rc5+ #15 PREEMPT(voluntary)  c900881ed1c1988ec5cf3e914d0edeb1b4d83ca3
[    8.599244][    T1] Hardware name: riscv-virtio qemu/qemu, BIOS 2025.10 10/01/2025
[    8.599659][    T1] Call Trace:
[    8.600117][    T1] [<ffffffff8001a1f8>] dump_backtrace+0x28/0x38
[    8.600517][    T1] [<ffffffff80002502>] show_stack+0x3a/0x50
[    8.600844][    T1] [<ffffffff800122be>] dump_stack_lvl+0x56/0x80
[    8.601176][    T1] [<ffffffff80012300>] dump_stack+0x18/0x22
[    8.601518][    T1] [<ffffffff80002abe>] vpanic+0xf6/0x328
[    8.601819][    T1] [<ffffffff80002d2e>] panic+0x3e/0x40
[    8.602088][    T1] [<ffffffff80019ef0>] handle_bad_stack+0x98/0xa0
[    8.602395][    T1] [<ffffffff801e6070>] bpf_probe_read_kernel+0x20/0x60

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Re: [PATCH bpf-next v3 3/6] bpf: fix the usage of BPF_TRAMP_F_SKIP_FRAME
Posted by Menglong Dong 1 month, 3 weeks ago
On Thu, Dec 18, 2025 at 10:45 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> On Nov 18 2025, Menglong Dong wrote:
>
> > Some places calculate the origin_call by checking if
> > BPF_TRAMP_F_SKIP_FRAME is set. However, it should use
> > BPF_TRAMP_F_ORIG_STACK for this propose. Just fix them.
> >
> > Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
> > Acked-by: Alexei Starovoitov <ast@kernel.org>
>
> This breaks RISC-V:

It's weird, as the 2 flags should be set together all the time
in RISC-V. Sorry that I'm already in bed, I'll check it tomorrow
morning.

Thanks!
Menglong Dong

>
> [    8.584381][    T1] systemd[1]: bpf-restrict-fs: LSM BPF program attached
> [    8.588359][    T1] Insufficient stack space to handle exception!
> [    8.588823][    T1] Task stack:     [0xff20000000010000..0xff20000000014000]
> [    8.589219][    T1] Overflow stack: [0xff600000ffdad070..0xff600000ffdae070]
> [    8.590133][    T1] CPU: 1 UID: 0 PID: 1 Comm: systemd Not tainted 6.18.0-rc5+ #15 PREEMPT(voluntary)  c900881ed1c1988ec5cf3e914d0edeb1b4d83ca3
> [    8.590898][    T1] Hardware name: riscv-virtio qemu/qemu, BIOS 2025.10 10/01/2025
> [    8.591494][    T1] epc : copy_from_kernel_nofault+0xa/0x198
> [    8.592292][    T1]  ra : bpf_probe_read_kernel+0x20/0x60
> [    8.592658][    T1] epc : ffffffff802b732a ra : ffffffff801e6070 sp : ff2000000000ffe0
> [    8.593121][    T1]  gp : ffffffff82262ed0 tp : 0000000000000000 t0 : ffffffff80022320
> [    8.593566][    T1]  t1 : ffffffff801e6056 t2 : 0000000000000000 s0 : ff20000000010040
> [    8.593997][    T1]  s1 : 0000000000000008 a0 : ff20000000010050 a1 : ff60000083b3d320
> [    8.594446][    T1]  a2 : 0000000000000008 a3 : 0000000000000097 a4 : 0000000000000000
> [    8.594940][    T1]  a5 : 0000000000000000 a6 : 0000000000000021 a7 : 0000000000000003
> [    8.595396][    T1]  s2 : ff20000000010050 s3 : ff6000008459fc18 s4 : ff60000083b3d340
> [    8.595831][    T1]  s5 : ff20000000010060 s6 : 0000000000000000 s7 : ff20000000013aa8
> [    8.596215][    T1]  s8 : 0000000000000000 s9 : 0000000000008000 s10: 000000000058dcb0
> [    8.596641][    T1]  s11: 000000000058dca7 t3 : 000000006925116d t4 : ff6000008090f026
> [    8.597065][    T1]  t5 : 00007fff9b0cbaa8 t6 : 0000000000000016
> [    8.597363][    T1] status: 0000000200000120 badaddr: 0000000000000000 cause: 8000000000000005
> [    8.598033][    T1] Kernel panic - not syncing: Kernel stack overflow
> [    8.598597][    T1] CPU: 1 UID: 0 PID: 1 Comm: systemd Not tainted 6.18.0-rc5+ #15 PREEMPT(voluntary)  c900881ed1c1988ec5cf3e914d0edeb1b4d83ca3
> [    8.599244][    T1] Hardware name: riscv-virtio qemu/qemu, BIOS 2025.10 10/01/2025
> [    8.599659][    T1] Call Trace:
> [    8.600117][    T1] [<ffffffff8001a1f8>] dump_backtrace+0x28/0x38
> [    8.600517][    T1] [<ffffffff80002502>] show_stack+0x3a/0x50
> [    8.600844][    T1] [<ffffffff800122be>] dump_stack_lvl+0x56/0x80
> [    8.601176][    T1] [<ffffffff80012300>] dump_stack+0x18/0x22
> [    8.601518][    T1] [<ffffffff80002abe>] vpanic+0xf6/0x328
> [    8.601819][    T1] [<ffffffff80002d2e>] panic+0x3e/0x40
> [    8.602088][    T1] [<ffffffff80019ef0>] handle_bad_stack+0x98/0xa0
> [    8.602395][    T1] [<ffffffff801e6070>] bpf_probe_read_kernel+0x20/0x60
>
> --
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."
Re: [PATCH bpf-next v3 3/6] bpf: fix the usage of BPF_TRAMP_F_SKIP_FRAME
Posted by Menglong Dong 1 month, 3 weeks ago
On 2025/12/18 22:45 Andreas Schwab <schwab@linux-m68k.org> write:
> On Nov 18 2025, Menglong Dong wrote:
> 
> > Some places calculate the origin_call by checking if
> > BPF_TRAMP_F_SKIP_FRAME is set. However, it should use
> > BPF_TRAMP_F_ORIG_STACK for this propose. Just fix them.
> >
> > Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
> > Acked-by: Alexei Starovoitov <ast@kernel.org>
> 
> This breaks RISC-V:

Hi, Andreas. Can you offer more information here? After my analysis,
I didn't see the problem. BPF_TRAMP_F_SKIP_FRAME and
BPF_TRAMP_F_ORIG_STACK are set together all the time in RISC-V, so
I changed BPF_TRAMP_F_SKIP_FRAME to BPF_TRAMP_F_ORIG_STACK
*should* have no influence.

Thanks!
Menglong Dong

> 
> [    8.584381][    T1] systemd[1]: bpf-restrict-fs: LSM BPF program attached
> [    8.588359][    T1] Insufficient stack space to handle exception!
> [    8.588823][    T1] Task stack:     [0xff20000000010000..0xff20000000014000]
> [    8.589219][    T1] Overflow stack: [0xff600000ffdad070..0xff600000ffdae070]
> [    8.590133][    T1] CPU: 1 UID: 0 PID: 1 Comm: systemd Not tainted 6.18.0-rc5+ #15 PREEMPT(voluntary)  c900881ed1c1988ec5cf3e914d0edeb1b4d83ca3
> [    8.590898][    T1] Hardware name: riscv-virtio qemu/qemu, BIOS 2025.10 10/01/2025
> [    8.591494][    T1] epc : copy_from_kernel_nofault+0xa/0x198
> [    8.592292][    T1]  ra : bpf_probe_read_kernel+0x20/0x60
> [    8.592658][    T1] epc : ffffffff802b732a ra : ffffffff801e6070 sp : ff2000000000ffe0
> [    8.593121][    T1]  gp : ffffffff82262ed0 tp : 0000000000000000 t0 : ffffffff80022320
> [    8.593566][    T1]  t1 : ffffffff801e6056 t2 : 0000000000000000 s0 : ff20000000010040
> [    8.593997][    T1]  s1 : 0000000000000008 a0 : ff20000000010050 a1 : ff60000083b3d320
> [    8.594446][    T1]  a2 : 0000000000000008 a3 : 0000000000000097 a4 : 0000000000000000
> [    8.594940][    T1]  a5 : 0000000000000000 a6 : 0000000000000021 a7 : 0000000000000003
> [    8.595396][    T1]  s2 : ff20000000010050 s3 : ff6000008459fc18 s4 : ff60000083b3d340
> [    8.595831][    T1]  s5 : ff20000000010060 s6 : 0000000000000000 s7 : ff20000000013aa8
> [    8.596215][    T1]  s8 : 0000000000000000 s9 : 0000000000008000 s10: 000000000058dcb0
> [    8.596641][    T1]  s11: 000000000058dca7 t3 : 000000006925116d t4 : ff6000008090f026
> [    8.597065][    T1]  t5 : 00007fff9b0cbaa8 t6 : 0000000000000016
> [    8.597363][    T1] status: 0000000200000120 badaddr: 0000000000000000 cause: 8000000000000005
> [    8.598033][    T1] Kernel panic - not syncing: Kernel stack overflow
> [    8.598597][    T1] CPU: 1 UID: 0 PID: 1 Comm: systemd Not tainted 6.18.0-rc5+ #15 PREEMPT(voluntary)  c900881ed1c1988ec5cf3e914d0edeb1b4d83ca3
> [    8.599244][    T1] Hardware name: riscv-virtio qemu/qemu, BIOS 2025.10 10/01/2025
> [    8.599659][    T1] Call Trace:
> [    8.600117][    T1] [<ffffffff8001a1f8>] dump_backtrace+0x28/0x38
> [    8.600517][    T1] [<ffffffff80002502>] show_stack+0x3a/0x50
> [    8.600844][    T1] [<ffffffff800122be>] dump_stack_lvl+0x56/0x80
> [    8.601176][    T1] [<ffffffff80012300>] dump_stack+0x18/0x22
> [    8.601518][    T1] [<ffffffff80002abe>] vpanic+0xf6/0x328
> [    8.601819][    T1] [<ffffffff80002d2e>] panic+0x3e/0x40
> [    8.602088][    T1] [<ffffffff80019ef0>] handle_bad_stack+0x98/0xa0
> [    8.602395][    T1] [<ffffffff801e6070>] bpf_probe_read_kernel+0x20/0x60
> 
> -- 
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."
> 
>
Re: [PATCH bpf-next v3 3/6] bpf: fix the usage of BPF_TRAMP_F_SKIP_FRAME
Posted by Andreas Schwab 1 month, 3 weeks ago
On Dez 19 2025, Menglong Dong wrote:

> BPF_TRAMP_F_ORIG_STACK

How can that ever be set?

	if (flags & (BPF_TRAMP_F_ORIG_STACK | BPF_TRAMP_F_SHARE_IPMODIFY))
		return -ENOTSUPP;

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Re: [PATCH bpf-next v3 3/6] bpf: fix the usage of BPF_TRAMP_F_SKIP_FRAME
Posted by Menglong Dong 1 month, 3 weeks ago
On 2025/12/19 19:41, Andreas Schwab wrote:
> On Dez 19 2025, Menglong Dong wrote:
> 
> > BPF_TRAMP_F_ORIG_STACK
> 
> How can that ever be set?

Oops, my bad! It should be BPF_TRAMP_F_CALL_ORIG here. I think
it is some kind of copy-paste mistake. I'll send a fix for it.

Thanks!
Menglong Dong

> 
> 	if (flags & (BPF_TRAMP_F_ORIG_STACK | BPF_TRAMP_F_SHARE_IPMODIFY))
> 		return -ENOTSUPP;
> 
>
Re: [PATCH bpf-next v3 3/6] bpf: fix the usage of BPF_TRAMP_F_SKIP_FRAME
Posted by Menglong Dong 1 month, 3 weeks ago
On 2025/12/19 20:27, Menglong Dong wrote:
> On 2025/12/19 19:41, Andreas Schwab wrote:
> > On Dez 19 2025, Menglong Dong wrote:
> > 
> > > BPF_TRAMP_F_ORIG_STACK
> > 
> > How can that ever be set?
> 
> Oops, my bad! It should be BPF_TRAMP_F_CALL_ORIG here. I think
> it is some kind of copy-paste mistake. I'll send a fix for it.

I sent the following patch twice, but I didn't see it in the
mail list. I suspect there is something wrong with my gmail.

Hi, Alexei. Can you see my patch?

-->patch<--

From 5dbae5dcba3aa7fa10e506e9fd1a28a6802d9b00 Mon Sep 17 00:00:00 2001
From: Menglong Dong <dongml2@chinatelecom.cn>
Date: Fri, 19 Dec 2025 20:33:10 +0800
Subject: [PATCH RESEND bpf] riscv, bpf: fix incorrect usage of BPF_TRAMP_F_ORIG_STACK

The usage of BPF_TRAMP_F_ORIG_STACK in __arch_prepare_bpf_trampoline() is
wrong, and it should be BPF_TRAMP_F_CALL_ORIG, which caused crash as
Andreas reported:

  Insufficient stack space to handle exception!
  Task stack:     [0xff20000000010000..0xff20000000014000]
  Overflow stack: [0xff600000ffdad070..0xff600000ffdae070]
  CPU: 1 UID: 0 PID: 1 Comm: systemd Not tainted 6.18.0-rc5+ #15 PREEMPT(voluntary)
  Hardware name: riscv-virtio qemu/qemu, BIOS 2025.10 10/01/2025
  epc : copy_from_kernel_nofault+0xa/0x198
   ra : bpf_probe_read_kernel+0x20/0x60
  epc : ffffffff802b732a ra : ffffffff801e6070 sp : ff2000000000ffe0
   gp : ffffffff82262ed0 tp : 0000000000000000 t0 : ffffffff80022320
   t1 : ffffffff801e6056 t2 : 0000000000000000 s0 : ff20000000010040
   s1 : 0000000000000008 a0 : ff20000000010050 a1 : ff60000083b3d320
   a2 : 0000000000000008 a3 : 0000000000000097 a4 : 0000000000000000
   a5 : 0000000000000000 a6 : 0000000000000021 a7 : 0000000000000003
   s2 : ff20000000010050 s3 : ff6000008459fc18 s4 : ff60000083b3d340
   s5 : ff20000000010060 s6 : 0000000000000000 s7 : ff20000000013aa8
   s8 : 0000000000000000 s9 : 0000000000008000 s10: 000000000058dcb0
   s11: 000000000058dca7 t3 : 000000006925116d t4 : ff6000008090f026
   t5 : 00007fff9b0cbaa8 t6 : 0000000000000016
  status: 0000000200000120 badaddr: 0000000000000000 cause: 8000000000000005
  Kernel panic - not syncing: Kernel stack overflow
  CPU: 1 UID: 0 PID: 1 Comm: systemd Not tainted 6.18.0-rc5+ #15 PREEMPT(voluntary)
  Hardware name: riscv-virtio qemu/qemu, BIOS 2025.10 10/01/2025
  Call Trace:
  [<ffffffff8001a1f8>] dump_backtrace+0x28/0x38
  [<ffffffff80002502>] show_stack+0x3a/0x50
  [<ffffffff800122be>] dump_stack_lvl+0x56/0x80
  [<ffffffff80012300>] dump_stack+0x18/0x22
  [<ffffffff80002abe>] vpanic+0xf6/0x328
  [<ffffffff80002d2e>] panic+0x3e/0x40
  [<ffffffff80019ef0>] handle_bad_stack+0x98/0xa0
  [<ffffffff801e6070>] bpf_probe_read_kernel+0x20/0x60

Just fix it.

Fixes: 47c9214dcbea ("bpf: fix the usage of BPF_TRAMP_F_SKIP_FRAME")
Reported-by: Andreas Schwab <schwab@linux-m68k.org>
Closes: https://lore.kernel.org/bpf/874ipnkfvt.fsf@igel.home/
Signed-off-by: Menglong Dong <dongml2@chinatelecom.cn>
---
 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 5f9457e910e8..09b70bf362d3 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -1134,7 +1134,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
 	store_args(nr_arg_slots, args_off, ctx);
 
 	/* skip to actual body of traced function */
-	if (flags & BPF_TRAMP_F_ORIG_STACK)
+	if (flags & BPF_TRAMP_F_CALL_ORIG)
 		orig_call += RV_FENTRY_NINSNS * 4;
 
 	if (flags & BPF_TRAMP_F_CALL_ORIG) {
-- 
2.52.0

--<patch>--

> 
> Thanks!
> Menglong Dong
> 
> > 
> > 	if (flags & (BPF_TRAMP_F_ORIG_STACK | BPF_TRAMP_F_SHARE_IPMODIFY))
> > 		return -ENOTSUPP;
> > 
> > 
> 
> 
> 
> 
> 
>
Re: [PATCH bpf-next v3 3/6] bpf: fix the usage of BPF_TRAMP_F_SKIP_FRAME
Posted by Andreas Schwab 1 month, 3 weeks ago
On Dez 19 2025, Menglong Dong wrote:

> diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
> index 5f9457e910e8..09b70bf362d3 100644
> --- a/arch/riscv/net/bpf_jit_comp64.c
> +++ b/arch/riscv/net/bpf_jit_comp64.c
> @@ -1134,7 +1134,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
>  	store_args(nr_arg_slots, args_off, ctx);
>  
>  	/* skip to actual body of traced function */
> -	if (flags & BPF_TRAMP_F_ORIG_STACK)
> +	if (flags & BPF_TRAMP_F_CALL_ORIG)
>  		orig_call += RV_FENTRY_NINSNS * 4;

There are now three occurrences of that condition, and only the third
one uses orig_call.  How about merging them?

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Re: [PATCH bpf-next v3 3/6] bpf: fix the usage of BPF_TRAMP_F_SKIP_FRAME
Posted by Menglong Dong 1 month, 3 weeks ago
On Fri, Dec 19, 2025 at 9:49 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> On Dez 19 2025, Menglong Dong wrote:
>
> > diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
> > index 5f9457e910e8..09b70bf362d3 100644
> > --- a/arch/riscv/net/bpf_jit_comp64.c
> > +++ b/arch/riscv/net/bpf_jit_comp64.c
> > @@ -1134,7 +1134,7 @@ static int __arch_prepare_bpf_trampoline(struct bpf_tramp_image *im,
> >       store_args(nr_arg_slots, args_off, ctx);
> >
> >       /* skip to actual body of traced function */
> > -     if (flags & BPF_TRAMP_F_ORIG_STACK)
> > +     if (flags & BPF_TRAMP_F_CALL_ORIG)
> >               orig_call += RV_FENTRY_NINSNS * 4;
>
> There are now three occurrences of that condition, and only the third
> one uses orig_call.  How about merging them?

Yeah, I think we can merge it to the third one, like this:

diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c
index 5f9457e910e8..37888abee70c 100644
--- a/arch/riscv/net/bpf_jit_comp64.c
+++ b/arch/riscv/net/bpf_jit_comp64.c
@@ -1133,10 +1133,6 @@ static int __arch_prepare_bpf_trampoline(struct
bpf_tramp_image *im,

        store_args(nr_arg_slots, args_off, ctx);

-       /* skip to actual body of traced function */
-       if (flags & BPF_TRAMP_F_ORIG_STACK)
-               orig_call += RV_FENTRY_NINSNS * 4;
-
        if (flags & BPF_TRAMP_F_CALL_ORIG) {
                emit_imm(RV_REG_A0, ctx->insns ? (const s64)im :
RV_MAX_COUNT_IMM, ctx);
                ret = emit_call((const u64)__bpf_tramp_enter, true, ctx);
@@ -1171,6 +1167,8 @@ static int __arch_prepare_bpf_trampoline(struct
bpf_tramp_image *im,
        }

        if (flags & BPF_TRAMP_F_CALL_ORIG) {
+               /* skip to actual body of traced function */
+               orig_call += RV_FENTRY_NINSNS * 4;
                restore_args(min_t(int, nr_arg_slots,
RV_MAX_REG_ARGS), args_off, ctx);
                restore_stack_args(nr_arg_slots - RV_MAX_REG_ARGS,
args_off, stk_arg_off, ctx);
                ret = emit_call((const u64)orig_call, true, ctx);

>
> --
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."
Re: [PATCH bpf-next v3 3/6] bpf: fix the usage of BPF_TRAMP_F_SKIP_FRAME
Posted by Andreas Schwab 1 month, 3 weeks ago
On Dez 19 2025, Menglong Dong wrote:

> @@ -1171,6 +1167,8 @@ static int __arch_prepare_bpf_trampoline(struct
> bpf_tramp_image *im,
>         }
>
>         if (flags & BPF_TRAMP_F_CALL_ORIG) {
> +               /* skip to actual body of traced function */
> +               orig_call += RV_FENTRY_NINSNS * 4;

Before this line, orig_call still contains the same value as func_addr,
with the latter being dead, so there is not much point in using a copy.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Re: [PATCH bpf-next v3 3/6] bpf: fix the usage of BPF_TRAMP_F_SKIP_FRAME
Posted by Menglong Dong 1 month, 3 weeks ago
On Fri, Dec 19, 2025 at 10:50 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> On Dez 19 2025, Menglong Dong wrote:
>
> > @@ -1171,6 +1167,8 @@ static int __arch_prepare_bpf_trampoline(struct
> > bpf_tramp_image *im,
> >         }
> >
> >         if (flags & BPF_TRAMP_F_CALL_ORIG) {
> > +               /* skip to actual body of traced function */
> > +               orig_call += RV_FENTRY_NINSNS * 4;
>
> Before this line, orig_call still contains the same value as func_addr,
> with the latter being dead, so there is not much point in using a copy.

Yeah, we can use "func_addr + RV_FENTRY_NINSNS * 4" here directly.

>
> --
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."