Skip to contentSkip to conversation

eBPF RSS support for virtio-net

PATCH Superseded Andrew Melnychenko 5 participants 15 messages Mar 25, 2021 – May 17, 2021

Subsystems (2)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v5 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.
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/7.

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.
* IPv6 extensions still in progress.

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().

Changes since v3:
* rebased to last master.
* fixed issue with failed build without libbpf.
* fixed ebpf loading without rss option.
* refactored labels in ebpf_rss.c

Changes since v4:
* refactored configure/meson script.
* added checks for load_bytes in ebpf.
* documentation added to the index.
* refactored Makefile and rss.bpf.c.
* rebased to last master.

Andrew (7):
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: Added eBPF maintainers information.

 MAINTAINERS                    |   8 +
 configure                      |   8 +-
 docs/devel/ebpf_rss.rst        | 125 ++++++++
 docs/devel/index.rst           |   1 +
 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        | 423 +++++++++++++++++++++++++
 ebpf/trace-events              |   4 +
 ebpf/trace.h                   |   2 +
 hw/net/vhost_net.c             |   3 +
 hw/net/virtio-net.c            | 115 ++++++-
 include/hw/virtio/virtio-net.h |   4 +
 include/net/net.h              |   2 +
 meson.build                    |   9 +
 meson_options.txt              |   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 +
 net/vhost-vdpa.c               |   2 +
 tools/ebpf/Makefile.ebpf       |  22 ++
 tools/ebpf/rss.bpf.c           | 552 +++++++++++++++++++++++++++++++++
 27 files changed, 1567 insertions(+), 4 deletions(-)
 create mode 100644 docs/devel/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.31.0
#1 lore raw

PATCH v5 1/7 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
index 2f36d100fc..1d06fe0de6 100644
@@ -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.31.0
#2 lore raw

PATCH v5 2/7 net: Added SetSteeringEBPF method for NetClientState.

In reply to Andrew Melnychenko

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-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
index a02949f6db..fc617b2f8c 100644
@@ -63,6 +63,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;
@@ -84,6 +85,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
index 77aaf674b1..4f64f31e98 100644
@@ -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
index b0635e9e32..9584769740 100644
@@ -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
index 0475a58207..d85224242b 100644
@@ -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
index de525a2e69..a0fa25804b 100644
@@ -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
index 12a08d54fe..ea65ed9e19 100644
@@ -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
index 225a49ea48..547f8a5a28 100644
@@ -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.31.0
#3 lore raw

PATCH v5 3/7 ebpf: Added eBPF RSS program.

In reply to Andrew Melnychenko

From: 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 |  22 ++
 tools/ebpf/rss.bpf.c     | 552 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 574 insertions(+)
 create mode 100755 tools/ebpf/Makefile.ebpf
 create mode 100644 tools/ebpf/rss.bpf.c
tools/ebpf/Makefile.ebpf new file +22 -0
new file mode 100755
index 0000000000..45b5551fc7
@@ -0,0 +1,22 @@
+OBJS = rss.bpf.o
+
+LLC ?= llc
+CLANG ?= clang
+INC_FLAGS = `$(CLANG) -print-file-name=include`
+EXTRA_CFLAGS ?= -O2 -emit-llvm -fno-stack-protector
+
+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 +552 -0

552 lines not on this page · raw message

Signature · 1 line
2.31.0
#4 lore raw

PATCH v5 4/7 ebpf: Added eBPF RSS loader.

In reply to 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.

---
 configure               |   8 +-
 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 | 423 ++++++++++++++++++++++++++++++++++++++++
 ebpf/trace-events       |   4 +
 ebpf/trace.h            |   2 +
 meson.build             |   9 +
 meson_options.txt       |   2 +
 10 files changed, 697 insertions(+), 1 deletion(-)
 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 +7 -1
index f7d022a5db..23e628f6c3 100755
@@ -348,6 +348,7 @@ vhost_vsock="$default_feature"
 vhost_user="no"
 vhost_user_blk_server="auto"
 vhost_user_fs="$default_feature"
+bpf="auto"
 kvm="auto"
 hax="auto"
 hvf="auto"
@@ -1227,6 +1228,10 @@ for opt do
   ;;
   --enable-membarrier) membarrier="yes"
   ;;
+  --disable-bpf) bpf="disabled"
+  ;;
+  --enable-bpf) bpf="enabled"
+  ;;
   --disable-blobs) blobs="false"
   ;;
   --with-pkgversion=*) pkgversion="$optarg"
@@ -1860,6 +1865,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
@@ -6424,7 +6430,7 @@ NINJA=$ninja $meson setup \
         -Dattr=$attr -Ddefault_devices=$default_devices \
         -Ddocs=$docs -Dsphinx_build=$sphinx_build -Dinstall_blobs=$blobs \
         -Dvhost_user_blk_server=$vhost_user_blk_server -Dmultiprocess=$multiprocess \
-        -Dfuse=$fuse -Dfuse_lseek=$fuse_lseek -Dguest_agent_msi=$guest_agent_msi \
+        -Dfuse=$fuse -Dfuse_lseek=$fuse_lseek -Dguest_agent_msi=$guest_agent_msi -Dbpf=$bpf\
         $(if test "$default_features" = no; then echo "-Dauto_features=disabled"; fi) \
 	-Dtcg_interpreter=$tcg_interpreter \
         $cross_arg \
ebpf/ebpf_rss-stub.c new file +40 -0
new file mode 100644
index 0000000000..e71e229190
@@ -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
new file mode 100644
index 0000000000..9cd0635370
@@ -0,0 +1 @@
+common_ss.add(when: libbpf, if_true: files('ebpf_rss.c'), if_false: files('ebpf_rss-stub.c'))
ebpf/rss.bpf.skeleton.h new file +423 -0

423 lines not on this page · raw message

ebpf/trace-events new file +4 -0
new file mode 100644
index 0000000000..411b1e2be3
@@ -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
new file mode 100644
index 0000000000..ad570e6691
@@ -0,0 +1,2 @@
+#include "trace/trace-ebpf.h"
+
meson.build +9 -0
index a7d2dd429d..bc97d93338 100644
@@ -1016,6 +1016,9 @@ if not get_option('fuse_lseek').disabled()
   endif
 endif
 
+# libbpf
+libbpf = dependency('libbpf', required: get_option('bpf'))
+
 if get_option('cfi')
   cfi_flags=[]
   # Check for dependency on LTO
@@ -1115,6 +1118,7 @@ endif
 config_host_data.set('CONFIG_GTK', gtk.found())
 config_host_data.set('CONFIG_LIBATTR', have_old_libattr)
 config_host_data.set('CONFIG_LIBCAP_NG', libcap_ng.found())
+config_host_data.set('CONFIG_EBPF', libbpf.found())
 config_host_data.set('CONFIG_LIBISCSI', libiscsi.found())
 config_host_data.set('CONFIG_LIBNFS', libnfs.found())
 config_host_data.set('CONFIG_RBD', rbd.found())
