eBPF RSS support for virtio-net
Subsystems (2)
v3 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 eBPF array file initially generated by bpftool. 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 6/6.
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.
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.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.
Changes since v2:
* using bpftool for eBPF skeleton generation.
* ebpf_rss is refactored to use skeleton generated by bpftool.
* added/adjasted license in comment sections and in eBPF file.
* rss.bpf.c and Makefile.ebpf moved to the tool/ebpf folder.
* virtio-net eBPF rss refactored. Now eBPF initialized during realize().
Andrew (6):
net/tap: Added TUNSETSTEERINGEBPF code.
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 documentation.
MAINTAINERS | 8 + configure | 33 +++ docs/ebpf_rss.rst | 125 ++++++++ ebpf/ebpf_rss-stub.c | 40 +++ ebpf/ebpf_rss.c | 165 +++++++++++ ebpf/ebpf_rss.h | 44 +++ ebpf/meson.build | 1 + ebpf/rss.bpf.skeleton.h | 397 ++++++++++++++++++++++++++ ebpf/trace-events | 4 + ebpf/trace.h | 2 + hw/net/vhost_net.c | 2 + hw/net/virtio-net.c | 125 +++++++- include/hw/virtio/virtio-net.h | 4 + include/net/net.h | 2 + meson.build | 13 + 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 + tools/ebpf/Makefile.ebpf | 33 +++ tools/ebpf/rss.bpf.c | 505 +++++++++++++++++++++++++++++++++ 25 files changed, 1540 insertions(+), 4 deletions(-) create mode 100644 docs/ebpf_rss.rst 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.skeleton.h create mode 100644 ebpf/trace-events create mode 100644 ebpf/trace.h create mode 100755 tools/ebpf/Makefile.ebpf create mode 100644 tools/ebpf/rss.bpf.c
Signature · 1 line
2.30.0
RFC PATCH v3 1/6 net/tap: Added TUNSETSTEERINGEBPF code.
From: Andrew <[email protected]>
Additional code that will be used for eBPF setting steering routine.
--- net/tap-linux.h | 1 + 1 file changed, 1 insertion(+)
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
Signature · 1 line
2.30.0
RFC PATCH v3 2/6 net: Added SetSteeringEBPF method for NetClientState.
In reply to Andrew MelnychenkoFrom: 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-solaris.c | 5 +++++ net/tap-stub.c | 5 +++++ net/tap.c | 9 +++++++++ net/tap_int.h | 1 + 7 files changed, 40 insertions(+)
include/net/net.h +2 -0
@@ -61,6 +61,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;
@@ -82,6 +83,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-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.30.0
RFC PATCH v3 3/6 ebpf: Added eBPF RSS program.
In reply to Andrew MelnychenkoFrom: Andrew <[email protected]>
RSS program and Makefile to build it.
The bpftool used to 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 rss.bpf.skeleton.h.
--- tools/ebpf/Makefile.ebpf | 33 +++ tools/ebpf/rss.bpf.c | 505 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 538 insertions(+) create mode 100755 tools/ebpf/Makefile.ebpf create mode 100644 tools/ebpf/rss.bpf.c
tools/ebpf/Makefile.ebpf new file +33 -0
@@ -0,0 +1,33 @@ +OBJS = rss.bpf.o + +LLC ?= llc +CLANG ?= clang +INC_FLAGS = `$(CLANG) -print-file-name=include` +EXTRA_CFLAGS ?= -O2 -emit-llvm -fno-stack-protector + +ifdef linuxhdrs +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 +INC_FLAGS += -nostdinc -isystem +endif + +all: $(OBJS) + +.PHONY: clean + +clean: + rm -f $(OBJS) + +$(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 $@ + bpftool gen skeleton rss.bpf.o > rss.bpf.skeleton.h + cp rss.bpf.skeleton.h ../../ebpf/ +
tools/ebpf/rss.bpf.c new file +505 -0
505 lines not on this page · raw message
Signature · 1 line
2.30.0
RFC PATCH v3 4/6 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 | 165 +++++++++++++++++ ebpf/ebpf_rss.h | 44 +++++ ebpf/meson.build | 1 + ebpf/rss.bpf.skeleton.h | 397 ++++++++++++++++++++++++++++++++++++++++ ebpf/trace-events | 4 + ebpf/trace.h | 2 + meson.build | 13 ++ 9 files changed, 699 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/rss.bpf.skeleton.h create mode 100644 ebpf/trace-events create mode 100644 ebpf/trace.h
configure +33 -0
@@ -342,6 +342,7 @@ vhost_vsock="$default_feature" vhost_user="no" vhost_user_blk_server="auto" vhost_user_fs="$default_feature" +bpf="" kvm="auto" hax="auto" hvf="auto"
@@ -1236,6 +1237,10 @@ for opt do ;; --enable-membarrier) membarrier="yes" ;; + --disable-bpf) bpf="no" + ;; + --enable-bpf) bpf="yes" + ;; --disable-blobs) blobs="false" ;; --with-pkgversion=*) pkgversion="$optarg"
@@ -1845,6 +1850,7 @@ disabled with --disable-FEATURE, default is enabled if available vhost-user vhost-user backend support vhost-user-blk-server vhost-user-blk server support vhost-vdpa vhost-vdpa kernel backend support + bpf BPF kernel support spice spice rbd rados block device (rbd) libiscsi iscsi support
@@ -5057,6 +5063,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
@@ -5905,6 +5935,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 +165 -0
165 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/rss.bpf.skeleton.h new file +397 -0
397 lines not on this page · raw message
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 +13 -0
@@ -968,6 +968,13 @@ if not get_option('fuse_lseek').disabled() endif endif +# libbpf +libbpf = not_found +if 'CONFIG_EBPF' in config_host + libbpf = cc.find_library('bpf', required: true) + +endif + if get_option('cfi') cfi_flags=[] # Check for dependency on LTO
@@ -1685,6 +1692,7 @@ if have_system 'backends', 'backends/tpm', 'chardev', + 'ebpf', 'hw/9pfs', 'hw/acpi', 'hw/alpha',
@@ -1850,6 +1858,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)
@@ -2415,6 +2426,7 @@ summary_info += {'vhost-user support': config_host.has_key('CONFIG_VHOST_USER')} summary_info += {'vhost-user-blk server support': have_vhost_user_blk_server} 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>'}
@@ -2516,3 +2528,4 @@ if not supported_oses.contains(targetos) message('if you care about QEMU on this platform you should contact') message('us upstream at [email protected].') endif +
Signature · 1 line
2.30.0
Re: [RFC PATCH v3 4/6] ebpf: Added eBPF RSS loader.
Quoted 62 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 | 165 +++++++++++++++++ ebpf/ebpf_rss.h | 44 +++++ ebpf/meson.build | 1 + ebpf/rss.bpf.skeleton.h | 397 ++++++++++++++++++++++++++++++++++++++++ ebpf/trace-events | 4 + ebpf/trace.h | 2 + meson.build | 13 ++ 9 files changed, 699 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 100644ebpf/rss.bpf.skeleton.h
create mode 100644 ebpf/trace-events
create mode 100644ebpf/trace.hconfigure +6
-0@@ -342,6 +342,7 @@ vhost_vsock="$default_feature" vhost_user="no" vhost_user_blk_server="auto" vhost_user_fs="$default_feature" +bpf="" kvm="auto" hax="auto" hvf="auto"@@ -1236,6 +1237,10 @@ for opt do ;; --enable-membarrier) membarrier="yes" ;; + --disable-bpf) bpf="no" + ;; + --enable-bpf) bpf="yes" + ;; --disable-blobs) blobs="false" ;; --with-pkgversion=*) pkgversion="$optarg"@@ -1845,6 +1850,7 @@ disabled with --disable-FEATURE, default is enabled if available vhost-user vhost-user backend support vhost-user-blk-server vhost-user-blk server support vhost-vdpa vhost-vdpa kernel backend support + bpf BPF kernel support spice spice rbd rados block device (rbd) libiscsi iscsi support
configure else · line 5068
Quoted 6 lines
configure +3
-0@@ -5057,6 +5063,30 @@ else membarrier=no fi +########################################## +# check for usable bpf system call +if test "$bpf" = ""; then
This implies the bpf is enabled by default?
Quoted 44 lines
configure +24
-0+ 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@@ -5905,6 +5935,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 +4
-0@@ -0,0 +1,40 @@ +/* +* eBPF RSS stub file +* +* Developed by Daynix Computing LTD (http://www.daynix.com)
ebpf/ebpf_rss-stub.c line 14
Quoted 10 lines
ebpf/ebpf_rss-stub.c new file +10
-0+* +* 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"
I wonder why not simply use #ifdef #else to exclude the rss functions.
If I read code correctly, this stub requires rss_is_loaded called before ebpf_rss_set_all(), so actually ebpf_rss_is_loaded serve the same as
Quoted 71 lines
ebpf/ebpf_rss-stub.c new file +26
-0+ +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 +39
-0@@ -0,0 +1,165 @@ +/* +* 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/rss.bpf.skeleton.h" +#include "trace.h" + +void ebpf_rss_init (struct EBPFRSSContext *ctx) +{ +if (ctx !=NULL ) { + ctx->obj =NULL ; + } +} + +bool ebpf_rss_is_loaded (struct EBPFRSSContext *ctx) +{ +return ctx !=NULL && ctx->obj !=NULL ; +} + +bool ebpf_rss_load (struct EBPFRSSContext *ctx) +{
ebpf/ebpf_rss.c line 49
Quoted 10 lines
ebpf/ebpf_rss.c new file +10
-0+struct rss_bpf *rss_bpf_ctx; + +if (ctx ==NULL ) { +return false; + } + + rss_bpf_ctx =rss_bpf__open (); +if (rss_bpf_ctx ==NULL ) { +trace_ebpf_error ("eBPF RSS" ,"can not open eBPF RSS object" ); + goto l_issue;
Nit: it's not easy to infer what did "l" mean, it's probably better to use "error".
Thanks
Re: [RFC PATCH v3 4/6] ebpf: Added eBPF RSS loader.
Quoted 68 lines · Jason Wang
Quoted 65 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 | 165 +++++++++++++++++ ebpf/ebpf_rss.h | 44 +++++ ebpf/meson.build | 1 + ebpf/rss.bpf.skeleton.h | 397 ++++++++++++++++++++++++++++++++++++++++ ebpf/trace-events | 4 + ebpf/trace.h | 2 + meson.build | 13 ++ 9 files changed, 699 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 100644ebpf/rss.bpf.skeleton.h
create mode 100644 ebpf/trace-events
create mode 100644ebpf/trace.hconfigure +6
-0@@ -342,6 +342,7 @@ vhost_vsock="$default_feature" vhost_user="no" vhost_user_blk_server="auto" vhost_user_fs="$default_feature" +bpf="" kvm="auto" hax="auto" hvf="auto"@@ -1236,6 +1237,10 @@ for opt do ;; --enable-membarrier) membarrier="yes" ;; + --disable-bpf) bpf="no" + ;; + --enable-bpf) bpf="yes" + ;; --disable-blobs) blobs="false" ;; --with-pkgversion=*) pkgversion="$optarg"@@ -1845,6 +1850,7 @@ disabled with --disable-FEATURE, default is enabled if available vhost-user vhost-user backend support vhost-user-blk-server vhost-user-blk server support vhost-vdpa vhost-vdpa kernel backend support + bpf BPF kernel support spice spice rbd rados block device (rbd) libiscsi iscsi support@@ -5057,6 +5063,30 @@ else membarrier=no fi
Quoted 6 lines
configure else · line 5068
Quoted 3 lines
configure +3
-0+########################################## +# check for usable bpf system call +if test "$bpf" = ""; thenThis implies the bpf is enabled by default?
Yes, assuming libbpf-devel present and bpf system call defined.
Any problem with it?
Quoted 51 lines
Quoted 51 lines
configure +24
-0+ 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@@ -5905,6 +5935,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 +9
-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
Quoted 8 lines
ebpf/ebpf_rss-stub.c line 14
Quoted 5 lines
ebpf/ebpf_rss-stub.c new file +5
-0+* the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "ebpf/ebpf_rss.h" I wonder why not simply use #ifdef #else to exclude the rss functions.
Just to make the reading easier.
Quoted 3 lines
If I read code correctly, this stub requires
rss_is_loadedcalled beforeebpf_rss_set_all(), so actuallyebpf_rss_is_loadedserve the same as
Can you please get into details?
I think the stub does not require it, it just converts all the ebpf_rss calls to nop at link time.
If I miss something please let us know, we'll fix it in v4.
Quoted 79 lines
Quoted 79 lines
ebpf/ebpf_rss-stub.c new file +26
-0+ +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 +45
-0@@ -0,0 +1,165 @@ +/* +* 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/rss.bpf.skeleton.h" +#include "trace.h" + +void ebpf_rss_init (struct EBPFRSSContext *ctx) +{ +if (ctx !=NULL ) { + ctx->obj =NULL ; + } +} + +bool ebpf_rss_is_loaded (struct EBPFRSSContext *ctx) +{ +return ctx !=NULL && ctx->obj !=NULL ; +} + +bool ebpf_rss_load (struct EBPFRSSContext *ctx) +{ +struct rss_bpf *rss_bpf_ctx; + +if (ctx ==NULL ) { +return false; + } +
Quoted 8 lines
ebpf/ebpf_rss.c line 49
Quoted 4 lines
ebpf/ebpf_rss.c new file +4
-0+ rss_bpf_ctx =rss_bpf__open (); +if (rss_bpf_ctx ==NULL ) { +trace_ebpf_error ("eBPF RSS" ,"can not open eBPF RSS object" ); + goto l_issue;Nit: it's not easy to infer what did "l" mean, it's probably better to use "error".
ok, will be renamed, 'l' means 'load' probably
Quoted 3 lines
Thanks
Re: [RFC PATCH v3 4/6] ebpf: Added eBPF RSS loader.
Quoted 68 lines · Yuri Benditovich
Quoted 67 lines · Jason Wang
Quoted 65 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 | 165 +++++++++++++++++ ebpf/ebpf_rss.h | 44 +++++ ebpf/meson.build | 1 + ebpf/rss.bpf.skeleton.h | 397 ++++++++++++++++++++++++++++++++++++++++ ebpf/trace-events | 4 + ebpf/trace.h | 2 + meson.build | 13 ++ 9 files changed, 699 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 100644ebpf/rss.bpf.skeleton.h
create mode 100644 ebpf/trace-events
create mode 100644ebpf/trace.hconfigure +6
-0@@ -342,6 +342,7 @@ vhost_vsock="$default_feature" vhost_user="no" vhost_user_blk_server="auto" vhost_user_fs="$default_feature" +bpf="" kvm="auto" hax="auto" hvf="auto"@@ -1236,6 +1237,10 @@ for opt do ;; --enable-membarrier) membarrier="yes" ;; + --disable-bpf) bpf="no" + ;; + --enable-bpf) bpf="yes" + ;; --disable-blobs) blobs="false" ;; --with-pkgversion=*) pkgversion="$optarg"@@ -1845,6 +1850,7 @@ disabled with --disable-FEATURE, default is enabled if available vhost-user vhost-user backend support vhost-user-blk-server vhost-user-blk server support vhost-vdpa vhost-vdpa kernel backend support + bpf BPF kernel support spice spice rbd rados block device (rbd) libiscsi iscsi support@@ -5057,6 +5063,30 @@ else membarrier=no fi
Quoted 8 lines
Quoted 5 lines
configure else · line 5068
Quoted 3 lines
configure +3
-0+########################################## +# check for usable bpf system call +if test "$bpf" = ""; thenThis implies the bpf is enabled by default?
Yes, assuming libbpf-devel present and bpf system call defined.
Any problem with it?
It means the configure will fail if libbpf is not installed. Consider libbpf is not very common at current stage. I think it's better to make it auto or disabled by default.
Quoted 58 lines
Quoted 50 lines
Quoted 50 lines
configure +24
-0+ 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@@ -5905,6 +5935,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 +8
-0@@ -0,0 +1,40 @@ +/* +* eBPF RSS stub file +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Yuri Benditovich <[email protected]> +* Quoted 8 lines
ebpf/ebpf_rss-stub.c line 14
Quoted 6 lines
ebpf/ebpf_rss-stub.c new file +6
-0+* 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" I wonder why not simply use #ifdef #else to exclude the rss functions.
Quoted 8 lines
Just to make the reading easier.
Quoted 2 lines
If I read code correctly, this stub requires
rss_is_loadedcalled beforeebpf_rss_set_all(), so actuallyebpf_rss_is_loadedserve the same asCan you please get into details?
I think the stub does not require it, it just converts all theebpf_rsscalls to nop at link time.
If I miss something please let us know, we'll fix it in v4.
I mean the current can not be used without checking rss_is_loaded(). So rss_is_loaded() is somehow a guard like macro.
I personally prefer #ifdef but it's not a must.
Thanks
Re: [RFC PATCH v3 4/6] ebpf: Added eBPF RSS loader.
Quoted 76 lines · Jason Wang
Quoted 73 lines · Yuri Benditovich
Quoted 72 lines · Jason Wang
Quoted 62 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 | 165 +++++++++++++++++ ebpf/ebpf_rss.h | 44 +++++ ebpf/meson.build | 1 + ebpf/rss.bpf.skeleton.h | 397 ++++++++++++++++++++++++++++++++++++++++ ebpf/trace-events | 4 + ebpf/trace.h | 2 + meson.build | 13 ++ 9 files changed, 699 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 100644ebpf/rss.bpf.skeleton.h
create mode 100644 ebpf/trace-events
create mode 100644ebpf/trace.hconfigure +6
-0@@ -342,6 +342,7 @@ vhost_vsock="$default_feature" vhost_user="no" vhost_user_blk_server="auto" vhost_user_fs="$default_feature" +bpf="" kvm="auto" hax="auto" hvf="auto"@@ -1236,6 +1237,10 @@ for opt do ;; --enable-membarrier) membarrier="yes" ;; + --disable-bpf) bpf="no" + ;; + --enable-bpf) bpf="yes" + ;; --disable-blobs) blobs="false" ;; --with-pkgversion=*) pkgversion="$optarg"@@ -1845,6 +1850,7 @@ disabled with --disable-FEATURE, default is enabled if available vhost-user vhost-user backend support vhost-user-blk-server vhost-user-blk server support vhost-vdpa vhost-vdpa kernel backend support + bpf BPF kernel support spice spice rbd rados block device (rbd) libiscsi iscsi supportconfigure else · line 5068
Quoted 6 lines
configure +3
-0@@ -5057,6 +5063,30 @@ else membarrier=no fi +########################################## +# check for usable bpf system call +if test "$bpf" = ""; thenThis implies the bpf is enabled by default?
Quoted 31 lines
Quoted 3 lines
Yes, assuming libbpf-devel present and bpf system call defined.
Any problem with it?
It means the configure will fail if libbpf is not installed. Consider libbpf is not very common at current stage. I think it's better to make it auto or disabled by default.
Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
configure +19
-0+ 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
Yes, this is a mistake. These 3 lines are to be removed. If libbpf is not installed, this should not fail the build.
Quoted 54 lines
Quoted 37 lines
Quoted 29 lines
Quoted 29 lines
configure +5
-0+fi + ########################################## # check if rtnetlink.h exists and is useful have_rtnetlink=no@@ -5905,6 +5935,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 +8
-0@@ -0,0 +1,40 @@ +/* +* eBPF RSS stub file +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Yuri Benditovich <[email protected]> +* Quoted 8 lines
ebpf/ebpf_rss-stub.c line 14
Quoted 6 lines
ebpf/ebpf_rss-stub.c new file +6
-0+* 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" I wonder why not simply use #ifdef #else to exclude the rss functions.
Quoted 8 lines
Just to make the reading easier.
Quoted 2 lines
If I read code correctly, this stub requires
rss_is_loadedcalled beforeebpf_rss_set_all(), so actuallyebpf_rss_is_loadedserve the same asCan you please get into details?
I think the stub does not require it, it just converts all theebpf_rsscalls to nop at link time.
If I miss something please let us know, we'll fix it in v4.I mean the current can not be used without checking
rss_is_loaded(). Sorss_is_loaded()is somehow a guard like macro.I personally prefer #ifdef but it's not a must.
Thanks
RFC PATCH v3 5/6 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 | 125 +++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 4 ++ net/vhost-vdpa.c | 2 + 4 files changed, 129 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 +121 -4
185 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;
@@ -209,6 +212,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.30.0
Re: [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net.
Quoted 35 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 | 125 +++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 4 ++ net/vhost-vdpa.c | 2 + 4 files changed, 129 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
hw/net/virtio-net.c static void virtio_net_set_queues(VirtIONet *n) · line 696
Quoted 6 lines
hw/net/virtio-net.c +3
-0@@ -691,6 +691,19 @@ static void virtio_net_set_queues(VirtIONet *n)static 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 */
I still think we should not clear feature silently. This may break migraiton if the feature is cleared on destination.
Quoted 107 lines
hw/net/virtio-net.c +80
-3+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 ); + +return ret; +} +static uint64_t virtio_net_get_features (VirtIODevice *vdev,uint64_t features,Error **errp) {@@ -725,9 +738,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 &&@@ -1151,12 +1164,79 @@ static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd, } } +static void virtio_net_detach_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; + +virtio_net_detach_epbf_rss (n); +} + +static bool virtio_net_attach_ebpf_to_backend (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_attach_epbf_rss (VirtIONet *n) +{ +struct EBPFRSSConfig config = {}; + +if (!ebpf_rss_is_loaded (&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)) { +return false; + } + +if (!virtio_net_attach_ebpf_to_backend (n->nic, n->ebpf_rss.program_fd)) { +return false; + } + +return true; +} + +static void virtio_net_detach_epbf_rss (VirtIONet *n) +{ +virtio_net_attach_ebpf_to_backend (n->nic,-1 ); +} + +static bool virtio_net_load_ebpf (VirtIONet *n) +{ +if (!virtio_net_attach_ebpf_to_backend (n->nic,-1 )) { +/* backend does't support steering ebpf */ +return false; + } + +return ebpf_rss_load (&n->ebpf_rss); +} + +static void virtio_net_unload_ebpf (VirtIONet *n) +{ +virtio_net_attach_ebpf_to_backend (n->nic,-1 ); +ebpf_rss_unload (&n->ebpf_rss); } static uint16_t virtio_net_handle_rss(VirtIONet *n,
hw/net/virtio-net.c static uint16_t virtio_net_handle_rss(VirtIONet *n, · line 1360
Quoted 10 lines
hw/net/virtio-net.c +7
-0@@ -1271,6 +1351,25 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, goto error; } n->rss_data.enabled = true; + +if (!n->rss_data.populate_hash) { +if (!virtio_net_attach_epbf_rss (n)) { +/* EBPF must be loaded for vhost */ +if (get_vhost_net (qemu_get_queue (n->nic)->peer)) { +warn_report ("Can't load eBPF RSS for vhost" ); + goto error;
How about stop the vhost in this case?
Thanks
Re: [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net.
Quoted 41 lines · Jason Wang
Quoted 38 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 | 125 +++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 4 ++ net/vhost-vdpa.c | 2 + 4 files changed, 129 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@@ -691,6 +691,19 @@ static void virtio_net_set_queues(VirtIONet *n)static void virtio_net_set_multiqueue (VirtIONet *n,int multiqueue);
Quoted 7 lines
hw/net/virtio-net.c static void virtio_net_set_queues(VirtIONet *n) · line 696
Quoted 3 lines
hw/net/virtio-net.c +3
-0+static uint64_t fix_ebpf_vhost_features (uint64_t features) +{ +/* If vhost=on & CONFIG_EBPF doesn't set - disable RSS feature */ I still think we should not clear feature silently. This may break migraiton if the feature is cleared on destination.
Do I understand it correctly that if we do not clear features silently and implement a graceful drop to vhost=off when we can't do what we need with vhost - then we do not need to add any migration blocker?
Quoted 126 lines
Quoted 109 lines
hw/net/virtio-net.c +80
-3+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 ); + +return ret; +} +static uint64_t virtio_net_get_features (VirtIODevice *vdev,uint64_t features,Error **errp) {@@ -725,9 +738,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 &&@@ -1151,12 +1164,79 @@ static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd, } } +static void virtio_net_detach_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; + +virtio_net_detach_epbf_rss (n); +} + +static bool virtio_net_attach_ebpf_to_backend (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_attach_epbf_rss (VirtIONet *n) +{ +struct EBPFRSSConfig config = {}; + +if (!ebpf_rss_is_loaded (&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)) { +return false; + } + +if (!virtio_net_attach_ebpf_to_backend (n->nic, n->ebpf_rss.program_fd)) { +return false; + } + +return true; +} + +static void virtio_net_detach_epbf_rss (VirtIONet *n) +{ +virtio_net_attach_ebpf_to_backend (n->nic,-1 ); +} + +static bool virtio_net_load_ebpf (VirtIONet *n) +{ +if (!virtio_net_attach_ebpf_to_backend (n->nic,-1 )) { +/* backend does't support steering ebpf */ +return false; + } + +return ebpf_rss_load (&n->ebpf_rss); +} + +static void virtio_net_unload_ebpf (VirtIONet *n) +{ +virtio_net_attach_ebpf_to_backend (n->nic,-1 ); +ebpf_rss_unload (&n->ebpf_rss); } static uint16_t virtio_net_handle_rss(VirtIONet *n,hw/net/virtio-net.c static uint16_t virtio_net_handle_rss(VirtIONet *n, · line 1360
Quoted 10 lines
hw/net/virtio-net.c +7
-0@@ -1271,6 +1351,25 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n, goto error; } n->rss_data.enabled = true; + +if (!n->rss_data.populate_hash) { +if (!virtio_net_attach_epbf_rss (n)) { +/* EBPF must be loaded for vhost */ +if (get_vhost_net (qemu_get_queue (n->nic)->peer)) { +warn_report ("Can't load eBPF RSS for vhost" ); + goto error;How about stop the vhost in this case?
Thanks
Re: [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net.
Quoted 40 lines · Yuri Benditovich
Quoted 39 lines · Jason Wang
Quoted 38 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 | 125 +++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 4 ++ net/vhost-vdpa.c | 2 + 4 files changed, 129 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@@ -691,6 +691,19 @@ static void virtio_net_set_queues(VirtIONet *n)static void virtio_net_set_multiqueue (VirtIONet *n,int multiqueue);
Quoted 8 lines
Quoted 5 lines
hw/net/virtio-net.c static void virtio_net_set_queues(VirtIONet *n) · line 696
Quoted 3 lines
hw/net/virtio-net.c +3
-0+static uint64_t fix_ebpf_vhost_features (uint64_t features) +{ +/* If vhost=on & CONFIG_EBPF doesn't set - disable RSS feature */ I still think we should not clear feature silently. This may break migraiton if the feature is cleared on destination.
Do I understand it correctly that if we do not clear features silently and implement a graceful drop to vhost=off when we can't do what we need with vhost - then we do not need to add any migration blocker?
Yes. I think we won't go with migration blocker since we need support migration in the end.
Thanks
Quoted 1 line
Re: [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net.
Hi Jason,
I've prepared a POC of graceful switch to 'vhost off' if respective features are acked by the guest.
Such a way we do not need to silently clear RSS and hash report features in case of 'vhost on'.
Can you please review it and provide your feedback?
I think the only open question is what to do with cases of vhost-user and vhost-vdpa.
https://github.com/qemu/qemu/pull/105
This pull request is for reviews only.
Thanks in advance
Quoted 61 lines · Jason Wang
Quoted 40 lines · Yuri Benditovich
Quoted 39 lines · Jason Wang
Quoted 38 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 | 125 +++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 4 ++ net/vhost-vdpa.c | 2 + 4 files changed, 129 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@@ -691,6 +691,19 @@ static void virtio_net_set_queues(VirtIONet *n)static void virtio_net_set_multiqueue (VirtIONet *n,int multiqueue);Quoted 8 lines
Quoted 5 lines
hw/net/virtio-net.c static void virtio_net_set_queues(VirtIONet *n) · line 696
Quoted 3 lines
hw/net/virtio-net.c +3
-0+static uint64_t fix_ebpf_vhost_features (uint64_t features) +{ +/* If vhost=on & CONFIG_EBPF doesn't set - disable RSS feature */ I still think we should not clear feature silently. This may break migraiton if the feature is cleared on destination.
Do I understand it correctly that if we do not clear features silently and implement a graceful drop to vhost=off when we can't do what we need with vhost - then we do not need to add any migration blocker?
Yes. I think we won't go with migration blocker since we need support migration in the end.
Thanks
Quoted 1 line
Re: [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net.
Quoted 9 lines · Yuri Benditovich
Hi Jason,
I've prepared a POC of graceful switch to 'vhost off' if respective features are acked by the guest.
Such a way we do not need to silently clear RSS and hash report features in case of 'vhost on'.
Can you please review it and provide your feedback?
Quoted 5 lines
I think the only open question is what to do with cases of vhost-user and vhost-vdpa.
https://github.com/qemu/qemu/pull/105
This pull request is for reviews only.
Unfortunately qemu github PR is closed for comments This is the link to the same on Daynix repository
https://github.com/daynix/qemu/pull/1
Quoted 70 lines
Thanks in advance
Quoted 61 lines · Jason Wang
Quoted 40 lines · Yuri Benditovich
Quoted 39 lines · Jason Wang
Quoted 38 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 | 125 +++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 4 ++ net/vhost-vdpa.c | 2 + 4 files changed, 129 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@@ -691,6 +691,19 @@ static void virtio_net_set_queues(VirtIONet *n)static void virtio_net_set_multiqueue (VirtIONet *n,int multiqueue);Quoted 8 lines
Quoted 5 lines
hw/net/virtio-net.c static void virtio_net_set_queues(VirtIONet *n) · line 696
Quoted 3 lines
hw/net/virtio-net.c +3
-0+static uint64_t fix_ebpf_vhost_features (uint64_t features) +{ +/* If vhost=on & CONFIG_EBPF doesn't set - disable RSS feature */ I still think we should not clear feature silently. This may break migraiton if the feature is cleared on destination.
Do I understand it correctly that if we do not clear features silently and implement a graceful drop to vhost=off when we can't do what we need with vhost - then we do not need to add any migration blocker?
Yes. I think we won't go with migration blocker since we need support migration in the end.
Thanks
Quoted 1 line
Re: [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net.
In reply to Yuri BenditovichQuoted 8 lines · Yuri Benditovich
Hi Jason,
I've prepared a POC of graceful switch to 'vhost off' if respective features are acked by the guest.
Such a way we do not need to silently clear RSS and hash report features in case of 'vhost on'.
Can you please review it and provide your feedback?
Quoted 7 lines
I think the only open question is what to do with cases of vhost-user and vhost-vdpa.
https://github.com/qemu/qemu/pull/105
This pull request is for reviews only.Thanks in advance
Will review it sometime this week.
Thanks
Quoted 64 lines · Jason Wang
Quoted 57 lines · Yuri Benditovich
Quoted 40 lines · Jason Wang
Quoted 39 lines · Andrew Melnychenko
Quoted 38 lines
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 | 125 +++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 4 ++ net/vhost-vdpa.c | 2 + 4 files changed, 129 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@@ -691,6 +691,19 @@ static void virtio_net_set_queues(VirtIONet *n)static void virtio_net_set_multiqueue (VirtIONet *n,int multiqueue);Quoted 8 lines
Quoted 5 lines
hw/net/virtio-net.c static void virtio_net_set_queues(VirtIONet *n) · line 696
Quoted 3 lines
hw/net/virtio-net.c +3
-0+static uint64_t fix_ebpf_vhost_features (uint64_t features) +{ +/* If vhost=on & CONFIG_EBPF doesn't set - disable RSS feature */ I still think we should not clear feature silently. This may break migraiton if the feature is cleared on destination.
Do I understand it correctly that if we do not clear features silently and implement a graceful drop to vhost=off when we can't do what we need with vhost - then we do not need to add any migration blocker?
Yes. I think we won't go with migration blocker since we need support migration in the end.
Thanks
RFC PATCH v3 6/6 docs: Added eBPF documentation.
In reply to Andrew MelnychenkoFrom: Andrew <[email protected]>
Also, added maintainers information.
--- MAINTAINERS | 8 +++ docs/ebpf_rss.rst | 125 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 docs/ebpf_rss.rst
MAINTAINERS +8 -0
@@ -3173,6 +3173,14 @@ 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/* +F: tools/ebpf/* + Build and test automation ------------------------- Build and test automation
docs/ebpf_rss.rst new file +125 -0
125 lines not on this page · raw message
Signature · 1 line
2.30.0
Re: [RFC PATCH v3 6/6] docs: Added eBPF documentation.
Quoted 17 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 | 8 +++ docs/ebpf_rss.rst | 125 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+)create mode 100644
docs/ebpf_rss.rstMAINTAINERS +0
-0
MAINTAINERS S: Maintained · line 3182
Quoted 10 lines
MAINTAINERS +7
-0@@ -3173,6 +3173,14 @@ 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/* +F: tools/ebpf/*
It's better to do this in another patch.
Thanks
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [RFC PATCH v3 0/6] eBPF RSS support for virtio-net
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected] -> patchew/[email protected] - [tag update] patchew/[email protected] -> patchew/[email protected] - [tag update] patchew/[email protected] -> patchew/[email protected] - [tag update] patchew/[email protected] -> patchew/[email protected] - [tag update] patchew/[email protected] -> patchew/[email protected] * [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
32a7d31 docs: Added eBPF documentation.
5829b35 virtio-net: Added eBPF RSS to virtio-net. c1e16f7 ebpf: Added eBPF RSS loader.
67e8d5f ebpf: Added eBPF RSS program.
9955cbd net: Added SetSteeringEBPF method for NetClientState. 7255813 net/tap: Added TUNSETSTEERINGEBPF code.
=== OUTPUT BEGIN ===
1/6 Checking commit 725581347a66 (net/tap: Added TUNSETSTEERINGEBPF code.) 2/6 Checking commit 9955cbd7e95d (net: Added SetSteeringEBPF method for NetClientState.) 3/6 Checking commit 67e8d5f1220d (ebpf: Added eBPF RSS program.)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #18:
new file mode 100755
WARNING: line over 80 characters
#216: FILE: tools/ebpf/rss.bpf.c:155:
+ * According to https://www.iana.org/assignments/ipv6-parameters/ipv6-parameters.xhtml
WARNING: line over 80 characters
#219: FILE: tools/ebpf/rss.bpf.c:158:
+ * Need to choose reasonable amount of maximum extensions/options we may check to find
WARNING: line over 80 characters
#279: FILE: tools/ebpf/rss.bpf.c:218:
+ *l4_offset + opt_offset + offsetof(struct ipv6_destopt_hao, addr),
total: 0 errors, 4 warnings, 538 lines checked
Patch 3/6 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
4/6 Checking commit c1e16f784c92 (ebpf: Added eBPF RSS loader.)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #91:
new file mode 100644
WARNING: architecture specific defines should be avoided #373: FILE: ebpf/rss.bpf.skeleton.h:4:
+#ifndef __RSS_BPF_SKEL_H__
ERROR: code indent should never use tabs
#380: FILE: ebpf/rss.bpf.skeleton.h:11:
+^Istruct bpf_object_skeleton *skeleton;$
ERROR: code indent should never use tabs
#381: FILE: ebpf/rss.bpf.skeleton.h:12:
+^Istruct bpf_object *obj;$
ERROR: code indent should never use tabs
#382: FILE: ebpf/rss.bpf.skeleton.h:13:
+^Istruct {$
ERROR: code indent should never use tabs
#383: FILE: ebpf/rss.bpf.skeleton.h:14:
+^I^Istruct bpf_map *tap_rss_map_configurations;$
ERROR: code indent should never use tabs #384: FILE: ebpf/rss.bpf.skeleton.h:15:
+^I^Istruct bpf_map *tap_rss_map_indirection_table;$
ERROR: code indent should never use tabs
#385: FILE: ebpf/rss.bpf.skeleton.h:16:
+^I^Istruct bpf_map *tap_rss_map_toeplitz_key;$
ERROR: code indent should never use tabs
#386: FILE: ebpf/rss.bpf.skeleton.h:17:
+^I} maps;$
ERROR: code indent should never use tabs
#387: FILE: ebpf/rss.bpf.skeleton.h:18:
+^Istruct {$
ERROR: code indent should never use tabs
#388: FILE: ebpf/rss.bpf.skeleton.h:19:
+^I^Istruct bpf_program *tun_rss_steering_prog;$
ERROR: code indent should never use tabs
#389: FILE: ebpf/rss.bpf.skeleton.h:20:
+^I} progs;$
ERROR: code indent should never use tabs
#390: FILE: ebpf/rss.bpf.skeleton.h:21:
+^Istruct {$
ERROR: code indent should never use tabs
#391: FILE: ebpf/rss.bpf.skeleton.h:22:
+^I^Istruct bpf_link *tun_rss_steering_prog;$
ERROR: code indent should never use tabs
#392: FILE: ebpf/rss.bpf.skeleton.h:23:
+^I} links;$
ERROR: code indent should never use tabs
#398: FILE: ebpf/rss.bpf.skeleton.h:29:
+^Iif (!obj)$
ERROR: braces {} are necessary for all arms of this statement #398: FILE: ebpf/rss.bpf.skeleton.h:29:
+ if (!obj)
[...]
ERROR: code indent should never use tabs
#399: FILE: ebpf/rss.bpf.skeleton.h:30:
+^I^Ireturn;$
ERROR: code indent should never use tabs
#400: FILE: ebpf/rss.bpf.skeleton.h:31:
+^Iif (obj->skeleton)$
ERROR: braces {} are necessary for all arms of this statement #400: FILE: ebpf/rss.bpf.skeleton.h:31:
+ if (obj->skeleton)
[...]
ERROR: code indent should never use tabs #401: FILE: ebpf/rss.bpf.skeleton.h:32:
+^I^Ibpf_object__destroy_skeleton(obj->skeleton);$
ERROR: code indent should never use tabs
#402: FILE: ebpf/rss.bpf.skeleton.h:33:
+^Ifree(obj);$
ERROR: code indent should never use tabs
#411: FILE: ebpf/rss.bpf.skeleton.h:42:
+^Istruct rss_bpf *obj;$
ERROR: code indent should never use tabs #413: FILE: ebpf/rss.bpf.skeleton.h:44:
+^Iobj = (struct rss_bpf *)calloc(1, sizeof(*obj));$
ERROR: code indent should never use tabs
#414: FILE: ebpf/rss.bpf.skeleton.h:45:
+^Iif (!obj)$
ERROR: braces {} are necessary for all arms of this statement #414: FILE: ebpf/rss.bpf.skeleton.h:45:
+ if (!obj)
[...]
ERROR: code indent should never use tabs
#415: FILE: ebpf/rss.bpf.skeleton.h:46:
+^I^Ireturn NULL;$
ERROR: code indent should never use tabs
#416: FILE: ebpf/rss.bpf.skeleton.h:47:
+^Iif (rss_bpf__create_skeleton(obj))$
ERROR: braces {} are necessary for all arms of this statement #416: FILE: ebpf/rss.bpf.skeleton.h:47:
+ if (rss_bpf__create_skeleton(obj))
[...]
ERROR: code indent should never use tabs
#417: FILE: ebpf/rss.bpf.skeleton.h:48:
+^I^Igoto err;$
ERROR: code indent should never use tabs
#418: FILE: ebpf/rss.bpf.skeleton.h:49:
+^Iif (bpf_object__open_skeleton(obj->skeleton, opts))$
ERROR: braces {} are necessary for all arms of this statement #418: FILE: ebpf/rss.bpf.skeleton.h:49:
+ if (bpf_object__open_skeleton(obj->skeleton, opts))
[...]
ERROR: code indent should never use tabs
#419: FILE: ebpf/rss.bpf.skeleton.h:50:
+^I^Igoto err;$
ERROR: code indent should never use tabs
#421: FILE: ebpf/rss.bpf.skeleton.h:52:
+^Ireturn obj;$
ERROR: code indent should never use tabs
#423: FILE: ebpf/rss.bpf.skeleton.h:54:
+^Irss_bpf__destroy(obj);$
ERROR: code indent should never use tabs
#424: FILE: ebpf/rss.bpf.skeleton.h:55:
+^Ireturn NULL;$
ERROR: code indent should never use tabs
#430: FILE: ebpf/rss.bpf.skeleton.h:61:
+^Ireturn rss_bpf__open_opts(NULL);$
ERROR: code indent should never use tabs #436: FILE: ebpf/rss.bpf.skeleton.h:67:
+^Ireturn bpf_object__load_skeleton(obj->skeleton);$
ERROR: code indent should never use tabs
#442: FILE: ebpf/rss.bpf.skeleton.h:73:
+^Istruct rss_bpf *obj;$
ERROR: code indent should never use tabs
#444: FILE: ebpf/rss.bpf.skeleton.h:75:
+^Iobj = rss_bpf__open();$
ERROR: code indent should never use tabs
#445: FILE: ebpf/rss.bpf.skeleton.h:76:
+^Iif (!obj)$
ERROR: braces {} are necessary for all arms of this statement #445: FILE: ebpf/rss.bpf.skeleton.h:76:
+ if (!obj)
[...]
ERROR: code indent should never use tabs
#446: FILE: ebpf/rss.bpf.skeleton.h:77:
+^I^Ireturn NULL;$
ERROR: code indent should never use tabs
#447: FILE: ebpf/rss.bpf.skeleton.h:78:
+^Iif (rss_bpf__load(obj)) {$
ERROR: code indent should never use tabs
#448: FILE: ebpf/rss.bpf.skeleton.h:79:
+^I^Irss_bpf__destroy(obj);$
ERROR: code indent should never use tabs
#449: FILE: ebpf/rss.bpf.skeleton.h:80:
+^I^Ireturn NULL;$
ERROR: code indent should never use tabs
#450: FILE: ebpf/rss.bpf.skeleton.h:81:
+^I}$
ERROR: code indent should never use tabs
#451: FILE: ebpf/rss.bpf.skeleton.h:82:
+^Ireturn obj;$
ERROR: code indent should never use tabs #457: FILE: ebpf/rss.bpf.skeleton.h:88:
+^Ireturn bpf_object__attach_skeleton(obj->skeleton);$
ERROR: code indent should never use tabs #463: FILE: ebpf/rss.bpf.skeleton.h:94:
+^Ireturn bpf_object__detach_skeleton(obj->skeleton);$
ERROR: code indent should never use tabs
#469: FILE: ebpf/rss.bpf.skeleton.h:100:
+^Istruct bpf_object_skeleton *s;$
ERROR: code indent should never use tabs
#471: FILE: ebpf/rss.bpf.skeleton.h:102:
+^Is = (struct bpf_object_skeleton *)calloc(1, sizeof(*s));$
ERROR: code indent should never use tabs
#472: FILE: ebpf/rss.bpf.skeleton.h:103:
+^Iif (!s)$
ERROR: braces {} are necessary for all arms of this statement #472: FILE: ebpf/rss.bpf.skeleton.h:103:
+ if (!s)
[...]
ERROR: code indent should never use tabs
#473: FILE: ebpf/rss.bpf.skeleton.h:104:
+^I^Ireturn -1;$
ERROR: code indent should never use tabs
#474: FILE: ebpf/rss.bpf.skeleton.h:105:
+^Iobj->skeleton = s;$
ERROR: code indent should never use tabs
#476: FILE: ebpf/rss.bpf.skeleton.h:107:
+^Is->sz = sizeof(*s);$
ERROR: code indent should never use tabs
#477: FILE: ebpf/rss.bpf.skeleton.h:108:
+^Is->name = "rss_bpf";$
ERROR: code indent should never use tabs
#478: FILE: ebpf/rss.bpf.skeleton.h:109:
+^Is->obj = &obj->obj;$
ERROR: code indent should never use tabs
#480: FILE: ebpf/rss.bpf.skeleton.h:111:
+^I/* maps */$
ERROR: code indent should never use tabs
#481: FILE: ebpf/rss.bpf.skeleton.h:112:
+^Is->map_cnt = 3;$
ERROR: code indent should never use tabs
#482: FILE: ebpf/rss.bpf.skeleton.h:113:
+^Is->map_skel_sz = sizeof(*s->maps);$
ERROR: code indent should never use tabs
#483: FILE: ebpf/rss.bpf.skeleton.h:114:
+^Is->maps = (struct bpf_map_skeleton *)calloc(s->map_cnt, s->map_skel_sz);$
ERROR: code indent should never use tabs
#484: FILE: ebpf/rss.bpf.skeleton.h:115:
+^Iif (!s->maps)$
ERROR: braces {} are necessary for all arms of this statement #484: FILE: ebpf/rss.bpf.skeleton.h:115:
+ if (!s->maps)
[...]
ERROR: code indent should never use tabs
#485: FILE: ebpf/rss.bpf.skeleton.h:116:
+^I^Igoto err;$
ERROR: code indent should never use tabs #487: FILE: ebpf/rss.bpf.skeleton.h:118:
+^Is->maps[0].name = "tap_rss_map_configurations";$
ERROR: code indent should never use tabs
#488: FILE: ebpf/rss.bpf.skeleton.h:119:
+^Is->maps[0].map = &obj->maps.tap_rss_map_configurations;$
ERROR: code indent should never use tabs #490: FILE: ebpf/rss.bpf.skeleton.h:121:
+^Is->maps[1].name = "tap_rss_map_indirection_table";$
ERROR: code indent should never use tabs
#491: FILE: ebpf/rss.bpf.skeleton.h:122:
+^Is->maps[1].map = &obj->maps.tap_rss_map_indirection_table;$
ERROR: code indent should never use tabs
#493: FILE: ebpf/rss.bpf.skeleton.h:124:
+^Is->maps[2].name = "tap_rss_map_toeplitz_key";$
ERROR: code indent should never use tabs
#494: FILE: ebpf/rss.bpf.skeleton.h:125:
+^Is->maps[2].map = &obj->maps.tap_rss_map_toeplitz_key;$
ERROR: code indent should never use tabs
#496: FILE: ebpf/rss.bpf.skeleton.h:127:
+^I/* programs */$
ERROR: code indent should never use tabs
#497: FILE: ebpf/rss.bpf.skeleton.h:128:
+^Is->prog_cnt = 1;$
ERROR: code indent should never use tabs
#498: FILE: ebpf/rss.bpf.skeleton.h:129:
+^Is->prog_skel_sz = sizeof(*s->progs);$
WARNING: line over 80 characters
#499: FILE: ebpf/rss.bpf.skeleton.h:130:
+ s->progs = (struct bpf_prog_skeleton *)calloc(s->prog_cnt, s->prog_skel_sz);
ERROR: code indent should never use tabs
#499: FILE: ebpf/rss.bpf.skeleton.h:130:
+^Is->progs = (struct bpf_prog_skeleton *)calloc(s->prog_cnt, s->prog_skel_sz);$
ERROR: code indent should never use tabs
#500: FILE: ebpf/rss.bpf.skeleton.h:131:
+^Iif (!s->progs)$
ERROR: braces {} are necessary for all arms of this statement #500: FILE: ebpf/rss.bpf.skeleton.h:131:
+ if (!s->progs)
[...]
ERROR: code indent should never use tabs
#501: FILE: ebpf/rss.bpf.skeleton.h:132:
+^I^Igoto err;$
ERROR: code indent should never use tabs
#503: FILE: ebpf/rss.bpf.skeleton.h:134:
+^Is->progs[0].name = "tun_rss_steering_prog";$
ERROR: code indent should never use tabs
#504: FILE: ebpf/rss.bpf.skeleton.h:135:
+^Is->progs[0].prog = &obj->progs.tun_rss_steering_prog;$
ERROR: code indent should never use tabs
#505: FILE: ebpf/rss.bpf.skeleton.h:136:
+^Is->progs[0].link = &obj->links.tun_rss_steering_prog;$
ERROR: code indent should never use tabs
#507: FILE: ebpf/rss.bpf.skeleton.h:138:
+^Is->data_sz = 7088;$
ERROR: code indent should never use tabs
#508: FILE: ebpf/rss.bpf.skeleton.h:139:
+^Is->data = (void *)"\$
ERROR: code indent should never use tabs
#760: FILE: ebpf/rss.bpf.skeleton.h:391:
+^Ireturn 0;$
ERROR: code indent should never use tabs
#762: FILE: ebpf/rss.bpf.skeleton.h:393:
+^Ibpf_object__destroy_skeleton(s);$
ERROR: code indent should never use tabs
#763: FILE: ebpf/rss.bpf.skeleton.h:394:
+^Ireturn -1;$
total: 85 errors, 3 warnings, 756 lines checked
Patch 4/6 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
5/6 Checking commit 5829b35f89fc (virtio-net: Added eBPF RSS to virtio-net.)
WARNING: line over 80 characters
#192: FILE: hw/net/virtio-net.c:2868:
+ warn_report("Can't post-load eBPF RSS - fallback to software RSS");
total: 0 errors, 1 warnings, 223 lines checked
Patch 5/6 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
6/6 Checking commit 32a7d313e818 (docs: Added eBPF documentation.)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #33:
new file mode 100644
total: 0 errors, 1 warnings, 139 lines checked
Patch 6/6 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
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 eBPF array file initially generated by bpftool. 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 6/6.
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 4 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.
Looks good overall. I think a formal series could be posted for the next version.
Please see comments in the patch and I think we need to add a migration blocker if RSS is supported by virtio-net. (And implement migration in the future).
Thanks
Quoted 71 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.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.Changes since v2:
* using bpftool for eBPF skeleton generation.
*ebpf_rssis refactored to use skeleton generated by bpftool.
* added/adjasted license in comment sections and in eBPF file.
*rss.bpf.cand Makefile.ebpf moved to the tool/ebpf folder.
* virtio-net eBPF rss refactored. Now eBPF initialized duringrealize().Andrew (6):
net/tap: Added TUNSETSTEERINGEBPF code.
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 documentation.MAINTAINERS | 8 + configure | 33 +++ docs/ebpf_rss.rst | 125 ++++++++ ebpf/ebpf_rss-stub.c | 40 +++ ebpf/ebpf_rss.c | 165 +++++++++++ ebpf/ebpf_rss.h | 44 +++ ebpf/meson.build | 1 + ebpf/rss.bpf.skeleton.h | 397 ++++++++++++++++++++++++++ ebpf/trace-events | 4 + ebpf/trace.h | 2 + hw/net/vhost_net.c | 2 + hw/net/virtio-net.c | 125 +++++++- include/hw/virtio/virtio-net.h | 4 + include/net/net.h | 2 + meson.build | 13 + 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 + tools/ebpf/Makefile.ebpf | 33 +++ tools/ebpf/rss.bpf.c | 505 +++++++++++++++++++++++++++++++++ 25 files changed, 1540 insertions(+), 4 deletions(-)create mode 100644
docs/ebpf_rss.rst
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.skeleton.h
create mode 100644 ebpf/trace-events
create mode 100644ebpf/trace.h
create mode 100755tools/ebpf/Makefile.ebpf
create mode 100644tools/ebpf/rss.bpf.c