libbpf / libbpf-bootstrap

Scaffolding for BPF application development with libbpf and BPF CO-RE
BSD 3-Clause "New" or "Revised" License
1.09k stars 294 forks source link

run fentry examples in Loongarch cpu failed #235

Closed georgejguo closed 5 months ago

georgejguo commented 1 year ago

libbpf version: v1.1.0 bpftool:7.1.0 ARCH: Loongarch

These examples are running well in x86 or arm64. This is new arch, Could you give me advice ? The log is below:

[root@localhost c]# ./fentry !libbpf: loading object 'fentry_bpf' from buffer libbpf: elf: section(2) .symtab, size 240, link 1, flags 0, type=2 libbpf: elf: section(3) fentry/do_unlinkat, size 88, link 0, flags 6, type=1 libbpf: sec 'fentry/do_unlinkat': found program 'do_unlinkat' at insn offset 0 (0 bytes), code size 11 insns (88 bytes) libbpf: elf: section(4) fexit/do_unlinkat, size 104, link 0, flags 6, type=1 libbpf: sec 'fexit/do_unlinkat': found program 'do_unlinkat_exit' at insn offset 0 (0 bytes), code size 13 insns (104 bytes) libbpf: elf: section(5) license, size 13, link 0, flags 3, type=1 libbpf: license of fentry_bpf is Dual BSD/GPL libbpf: elf: section(6) .rodata, size 76, link 0, flags 2, type=1 libbpf: elf: section(7) .relfentry/do_unlinkat, size 16, link 2, flags 0, type=9 libbpf: elf: section(8) .relfexit/do_unlinkat, size 16, link 2, flags 0, type=9 libbpf: elf: section(9) .BTF, size 1095, link 0, flags 0, type=1 libbpf: elf: section(10) .BTF.ext, size 332, link 0, flags 0, type=1 libbpf: looking for externs among 10 symbols... libbpf: collected 0 externs total libbpf: map 'fentry_b.rodata' (global data): at sec_idx 6, offset 0, flags 80. libbpf: map 0 is "fentry_b.rodata" libbpf: sec '.relfentry/do_unlinkat': collecting relocation for section(3) 'fentry/do_unlinkat' libbpf: sec '.relfentry/do_unlinkat': relo #0: insn #4 against '.rodata' libbpf: prog 'do_unlinkat': found data map 0 (fentry_b.rodata, sec 6, off 0) for insn 4 libbpf: sec '.relfexit/do_unlinkat': collecting relocation for section(4) 'fexit/do_unlinkat' libbpf: sec '.relfexit/do_unlinkat': relo #0: insn #5 against '.rodata' libbpf: prog 'do_unlinkat_exit': found data map 0 (fentry_b.rodata, sec 6, off 0) for insn 5 libbpf: loading kernel BTF '/sys/kernel/btf/vmlinux': 0 libbpf: map 'fentry_b.rodata': created successfully, fd=4 libbpf: sec 'fentry/do_unlinkat': found 1 CO-RE relocations libbpf: CO-RE relocating [6] struct filename: found target candidate [7633] struct filename in [vmlinux] libbpf: prog 'do_unlinkat': relo #0: [6] struct filename.name (0:0 @ offset 0) libbpf: prog 'do_unlinkat': relo #0: matching candidate #0 [7633] struct filename.name (0:0 @ offset 0) libbpf: prog 'do_unlinkat': relo #0: patched insn #2 (LDX/ST/STX) off 0 -> 0 libbpf: sec 'fexit/do_unlinkat': found 1 CO-RE relocations libbpf: prog 'do_unlinkat_exit': relo #0: [6] struct filename.name (0:0 @ offset 0) libbpf: prog 'do_unlinkat_exit': relo #0: matching candidate #0 [7633] struct filename.name (0:0 @ offset 0) libbpf: prog 'do_unlinkat_exit': relo #0: patched insn #3 (LDX/ST/STX) off 0 -> 0 libbpf: prog 'do_unlinkat': BPF program load failed: ERROR: strerror_r(524)=22 libbpf: prog 'do_unlinkat': -- BEGIN PROG LOAD LOG -- arg#0 type is not a struct Unrecognized arg#0 type PTR ; int BPF_PROG(do_unlinkat, int dfd, struct filename name) 0: (79) r6 = (u64 )(r1 +8) func 'do_unlinkat' arg1 has btf_id 7633 type STRUCT 'filename' ; pid = bpf_get_current_pid_tgid() >> 32; 1: (85) call bpf_get_current_pid_tgid#14 ; bpf_printk("fentry: pid = %d, filename = %s\n", pid, name->name); 2: (79) r4 = (u64 )(r6 +0) ; pid = bpf_get_current_pid_tgid() >> 32; 3: (77) r0 >>= 32 ; bpf_printk("fentry: pid = %d, filename = %s\n", pid, name->name); 4: (18) r1 = 0x9000202021525d10 6: (b7) r2 = 33 7: (bf) r3 = r0 8: (85) call bpf_trace_printk#6 R0_w=inv(id=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R1_w=map_value(id=0,off=0,ks=4,vs=76,imm=0) R2_w=inv33 R3_w=inv(id=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R4_w=inv(id=0) R6_w=ptr_filename(id=0,off=0,imm=0) R10=fp0 last_idx 8 first_idx 0 regs=4 stack=0 before 7: (bf) r3 = r0 regs=4 stack=0 before 6: (b7) r2 = 33 ; int BPF_PROG(do_unlinkat, int dfd, struct filename name) 9: (b7) r0 = 0 10: (95) exit processed 10 insns (limit 1000000) max_states_per_insn 0 total_states 1 peak_states 1 mark_read 0 -- END PROG LOAD LOG -- libbpf: prog 'do_unlinkat': failed to load: -524 libbpf: failed to load object 'fentry_bpf' libbpf: failed to load BPF skeleton 'fentry_bpf': -524 Failed to open BPF skeleton

anakryiko commented 12 months ago

Probably LoongArch doesn't yet support BPF trampoline-based BPF programs (fentry/fexit). Please check latest kernels to see if such support was already added upstream.

anakryiko commented 11 months ago

I think LoongArch doesn't support BPF trampoline, so fentry/fexit programs won't work on that architecture. You'll have to work with upstream Linux community to add support for BPF trampoline to LoongArch.