@@ -1785,6 +1789,7 @@ if have_system
     'backends',
     'backends/tpm',
     'chardev',
+    'ebpf',
     'hw/9pfs',
     'hw/acpi',
     'hw/adc',
@@ -1957,6 +1962,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)
@@ -2661,6 +2669,7 @@ summary_info += {'RDMA support':      config_host.has_key('CONFIG_RDMA')}
 summary_info += {'PVRDMA support':    config_host.has_key('CONFIG_PVRDMA')}
 summary_info += {'fdt support':       fdt_opt == 'disabled' ? false : fdt_opt}
 summary_info += {'libcap-ng support': libcap_ng.found()}
+summary_info += {'bpf support': libbpf.found()}
 # TODO: add back protocol and server version
 summary_info += {'spice support':     config_host.has_key('CONFIG_SPICE')}
 summary_info += {'rbd support':       rbd.found()}
meson_options.txt +2 -0
index 9734019995..58bc80ecfb 100644
@@ -56,6 +56,8 @@ option('bzip2', type : 'feature', value : 'auto',
        description: 'bzip2 support for DMG images')
 option('cap_ng', type : 'feature', value : 'auto',
        description: 'cap_ng support')
+option('bpf', type : 'feature', value : 'auto',
+        description: 'eBPF support')
 option('cocoa', type : 'feature', value : 'auto',
        description: 'Cocoa user interface (macOS only)')
 option('curl', type : 'feature', value : 'auto',
Signature · 1 line
2.31.0
#5 lore raw

PATCH v5 5/7 virtio-net: Added eBPF RSS to virtio-net.

In reply to 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.

---
 hw/net/vhost_net.c             |   3 +
 hw/net/virtio-net.c            | 115 ++++++++++++++++++++++++++++++++-
 include/hw/virtio/virtio-net.h |   4 ++
 net/vhost-vdpa.c               |   2 +
 4 files changed, 121 insertions(+), 3 deletions(-)
hw/net/vhost_net.c +3 -0
index 24d555e764..44c1ed92dc 100644
@@ -45,6 +45,7 @@ static const int kernel_feature_bits[] = {
     VIRTIO_NET_F_MTU,
     VIRTIO_F_IOMMU_PLATFORM,
     VIRTIO_F_RING_PACKED,
+    VIRTIO_NET_F_HASH_REPORT,
     VHOST_INVALID_FEATURE_BIT
 };
 
@@ -71,6 +72,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 +112 -3

169 lines not on this page · raw message

include/hw/virtio/virtio-net.h +4 -0
index 7e96d193aa..824a69c23f 100644
@@ -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
index 5a28bbcd7b..b5bff4032c 100644
@@ -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.31.0
#6 lore raw

PATCH v5 6/7 docs: Added eBPF documentation.

In reply to Andrew Melnychenko

From: Andrew <[email protected]>

---
 docs/devel/ebpf_rss.rst | 125 ++++++++++++++++++++++++++++++++++++++++
 docs/devel/index.rst    |   1 +
 2 files changed, 126 insertions(+)
 create mode 100644 docs/devel/ebpf_rss.rst
docs/devel/ebpf_rss.rst new file +125 -0
new file mode 100644
index 0000000000..e00962577a
@@ -0,0 +1,125 @@
+===========================
+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/rss.bpf.skeleton.h generated by bpftool.
+So the program is part of the qemu binary.
+Initially, the eBPF program was compiled by clang and source code located at tools/ebpf/rss.bpf.c.
+Prerequisites to recompile the eBPF program (regenerate ebpf/rss.bpf.skeleton.h):
+
+        llvm, clang, kernel source tree, bpftool
+        Adjust Makefile.ebpf to reflect the location of the kernel source tree
+
+        $ cd tools/ebpf
+        $ make -f Makefile.ebpf
+
+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+.
+
+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 the rss.bpf.skeleton.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.
docs/devel/index.rst +1 -0
index 7c424ea6d7..dd732a627c 100644
@@ -40,3 +40,4 @@ Contents:
    qom
    block-coroutine-wrapper
    multi-process
+   ebpf_rss
Signature · 1 line
2.31.0
#7 lore raw

PATCH v5 7/7 MAINTAINERS: Added eBPF maintainers information.

In reply to Andrew Melnychenko

From: Andrew <[email protected]>

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 5e4be6b667..0f74778ed7 100644
@@ -3304,6 +3304,14 @@ F: include/hw/remote/proxy-memory-listener.h
 F: hw/remote/iohub.c
 F: include/hw/remote/iohub.h
 
+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, general continuous integration
Signature · 1 line
2.31.0
#8 lore raw
In reply to Andrew Melnychenko
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: [PATCH v5 0/7] 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 Switched to a new branch 'test'
ad293ca MAINTAINERS: Added eBPF maintainers information. 57b0f9a docs: Added eBPF documentation.
043dbde virtio-net: Added eBPF RSS to virtio-net. aa652c0 ebpf: Added eBPF RSS loader.
9f24275 ebpf: Added eBPF RSS program.
6a33681 net: Added SetSteeringEBPF method for NetClientState. ad82041 net/tap: Added TUNSETSTEERINGEBPF code.

=== OUTPUT BEGIN ===
1/7 Checking commit ad820417b22d (net/tap: Added TUNSETSTEERINGEBPF code.)
2/7 Checking commit 6a33681ca4bf (net: Added SetSteeringEBPF method for NetClientState.) 3/7 Checking commit 9f24275a1eef (ebpf: Added eBPF RSS program.)
Use of uninitialized value $acpi_testexpected in string eq at ./scripts/checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#22:
new file mode 100755

WARNING: line over 80 characters
#210: FILE: tools/ebpf/rss.bpf.c:156:
+ * According to https://www.iana.org/assignments/ipv6-parameters/ipv6-parameters.xhtml

WARNING: line over 80 characters
#213: FILE: tools/ebpf/rss.bpf.c:159:
+ * Need to choose reasonable amount of maximum extensions/options we may check to find

ERROR: braces {} are necessary for all arms of this statement #235: FILE: tools/ebpf/rss.bpf.c:181:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #243: FILE: tools/ebpf/rss.bpf.c:189:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #254: FILE: tools/ebpf/rss.bpf.c:200:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #271: FILE: tools/ebpf/rss.bpf.c:217:
+ if (err)
[...]

WARNING: line over 80 characters
#283: FILE: tools/ebpf/rss.bpf.c:229:
+ *l4_offset + opt_offset + offsetof(struct ipv6_destopt_hao, addr),

ERROR: braces {} are necessary for all arms of this statement #286: FILE: tools/ebpf/rss.bpf.c:232:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #316: FILE: tools/ebpf/rss.bpf.c:262:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #330: FILE: tools/ebpf/rss.bpf.c:276:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #359: FILE: tools/ebpf/rss.bpf.c:305:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #373: FILE: tools/ebpf/rss.bpf.c:319:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #383: FILE: tools/ebpf/rss.bpf.c:329:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #394: FILE: tools/ebpf/rss.bpf.c:340:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #405: FILE: tools/ebpf/rss.bpf.c:351:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #429: FILE: tools/ebpf/rss.bpf.c:375:
+ if (err)
[...]

total: 13 errors, 4 warnings, 574 lines checked

Patch 3/7 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

4/7 Checking commit aa652c04e4a0 (ebpf: Added eBPF RSS loader.)
Use of uninitialized value $acpi_testexpected in string eq at ./scripts/checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#71:
new file mode 100644

WARNING: architecture specific defines should be avoided #353: FILE: ebpf/rss.bpf.skeleton.h:4:
+#ifndef __RSS_BPF_SKEL_H__

ERROR: code indent should never use tabs
#360: FILE: ebpf/rss.bpf.skeleton.h:11:
+^Istruct bpf_object_skeleton *skeleton;$

ERROR: code indent should never use tabs
#361: FILE: ebpf/rss.bpf.skeleton.h:12:
+^Istruct bpf_object *obj;$

ERROR: code indent should never use tabs
#362: FILE: ebpf/rss.bpf.skeleton.h:13:
+^Istruct {$

ERROR: code indent should never use tabs
#363: FILE: ebpf/rss.bpf.skeleton.h:14:
+^I^Istruct bpf_map *tap_rss_map_configurations;$

ERROR: code indent should never use tabs #364: FILE: ebpf/rss.bpf.skeleton.h:15:
+^I^Istruct bpf_map *tap_rss_map_indirection_table;$

ERROR: code indent should never use tabs
#365: FILE: ebpf/rss.bpf.skeleton.h:16:
+^I^Istruct bpf_map *tap_rss_map_toeplitz_key;$

ERROR: code indent should never use tabs
#366: FILE: ebpf/rss.bpf.skeleton.h:17:
+^I} maps;$

ERROR: code indent should never use tabs
#367: FILE: ebpf/rss.bpf.skeleton.h:18:
+^Istruct {$

ERROR: code indent should never use tabs
#368: FILE: ebpf/rss.bpf.skeleton.h:19:
+^I^Istruct bpf_program *tun_rss_steering_prog;$

ERROR: code indent should never use tabs
#369: FILE: ebpf/rss.bpf.skeleton.h:20:
+^I} progs;$

ERROR: code indent should never use tabs
#370: FILE: ebpf/rss.bpf.skeleton.h:21:
+^Istruct {$

ERROR: code indent should never use tabs
#371: FILE: ebpf/rss.bpf.skeleton.h:22:
+^I^Istruct bpf_link *tun_rss_steering_prog;$

ERROR: code indent should never use tabs
#372: FILE: ebpf/rss.bpf.skeleton.h:23:
+^I} links;$

ERROR: code indent should never use tabs
#378: FILE: ebpf/rss.bpf.skeleton.h:29:
+^Iif (!obj)$

ERROR: braces {} are necessary for all arms of this statement #378: FILE: ebpf/rss.bpf.skeleton.h:29:
+ if (!obj)
[...]

ERROR: code indent should never use tabs
#379: FILE: ebpf/rss.bpf.skeleton.h:30:
+^I^Ireturn;$

ERROR: code indent should never use tabs
#380: FILE: ebpf/rss.bpf.skeleton.h:31:
+^Iif (obj->skeleton)$

ERROR: braces {} are necessary for all arms of this statement #380: FILE: ebpf/rss.bpf.skeleton.h:31:
+ if (obj->skeleton)
[...]

ERROR: code indent should never use tabs #381: FILE: ebpf/rss.bpf.skeleton.h:32:
+^I^Ibpf_object__destroy_skeleton(obj->skeleton);$

ERROR: code indent should never use tabs
#382: FILE: ebpf/rss.bpf.skeleton.h:33:
+^Ifree(obj);$

ERROR: code indent should never use tabs
#391: FILE: ebpf/rss.bpf.skeleton.h:42:
+^Istruct rss_bpf *obj;$

ERROR: code indent should never use tabs #393: FILE: ebpf/rss.bpf.skeleton.h:44:
+^Iobj = (struct rss_bpf *)calloc(1, sizeof(*obj));$

ERROR: code indent should never use tabs
#394: FILE: ebpf/rss.bpf.skeleton.h:45:
+^Iif (!obj)$

ERROR: braces {} are necessary for all arms of this statement #394: FILE: ebpf/rss.bpf.skeleton.h:45:
+ if (!obj)
[...]

ERROR: code indent should never use tabs
#395: FILE: ebpf/rss.bpf.skeleton.h:46:
+^I^Ireturn NULL;$

ERROR: code indent should never use tabs
#396: FILE: ebpf/rss.bpf.skeleton.h:47:
+^Iif (rss_bpf__create_skeleton(obj))$

ERROR: braces {} are necessary for all arms of this statement #396: FILE: ebpf/rss.bpf.skeleton.h:47:
+ if (rss_bpf__create_skeleton(obj))
[...]

ERROR: code indent should never use tabs
#397: FILE: ebpf/rss.bpf.skeleton.h:48:
+^I^Igoto err;$

ERROR: code indent should never use tabs
#398: 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 #398: FILE: ebpf/rss.bpf.skeleton.h:49:
+ if (bpf_object__open_skeleton(obj->skeleton, opts))
[...]

ERROR: code indent should never use tabs
#399: FILE: ebpf/rss.bpf.skeleton.h:50:
+^I^Igoto err;$

ERROR: code indent should never use tabs
#401: FILE: ebpf/rss.bpf.skeleton.h:52:
+^Ireturn obj;$

ERROR: code indent should never use tabs
#403: FILE: ebpf/rss.bpf.skeleton.h:54:
+^Irss_bpf__destroy(obj);$

ERROR: code indent should never use tabs
#404: FILE: ebpf/rss.bpf.skeleton.h:55:
+^Ireturn NULL;$

ERROR: code indent should never use tabs
#410: FILE: ebpf/rss.bpf.skeleton.h:61:
+^Ireturn rss_bpf__open_opts(NULL);$

ERROR: code indent should never use tabs #416: FILE: ebpf/rss.bpf.skeleton.h:67:
+^Ireturn bpf_object__load_skeleton(obj->skeleton);$

ERROR: code indent should never use tabs
#422: FILE: ebpf/rss.bpf.skeleton.h:73:
+^Istruct rss_bpf *obj;$

ERROR: code indent should never use tabs
#424: FILE: ebpf/rss.bpf.skeleton.h:75:
+^Iobj = rss_bpf__open();$

ERROR: code indent should never use tabs
#425: FILE: ebpf/rss.bpf.skeleton.h:76:
+^Iif (!obj)$

ERROR: braces {} are necessary for all arms of this statement #425: FILE: ebpf/rss.bpf.skeleton.h:76:
+ if (!obj)
[...]

ERROR: code indent should never use tabs
#426: FILE: ebpf/rss.bpf.skeleton.h:77:
+^I^Ireturn NULL;$

ERROR: code indent should never use tabs
#427: FILE: ebpf/rss.bpf.skeleton.h:78:
+^Iif (rss_bpf__load(obj)) {$

ERROR: code indent should never use tabs
#428: FILE: ebpf/rss.bpf.skeleton.h:79:
+^I^Irss_bpf__destroy(obj);$

ERROR: code indent should never use tabs
#429: FILE: ebpf/rss.bpf.skeleton.h:80:
+^I^Ireturn NULL;$

ERROR: code indent should never use tabs
#430: FILE: ebpf/rss.bpf.skeleton.h:81:
+^I}$

ERROR: code indent should never use tabs
#431: FILE: ebpf/rss.bpf.skeleton.h:82:
+^Ireturn obj;$

ERROR: code indent should never use tabs #437: FILE: ebpf/rss.bpf.skeleton.h:88:
+^Ireturn bpf_object__attach_skeleton(obj->skeleton);$

ERROR: code indent should never use tabs #443: FILE: ebpf/rss.bpf.skeleton.h:94:
+^Ireturn bpf_object__detach_skeleton(obj->skeleton);$

ERROR: code indent should never use tabs
#449: FILE: ebpf/rss.bpf.skeleton.h:100:
+^Istruct bpf_object_skeleton *s;$

ERROR: code indent should never use tabs
#451: FILE: ebpf/rss.bpf.skeleton.h:102:
+^Is = (struct bpf_object_skeleton *)calloc(1, sizeof(*s));$

ERROR: code indent should never use tabs
#452: FILE: ebpf/rss.bpf.skeleton.h:103:
+^Iif (!s)$

ERROR: braces {} are necessary for all arms of this statement #452: FILE: ebpf/rss.bpf.skeleton.h:103:
+ if (!s)
[...]

ERROR: code indent should never use tabs
#453: FILE: ebpf/rss.bpf.skeleton.h:104:
+^I^Ireturn -1;$

ERROR: code indent should never use tabs
#454: FILE: ebpf/rss.bpf.skeleton.h:105:
+^Iobj->skeleton = s;$

ERROR: code indent should never use tabs
#456: FILE: ebpf/rss.bpf.skeleton.h:107:
+^Is->sz = sizeof(*s);$

ERROR: code indent should never use tabs
#457: FILE: ebpf/rss.bpf.skeleton.h:108:
+^Is->name = "rss_bpf";$

ERROR: code indent should never use tabs
#458: FILE: ebpf/rss.bpf.skeleton.h:109:
+^Is->obj = &obj->obj;$

ERROR: code indent should never use tabs
#460: FILE: ebpf/rss.bpf.skeleton.h:111:
+^I/* maps */$

ERROR: code indent should never use tabs
#461: FILE: ebpf/rss.bpf.skeleton.h:112:
+^Is->map_cnt = 3;$

ERROR: code indent should never use tabs
#462: FILE: ebpf/rss.bpf.skeleton.h:113:
+^Is->map_skel_sz = sizeof(*s->maps);$

ERROR: code indent should never use tabs
#463: 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
#464: FILE: ebpf/rss.bpf.skeleton.h:115:
+^Iif (!s->maps)$

ERROR: braces {} are necessary for all arms of this statement #464: FILE: ebpf/rss.bpf.skeleton.h:115:
+ if (!s->maps)
[...]

ERROR: code indent should never use tabs
#465: FILE: ebpf/rss.bpf.skeleton.h:116:
+^I^Igoto err;$

ERROR: code indent should never use tabs #467: FILE: ebpf/rss.bpf.skeleton.h:118:
+^Is->maps[0].name = "tap_rss_map_configurations";$

ERROR: code indent should never use tabs
#468: FILE: ebpf/rss.bpf.skeleton.h:119:
+^Is->maps[0].map = &obj->maps.tap_rss_map_configurations;$

ERROR: code indent should never use tabs #470: FILE: ebpf/rss.bpf.skeleton.h:121:
+^Is->maps[1].name = "tap_rss_map_indirection_table";$

ERROR: code indent should never use tabs
#471: 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
#473: FILE: ebpf/rss.bpf.skeleton.h:124:
+^Is->maps[2].name = "tap_rss_map_toeplitz_key";$

ERROR: code indent should never use tabs
#474: 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
#476: FILE: ebpf/rss.bpf.skeleton.h:127:
+^I/* programs */$

ERROR: code indent should never use tabs
#477: FILE: ebpf/rss.bpf.skeleton.h:128:
+^Is->prog_cnt = 1;$

ERROR: code indent should never use tabs
#478: FILE: ebpf/rss.bpf.skeleton.h:129:
+^Is->prog_skel_sz = sizeof(*s->progs);$

WARNING: line over 80 characters
#479: 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
#479: 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
#480: FILE: ebpf/rss.bpf.skeleton.h:131:
+^Iif (!s->progs)$

ERROR: braces {} are necessary for all arms of this statement #480: FILE: ebpf/rss.bpf.skeleton.h:131:
+ if (!s->progs)
[...]

ERROR: code indent should never use tabs
#481: FILE: ebpf/rss.bpf.skeleton.h:132:
+^I^Igoto err;$

ERROR: code indent should never use tabs
#483: FILE: ebpf/rss.bpf.skeleton.h:134:
+^Is->progs[0].name = "tun_rss_steering_prog";$

ERROR: code indent should never use tabs
#484: FILE: ebpf/rss.bpf.skeleton.h:135:
+^Is->progs[0].prog = &obj->progs.tun_rss_steering_prog;$

ERROR: code indent should never use tabs
#485: FILE: ebpf/rss.bpf.skeleton.h:136:
+^Is->progs[0].link = &obj->links.tun_rss_steering_prog;$

ERROR: code indent should never use tabs
#487: FILE: ebpf/rss.bpf.skeleton.h:138:
+^Is->data_sz = 7864;$

ERROR: code indent should never use tabs
#488: FILE: ebpf/rss.bpf.skeleton.h:139:
+^Is->data = (void *)"\$

ERROR: code indent should never use tabs
#766: FILE: ebpf/rss.bpf.skeleton.h:417:
+^Ireturn 0;$

ERROR: code indent should never use tabs
#768: FILE: ebpf/rss.bpf.skeleton.h:419:
+^Ibpf_object__destroy_skeleton(s);$

ERROR: code indent should never use tabs
#769: FILE: ebpf/rss.bpf.skeleton.h:420:
+^Ireturn -1;$

total: 85 errors, 3 warnings, 758 lines checked

Patch 4/7 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

5/7 Checking commit 043dbde56379 (virtio-net: Added eBPF RSS to virtio-net.)
WARNING: line over 80 characters
#185: FILE: hw/net/virtio-net.c:2868:
+ warn_report("Can't post-load eBPF RSS - fallback to software RSS");

total: 0 errors, 1 warnings, 214 lines checked

Patch 5/7 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
6/7 Checking commit 57b0f9a94036 (docs: Added eBPF documentation.)
Use of uninitialized value $acpi_testexpected in string eq at ./scripts/checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#16:
new file mode 100644

total: 0 errors, 1 warnings, 129 lines checked

Patch 6/7 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
7/7 Checking commit ad293ca1c684 (MAINTAINERS: Added eBPF maintainers information.) === 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]

