xdp-project / xdp-tutorial

XDP tutorial
2.33k stars 562 forks source link

Run basic03 examples failed #353

Closed tengliu0929 closed 1 year ago

tengliu0929 commented 1 year ago

A newer to xdp. When I run basic03-map-counter example, I get some wrong message and can't understand why. I use the command below

./xdp_load_and_stats -d veth-basic02 -F --progsec xdp_stats1

and I got the wrong message

libbpf: Error loading .BTF into kernel: -22. libbpf: load bpf program failed: Invalid argument libbpf: -- BEGIN DUMP LOG --- libbpf: unknown opcode 8d processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0 libbpf: -- END LOG -- libbpf: failed to load program 'xdp_stats1' libbpf: failed to load object 'xdp_prog_kern.o' ERR: loading BPF-OBJ file(xdp_prog_kern.o) (-22): Invalid argument ERR: loading file: xdp_prog_kern.o Also, I use the ulimit command ulimit -l ulimited to change max locked memory. I suppose this can't create map. Need help,

tohojo commented 1 year ago

Which kernel and compiler versions are you using? Did you do a submodule update --init in the root directory before compiling?

tengliu0929 commented 1 year ago

Which kernel and compiler versions are you using? Did you do a submodule update --init in the root directory before compiling? Yes, I do. I run the first basic example and second basic example success on my virtual machine. And I google this problem, not find any valid information for solving this.

tengliu0929 commented 1 year ago

Which kernel and compiler versions are you using? Did you do a submodule update --init in the root directory before compiling? I tried to rerun testenv.sh to setup a new veth NIC, and run the basic3 example, I got the invalid arg , as show below

libbpf: Error loading BTF: Invalid argument(22) libbpf: magic: 0xeb9f version: 1 flags: 0x0 hdr_len: 24 type_off: 0 type_len: 484 str_off: 484 str_len: 533 btf_total_size: 1041 [1] FUNC_PROTO (anon) return=2 args=(3 (anon)) [2] INT int size=4 bits_offset=0 nr_bits=32 encoding=SIGNED [3] PTR (anon) type_id=4 [4] STRUCT xdp_md size=20 vlen=5 data type_id=5 bits_offset=0 data_end type_id=5 bits_offset=32 data_meta type_id=5 bits_offset=64 ingress_ifindex type_id=5 bits_offset=96 rx_queue_index type_id=5 bits_offset=128 [5] TYPEDEF u32 type_id=6 [6] INT unsigned int size=4 bits_offset=0 nr_bits=32 encoding=(none) [7] FUNC xdp_stats1_func type_id=1 [8] STRUCT bpf_map_def size=20 vlen=5 type type_id=6 bits_offset=0 key_size type_id=6 bits_offset=32 value_size type_id=6 bits_offset=64 max_entries type_id=6 bits_offset=96 map_flags type_id=6 bits_offset=128 [9] VAR xdp_stats_map type_id=8 linkage=1 [10] PTR (anon) type_id=11 [11] FUNC_PROTO (anon) return=12 args=(12 (anon), 13 (anon)) [12] PTR (anon) type_id=0 [13] PTR (anon) type_id=14 [14] CONST (anon) type_id=0 [15] VAR bpf_map_lookup_elem type_id=10 linkage=0 [16] INT char size=1 bits_offset=0 nr_bits=8 encoding=SIGNED [17] ARRAY (anon) type_id=16 index_type_id=18 nr_elems=4 [18] INT ARRAY_SIZE_TYPE__ size=4 bits_offset=0 nr_bits=32 encoding=(none) [19] VAR _license type_id=17 linkage=1 [20] DATASEC .data size=8 vlen=1 type_id=15 offset=0 size=8 [21] DATASEC license size=4 vlen=1 type_id=19 offset=0 size=4 [22] DATASEC maps size=20 vlen=1 type_id=9 offset=0 size=20 [7] FUNC xdp_stats1_func type_id=1 Invalid arg#1 libbpf: Error loading .BTF into kernel: -22. libbpf: load bpf program failed: Invalid argument libbpf: -- BEGIN DUMP LOG --- libbpf: unknown opcode 8d processed 0 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0 libbpf: -- END LOG -- libbpf: failed to load program 'xdp_stats1' libbpf: failed to load object 'xdp_prog_kern.o' ERR: loading BPF-OBJ file(xdp_prog_kern.o) (-22): Invalid argument ERR: loading file: xdp_prog_kern.o

The up section shows [7] FUNC xdp_stats1_func type_id=1 Invalid arg#1 .

The command I used : ./xdp_load_and_stats -d veth3 -F --force --progsec xdp_stats1 The kernel version: 5.15.0-60-generic My clang version: clang version 10.0.0-4ubuntu1 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin My gcc version: gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)

tengliu0929 commented 1 year ago

I've solved this problem by compiling the program with "O2" not with "-g -O0", I can not understand why couldn't use "-g -O0" option to compile the basic example which show the usage of map