eBPF RSS support for virtio-net
Subsystems (2)
v2 cover eBPF RSS support for virtio-net
This set of patches introduces the usage of eBPF for packet steering and RSS hash calculation:
* RSS(Receive Side Scaling) is used to distribute network packets to guest virtqueues by calculating packet hash
* Additionally adding support for the usage of RSS with vhost
The eBPF works on kernels 5.8+
On earlier kerneld it fails to load and the RSS feature is reported only without vhost and implemented in 'in-qemu' software.
Implementation notes:
Linux TAP TUNSETSTEERINGEBPF ioctl was used to set the eBPF program. Added libbpf dependency and eBPF support.
The eBPF program is part of the qemu and presented as an array of BPF ELF file data.
The compilation of eBPF is not part of QEMU build and can be done using provided Makefile.ebpf(need to adjust 'linuxhdrs').
Added changes to virtio-net and vhost, primary eBPF RSS is used. 'in-qemu' RSS used in the case of hash population and as a fallback option. For vhost, the hash population feature is not reported to the guest.
Please also see the documentation in PATCH 5/5.
I am sending those patches as RFC to initiate the discussions and get feedback on the following points:
* Fallback when eBPF is not supported by the kernel
* Live migration to the kernel that doesn't have eBPF support
* Integration with current QEMU build
* Additional usage for eBPF for packet filtering
Known issues:
* hash population not supported by eBPF RSS: 'in-qemu' RSS used
as a fallback, also, hash population feature is not reported to guests with vhost.
* big-endian BPF support: for now, eBPF isn't supported on
big-endian systems. Can be added in future if required.
* huge .h file with eBPF binary. The size of .h file containing
eBPF binary is currently ~5K lines, because the binary is built with debug information. The binary without debug/BTF info can't be loaded by libbpf.
We're looking for possibilities to reduce the size of the .h files.
Changes since v1:
* using libbpf instead of direct 'bpf' system call.
* added libbpf dependency to the configure/meson scripts.
* changed python script for eBPF .h file generation.
* changed eBPF program - reading L3 proto from ethernet frame.
* added TUNSETSTEERINGEBPF define for TUN.
* changed the maintainer's info.
* added license headers.
* refactored code.
Andrew (5):
net: Added SetSteeringEBPF method for NetClientState.
ebpf: Added eBPF RSS program.
ebpf: Added eBPF RSS loader.
virtio-net: Added eBPF RSS to virtio-net.
docs: Added eBPF RSS documentation.
MAINTAINERS | 7 + configure | 33 + docs/ebpf_rss.rst | 133 + ebpf/EbpfElf_to_C.py | 36 + ebpf/Makefile.ebpf | 33 + ebpf/ebpf_rss-stub.c | 40 + ebpf/ebpf_rss.c | 186 ++ ebpf/ebpf_rss.h | 44 + ebpf/meson.build | 1 + ebpf/rss.bpf.c | 505 +++ ebpf/tun_rss_steering.h | 5439 ++++++++++++++++++++++++++++++++ hw/net/vhost_net.c | 2 + hw/net/virtio-net.c | 120 +- include/hw/virtio/virtio-net.h | 4 + include/net/net.h | 2 + meson.build | 11 + net/tap-bsd.c | 5 + net/tap-linux.c | 13 + net/tap-linux.h | 1 + net/tap-solaris.c | 5 + net/tap-stub.c | 5 + net/tap.c | 9 + net/tap_int.h | 1 + net/vhost-vdpa.c | 2 + 24 files changed, 6633 insertions(+), 4 deletions(-) create mode 100644 docs/ebpf_rss.rst create mode 100644 ebpf/EbpfElf_to_C.py create mode 100755 ebpf/Makefile.ebpf create mode 100644 ebpf/ebpf_rss-stub.c create mode 100644 ebpf/ebpf_rss.c create mode 100644 ebpf/ebpf_rss.h create mode 100644 ebpf/meson.build create mode 100644 ebpf/rss.bpf.c create mode 100644 ebpf/tun_rss_steering.h
Signature · 1 line
2.29.2
RFC PATCH v2 1/5 net: Added SetSteeringEBPF method for NetClientState.
From: Andrew <[email protected]>
For now, that method supported only by Linux TAP.
Linux TAP uses TUNSETSTEERINGEBPF ioctl.
--- include/net/net.h | 2 ++ net/tap-bsd.c | 5 +++++ net/tap-linux.c | 13 +++++++++++++ net/tap-linux.h | 1 + net/tap-solaris.c | 5 +++++ net/tap-stub.c | 5 +++++ net/tap.c | 9 +++++++++ net/tap_int.h | 1 + 8 files changed, 41 insertions(+)
include/net/net.h +2 -0
@@ -60,6 +60,7 @@ typedef int (SetVnetBE)(NetClientState *, bool);typedef struct SocketReadState SocketReadState ;typedef void (SocketReadStateFinalize )(SocketReadState *rs);typedef void (NetAnnounce )(NetClientState *); +typedef bool (SetSteeringEBPF )(NetClientState *,int ); typedef struct NetClientInfo { NetClientDriver type;
@@ -81,6 +82,7 @@ typedef struct NetClientInfo {SetVnetLE *set_vnet_le;SetVnetBE *set_vnet_be;NetAnnounce *announce; +SetSteeringEBPF *set_steering_ebpf; } NetClientInfo;struct NetClientState {
net/tap-bsd.c +5 -0
@@ -259,3 +259,8 @@ int tap_fd_get_ifname(int fd, char *ifname) {return -1 ; } + +int tap_fd_set_steering_ebpf (int fd,int prog_fd) +{ +return -1 ; +}
net/tap-linux.c +13 -0
@@ -316,3 +316,16 @@ int tap_fd_get_ifname(int fd, char *ifname)pstrcpy (ifname,sizeof (ifr.ifr_name), ifr.ifr_name);return 0 ; } + +int tap_fd_set_steering_ebpf (int fd,int prog_fd) +{ +if (ioctl (fd,TUNSETSTEERINGEBPF , (void *) &prog_fd) !=0 ) { +error_report ("Issue while setting TUNSETSTEERINGEBPF:" +" %s with fd: %d, prog_fd: %d" , +strerror (errno), fd, prog_fd); + +return -1 ; + } + +return 0 ; +}
net/tap-linux.h +1 -0
@@ -31,6 +31,7 @@#define TUNSETQUEUE _IOW('T', 217, int)#define TUNSETVNETLE _IOW('T', 220, int)#define TUNSETVNETBE _IOW('T', 222, int) +#define TUNSETSTEERINGEBPF _IOR('T', 224, int)#endif
net/tap-solaris.c +5 -0
@@ -255,3 +255,8 @@ int tap_fd_get_ifname(int fd, char *ifname) {return -1 ; } + +int tap_fd_set_steering_ebpf (int fd,int prog_fd) +{ +return -1 ; +}
net/tap-stub.c +5 -0
@@ -85,3 +85,8 @@ int tap_fd_get_ifname(int fd, char *ifname) {return -1 ; } + +int tap_fd_set_steering_ebpf (int fd,int prog_fd) +{ +return -1 ; +}
net/tap.c +9 -0
@@ -337,6 +337,14 @@ static void tap_poll(NetClientState *nc, bool enable)tap_write_poll (s, enable); } +static bool tap_set_steering_ebpf (NetClientState *nc,int prog_fd) +{ +TAPState *s =DO_UPCAST (TAPState, nc, nc); +assert (nc->info->type ==NET_CLIENT_DRIVER_TAP ); + +return tap_fd_set_steering_ebpf (s->fd, prog_fd) ==0 ; +} +int tap_get_fd (NetClientState *nc) {TAPState *s =DO_UPCAST (TAPState, nc, nc);
@@ -362,6 +370,7 @@ static NetClientInfo net_tap_info = { .set_vnet_hdr_len = tap_set_vnet_hdr_len, .set_vnet_le = tap_set_vnet_le, .set_vnet_be = tap_set_vnet_be, + .set_steering_ebpf = tap_set_steering_ebpf, }; static TAPState *net_tap_fd_init(NetClientState *peer,
net/tap_int.h +1 -0
@@ -44,5 +44,6 @@ int tap_fd_set_vnet_be(int fd, int vnet_is_be);int tap_fd_enable (int fd);int tap_fd_disable (int fd);int tap_fd_get_ifname (int fd,char *ifname); +int tap_fd_set_steering_ebpf (int fd,int prog_fd);#endif /* NET_TAP_INT_H */
Signature · 1 line
2.29.2
Re: [RFC PATCH v2 1/5] net: Added SetSteeringEBPF method for NetClientState.
Quoted 76 lines · Andrew Melnychenko
From: Andrew <[email protected]>
For now, that method supported only by Linux TAP.
Linux TAP uses TUNSETSTEERINGEBPF ioctl.Signed-off-by Andrew Melnychenko <[email protected]>--- include/net/net.h | 2 ++ net/tap-bsd.c | 5 +++++ net/tap-linux.c | 13 +++++++++++++ net/tap-linux.h | 1 + net/tap-solaris.c | 5 +++++ net/tap-stub.c | 5 +++++ net/tap.c | 9 +++++++++ net/tap_int.h | 1 + 8 files changed, 41 insertions(+)include/net/net.h +2
-0@@ -60,6 +60,7 @@ typedef int (SetVnetBE)(NetClientState *, bool);typedef struct SocketReadState SocketReadState ;typedef void (SocketReadStateFinalize )(SocketReadState *rs);typedef void (NetAnnounce )(NetClientState *); +typedef bool (SetSteeringEBPF )(NetClientState *,int ); typedef struct NetClientInfo { NetClientDriver type;@@ -81,6 +82,7 @@ typedef struct NetClientInfo {SetVnetLE *set_vnet_le;SetVnetBE *set_vnet_be;NetAnnounce *announce; +SetSteeringEBPF *set_steering_ebpf; } NetClientInfo;struct NetClientState {net/tap-bsd.c +5
-0@@ -259,3 +259,8 @@ int tap_fd_get_ifname(int fd, char *ifname) {return -1 ; } + +int tap_fd_set_steering_ebpf (int fd,int prog_fd) +{ +return -1 ; +}net/tap-linux.c +13
-0@@ -316,3 +316,16 @@ int tap_fd_get_ifname(int fd, char *ifname)pstrcpy (ifname,sizeof (ifr.ifr_name), ifr.ifr_name);return 0 ; } + +int tap_fd_set_steering_ebpf (int fd,int prog_fd) +{ +if (ioctl (fd,TUNSETSTEERINGEBPF , (void *) &prog_fd) !=0 ) { +error_report ("Issue while setting TUNSETSTEERINGEBPF:" +" %s with fd: %d, prog_fd: %d" , +strerror (errno), fd, prog_fd); + +return -1 ; + } + +return 0 ; +}net/tap-linux.h +0
-0
net/tap-linux.h line 34
Quoted 4 lines
net/tap-linux.h +1
-0@@ -31,6 +31,7 @@#define TUNSETQUEUE _IOW('T', 217, int)#define TUNSETVNETLE _IOW('T', 220, int)#define TUNSETVNETBE _IOW('T', 222, int) +#define TUNSETSTEERINGEBPF _IOR('T', 224, int)
Let's do this in another patch.
Thanks
RFC PATCH v2 2/5 ebpf: Added eBPF RSS program.
In reply to Andrew MelnychenkoFrom: Andrew <[email protected]>
RSS program and Makefile to build it.
Also, added a python script that would generate '.h' file. The data in that file may be loaded by libbpf.
EBPF compilation is not required for building qemu.
You can use Makefile if you need to regenerate tun_rss_steering.h.
NOTE: BPF program can't be loaded without debug/btf info. Which brings to huge tun_rss_steering.h file.
In future, need to find proper way to shrink the file and leave only the program data and btf info.
--- ebpf/EbpfElf_to_C.py | 36 + ebpf/Makefile.ebpf | 33 + ebpf/rss.bpf.c | 505 ++++ ebpf/tun_rss_steering.h | 5439 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 6013 insertions(+) create mode 100644 ebpf/EbpfElf_to_C.py create mode 100755 ebpf/Makefile.ebpf create mode 100644 ebpf/rss.bpf.c create mode 100644 ebpf/tun_rss_steering.h
ebpf/EbpfElf_to_C.py new file +36 -0
@@ -0,0 +1,36 @@ +#!/usr/bin/python3 + +import sys +import argparse + +def process_file(filename, prog_name): + print('Processing file:', filename) + with open(filename, 'rb') as f: + with open("%s.h" % prog_name, 'w') as w: + + w.write('#ifndef %s\n' % prog_name.upper()) + w.write('#define %s\n\n' % prog_name.upper()) + + w.write("uint8_t data_%s[] = {\n" % prog_name) + + data = f.read(8) + while data: + w.write(" " + ", ".join("0x%02x" % x for x in data) + ",\n") + data = f.read(8) + + w.write('};\n\n') + + w.write('#endif /* %s */\n' % prog_name.upper()) + + return 0 + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description='Convert eBPF ELF to C header. ' + 'Section name will be used in C namings.') + parser.add_argument('--file', '-f', nargs=1, required=True, + help='eBPF ELF file') + parser.add_argument('--section', '-s', nargs=1, required=True, + help='section in ELF with eBPF program.') + args = parser.parse_args() + sys.exit(process_file(args.file[0], args.section[0]))
ebpf/Makefile.ebpf new file +33 -0
@@ -0,0 +1,33 @@ +OBJS = rss.bpf.o + +LLC ?= llc +CLANG ?= clang +INC_FLAGS = -nostdinc -isystem `$(CLANG) -print-file-name=include` +EXTRA_CFLAGS ?= -O2 -g -emit-llvm + +linuxhdrs = ~/src/kernel/master + +LINUXINCLUDE = -I $(linuxhdrs)/arch/x86/include/uapi \ + -I $(linuxhdrs)/arch/x86/include/generated/uapi \ + -I $(linuxhdrs)/arch/x86/include/generated \ + -I $(linuxhdrs)/include/generated/uapi \ + -I $(linuxhdrs)/include/uapi \ + -I $(linuxhdrs)/include \ + -I $(linuxhdrs)/tools/lib + +all: $(OBJS) + +.PHONY: clean + +clean: + rm -f $(OBJS) + +INC_FLAGS = -nostdinc -isystem `$(CLANG) -print-file-name=include` + +$(OBJS): %.o:%.c + $(CLANG) $(INC_FLAGS) \ + -D__KERNEL__ -D__ASM_SYSREG_H \ + -I../include $(LINUXINCLUDE) \ + $(EXTRA_CFLAGS) -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@ + python3 EbpfElf_to_C.py -f rss.bpf.o -s tun_rss_steering +
ebpf/rss.bpf.c new file +505 -0
505 lines not on this page · raw message
ebpf/tun_rss_steering.h new file +5439 -0
2,426 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.29.2
Part of the diff is not shown here. View the raw message.
Re: [RFC PATCH v2 2/5] ebpf: Added eBPF RSS program.
Quoted 13 lines · Andrew Melnychenko
From: Andrew<[email protected]>
RSS program and
Makefileto build it.
Also, added a python script that would generate '.h' file. The data in that file may be loaded by libbpf.
EBPF compilation is not required for building qemu.
You can useMakefileif you need to regeneratetun_rss_steering.h.NOTE: BPF program can't be loaded without debug/btf info. Which brings to huge
tun_rss_steering.hfile.
In future, need to find proper way to shrink the file and leave only the program data and btf info.
Quoted 6 lines
Signed-off-by Yuri Benditovich<[email protected]>Signed-off-by Andrew Melnychenko<[email protected]>--- ebpf/EbpfElf_to_C.py | 36 + ebpf/Makefile.ebpf | 33 + ebpf/rss.bpf.c | 505 ++++
I think it's better to place them under tools/
Quoted 1 line
ebpf/tun_rss_steering.h | 5439 +++++++++++++++++++++++++++++++++++++++
And move this to net/
ebpf/EbpfElf_to_C.py line 1
Quoted 13 lines
4 files changed, 6013 insertions(+)create mode 100644
ebpf/EbpfElf_to_C.py
create mode 100755 ebpf/Makefile.ebpf
create mode 100644ebpf/rss.bpf.c
create mode 100644ebpf/tun_rss_steering.hebpf/EbpfElf_to_C.py new file +1
-0@@ -0,0 +1,36 @@ +#!/usr/bin/python3
Missing license.
Quoted 41 lines
ebpf/EbpfElf_to_C.py new file +35
-0+ +import sys +import argparse + +def process_file(filename, prog_name): + print('Processing file:', filename) + with open(filename, 'rb') as f: + with open("%s.h" % prog_name, 'w') as w: + + w.write('#ifndef %s\n' % prog_name.upper()) + w.write('#define %s\n\n' % prog_name.upper()) + + w.write("uint8_t data_%s[] = {\n" % prog_name) + + data = f.read(8) + while data: + w.write(" " + ", ".join("0x%02x" % x for x in data) + ",\n") + data = f.read(8) + + w.write('};\n\n') + + w.write('#endif /* %s */\n' % prog_name.upper()) + + return 0 + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description='Convert eBPF ELF to C header. ' + 'Section name will be used in C namings.') + parser.add_argument('--file', '-f', nargs=1, required=True, + help='eBPF ELF file') + parser.add_argument('--section', '-s', nargs=1, required=True, + help='section in ELF with eBPF program.') + args = parser.parse_args() + sys.exit(process_file(args.file[0], args.section[0]))ebpf/Makefile.ebpf new file +0
-0
ebpf/Makefile.ebpf line 6
Quoted 6 lines
ebpf/Makefile.ebpf new file +6
-0@@ -0,0 +1,33 @@ +OBJS = rss.bpf.o + +LLC ?= llc +CLANG ?= clang +INC_FLAGS = -nostdinc -isystem `$(CLANG) -print-file-name=include` +EXTRA_CFLAGS ?= -O2 -g -emit-llvm
Do we need a check of clang version to make sure BTF can be generated with "-g"?
Quoted 58 lines
ebpf/Makefile.ebpf new file +27
-0+ +linuxhdrs = ~/src/kernel/master + +LINUXINCLUDE = -I $(linuxhdrs)/arch/x86/include/uapi \ + -I $(linuxhdrs)/arch/x86/include/generated/uapi \ + -I $(linuxhdrs)/arch/x86/include/generated \ + -I $(linuxhdrs)/include/generated/uapi \ + -I $(linuxhdrs)/include/uapi \ + -I $(linuxhdrs)/include \ + -I $(linuxhdrs)/tools/lib + +all: $(OBJS) + +.PHONY: clean + +clean: + rm -f $(OBJS) + +INC_FLAGS = -nostdinc -isystem `$(CLANG) -print-file-name=include` + +$(OBJS): %.o:%.c + $(CLANG) $(INC_FLAGS) \ + -D__KERNEL__ -D__ASM_SYSREG_H \ + -I../include $(LINUXINCLUDE) \ + $(EXTRA_CFLAGS) -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@ + python3 EbpfElf_to_C.py -f rss.bpf.o -s tun_rss_steering +ebpf/rss.bpf.c new file +25
-0@@ -0,0 +1,505 @@ +/* +* eBPF RSS program +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko<[email protected]> +* Yuri Benditovich<[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +*/ + +#include <stddef.h> +#include <stdbool.h> +#include <linux/bpf.h> + +#include <linux/in.h> +#include <linux/if_ether.h> +#include <linux/ip.h> +#include <linux/ipv6.h> + +#include <linux/udp.h> +#include <linux/tcp.h> +
ebpf/rss.bpf.c line 35
Quoted 10 lines
ebpf/rss.bpf.c new file +10
-0+#include <bpf/bpf_helpers.h> +#include <linux/virtio_net.h> + +/* +* Prepare: +* Requires llvm, clang, python3, linux kernel tree +* +* Build tun_rss_steering.h: +* make -f Mefile.ebpf clean all +*/
It's better to merge those instructions with the comments at the beginning.
Quoted 17 lines
ebpf/rss.bpf.c new file +17
-0+ +#define INDIRECTION_TABLE_SIZE 128 +#define HASH_CALCULATION_BUFFER_SIZE 36 + +struct rss_config_t { +__u8 redirect; +__u8 populate_hash; +__u32 hash_types; +__u16 indirections_len; +__u16 default_queue; +}; + +struct toeplitz_key_data_t { +__u32 leftmost_32_bits; +__u8 next_byte[HASH_CALCULATION_BUFFER_SIZE ]; +}; +
[...]
ebpf/rss.bpf.c line 473
Quoted 7 lines
ebpf/rss.bpf.c new file +7
-0+ +SEC("tun_rss_steering") +int tun_rss_steering_prog (struct __sk_buff *skb) +{ + +struct rss_config_t *config =0 ; +struct toeplitz_key_data_t *toe =0 ;
There's no need to initialize the above two.
Thanks
RFC PATCH v2 3/5 ebpf: Added eBPF RSS loader.
In reply to Andrew MelnychenkoFrom: Andrew <[email protected]>
Added function that loads RSS eBPF program.
Added stub functions for RSS eBPF loader.
Added meson and configuration options.
By default, eBPF feature enabled if libbpf is present in the build system. libbpf checked in configuration shell script and meson script.
--- configure | 33 ++++++++ ebpf/ebpf_rss-stub.c | 40 +++++++++ ebpf/ebpf_rss.c | 187 +++++++++++++++++++++++++++++++++++++++++++ ebpf/ebpf_rss.h | 44 ++++++++++ ebpf/meson.build | 1 + ebpf/trace-events | 4 + ebpf/trace.h | 2 + meson.build | 11 +++ 8 files changed, 322 insertions(+) create mode 100644 ebpf/ebpf_rss-stub.c create mode 100644 ebpf/ebpf_rss.c create mode 100644 ebpf/ebpf_rss.h create mode 100644 ebpf/meson.build create mode 100644 ebpf/trace-events create mode 100644 ebpf/trace.h
configure +33 -0
@@ -330,6 +330,7 @@ vhost_scsi="" vhost_vsock="" vhost_user="" vhost_user_fs="" +bpf="" kvm="auto" hax="auto" hvf="auto"
@@ -1210,6 +1211,10 @@ for opt do ;; --enable-membarrier) membarrier="yes" ;; + --disable-bpf) bpf="no" + ;; + --enable-bpf) bpf="yes" + ;; --disable-blobs) blobs="false" ;; --with-pkgversion=*) pkgversion="$optarg"
@@ -1792,6 +1797,7 @@ disabled with --disable-FEATURE, default is enabled if available: vhost-kernel vhost kernel backend support vhost-user vhost-user backend support vhost-vdpa vhost-vdpa kernel backend support + bpf BPF kernel support spice spice rbd rados block device (rbd) libiscsi iscsi support
@@ -5347,6 +5353,30 @@ else membarrier=no fi +########################################## +# check for usable bpf system call +if test "$bpf" = ""; then + have_bpf=no + if test "$linux" = "yes" -a "$bigendian" != "yes"; then + cat > $TMPC << EOF + #include <stdlib.h> + #include <bpf/libbpf.h> + int main(void) { + struct bpf_object *obj = NULL; + bpf_object__load(obj); + exit(0); + } +EOF + if compile_prog "" "-lbpf" ; then + have_bpf=yes + bpf=yes + fi + fi + if test "$have_bpf" = "no"; then + feature_not_found "bpf" "the libbpf is not available" + fi +fi + ########################################## # check if rtnetlink.h exists and is useful have_rtnetlink=no
@@ -6279,6 +6309,9 @@ fi if test "$membarrier" = "yes" ; then echo "CONFIG_MEMBARRIER=y" >> $config_host_mak fi +if test "$bpf" = "yes" -a "$bigendian" != "yes" -a "$linux" = "yes" ; then + echo "CONFIG_EBPF=y" >> $config_host_mak +fi if test "$signalfd" = "yes" ; then echo "CONFIG_SIGNALFD=y" >> $config_host_mak fi
ebpf/ebpf_rss-stub.c new file +40 -0
@@ -0,0 +1,40 @@ +/* +* eBPF RSS stub file +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Yuri Benditovich <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "ebpf/ebpf_rss.h" + +void ebpf_rss_init (struct EBPFRSSContext *ctx) +{ + +} + +bool ebpf_rss_is_loaded (struct EBPFRSSContext *ctx) +{ +return false; +} + +bool ebpf_rss_load (struct EBPFRSSContext *ctx) +{ +return false; +} + +bool ebpf_rss_set_all (struct EBPFRSSContext *ctx,struct EBPFRSSConfig *config, +uint16_t *indirections_table,uint8_t *toeplitz_key) +{ +return false; +} + +void ebpf_rss_unload (struct EBPFRSSContext *ctx) +{ + +}
ebpf/ebpf_rss.c new file +187 -0
187 lines not on this page · raw message
ebpf/ebpf_rss.h new file +44 -0
44 lines not on this page · raw message
ebpf/meson.build new file +1 -0
@@ -0,0 +1 @@ +common_ss.add(when: 'CONFIG_EBPF', if_true: files('ebpf_rss.c'), if_false: files('ebpf_rss-stub.c'))
ebpf/trace-events new file +4 -0
@@ -0,0 +1,4 @@ +# See docs/devel/tracing.txt for syntax documentation. + +# ebpf-rss.c +ebpf_error(const char *s1, const char *s2) "error in %s: %s"
ebpf/trace.h new file +2 -0
@@ -0,0 +1,2 @@ +#include "trace/trace-ebpf.h" +
meson.build +11 -0
@@ -736,6 +736,12 @@ if not has_malloc_trim and get_option('malloc_trim').enabled() endif endif +# libbpf +libbpf = not_found +if 'CONFIG_EBPF' in config_host + libbpf = cc.find_library('bpf', required: true) +endif + ################# # config-host.h # #################
@@ -1368,6 +1374,7 @@ if have_system 'backends', 'backends/tpm', 'chardev', + 'ebpf', 'hw/9pfs', 'hw/acpi', 'hw/alpha',
@@ -1530,6 +1537,9 @@ subdir('accel') subdir('plugins') subdir('bsd-user') subdir('linux-user') +subdir('ebpf') + +common_ss.add(libbpf) bsd_user_ss.add(files('gdbstub.c')) specific_ss.add_all(when: 'CONFIG_BSD_USER', if_true: bsd_user_ss)
@@ -2093,6 +2103,7 @@ summary_info += {'vhost-vsock support': config_host.has_key('CONFIG_VHOST_VSOCK' summary_info += {'vhost-user support': config_host.has_key('CONFIG_VHOST_KERNEL')} summary_info += {'vhost-user-fs support': config_host.has_key('CONFIG_VHOST_USER_FS')} summary_info += {'vhost-vdpa support': config_host.has_key('CONFIG_VHOST_VDPA')} +summary_info += {'bpf support': config_host.has_key('CONFIG_EBPF')} summary_info += {'Trace backends': config_host['TRACE_BACKENDS']} if config_host['TRACE_BACKENDS'].split().contains('simple') summary_info += {'Trace output file': config_host['CONFIG_TRACE_FILE'] + '-<pid>'}
Signature · 1 line
2.29.2
Re: [RFC PATCH v2 3/5] ebpf: Added eBPF RSS loader.
Quoted 64 lines · Andrew Melnychenko
From: Andrew <[email protected]>
Added function that loads RSS eBPF program.
Added stub functions for RSS eBPF loader.
Added meson and configuration options.By default, eBPF feature enabled if libbpf is present in the build system. libbpf checked in configuration shell script and meson script.
Signed-off-by Yuri Benditovich <[email protected]>Signed-off-by Andrew Melnychenko <[email protected]>--- configure | 33 ++++++++ ebpf/ebpf_rss-stub.c | 40 +++++++++ ebpf/ebpf_rss.c | 187 +++++++++++++++++++++++++++++++++++++++++++ ebpf/ebpf_rss.h | 44 ++++++++++ ebpf/meson.build | 1 + ebpf/trace-events | 4 + ebpf/trace.h | 2 + meson.build | 11 +++ 8 files changed, 322 insertions(+)create mode 100644
ebpf/ebpf_rss-stub.c
create mode 100644ebpf/ebpf_rss.c
create mode 100644ebpf/ebpf_rss.h
create mode 100644 ebpf/meson.build
create mode 100644 ebpf/trace-events
create mode 100644ebpf/trace.hconfigure +7
-0@@ -330,6 +330,7 @@ vhost_scsi="" vhost_vsock="" vhost_user="" vhost_user_fs="" +bpf="" kvm="auto" hax="auto" hvf="auto"@@ -1210,6 +1211,10 @@ for opt do ;; --enable-membarrier) membarrier="yes" ;; + --disable-bpf) bpf="no" + ;; + --enable-bpf) bpf="yes" + ;; --disable-blobs) blobs="false" ;; --with-pkgversion=*) pkgversion="$optarg"@@ -1792,6 +1797,7 @@ disabled with --disable-FEATURE, default is enabled if available: vhost-kernel vhost kernel backend support vhost-user vhost-user backend support vhost-vdpa vhost-vdpa kernel backend support + bpf BPF kernel support spice spice rbd rados block device (rbd) libiscsi iscsi support@@ -5347,6 +5353,30 @@ else membarrier=no fi +##########################################
configure else · line 5366
Quoted 10 lines
configure +10
-0+# check for usable bpf system call +if test "$bpf" = ""; then + have_bpf=no + if test "$linux" = "yes" -a "$bigendian" != "yes"; then + cat > $TMPC << EOF + #include <stdlib.h> + #include <bpf/libbpf.h> + int main(void) { + struct bpf_object *obj = NULL; + bpf_object__load(obj);
Do we need a test of btf here?
Quoted 109 lines
configure +16
-0+ exit(0); + } +EOF + if compile_prog "" "-lbpf" ; then + have_bpf=yes + bpf=yes + fi + fi + if test "$have_bpf" = "no"; then + feature_not_found "bpf" "the libbpf is not available" + fi +fi + ########################################## # check if rtnetlink.h exists and is useful have_rtnetlink=no@@ -6279,6 +6309,9 @@ fi if test "$membarrier" = "yes" ; then echo "CONFIG_MEMBARRIER=y" >> $config_host_mak fi +if test "$bpf" = "yes" -a "$bigendian" != "yes" -a "$linux" = "yes" ; then + echo "CONFIG_EBPF=y" >> $config_host_mak +fi if test "$signalfd" = "yes" ; then echo "CONFIG_SIGNALFD=y" >> $config_host_mak fiebpf/ebpf_rss-stub.c new file +40
-0@@ -0,0 +1,40 @@ +/* +* eBPF RSS stub file +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Yuri Benditovich <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "ebpf/ebpf_rss.h" + +void ebpf_rss_init (struct EBPFRSSContext *ctx) +{ + +} + +bool ebpf_rss_is_loaded (struct EBPFRSSContext *ctx) +{ +return false; +} + +bool ebpf_rss_load (struct EBPFRSSContext *ctx) +{ +return false; +} + +bool ebpf_rss_set_all (struct EBPFRSSContext *ctx,struct EBPFRSSConfig *config, +uint16_t *indirections_table,uint8_t *toeplitz_key) +{ +return false; +} + +void ebpf_rss_unload (struct EBPFRSSContext *ctx) +{ + +}ebpf/ebpf_rss.c new file +31
-0@@ -0,0 +1,187 @@ +/* +* eBPF RSS loader +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko <[email protected]> +* Yuri Benditovich <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "qemu/error-report.h" + +#include <bpf/libbpf.h> +#include <bpf/bpf.h> + +#include "hw/virtio/virtio-net.h" /* VIRTIO_NET_RSS_MAX_TABLE_LEN */ + +#include "ebpf/ebpf_rss.h" +#include "ebpf/tun_rss_steering.h" +#include "trace.h" + +void ebpf_rss_init (struct EBPFRSSContext *ctx) +{ +if (ctx !=NULL ) { + ctx->obj =NULL ; + } +}
ebpf/ebpf_rss.c line 41
Quoted 10 lines
ebpf/ebpf_rss.c new file +10
-0+ +bool ebpf_rss_is_loaded (struct EBPFRSSContext *ctx) +{ +return ctx !=NULL && ctx->obj !=NULL ; +} + +bool ebpf_rss_load (struct EBPFRSSContext *ctx) +{ +struct bpf_object *object =NULL ; +struct bpf_program *prog =NULL ;
Unnecessary initialization.
Quoted 12 lines
ebpf/ebpf_rss.c new file +12
-0+ +if (ctx ==NULL ) { +return false; + } + + object =bpf_object__open_mem (data_tun_rss_steering, +sizeof (data_tun_rss_steering),NULL ); +if (object ==NULL ) { +trace_ebpf_error ("eBPF RSS" ,"can not open eBPF object" ); +return false; + } +
ebpf/ebpf_rss.c line 63
Quoted 10 lines
ebpf/ebpf_rss.c new file +10
-0+ prog =bpf_object__find_program_by_title (object,"tun_rss_steering" ); +if (prog ==NULL ) { +trace_ebpf_error ("eBPF RSS" ,"can not find RSS program" ); + goto l_issue; + } + +bpf_program__set_socket_filter (prog); + +if (bpf_object__load (object)) { +trace_ebpf_error ("eBPF RSS" ,"can not load RSS program" );
It would be useful for getting the verbose log via extack but I'm not sure if libbpf support this. If yes, it's better to add the output to the trace.
Quoted 25 lines
ebpf/ebpf_rss.c new file +25
-0+ goto l_issue; + } + + ctx->obj = object; + ctx->program_fd =bpf_program__fd (prog); + + ctx->map_configuration = +bpf_object__find_map_fd_by_name (object, +"tap_rss_map_configurations" ); +if (ctx->map_configuration <0 ) { +trace_ebpf_error ("eBPF RSS" ,"can not find MAP for configurations" ); + goto l_issue; + } + + ctx->map_toeplitz_key = +bpf_object__find_map_fd_by_name (object, +"tap_rss_map_toeplitz_key" ); +if (ctx->map_toeplitz_key <0 ) { +trace_ebpf_error ("eBPF RSS" ,"can not find MAP for toeplitz key" ); + goto l_issue; + } + + ctx->map_indirections_table = +bpf_object__find_map_fd_by_name (object, +"tap_rss_map_indirection_table" );
ebpf/ebpf_rss.c line 98
Quoted 10 lines
ebpf/ebpf_rss.c new file +10
-0+if (ctx->map_indirections_table <0 ) { +trace_ebpf_error ("eBPF RSS" ,"can not find MAP for indirections table" ); + goto l_issue; + } + +return true; + +l_issue: +bpf_object__close (object); + ctx->obj =NULL ;
Do we need to clean other member of ctx?
Quoted 23 lines
ebpf/ebpf_rss.c new file +23
-0+return false; +} + +static bool ebpf_rss_set_config (struct EBPFRSSContext *ctx, +struct EBPFRSSConfig *config) +{ +if (!ebpf_rss_is_loaded (ctx)) { +return false; + } +uint32_t map_key =0 ; +if (bpf_map_update_elem (ctx->map_configuration, + &map_key, config,0 ) <0 ) { +return false; + } +return true; +} + +static bool ebpf_rss_set_indirections_table (struct EBPFRSSContext *ctx, +uint16_t *indirections_table, +size_t len) +{ +if (!ebpf_rss_is_loaded (ctx) || indirections_table ==NULL || + len >VIRTIO_NET_RSS_MAX_TABLE_LEN ) {
ebpf/ebpf_rss.c line 131
Quoted 10 lines
ebpf/ebpf_rss.c new file +10
-0+return false; + } +uint32_t i =0 ; + +for (; i < len; ++i) { +if (bpf_map_update_elem (ctx->map_indirections_table, &i, + indirections_table + i,0 ) <0 ) { +return false; + } + }
Do we need to delete the elem in the range of [i, len)?
ebpf/ebpf_rss.c line 144
Quoted 13 lines
ebpf/ebpf_rss.c new file +13
-0+return true; +} + +static bool ebpf_rss_set_toepliz_key (struct EBPFRSSContext *ctx, +uint8_t *toeplitz_key) +{ +if (!ebpf_rss_is_loaded (ctx) || toeplitz_key ==NULL ) { +return false; + } +uint32_t map_key =0 ; + +/* prepare toeplitz key */ +uint8_t toe[VIRTIO_NET_RSS_MAX_KEY_SIZE ] = {};
Compilers may warn about such declaration after statement.
Quoted 161 lines
ebpf/ebpf_rss.c new file +43
-0+memcpy (toe, toeplitz_key,VIRTIO_NET_RSS_MAX_KEY_SIZE ); + *(uint32_t *)toe =ntohl (*(uint32_t *)toe); + +if (bpf_map_update_elem (ctx->map_toeplitz_key, &map_key, toe, +0 ) <0 ) { +return false; + } +return true; +} + +bool ebpf_rss_set_all (struct EBPFRSSContext *ctx,struct EBPFRSSConfig *config, +uint16_t *indirections_table,uint8_t *toeplitz_key) +{ +if (!ebpf_rss_is_loaded (ctx) || config ==NULL || + indirections_table ==NULL || toeplitz_key ==NULL ) { +return false; + } + +if (!ebpf_rss_set_config (ctx, config)) { +return false; + } + +if (!ebpf_rss_set_indirections_table (ctx, indirections_table, + config->indirections_len)) { +return false; + } + +if (!ebpf_rss_set_toepliz_key (ctx, toeplitz_key)) { +return false; + } + +return true; +} + +void ebpf_rss_unload (struct EBPFRSSContext *ctx) +{ +if (!ebpf_rss_is_loaded (ctx)) { +return ; + } + +bpf_object__close (ctx->obj); + ctx->obj =NULL ; +}ebpf/ebpf_rss.h new file +44
-0@@ -0,0 +1,44 @@ +/* +* eBPF RSS header +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko <[email protected]> +* Yuri Benditovich <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +*/ + +#ifndef QEMU_EBPF_RSS_H +#define QEMU_EBPF_RSS_H + +struct EBPFRSSContext { +void *obj; +int program_fd; +int map_configuration; +int map_toeplitz_key; +int map_indirections_table; +}; + +struct EBPFRSSConfig { +uint8_t redirect; +uint8_t populate_hash; +uint32_t hash_types; +uint16_t indirections_len; +uint16_t default_queue; +}; + +void ebpf_rss_init (struct EBPFRSSContext *ctx); + +bool ebpf_rss_is_loaded (struct EBPFRSSContext *ctx); + +bool ebpf_rss_load (struct EBPFRSSContext *ctx); + +bool ebpf_rss_set_all (struct EBPFRSSContext *ctx,struct EBPFRSSConfig *config, +uint16_t *indirections_table,uint8_t *toeplitz_key); + +void ebpf_rss_unload (struct EBPFRSSContext *ctx); + +#endif /* QEMU_EBPF_RSS_H */ ebpf/meson.build new file +1
-0@@ -0,0 +1 @@ +common_ss.add(when: 'CONFIG_EBPF', if_true: files('ebpf_rss.c'), if_false: files('ebpf_rss-stub.c'))ebpf/trace-events new file +4
-0@@ -0,0 +1,4 @@ +# See docs/devel/tracing.txt for syntax documentation. + +# ebpf-rss.c +ebpf_error(const char *s1, const char *s2) "error in %s: %s"ebpf/trace.h new file +2
-0@@ -0,0 +1,2 @@ +#include "trace/trace-ebpf.h" +meson.build +11
-0@@ -736,6 +736,12 @@ if not has_malloc_trim and get_option('malloc_trim').enabled() endif endif +# libbpf +libbpf = not_found +if 'CONFIG_EBPF' in config_host + libbpf = cc.find_library('bpf', required: true) +endif + ################# # config-host.h # #################@@ -1368,6 +1374,7 @@ if have_system 'backends', 'backends/tpm', 'chardev', + 'ebpf', 'hw/9pfs', 'hw/acpi', 'hw/alpha',@@ -1530,6 +1537,9 @@ subdir('accel') subdir('plugins') subdir('bsd-user') subdir('linux-user') +subdir('ebpf') + +common_ss.add(libbpf) bsd_user_ss.add(files('gdbstub.c')) specific_ss.add_all(when: 'CONFIG_BSD_USER', if_true: bsd_user_ss)@@ -2093,6 +2103,7 @@ summary_info += {'vhost-vsock support': config_host.has_key('CONFIG_VHOST_VSOCK' summary_info += {'vhost-user support': config_host.has_key('CONFIG_VHOST_KERNEL')} summary_info += {'vhost-user-fs support': config_host.has_key('CONFIG_VHOST_USER_FS')} summary_info += {'vhost-vdpa support': config_host.has_key('CONFIG_VHOST_VDPA')} +summary_info += {'bpf support': config_host.has_key('CONFIG_EBPF')} summary_info += {'Trace backends': config_host['TRACE_BACKENDS']} if config_host['TRACE_BACKENDS'].split().contains('simple') summary_info += {'Trace output file': config_host['CONFIG_TRACE_FILE'] + '-<pid>'}
RFC PATCH v2 4/5 virtio-net: Added eBPF RSS to virtio-net.
In reply to Andrew MelnychenkoFrom: Andrew <[email protected]>
When RSS is enabled the device tries to load the eBPF program to select RX virtqueue in the TUN. If eBPF can be loaded
the RSS will function also with vhost (works with kernel 5.8 and later). Software RSS is used as a fallback with vhost=off when eBPF can't be loaded or when hash population requested by the guest.
--- hw/net/vhost_net.c | 2 + hw/net/virtio-net.c | 120 +++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 4 ++ net/vhost-vdpa.c | 2 + 4 files changed, 124 insertions(+), 4 deletions(-)
hw/net/vhost_net.c +2 -0
@@ -71,6 +71,8 @@ static const int user_feature_bits[] = {VIRTIO_NET_F_MTU ,VIRTIO_F_IOMMU_PLATFORM ,VIRTIO_F_RING_PACKED , +VIRTIO_NET_F_RSS , +VIRTIO_NET_F_HASH_REPORT ,/* This bit implies RARP isn't sent by QEMU out of band */ VIRTIO_NET_F_GUEST_ANNOUNCE,
hw/net/virtio-net.c +116 -4
177 lines not on this page · raw message
include/hw/virtio/virtio-net.h +4 -0
@@ -21,6 +21,8 @@#include "qemu/option_int.h" #include "qom/object.h" +#include "ebpf/ebpf_rss.h" +#define TYPE_VIRTIO_NET "virtio-net-device"OBJECT_DECLARE_SIMPLE_TYPE (VirtIONet,VIRTIO_NET )
@@ -130,6 +132,7 @@ typedef struct VirtioNetRscChain { typedef struct VirtioNetRssData { bool enabled; + bool enabled_software_rss; bool redirect; bool populate_hash; uint32_t hash_types;
@@ -214,6 +217,7 @@ struct VirtIONet {Notifier migration_state;VirtioNetRssData rss_data;struct NetRxPkt *rx_pkt; +struct EBPFRSSContext ebpf_rss; }; void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
net/vhost-vdpa.c +2 -0
@@ -54,6 +54,8 @@ const int vdpa_feature_bits[] = {VIRTIO_NET_F_MTU ,VIRTIO_F_IOMMU_PLATFORM ,VIRTIO_F_RING_PACKED , +VIRTIO_NET_F_RSS , +VIRTIO_NET_F_HASH_REPORT ,VIRTIO_NET_F_GUEST_ANNOUNCE ,VIRTIO_NET_F_STATUS ,VHOST_INVALID_FEATURE_BIT
Signature · 1 line
2.29.2
Re: [RFC PATCH v2 4/5] virtio-net: Added eBPF RSS to virtio-net.
Quoted 37 lines · Andrew Melnychenko
From: Andrew <[email protected]>
When RSS is enabled the device tries to load the eBPF program to select RX virtqueue in the TUN. If eBPF can be loaded
the RSS will function also with vhost (works with kernel 5.8 and later). Software RSS is used as a fallback with vhost=off when eBPF can't be loaded or when hash population requested by the guest.Signed-off-by Yuri Benditovich <[email protected]>Signed-off-by Andrew Melnychenko <[email protected]>--- hw/net/vhost_net.c | 2 + hw/net/virtio-net.c | 120 +++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 4 ++ net/vhost-vdpa.c | 2 + 4 files changed, 124 insertions(+), 4 deletions(-)hw/net/vhost_net.c +2
-0@@ -71,6 +71,8 @@ static const int user_feature_bits[] = {VIRTIO_NET_F_MTU ,VIRTIO_F_IOMMU_PLATFORM ,VIRTIO_F_RING_PACKED , +VIRTIO_NET_F_RSS , +VIRTIO_NET_F_HASH_REPORT ,/* This bit implies RARP isn't sent by QEMU out of band */ VIRTIO_NET_F_GUEST_ANNOUNCE,hw/net/virtio-net.c +0
-0@@ -698,6 +698,19 @@ static void virtio_net_set_queues(VirtIONet *n)static void virtio_net_set_multiqueue (VirtIONet *n,int multiqueue);
hw/net/virtio-net.c static void virtio_net_set_queues(VirtIONet *n) · line 709
Quoted 10 lines
hw/net/virtio-net.c +9
-0+static uint64_t fix_ebpf_vhost_features (uint64_t features) +{ +/* If vhost=on & CONFIG_EBPF doesn't set - disable RSS feature */ +uint64_t ret = features; +#ifndef CONFIG_EBPF +virtio_clear_feature (&ret,VIRTIO_NET_F_RSS ); +#endif +/* for now, there is no solution for populating the hash from eBPF */ +virtio_clear_feature (&ret,VIRTIO_NET_F_HASH_REPORT );
I think there's still some misunderstanding here.
When "rss" is enabled via command line, qemu can't not turn it off silently, otherwise it may break migration. Instead, qemu should disable vhost-net if eBPF can't be loaded.
When "hash_report" is enabled via command line, qemu should disable vhost-net unconditionally.
Quoted 105 lines
hw/net/virtio-net.c +71
-3+ +return ret; +} +static uint64_t virtio_net_get_features (VirtIODevice *vdev,uint64_t features,Error **errp) {@@ -732,9 +745,9 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,return features; } -virtio_clear_feature (&features,VIRTIO_NET_F_RSS ); -virtio_clear_feature (&features,VIRTIO_NET_F_HASH_REPORT ); - features =vhost_net_get_features (get_vhost_net (nc->peer), features); + features =fix_ebpf_vhost_features ( +vhost_net_get_features (get_vhost_net (nc->peer), features)); + vdev->backend_features = features; if (n->mtu_bypass_backend &&@@ -1169,12 +1182,75 @@ static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd, } } +static void virtio_net_unload_epbf_rss (VirtIONet *n); +static void virtio_net_disable_rss (VirtIONet *n) {if (n->rss_data.enabled) {trace_virtio_net_rss_disable (); } n->rss_data.enabled = false; + +if (!n->rss_data.enabled_software_rss &&ebpf_rss_is_loaded (&n->ebpf_rss)) { +virtio_net_unload_epbf_rss (n); + } +} + +static bool virtio_net_attach_steering_ebpf (NICState *nic,int prog_fd) +{ +NetClientState *nc =qemu_get_peer (qemu_get_queue (nic),0 ); +if (nc ==NULL || nc->info->set_steering_ebpf ==NULL ) { +return false; + } + +return nc->info->set_steering_ebpf (nc, prog_fd); +} + +static void rss_data_to_rss_config (struct VirtioNetRssData *data, +struct EBPFRSSConfig *config) +{ + config->redirect = data->redirect; + config->populate_hash = data->populate_hash; + config->hash_types = data->hash_types; + config->indirections_len = data->indirections_len; + config->default_queue = data->default_queue; +} + +static bool virtio_net_load_epbf_rss (VirtIONet *n) +{ +struct EBPFRSSConfig config = {}; + +if (!n->rss_data.enabled) { +if (ebpf_rss_is_loaded (&n->ebpf_rss)) { +ebpf_rss_unload (&n->ebpf_rss); + } +return true; + } + +if (!ebpf_rss_is_loaded (&n->ebpf_rss) && !ebpf_rss_load (&n->ebpf_rss)) { +return false; + } + +rss_data_to_rss_config (&n->rss_data, &config); + +if (!ebpf_rss_set_all (&n->ebpf_rss, &config, + n->rss_data.indirections_table, n->rss_data.key)) { +ebpf_rss_unload (&n->ebpf_rss); +return false; + } + +if (!virtio_net_attach_steering_ebpf (n->nic, n->ebpf_rss.program_fd)) { +ebpf_rss_unload (&n->ebpf_rss); +return false; + } + +return true; +} + +static void virtio_net_unload_epbf_rss (VirtIONet *n) +{ +virtio_net_attach_steering_ebpf (n->nic,-1 ); +ebpf_rss_unload (&n->ebpf_rss); } static uint16_t virtio_net_handle_rss(VirtIONet *n,@@ -1208,6 +1284,7 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, err_value = (uint32_t )s; goto error; } + n->rss_data.enabled_software_rss = false; n->rss_data.hash_types =virtio_ldl_p (vdev, &cfg.hash_types); n->rss_data.indirections_len =virtio_lduw_p (vdev, &cfg.indirection_table_mask);
hw/net/virtio-net.c static uint16_t virtio_net_handle_rss(VirtIONet *n, · line 1371
Quoted 6 lines
hw/net/virtio-net.c +3
-0@@ -1289,9 +1366,30 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, goto error; } n->rss_data.enabled = true; + +if (!n->rss_data.populate_hash) { +/* load EBPF RSS */
The code explains itself, so the comment is no necessary.
hw/net/virtio-net.c static uint16_t virtio_net_handle_rss(VirtIONet *n, · line 1372
Quoted 1 line
hw/net/virtio-net.c +1
-0+if (!virtio_net_load_epbf_rss (n)) {
Any reason that we load eBPF RSS here? I thought it would be easier to do it during set_features (e.g when RSS is negotiated but not HASH_REPORT) and if we do that we don't need extra care about migration.
hw/net/virtio-net.c static uint16_t virtio_net_handle_rss(VirtIONet *n, · line 1373
Quoted 1 line
hw/net/virtio-net.c +1
-0+/* EBPF mast be loaded for vhost */
Typo.
Quoted 9 lines
hw/net/virtio-net.c +9
-0+if (get_vhost_net (qemu_get_queue (n->nic)->peer)) { +warn_report ("Can't load eBPF RSS for vhost" ); + goto error; + } +/* fallback to software RSS */ +warn_report ("Can't load eBPF RSS - fallback to software RSS" ); + n->rss_data.enabled_software_rss = true; + } + }else {
hw/net/virtio-net.c static uint16_t virtio_net_handle_rss(VirtIONet *n, · line 1392
Quoted 10 lines
hw/net/virtio-net.c +7
-0+/* use software RSS for hash populating */ +/* and unload eBPF if was loaded before */ +virtio_net_unload_epbf_rss (n); + n->rss_data.enabled_software_rss = true; + } +trace_virtio_net_rss_enable (n->rss_data.hash_types, n->rss_data.indirections_len, temp.b); +
Unnecessary changes.
Quoted 17 lines
hw/net/virtio-net.c +2
-1return queues; error:trace_virtio_net_rss_error (err_msg, err_value);@@ -1674,7 +1772,7 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,return -1 ; } -if (!no_rss && n->rss_data.enabled) { +if (!no_rss && n->rss_data.enabled && n->rss_data.enabled_software_rss) {int index =virtio_net_process_rss (nc, buf, size);if (index >=0 ) {NetClientState *nc2 =qemu_get_subqueue (n->nic, index);@@ -2780,6 +2878,18 @@ static int virtio_net_post_load_device(void *opaque, int version_id) }if (n->rss_data.enabled) { + n->rss_data.enabled_software_rss = n->rss_data.populate_hash;
hw/net/virtio-net.c static int virtio_net_post_load_device(void *opaque, int version_id) · line 2891
Quoted 10 lines
hw/net/virtio-net.c +10
-0+if (!n->rss_data.populate_hash) { +if (!virtio_net_load_epbf_rss (n)) { +if (get_vhost_net (qemu_get_queue (n->nic)->peer)) { +error_report ("Can't post-load eBPF RSS for vhost" ); + }else { +warn_report ("Can't post-load eBPF RSS - fallback to software RSS" ); + n->rss_data.enabled_software_rss = true; + } + } + }
btw, I don't see the save and restore of bpf maps, or is it unnecessary?
Thanks
Quoted 55 lines
hw/net/virtio-net.c +3
-0+trace_virtio_net_rss_enable (n->rss_data.hash_types, n->rss_data.indirections_len,sizeof (n->rss_data.key));@@ -3453,6 +3563,8 @@ static void virtio_net_instance_init(Object *obj)device_add_bootindex_property (obj, &n->nic_conf.bootindex,"bootindex" ,"/ethernet-phy@0" ,DEVICE (n)); + +ebpf_rss_init (&n->ebpf_rss); }static int virtio_net_pre_save (void *opaque)include/hw/virtio/virtio-net.h +4
-0@@ -21,6 +21,8 @@#include "qemu/option_int.h" #include "qom/object.h" +#include "ebpf/ebpf_rss.h" +#define TYPE_VIRTIO_NET "virtio-net-device"OBJECT_DECLARE_SIMPLE_TYPE (VirtIONet,VIRTIO_NET )@@ -130,6 +132,7 @@ typedef struct VirtioNetRscChain { typedef struct VirtioNetRssData { bool enabled; + bool enabled_software_rss; bool redirect; bool populate_hash; uint32_t hash_types;@@ -214,6 +217,7 @@ struct VirtIONet {Notifier migration_state;VirtioNetRssData rss_data;struct NetRxPkt *rx_pkt; +struct EBPFRSSContext ebpf_rss; }; void virtio_net_set_netclient_name(VirtIONet *n, const char *name,net/vhost-vdpa.c +2
-0@@ -54,6 +54,8 @@ const int vdpa_feature_bits[] = {VIRTIO_NET_F_MTU ,VIRTIO_F_IOMMU_PLATFORM ,VIRTIO_F_RING_PACKED , +VIRTIO_NET_F_RSS , +VIRTIO_NET_F_HASH_REPORT ,VIRTIO_NET_F_GUEST_ANNOUNCE ,VIRTIO_NET_F_STATUS ,VHOST_INVALID_FEATURE_BIT
Re: [RFC PATCH v2 4/5] virtio-net: Added eBPF RSS to virtio-net.
Quoted 53 lines · Jason Wang
Quoted 6 lines · Andrew Melnychenko
From: Andrew <[email protected]>
When RSS is enabled the device tries to load the eBPF program to select RX virtqueue in the TUN. If eBPF can be loaded
the RSS will function also with vhost (works with kernel 5.8 and later). Software RSS is used as a fallback with vhost=off when eBPF can't beloaded
Quoted 30 lines
or when hash population requested by the guest.
Signed-off-by Yuri Benditovich <[email protected]>Signed-off-by Andrew Melnychenko <[email protected]>--- hw/net/vhost_net.c | 2 + hw/net/virtio-net.c | 120 +++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 4 ++ net/vhost-vdpa.c | 2 + 4 files changed, 124 insertions(+), 4 deletions(-)hw/net/vhost_net.c +2
-0@@ -71,6 +71,8 @@ static const int user_feature_bits[] = {VIRTIO_NET_F_MTU ,VIRTIO_F_IOMMU_PLATFORM ,VIRTIO_F_RING_PACKED , +VIRTIO_NET_F_RSS , +VIRTIO_NET_F_HASH_REPORT ,/* This bit implies RARP isn't sent by QEMU out of band */ VIRTIO_NET_F_GUEST_ANNOUNCE,hw/net/virtio-net.c +0
-0@@ -698,6 +698,19 @@ static void virtio_net_set_queues(VirtIONet *n)hw/net/virtio-net.c static void virtio_net_set_queues(VirtIONet *n) · line 708
Quoted 10 lines
hw/net/virtio-net.c +8
-0static void virtio_net_set_multiqueue (VirtIONet *n,int multiqueue); +static uint64_t fix_ebpf_vhost_features (uint64_t features) +{ +/* If vhost=on & CONFIG_EBPF doesn't set - disable RSS feature */ +uint64_t ret = features; +#ifndef CONFIG_EBPF +virtio_clear_feature (&ret,VIRTIO_NET_F_RSS ); +#endif +/* for now, there is no solution for populating the hash from eBPF */
hw/net/virtio-net.c static void virtio_net_set_queues(VirtIONet *n) · line 709
Quoted 1 line
hw/net/virtio-net.c +1
-0+virtio_clear_feature (&ret,VIRTIO_NET_F_HASH_REPORT );
Quoted 10 lines
I think there's still some misunderstanding here.
When "rss" is enabled via command line, qemu can't not turn it off silently, otherwise it may break migration. Instead, qemu should disable vhost-net if eBPF can't be loaded.
When "
hash_report" is enabled via command line, qemu should disable vhost-net unconditionally.
I agree in general with this requirement and I'm preparing an implementation of such fallback.
The problem is that qemu already uses the mechanism of turning off host features
silently if they are not supported by the current vhost in kernel:
https://github.com/qemu/qemu/blob/b0f8c22d6d4d07f3bd2307bcc62e1660ef965472/hw/virtio/vhost.c#L1526
Can you please comment on it and let me know how it should be modified in future?
I've planned to use it in next work (implementing hash report in kernel)
Quoted 261 lines
hw/net/virtio-net.c static void virtio_net_set_queues(VirtIONet *n)
Quoted 6 lines
hw/net/virtio-net.c +4
-0+ +return ret; +} + static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_tfeatures,
hw/net/virtio-net.c static uint64_t virtio_net_get_features(VirtIODevice
Quoted 3 lines
hw/net/virtio-net.c +0
-0Error **errp) {@@ -732,9 +745,9 @@ static uint64_t virtio_net_get_features(VirtIODevice*vdev,
uint64_tfeatures,hw/net/virtio-net.c static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
Quoted 6 lines
hw/net/virtio-net.c +0
-3return features; } -virtio_clear_feature (&features,VIRTIO_NET_F_RSS ); -virtio_clear_feature (&features,VIRTIO_NET_F_HASH_REPORT ); - features = vhost_net_get_features(get_vhost_net(nc->peer),features);
hw/net/virtio-net.c static int virtio_net_handle_announce(VirtIONet
Quoted 7 lines
hw/net/virtio-net.c +3
-0+ features =fix_ebpf_vhost_features ( +vhost_net_get_features (get_vhost_net (nc->peer), features)); + vdev->backend_features = features; if (n->mtu_bypass_backend &&@@ -1169,12 +1182,75 @@ static int virtio_net_handle_announce(VirtIONet*n,
uint8_tcmd,hw/net/virtio-net.c static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd,
Quoted 13 lines
hw/net/virtio-net.c +4
-0} } +static void virtio_net_unload_epbf_rss (VirtIONet *n); +static void virtio_net_disable_rss (VirtIONet *n) {if (n->rss_data.enabled) {trace_virtio_net_rss_disable (); } n->rss_data.enabled = false; + + if (!n->rss_data.enabled_software_rss &&
ebpf_rss_is_loaded(&n->ebpf_rss)) {Quoted 26 lines
hw/net/virtio-net.c +26
-0+virtio_net_unload_epbf_rss (n); + } +} + +static bool virtio_net_attach_steering_ebpf (NICState *nic,int prog_fd) +{ +NetClientState *nc =qemu_get_peer (qemu_get_queue (nic),0 ); +if (nc ==NULL || nc->info->set_steering_ebpf ==NULL ) { +return false; + } + +return nc->info->set_steering_ebpf (nc, prog_fd); +} + +static void rss_data_to_rss_config (struct VirtioNetRssData *data, +struct EBPFRSSConfig *config) +{ + config->redirect = data->redirect; + config->populate_hash = data->populate_hash; + config->hash_types = data->hash_types; + config->indirections_len = data->indirections_len; + config->default_queue = data->default_queue; +} + +static bool virtio_net_load_epbf_rss (VirtIONet *n) +{hw/net/virtio-net.c static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd,
Quoted 10 lines
hw/net/virtio-net.c +10
-0+struct EBPFRSSConfig config = {}; + +if (!n->rss_data.enabled) { +if (ebpf_rss_is_loaded (&n->ebpf_rss)) { +ebpf_rss_unload (&n->ebpf_rss); + } +return true; + } + + if (!ebpf_rss_is_loaded(&n->ebpf_rss) &&!ebpf_rss_load(&n->ebpf_rss)) {
hw/net/virtio-net.c static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd,
Quoted 7 lines
hw/net/virtio-net.c +7
-0+return false; + } + +rss_data_to_rss_config (&n->rss_data, &config); + + if (!ebpf_rss_set_all(&n->ebpf_rss, &config, + n->rss_data.indirections_table,
n->rss_data.key)) {hw/net/virtio-net.c static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd,
Quoted 5 lines
hw/net/virtio-net.c +5
-0+ebpf_rss_unload (&n->ebpf_rss); +return false; + } + + if (!virtio_net_attach_steering_ebpf(n->nic,
n->ebpf_rss.program_fd)) {hw/net/virtio-net.c static uint16_t virtio_net_handle_rss(VirtIONet
Quoted 23 lines
hw/net/virtio-net.c +12
-0+ebpf_rss_unload (&n->ebpf_rss); +return false; + } + +return true; +} + +static void virtio_net_unload_epbf_rss (VirtIONet *n) +{ +virtio_net_attach_steering_ebpf (n->nic,-1 ); +ebpf_rss_unload (&n->ebpf_rss); } static uint16_t virtio_net_handle_rss(VirtIONet *n,@@ -1208,6 +1284,7 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, err_value = (uint32_t )s; goto error; } + n->rss_data.enabled_software_rss = false; n->rss_data.hash_types =virtio_ldl_p (vdev, &cfg.hash_types); n->rss_data.indirections_len =virtio_lduw_p (vdev, &cfg.indirection_table_mask);@@ -1289,9 +1366,30 @@ static uint16_t virtio_net_handle_rss(VirtIONet*n,
hw/net/virtio-net.c static uint16_t virtio_net_handle_rss(VirtIONet *n, · line 1371
Quoted 6 lines
hw/net/virtio-net.c +3
-0goto error; } n->rss_data.enabled = true; + +if (!n->rss_data.populate_hash) { +/* load EBPF RSS */ The code explains itself, so the comment is no necessary.
hw/net/virtio-net.c static uint16_t virtio_net_handle_rss(VirtIONet · line 1372
Quoted 1 line
hw/net/virtio-net.c +1
-0+if (!virtio_net_load_epbf_rss (n)) {Any reason that we load eBPF RSS here? I thought it would be easier to do it during
set_features(e.g when RSS is negotiated but notHASH_REPORT) and if we do that we don't need extra care about migration.hw/net/virtio-net.c static uint16_t virtio_net_handle_rss(VirtIONet *n, · line 1373
Quoted 1 line
hw/net/virtio-net.c +1
-0+/* EBPF mast be loaded for vhost */ Typo.
hw/net/virtio-net.c static uint16_t virtio_net_handle_rss(VirtIONet *n,
Quoted 6 lines
hw/net/virtio-net.c +6
-0+if (get_vhost_net (qemu_get_queue (n->nic)->peer)) { +warn_report ("Can't load eBPF RSS for vhost" ); + goto error; + } +/* fallback to software RSS */ + warn_report("Can't load eBPF RSS - fallback to softwareRSS");
hw/net/virtio-net.c static uint16_t virtio_net_handle_rss(VirtIONet *n, · line 1392
Quoted 13 lines
hw/net/virtio-net.c +10
-0+ n->rss_data.enabled_software_rss = true; + } + }else { +/* use software RSS for hash populating */ +/* and unload eBPF if was loaded before */ +virtio_net_unload_epbf_rss (n); + n->rss_data.enabled_software_rss = true; + } +trace_virtio_net_rss_enable (n->rss_data.hash_types, n->rss_data.indirections_len, temp.b); +Unnecessary changes.
hw/net/virtio-net.c static ssize_t
Quoted 4 lines
hw/net/virtio-net.c +0
-0return queues; error:trace_virtio_net_rss_error (err_msg, err_value);@@ -1674,7 +1772,7 @@ static ssize_tvirtio_net_receive_rcu(NetClientState *nc, const
uint8_t*buf,hw/net/virtio-net.c static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,
Quoted 5 lines
hw/net/virtio-net.c +1
-1return -1 ; } -if (!no_rss && n->rss_data.enabled) { + if (!no_rss && n->rss_data.enabled &&
n->rss_data.enabled_software_rss) {hw/net/virtio-net.c static int virtio_net_post_load_device(void
Quoted 4 lines
hw/net/virtio-net.c +0
-0int index =virtio_net_process_rss (nc, buf, size);if (index >=0 ) {NetClientState *nc2 =qemu_get_subqueue (n->nic, index);@@ -2780,6 +2878,18 @@ static int virtio_net_post_load_device(void*opaque, int
version_id)hw/net/virtio-net.c static int virtio_net_post_load_device(void *opaque, int version_id)
Quoted 10 lines
hw/net/virtio-net.c +7
-0}if (n->rss_data.enabled) { + n->rss_data.enabled_software_rss = n->rss_data.populate_hash; +if (!n->rss_data.populate_hash) { +if (!virtio_net_load_epbf_rss (n)) { +if (get_vhost_net (qemu_get_queue (n->nic)->peer)) { +error_report ("Can't post-load eBPF RSS for vhost" ); + }else { + warn_report("Can't post-load eBPF RSS - fallback tosoftware RSS");
hw/net/virtio-net.c static int virtio_net_post_load_device(void *opaque, int version_id) · line 2891
Quoted 4 lines
hw/net/virtio-net.c +4
-0+ n->rss_data.enabled_software_rss = true; + } + } + }btw, I don't see the save and restore of bpf maps, or is it unnecessary?
Thanks
Review
Quoted 14 lines
hw/net/virtio-net.c +3
-0+trace_virtio_net_rss_enable (n->rss_data.hash_types, n->rss_data.indirections_len,sizeof (n->rss_data.key));@@ -3453,6 +3563,8 @@ static void virtio_net_instance_init(Object *obj)device_add_bootindex_property (obj, &n->nic_conf.bootindex,"bootindex" ,"/ethernet-phy@0" ,DEVICE (n)); + +ebpf_rss_init (&n->ebpf_rss); }static int virtio_net_pre_save (void *opaque)(quoted diff) +0
-0
b/include/hw/virtio/virtio-net.hQuoted 41 lines
index
f4852ac27b..4d29a577eb100644include/hw/virtio/virtio-net.h +4
-0@@ -21,6 +21,8 @@#include "qemu/option_int.h" #include "qom/object.h" +#include "ebpf/ebpf_rss.h" +#define TYPE_VIRTIO_NET "virtio-net-device"OBJECT_DECLARE_SIMPLE_TYPE (VirtIONet,VIRTIO_NET )@@ -130,6 +132,7 @@ typedef struct VirtioNetRscChain { typedef struct VirtioNetRssData { bool enabled; + bool enabled_software_rss; bool redirect; bool populate_hash; uint32_t hash_types;@@ -214,6 +217,7 @@ struct VirtIONet {Notifier migration_state;VirtioNetRssData rss_data;struct NetRxPkt *rx_pkt; +struct EBPFRSSContext ebpf_rss; }; void virtio_net_set_netclient_name(VirtIONet *n, const char *name,net/vhost-vdpa.c +2
-0@@ -54,6 +54,8 @@ const int vdpa_feature_bits[] = {VIRTIO_NET_F_MTU ,VIRTIO_F_IOMMU_PLATFORM ,VIRTIO_F_RING_PACKED , +VIRTIO_NET_F_RSS , +VIRTIO_NET_F_HASH_REPORT ,VIRTIO_NET_F_GUEST_ANNOUNCE ,VIRTIO_NET_F_STATUS ,VHOST_INVALID_FEATURE_BIT
Re: [RFC PATCH v2 4/5] virtio-net: Added eBPF RSS to virtio-net.
Quoted 74 lines · Yuri Benditovich
On Tue, Nov 24, 2020 at 10:49 AM Jason Wang <[email protected] <mailto:[email protected]>> wrote:
On 2020/11/19 下午7:13, Andrew Melnychenko wrote:
> From: Andrew <[email protected] <mailto:[email protected]>> >
> When RSS is enabled the device tries to load the eBPF program > to select RX virtqueue in the TUN. If eBPF can be loaded > the RSS will function also with vhost (works with kernel 5.8 and later).
> Software RSS is used as a fallback with vhost=off when eBPF can't be loaded
> or when hash population requested by the guest.
>
> Signed-off-by: Yuri Benditovich <[email protected] <mailto:[email protected]>>
> Signed-off-by: Andrew Melnychenko <[email protected] <mailto:[email protected]>>
> ---
> hw/net/vhost_net.c | 2 +
> hw/net/virtio-net.c | 120
+++++++++++++++++++++++++++++++--
> include/hw/virtio/virtio-net.h | 4 ++
> net/vhost-vdpa.c | 2 +
> 4 files changed, 124 insertions(+), 4 deletions(-)
>
> diff --gita/hw/net/vhost_net.cb/hw/net/vhost_net.c
> index24d555e764..16124f99c3100644
> ---a/hw/net/vhost_net.c
> +++b/hw/net/vhost_net.c
> @@ -71,6 +71,8 @@ static const int user_feature_bits[] = { > VIRTIO_NET_F_MTU,
> VIRTIO_F_IOMMU_PLATFORM,
> VIRTIO_F_RING_PACKED,
> +VIRTIO_NET_F_RSS,
> +VIRTIO_NET_F_HASH_REPORT,
>
> /* This bit implies RARP isn't sent by QEMU out of band */ > VIRTIO_NET_F_GUEST_ANNOUNCE,
> diff --gita/hw/net/virtio-net.cb/hw/net/virtio-net.c
> index277289d56e..afcc3032ec100644
> ---a/hw/net/virtio-net.c
> +++b/hw/net/virtio-net.c
> @@ -698,6 +698,19 @@ static voidvirtio_net_set_queues(VirtIONet *n)>
> static voidvirtio_net_set_multiqueue(VirtIONet *n, int multiqueue);
>
> +staticuint64_tfix_ebpf_vhost_features(uint64_t features)> +{
> + /* If vhost=on &CONFIG_EBPFdoesn't set - disable RSS feature */
> +uint64_tret = features;
> +#ifndefCONFIG_EBPF
> +virtio_clear_feature(&ret, VIRTIO_NET_F_RSS);
> +#endif
> + /* for now, there is no solution for populating the hash from eBPF */
> +virtio_clear_feature(&ret, VIRTIO_NET_F_HASH_REPORT);I think there's still some misunderstanding here.
When "rss" is enabled via command line, qemu can't not turn it off silently, otherwise it may break migration. Instead, qemu should disable
vhost-net if eBPF can't be loaded.When "
hash_report" is enabled via command line, qemu should disable vhost-net unconditionally.
Quoted 8 lines
I agree in general with this requirement and I'm preparing an implementation of such fallback.
The problem is that qemu already uses the mechanism of turning off host features silently if they are not supported by the current vhost in kernel:
https://github.com/qemu/qemu/blob/b0f8c22d6d4d07f3bd2307bcc62e1660ef965472/hw/virtio/vhost.c#L1526Can you please comment on it and let me know how it should be modified in future? I've planned to use it in next work (implementing hash report in kernel)
This looks like a bug that needs to be solved. Otherwise we break migration from rss=on, vhost=off to rss=on,vhost=on.
I think you can keep the current code as is and I will try to seek a way to solve the issue.
Thanks
Re: [RFC PATCH v2 4/5] virtio-net: Added eBPF RSS to virtio-net.
Quoted 92 lines · Jason Wang
Quoted 39 lines · Yuri Benditovich
On Tue, Nov 24, 2020 at 10:49 AM Jason Wang <[email protected] <mailto:[email protected]>> wrote:
On 2020/11/19 下午7:13, Andrew Melnychenko wrote: > From: Andrew <[email protected] <mailto:[email protected]>> > > When RSS is enabled the device tries to load the eBPF program > to select RX virtqueue in the TUN. If eBPF can be loaded > the RSS will function also with vhost (works with kernel 5.8 and later). > Software RSS is used as a fallback with vhost=off when eBPF can't be loaded > or when hash population requested by the guest. > > Signed-off-by: Yuri Benditovich <[email protected] <mailto:[email protected]>> > Signed-off-by: Andrew Melnychenko <[email protected] <mailto:[email protected]>> > --- > hw/net/vhost_net.c | 2 + > hw/net/virtio-net.c | 120 +++++++++++++++++++++++++++++++-- > include/hw/virtio/virtio-net.h | 4 ++ > net/vhost-vdpa.c | 2 + > 4 files changed, 124 insertions(+), 4 deletions(-) > > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c > index 24d555e764..16124f99c3 100644 > --- a/hw/net/vhost_net.c > +++ b/hw/net/vhost_net.c > @@ -71,6 +71,8 @@ static const int user_feature_bits[] = { > VIRTIO_NET_F_MTU, > VIRTIO_F_IOMMU_PLATFORM, > VIRTIO_F_RING_PACKED, > + VIRTIO_NET_F_RSS, > + VIRTIO_NET_F_HASH_REPORT,Quoted 8 lines
> > /* This bit implies RARP isn't sent by QEMU out of band */ > VIRTIO_NET_F_GUEST_ANNOUNCE, > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c > index 277289d56e..afcc3032ec 100644 > --- a/hw/net/virtio-net.c > +++ b/hw/net/virtio-net.c > @@ -698,6 +698,19 @@ static void virtio_net_set_queues(VirtIONet*n)
Quoted 28 lines
Quoted 2 lines
static void virtio_net_set_multiqueue(VirtIONet *n, int
multiqueue);
>
> +staticuint64_tfix_ebpf_vhost_features(uint64_t features)> +{
> + /* If vhost=on &CONFIG_EBPFdoesn't set - disable RSS
feature */
> +uint64_tret = features;
> +#ifndefCONFIG_EBPF
> +virtio_clear_feature(&ret, VIRTIO_NET_F_RSS);
> +#endif
> + /* for now, there is no solution for populating the hash
from eBPF */
> +virtio_clear_feature(&ret, VIRTIO_NET_F_HASH_REPORT);I think there's still some misunderstanding here.
When "rss" is enabled via command line, qemu can't not turn it off silently, otherwise it may break migration. Instead, qemu should disable
vhost-net if eBPF can't be loaded.When "
hash_report" is enabled via command line, qemu should disable vhost-net unconditionally.Quoted 7 lines
I agree in general with this requirement and I'm preparing an implementation of such fallback.
The problem is that qemu already uses the mechanism of turning off host features
silently if they are not supported by the current vhost in kernel:https://github.com/qemu/qemu/blob/b0f8c22d6d4d07f3bd2307bcc62e1660ef965472/hw/virtio/vhost.c#L1526
Quoted 4 lines
Can you please comment on it and let me know how it should be modified in future?
I've planned to use it in next work (implementing hash report in kernel)
Quoted 4 lines
This looks like a bug that needs to be solved. Otherwise we break migration from rss=on, vhost=off to rss=on,vhost=on.
I think I need to fill the gap in my understanding of migration's
prerequisites.
According to
https://github.com/qemu/qemu/blob/b0f8c22d6d4d07f3bd2307bcc62e1660ef965472/docs/devel/migration.rst
"... QEMU has to be launched with the same arguments the two times ..." and we test the migration during development
according to this statement.
What are the real requirements and prerequisites of the migration?
Quoted 6 lines
I think you can keep the current code as is and I will try to seek a way to solve the issue.
Thanks
Re: [RFC PATCH v2 4/5] virtio-net: Added eBPF RSS to virtio-net.
Quoted 107 lines · Yuri Benditovich
On Wed, Dec 2, 2020 at 6:06 AM Jason Wang <[email protected] <mailto:[email protected]>> wrote:
On 2020/12/1 下午3:40, Yuri Benditovich wrote:
>
>
> On Tue, Nov 24, 2020 at 10:49 AM Jason Wang <[email protected] <mailto:[email protected]>
> <mailto:[email protected] <mailto:[email protected]>>> wrote:
>
>
> On 2020/11/19 下午7:13, Andrew Melnychenko wrote:
> > From: Andrew <[email protected] <mailto:[email protected]> <mailto:[email protected] <mailto:[email protected]>>>
> >
> > When RSS is enabled the device tries to load the eBPF program > > to select RX virtqueue in the TUN. If eBPF can be loaded > > the RSS will function also with vhost (works with kernel 5.8 and
> later).
> > Software RSS is used as a fallback with vhost=off when eBPF > can't be loaded
> > or when hash population requested by the guest.
> >
> > Signed-off-by: Yuri Benditovich <[email protected] <mailto:[email protected]> > <mailto:[email protected] <mailto:[email protected]>>>
> > Signed-off-by: Andrew Melnychenko <[email protected] <mailto:[email protected]>
> <mailto:[email protected] <mailto:[email protected]>>> > > ---
> > hw/net/vhost_net.c | 2 +
> > hw/net/virtio-net.c | 120
> +++++++++++++++++++++++++++++++--
> > include/hw/virtio/virtio-net.h | 4 ++
> > net/vhost-vdpa.c | 2 +
> > 4 files changed, 124 insertions(+), 4 deletions(-) > >
> > diff --gita/hw/net/vhost_net.cb/hw/net/vhost_net.c> > index24d555e764..16124f99c3100644
> > ---a/hw/net/vhost_net.c
> > +++b/hw/net/vhost_net.c
> > @@ -71,6 +71,8 @@ static const int user_feature_bits[] = { > > VIRTIO_NET_F_MTU,
> > VIRTIO_F_IOMMU_PLATFORM,
> > VIRTIO_F_RING_PACKED,
> > +VIRTIO_NET_F_RSS,
> > +VIRTIO_NET_F_HASH_REPORT,
> >
> > /* This bit implies RARP isn't sent by QEMU out of band */
> > VIRTIO_NET_F_GUEST_ANNOUNCE,
> > diff --gita/hw/net/virtio-net.cb/hw/net/virtio-net.c> > index277289d56e..afcc3032ec100644
> > ---a/hw/net/virtio-net.c
> > +++b/hw/net/virtio-net.c
> > @@ -698,6 +698,19 @@ static voidvirtio_net_set_queues(VirtIONet *n)
> >
> > static voidvirtio_net_set_multiqueue(VirtIONet *n, int > multiqueue);
> >
> > +staticuint64_tfix_ebpf_vhost_features(uint64_t features)> > +{
> > + /* If vhost=on &CONFIG_EBPFdoesn't set - disable RSS > feature */
> > +uint64_tret = features;
> > +#ifndefCONFIG_EBPF
> > +virtio_clear_feature(&ret, VIRTIO_NET_F_RSS); > > +#endif
> > + /* for now, there is no solution for populating the hash > from eBPF */
> > +virtio_clear_feature(&ret, VIRTIO_NET_F_HASH_REPORT); >
>
> I think there's still some misunderstanding here.
>
> When "rss" is enabled via command line, qemu can't not turn it off
> silently, otherwise it may break migration. Instead, qemu should > disable
> vhost-net if eBPF can't be loaded.
>
> When "hash_report" is enabled via command line, qemu should disable
> vhost-net unconditionally.
>
>
> I agree in general with this requirement and I'm preparing an > implementation of such fallback.
>
> The problem is that qemu already uses the mechanism of turning off > host features
> silently if they are not supported by the current vhost in kernel:
>
https://github.com/qemu/qemu/blob/b0f8c22d6d4d07f3bd2307bcc62e1660ef965472/hw/virtio/vhost.c#L1526
>
> Can you please comment on it and let me know how it should be modified
> in future?
> I've planned to use it in next work (implementing hash report in kernel)
Quoted 7 lines
This looks like a bug that needs to be solved. Otherwise we break migration from rss=on, vhost=off to rss=on,vhost=on.
I think I need to fill the gap in my understanding of migration's prerequisites.
According to https://github.com/qemu/qemu/blob/b0f8c22d6d4d07f3bd2307bcc62e1660ef965472/docs/devel/migration.rst
"... QEMU has to be launched with the same arguments the two times ..." and we test the migration during development according to this statement.
Yes, that's the overall requirement. And it shows the issue of disabling feature silently. If we had src whose vhost support feature A and dst vhost doesn't support. Even if we launch the QEMU with the same arguments, it can still fail.
So actually two issues:
1) whether or not to disable features silently
2) whether or not to support migration between vhost=on to vhost=off
For 1), I think we'd better don't do that, and if we can do 1), it would be possible to achieve 2).
Quoted 1 line
What are the real requirements and prerequisites of the migration?
For virtio, I think we allow some kind of extra flexibility. We try to make migration work between vhost=off and vhost=on. What we need is just to keep everything that visible to guest after migration the same as before migration. Obviously, device features is one of the thing.
Thanks
Quoted 7 lines
I think you can keep the current code as is and I will try to seek a way
to solve the issue.Thanks
RFC PATCH v2 5/5 docs: Added eBPF documentation.
In reply to Andrew MelnychenkoFrom: Andrew <[email protected]>
Also, added maintainers information.
--- MAINTAINERS | 7 +++ docs/ebpf_rss.rst | 133 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) create mode 100644 docs/ebpf_rss.rst
MAINTAINERS +7 -0
@@ -3111,6 +3111,13 @@ S: Maintained F: hw/semihosting/ F: include/hw/semihosting/ +EBPF: +M: Jason Wang <[email protected]> +R: Andrew Melnychenko <[email protected]> +R: Yuri Benditovich <[email protected]> +S: Maintained +F: ebpf/* + Build and test automation ------------------------- Build and test automation
docs/ebpf_rss.rst new file +133 -0
133 lines not on this page · raw message
Signature · 1 line
2.29.2
Re: [RFC PATCH v2 5/5] docs: Added eBPF documentation.
Quoted 102 lines · Andrew Melnychenko
From: Andrew <[email protected]>
Also, added maintainers information.
Signed-off-by Yuri Benditovich <[email protected]>Signed-off-by Andrew Melnychenko <[email protected]>--- MAINTAINERS | 7 +++ docs/ebpf_rss.rst | 133 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+)create mode 100644
docs/ebpf_rss.rstMAINTAINERS +7
-0@@ -3111,6 +3111,13 @@ S: Maintained F: hw/semihosting/ F: include/hw/semihosting/ +EBPF: +M: Jason Wang <[email protected]> +R: Andrew Melnychenko <[email protected]> +R: Yuri Benditovich <[email protected]> +S: Maintained +F: ebpf/* + Build and test automation ------------------------- Build and test automationdocs/ebpf_rss.rst new file +66
-0@@ -0,0 +1,133 @@ +=========================== +eBPF RSS virtio-net support +=========================== + +RSS(Receive Side Scaling) is used to distribute network packets to guest virtqueues +by calculating packet hash. Usually every queue is processed then by a specific guest CPU core. + +For now there are 2 RSS implementations in qemu: +- 'in-qemu' RSS (functions if qemu receives network packets, i.e. vhost=off) +- eBPF RSS (can function with also with vhost=on) + +eBPF support (CONFIG_EBPF) is enabled by 'configure' script. +To enable eBPF RSS support use './configure --enable-bpf'. + +If steering BPF is not set for kernel's TUN module, the TUN uses automatic selection +of rx virtqueue based on lookup table built according to calculated symmetric hash +of transmitted packets. +If steering BPF is set for TUN the BPF code calculates the hash of packet header and +returns the virtqueue number to place the packet to. + +Simplified decision formula: + +.. code:: C + + queue_index = indirection_table[hash(<packet data>)%<indirection_table size>] + + +Not for all packets, the hash can/should be calculated. + +Note: currently, eBPF RSS does not support hash reporting. + +eBPF RSS turned on by different combinations of vhost-net, vitrio-net and tap configurations: + +- eBPF is used: + + tap,vhost=off & virtio-net-pci,rss=on,hash=off + +- eBPF is used: + + tap,vhost=on & virtio-net-pci,rss=on,hash=off + +- 'in-qemu' RSS is used: + + tap,vhost=off & virtio-net-pci,rss=on,hash=on + +- eBPF is used, hash population feature is not reported to the guest: + + tap,vhost=on & virtio-net-pci,rss=on,hash=on + +If CONFIG_EBPF is not set then only 'in-qemu' RSS is supported. +Also 'in-qemu' RSS, as a fallback, is used if the eBPF program failed to load or set to TUN. + +RSS eBPF program +---------------- + +RSS program located in ebpf/tun_rss_steering.h as an array of 'struct bpf_insn'. +So the program is part of the qemu binary. +Initially, the eBPF program was compiled by clang and source code located at ebpf/rss.bpf.c. +Prerequisites to recompile the eBPF program (regenerate ebpf/tun_rss_steering.h): + + llvm, clang, kernel source tree, python3 + (pip3 pyelftools) + Adjust 'linuxhdrs' in Makefile.ebpf to reflect the location of the kernel source tree + + $ cd ebpf + $ make -f Makefile.ebpf +
docs/ebpf_rss.rst line 76
Quoted 10 lines
docs/ebpf_rss.rst new file +10
-0+Note the python script for convertation from eBPF ELF object to '.h' file - Ebpf_to_C.py: + + $ python EbpfElf_to_C.py rss.bpf.o tun_rss_steering + +The first argument of the script is ELF object, second - section name where the eBPF program located. +The script would generate <section name>.h file with eBPF instructions and 'relocate array'. +'relocate array' is an array of 'struct fixup_mapfd_t' with the name of the eBPF map and instruction offset where the file descriptor of the map should be placed. + +Current eBPF RSS implementation uses 'bounded loops' with 'backward jump instructions' which present in the last kernels. +Overall eBPF RSS works on kernels 5.8+.
This reminds me that we probably need to probe this ability via configure script.
Thanks
Quoted 57 lines
docs/ebpf_rss.rst new file +57
-0+ +eBPF RSS implementation +----------------------- + +eBPF RSS loading functionality located in ebpf/ebpf_rss.c and ebpf/ebpf_rss.h. + +The `struct EBPFRSSContext` structure that holds 4 file descriptors: + +- ctx - pointer of the libbpf context. +- program_fd - file descriptor of the eBPF RSS program. +- map_configuration - file descriptor of the 'configuration' map. This map contains one element of 'struct EBPFRSSConfig'. This configuration determines eBPF program behavior. +- map_toeplitz_key - file descriptor of the 'Toeplitz key' map. One element of the 40byte key prepared for the hashing algorithm. +- map_indirections_table - 128 elements of queue indexes. + +`struct EBPFRSSConfig` fields: + +- redirect - "boolean" value, should the hash be calculated, on false - `default_queue` would be used as the final decision. +- populate_hash - for now, not used. eBPF RSS doesn't support hash reporting. +- hash_types - binary mask of different hash types. See `VIRTIO_NET_RSS_HASH_TYPE_*` defines. If for packet hash should not be calculated - `default_queue` would be used. +- indirections_len - length of the indirections table, maximum 128. +- default_queue - the queue index that used for packet that shouldn't be hashed. For some packets, the hash can't be calculated(g.e ARP). + +Functions: + +- `ebpf_rss_init()` - sets ctx to NULL, which indicates that EBPFRSSContext is not loaded. +- `ebpf_rss_load()` - creates 3 maps and loads eBPF program from tun_rss_steering.h. Returns 'true' on success. After that, program_fd can be used to set steering for TAP. +- `ebpf_rss_set_all()` - sets values for eBPF maps. `indirections_table` length is in EBPFRSSConfig. `toeplitz_key` is VIRTIO_NET_RSS_MAX_KEY_SIZE aka 40 bytes array. +- `ebpf_rss_unload()` - close all file descriptors and set ctx to NULL. + +Simplified eBPF RSS workflow: + +.. code:: C + + struct EBPFRSSConfig config; + config.redirect = 1; + config.hash_types = VIRTIO_NET_RSS_HASH_TYPE_UDPv4 | VIRTIO_NET_RSS_HASH_TYPE_TCPv4; + config.indirections_len = VIRTIO_NET_RSS_MAX_TABLE_LEN; + config.default_queue = 0; + + uint16_t table[VIRTIO_NET_RSS_MAX_TABLE_LEN] = {...}; + uint8_t key[VIRTIO_NET_RSS_MAX_KEY_SIZE] = {...}; + + struct EBPFRSSContext ctx; + ebpf_rss_init(&ctx); + ebpf_rss_load(&ctx); + ebpf_rss_set_all(&ctx, &config, table, key); + if (net_client->info->set_steering_ebpf != NULL) { + net_client->info->set_steering_ebpf(net_client, ctx->program_fd); + } + ... + ebpf_unload(&ctx); + + +NetClientState SetSteeringEBPF() +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +For now, `set_steering_ebpf()` method supported by Linux TAP NetClientState. The method requires an eBPF program file descriptor as an argument.
Re: [RFC PATCH v2 5/5] docs: Added eBPF documentation.
Quoted 129 lines · Jason Wang
Quoted 36 lines · Andrew Melnychenko
From: Andrew <[email protected]>
Also, added maintainers information.
Signed-off-by Yuri Benditovich <[email protected]>Signed-off-by Andrew Melnychenko <[email protected]>--- MAINTAINERS | 7 +++ docs/ebpf_rss.rst | 133 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+)create mode 100644
docs/ebpf_rss.rstMAINTAINERS +7
-0@@ -3111,6 +3111,13 @@ S: Maintained F: hw/semihosting/ F: include/hw/semihosting/ +EBPF: +M: Jason Wang <[email protected]> +R: Andrew Melnychenko <[email protected]> +R: Yuri Benditovich <[email protected]> +S: Maintained +F: ebpf/* + Build and test automation ------------------------- Build and test automationdocs/ebpf_rss.rst new file +0
-0docs/ebpf_rss.rst line 5
Quoted 5 lines
docs/ebpf_rss.rst new file +5
-0@@ -0,0 +1,133 @@ +=========================== +eBPF RSS virtio-net support +=========================== + +RSS(Receive Side Scaling) is used to distribute network packets toguest virtqueues
docs/ebpf_rss.rst line 6
Quoted 1 line
docs/ebpf_rss.rst new file +1
-0+by calculating packet hash. Usually every queue is processed then by aspecific guest CPU core.
docs/ebpf_rss.rst
Quoted 3 lines
docs/ebpf_rss.rst new file +3
-0+ +For now there are 2 RSS implementations in qemu: +- 'in-qemu' RSS (functions if qemu receives network packets, i.e.vhost=off)
docs/ebpf_rss.rst
Quoted 6 lines
docs/ebpf_rss.rst new file +6
-0+- eBPF RSS (can function with also with vhost=on) + +eBPF support (CONFIG_EBPF) is enabled by 'configure' script. +To enable eBPF RSS support use './configure --enable-bpf'. + +If steering BPF is not set for kernel's TUN module, the TUN usesautomatic selection
docs/ebpf_rss.rst line 16
Quoted 1 line
docs/ebpf_rss.rst new file +1
-0+of rx virtqueue based on lookup table built according to calculatedsymmetric hash
docs/ebpf_rss.rst line 18
Quoted 2 lines
docs/ebpf_rss.rst new file +2
-0+of transmitted packets. +If steering BPF is set for TUN the BPF code calculates the hash ofpacket header and
docs/ebpf_rss.rst
Quoted 7 lines
docs/ebpf_rss.rst new file +7
-0+returns the virtqueue number to place the packet to. + +Simplified decision formula: + +.. code:: C + + queue_index = indirection_table[hash(<packetdata>)%<indirection_table size>]
docs/ebpf_rss.rst
Quoted 7 lines
docs/ebpf_rss.rst new file +7
-0+ + +Not for all packets, the hash can/should be calculated. + +Note: currently, eBPF RSS does not support hash reporting. + +eBPF RSS turned on by different combinations of vhost-net, vitrio-netand tap configurations:
Quoted 9 lines
docs/ebpf_rss.rst new file +9
-0+ +- eBPF is used: + + tap,vhost=off & virtio-net-pci,rss=on,hash=off + +- eBPF is used: + + tap,vhost=on & virtio-net-pci,rss=on,hash=off +docs/ebpf_rss.rst
Quoted 10 lines
docs/ebpf_rss.rst new file +10
-0+- 'in-qemu' RSS is used: + + tap,vhost=off & virtio-net-pci,rss=on,hash=on + +- eBPF is used, hash population feature is not reported to the guest: + + tap,vhost=on & virtio-net-pci,rss=on,hash=on + +If CONFIG_EBPF is not set then only 'in-qemu' RSS is supported. +Also 'in-qemu' RSS, as a fallback, is used if the eBPF program failedto load or set to TUN.
docs/ebpf_rss.rst
Quoted 5 lines
docs/ebpf_rss.rst new file +5
-0+ +RSS eBPF program +---------------- + +RSS program located in ebpf/tun_rss_steering.h as an array of 'struct
bpf_insn'.docs/ebpf_rss.rst line 58
Quoted 2 lines
docs/ebpf_rss.rst new file +2
-0+So the program is part of the qemu binary. +Initially, the eBPF program was compiled by clang and source codelocated at
ebpf/rss.bpf.c.docs/ebpf_rss.rst line 59
Quoted 1 line
docs/ebpf_rss.rst new file +1
-0+Prerequisites to recompile the eBPF program (regenerate
ebpf/tun_rss_steering.h):docs/ebpf_rss.rst
Quoted 3 lines
docs/ebpf_rss.rst new file +3
-0+ + llvm, clang, kernel source tree, python3 + (pip3 pyelftools) + Adjust 'linuxhdrs' in Makefile.ebpf to reflect the location ofthe kernel source tree
docs/ebpf_rss.rst
Quoted 5 lines
docs/ebpf_rss.rst new file +5
-0+ + $ cd ebpf + $ make -f Makefile.ebpf + +Note the python script for convertation from eBPF ELF object to '.h'file -
Ebpf_to_C.py:docs/ebpf_rss.rst
Quoted 4 lines
docs/ebpf_rss.rst new file +4
-0+ + $ python EbpfElf_to_C.py rss.bpf.o tun_rss_steering + +The first argument of the script is ELF object, second - section namewhere the eBPF program located.
docs/ebpf_rss.rst line 72
Quoted 1 line
docs/ebpf_rss.rst new file +1
-0+The script would generate <section name>.h file with eBPF instructionsand 'relocate array'.
docs/ebpf_rss.rst line 73
Quoted 1 line
docs/ebpf_rss.rst new file +1
-0+'relocate array' is an array of 'struct fixup_mapfd_t' with the name ofthe eBPF map and instruction offset where the file descriptor of the map should be placed.
Quoted 10 lines
docs/ebpf_rss.rst line 75
Quoted 2 lines
docs/ebpf_rss.rst new file +2
-0+ +Current eBPF RSS implementation uses 'bounded loops' with 'backwardjump instructions' which present in the last kernels.
docs/ebpf_rss.rst line 76
Quoted 1 line
docs/ebpf_rss.rst new file +1
-0+Overall eBPF RSS works on kernels 5.8+.This reminds me that we probably need to probe this ability via configure script.
I'm not sure. One can boot with an older kernel, build qemu and run it with a newer kernel, correct?
Quoted 80 lines
Thanks
docs/ebpf_rss.rst
Quoted 5 lines
docs/ebpf_rss.rst new file +5
-0+ +eBPF RSS implementation +----------------------- + +eBPF RSS loading functionality located in ebpf/ebpf_rss.c and
ebpf/ebpf_rss.h.docs/ebpf_rss.rst
Quoted 6 lines
docs/ebpf_rss.rst new file +6
-0+ +The `struct EBPFRSSContext` structure that holds 4 file descriptors: + +- ctx - pointer of the libbpf context. +- program_fd - file descriptor of the eBPF RSS program. +- map_configuration - file descriptor of the 'configuration' map. Thismap contains one element of 'struct EBPFRSSConfig'. This configuration determines eBPF program behavior.
docs/ebpf_rss.rst line 88
Quoted 1 line
docs/ebpf_rss.rst new file +1
-0+- map_toeplitz_key - file descriptor of the 'Toeplitz key' map. Oneelement of the 40byte key prepared for the hashing algorithm.
docs/ebpf_rss.rst
Quoted 5 lines
docs/ebpf_rss.rst new file +5
-0+- map_indirections_table - 128 elements of queue indexes. + +`struct EBPFRSSConfig` fields: + +- redirect - "boolean" value, should the hash be calculated, on false-
default_queuewould be used as the final decision.docs/ebpf_rss.rst line 94
Quoted 1 line
docs/ebpf_rss.rst new file +1
-0+- populate_hash - for now, not used. eBPF RSS doesn't support hashreporting.
docs/ebpf_rss.rst line 95
Quoted 1 line
docs/ebpf_rss.rst new file +1
-0+- hash_types - binary mask of different hash types. See
VIRTIO_NET_RSS_HASH_TYPE_*defines. If for packet hash should not be calculated -default_queuewould be used.docs/ebpf_rss.rst line 97
Quoted 2 lines
docs/ebpf_rss.rst new file +2
-0+- indirections_len - length of the indirections table, maximum 128. +- default_queue - the queue index that used for packet that shouldn'tbe hashed. For some packets, the hash can't be calculated(g.e ARP).
docs/ebpf_rss.rst
Quoted 4 lines
docs/ebpf_rss.rst new file +4
-0+ +Functions: + +- `ebpf_rss_init()` - sets ctx to NULL, which indicates thatEBPFRSSContext is not loaded.
docs/ebpf_rss.rst line 102
Quoted 1 line
docs/ebpf_rss.rst new file +1
-0+- `ebpf_rss_load()` - creates 3 maps and loads eBPF program from
tun_rss_steering.h. Returns 'true' on success. After that,program_fdcan be used to set steering for TAP.docs/ebpf_rss.rst line 103
Quoted 1 line
docs/ebpf_rss.rst new file +1
-0+- `ebpf_rss_set_all()` - sets values for eBPF maps.
indirections_tablelength is in EBPFRSSConfig.toeplitz_keyisVIRTIO_NET_RSS_MAX_KEY_SIZEaka 40 bytes array.docs/ebpf_rss.rst
Quoted 9 lines
docs/ebpf_rss.rst new file +9
-0+- `ebpf_rss_unload()` - close all file descriptors and set ctx to NULL. + +Simplified eBPF RSS workflow: + +.. code:: C + + struct EBPFRSSConfig config; + config.redirect = 1; + config.hash_types = VIRTIO_NET_RSS_HASH_TYPE_UDPv4 |
VIRTIO_NET_RSS_HASH_TYPE_TCPv4;docs/ebpf_rss.rst
Quoted 12 lines
docs/ebpf_rss.rst new file +12
-0+ config.indirections_len = VIRTIO_NET_RSS_MAX_TABLE_LEN; + config.default_queue = 0; + + uint16_t table[VIRTIO_NET_RSS_MAX_TABLE_LEN] = {...}; + uint8_t key[VIRTIO_NET_RSS_MAX_KEY_SIZE] = {...}; + + struct EBPFRSSContext ctx; + ebpf_rss_init(&ctx); + ebpf_rss_load(&ctx); + ebpf_rss_set_all(&ctx, &config, table, key); + if (net_client->info->set_steering_ebpf != NULL) { + net_client->info->set_steering_ebpf(net_client,
ctx->program_fd);docs/ebpf_rss.rst
Quoted 9 lines
docs/ebpf_rss.rst new file +9
-0+ } + ... + ebpf_unload(&ctx); + + +NetClientState SetSteeringEBPF() +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +For now, `set_steering_ebpf()` method supported by Linux TAPNetClientState. The method requires an eBPF program file descriptor as an argument.
Re: [RFC PATCH v2 5/5] docs: Added eBPF documentation.
Quoted 8 lines · Yuri Benditovich
This reminds me that we probably need to probe this ability via configure script.
I'm not sure. One can boot with an older kernel, build qemu and run it with a newer kernel, correct?
Yes, so we should depend on verifier instead of the probe here.
Thanks
Quoted 2 lines
Thanks
Quoted 30 lines · Andrew Melnychenko
This set of patches introduces the usage of eBPF for packet steering and RSS hash calculation:
* RSS(Receive Side Scaling) is used to distribute network packets to guest virtqueues by calculating packet hash
* Additionally adding support for the usage of RSS with vhostThe eBPF works on kernels 5.8+
On earlier kerneld it fails to load and the RSS feature is reported only without vhost and implemented in 'in-qemu' software.Implementation notes:
Linux TAP TUNSETSTEERINGEBPF ioctl was used to set the eBPF program. Added libbpf dependency and eBPF support.
The eBPF program is part of the qemu and presented as an array of BPF ELF file data.
The compilation of eBPF is not part of QEMU build and can be done using providedMakefile.ebpf(need to adjust 'linuxhdrs').
Added changes to virtio-net and vhost, primary eBPF RSS is used. 'in-qemu' RSS used in the case of hash population and as a fallback option. For vhost, the hash population feature is not reported to the guest.Please also see the documentation in PATCH 5/5.
I am sending those patches as RFC to initiate the discussions and get feedback on the following points:
* Fallback when eBPF is not supported by the kernel
* Live migration to the kernel that doesn't have eBPF support
* Integration with current QEMU build
* Additional usage for eBPF for packet filtering
Quoted 10 lines
Known issues:
* hash population not supported by eBPF RSS: 'in-qemu' RSS used
as a fallback, also, hash population feature is not reported to guests with vhost.
* big-endian BPF support: for now, eBPF isn't supported on
big-endian systems. Can be added in future if required.
* huge .h file with eBPF binary. The size of .h file containing
eBPF binary is currently ~5K lines, because the binary is built with debug information. The binary without debug/BTF info can't be loaded by libbpf.
We're looking for possibilities to reduce the size of the .h files.
A question here, is this because the binary file contains DWARF data? If yes, is it a building or loading dependency? If it's latter, maybe we can try to strip them out, anyhow it can't be recognized by kernel.
Thanks
Quoted 53 lines
Changes since v1:
* using libbpf instead of direct 'bpf' system call.
* added libbpf dependency to the configure/meson scripts.
* changed python script for eBPF .h file generation.
* changed eBPF program - reading L3 proto from ethernet frame.
* added TUNSETSTEERINGEBPF define for TUN.
* changed the maintainer's info.
* added license headers.
* refactored code.Andrew (5):
net: Added SetSteeringEBPF method for NetClientState.
ebpf: Added eBPF RSS program.
ebpf: Added eBPF RSS loader.
virtio-net: Added eBPF RSS to virtio-net.
docs: Added eBPF RSS documentation.MAINTAINERS | 7 + configure | 33 + docs/ebpf_rss.rst | 133 + ebpf/EbpfElf_to_C.py | 36 + ebpf/Makefile.ebpf | 33 + ebpf/ebpf_rss-stub.c | 40 + ebpf/ebpf_rss.c | 186 ++ ebpf/ebpf_rss.h | 44 + ebpf/meson.build | 1 + ebpf/rss.bpf.c | 505 +++ ebpf/tun_rss_steering.h | 5439 ++++++++++++++++++++++++++++++++ hw/net/vhost_net.c | 2 + hw/net/virtio-net.c | 120 +- include/hw/virtio/virtio-net.h | 4 + include/net/net.h | 2 + meson.build | 11 + net/tap-bsd.c | 5 + net/tap-linux.c | 13 + net/tap-linux.h | 1 + net/tap-solaris.c | 5 + net/tap-stub.c | 5 + net/tap.c | 9 + net/tap_int.h | 1 + net/vhost-vdpa.c | 2 + 24 files changed, 6633 insertions(+), 4 deletions(-)create mode 100644
docs/ebpf_rss.rst
create mode 100644ebpf/EbpfElf_to_C.py
create mode 100755 ebpf/Makefile.ebpf
create mode 100644ebpf/ebpf_rss-stub.c
create mode 100644ebpf/ebpf_rss.c
create mode 100644ebpf/ebpf_rss.h
create mode 100644 ebpf/meson.build
create mode 100644ebpf/rss.bpf.c
create mode 100644ebpf/tun_rss_steering.h
Quoted 46 lines · Jason Wang
Quoted 10 lines · Andrew Melnychenko
This set of patches introduces the usage of eBPF for packet steering and RSS hash calculation:
* RSS(Receive Side Scaling) is used to distribute network packets to guest virtqueues by calculating packet hash
* Additionally adding support for the usage of RSS with vhostThe eBPF works on kernels 5.8+
On earlier kerneld it fails to load and the RSS feature is reported only without vhost and implemented in 'in-qemu' software.Quoted 9 lines
Implementation notes:
Linux TAP TUNSETSTEERINGEBPF ioctl was used to set the eBPF program. Added libbpf dependency and eBPF support.
The eBPF program is part of the qemu and presented as an array of BPF ELF file data.
The compilation of eBPF is not part of QEMU build and can be done using providedMakefile.ebpf(need to adjust 'linuxhdrs'). Added changes to virtio-net and vhost, primary eBPF RSS is used. 'in-qemu' RSS used in the case of hash population and as a fallbackoption.
Quoted 11 lines
For vhost, the hash population feature is not reported to the guest.
Please also see the documentation in PATCH 5/5.
I am sending those patches as RFC to initiate the discussions and get feedback on the following points:
* Fallback when eBPF is not supported by the kernel
* Live migration to the kernel that doesn't have eBPF support
* Integration with current QEMU build
* Additional usage for eBPF for packet filteringQuoted 8 lines
Known issues:
* hash population not supported by eBPF RSS: 'in-qemu' RSS used as a fallback, also, hash population feature is not reported to guests with vhost.
* big-endian BPF support: for now, eBPF isn't supported on big-endian systems. Can be added in future if required.
* huge .h file with eBPF binary. The size of .h file containing eBPF binary is currently ~5K lines, because the binary is built withdebug information.
Quoted 2 lines
The binary without debug/BTF info can't be loaded by libbpf. We're looking for possibilities to reduce the size of the .h files.
Quoted 7 lines
A question here, is this because the binary file contains DWARF data? If yes, is it a building or loading dependency? If it's latter, maybe we can try to strip them out, anyhow it can't be recognized by kernel.
Thanks
After some experiments we can see that stripping of debug sections reduces the size of
ELF from ~45K to ~20K (we tried to strip more but the libbpf fails to load it, libbpf needs BTF and symbols)
So I suggest to reevaluate the necessity of libbpf.
For this specific BPF it does not present advantage and we hardly can create some reusable code
related to libbpf, i.e. any further BPF will need its own libbpf wrapper. The BTF is really good feature and in case some later BPF will need an access to kernel
structures it will use libbpf loader.
What you think about it?
Quoted 56 lines
Quoted 54 lines
Changes since v1:
* using libbpf instead of direct 'bpf' system call.
* added libbpf dependency to the configure/meson scripts.
* changed python script for eBPF .h file generation.
* changed eBPF program - reading L3 proto from ethernet frame.
* added TUNSETSTEERINGEBPF define for TUN.
* changed the maintainer's info.
* added license headers.
* refactored code.Andrew (5):
net: Added SetSteeringEBPF method for NetClientState.
ebpf: Added eBPF RSS program.
ebpf: Added eBPF RSS loader.
virtio-net: Added eBPF RSS to virtio-net.
docs: Added eBPF RSS documentation.MAINTAINERS | 7 + configure | 33 + docs/ebpf_rss.rst | 133 + ebpf/EbpfElf_to_C.py | 36 + ebpf/Makefile.ebpf | 33 + ebpf/ebpf_rss-stub.c | 40 + ebpf/ebpf_rss.c | 186 ++ ebpf/ebpf_rss.h | 44 + ebpf/meson.build | 1 + ebpf/rss.bpf.c | 505 +++ ebpf/tun_rss_steering.h | 5439 ++++++++++++++++++++++++++++++++ hw/net/vhost_net.c | 2 + hw/net/virtio-net.c | 120 +- include/hw/virtio/virtio-net.h | 4 + include/net/net.h | 2 + meson.build | 11 + net/tap-bsd.c | 5 + net/tap-linux.c | 13 + net/tap-linux.h | 1 + net/tap-solaris.c | 5 + net/tap-stub.c | 5 + net/tap.c | 9 + net/tap_int.h | 1 + net/vhost-vdpa.c | 2 + 24 files changed, 6633 insertions(+), 4 deletions(-)create mode 100644
docs/ebpf_rss.rst
create mode 100644ebpf/EbpfElf_to_C.py
create mode 100755 ebpf/Makefile.ebpf
create mode 100644ebpf/ebpf_rss-stub.c
create mode 100644ebpf/ebpf_rss.c
create mode 100644ebpf/ebpf_rss.h
create mode 100644 ebpf/meson.build
create mode 100644ebpf/rss.bpf.c
create mode 100644ebpf/tun_rss_steering.h
Quoted 60 lines · Yuri Benditovich
On Mon, Nov 23, 2020 at 8:08 AM Jason Wang <[email protected] <mailto:[email protected]>> wrote:
On 2020/11/19 下午7:13, Andrew Melnychenko wrote:
> This set of patches introduces the usage of eBPF for packet steering > and RSS hash calculation:
> * RSS(Receive Side Scaling) is used to distribute network packets to > guest virtqueues by calculating packet hash
> * Additionally adding support for the usage of RSS with vhost >
> The eBPF works on kernels 5.8+
> On earlier kerneld it fails to load and the RSS feature is reported > only without vhost and implemented in 'in-qemu' software. >
> Implementation notes:
> Linux TAP TUNSETSTEERINGEBPF ioctl was used to set the eBPF program. > Added libbpf dependency and eBPF support.
> The eBPF program is part of the qemu and presented as an array > of BPF ELF file data.
> The compilation of eBPF is not part of QEMU build and can be done > using providedMakefile.ebpf(need to adjust 'linuxhdrs'). > Added changes to virtio-net and vhost, primary eBPF RSS is used. > 'in-qemu' RSS used in the case of hash population and as a fallback option.
> For vhost, the hash population feature is not reported to the guest. >
> Please also see the documentation in PATCH 5/5.
>
> I am sending those patches as RFC to initiate the discussions and get
> feedback on the following points:
> * Fallback when eBPF is not supported by the kernel
> * Live migration to the kernel that doesn't have eBPF support > * Integration with current QEMU build
> * Additional usage for eBPF for packet filtering
>
> Known issues:
> * hash population not supported by eBPF RSS: 'in-qemu' RSS used > as a fallback, also, hash population feature is not reported to guests
> with vhost.
> * big-endian BPF support: for now, eBPF isn't supported on > big-endian systems. Can be added in future if required. > * huge .h file with eBPF binary. The size of .h file containing > eBPF binary is currently ~5K lines, because the binary is built with debug information.
> The binary without debug/BTF info can't be loaded by libbpf. > We're looking for possibilities to reduce the size of the .h files.A question here, is this because the binary file contains DWARF data? If
yes, is it a building or loading dependency? If it's latter, maybe we can try to strip them out, anyhow it can't be recognized by kernel.Thanks
Quoted 8 lines
After some experiments we can see that stripping of debug sections reduces the size of
ELF from ~45K to ~20K (we tried to strip more but the libbpf fails to load it, libbpf needs BTF and symbols) So I suggest to reevaluate the necessity of libbpf.
For this specific BPF it does not present advantage and we hardly can create some reusable code related to libbpf, i.e. any further BPF will need its own libbpf wrapper.
The BTF is really good feature and in case some later BPF will need an access to kernel structures it will use libbpf loader.
What you think about it?
If we can find a way to use BTF without libbpf, it should be acceptable.
Thanks
Quoted 56 lines
Quoted 25 lines
Changes since v1:
* using libbpf instead of direct 'bpf' system call.
* added libbpf dependency to the configure/meson scripts.
* changed python script for eBPF .h file generation.
* changed eBPF program - reading L3 proto from ethernet frame.
* added TUNSETSTEERINGEBPF define for TUN.
* changed the maintainer's info.
* added license headers.
* refactored code.Andrew (5):
net: Added SetSteeringEBPF method for NetClientState.
ebpf: Added eBPF RSS program.
ebpf: Added eBPF RSS loader.
virtio-net: Added eBPF RSS to virtio-net.
docs: Added eBPF RSS documentation.MAINTAINERS | 7 +
configure | 33 +
docs/ebpf_rss.rst | 133 +
ebpf/EbpfElf_to_C.py | 36 +
ebpf/Makefile.ebpf | 33 +
ebpf/ebpf_rss-stub.c | 40 +Quoted 5 lines
ebpf/ebpf_rss.c | 186 ++ ebpf/ebpf_rss.h | 44 + ebpf/meson.build | 1 +ebpf/rss.bpf.c | 505 +++
ebpf/tun_rss_steering.h | 5439++++++++++++++++++++++++++++++++
> hw/net/vhost_net.c | 2 +
> hw/net/virtio-net.c | 120 +-
> include/hw/virtio/virtio-net.h | 4 +
> include/net/net.h | 2 +
> meson.build | 11 +
> net/tap-bsd.c | 5 +
> net/tap-linux.c | 13 +
> net/tap-linux.h | 1 +
> net/tap-solaris.c | 5 +
> net/tap-stub.c | 5 +
> net/tap.c | 9 +
> net/tap_int.h | 1 +
> net/vhost-vdpa.c | 2 +
> 24 files changed, 6633 insertions(+), 4 deletions(-) > create mode 100644docs/ebpf_rss.rst
> create mode 100644ebpf/EbpfElf_to_C.py
> create mode 100755 ebpf/Makefile.ebpf
> create mode 100644ebpf/ebpf_rss-stub.c
> create mode 100644ebpf/ebpf_rss.c
> create mode 100644ebpf/ebpf_rss.h
> create mode 100644 ebpf/meson.build
> create mode 100644ebpf/rss.bpf.c
> create mode 100644ebpf/tun_rss_steering.h>
Quoted 81 lines · Jason Wang
Quoted 8 lines · Yuri Benditovich
On Mon, Nov 23, 2020 at 8:08 AM Jason Wang <[email protected] <mailto:[email protected]>> wrote:
On 2020/11/19 下午7:13, Andrew Melnychenko wrote:
> This set of patches introduces the usage of eBPF for packetsteering
Quoted 2 lines
Quoted 2 lines
and RSS hash calculation:
* RSS(Receive Side Scaling) is used to distribute network packetsto
Quoted 9 lines
Quoted 9 lines
guest virtqueues by calculating packet hash
* Additionally adding support for the usage of RSS with vhostThe eBPF works on kernels 5.8+
On earlier kerneld it fails to load and the RSS feature is reported only without vhost and implemented in 'in-qemu' software.Implementation notes:
Linux TAP TUNSETSTEERINGEBPF ioctl was used to set the eBPFprogram.
Quoted 9 lines
Quoted 7 lines
Added libbpf dependency and eBPF support.
The eBPF program is part of the qemu and presented as an array of BPF ELF file data.
The compilation of eBPF is not part of QEMU build and can be done using providedMakefile.ebpf(need to adjust 'linuxhdrs'). Added changes to virtio-net and vhost, primary eBPF RSS is used. 'in-qemu' RSS used in the case of hash population and as afallback option.
> For vhost, the hash population feature is not reported to theguest.
Quoted 33 lines
Quoted 4 lines
Please also see the documentation in PATCH 5/5.
I am sending those patches as RFC to initiate the discussions
and get
> feedback on the following points:
> * Fallback when eBPF is not supported by the kernel
> * Live migration to the kernel that doesn't have eBPF support > * Integration with current QEMU build
> * Additional usage for eBPF for packet filtering
>
> Known issues:
> * hash population not supported by eBPF RSS: 'in-qemu' RSS used > as a fallback, also, hash population feature is not reported to guests
> with vhost.
> * big-endian BPF support: for now, eBPF isn't supported on > big-endian systems. Can be added in future if required. > * huge .h file with eBPF binary. The size of .h file containing > eBPF binary is currently ~5K lines, because the binary is built with debug information.
> The binary without debug/BTF info can't be loaded by libbpf. > We're looking for possibilities to reduce the size of the .h files.A question here, is this because the binary file contains DWARF data? If
yes, is it a building or loading dependency? If it's latter, maybe we can try to strip them out, anyhow it can't be recognized by kernel.Thanks
Quoted 12 lines
After some experiments we can see that stripping of debug sections reduces the size of
ELF from ~45K to ~20K (we tried to strip more but the libbpf fails to load it, libbpf needs BTF and symbols)
So I suggest to reevaluate the necessity of libbpf.
For this specific BPF it does not present advantage and we hardly can create some reusable code
related to libbpf, i.e. any further BPF will need its own libbpf wrapper. The BTF is really good feature and in case some later BPF will need an access to kernel
structures it will use libbpf loader.
What you think about it?
Quoted 3 lines
If we can find a way to use BTF without libbpf, it should be acceptable.
But the point is that the RSS BPF does not need the BTF as it does not use
any kernel structures.
When we have, for example, filter BPF that will need the BTF - we'll use libbpf for it.
Anyway we do not have here any infrastructural code related to libbpf,
Quoted 61 lines
Thanks
Quoted 56 lines
Quoted 19 lines
Changes since v1:
* using libbpf instead of direct 'bpf' system call.
* added libbpf dependency to the configure/meson scripts.
* changed python script for eBPF .h file generation.
* changed eBPF program - reading L3 proto from ethernet frame.
* added TUNSETSTEERINGEBPF define for TUN.
* changed the maintainer's info.
* added license headers.
* refactored code.Andrew (5):
net: Added SetSteeringEBPF method for NetClientState.
ebpf: Added eBPF RSS program.
ebpf: Added eBPF RSS loader.
virtio-net: Added eBPF RSS to virtio-net.
docs: Added eBPF RSS documentation.Quoted 11 lines
MAINTAINERS | 7 + configure | 33 + docs/ebpf_rss.rst | 133 + ebpf/EbpfElf_to_C.py | 36 + ebpf/Makefile.ebpf | 33 + ebpf/ebpf_rss-stub.c | 40 + ebpf/ebpf_rss.c | 186 ++ ebpf/ebpf_rss.h | 44 + ebpf/meson.build | 1 + ebpf/rss.bpf.c | 505 +++ ebpf/tun_rss_steering.h | 5439++++++++++++++++++++++++++++++++
>hw/net/vhost_net.c| 2 +
>hw/net/virtio-net.c| 120 +-
>include/hw/virtio/virtio-net.h| 4 +
>include/net/net.h| 2 +
> meson.build | 11 +
>net/tap-bsd.c| 5 +
>net/tap-linux.c| 13 +
>net/tap-linux.h| 1 +
>net/tap-solaris.c| 5 +
>net/tap-stub.c| 5 +
>net/tap.c| 9 +
>net/tap_int.h| 1 +
>net/vhost-vdpa.c| 2 +
> 24 files changed, 6633 insertions(+), 4 deletions(-)
> create mode 100644docs/ebpf_rss.rst
> create mode 100644ebpf/EbpfElf_to_C.py
> create mode 100755 ebpf/Makefile.ebpf
> create mode 100644ebpf/ebpf_rss-stub.c
> create mode 100644ebpf/ebpf_rss.c
> create mode 100644ebpf/ebpf_rss.h
> create mode 100644 ebpf/meson.build
> create mode 100644ebpf/rss.bpf.c
> create mode 100644ebpf/tun_rss_steering.h
>
Quoted 20 lines · Yuri Benditovich
Quoted 5 lines
After some experiments we can see that stripping of debug sections reduces the size of
ELF from ~45K to ~20K (we tried to strip more but the libbpffails to
> load it, libbpf needs BTF and symbols)
> So I suggest to reevaluate the necessity of libbpf.
> For this specific BPF it does not present advantage and we hardly can
> create some reusable code
> related to libbpf, i.e. any further BPF will need its own libbpf wrapper.
> The BTF is really good feature and in case some later BPF will need an
> access to kernel
> structures it will use libbpf loader.
> What you think about it?
Quoted 4 lines
If we can find a way to use BTF without libbpf, it should be acceptable.
But the point is that the RSS BPF does not need the BTF as it does not use any kernel structures.
Kinds of, it tries to access skb. But yes, it doesn't access any metadata of skb.
Quoted 2 lines
When we have, for example, filter BPF that will need the BTF - we'll use libbpf for it. Anyway we do not have here any infrastructural code related to libbpf,
Right, so I think we can probably start from a non BTF version without libbpf. And adding other features on top.
Thanks
Quoted 30 lines · Andrew Melnychenko
This set of patches introduces the usage of eBPF for packet steering and RSS hash calculation:
* RSS(Receive Side Scaling) is used to distribute network packets to guest virtqueues by calculating packet hash
* Additionally adding support for the usage of RSS with vhostThe eBPF works on kernels 5.8+
On earlier kerneld it fails to load and the RSS feature is reported only without vhost and implemented in 'in-qemu' software.Implementation notes:
Linux TAP TUNSETSTEERINGEBPF ioctl was used to set the eBPF program. Added libbpf dependency and eBPF support.
The eBPF program is part of the qemu and presented as an array of BPF ELF file data.
The compilation of eBPF is not part of QEMU build and can be done using providedMakefile.ebpf(need to adjust 'linuxhdrs').
Added changes to virtio-net and vhost, primary eBPF RSS is used. 'in-qemu' RSS used in the case of hash population and as a fallback option. For vhost, the hash population feature is not reported to the guest.Please also see the documentation in PATCH 5/5.
I am sending those patches as RFC to initiate the discussions and get feedback on the following points:
* Fallback when eBPF is not supported by the kernel
* Live migration to the kernel that doesn't have eBPF support
* Integration with current QEMU build
* Additional usage for eBPF for packet filtering
Quoted 10 lines
Known issues:
* hash population not supported by eBPF RSS: 'in-qemu' RSS used
as a fallback, also, hash population feature is not reported to guests with vhost.
* big-endian BPF support: for now, eBPF isn't supported on
big-endian systems. Can be added in future if required.
* huge .h file with eBPF binary. The size of .h file containing
eBPF binary is currently ~5K lines, because the binary is built with debug information. The binary without debug/BTF info can't be loaded by libbpf.
We're looking for possibilities to reduce the size of the .h files.
Adding Toke for sharing more idea from eBPF side.
We had some discussion on the eBPF issues:
1) Whether or not to use libbpf. Toke strongly suggest to use libbpf
2) Whether or not to use BTF. Toke confirmed that if we don't access any skb metadata, BTF is not strictly required for CO-RE. But it might still useful for e.g debugging.
3) About the huge (5K lines, see patch #2 Toke). Toke confirmed that we can strip debug symbols, but Yuri found some sections can't be stripped, we can keep discussing here.
Toke, feel free to correct me if I was wrong.
Thanks
Quoted 53 lines
Changes since v1:
* using libbpf instead of direct 'bpf' system call.
* added libbpf dependency to the configure/meson scripts.
* changed python script for eBPF .h file generation.
* changed eBPF program - reading L3 proto from ethernet frame.
* added TUNSETSTEERINGEBPF define for TUN.
* changed the maintainer's info.
* added license headers.
* refactored code.Andrew (5):
net: Added SetSteeringEBPF method for NetClientState.
ebpf: Added eBPF RSS program.
ebpf: Added eBPF RSS loader.
virtio-net: Added eBPF RSS to virtio-net.
docs: Added eBPF RSS documentation.MAINTAINERS | 7 + configure | 33 + docs/ebpf_rss.rst | 133 + ebpf/EbpfElf_to_C.py | 36 + ebpf/Makefile.ebpf | 33 + ebpf/ebpf_rss-stub.c | 40 + ebpf/ebpf_rss.c | 186 ++ ebpf/ebpf_rss.h | 44 + ebpf/meson.build | 1 + ebpf/rss.bpf.c | 505 +++ ebpf/tun_rss_steering.h | 5439 ++++++++++++++++++++++++++++++++ hw/net/vhost_net.c | 2 + hw/net/virtio-net.c | 120 +- include/hw/virtio/virtio-net.h | 4 + include/net/net.h | 2 + meson.build | 11 + net/tap-bsd.c | 5 + net/tap-linux.c | 13 + net/tap-linux.h | 1 + net/tap-solaris.c | 5 + net/tap-stub.c | 5 + net/tap.c | 9 + net/tap_int.h | 1 + net/vhost-vdpa.c | 2 + 24 files changed, 6633 insertions(+), 4 deletions(-)create mode 100644
docs/ebpf_rss.rst
create mode 100644ebpf/EbpfElf_to_C.py
create mode 100755 ebpf/Makefile.ebpf
create mode 100644ebpf/ebpf_rss-stub.c
create mode 100644ebpf/ebpf_rss.c
create mode 100644ebpf/ebpf_rss.h
create mode 100644 ebpf/meson.build
create mode 100644ebpf/rss.bpf.c
create mode 100644ebpf/tun_rss_steering.h
Quoted 47 lines · Jason Wang
Quoted 30 lines · Andrew Melnychenko
This set of patches introduces the usage of eBPF for packet steering and RSS hash calculation:
* RSS(Receive Side Scaling) is used to distribute network packets to guest virtqueues by calculating packet hash
* Additionally adding support for the usage of RSS with vhostThe eBPF works on kernels 5.8+
On earlier kerneld it fails to load and the RSS feature is reported only without vhost and implemented in 'in-qemu' software.Implementation notes:
Linux TAP TUNSETSTEERINGEBPF ioctl was used to set the eBPF program. Added libbpf dependency and eBPF support.
The eBPF program is part of the qemu and presented as an array of BPF ELF file data.
The compilation of eBPF is not part of QEMU build and can be done using providedMakefile.ebpf(need to adjust 'linuxhdrs').
Added changes to virtio-net and vhost, primary eBPF RSS is used. 'in-qemu' RSS used in the case of hash population and as a fallback option. For vhost, the hash population feature is not reported to the guest.Please also see the documentation in PATCH 5/5.
I am sending those patches as RFC to initiate the discussions and get feedback on the following points:
* Fallback when eBPF is not supported by the kernel
* Live migration to the kernel that doesn't have eBPF support
* Integration with current QEMU build
* Additional usage for eBPF for packet filteringQuoted 10 lines
Known issues:
* hash population not supported by eBPF RSS: 'in-qemu' RSS used
as a fallback, also, hash population feature is not reported to guests with vhost.
* big-endian BPF support: for now, eBPF isn't supported on
big-endian systems. Can be added in future if required.
* huge .h file with eBPF binary. The size of .h file containing
eBPF binary is currently ~5K lines, because the binary is built with debug information. The binary without debug/BTF info can't be loaded by libbpf.
We're looking for possibilities to reduce the size of the .h files.Adding Toke for sharing more idea from eBPF side.
We had some discussion on the eBPF issues:
Quoted 7 lines
1) Whether or not to use libbpf. Toke strongly suggest to use libbpf
2) Whether or not to use BTF. Toke confirmed that if we don't access any skb metadata, BTF is not strictly required for CO-RE. But it might still useful for e.g debugging.
3) About the huge (5K lines, see patch #2 Toke). Toke confirmed that we can strip debug symbols, but Yuri found some sections can't be stripped, we can keep discussing here.
I just tried simply running 'strip' on a sample trivial XDP program, which brought its size down from ~5k to ~1k and preserved the BTF information without me having to do anything.
As a side note, though, instead of embedding the BPF program into a .h, you could simply ship it as a .o and load it from the file system. We do that with xdp-tools and install the bpf object files into /usr/$LIB/bpf/.
-Toke
Quoted 59 lines · Toke Høiland-Jørgensen
Quoted 11 lines · Jason Wang
Quoted 10 lines · Andrew Melnychenko
This set of patches introduces the usage of eBPF for packet steering and RSS hash calculation:
* RSS(Receive Side Scaling) is used to distribute network packets to guest virtqueues by calculating packet hash
* Additionally adding support for the usage of RSS with vhostThe eBPF works on kernels 5.8+
On earlier kerneld it fails to load and the RSS feature is reported only without vhost and implemented in 'in-qemu' software.Quoted 9 lines
Quoted 9 lines
Implementation notes:
Linux TAP TUNSETSTEERINGEBPF ioctl was used to set the eBPF program. Added libbpf dependency and eBPF support.
The eBPF program is part of the qemu and presented as an array of BPF ELF file data.
The compilation of eBPF is not part of QEMU build and can be done using providedMakefile.ebpf(need to adjust 'linuxhdrs'). Added changes to virtio-net and vhost, primary eBPF RSS is used. 'in-qemu' RSS used in the case of hash population and as a fallbackoption.
Quoted 11 lines
Quoted 11 lines
For vhost, the hash population feature is not reported to the guest.
Please also see the documentation in PATCH 5/5.
I am sending those patches as RFC to initiate the discussions and get feedback on the following points:
* Fallback when eBPF is not supported by the kernel
* Live migration to the kernel that doesn't have eBPF support
* Integration with current QEMU build
* Additional usage for eBPF for packet filteringQuoted 8 lines
Quoted 8 lines
Known issues:
* hash population not supported by eBPF RSS: 'in-qemu' RSS used as a fallback, also, hash population feature is not reported to guests with vhost.
* big-endian BPF support: for now, eBPF isn't supported on big-endian systems. Can be added in future if required.
* huge .h file with eBPF binary. The size of .h file containing eBPF binary is currently ~5K lines, because the binary is built withdebug information.
Quoted 8 lines
Quoted 2 lines
The binary without debug/BTF info can't be loaded by libbpf. We're looking for possibilities to reduce the size of the .h files.
Adding Toke for sharing more idea from eBPF side.
We had some discussion on the eBPF issues:
Quoted 7 lines
1) Whether or not to use libbpf. Toke strongly suggest to use libbpf
2) Whether or not to use BTF. Toke confirmed that if we don't access any skb metadata, BTF is not strictly required for CO-RE. But it might still useful for e.g debugging.
3) About the huge (5K lines, see patch #2 Toke). Toke confirmed that we can strip debug symbols, but Yuri found some sections can't be stripped, we can keep discussing here.
Quoted 4 lines
I just tried simply running 'strip' on a sample trivial XDP program, which brought its size down from ~5k to ~1k and preserved the BTF information without me having to do anything.
With our eBPF code the numbers are slightly different:
The code size without BTF: 7.5K (built without '-g')
Built with '-g': 45K
Stripped: 19K
The difference between 7.5 and 19K still seems significant, especially when we do not use any kernel structures and do not need these BTF sections This is only reason to prefer non-libbpf option for this specific eBPF
Quoted 5 lines
As a side note, though, instead of embedding the BPF program into a .h, you could simply ship it as a .o and load it from the file system. We do that with xdp-tools and install the bpf object files into
/usr/$LIB/bpf/.
Yes, we've discussed this option and decided to go with embedding the BPF
https://lists.gnu.org/archive/html/qemu-devel/2020-11/msg02157.html
Quoted 3 lines
-Toke
Quoted 67 lines · Yuri Benditovich
Quoted 59 lines · Toke Høiland-Jørgensen
Quoted 11 lines · Jason Wang
Quoted 10 lines · Andrew Melnychenko
This set of patches introduces the usage of eBPF for packet steering and RSS hash calculation:
* RSS(Receive Side Scaling) is used to distribute network packets to guest virtqueues by calculating packet hash
* Additionally adding support for the usage of RSS with vhostThe eBPF works on kernels 5.8+
On earlier kerneld it fails to load and the RSS feature is reported only without vhost and implemented in 'in-qemu' software.Quoted 9 lines
Quoted 9 lines
Implementation notes:
Linux TAP TUNSETSTEERINGEBPF ioctl was used to set the eBPF program. Added libbpf dependency and eBPF support.
The eBPF program is part of the qemu and presented as an array of BPF ELF file data.
The compilation of eBPF is not part of QEMU build and can be done using providedMakefile.ebpf(need to adjust 'linuxhdrs'). Added changes to virtio-net and vhost, primary eBPF RSS is used. 'in-qemu' RSS used in the case of hash population and as a fallbackoption.
Quoted 11 lines
Quoted 11 lines
For vhost, the hash population feature is not reported to the guest.
Please also see the documentation in PATCH 5/5.
I am sending those patches as RFC to initiate the discussions and get feedback on the following points:
* Fallback when eBPF is not supported by the kernel
* Live migration to the kernel that doesn't have eBPF support
* Integration with current QEMU build
* Additional usage for eBPF for packet filteringQuoted 8 lines
Quoted 8 lines
Known issues:
* hash population not supported by eBPF RSS: 'in-qemu' RSS used as a fallback, also, hash population feature is not reported to guests with vhost.
* big-endian BPF support: for now, eBPF isn't supported on big-endian systems. Can be added in future if required.
* huge .h file with eBPF binary. The size of .h file containing eBPF binary is currently ~5K lines, because the binary is built withdebug information.
Quoted 8 lines
Quoted 2 lines
The binary without debug/BTF info can't be loaded by libbpf. We're looking for possibilities to reduce the size of the .h files.
Adding Toke for sharing more idea from eBPF side.
We had some discussion on the eBPF issues:
Quoted 7 lines
1) Whether or not to use libbpf. Toke strongly suggest to use libbpf
2) Whether or not to use BTF. Toke confirmed that if we don't access any skb metadata, BTF is not strictly required for CO-RE. But it might still useful for e.g debugging.
3) About the huge (5K lines, see patch #2 Toke). Toke confirmed that we can strip debug symbols, but Yuri found some sections can't be stripped, we can keep discussing here.Quoted 4 lines
I just tried simply running 'strip' on a sample trivial XDP program, which brought its size down from ~5k to ~1k and preserved the BTF information without me having to do anything.
Quoted 6 lines
With our eBPF code the numbers are slightly different:
The code size without BTF: 7.5K (built without '-g')
Built with '-g': 45K
Stripped: 19K
The difference between 7.5 and 19K still seems significant, especially when we do not use any kernel structures and do not need these BTF sections
That does seem like a lot of BTF information. Did you confirm (with objdump) that it's the .BTF* sections that take up these extra 12k? Do you have some really complicated data structures in the file or something? Got a link to the source somewhere that isn't a web mailing list archive? :)
In any case, while I do think it smells a little of premature optimisation, you can of course strip the BTF information until you need it. Having it around makes debugging easier (bpftool will expand your map structures for you when dumping maps, and that sort of thing), but it's not really essential if you don't need CO-RE.
Quoted 1 line
This is only reason to prefer non-libbpf option for this specific eBPF
You can still use libbpf without BTF. It's using BTF without libbpf that tends to not work so well...
Quoted 7 lines
Quoted 4 lines
As a side note, though, instead of embedding the BPF program into a .h, you could simply ship it as a .o and load it from the file system. We do that with xdp-tools and install the bpf object files into
/usr/$LIB/bpf/.Yes, we've discussed this option and decided to go with embedding the BPF
https://lists.gnu.org/archive/html/qemu-devel/2020-11/msg02157.html
Right, okay. I'll note, though, that if your concern is that the BPF code should always match the rest of the code base, omitting the compilation if there's no Clang present seems like it could lead to problems :)
Also, if you do go the embedded-bytecode route, you may want to have a look at the upstream 'skeleton' concept. It takes a BPF object file and automatically generates a header file that gives you direct access to maps, programs and global data in C. There are some examples in selftests/bpf on how to use it, but you basically just run 'bpftool gen skeleton mybpf.o'.
-Toke
Quoted 79 lines · Toke Høiland-Jørgensen
Quoted 37 lines · Yuri Benditovich
Quoted 34 lines · Toke Høiland-Jørgensen
Quoted 11 lines · Jason Wang
Quoted 10 lines · Andrew Melnychenko
This set of patches introduces the usage of eBPF for packet steering and RSS hash calculation:
* RSS(Receive Side Scaling) is used to distribute network packets to guest virtqueues by calculating packet hash
* Additionally adding support for the usage of RSS with vhostThe eBPF works on kernels 5.8+
On earlier kerneld it fails to load and the RSS feature is reported only without vhost and implemented in 'in-qemu' software.Quoted 9 lines
Quoted 9 lines
Implementation notes:
Linux TAP TUNSETSTEERINGEBPF ioctl was used to set the eBPF program. Added libbpf dependency and eBPF support.
The eBPF program is part of the qemu and presented as an array of BPF ELF file data.
The compilation of eBPF is not part of QEMU build and can be done using providedMakefile.ebpf(need to adjust 'linuxhdrs'). Added changes to virtio-net and vhost, primary eBPF RSS is used. 'in-qemu' RSS used in the case of hash population and as a fallbackoption.
Quoted 11 lines
Quoted 11 lines
For vhost, the hash population feature is not reported to the guest.
Please also see the documentation in PATCH 5/5.
I am sending those patches as RFC to initiate the discussions and get feedback on the following points:
* Fallback when eBPF is not supported by the kernel
* Live migration to the kernel that doesn't have eBPF support
* Integration with current QEMU build
* Additional usage for eBPF for packet filteringQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Known issues:
* hash population not supported by eBPF RSS: 'in-qemu' RSS used as a fallback, also, hash population feature is not reported toguests
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines
with vhost.
* big-endian BPF support: for now, eBPF isn't supported on big-endian systems. Can be added in future if required.
* huge .h file with eBPF binary. The size of .h file containing eBPF binary is currently ~5K lines, because the binary is built withdebug information.
Quoted 4 lines
Quoted 2 lines
The binary without debug/BTF info can't be loaded by libbpf. We're looking for possibilities to reduce the size of the .h files.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Adding Toke for sharing more idea from eBPF side.
We had some discussion on the eBPF issues:
1) Whether or not to use libbpf. Toke strongly suggest to use libbpf
2) Whether or not to use BTF. Toke confirmed that if we don't accessany
Quoted 1 line
Quoted 1 line
Quoted 1 line
skb metadata, BTF is not strictly required for CO-RE. But it might
still
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
useful for e.g debugging.
3) About the huge (5K lines, see patch #2 Toke). Toke confirmed thatwe
Quoted 1 line
Quoted 1 line
Quoted 1 line
can strip debug symbols, but Yuri found some sections can't be
stripped,
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
we can keep discussing here.
I just tried simply running 'strip' on a sample trivial XDP program, which brought its size down from ~5k to ~1k and preserved the BTF information without me having to do anything.
Quoted 5 lines
With our eBPF code the numbers are slightly different:
The code size without BTF: 7.5K (built without '-g')
Built with '-g': 45K
Stripped: 19K
The difference between 7.5 and 19K still seems significant, especially
Quoted 10 lines
when
Quoted 1 line
we do not use any kernel structures and do not need these BTF sections
That does seem like a lot of BTF information. Did you confirm (with objdump) that it's the .BTF* sections that take up these extra 12k? Do you have some really complicated data structures in the file or something? Got a link to the source somewhere that isn't a web mailing list archive? :)
Looks like the extra size is related to BTF: there are 4 BTF sections that take 12.5K
[ 7] .BTF PROGBITS 0000000000000000 00144c 00175d 00
0 0 1
[ 8] .rel.BTF REL 0000000000000000 002bb0 000040 10
14 7 8
[ 9] .BTF.ext PROGBITS 0000000000000000 002bf0 000cd0 00
0 0 1
[10] .rel.BTF.ext REL 0000000000000000 0038c0 000ca0 10
14 9 8All the sources are at:
The branch without libbpf
https://github.com/daynix/qemu/tree/eBPF_RFC
The branch with libbpf
https://github.com/daynix/qemu/tree/eBPF_RFCv2
all the eBPF-related code is under qemu/ebpf directory.
Quoted 6 lines
In any case, while I do think it smells a little of premature optimisation, you can of course strip the BTF information until you need it. Having it around makes debugging easier (bpftool will expand your map structures for you when dumping maps, and that sort of thing), but it's not really essential if you don't need CO-RE.
Quoted 6 lines
Quoted 1 line
This is only reason to prefer non-libbpf option for this specific eBPF
You can still use libbpf without BTF. It's using BTF without libbpf that tends to not work so well...
If we build the eBPF without '-g' or strip the BTF information out of the object file the libbpf crashes right after issuing printout "libbpf: BTF is required, but is missing or corrupted".
We did not investigate this too deeply but on the first glance it looks like the presence of maps automatically makes the libbpf to require BTF.
Quoted 14 lines
Quoted 3 lines
Quoted 3 lines
As a side note, though, instead of embedding the BPF program into a .h, you could simply ship it as a .o and load it from the file system. We do that with xdp-tools and install the bpf object files into
/usr/$LIB/bpf/.Quoted 4 lines
Quoted 1 line
Yes, we've discussed this option and decided to go with embedding the BPF
https://lists.gnu.org/archive/html/qemu-devel/2020-11/msg02157.htmlRight, okay. I'll note, though, that if your concern is that the BPF code should always match the rest of the code base, omitting the compilation if there's no Clang present seems like it could lead to problems :)
Quoted 8 lines
Also, if you do go the embedded-bytecode route, you may want to have a look at the upstream 'skeleton' concept. It takes a BPF object file and automatically generates a header file that gives you direct access to maps, programs and global data in C. There are some examples in selftests/bpf on how to use it, but you basically just run 'bpftool gen skeleton mybpf.o'.
Indeed looks very interesting. We've missed this feature. Thank you very much!
Quoted 3 lines
-Toke
Quoted 95 lines · Yuri Benditovich
Quoted 79 lines · Toke Høiland-Jørgensen
Quoted 37 lines · Yuri Benditovich
Quoted 34 lines · Toke Høiland-Jørgensen
Quoted 11 lines · Jason Wang
Quoted 10 lines · Andrew Melnychenko
This set of patches introduces the usage of eBPF for packet steering and RSS hash calculation:
* RSS(Receive Side Scaling) is used to distribute network packets to guest virtqueues by calculating packet hash
* Additionally adding support for the usage of RSS with vhostThe eBPF works on kernels 5.8+
On earlier kerneld it fails to load and the RSS feature is reported only without vhost and implemented in 'in-qemu' software.Quoted 9 lines
Quoted 9 lines
Implementation notes:
Linux TAP TUNSETSTEERINGEBPF ioctl was used to set the eBPF program. Added libbpf dependency and eBPF support.
The eBPF program is part of the qemu and presented as an array of BPF ELF file data.
The compilation of eBPF is not part of QEMU build and can be done using providedMakefile.ebpf(need to adjust 'linuxhdrs'). Added changes to virtio-net and vhost, primary eBPF RSS is used. 'in-qemu' RSS used in the case of hash population and as a fallbackoption.
Quoted 11 lines
Quoted 11 lines
For vhost, the hash population feature is not reported to the guest.
Please also see the documentation in PATCH 5/5.
I am sending those patches as RFC to initiate the discussions and get feedback on the following points:
* Fallback when eBPF is not supported by the kernel
* Live migration to the kernel that doesn't have eBPF support
* Integration with current QEMU build
* Additional usage for eBPF for packet filteringQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Known issues:
* hash population not supported by eBPF RSS: 'in-qemu' RSS used as a fallback, also, hash population feature is not reported toguests
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Quoted 5 lines
with vhost.
* big-endian BPF support: for now, eBPF isn't supported on big-endian systems. Can be added in future if required.
* huge .h file with eBPF binary. The size of .h file containing eBPF binary is currently ~5K lines, because the binary is built withdebug information.
Quoted 4 lines
Quoted 2 lines
The binary without debug/BTF info can't be loaded by libbpf. We're looking for possibilities to reduce the size of the .h files.
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Adding Toke for sharing more idea from eBPF side.
We had some discussion on the eBPF issues:
1) Whether or not to use libbpf. Toke strongly suggest to use libbpf
2) Whether or not to use BTF. Toke confirmed that if we don't accessany
Quoted 1 line
Quoted 1 line
Quoted 1 line
skb metadata, BTF is not strictly required for CO-RE. But it might
still
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
useful for e.g debugging.
3) About the huge (5K lines, see patch #2 Toke). Toke confirmed thatwe
Quoted 1 line
Quoted 1 line
Quoted 1 line
can strip debug symbols, but Yuri found some sections can't be
stripped,
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
we can keep discussing here.
I just tried simply running 'strip' on a sample trivial XDP program, which brought its size down from ~5k to ~1k and preserved the BTF information without me having to do anything.
Quoted 5 lines
With our eBPF code the numbers are slightly different:
The code size without BTF: 7.5K (built without '-g')
Built with '-g': 45K
Stripped: 19K
The difference between 7.5 and 19K still seems significant, especiallyQuoted 10 lines
when
Quoted 1 line
we do not use any kernel structures and do not need these BTF sections
That does seem like a lot of BTF information. Did you confirm (with objdump) that it's the .BTF* sections that take up these extra 12k? Do you have some really complicated data structures in the file or something? Got a link to the source somewhere that isn't a web mailing list archive? :)
Looks like the extra size is related to BTF: there are 4 BTF sections that take 12.5K
[ 7] .BTF PROGBITS 0000000000000000 00144c 00175d 00
Quoted 7 lines
0 0 1
[ 8] .rel.BTF REL 0000000000000000 002bb0 000040 10
14 7 8
[ 9] .BTF.ext PROGBITS 0000000000000000 002bf0 000cd0 00
0 0 1
[10] .rel.BTF.ext REL 0000000000000000 0038c0 000ca0 10
14 9 8Right, okay, that does not look completely outrageous with the amount of code and type information you have in that file.
Quoted 7 lines
All the sources are at:
The branch without libbpf
https://github.com/daynix/qemu/tree/eBPF_RFC
The branch with libbpf
https://github.com/daynix/qemu/tree/eBPF_RFCv2all the eBPF-related code is under qemu/ebpf directory.
Ah, cool, thanks!
Quoted 12 lines
Quoted 6 lines
In any case, while I do think it smells a little of premature optimisation, you can of course strip the BTF information until you need it. Having it around makes debugging easier (bpftool will expand your map structures for you when dumping maps, and that sort of thing), but it's not really essential if you don't need CO-RE.
Quoted 6 lines
Quoted 1 line
This is only reason to prefer non-libbpf option for this specific eBPF
You can still use libbpf without BTF. It's using BTF without libbpf that tends to not work so well...
Quoted 5 lines
If we build the eBPF without '-g' or strip the BTF information out of the object file the libbpf crashes right after issuing printout "libbpf: BTF is required, but is missing or corrupted".
We did not investigate this too deeply but on the first glance it looks like the presence of maps automatically makes the libbpf to require BTF.
Ah, right. Well, you're using the BTF-based map definition syntax. So yeah, that does require BTF: The __uint() and __type() macros really expand to type definitions that are specifically crafted to be embedded as BTF in the file.
You could use the old-style map definitions that don't use BTF[0], but BTF is really where things are going in BPF-land so I think longer term you'll probably end up needing it anyway. So going to this much trouble just to save 10k on binary size seems to me like it's a decision you'll end up regretting :)
[0] https://github.com/xdp-project/xdp-tutorial/blob/master/basic03-map-counter/xdp_prog_kern.c#L11
-Toke
Quoted 151 lines · Toke Høiland-Jørgensen
Quoted 6 lines · Yuri Benditovich
Quoted 3 lines · Toke Høiland-Jørgensen
Quoted 1 line · Yuri Benditovich
On Wed, Dec 2, 2020 at 4:18 PM Toke Høiland-Jørgensen <
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines · wrote:
Quoted 2 lines · Jason Wang
Quoted 1 line · Andrew Melnychenko
This set of patches introduces the usage of eBPF for packet
steering
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
and RSS hash calculation:
* RSS(Receive Side Scaling) is used to distribute network packetsto
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
guest virtqueues by calculating packet hash
* Additionally adding support for the usage of RSS with vhostThe eBPF works on kernels 5.8+
On earlier kerneld it fails to load and the RSS feature isreported
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
only without vhost and implemented in 'in-qemu' software.
Implementation notes:
Linux TAP TUNSETSTEERINGEBPF ioctl was used to set the eBPFprogram.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Added libbpf dependency and eBPF support.
The eBPF program is part of the qemu and presented as an array of BPF ELF file data.
The compilation of eBPF is not part of QEMU build and can be done using providedMakefile.ebpf(need to adjust 'linuxhdrs'). Added changes to virtio-net and vhost, primary eBPF RSS is used. 'in-qemu' RSS used in the case of hash population and as afallback
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
option.
Quoted 1 line
Quoted 1 line
For vhost, the hash population feature is not reported to the
guest.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Please also see the documentation in PATCH 5/5.
I am sending those patches as RFC to initiate the discussions and
get
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
feedback on the following points:
* Fallback when eBPF is not supported by the kernel
* Live migration to the kernel that doesn't have eBPF support
* Integration with current QEMU build
* Additional usage for eBPF for packet filteringKnown issues:
* hash population not supported by eBPF RSS: 'in-qemu' RSS used as a fallback, also, hash population feature is not reported toQuoted 6 lines
Quoted 6 lines
guests
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
with vhost.
* big-endian BPF support: for now, eBPF isn't supported on big-endian systems. Can be added in future if required.
* huge .h file with eBPF binary. The size of .h file containing eBPF binary is currently ~5K lines, because the binary is builtwith
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
debug information.
Quoted 2 lines
Quoted 2 lines
The binary without debug/BTF info can't be loaded by libbpf. We're looking for possibilities to reduce the size of the .h
files.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Adding Toke for sharing more idea from eBPF side.
We had some discussion on the eBPF issues:
1) Whether or not to use libbpf. Toke strongly suggest to use
libbpf
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
2) Whether or not to use BTF. Toke confirmed that if we don't
access
Quoted 5 lines
Quoted 5 lines
any
Quoted 1 line
Quoted 1 line
Quoted 1 line
skb metadata, BTF is not strictly required for CO-RE. But it might
still
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
useful for e.g debugging.
3) About the huge (5K lines, see patch #2 Toke). Toke confirmedthat
Quoted 18 lines
Quoted 18 lines
we
Quoted 1 line
Quoted 1 line
Quoted 1 line
can strip debug symbols, but Yuri found some sections can't be
stripped,
Quoted 7 lines
Quoted 6 lines
Quoted 1 line
we can keep discussing here.
I just tried simply running 'strip' on a sample trivial XDP program, which brought its size down from ~5k to ~1k and preserved the BTF information without me having to do anything.
Quoted 5 lines
With our eBPF code the numbers are slightly different:
The code size without BTF: 7.5K (built without '-g')
Built with '-g': 45K
Stripped: 19K
The difference between 7.5 and 19K still seems significant, especiallywhen
Quoted 1 line
we do not use any kernel structures and do not need these BTF sections
Quoted 8 lines
Quoted 7 lines
That does seem like a lot of BTF information. Did you confirm (with objdump) that it's the .BTF* sections that take up these extra 12k? Do you have some really complicated data structures in the file or something? Got a link to the source somewhere that isn't a web mailing list archive? :)
Looks like the extra size is related to BTF: there are 4 BTF sections
that
Quoted 2 lines
take 12.5K
[ 7] .BTF PROGBITS 0000000000000000 00144c 00175d00
Quoted 2 lines
0 0 1[ 8] .rel.BTF REL 0000000000000000 002bb0 000040
10
Quoted 2 lines
14 7 8[ 9] .BTF.ext PROGBITS 0000000000000000 002bf0 000cd0
00
Quoted 2 lines
0 0 1[10] .rel.BTF.ext REL 0000000000000000 0038c0 000ca0
10
Quoted 1 line
14 9 8Right, okay, that does not look completely outrageous with the amount of code and type information you have in that file.
Quoted 7 lines
All the sources are at:
The branch without libbpf
https://github.com/daynix/qemu/tree/eBPF_RFC
The branch with libbpf
https://github.com/daynix/qemu/tree/eBPF_RFCv2all the eBPF-related code is under qemu/ebpf directory.
Ah, cool, thanks!
Quoted 6 lines
Quoted 6 lines
In any case, while I do think it smells a little of premature optimisation, you can of course strip the BTF information until you need it. Having it around makes debugging easier (bpftool will expand your map structures for you when dumping maps, and that sort of thing), but it's not really essential if you don't need CO-RE.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
This is only reason to prefer non-libbpf option for this specific eBPF
You can still use libbpf without BTF. It's using BTF without libbpf that tends to not work so well...
If we build the eBPF without '-g' or strip the BTF information out of the object file the libbpf crashes right after issuing printout "libbpf: BTF
is
Quoted 9 lines
Quoted 3 lines
required, but is missing or corrupted".
We did not investigate this too deeply but on the first glance it looks like the presence of maps automatically makes the libbpf to require BTF.Ah, right. Well, you're using the BTF-based map definition syntax. So yeah, that does require BTF: The
__uint()and__type()macros really expand to type definitions that are specifically crafted to be embedded as BTF in the file.
Yes, now the EBPF built without '-g' also can be loaded via libbpf and we can enable/disable BTF as we need.
Again, thank you very much!
Quoted 13 lines
You could use the old-style map definitions that don't use BTF[0], but BTF is really where things are going in BPF-land so I think longer term you'll probably end up needing it anyway. So going to this much trouble just to save 10k on binary size seems to me like it's a decision you'll end up regretting :)
[0]
https://github.com/xdp-project/xdp-tutorial/blob/master/basic03-map-counter/xdp_prog_kern.c#L11-Toke