#9 lore raw

The skeleton is generated file. Style issues with rss.bpf.c would be fixed in upcoming patches.

Quoted 541 lines · On Thu, Mar 25, 2021 at 5:58 PM <[email protected]> wrote:

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: [PATCH v5 0/7] 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 Switched to a new branch 'test'
ad293ca MAINTAINERS: Added eBPF maintainers information. 57b0f9a docs: Added eBPF documentation.
043dbde virtio-net: Added eBPF RSS to virtio-net. aa652c0 ebpf: Added eBPF RSS loader.
9f24275 ebpf: Added eBPF RSS program.
6a33681 net: Added SetSteeringEBPF method for NetClientState. ad82041 net/tap: Added TUNSETSTEERINGEBPF code.

=== OUTPUT BEGIN ===
1/7 Checking commit ad820417b22d (net/tap: Added TUNSETSTEERINGEBPF code.) 2/7 Checking commit 6a33681ca4bf (net: Added SetSteeringEBPF method for NetClientState.)
3/7 Checking commit 9f24275a1eef (ebpf: Added eBPF RSS program.) Use of uninitialized value $acpi_testexpected in string eq at ./scripts/ checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #22:
new file mode 100755

WARNING: line over 80 characters
#210: FILE: tools/ebpf/rss.bpf.c:156:
+ * According to
https://www.iana.org/assignments/ipv6-parameters/ipv6-parameters.xhtml

