xdp-tutorial icon indicating copy to clipboard operation
xdp-tutorial copied to clipboard

Error: virtio_net: XDP expects header/data in single page, any_header_sg required.

Open gitsmiles opened this issue 2 years ago • 3 comments

1、code like this: #include <linux/bpf.h>

#define SEC(NAME) attribute((section(NAME), used)) SEC("xdp") int xdp_drop_the_world(struct xdp_md *ctx) { // drop everything return XDP_DROP; } char _license[] SEC("license") = "GPL";

2、ubuntu@demo:~$ clang -O2 -target bpf -c ping_drop.c -o ping_drop.o ubuntu@demo:~$ readelf -a ping_drop.o ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: REL (Relocatable file) Machine: Linux BPF Version: 0x1 Entry point address: 0x0 Start of program headers: 0 (bytes into file) Start of section headers: 272 (bytes into file) Flags: 0x0 Size of this header: 64 (bytes) Size of program headers: 0 (bytes) Number of program headers: 0 Size of section headers: 64 (bytes) Number of section headers: 7 Section header string table index: 1

Section Headers: [Nr] Name Type Address Offset Size EntSize Flags Link Info Align [ 0] NULL 0000000000000000 00000000 0000000000000000 0000000000000000 0 0 0 [ 1] .strtab STRTAB 0000000000000000 000000ba 0000000000000051 0000000000000000 0 0 1 [ 2] .text PROGBITS 0000000000000000 00000040 0000000000000000 0000000000000000 AX 0 0 4 [ 3] xdp PROGBITS 0000000000000000 00000040 0000000000000010 0000000000000000 AX 0 0 8 [ 4] license PROGBITS 0000000000000000 00000050 0000000000000004 0000000000000000 WA 0 0 1 [ 5] .llvm_addrsig LOOS+0xfff4c03 0000000000000000 000000b8 0000000000000002 0000000000000000 E 6 0 1 [ 6] .symtab SYMTAB 0000000000000000 00000058 0000000000000060 0000000000000018 1 2 8 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), p (processor specific)

There are no section groups in this file.

There are no program headers in this file.

There is no dynamic section in this file.

There are no relocations in this file.

The decoding of unwind sections for machine type Linux BPF is not currently supported.

Symbol table '.symtab' contains 4 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS ping_drop.c 2: 0000000000000000 4 OBJECT GLOBAL DEFAULT 4 _license 3: 0000000000000000 16 FUNC GLOBAL DEFAULT 3 xdp_drop_the_world

No version information found in this file.

3、ubuntu@demo:~$ sudo -E ip link set dev enp0s2 xdp object ping_drop.o section xdp Error: virtio_net: XDP expects header/data in single page, any_header_sg required.

gitsmiles avatar Mar 09 '22 06:03 gitsmiles

gitsmiles @.***> writes:

@.***:~$ sudo -E ip link set dev enp0s2 xdp object ping_drop.o section xdp Error: virtio_net: XDP expects header/data in single page, any_header_sg required.

This error message is coming from the virtio driver:

https://elixir.bootlin.com/linux/latest/source/drivers/net/virtio_net.c#L2537

I guess it's some kind of configuration issue (of the virtio system)? Seems to be gated on some feature bits:

https://elixir.bootlin.com/linux/latest/source/drivers/net/virtio_net.c#L3213

No idea what it takes to get those bits flipped, though...

tohojo avatar Mar 09 '22 11:03 tohojo

int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags) When link xdp for virtio_net, flags = XDP_FLAGS_SKB_MODE, instead of XDP_FLAGS_UPDATE_IF_NOEXIST

SoonyangZhang avatar Dec 29 '23 01:12 SoonyangZhang

zsy @.***> writes:

int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags) When link xdp for virtio_net, flags = XDP_FLAGS_SKB_MODE, instead of XDP_FLAGS_UPDATE_IF_NOEXIST

This will attach in generic mode, though, which won't achieve the same performance; might as well use the TC hook in that case...

tohojo avatar Jan 02 '24 19:01 tohojo