mbox series

[v6,0/7] eBPF RSS support for virtio-net

Message ID 20210412082512.14998-1-andrew@daynix.com (mailing list archive)
Headers show
Series eBPF RSS support for virtio-net | expand

Message

Andrew Melnichenko April 12, 2021, 8:25 a.m. UTC
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.

Changes since v5:
* fixed issue with dstopt parsing in the eBPF program.
* added fragment packet parsing to skip L4.

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        | 431 +++++++++++++++++++++++++
 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           | 569 +++++++++++++++++++++++++++++++++
 27 files changed, 1592 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

Comments

no-reply@patchew.org April 12, 2021, 8:40 a.m. UTC | #1
Patchew URL: https://patchew.org/QEMU/20210412082512.14998-1-andrew@daynix.com/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20210412082512.14998-1-andrew@daynix.com
Subject: [PATCH v6 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
From https://github.com/patchew-project/qemu
 * [new tag]         patchew/20210412082512.14998-1-andrew@daynix.com -> patchew/20210412082512.14998-1-andrew@daynix.com
Switched to a new branch 'test'
48992c9 MAINTAINERS: Added eBPF maintainers information.
56c94d0 docs: Added eBPF documentation.
ec7b685 virtio-net: Added eBPF RSS to virtio-net.
9731e1e ebpf: Added eBPF RSS loader.
9cf91d5 ebpf: Added eBPF RSS program.
1556709 net: Added SetSteeringEBPF method for NetClientState.
79b1d59 net/tap: Added TUNSETSTEERINGEBPF code.

=== OUTPUT BEGIN ===
1/7 Checking commit 79b1d59a6332 (net/tap: Added TUNSETSTEERINGEBPF code.)
2/7 Checking commit 15567095a567 (net: Added SetSteeringEBPF method for NetClientState.)
3/7 Checking commit 9cf91d50d877 (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
#211: FILE: tools/ebpf/rss.bpf.c:157:
+ * According to https://www.iana.org/assignments/ipv6-parameters/ipv6-parameters.xhtml

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

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

total: 0 errors, 4 warnings, 591 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 9731e1e3d2ce (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 = 8088;$

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
#774: FILE: ebpf/rss.bpf.skeleton.h:425:
+^Ireturn 0;$

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

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

total: 85 errors, 3 warnings, 766 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 ec7b6853a867 (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 56c94d0c4e4f (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 48992c9748f1 (MAINTAINERS: Added eBPF maintainers information.)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20210412082512.14998-1-andrew@daynix.com/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
Jason Wang April 25, 2021, 3:32 a.m. UTC | #2
在 2021/4/12 下午4:25, 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.
>
> 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.


Want to merge but it fails to build on Debian 10.9:

dpkg -l | grep libbpf
ii  libbpf-dev:amd64              4.19.181-1 amd64        eBPF helper 
library (development files)
ii  libbpf4.19:amd64              4.19.181-1 amd64        eBPF helper 
library (shared library)

I configure use --enable-bpf --target-list=x86_64-softmmu, and I get:

[3/1375] Compiling C object libcommon.fa.p/ebpf_ebpf_rss.c.o
FAILED: libcommon.fa.p/ebpf_ebpf_rss.c.o
cc -Ilibcommon.fa.p -I. -I.. -I../slirp -I../slirp/src -I../dtc/libfdt 
-I../capstone/include/capstone -Iqapi -Itrace -Iui -Iui/shader 
-I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid 
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include 
-I/usr/include/gio-unix-2.0 -I/usr/include/pixman-1 
-fdiagnostics-color=auto -pipe -Wall -Winvalid-pch -Werror -std=gnu99 
-O2 -g -isystem /home/devel/git/qemu/linux-headers -isystem 
linux-headers -iquote . -iquote /home/devel/git/qemu -iquote 
/home/devel/git/qemu/include -iquote /home/devel/git/qemu/disas/libvixl 
-iquote /home/devel/git/qemu/tcg/i386 -iquote 
/home/devel/git/qemu/accel/tcg -pthread -U_FORTIFY_SOURCE 
-D_FORTIFY_SOURCE=2 -m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 
-D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef 
-Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common 
-fwrapv -Wold-style-declaration -Wold-style-definition -Wtype-limits 
-Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers 
-Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined 
-Wimplicit-fallthrough=2 -Wno-missing-include-dirs 
-Wno-shift-negative-value -Wno-psabi -fstack-protector-strong -fPIC -MD 
-MQ libcommon.fa.p/ebpf_ebpf_rss.c.o -MF 
libcommon.fa.p/ebpf_ebpf_rss.c.o.d -o libcommon.fa.p/ebpf_ebpf_rss.c.o 
-c ../ebpf/ebpf_rss.c
In file included from ../ebpf/ebpf_rss.c:23:
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function 
‘rss_bpf__destroy’:
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:32:3: error: implicit 
declaration of function ‘bpf_object__destroy_skeleton’; did you mean 
‘bpf_object__kversion’? [-Werror=implicit-function-declaration]
    bpf_object__destroy_skeleton(obj->skeleton);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    bpf_object__kversion
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:32:3: error: nested extern 
declaration of ‘bpf_object__destroy_skeleton’ [-Werror=nested-externs]
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: At top level:
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:40:33: error: ‘struct 
bpf_object_open_opts’ declared inside parameter list will not be visible 
outside of this definition or declaration [-Werror]
  rss_bpf__open_opts(const struct bpf_object_open_opts *opts)
                                  ^~~~~~~~~~~~~~~~~~~~
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function 
‘rss_bpf__open_opts’:
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:49:6: error: implicit 
declaration of function ‘bpf_object__open_skeleton’; did you mean 
‘bpf_object__open_buffer’? [-Werror=implicit-function-declaration]
   if (bpf_object__open_skeleton(obj->skeleton, opts))
       ^~~~~~~~~~~~~~~~~~~~~~~~~
       bpf_object__open_buffer
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:49:6: error: nested extern 
declaration of ‘bpf_object__open_skeleton’ [-Werror=nested-externs]
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function ‘rss_bpf__load’:
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:67:9: error: implicit 
declaration of function ‘bpf_object__load_skeleton’; did you mean 
‘bpf_object__load’? [-Werror=implicit-function-declaration]
   return bpf_object__load_skeleton(obj->skeleton);
          ^~~~~~~~~~~~~~~~~~~~~~~~~
          bpf_object__load
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:67:9: error: nested extern 
declaration of ‘bpf_object__load_skeleton’ [-Werror=nested-externs]
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function ‘rss_bpf__attach’:
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:88:9: error: implicit 
declaration of function ‘bpf_object__attach_skeleton’; did you mean 
‘bpf_object__for_each_safe’? [-Werror=implicit-function-declaration]
   return bpf_object__attach_skeleton(obj->skeleton);
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
          bpf_object__for_each_safe
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:88:9: error: nested extern 
declaration of ‘bpf_object__attach_skeleton’ [-Werror=nested-externs]
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function ‘rss_bpf__detach’:
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:94:9: error: implicit 
declaration of function ‘bpf_object__detach_skeleton’; did you mean 
‘bpf_object__for_each_safe’? [-Werror=implicit-function-declaration]
   return bpf_object__detach_skeleton(obj->skeleton);
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
          bpf_object__for_each_safe
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:94:9: error: nested extern 
declaration of ‘bpf_object__detach_skeleton’ [-Werror=nested-externs]
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:94:9: error: ‘return’ with 
a value, in function returning void [-Werror]
   return bpf_object__detach_skeleton(obj->skeleton);
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:92:1: note: declared here
  rss_bpf__detach(struct rss_bpf *obj)
  ^~~~~~~~~~~~~~~
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function 
‘rss_bpf__create_skeleton’:
/home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:102:53: error: 
dereferencing pointer to incomplete type ‘struct bpf_object_skeleton’
   s = (struct bpf_object_skeleton *)calloc(1, sizeof(*s));
                                                      ^~
cc1: all warnings being treated as errors

Thanks


>
> 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.
>
> Changes since v5:
> * fixed issue with dstopt parsing in the eBPF program.
> * added fragment packet parsing to skip L4.
>
> 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        | 431 +++++++++++++++++++++++++
>   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           | 569 +++++++++++++++++++++++++++++++++
>   27 files changed, 1592 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
>
Andrew Melnichenko April 27, 2021, 10:47 a.m. UTC | #3
Hi,
I've checked the issue. Apparently, libbpf can't work with a skeleton on
Debian.
Version check would not help - versioning differs at different distros.
I've added a small check:

diff --git a/meson.build b/meson.build
> index ca551dd15d..4a51a25643 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -1018,6 +1018,20 @@ endif
>
>  # libbpf
>  libbpf = dependency('libbpf', required: get_option('bpf'))
> +if libbpf.found() and not cc.links('''
> +   #include <bpf/libbpf.h>
> +   int main(void)
> +   {
> +     bpf_object__destroy_skeleton(NULL);
> +     return 0;
> +   }''', dependencies: libbpf)
> +  libbpf = not_found
> +  if get_option('bpf').enabled()
> +    error('libbpf skeleton test failed')
> +  else
> +    warning('libbpf skeleton test failed, disabling')
> +  endif
> +endif
>
>  if get_option('cfi')
>    cfi_flags=[]
>

Is it possible to prepare an additional patch or should I prepare new
eBPFv7 patches?


On Sun, Apr 25, 2021 at 6:32 AM Jason Wang <jasowang@redhat.com> wrote:

>
> 在 2021/4/12 下午4:25, 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.
> >
> > 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.
>
>
> Want to merge but it fails to build on Debian 10.9:
>
> dpkg -l | grep libbpf
> ii  libbpf-dev:amd64              4.19.181-1 amd64        eBPF helper
> library (development files)
> ii  libbpf4.19:amd64              4.19.181-1 amd64        eBPF helper
> library (shared library)
>
> I configure use --enable-bpf --target-list=x86_64-softmmu, and I get:
>
> [3/1375] Compiling C object libcommon.fa.p/ebpf_ebpf_rss.c.o
> FAILED: libcommon.fa.p/ebpf_ebpf_rss.c.o
> cc -Ilibcommon.fa.p -I. -I.. -I../slirp -I../slirp/src -I../dtc/libfdt
> -I../capstone/include/capstone -Iqapi -Itrace -Iui -Iui/shader
> -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid
> -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
> -I/usr/include/gio-unix-2.0 -I/usr/include/pixman-1
> -fdiagnostics-color=auto -pipe -Wall -Winvalid-pch -Werror -std=gnu99
> -O2 -g -isystem /home/devel/git/qemu/linux-headers -isystem
> linux-headers -iquote . -iquote /home/devel/git/qemu -iquote
> /home/devel/git/qemu/include -iquote /home/devel/git/qemu/disas/libvixl
> -iquote /home/devel/git/qemu/tcg/i386 -iquote
> /home/devel/git/qemu/accel/tcg -pthread -U_FORTIFY_SOURCE
> -D_FORTIFY_SOURCE=2 -m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
> -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef
> -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common
> -fwrapv -Wold-style-declaration -Wold-style-definition -Wtype-limits
> -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers
> -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined
> -Wimplicit-fallthrough=2 -Wno-missing-include-dirs
> -Wno-shift-negative-value -Wno-psabi -fstack-protector-strong -fPIC -MD
> -MQ libcommon.fa.p/ebpf_ebpf_rss.c.o -MF
> libcommon.fa.p/ebpf_ebpf_rss.c.o.d -o libcommon.fa.p/ebpf_ebpf_rss.c.o
> -c ../ebpf/ebpf_rss.c
> In file included from ../ebpf/ebpf_rss.c:23:
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function
> ‘rss_bpf__destroy’:
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:32:3: error: implicit
> declaration of function ‘bpf_object__destroy_skeleton’; did you mean
> ‘bpf_object__kversion’? [-Werror=implicit-function-declaration]
>     bpf_object__destroy_skeleton(obj->skeleton);
>     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     bpf_object__kversion
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:32:3: error: nested extern
> declaration of ‘bpf_object__destroy_skeleton’ [-Werror=nested-externs]
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: At top level:
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:40:33: error: ‘struct
> bpf_object_open_opts’ declared inside parameter list will not be visible
> outside of this definition or declaration [-Werror]
>   rss_bpf__open_opts(const struct bpf_object_open_opts *opts)
>                                   ^~~~~~~~~~~~~~~~~~~~
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function
> ‘rss_bpf__open_opts’:
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:49:6: error: implicit
> declaration of function ‘bpf_object__open_skeleton’; did you mean
> ‘bpf_object__open_buffer’? [-Werror=implicit-function-declaration]
>    if (bpf_object__open_skeleton(obj->skeleton, opts))
>        ^~~~~~~~~~~~~~~~~~~~~~~~~
>        bpf_object__open_buffer
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:49:6: error: nested extern
> declaration of ‘bpf_object__open_skeleton’ [-Werror=nested-externs]
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function ‘rss_bpf__load’:
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:67:9: error: implicit
> declaration of function ‘bpf_object__load_skeleton’; did you mean
> ‘bpf_object__load’? [-Werror=implicit-function-declaration]
>    return bpf_object__load_skeleton(obj->skeleton);
>           ^~~~~~~~~~~~~~~~~~~~~~~~~
>           bpf_object__load
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:67:9: error: nested extern
> declaration of ‘bpf_object__load_skeleton’ [-Werror=nested-externs]
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function
> ‘rss_bpf__attach’:
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:88:9: error: implicit
> declaration of function ‘bpf_object__attach_skeleton’; did you mean
> ‘bpf_object__for_each_safe’? [-Werror=implicit-function-declaration]
>    return bpf_object__attach_skeleton(obj->skeleton);
>           ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>           bpf_object__for_each_safe
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:88:9: error: nested extern
> declaration of ‘bpf_object__attach_skeleton’ [-Werror=nested-externs]
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function
> ‘rss_bpf__detach’:
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:94:9: error: implicit
> declaration of function ‘bpf_object__detach_skeleton’; did you mean
> ‘bpf_object__for_each_safe’? [-Werror=implicit-function-declaration]
>    return bpf_object__detach_skeleton(obj->skeleton);
>           ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>           bpf_object__for_each_safe
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:94:9: error: nested extern
> declaration of ‘bpf_object__detach_skeleton’ [-Werror=nested-externs]
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:94:9: error: ‘return’ with
> a value, in function returning void [-Werror]
>    return bpf_object__detach_skeleton(obj->skeleton);
>           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:92:1: note: declared here
>   rss_bpf__detach(struct rss_bpf *obj)
>   ^~~~~~~~~~~~~~~
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function
> ‘rss_bpf__create_skeleton’:
> /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:102:53: error:
> dereferencing pointer to incomplete type ‘struct bpf_object_skeleton’
>    s = (struct bpf_object_skeleton *)calloc(1, sizeof(*s));
>                                                       ^~
> cc1: all warnings being treated as errors
>
> Thanks
>
>
> >
> > 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.
> >
> > Changes since v5:
> > * fixed issue with dstopt parsing in the eBPF program.
> > * added fragment packet parsing to skip L4.
> >
> > 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        | 431 +++++++++++++++++++++++++
> >   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           | 569 +++++++++++++++++++++++++++++++++
> >   27 files changed, 1592 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
> >
>
>
Jason Wang April 28, 2021, 2:22 a.m. UTC | #4
在 2021/4/27 下午6:47, Andrew Melnichenko 写道:
> Hi,
> I've checked the issue. Apparently, libbpf can't work with a 
> skeleton on Debian.
> Version check would not help - versioning differs at different distros.


So you meant the libbpf version is too old?


> I've added a small check:
>
>     diff --git a/meson.build b/meson.build
>     index ca551dd15d..4a51a25643 100644
>     --- a/meson.build
>     +++ b/meson.build
>     @@ -1018,6 +1018,20 @@ endif
>
>      # libbpf
>      libbpf = dependency('libbpf', required: get_option('bpf'))
>     +if libbpf.found() and not cc.links('''
>     +   #include <bpf/libbpf.h>
>     +   int main(void)
>     +   {
>     +     bpf_object__destroy_skeleton(NULL);
>     +     return 0;
>     +   }''', dependencies: libbpf)
>     +  libbpf = not_found
>     +  if get_option('bpf').enabled()
>     +    error('libbpf skeleton test failed')
>     +  else
>     +    warning('libbpf skeleton test failed, disabling')
>     +  endif
>     +endif
>
>      if get_option('cfi')
>        cfi_flags=[]
>
>
> Is it possible to prepare an additional patch or should I prepare new 
> eBPFv7 patches?


Please send V7.

Thanks


>
>
> On Sun, Apr 25, 2021 at 6:32 AM Jason Wang <jasowang@redhat.com 
> <mailto:jasowang@redhat.com>> wrote:
>
>
>     在 2021/4/12 下午4:25, 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.
>     >
>     > 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.
>
>
>     Want to merge but it fails to build on Debian 10.9:
>
>     dpkg -l | grep libbpf
>     ii  libbpf-dev:amd64              4.19.181-1 amd64        eBPF helper
>     library (development files)
>     ii  libbpf4.19:amd64              4.19.181-1 amd64        eBPF helper
>     library (shared library)
>
>     I configure use --enable-bpf --target-list=x86_64-softmmu, and I get:
>
>     [3/1375] Compiling C object libcommon.fa.p/ebpf_ebpf_rss.c.o
>     FAILED: libcommon.fa.p/ebpf_ebpf_rss.c.o
>     cc -Ilibcommon.fa.p -I. -I.. -I../slirp -I../slirp/src
>     -I../dtc/libfdt
>     -I../capstone/include/capstone -Iqapi -Itrace -Iui -Iui/shader
>     -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid
>     -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
>     -I/usr/include/gio-unix-2.0 -I/usr/include/pixman-1
>     -fdiagnostics-color=auto -pipe -Wall -Winvalid-pch -Werror -std=gnu99
>     -O2 -g -isystem /home/devel/git/qemu/linux-headers -isystem
>     linux-headers -iquote . -iquote /home/devel/git/qemu -iquote
>     /home/devel/git/qemu/include -iquote
>     /home/devel/git/qemu/disas/libvixl
>     -iquote /home/devel/git/qemu/tcg/i386 -iquote
>     /home/devel/git/qemu/accel/tcg -pthread -U_FORTIFY_SOURCE
>     -D_FORTIFY_SOURCE=2 -m64 -mcx16 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
>     -D_LARGEFILE_SOURCE -Wstrict-prototypes -Wredundant-decls -Wundef
>     -Wwrite-strings -Wmissing-prototypes -fno-strict-aliasing -fno-common
>     -fwrapv -Wold-style-declaration -Wold-style-definition -Wtype-limits
>     -Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers
>     -Wempty-body -Wnested-externs -Wendif-labels -Wexpansion-to-defined
>     -Wimplicit-fallthrough=2 -Wno-missing-include-dirs
>     -Wno-shift-negative-value -Wno-psabi -fstack-protector-strong
>     -fPIC -MD
>     -MQ libcommon.fa.p/ebpf_ebpf_rss.c.o -MF
>     libcommon.fa.p/ebpf_ebpf_rss.c.o.d -o
>     libcommon.fa.p/ebpf_ebpf_rss.c.o
>     -c ../ebpf/ebpf_rss.c
>     In file included from ../ebpf/ebpf_rss.c:23:
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function
>     ‘rss_bpf__destroy’:
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:32:3: error: implicit
>     declaration of function ‘bpf_object__destroy_skeleton’; did you mean
>     ‘bpf_object__kversion’? [-Werror=implicit-function-declaration]
>         bpf_object__destroy_skeleton(obj->skeleton);
>         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
>         bpf_object__kversion
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:32:3: error: nested
>     extern
>     declaration of ‘bpf_object__destroy_skeleton’ [-Werror=nested-externs]
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: At top level:
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:40:33: error: ‘struct
>     bpf_object_open_opts’ declared inside parameter list will not be
>     visible
>     outside of this definition or declaration [-Werror]
>       rss_bpf__open_opts(const struct bpf_object_open_opts *opts)
>                                       ^~~~~~~~~~~~~~~~~~~~
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function
>     ‘rss_bpf__open_opts’:
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:49:6: error: implicit
>     declaration of function ‘bpf_object__open_skeleton’; did you mean
>     ‘bpf_object__open_buffer’? [-Werror=implicit-function-declaration]
>        if (bpf_object__open_skeleton(obj->skeleton, opts))
>            ^~~~~~~~~~~~~~~~~~~~~~~~~
>            bpf_object__open_buffer
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:49:6: error: nested
>     extern
>     declaration of ‘bpf_object__open_skeleton’ [-Werror=nested-externs]
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function
>     ‘rss_bpf__load’:
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:67:9: error: implicit
>     declaration of function ‘bpf_object__load_skeleton’; did you mean
>     ‘bpf_object__load’? [-Werror=implicit-function-declaration]
>        return bpf_object__load_skeleton(obj->skeleton);
>               ^~~~~~~~~~~~~~~~~~~~~~~~~
>               bpf_object__load
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:67:9: error: nested
>     extern
>     declaration of ‘bpf_object__load_skeleton’ [-Werror=nested-externs]
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function
>     ‘rss_bpf__attach’:
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:88:9: error: implicit
>     declaration of function ‘bpf_object__attach_skeleton’; did you mean
>     ‘bpf_object__for_each_safe’? [-Werror=implicit-function-declaration]
>        return bpf_object__attach_skeleton(obj->skeleton);
>               ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>               bpf_object__for_each_safe
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:88:9: error: nested
>     extern
>     declaration of ‘bpf_object__attach_skeleton’ [-Werror=nested-externs]
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function
>     ‘rss_bpf__detach’:
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:94:9: error: implicit
>     declaration of function ‘bpf_object__detach_skeleton’; did you mean
>     ‘bpf_object__for_each_safe’? [-Werror=implicit-function-declaration]
>        return bpf_object__detach_skeleton(obj->skeleton);
>               ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>               bpf_object__for_each_safe
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:94:9: error: nested
>     extern
>     declaration of ‘bpf_object__detach_skeleton’ [-Werror=nested-externs]
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:94:9: error: ‘return’
>     with
>     a value, in function returning void [-Werror]
>        return bpf_object__detach_skeleton(obj->skeleton);
>               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:92:1: note: declared here
>       rss_bpf__detach(struct rss_bpf *obj)
>       ^~~~~~~~~~~~~~~
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h: In function
>     ‘rss_bpf__create_skeleton’:
>     /home/devel/git/qemu/ebpf/rss.bpf.skeleton.h:102:53: error:
>     dereferencing pointer to incomplete type ‘struct bpf_object_skeleton’
>        s = (struct bpf_object_skeleton *)calloc(1, sizeof(*s));
>                                                           ^~
>     cc1: all warnings being treated as errors
>
>     Thanks
>
>
>     >
>     > 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.
>     >
>     > Changes since v5:
>     > * fixed issue with dstopt parsing in the eBPF program.
>     > * added fragment packet parsing to skip L4.
>     >
>     > 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        | 431 +++++++++++++++++++++++++
>     >   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           | 569
>     +++++++++++++++++++++++++++++++++
>     >   27 files changed, 1592 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
>     >
>