WARNING: line over 80 characters
#213: FILE: tools/ebpf/rss.bpf.c:159:
+ * Need to choose reasonable amount of maximum extensions/options we may check to find

ERROR: braces {} are necessary for all arms of this statement #235: FILE: tools/ebpf/rss.bpf.c:181:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #243: FILE: tools/ebpf/rss.bpf.c:189:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #254: FILE: tools/ebpf/rss.bpf.c:200:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #271: FILE: tools/ebpf/rss.bpf.c:217:
+ if (err)
[...]

WARNING: line over 80 characters
#283: FILE: tools/ebpf/rss.bpf.c:229:
+ *l4_offset + opt_offset + offsetof(struct
ipv6_destopt_hao, addr),

ERROR: braces {} are necessary for all arms of this statement #286: FILE: tools/ebpf/rss.bpf.c:232:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #316: FILE: tools/ebpf/rss.bpf.c:262:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #330: FILE: tools/ebpf/rss.bpf.c:276:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #359: FILE: tools/ebpf/rss.bpf.c:305:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #373: FILE: tools/ebpf/rss.bpf.c:319:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #383: FILE: tools/ebpf/rss.bpf.c:329:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #394: FILE: tools/ebpf/rss.bpf.c:340:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #405: FILE: tools/ebpf/rss.bpf.c:351:
+ if (err)
[...]

