LoongArch: BPF: Use move_addr() for BPF_PSEUDO_FUNC
Subsystems (3)
Hengqi Chen
reviewerPATCH 1/1 LoongArch: BPF: Use move_addr() for BPF_PSEUDO_FUNC
Vincent reported that running XDP synproxy program on LoongArch results in the following error:
JIT doesn't support bpf-to-bpf calls
With dmesg:
multi-func JIT bug 1391 != 1390
The root cause is that verifier will refill the imm with the correct addresses of bpf_calls for BPF_PSEUDO_FUNC instructions and then run the last pass of JIT. So we generate different JIT code for the same instruction in two passes (one for placeholder and one for real address). Let's use move_addr() instead.
See commit 64f50f657572 ("LoongArch, bpf: Use 4 instructions for
function address in JIT") for a similar fix.
--- arch/loongarch/net/bpf_jit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
arch/loongarch/net/bpf_jit.c +4 -1
@@ -930,7 +930,10 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext {const u64 imm64 = (u64)(insn +1 )->imm <<32 | (u32 )insn->imm; -move_imm (ctx, dst, imm64, is32); +if (bpf_pseudo_func (insn)) +move_addr (ctx, dst, imm64); +else +move_imm (ctx, dst, imm64, is32);return 1 ; }
Signature · 1 line
2.43.5
Quoted 42 lines · Hengqi Chen
Vincent reported that running XDP synproxy program on LoongArch results in the following error:
JIT doesn't support bpf-to-bpf calls
With dmesg:multi-func JIT bug 1391 != 1390The root cause is that verifier will refill the imm with the correct addresses of
bpf_callsforBPF_PSEUDO_FUNCinstructions and then run the last pass of JIT. So we generate different JIT code for the same instruction in two passes (one for placeholder and one for real address). Let's usemove_addr()instead.See commit
64f50f657572("LoongArch, bpf: Use 4 instructions for
function address in JIT") for a similar fix.Fixes 69c087ba6225 ("bpf: Add bpf_for_each_map_elem() helper")Fixes bb035ef0cc91 ("LoongArch: BPF: Support mixing bpf2bpf and tailcalls")Reported-by Vincent Li <[email protected]>Closes https://lore.kernel.org/loongarch/CAK3+h2yfM9FTNiXvEQBkvtuoJrvzmN4c_NZsFXqEk4Cj1tsBNA@mail.gmail.com/T/#u open hereSigned-off-by Hengqi Chen <[email protected]>--- arch/loongarch/net/bpf_jit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)arch/loongarch/net/bpf_jit.c +4
-2@@ -930,7 +930,10 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext {const u64 imm64 = (u64)(insn +1 )->imm <<32 | (u32 )insn->imm; -move_imm (ctx, dst, imm64, is32); +if (bpf_pseudo_func (insn)) +move_addr (ctx, dst, imm64); +else +move_imm (ctx, dst, imm64, is32);return 1 ; } --
Quoted 2 lines
2.43.5
Thanks Hengqi for the quick fix! tested and verified working now.
[root@fedora xdp-tools]# uname -a
Linux fedora 6.14.0-rc5 #2 SMP PREEMPT_DYNAMIC Sun Mar 16 17:16:21 PDT 2025 loongarch64 GNU/Linux
[root@fedora xdp-tools]# ./xdp-loader/xdp-loader load -vvv lo -m skb -P 80 -p /sys/fs/bpf/xdp-synproxy-tailcall -n synproxy_tailcall ./xdp-synproxy-tailcall/xdp_synproxy_tailcall.bpf.o
Current rlimit 8388608 already >= minimum 1048576
Loading 1 files on interface 'lo'.
libbpf: loading object from./xdp-synproxy-tailcall/xdp_synproxy_tailcall.bpf.o
...
libbpf: map 'tail_call_tbl': created successfully, fd=4
libbpf: pinned map '/sys/fs/bpf/xdp-synproxy-tailcall/tail_call_tbl'
libbpf: found no pinned map to reuse at
'/sys/fs/bpf/xdp-synproxy-tailcall/values'
libbpf: map 'values': created successfully, fd=5
libbpf: pinned map '/sys/fs/bpf/xdp-synproxy-tailcall/values'
libbpf: found no pinned map to reuse at
'/sys/fs/bpf/xdp-synproxy-tailcall/allowed_ports'
libbpf: map 'allowed_ports': created successfully, fd=6
libbpf: pinned map '/sys/fs/bpf/xdp-synproxy-tailcall/allowed_ports'
libbpf: map 'xdp_synp.rodata': created successfully, fd=7
libbpf: map 'tail_call_tbl': slot [0] set to prog 'syncookie_xdp' fd=65
libxdp: Loaded XDP program synproxy_tailcall, got fd 66
libxdp: Duplicated fd 66 to 3 for prog synproxy_tailcall
libxdp: Replacing XDP fd -1 with 3 on ifindex 1
[root@fedora xdp-tools]# bpftool prog
...
55: xdp name syncookie_xdp tag 1426f5e6593da050 gpl loaded_at 2025-03-16T19:38:49-0700 uid 0
xlated 8392B jited 6412B memlock 16384B map_ids 11,10,12 btf_id 75
56: xdp name synproxy_tailcall tag 0433e599459b925f gpl loaded_at 2025-03-16T19:38:49-0700 uid 0
xlated 192B jited 328B memlock 16384B map_ids 9,12 btf_id 75
Vincent Li
Tested-byQuoted 84 lines · Vincent Li
Quoted 42 lines · Hengqi Chen
Vincent reported that running XDP synproxy program on LoongArch results in the following error:
JIT doesn't support bpf-to-bpf calls
With dmesg:multi-func JIT bug 1391 != 1390The root cause is that verifier will refill the imm with the correct addresses of
bpf_callsforBPF_PSEUDO_FUNCinstructions and then run the last pass of JIT. So we generate different JIT code for the same instruction in two passes (one for placeholder and one for real address). Let's usemove_addr()instead.See commit
64f50f657572("LoongArch, bpf: Use 4 instructions for
function address in JIT") for a similar fix.Fixes 69c087ba6225 ("bpf: Add bpf_for_each_map_elem() helper")Fixes bb035ef0cc91 ("LoongArch: BPF: Support mixing bpf2bpf and tailcalls")Reported-by Vincent Li <[email protected]>Closes https://lore.kernel.org/loongarch/CAK3+h2yfM9FTNiXvEQBkvtuoJrvzmN4c_NZsFXqEk4Cj1tsBNA@mail.gmail.com/T/#u open hereSigned-off-by Hengqi Chen <[email protected]>--- arch/loongarch/net/bpf_jit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)arch/loongarch/net/bpf_jit.c +4
-2@@ -930,7 +930,10 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext {const u64 imm64 = (u64)(insn +1 )->imm <<32 | (u32 )insn->imm; -move_imm (ctx, dst, imm64, is32); +if (bpf_pseudo_func (insn)) +move_addr (ctx, dst, imm64); +else +move_imm (ctx, dst, imm64, is32);return 1 ; } --Quoted 2 lines
2.43.5
Thanks Hengqi for the quick fix! tested and verified working now.
[root@fedora xdp-tools]# uname -a
Linux fedora 6.14.0-rc5 #2 SMPPREEMPT_DYNAMICSun Mar 16 17:16:21 PDT 2025 loongarch64 GNU/Linux[root@fedora xdp-tools]# ./xdp-loader/xdp-loader load -vvv lo -m skb -P 80 -p
/sys/fs/bpf/xdp-synproxy-tailcall-nsynproxy_tailcall./xdp-synproxy-tailcall/xdp_synproxy_tailcall.bpf.o
Current rlimit 8388608 already >= minimum 1048576
Loading 1 files on interface 'lo'.
libbpf: loading object from./xdp-synproxy-tailcall/xdp_synproxy_tailcall.bpf.o
...
libbpf: map 'tail_call_tbl': created successfully, fd=4
libbpf: pinned map '/sys/fs/bpf/xdp-synproxy-tailcall/tail_call_tbl'
libbpf: found no pinned map to reuse at
'/sys/fs/bpf/xdp-synproxy-tailcall/values'
libbpf: map 'values': created successfully, fd=5
libbpf: pinned map '/sys/fs/bpf/xdp-synproxy-tailcall/values'
libbpf: found no pinned map to reuse at
'/sys/fs/bpf/xdp-synproxy-tailcall/allowed_ports'
libbpf: map 'allowed_ports': created successfully, fd=6
libbpf: pinned map '/sys/fs/bpf/xdp-synproxy-tailcall/allowed_ports'
libbpf: map 'xdp_synp.rodata': created successfully, fd=7
libbpf: map 'tail_call_tbl': slot [0] set to prog 'syncookie_xdp' fd=65
libxdp: Loaded XDP programsynproxy_tailcall, got fd 66
libxdp: Duplicated fd 66 to 3 for progsynproxy_tailcall
libxdp: Replacing XDP fd -1 with 3 on ifindex 1[root@fedora xdp-tools]# bpftool prog
...
55: xdp namesyncookie_xdptag1426f5e6593da050gplloaded_at2025-03-16T19:38:49-0700 uid 0
xlated 8392B jited 6412B memlock 16384Bmap_ids11,10,12btf_id75
Quoted 4 lines
56: xdp name
synproxy_tailcalltag0433e599459b925fgplloaded_at2025-03-16T19:38:49-0700 uid 0
xlated 192B jited 328B memlock 16384Bmap_ids9,12btf_id75
Sorry missed the Tested-by, you can add:
Applied, thanks.
Huacai
Quoted 45 lines · Hengqi Chen
Vincent reported that running XDP synproxy program on LoongArch results in the following error:
JIT doesn't support bpf-to-bpf calls
With dmesg:multi-func JIT bug 1391 != 1390The root cause is that verifier will refill the imm with the correct addresses of
bpf_callsforBPF_PSEUDO_FUNCinstructions and then run the last pass of JIT. So we generate different JIT code for the same instruction in two passes (one for placeholder and one for real address). Let's usemove_addr()instead.See commit
64f50f657572("LoongArch, bpf: Use 4 instructions for
function address in JIT") for a similar fix.Fixes 69c087ba6225 ("bpf: Add bpf_for_each_map_elem() helper")Fixes bb035ef0cc91 ("LoongArch: BPF: Support mixing bpf2bpf and tailcalls")Reported-by Vincent Li <[email protected]>Closes https://lore.kernel.org/loongarch/CAK3+h2yfM9FTNiXvEQBkvtuoJrvzmN4c_NZsFXqEk4Cj1tsBNA@mail.gmail.com/T/#u open hereSigned-off-by Hengqi Chen <[email protected]>--- arch/loongarch/net/bpf_jit.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)arch/loongarch/net/bpf_jit.c +4
-2@@ -930,7 +930,10 @@ static int build_insn(const struct bpf_insn *insn, struct jit_ctx *ctx, bool ext {const u64 imm64 = (u64)(insn +1 )->imm <<32 | (u32 )insn->imm; -move_imm (ctx, dst, imm64, is32); +if (bpf_pseudo_func (insn)) +move_addr (ctx, dst, imm64); +else +move_imm (ctx, dst, imm64, is32);return 1 ; } --2.43.5