ERROR: braces {} are necessary for all arms of this statement #429: FILE: tools/ebpf/rss.bpf.c:375:
+ if (err)
[...]

total: 13 errors, 4 warnings, 574 lines checked

Patch 3/7 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

4/7 Checking commit aa652c04e4a0 (ebpf: Added eBPF RSS loader.) Use of uninitialized value $acpi_testexpected in string eq at ./scripts/ checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #71:
new file mode 100644

WARNING: architecture specific defines should be avoided #353: FILE: ebpf/rss.bpf.skeleton.h:4:
+#ifndef __RSS_BPF_SKEL_H__

ERROR: code indent should never use tabs
#360: FILE: ebpf/rss.bpf.skeleton.h:11:
+^Istruct bpf_object_skeleton *skeleton;$

ERROR: code indent should never use tabs
#361: FILE: ebpf/rss.bpf.skeleton.h:12:
+^Istruct bpf_object *obj;$

ERROR: code indent should never use tabs
#362: FILE: ebpf/rss.bpf.skeleton.h:13:
+^Istruct {$

ERROR: code indent should never use tabs
#363: FILE: ebpf/rss.bpf.skeleton.h:14:
+^I^Istruct bpf_map *tap_rss_map_configurations;$

ERROR: code indent should never use tabs #364: FILE: ebpf/rss.bpf.skeleton.h:15:
+^I^Istruct bpf_map *tap_rss_map_indirection_table;$

ERROR: code indent should never use tabs
#365: FILE: ebpf/rss.bpf.skeleton.h:16:
+^I^Istruct bpf_map *tap_rss_map_toeplitz_key;$

ERROR: code indent should never use tabs
#366: FILE: ebpf/rss.bpf.skeleton.h:17:
+^I} maps;$

ERROR: code indent should never use tabs
#367: FILE: ebpf/rss.bpf.skeleton.h:18:
+^Istruct {$

ERROR: code indent should never use tabs
#368: FILE: ebpf/rss.bpf.skeleton.h:19:
+^I^Istruct bpf_program *tun_rss_steering_prog;$

ERROR: code indent should never use tabs
#369: FILE: ebpf/rss.bpf.skeleton.h:20:
+^I} progs;$

ERROR: code indent should never use tabs
#370: FILE: ebpf/rss.bpf.skeleton.h:21:
+^Istruct {$

ERROR: code indent should never use tabs
#371: FILE: ebpf/rss.bpf.skeleton.h:22:
+^I^Istruct bpf_link *tun_rss_steering_prog;$

ERROR: code indent should never use tabs
#372: FILE: ebpf/rss.bpf.skeleton.h:23:
+^I} links;$

ERROR: code indent should never use tabs
#378: FILE: ebpf/rss.bpf.skeleton.h:29:
+^Iif (!obj)$

ERROR: braces {} are necessary for all arms of this statement #378: FILE: ebpf/rss.bpf.skeleton.h:29:
+ if (!obj)
[...]

ERROR: code indent should never use tabs
#379: FILE: ebpf/rss.bpf.skeleton.h:30:
+^I^Ireturn;$

ERROR: code indent should never use tabs
#380: FILE: ebpf/rss.bpf.skeleton.h:31:
+^Iif (obj->skeleton)$

ERROR: braces {} are necessary for all arms of this statement #380: FILE: ebpf/rss.bpf.skeleton.h:31:
+ if (obj->skeleton)
[...]

ERROR: code indent should never use tabs #381: FILE: ebpf/rss.bpf.skeleton.h:32:
+^I^Ibpf_object__destroy_skeleton(obj->skeleton);$

ERROR: code indent should never use tabs
#382: FILE: ebpf/rss.bpf.skeleton.h:33:
+^Ifree(obj);$

ERROR: code indent should never use tabs
#391: FILE: ebpf/rss.bpf.skeleton.h:42:
+^Istruct rss_bpf *obj;$

ERROR: code indent should never use tabs #393: FILE: ebpf/rss.bpf.skeleton.h:44:
+^Iobj = (struct rss_bpf *)calloc(1, sizeof(*obj));$

ERROR: code indent should never use tabs
#394: FILE: ebpf/rss.bpf.skeleton.h:45:
+^Iif (!obj)$

ERROR: braces {} are necessary for all arms of this statement #394: FILE: ebpf/rss.bpf.skeleton.h:45:
+ if (!obj)
[...]

ERROR: code indent should never use tabs
#395: FILE: ebpf/rss.bpf.skeleton.h:46:
+^I^Ireturn NULL;$

ERROR: code indent should never use tabs
#396: FILE: ebpf/rss.bpf.skeleton.h:47:
+^Iif (rss_bpf__create_skeleton(obj))$

ERROR: braces {} are necessary for all arms of this statement #396: FILE: ebpf/rss.bpf.skeleton.h:47:
+ if (rss_bpf__create_skeleton(obj))
[...]

ERROR: code indent should never use tabs
#397: FILE: ebpf/rss.bpf.skeleton.h:48:
+^I^Igoto err;$

ERROR: code indent should never use tabs
#398: 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 #398: FILE: ebpf/rss.bpf.skeleton.h:49:
+ if (bpf_object__open_skeleton(obj->skeleton, opts))
[...]

ERROR: code indent should never use tabs
#399: FILE: ebpf/rss.bpf.skeleton.h:50:
+^I^Igoto err;$

ERROR: code indent should never use tabs
#401: FILE: ebpf/rss.bpf.skeleton.h:52:
+^Ireturn obj;$

ERROR: code indent should never use tabs
#403: FILE: ebpf/rss.bpf.skeleton.h:54:
+^Irss_bpf__destroy(obj);$

ERROR: code indent should never use tabs
#404: FILE: ebpf/rss.bpf.skeleton.h:55:
+^Ireturn NULL;$

ERROR: code indent should never use tabs
#410: FILE: ebpf/rss.bpf.skeleton.h:61:
+^Ireturn rss_bpf__open_opts(NULL);$

ERROR: code indent should never use tabs #416: FILE: ebpf/rss.bpf.skeleton.h:67:
+^Ireturn bpf_object__load_skeleton(obj->skeleton);$

ERROR: code indent should never use tabs
#422: FILE: ebpf/rss.bpf.skeleton.h:73:
+^Istruct rss_bpf *obj;$

ERROR: code indent should never use tabs
#424: FILE: ebpf/rss.bpf.skeleton.h:75:
+^Iobj = rss_bpf__open();$

ERROR: code indent should never use tabs
#425: FILE: ebpf/rss.bpf.skeleton.h:76:
+^Iif (!obj)$

ERROR: braces {} are necessary for all arms of this statement #425: FILE: ebpf/rss.bpf.skeleton.h:76:
+ if (!obj)
[...]

ERROR: code indent should never use tabs
#426: FILE: ebpf/rss.bpf.skeleton.h:77:
+^I^Ireturn NULL;$

ERROR: code indent should never use tabs
#427: FILE: ebpf/rss.bpf.skeleton.h:78:
+^Iif (rss_bpf__load(obj)) {$

ERROR: code indent should never use tabs
#428: FILE: ebpf/rss.bpf.skeleton.h:79:
+^I^Irss_bpf__destroy(obj);$

ERROR: code indent should never use tabs
#429: FILE: ebpf/rss.bpf.skeleton.h:80:
+^I^Ireturn NULL;$

ERROR: code indent should never use tabs
#430: FILE: ebpf/rss.bpf.skeleton.h:81:
+^I}$

ERROR: code indent should never use tabs
#431: FILE: ebpf/rss.bpf.skeleton.h:82:
+^Ireturn obj;$

ERROR: code indent should never use tabs #437: FILE: ebpf/rss.bpf.skeleton.h:88:
+^Ireturn bpf_object__attach_skeleton(obj->skeleton);$

ERROR: code indent should never use tabs #443: FILE: ebpf/rss.bpf.skeleton.h:94:
+^Ireturn bpf_object__detach_skeleton(obj->skeleton);$

ERROR: code indent should never use tabs
#449: FILE: ebpf/rss.bpf.skeleton.h:100:
+^Istruct bpf_object_skeleton *s;$

ERROR: code indent should never use tabs
#451: FILE: ebpf/rss.bpf.skeleton.h:102:
+^Is = (struct bpf_object_skeleton *)calloc(1, sizeof(*s));$

ERROR: code indent should never use tabs
#452: FILE: ebpf/rss.bpf.skeleton.h:103:
+^Iif (!s)$

ERROR: braces {} are necessary for all arms of this statement #452: FILE: ebpf/rss.bpf.skeleton.h:103:
+ if (!s)
[...]

ERROR: code indent should never use tabs
#453: FILE: ebpf/rss.bpf.skeleton.h:104:
+^I^Ireturn -1;$

ERROR: code indent should never use tabs
#454: FILE: ebpf/rss.bpf.skeleton.h:105:
+^Iobj->skeleton = s;$

ERROR: code indent should never use tabs
#456: FILE: ebpf/rss.bpf.skeleton.h:107:
+^Is->sz = sizeof(*s);$

ERROR: code indent should never use tabs
#457: FILE: ebpf/rss.bpf.skeleton.h:108:
+^Is->name = "rss_bpf";$

ERROR: code indent should never use tabs
#458: FILE: ebpf/rss.bpf.skeleton.h:109:
+^Is->obj = &obj->obj;$

ERROR: code indent should never use tabs
#460: FILE: ebpf/rss.bpf.skeleton.h:111:
+^I/* maps */$

ERROR: code indent should never use tabs
#461: FILE: ebpf/rss.bpf.skeleton.h:112:
+^Is->map_cnt = 3;$

ERROR: code indent should never use tabs
#462: FILE: ebpf/rss.bpf.skeleton.h:113:
+^Is->map_skel_sz = sizeof(*s->maps);$

ERROR: code indent should never use tabs
#463: 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
#464: FILE: ebpf/rss.bpf.skeleton.h:115:
+^Iif (!s->maps)$

ERROR: braces {} are necessary for all arms of this statement #464: FILE: ebpf/rss.bpf.skeleton.h:115:
+ if (!s->maps)
[...]

ERROR: code indent should never use tabs
#465: FILE: ebpf/rss.bpf.skeleton.h:116:
+^I^Igoto err;$

ERROR: code indent should never use tabs #467: FILE: ebpf/rss.bpf.skeleton.h:118:
+^Is->maps[0].name = "tap_rss_map_configurations";$

ERROR: code indent should never use tabs
#468: FILE: ebpf/rss.bpf.skeleton.h:119:
+^Is->maps[0].map = &obj->maps.tap_rss_map_configurations;$

ERROR: code indent should never use tabs #470: FILE: ebpf/rss.bpf.skeleton.h:121:
+^Is->maps[1].name = "tap_rss_map_indirection_table";$

ERROR: code indent should never use tabs
#471: 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
#473: FILE: ebpf/rss.bpf.skeleton.h:124:
+^Is->maps[2].name = "tap_rss_map_toeplitz_key";$

ERROR: code indent should never use tabs
#474: 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
#476: FILE: ebpf/rss.bpf.skeleton.h:127:
+^I/* programs */$

ERROR: code indent should never use tabs
#477: FILE: ebpf/rss.bpf.skeleton.h:128:
+^Is->prog_cnt = 1;$

ERROR: code indent should never use tabs
#478: FILE: ebpf/rss.bpf.skeleton.h:129:
+^Is->prog_skel_sz = sizeof(*s->progs);$

WARNING: line over 80 characters
#479: 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
#479: 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
#480: FILE: ebpf/rss.bpf.skeleton.h:131:
+^Iif (!s->progs)$

ERROR: braces {} are necessary for all arms of this statement #480: FILE: ebpf/rss.bpf.skeleton.h:131:
+ if (!s->progs)
[...]

ERROR: code indent should never use tabs
#481: FILE: ebpf/rss.bpf.skeleton.h:132:
+^I^Igoto err;$

ERROR: code indent should never use tabs
#483: FILE: ebpf/rss.bpf.skeleton.h:134:
+^Is->progs[0].name = "tun_rss_steering_prog";$

ERROR: code indent should never use tabs
#484: FILE: ebpf/rss.bpf.skeleton.h:135:
+^Is->progs[0].prog = &obj->progs.tun_rss_steering_prog;$

ERROR: code indent should never use tabs
#485: FILE: ebpf/rss.bpf.skeleton.h:136:
+^Is->progs[0].link = &obj->links.tun_rss_steering_prog;$

ERROR: code indent should never use tabs
#487: FILE: ebpf/rss.bpf.skeleton.h:138:
+^Is->data_sz = 7864;$

ERROR: code indent should never use tabs
#488: FILE: ebpf/rss.bpf.skeleton.h:139:
+^Is->data = (void *)"\$

ERROR: code indent should never use tabs
#766: FILE: ebpf/rss.bpf.skeleton.h:417:
+^Ireturn 0;$

ERROR: code indent should never use tabs
#768: FILE: ebpf/rss.bpf.skeleton.h:419:
+^Ibpf_object__destroy_skeleton(s);$

ERROR: code indent should never use tabs
#769: FILE: ebpf/rss.bpf.skeleton.h:420:
+^Ireturn -1;$

total: 85 errors, 3 warnings, 758 lines checked

Patch 4/7 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

5/7 Checking commit 043dbde56379 (virtio-net: Added eBPF RSS to virtio-net.)
WARNING: line over 80 characters
#185: FILE: hw/net/virtio-net.c:2868:
+ warn_report("Can't post-load eBPF RSS - fallback to
software RSS");

total: 0 errors, 1 warnings, 214 lines checked

Patch 5/7 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
6/7 Checking commit 57b0f9a94036 (docs: Added eBPF documentation.) Use of uninitialized value $acpi_testexpected in string eq at ./scripts/ checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #16:
new file mode 100644

total: 0 errors, 1 warnings, 129 lines checked

Patch 6/7 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
7/7 Checking commit ad293ca1c684 (MAINTAINERS: Added eBPF maintainers information.)
=== 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]

#10 lore raw
In reply to Andrew Melnychenko
Quoted 21 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 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.
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.

Quoted 7 lines

Please also see the documentation in PATCH 6/7.

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.
* IPv6 extensions still in progress.

Hi Andrew:

The patch looks good at a glance. I tend to queue it for 6.1.

One issue is that, there's no easy way for testing it without a windows guest.

Do you have plan to extend Linux driver to support RSS (e.g via ethtool?).

Thanks

Quoted 79 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 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().

Changes since v3:
* rebased to last master.
* fixed issue with failed build without libbpf.
* fixed ebpf loading without rss option.
* refactored labels in ebpf_rss.c

Changes since v4:
* refactored configure/meson script.
* added checks for load_bytes in ebpf.
* documentation added to the index.
* refactored Makefile and rss.bpf.c.
* rebased to last master.

Andrew (7):
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: Added eBPF maintainers information.

  MAINTAINERS                    |   8 +
  configure                      |   8 +-
  docs/devel/ebpf_rss.rst        | 125 ++++++++
  docs/devel/index.rst           |   1 +
  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        | 423 +++++++++++++++++++++++++
  ebpf/trace-events              |   4 +
  ebpf/trace.h                   |   2 +
  hw/net/vhost_net.c             |   3 +
  hw/net/virtio-net.c            | 115 ++++++-
  include/hw/virtio/virtio-net.h |   4 +
  include/net/net.h              |   2 +
  meson.build                    |   9 +
  meson_options.txt              |   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 +
  net/vhost-vdpa.c               |   2 +
  tools/ebpf/Makefile.ebpf       |  22 ++
  tools/ebpf/rss.bpf.c           | 552 +++++++++++++++++++++++++++++++++
  27 files changed, 1567 insertions(+), 4 deletions(-)

create mode 100644 docs/devel/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

#11 lore raw

Hi Jason,

Yes, the work to support RSS in the Linux virtio-net driver is in progress.
https://bugzilla.redhat.com/show_bug.cgi?id=1912082

Quoted 125 lines · Jason Wang
Quoted 21 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 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.
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.

Quoted 7 lines

Please also see the documentation in PATCH 6/7.

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.
* IPv6 extensions still in progress.

Hi Andrew:

The patch looks good at a glance. I tend to queue it for 6.1.

One issue is that, there's no easy way for testing it without a windows guest.

Do you have plan to extend Linux driver to support RSS (e.g via ethtool?).

Thanks

Quoted 79 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 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().

Changes since v3:
* rebased to last master.
* fixed issue with failed build without libbpf.
* fixed ebpf loading without rss option.
* refactored labels in ebpf_rss.c

Changes since v4:
* refactored configure/meson script.
* added checks for load_bytes in ebpf.
* documentation added to the index.
* refactored Makefile and rss.bpf.c.
* rebased to last master.

Andrew (7):
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: Added eBPF maintainers information.

  MAINTAINERS                    |   8 +
  configure                      |   8 +-
  docs/devel/ebpf_rss.rst        | 125 ++++++++
  docs/devel/index.rst           |   1 +
  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        | 423 +++++++++++++++++++++++++
  ebpf/trace-events              |   4 +
  ebpf/trace.h                   |   2 +
  hw/net/vhost_net.c             |   3 +
  hw/net/virtio-net.c            | 115 ++++++-
  include/hw/virtio/virtio-net.h |   4 +
  include/net/net.h              |   2 +
  meson.build                    |   9 +
  meson_options.txt              |   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 +
  net/vhost-vdpa.c               |   2 +
  tools/ebpf/Makefile.ebpf       |  22 ++
  tools/ebpf/rss.bpf.c           | 552 +++++++++++++++++++++++++++++++++
  27 files changed, 1567 insertions(+), 4 deletions(-)

create mode 100644 docs/devel/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

#12 lore raw

More correctly, https://bugzilla.redhat.com/show_bug.cgi?id=1865786

Quoted 132 lines · Yuri Benditovich

Hi Jason,

Yes, the work to support RSS in the Linux virtio-net driver is in progress.
https://bugzilla.redhat.com/show_bug.cgi?id=1912082

Quoted 125 lines · Jason Wang
Quoted 21 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 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.
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.

Quoted 7 lines

Please also see the documentation in PATCH 6/7.

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.
* IPv6 extensions still in progress.

Hi Andrew:

The patch looks good at a glance. I tend to queue it for 6.1.

One issue is that, there's no easy way for testing it without a windows guest.

Do you have plan to extend Linux driver to support RSS (e.g via ethtool?).

Thanks

Quoted 79 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 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().

Changes since v3:
* rebased to last master.
* fixed issue with failed build without libbpf.
* fixed ebpf loading without rss option.
* refactored labels in ebpf_rss.c

Changes since v4:
* refactored configure/meson script.
* added checks for load_bytes in ebpf.
* documentation added to the index.
* refactored Makefile and rss.bpf.c.
* rebased to last master.

Andrew (7):
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: Added eBPF maintainers information.

  MAINTAINERS                    |   8 +
  configure                      |   8 +-
  docs/devel/ebpf_rss.rst        | 125 ++++++++
  docs/devel/index.rst           |   1 +
  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        | 423 +++++++++++++++++++++++++
  ebpf/trace-events              |   4 +
  ebpf/trace.h                   |   2 +
  hw/net/vhost_net.c             |   3 +
  hw/net/virtio-net.c            | 115 ++++++-
  include/hw/virtio/virtio-net.h |   4 +
  include/net/net.h              |   2 +
  meson.build                    |   9 +
  meson_options.txt              |   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 +
  net/vhost-vdpa.c               |   2 +
  tools/ebpf/Makefile.ebpf       |  22 ++
  tools/ebpf/rss.bpf.c           | 552 +++++++++++++++++++++++++++++++++
  27 files changed, 1567 insertions(+), 4 deletions(-)

create mode 100644 docs/devel/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

Reviewed-by on the v5 series
#13 lore raw
In reply to Andrew Melnychenko
Quoted 21 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 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.
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.

Quoted 1 line

Please also see the documentation in PATCH 6/7.

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.

Could we instead fail init when RSS is requested and vhost is enabled? we can't do it for on by default features but we can for off by default ones ...

Quoted 82 lines

* IPv6 extensions still in progress.

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().

Changes since v3:
* rebased to last master.
* fixed issue with failed build without libbpf.
* fixed ebpf loading without rss option.
* refactored labels in ebpf_rss.c

Changes since v4:
* refactored configure/meson script.
* added checks for load_bytes in ebpf.
* documentation added to the index.
* refactored Makefile and rss.bpf.c.
* rebased to last master.

Andrew (7):
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: Added eBPF maintainers information.

 MAINTAINERS                    |   8 +
 configure                      |   8 +-
 docs/devel/ebpf_rss.rst        | 125 ++++++++
 docs/devel/index.rst           |   1 +
 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        | 423 +++++++++++++++++++++++++
 ebpf/trace-events              |   4 +
 ebpf/trace.h                   |   2 +
 hw/net/vhost_net.c             |   3 +
 hw/net/virtio-net.c            | 115 ++++++-
 include/hw/virtio/virtio-net.h |   4 +
 include/net/net.h              |   2 +
 meson.build                    |   9 +
 meson_options.txt              |   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 +
 net/vhost-vdpa.c               |   2 +
 tools/ebpf/Makefile.ebpf       |  22 ++
 tools/ebpf/rss.bpf.c           | 552 +++++++++++++++++++++++++++++++++
 27 files changed, 1567 insertions(+), 4 deletions(-)
 create mode 100644 docs/devel/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.31.0
#14 lore raw
Quoted 27 lines · Michael S. Tsirkin
Quoted 21 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 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.
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.

Quoted 1 line

Please also see the documentation in PATCH 6/7.

Quoted 9 lines
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.

Could we instead fail init when RSS is requested and vhost is enabled? we can't do it for on by default features but we can for off by default ones ...

Of course this is possible.
I hope we do not need to stop the merge (it is in progress) and this can be done in a separate patch and after some discussion. Notes for the discussion:
1. We are not talking about RSS (it does not contradict with vhost anymore), this is about "hash report".
2. Linux guest does not acknowledge this feature and for Linux VM there is no motivation to enable it at all. So it looks like the issue is minor, if any.
3. Currently we clear this feature with vhost but there is nothing specific to the "hash report" feature; we clear it during a check of vhost features (as well as other features dependent on vhost). If/when this feature will be supported by the kernel - we'll not disable it automatically. You suggest to fail the init for "hash + vhost" explicitly without any special reason.
4. In general I think failing init is not the best behavior of qemu, it is typically used in case of a really significant problem. Absence of this feature is not something that leads to unexpected behavior or significant performance loss. Maybe a warning is enough?

Quoted 83 lines
Quoted 82 lines

* IPv6 extensions still in progress.

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().

Changes since v3:
* rebased to last master.
* fixed issue with failed build without libbpf.
* fixed ebpf loading without rss option.
* refactored labels in ebpf_rss.c

Changes since v4:
* refactored configure/meson script.
* added checks for load_bytes in ebpf.
* documentation added to the index.
* refactored Makefile and rss.bpf.c.
* rebased to last master.

Andrew (7):
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: Added eBPF maintainers information.

 MAINTAINERS                    |   8 +
 configure                      |   8 +-
 docs/devel/ebpf_rss.rst        | 125 ++++++++
 docs/devel/index.rst           |   1 +
 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        | 423 +++++++++++++++++++++++++
 ebpf/trace-events              |   4 +
 ebpf/trace.h                   |   2 +
 hw/net/vhost_net.c             |   3 +
 hw/net/virtio-net.c            | 115 ++++++-
 include/hw/virtio/virtio-net.h |   4 +
 include/net/net.h              |   2 +
 meson.build                    |   9 +
 meson_options.txt              |   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 +
 net/vhost-vdpa.c               |   2 +
 tools/ebpf/Makefile.ebpf       |  22 ++
 tools/ebpf/rss.bpf.c           | 552 +++++++++++++++++++++++++++++++++
 27 files changed, 1567 insertions(+), 4 deletions(-)
 create mode 100644 docs/devel/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

--
2.31.0