qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* Re: [RFC PATCH v3 0/6] eBPF RSS support for virtio-net
  2021-01-14 21:16 [RFC PATCH v3 0/6] eBPF RSS support for virtio-net Andrew Melnychenko
@ 2021-01-14 20:54 ` no-reply
  2021-01-14 21:16 ` [RFC PATCH v3 1/6] net/tap: Added TUNSETSTEERINGEBPF code Andrew Melnychenko
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: no-reply @ 2021-01-14 20:54 UTC (permalink / raw)
  To: andrew; +Cc: berrange, mst, jasowang, qemu-devel, yuri.benditovich, yan

Patchew URL: https://patchew.org/QEMU/20210114211612.387052-1-andrew@daynix.com/



Hi,

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

Type: series
Message-id: 20210114211612.387052-1-andrew@daynix.com
Subject: [RFC PATCH v3 0/6] eBPF RSS support for virtio-net

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 - [tag update]      patchew/20210109143637.29645-1-bmeng.cn@gmail.com -> patchew/20210109143637.29645-1-bmeng.cn@gmail.com
 - [tag update]      patchew/20210112164045.98565-1-thuth@redhat.com -> patchew/20210112164045.98565-1-thuth@redhat.com
 - [tag update]      patchew/20210114165730.31607-1-alex.bennee@linaro.org -> patchew/20210114165730.31607-1-alex.bennee@linaro.org
 - [tag update]      patchew/20210114170304.87507-1-mreitz@redhat.com -> patchew/20210114170304.87507-1-mreitz@redhat.com
 - [tag update]      patchew/20210114174509.2944817-1-philmd@redhat.com -> patchew/20210114174509.2944817-1-philmd@redhat.com
 * [new tag]         patchew/20210114211612.387052-1-andrew@daynix.com -> patchew/20210114211612.387052-1-andrew@daynix.com
Switched to a new branch 'test'
32a7d31 docs: Added eBPF documentation.
5829b35 virtio-net: Added eBPF RSS to virtio-net.
c1e16f7 ebpf: Added eBPF RSS loader.
67e8d5f ebpf: Added eBPF RSS program.
9955cbd net: Added SetSteeringEBPF method for NetClientState.
7255813 net/tap: Added TUNSETSTEERINGEBPF code.

=== OUTPUT BEGIN ===
1/6 Checking commit 725581347a66 (net/tap: Added TUNSETSTEERINGEBPF code.)
2/6 Checking commit 9955cbd7e95d (net: Added SetSteeringEBPF method for NetClientState.)
3/6 Checking commit 67e8d5f1220d (ebpf: Added eBPF RSS program.)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#18: 
new file mode 100755

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

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

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

total: 0 errors, 4 warnings, 538 lines checked

Patch 3/6 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
4/6 Checking commit c1e16f784c92 (ebpf: Added eBPF RSS loader.)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#91: 
new file mode 100644

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

ERROR: code indent should never use tabs
#418: FILE: ebpf/rss.bpf.skeleton.h:49:
+^Iif (bpf_object__open_skeleton(obj->skeleton, opts))$

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

ERROR: code indent should never use tabs
#483: FILE: ebpf/rss.bpf.skeleton.h:114:
+^Is->maps = (struct bpf_map_skeleton *)calloc(s->map_cnt, s->map_skel_sz);$

ERROR: code indent should never use tabs
#484: FILE: ebpf/rss.bpf.skeleton.h:115:
+^Iif (!s->maps)$

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

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

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

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

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

ERROR: code indent should never use tabs
#491: FILE: ebpf/rss.bpf.skeleton.h:122:
+^Is->maps[1].map = &obj->maps.tap_rss_map_indirection_table;$

ERROR: code indent should never use tabs
#493: FILE: ebpf/rss.bpf.skeleton.h:124:
+^Is->maps[2].name = "tap_rss_map_toeplitz_key";$

ERROR: code indent should never use tabs
#494: FILE: ebpf/rss.bpf.skeleton.h:125:
+^Is->maps[2].map = &obj->maps.tap_rss_map_toeplitz_key;$

ERROR: code indent should never use tabs
#496: FILE: ebpf/rss.bpf.skeleton.h:127:
+^I/* programs */$

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

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

WARNING: line over 80 characters
#499: FILE: ebpf/rss.bpf.skeleton.h:130:
+       s->progs = (struct bpf_prog_skeleton *)calloc(s->prog_cnt, s->prog_skel_sz);

ERROR: code indent should never use tabs
#499: FILE: ebpf/rss.bpf.skeleton.h:130:
+^Is->progs = (struct bpf_prog_skeleton *)calloc(s->prog_cnt, s->prog_skel_sz);$

ERROR: code indent should never use tabs
#500: FILE: ebpf/rss.bpf.skeleton.h:131:
+^Iif (!s->progs)$

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

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

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

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

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

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

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

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

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

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

total: 85 errors, 3 warnings, 756 lines checked

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

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

total: 0 errors, 1 warnings, 223 lines checked

Patch 5/6 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
6/6 Checking commit 32a7d313e818 (docs: Added eBPF documentation.)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#33: 
new file mode 100644

total: 0 errors, 1 warnings, 139 lines checked

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

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20210114211612.387052-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

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFC PATCH v3 0/6] eBPF RSS support for virtio-net
@ 2021-01-14 21:16 Andrew Melnychenko
  2021-01-14 20:54 ` no-reply
                   ` (7 more replies)
  0 siblings, 8 replies; 20+ messages in thread
From: Andrew Melnychenko @ 2021-01-14 21:16 UTC (permalink / raw)
  To: jasowang, mst; +Cc: yan, yuri.benditovich, berrange, qemu-devel

This set of patches introduces the usage of eBPF for packet steering
and RSS hash calculation:
* RSS(Receive Side Scaling) is used to distribute network packets to
guest virtqueues by calculating packet hash
* Additionally adding support for the usage of RSS with vhost

The eBPF works on kernels 5.8+
On earlier kerneld it fails to load and the RSS feature is reported
only without vhost and implemented in 'in-qemu' software.

Implementation notes:
Linux TAP TUNSETSTEERINGEBPF ioctl was used to set the eBPF program.
Added libbpf dependency and eBPF support.
The eBPF program is part of the qemu and presented as an array
of BPF ELF file data. The eBPF array file initially generated by bpftool.
The compilation of eBPF is not part of QEMU build and can be done
using provided Makefile.ebpf(need to adjust 'linuxhdrs').
Added changes to virtio-net and vhost, primary eBPF RSS is used.
'in-qemu' RSS used in the case of hash population and as a fallback option.
For vhost, the hash population feature is not reported to the guest.

Please also see the documentation in PATCH 6/6.

I am sending those patches as RFC to initiate the discussions and get
feedback on the following points:
* Fallback when eBPF is not supported by the kernel
* Live migration to the kernel that doesn't have eBPF support
* Integration with current QEMU build
* Additional usage for eBPF for packet filtering

Known issues:
* hash population not supported by eBPF RSS: 'in-qemu' RSS used
as a fallback, also, hash population feature is not reported to guests
with vhost.

Changes since v1:
* using libbpf instead of direct 'bpf' system call.
* added libbpf dependency to the configure/meson scripts.
* changed python script for eBPF .h file generation.
* changed eBPF program - reading L3 proto from ethernet frame.
* added TUNSETSTEERINGEBPF define for TUN.
* changed the maintainer's info.
* added license headers.
* refactored code.Changes since v1:
* using libbpf instead of direct 'bpf' system call.
* added libbpf dependency to the configure/meson scripts.
* changed python script for eBPF .h file generation.
* changed eBPF program - reading L3 proto from ethernet frame.
* added TUNSETSTEERINGEBPF define for TUN.
* changed the maintainer's info.
* added license headers.
* refactored code.

Changes since v2:
* using bpftool for eBPF skeleton generation.
* ebpf_rss is refactored to use skeleton generated by bpftool.
* added/adjasted license in comment sections and in eBPF file.
* rss.bpf.c and Makefile.ebpf moved to the tool/ebpf folder.
* virtio-net eBPF rss refactored. Now eBPF initialized during realize().

Andrew (6):
  net/tap: Added TUNSETSTEERINGEBPF code.
  net: Added SetSteeringEBPF method for NetClientState.
  ebpf: Added eBPF RSS program.
  ebpf: Added eBPF RSS loader.
  virtio-net: Added eBPF RSS to virtio-net.
  docs: Added eBPF documentation.

 MAINTAINERS                    |   8 +
 configure                      |  33 +++
 docs/ebpf_rss.rst              | 125 ++++++++
 ebpf/ebpf_rss-stub.c           |  40 +++
 ebpf/ebpf_rss.c                | 165 +++++++++++
 ebpf/ebpf_rss.h                |  44 +++
 ebpf/meson.build               |   1 +
 ebpf/rss.bpf.skeleton.h        | 397 ++++++++++++++++++++++++++
 ebpf/trace-events              |   4 +
 ebpf/trace.h                   |   2 +
 hw/net/vhost_net.c             |   2 +
 hw/net/virtio-net.c            | 125 +++++++-
 include/hw/virtio/virtio-net.h |   4 +
 include/net/net.h              |   2 +
 meson.build                    |  13 +
 net/tap-bsd.c                  |   5 +
 net/tap-linux.c                |  13 +
 net/tap-linux.h                |   1 +
 net/tap-solaris.c              |   5 +
 net/tap-stub.c                 |   5 +
 net/tap.c                      |   9 +
 net/tap_int.h                  |   1 +
 net/vhost-vdpa.c               |   2 +
 tools/ebpf/Makefile.ebpf       |  33 +++
 tools/ebpf/rss.bpf.c           | 505 +++++++++++++++++++++++++++++++++
 25 files changed, 1540 insertions(+), 4 deletions(-)
 create mode 100644 docs/ebpf_rss.rst
 create mode 100644 ebpf/ebpf_rss-stub.c
 create mode 100644 ebpf/ebpf_rss.c
 create mode 100644 ebpf/ebpf_rss.h
 create mode 100644 ebpf/meson.build
 create mode 100644 ebpf/rss.bpf.skeleton.h
 create mode 100644 ebpf/trace-events
 create mode 100644 ebpf/trace.h
 create mode 100755 tools/ebpf/Makefile.ebpf
 create mode 100644 tools/ebpf/rss.bpf.c

-- 
2.30.0



^ permalink raw reply	[flat|nested] 20+ messages in thread

* [RFC PATCH v3 1/6] net/tap: Added TUNSETSTEERINGEBPF code.
  2021-01-14 21:16 [RFC PATCH v3 0/6] eBPF RSS support for virtio-net Andrew Melnychenko
  2021-01-14 20:54 ` no-reply
@ 2021-01-14 21:16 ` Andrew Melnychenko
  2021-01-14 21:16 ` [RFC PATCH v3 2/6] net: Added SetSteeringEBPF method for NetClientState Andrew Melnychenko
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Andrew Melnychenko @ 2021-01-14 21:16 UTC (permalink / raw)
  To: jasowang, mst; +Cc: yan, yuri.benditovich, berrange, qemu-devel

From: Andrew <andrew@daynix.com>

Additional code that will be used for eBPF setting steering routine.

Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
---
 net/tap-linux.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/net/tap-linux.h b/net/tap-linux.h
index 2f36d100fc..1d06fe0de6 100644
--- a/net/tap-linux.h
+++ b/net/tap-linux.h
@@ -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
 
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v3 2/6] net: Added SetSteeringEBPF method for NetClientState.
  2021-01-14 21:16 [RFC PATCH v3 0/6] eBPF RSS support for virtio-net Andrew Melnychenko
  2021-01-14 20:54 ` no-reply
  2021-01-14 21:16 ` [RFC PATCH v3 1/6] net/tap: Added TUNSETSTEERINGEBPF code Andrew Melnychenko
@ 2021-01-14 21:16 ` Andrew Melnychenko
  2021-01-14 21:16 ` [RFC PATCH v3 3/6] ebpf: Added eBPF RSS program Andrew Melnychenko
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Andrew Melnychenko @ 2021-01-14 21:16 UTC (permalink / raw)
  To: jasowang, mst; +Cc: yan, yuri.benditovich, berrange, qemu-devel

From: Andrew <andrew@daynix.com>

For now, that method supported only by Linux TAP.
Linux TAP uses TUNSETSTEERINGEBPF ioctl.

Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
---
 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(+)

diff --git a/include/net/net.h b/include/net/net.h
index 919facaad2..d77fbb8878 100644
--- a/include/net/net.h
+++ b/include/net/net.h
@@ -61,6 +61,7 @@ typedef int (SetVnetBE)(NetClientState *, bool);
 typedef struct SocketReadState SocketReadState;
 typedef void (SocketReadStateFinalize)(SocketReadState *rs);
 typedef void (NetAnnounce)(NetClientState *);
+typedef bool (SetSteeringEBPF)(NetClientState *, int);
 
 typedef struct NetClientInfo {
     NetClientDriver type;
@@ -82,6 +83,7 @@ typedef struct NetClientInfo {
     SetVnetLE *set_vnet_le;
     SetVnetBE *set_vnet_be;
     NetAnnounce *announce;
+    SetSteeringEBPF *set_steering_ebpf;
 } NetClientInfo;
 
 struct NetClientState {
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index 77aaf674b1..4f64f31e98 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -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;
+}
diff --git a/net/tap-linux.c b/net/tap-linux.c
index b0635e9e32..9584769740 100644
--- a/net/tap-linux.c
+++ b/net/tap-linux.c
@@ -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;
+}
diff --git a/net/tap-solaris.c b/net/tap-solaris.c
index 0475a58207..d85224242b 100644
--- a/net/tap-solaris.c
+++ b/net/tap-solaris.c
@@ -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;
+}
diff --git a/net/tap-stub.c b/net/tap-stub.c
index de525a2e69..a0fa25804b 100644
--- a/net/tap-stub.c
+++ b/net/tap-stub.c
@@ -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;
+}
diff --git a/net/tap.c b/net/tap.c
index b7512853f4..d0c1356a04 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -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,
diff --git a/net/tap_int.h b/net/tap_int.h
index 225a49ea48..547f8a5a28 100644
--- a/net/tap_int.h
+++ b/net/tap_int.h
@@ -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 */
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v3 3/6] ebpf: Added eBPF RSS program.
  2021-01-14 21:16 [RFC PATCH v3 0/6] eBPF RSS support for virtio-net Andrew Melnychenko
                   ` (2 preceding siblings ...)
  2021-01-14 21:16 ` [RFC PATCH v3 2/6] net: Added SetSteeringEBPF method for NetClientState Andrew Melnychenko
@ 2021-01-14 21:16 ` Andrew Melnychenko
  2021-01-14 21:16 ` [RFC PATCH v3 4/6] ebpf: Added eBPF RSS loader Andrew Melnychenko
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Andrew Melnychenko @ 2021-01-14 21:16 UTC (permalink / raw)
  To: jasowang, mst; +Cc: yan, yuri.benditovich, berrange, qemu-devel

From: Andrew <andrew@daynix.com>

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.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
---
 tools/ebpf/Makefile.ebpf |  33 +++
 tools/ebpf/rss.bpf.c     | 505 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 538 insertions(+)
 create mode 100755 tools/ebpf/Makefile.ebpf
 create mode 100644 tools/ebpf/rss.bpf.c

diff --git a/tools/ebpf/Makefile.ebpf b/tools/ebpf/Makefile.ebpf
new file mode 100755
index 0000000000..d32d1680b8
--- /dev/null
+++ b/tools/ebpf/Makefile.ebpf
@@ -0,0 +1,33 @@
+OBJS = rss.bpf.o
+
+LLC ?= llc
+CLANG ?= clang
+INC_FLAGS = `$(CLANG) -print-file-name=include`
+EXTRA_CFLAGS ?= -O2 -emit-llvm -fno-stack-protector
+
+ifdef linuxhdrs
+LINUXINCLUDE =  -I $(linuxhdrs)/arch/x86/include/uapi \
+                -I $(linuxhdrs)/arch/x86/include/generated/uapi \
+                -I $(linuxhdrs)/arch/x86/include/generated \
+                -I $(linuxhdrs)/include/generated/uapi \
+                -I $(linuxhdrs)/include/uapi \
+                -I $(linuxhdrs)/include \
+                -I $(linuxhdrs)/tools/lib
+INC_FLAGS += -nostdinc -isystem
+endif
+
+all: $(OBJS)
+
+.PHONY: clean
+
+clean:
+	rm -f $(OBJS)
+
+$(OBJS):  %.o:%.c
+	$(CLANG) $(INC_FLAGS) \
+                -D__KERNEL__ -D__ASM_SYSREG_H \
+                -I../include $(LINUXINCLUDE) \
+                $(EXTRA_CFLAGS) -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@
+	bpftool gen skeleton rss.bpf.o > rss.bpf.skeleton.h
+	cp rss.bpf.skeleton.h ../../ebpf/
+
diff --git a/tools/ebpf/rss.bpf.c b/tools/ebpf/rss.bpf.c
new file mode 100644
index 0000000000..eb377247fc
--- /dev/null
+++ b/tools/ebpf/rss.bpf.c
@@ -0,0 +1,505 @@
+/*
+ * eBPF RSS program
+ *
+ * Developed by Daynix Computing LTD (http://www.daynix.com)
+ *
+ * Authors:
+ *  Andrew Melnychenko <andrew@daynix.com>
+ *  Yuri Benditovich <yuri.benditovich@daynix.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ * Prepare:
+ * Requires llvm, clang, bpftool, linux kernel tree
+ *
+ * Build rss.bpf.skeleton.h:
+ * make -f Makefile.ebpf clean all
+ */
+
+#include <stddef.h>
+#include <stdbool.h>
+#include <linux/bpf.h>
+
+#include <linux/in.h>
+#include <linux/if_ether.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+
+#include <linux/udp.h>
+#include <linux/tcp.h>
+
+#include <bpf/bpf_helpers.h>
+#include <linux/virtio_net.h>
+
+#define INDIRECTION_TABLE_SIZE 128
+#define HASH_CALCULATION_BUFFER_SIZE 36
+
+struct rss_config_t {
+    __u8 redirect;
+    __u8 populate_hash;
+    __u32 hash_types;
+    __u16 indirections_len;
+    __u16 default_queue;
+};
+
+struct toeplitz_key_data_t {
+    __u32 leftmost_32_bits;
+    __u8 next_byte[HASH_CALCULATION_BUFFER_SIZE];
+};
+
+struct packet_hash_info_t {
+    __u8 is_ipv4;
+    __u8 is_ipv6;
+    __u8 is_udp;
+    __u8 is_tcp;
+    __u8 is_ipv6_ext_src;
+    __u8 is_ipv6_ext_dst;
+
+    __u16 src_port;
+    __u16 dst_port;
+
+    union {
+        struct {
+            __be32 in_src;
+            __be32 in_dst;
+        };
+
+        struct {
+            struct in6_addr in6_src;
+            struct in6_addr in6_dst;
+            struct in6_addr in6_ext_src;
+            struct in6_addr in6_ext_dst;
+        };
+    };
+};
+
+struct bpf_map_def SEC("maps")
+tap_rss_map_configurations = {
+        .type        = BPF_MAP_TYPE_ARRAY,
+        .key_size    = sizeof(__u32),
+        .value_size  = sizeof(struct rss_config_t),
+        .max_entries = 1,
+};
+
+struct bpf_map_def SEC("maps")
+tap_rss_map_toeplitz_key = {
+        .type        = BPF_MAP_TYPE_ARRAY,
+        .key_size    = sizeof(__u32),
+        .value_size  = sizeof(struct toeplitz_key_data_t),
+        .max_entries = 1,
+};
+
+struct bpf_map_def SEC("maps")
+tap_rss_map_indirection_table = {
+        .type        = BPF_MAP_TYPE_ARRAY,
+        .key_size    = sizeof(__u32),
+        .value_size  = sizeof(__u16),
+        .max_entries = INDIRECTION_TABLE_SIZE,
+};
+
+static inline void net_rx_rss_add_chunk(__u8 *rss_input, size_t *bytes_written,
+                                        const void *ptr, size_t size) {
+    __builtin_memcpy(&rss_input[*bytes_written], ptr, size);
+    *bytes_written += size;
+}
+
+static inline
+void net_toeplitz_add(__u32 *result,
+                      __u8 *input,
+                      __u32 len
+        , struct toeplitz_key_data_t *key) {
+
+    __u32 accumulator = *result;
+    __u32 leftmost_32_bits = key->leftmost_32_bits;
+    __u32 byte;
+
+    for (byte = 0; byte < HASH_CALCULATION_BUFFER_SIZE; byte++) {
+        __u8 input_byte = input[byte];
+        __u8 key_byte = key->next_byte[byte];
+        __u8 bit;
+
+        for (bit = 0; bit < 8; bit++) {
+            if (input_byte & (1 << 7)) {
+                accumulator ^= leftmost_32_bits;
+            }
+
+            leftmost_32_bits =
+                    (leftmost_32_bits << 1) | ((key_byte & (1 << 7)) >> 7);
+
+            input_byte <<= 1;
+            key_byte <<= 1;
+        }
+    }
+
+    *result = accumulator;
+}
+
+
+static inline int ip6_extension_header_type(__u8 hdr_type)
+{
+    switch (hdr_type) {
+    case IPPROTO_HOPOPTS:
+    case IPPROTO_ROUTING:
+    case IPPROTO_FRAGMENT:
+    case IPPROTO_ICMPV6:
+    case IPPROTO_NONE:
+    case IPPROTO_DSTOPTS:
+    case IPPROTO_MH:
+        return 1;
+    default:
+        return 0;
+    }
+}
+/*
+ * According to https://www.iana.org/assignments/ipv6-parameters/ipv6-parameters.xhtml
+ * we suspect that there are would be no more than 11 extensions in IPv6 header,
+ * also there is 27 TLV options for Destination and Hop-by-hop extensions.
+ * Need to choose reasonable amount of maximum extensions/options we may check to find
+ * ext src/dst.
+ */
+#define IP6_EXTENSIONS_COUNT 11
+#define IP6_OPTIONS_COUNT 30
+
+static inline void parse_ipv6_ext(struct __sk_buff *skb,
+        struct packet_hash_info_t *info,
+        __u8 *l4_protocol, size_t *l4_offset)
+{
+    if (!ip6_extension_header_type(*l4_protocol)) {
+        return;
+    }
+
+    struct ipv6_opt_hdr ext_hdr = {};
+
+    for (unsigned int i = 0; i < IP6_EXTENSIONS_COUNT; ++i) {
+
+        bpf_skb_load_bytes_relative(skb, *l4_offset, &ext_hdr,
+                                    sizeof(ext_hdr), BPF_HDR_START_NET);
+
+        if (*l4_protocol == IPPROTO_ROUTING) {
+            struct ipv6_rt_hdr ext_rt = {};
+
+            bpf_skb_load_bytes_relative(skb, *l4_offset, &ext_rt,
+                                        sizeof(ext_rt), BPF_HDR_START_NET);
+
+            if ((ext_rt.type == IPV6_SRCRT_TYPE_2) &&
+                    (ext_rt.hdrlen == sizeof(struct in6_addr) / 8) &&
+                    (ext_rt.segments_left == 1)) {
+
+                bpf_skb_load_bytes_relative(skb,
+                    *l4_offset + offsetof(struct rt2_hdr, addr),
+                    &info->in6_ext_dst, sizeof(info->in6_ext_dst),
+                    BPF_HDR_START_NET);
+
+                info->is_ipv6_ext_dst = 1;
+            }
+
+        } else if (*l4_protocol == IPPROTO_DSTOPTS) {
+            struct ipv6_opt_t {
+                __u8 type;
+                __u8 length;
+            } __attribute__((packed)) opt = {};
+
+            size_t opt_offset = sizeof(ext_hdr);
+
+            for (unsigned int j = 0; j < IP6_OPTIONS_COUNT; ++j) {
+                bpf_skb_load_bytes_relative(skb, *l4_offset + opt_offset,
+                                        &opt, sizeof(opt), BPF_HDR_START_NET);
+
+                opt_offset += (opt.type == IPV6_TLV_PAD1) ?
+                        1 : opt.length + sizeof(opt);
+
+                if (opt_offset + 1 >= ext_hdr.hdrlen * 8) {
+                    break;
+                }
+
+                if (opt.type == IPV6_TLV_HAO) {
+                    bpf_skb_load_bytes_relative(skb,
+                        *l4_offset + opt_offset + offsetof(struct ipv6_destopt_hao, addr),
+                        &info->is_ipv6_ext_src, sizeof(info->is_ipv6_ext_src),
+                        BPF_HDR_START_NET);
+
+                    info->is_ipv6_ext_src = 1;
+                    break;
+                }
+            }
+        }
+
+        *l4_protocol = ext_hdr.nexthdr;
+        *l4_offset += (ext_hdr.hdrlen + 1) * 8;
+
+        if (!ip6_extension_header_type(ext_hdr.nexthdr)) {
+            return;
+        }
+    }
+}
+
+static __be16 parse_eth_type(struct __sk_buff *skb)
+{
+    unsigned int offset = 12;
+    __be16 ret = 0;
+
+    bpf_skb_load_bytes_relative(skb, offset, &ret, sizeof(ret),
+                                BPF_HDR_START_MAC);
+
+    switch (__be16_to_cpu(ret)) {
+    case ETH_P_8021AD:
+        offset += 4;
+    case ETH_P_8021Q:
+        offset += 4;
+        bpf_skb_load_bytes_relative(skb, offset, &ret, sizeof(ret),
+                                    BPF_HDR_START_MAC);
+    default:
+        break;
+    }
+
+    return ret;
+}
+
+static inline void parse_packet(struct __sk_buff *skb,
+        struct packet_hash_info_t *info)
+{
+    if (!info || !skb) {
+        return;
+    }
+
+    size_t l4_offset = 0;
+    __u8 l4_protocol = 0;
+    __u16 l3_protocol = __be16_to_cpu(parse_eth_type(skb));
+
+    if (l3_protocol == ETH_P_IP) {
+        info->is_ipv4 = 1;
+
+        struct iphdr ip = {};
+        bpf_skb_load_bytes_relative(skb, 0, &ip, sizeof(ip),
+                                    BPF_HDR_START_NET);
+
+        info->in_src = ip.saddr;
+        info->in_dst = ip.daddr;
+
+        l4_protocol = ip.protocol;
+        l4_offset = ip.ihl * 4;
+    } else if (l3_protocol == ETH_P_IPV6) {
+        info->is_ipv6 = 1;
+
+        struct ipv6hdr ip6 = {};
+        bpf_skb_load_bytes_relative(skb, 0, &ip6, sizeof(ip6),
+                                    BPF_HDR_START_NET);
+
+        info->in6_src = ip6.saddr;
+        info->in6_dst = ip6.daddr;
+
+        l4_protocol = ip6.nexthdr;
+        l4_offset = sizeof(ip6);
+
+        parse_ipv6_ext(skb, info, &l4_protocol, &l4_offset);
+    }
+
+    if (l4_protocol != 0) {
+        if (l4_protocol == IPPROTO_TCP) {
+            info->is_tcp = 1;
+
+            struct tcphdr tcp = {};
+            bpf_skb_load_bytes_relative(skb, l4_offset, &tcp, sizeof(tcp),
+                                        BPF_HDR_START_NET);
+
+            info->src_port = tcp.source;
+            info->dst_port = tcp.dest;
+        } else if (l4_protocol == IPPROTO_UDP) { /* TODO: add udplite? */
+            info->is_udp = 1;
+
+            struct udphdr udp = {};
+            bpf_skb_load_bytes_relative(skb, l4_offset, &udp, sizeof(udp),
+                                        BPF_HDR_START_NET);
+
+            info->src_port = udp.source;
+            info->dst_port = udp.dest;
+        }
+    }
+}
+
+static inline __u32 calculate_rss_hash(struct __sk_buff *skb,
+        struct rss_config_t *config, struct toeplitz_key_data_t *toe)
+{
+    __u8 rss_input[HASH_CALCULATION_BUFFER_SIZE] = {};
+    size_t bytes_written = 0;
+    __u32 result = 0;
+    struct packet_hash_info_t packet_info = {};
+
+    parse_packet(skb, &packet_info);
+
+    if (packet_info.is_ipv4) {
+        if (packet_info.is_tcp &&
+            config->hash_types & VIRTIO_NET_RSS_HASH_TYPE_TCPv4) {
+
+            net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                 &packet_info.in_src,
+                                 sizeof(packet_info.in_src));
+            net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                 &packet_info.in_dst,
+                                 sizeof(packet_info.in_dst));
+            net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                 &packet_info.src_port,
+                                 sizeof(packet_info.src_port));
+            net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                 &packet_info.dst_port,
+                                 sizeof(packet_info.dst_port));
+        } else if (packet_info.is_udp &&
+                   config->hash_types & VIRTIO_NET_RSS_HASH_TYPE_UDPv4) {
+
+            net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                 &packet_info.in_src,
+                                 sizeof(packet_info.in_src));
+            net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                 &packet_info.in_dst,
+                                 sizeof(packet_info.in_dst));
+            net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                 &packet_info.src_port,
+                                 sizeof(packet_info.src_port));
+            net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                 &packet_info.dst_port,
+                                 sizeof(packet_info.dst_port));
+        } else if (config->hash_types & VIRTIO_NET_RSS_HASH_TYPE_IPv4) {
+            net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                 &packet_info.in_src,
+                                 sizeof(packet_info.in_src));
+            net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                 &packet_info.in_dst,
+                                 sizeof(packet_info.in_dst));
+        }
+    } else if (packet_info.is_ipv6) {
+        if (packet_info.is_tcp &&
+            config->hash_types & VIRTIO_NET_RSS_HASH_TYPE_TCPv6) {
+
+            if (packet_info.is_ipv6_ext_src &&
+                config->hash_types & VIRTIO_NET_RSS_HASH_TYPE_TCP_EX) {
+
+                net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                     &packet_info.in6_ext_src,
+                                     sizeof(packet_info.in6_ext_src));
+            } else {
+                net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                     &packet_info.in6_src,
+                                     sizeof(packet_info.in6_src));
+            }
+            if (packet_info.is_ipv6_ext_dst &&
+                config->hash_types & VIRTIO_NET_RSS_HASH_TYPE_TCP_EX) {
+
+                net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                     &packet_info.in6_ext_dst,
+                                     sizeof(packet_info.in6_ext_dst));
+            } else {
+                net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                     &packet_info.in6_dst,
+                                     sizeof(packet_info.in6_dst));
+            }
+            net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                 &packet_info.src_port,
+                                 sizeof(packet_info.src_port));
+            net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                 &packet_info.dst_port,
+                                 sizeof(packet_info.dst_port));
+        } else if (packet_info.is_udp &&
+                   config->hash_types & VIRTIO_NET_RSS_HASH_TYPE_UDPv6) {
+
+            if (packet_info.is_ipv6_ext_src &&
+               config->hash_types & VIRTIO_NET_RSS_HASH_TYPE_UDP_EX) {
+
+                net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                     &packet_info.in6_ext_src,
+                                     sizeof(packet_info.in6_ext_src));
+            } else {
+                net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                     &packet_info.in6_src,
+                                     sizeof(packet_info.in6_src));
+            }
+            if (packet_info.is_ipv6_ext_dst &&
+               config->hash_types & VIRTIO_NET_RSS_HASH_TYPE_UDP_EX) {
+
+                net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                     &packet_info.in6_ext_dst,
+                                     sizeof(packet_info.in6_ext_dst));
+            } else {
+                net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                     &packet_info.in6_dst,
+                                     sizeof(packet_info.in6_dst));
+            }
+
+            net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                 &packet_info.src_port,
+                                 sizeof(packet_info.src_port));
+            net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                 &packet_info.dst_port,
+                                 sizeof(packet_info.dst_port));
+
+        } else if (config->hash_types & VIRTIO_NET_RSS_HASH_TYPE_IPv6) {
+            if (packet_info.is_ipv6_ext_src &&
+               config->hash_types & VIRTIO_NET_RSS_HASH_TYPE_IP_EX) {
+
+                net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                     &packet_info.in6_ext_src,
+                                     sizeof(packet_info.in6_ext_src));
+            } else {
+                net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                     &packet_info.in6_src,
+                                     sizeof(packet_info.in6_src));
+            }
+            if (packet_info.is_ipv6_ext_dst &&
+                config->hash_types & VIRTIO_NET_RSS_HASH_TYPE_IP_EX) {
+
+                net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                     &packet_info.in6_ext_dst,
+                                     sizeof(packet_info.in6_ext_dst));
+            } else {
+                net_rx_rss_add_chunk(rss_input, &bytes_written,
+                                     &packet_info.in6_dst,
+                                     sizeof(packet_info.in6_dst));
+            }
+        }
+    }
+
+    if (bytes_written) {
+        net_toeplitz_add(&result, rss_input, bytes_written, toe);
+    }
+
+    return result;
+}
+
+SEC("tun_rss_steering")
+int tun_rss_steering_prog(struct __sk_buff *skb)
+{
+
+    struct rss_config_t *config;
+    struct toeplitz_key_data_t *toe;
+
+    __u32 key = 0;
+    __u32 hash = 0;
+
+    config = bpf_map_lookup_elem(&tap_rss_map_configurations, &key);
+    toe = bpf_map_lookup_elem(&tap_rss_map_toeplitz_key, &key);
+
+    if (config && toe) {
+        if (!config->redirect) {
+            return config->default_queue;
+        }
+
+        hash = calculate_rss_hash(skb, config, toe);
+        if (hash) {
+            __u32 table_idx = hash % config->indirections_len;
+            __u16 *queue = 0;
+
+            queue = bpf_map_lookup_elem(&tap_rss_map_indirection_table,
+                                        &table_idx);
+
+            if (queue) {
+                return *queue;
+            }
+        }
+
+        return config->default_queue;
+    }
+
+    return -1;
+}
+
+char _license[] SEC("license") = "GPL v2";
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v3 4/6] ebpf: Added eBPF RSS loader.
  2021-01-14 21:16 [RFC PATCH v3 0/6] eBPF RSS support for virtio-net Andrew Melnychenko
                   ` (3 preceding siblings ...)
  2021-01-14 21:16 ` [RFC PATCH v3 3/6] ebpf: Added eBPF RSS program Andrew Melnychenko
@ 2021-01-14 21:16 ` Andrew Melnychenko
  2021-01-15  7:02   ` Jason Wang
  2021-01-14 21:16 ` [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net Andrew Melnychenko
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 20+ messages in thread
From: Andrew Melnychenko @ 2021-01-14 21:16 UTC (permalink / raw)
  To: jasowang, mst; +Cc: yan, yuri.benditovich, berrange, qemu-devel

From: Andrew <andrew@daynix.com>

Added function that loads RSS eBPF program.
Added stub functions for RSS eBPF loader.
Added meson and configuration options.

By default, eBPF feature enabled if libbpf is present in the build system.
libbpf checked in configuration shell script and meson script.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
---
 configure               |  33 ++++
 ebpf/ebpf_rss-stub.c    |  40 ++++
 ebpf/ebpf_rss.c         | 165 +++++++++++++++++
 ebpf/ebpf_rss.h         |  44 +++++
 ebpf/meson.build        |   1 +
 ebpf/rss.bpf.skeleton.h | 397 ++++++++++++++++++++++++++++++++++++++++
 ebpf/trace-events       |   4 +
 ebpf/trace.h            |   2 +
 meson.build             |  13 ++
 9 files changed, 699 insertions(+)
 create mode 100644 ebpf/ebpf_rss-stub.c
 create mode 100644 ebpf/ebpf_rss.c
 create mode 100644 ebpf/ebpf_rss.h
 create mode 100644 ebpf/meson.build
 create mode 100644 ebpf/rss.bpf.skeleton.h
 create mode 100644 ebpf/trace-events
 create mode 100644 ebpf/trace.h

diff --git a/configure b/configure
index 5860bdb77b..9d18e941f5 100755
--- a/configure
+++ b/configure
@@ -342,6 +342,7 @@ vhost_vsock="$default_feature"
 vhost_user="no"
 vhost_user_blk_server="auto"
 vhost_user_fs="$default_feature"
+bpf=""
 kvm="auto"
 hax="auto"
 hvf="auto"
@@ -1236,6 +1237,10 @@ for opt do
   ;;
   --enable-membarrier) membarrier="yes"
   ;;
+  --disable-bpf) bpf="no"
+  ;;
+  --enable-bpf) bpf="yes"
+  ;;
   --disable-blobs) blobs="false"
   ;;
   --with-pkgversion=*) pkgversion="$optarg"
@@ -1845,6 +1850,7 @@ disabled with --disable-FEATURE, default is enabled if available
   vhost-user      vhost-user backend support
   vhost-user-blk-server    vhost-user-blk server support
   vhost-vdpa      vhost-vdpa kernel backend support
+  bpf             BPF kernel support
   spice           spice
   rbd             rados block device (rbd)
   libiscsi        iscsi support
@@ -5057,6 +5063,30 @@ else
     membarrier=no
 fi
 
+##########################################
+# check for usable bpf system call
+if test "$bpf" = ""; then
+    have_bpf=no
+    if test "$linux" = "yes" -a "$bigendian" != "yes"; then
+        cat > $TMPC << EOF
+    #include <stdlib.h>
+    #include <bpf/libbpf.h>
+    int main(void) {
+        struct bpf_object *obj = NULL;
+        bpf_object__load(obj);
+        exit(0);
+    }
+EOF
+        if compile_prog "" "-lbpf" ; then
+            have_bpf=yes
+            bpf=yes
+        fi
+    fi
+    if test "$have_bpf" = "no"; then
+      feature_not_found "bpf" "the libbpf is not available"
+    fi
+fi
+
 ##########################################
 # check if rtnetlink.h exists and is useful
 have_rtnetlink=no
@@ -5905,6 +5935,9 @@ fi
 if test "$membarrier" = "yes" ; then
   echo "CONFIG_MEMBARRIER=y" >> $config_host_mak
 fi
+if test "$bpf" = "yes" -a "$bigendian" != "yes" -a "$linux" = "yes" ; then
+  echo "CONFIG_EBPF=y" >> $config_host_mak
+fi
 if test "$signalfd" = "yes" ; then
   echo "CONFIG_SIGNALFD=y" >> $config_host_mak
 fi
diff --git a/ebpf/ebpf_rss-stub.c b/ebpf/ebpf_rss-stub.c
new file mode 100644
index 0000000000..e71e229190
--- /dev/null
+++ b/ebpf/ebpf_rss-stub.c
@@ -0,0 +1,40 @@
+/*
+ * eBPF RSS stub file
+ *
+ * Developed by Daynix Computing LTD (http://www.daynix.com)
+ *
+ * Authors:
+ *  Yuri Benditovich <yuri.benditovich@daynix.com>
+ *
+ * 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)
+{
+
+}
diff --git a/ebpf/ebpf_rss.c b/ebpf/ebpf_rss.c
new file mode 100644
index 0000000000..f7f7102da5
--- /dev/null
+++ b/ebpf/ebpf_rss.c
@@ -0,0 +1,165 @@
+/*
+ * eBPF RSS loader
+ *
+ * Developed by Daynix Computing LTD (http://www.daynix.com)
+ *
+ * Authors:
+ *  Andrew Melnychenko <andrew@daynix.com>
+ *  Yuri Benditovich <yuri.benditovich@daynix.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu/error-report.h"
+
+#include <bpf/libbpf.h>
+#include <bpf/bpf.h>
+
+#include "hw/virtio/virtio-net.h" /* VIRTIO_NET_RSS_MAX_TABLE_LEN */
+
+#include "ebpf/ebpf_rss.h"
+#include "ebpf/rss.bpf.skeleton.h"
+#include "trace.h"
+
+void ebpf_rss_init(struct EBPFRSSContext *ctx)
+{
+    if (ctx != NULL) {
+        ctx->obj = NULL;
+    }
+}
+
+bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx)
+{
+    return ctx != NULL && ctx->obj != NULL;
+}
+
+bool ebpf_rss_load(struct EBPFRSSContext *ctx)
+{
+    struct rss_bpf *rss_bpf_ctx;
+
+    if (ctx == NULL) {
+        return false;
+    }
+
+    rss_bpf_ctx = rss_bpf__open();
+    if (rss_bpf_ctx == NULL) {
+        trace_ebpf_error("eBPF RSS", "can not open eBPF RSS object");
+        goto l_issue;
+    }
+
+    bpf_program__set_socket_filter(rss_bpf_ctx->progs.tun_rss_steering_prog);
+
+    if (rss_bpf__load(rss_bpf_ctx)) {
+        trace_ebpf_error("eBPF RSS", "can not load RSS program");
+        goto l_issue;
+    }
+
+    ctx->obj = rss_bpf_ctx;
+    ctx->program_fd = bpf_program__fd(
+            rss_bpf_ctx->progs.tun_rss_steering_prog);
+    ctx->map_configuration = bpf_map__fd(
+            rss_bpf_ctx->maps.tap_rss_map_configurations);
+    ctx->map_indirections_table = bpf_map__fd(
+            rss_bpf_ctx->maps.tap_rss_map_indirection_table);
+    ctx->map_toeplitz_key = bpf_map__fd(
+            rss_bpf_ctx->maps.tap_rss_map_toeplitz_key);
+
+    return true;
+l_issue:
+    rss_bpf__destroy(rss_bpf_ctx);
+    ctx->obj = NULL;
+
+    return false;
+}
+
+static bool ebpf_rss_set_config(struct EBPFRSSContext *ctx,
+                                struct EBPFRSSConfig *config)
+{
+    uint32_t map_key = 0;
+
+    if (!ebpf_rss_is_loaded(ctx)) {
+        return false;
+    }
+    if (bpf_map_update_elem(ctx->map_configuration,
+                            &map_key, config, 0) < 0) {
+        return false;
+    }
+    return true;
+}
+
+static bool ebpf_rss_set_indirections_table(struct EBPFRSSContext *ctx,
+                                            uint16_t *indirections_table,
+                                            size_t len)
+{
+    uint32_t i = 0;
+
+    if (!ebpf_rss_is_loaded(ctx) || indirections_table == NULL ||
+       len > VIRTIO_NET_RSS_MAX_TABLE_LEN) {
+        return false;
+    }
+
+    for (; i < len; ++i) {
+        if (bpf_map_update_elem(ctx->map_indirections_table, &i,
+                                indirections_table + i, 0) < 0) {
+            return false;
+        }
+    }
+    return true;
+}
+
+static bool ebpf_rss_set_toepliz_key(struct EBPFRSSContext *ctx,
+                                     uint8_t *toeplitz_key)
+{
+    uint32_t map_key = 0;
+
+    /* prepare toeplitz key */
+    uint8_t toe[VIRTIO_NET_RSS_MAX_KEY_SIZE] = {};
+
+    if (!ebpf_rss_is_loaded(ctx) || toeplitz_key == NULL) {
+        return false;
+    }
+    memcpy(toe, toeplitz_key, VIRTIO_NET_RSS_MAX_KEY_SIZE);
+    *(uint32_t *)toe = ntohl(*(uint32_t *)toe);
+
+    if (bpf_map_update_elem(ctx->map_toeplitz_key, &map_key, toe,
+                            0) < 0) {
+        return false;
+    }
+    return true;
+}
+
+bool ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config,
+                      uint16_t *indirections_table, uint8_t *toeplitz_key)
+{
+    if (!ebpf_rss_is_loaded(ctx) || config == NULL ||
+        indirections_table == NULL || toeplitz_key == NULL) {
+        return false;
+    }
+
+    if (!ebpf_rss_set_config(ctx, config)) {
+        return false;
+    }
+
+    if (!ebpf_rss_set_indirections_table(ctx, indirections_table,
+                                      config->indirections_len)) {
+        return false;
+    }
+
+    if (!ebpf_rss_set_toepliz_key(ctx, toeplitz_key)) {
+        return false;
+    }
+
+    return true;
+}
+
+void ebpf_rss_unload(struct EBPFRSSContext *ctx)
+{
+    if (!ebpf_rss_is_loaded(ctx)) {
+        return;
+    }
+
+    rss_bpf__destroy(ctx->obj);
+    ctx->obj = NULL;
+}
diff --git a/ebpf/ebpf_rss.h b/ebpf/ebpf_rss.h
new file mode 100644
index 0000000000..0fcb4e010f
--- /dev/null
+++ b/ebpf/ebpf_rss.h
@@ -0,0 +1,44 @@
+/*
+ * eBPF RSS header
+ *
+ * Developed by Daynix Computing LTD (http://www.daynix.com)
+ *
+ * Authors:
+ *  Andrew Melnychenko <andrew@daynix.com>
+ *  Yuri Benditovich <yuri.benditovich@daynix.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ */
+
+#ifndef QEMU_EBPF_RSS_H
+#define QEMU_EBPF_RSS_H
+
+struct EBPFRSSContext {
+    void *obj;
+    int program_fd;
+    int map_configuration;
+    int map_toeplitz_key;
+    int map_indirections_table;
+};
+
+struct EBPFRSSConfig {
+    uint8_t redirect;
+    uint8_t populate_hash;
+    uint32_t hash_types;
+    uint16_t indirections_len;
+    uint16_t default_queue;
+};
+
+void ebpf_rss_init(struct EBPFRSSContext *ctx);
+
+bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx);
+
+bool ebpf_rss_load(struct EBPFRSSContext *ctx);
+
+bool ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config,
+                      uint16_t *indirections_table, uint8_t *toeplitz_key);
+
+void ebpf_rss_unload(struct EBPFRSSContext *ctx);
+
+#endif /* QEMU_EBPF_RSS_H */
diff --git a/ebpf/meson.build b/ebpf/meson.build
new file mode 100644
index 0000000000..f5bd5a0f01
--- /dev/null
+++ b/ebpf/meson.build
@@ -0,0 +1 @@
+common_ss.add(when: 'CONFIG_EBPF', if_true: files('ebpf_rss.c'), if_false: files('ebpf_rss-stub.c'))
diff --git a/ebpf/rss.bpf.skeleton.h b/ebpf/rss.bpf.skeleton.h
new file mode 100644
index 0000000000..76616a5ca6
--- /dev/null
+++ b/ebpf/rss.bpf.skeleton.h
@@ -0,0 +1,397 @@
+/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
+
+/* THIS FILE IS AUTOGENERATED! */
+#ifndef __RSS_BPF_SKEL_H__
+#define __RSS_BPF_SKEL_H__
+
+#include <stdlib.h>
+#include <bpf/libbpf.h>
+
+struct rss_bpf {
+	struct bpf_object_skeleton *skeleton;
+	struct bpf_object *obj;
+	struct {
+		struct bpf_map *tap_rss_map_configurations;
+		struct bpf_map *tap_rss_map_indirection_table;
+		struct bpf_map *tap_rss_map_toeplitz_key;
+	} maps;
+	struct {
+		struct bpf_program *tun_rss_steering_prog;
+	} progs;
+	struct {
+		struct bpf_link *tun_rss_steering_prog;
+	} links;
+};
+
+static void
+rss_bpf__destroy(struct rss_bpf *obj)
+{
+	if (!obj)
+		return;
+	if (obj->skeleton)
+		bpf_object__destroy_skeleton(obj->skeleton);
+	free(obj);
+}
+
+static inline int
+rss_bpf__create_skeleton(struct rss_bpf *obj);
+
+static inline struct rss_bpf *
+rss_bpf__open_opts(const struct bpf_object_open_opts *opts)
+{
+	struct rss_bpf *obj;
+
+	obj = (struct rss_bpf *)calloc(1, sizeof(*obj));
+	if (!obj)
+		return NULL;
+	if (rss_bpf__create_skeleton(obj))
+		goto err;
+	if (bpf_object__open_skeleton(obj->skeleton, opts))
+		goto err;
+
+	return obj;
+err:
+	rss_bpf__destroy(obj);
+	return NULL;
+}
+
+static inline struct rss_bpf *
+rss_bpf__open(void)
+{
+	return rss_bpf__open_opts(NULL);
+}
+
+static inline int
+rss_bpf__load(struct rss_bpf *obj)
+{
+	return bpf_object__load_skeleton(obj->skeleton);
+}
+
+static inline struct rss_bpf *
+rss_bpf__open_and_load(void)
+{
+	struct rss_bpf *obj;
+
+	obj = rss_bpf__open();
+	if (!obj)
+		return NULL;
+	if (rss_bpf__load(obj)) {
+		rss_bpf__destroy(obj);
+		return NULL;
+	}
+	return obj;
+}
+
+static inline int
+rss_bpf__attach(struct rss_bpf *obj)
+{
+	return bpf_object__attach_skeleton(obj->skeleton);
+}
+
+static inline void
+rss_bpf__detach(struct rss_bpf *obj)
+{
+	return bpf_object__detach_skeleton(obj->skeleton);
+}
+
+static inline int
+rss_bpf__create_skeleton(struct rss_bpf *obj)
+{
+	struct bpf_object_skeleton *s;
+
+	s = (struct bpf_object_skeleton *)calloc(1, sizeof(*s));
+	if (!s)
+		return -1;
+	obj->skeleton = s;
+
+	s->sz = sizeof(*s);
+	s->name = "rss_bpf";
+	s->obj = &obj->obj;
+
+	/* maps */
+	s->map_cnt = 3;
+	s->map_skel_sz = sizeof(*s->maps);
+	s->maps = (struct bpf_map_skeleton *)calloc(s->map_cnt, s->map_skel_sz);
+	if (!s->maps)
+		goto err;
+
+	s->maps[0].name = "tap_rss_map_configurations";
+	s->maps[0].map = &obj->maps.tap_rss_map_configurations;
+
+	s->maps[1].name = "tap_rss_map_indirection_table";
+	s->maps[1].map = &obj->maps.tap_rss_map_indirection_table;
+
+	s->maps[2].name = "tap_rss_map_toeplitz_key";
+	s->maps[2].map = &obj->maps.tap_rss_map_toeplitz_key;
+
+	/* programs */
+	s->prog_cnt = 1;
+	s->prog_skel_sz = sizeof(*s->progs);
+	s->progs = (struct bpf_prog_skeleton *)calloc(s->prog_cnt, s->prog_skel_sz);
+	if (!s->progs)
+		goto err;
+
+	s->progs[0].name = "tun_rss_steering_prog";
+	s->progs[0].prog = &obj->progs.tun_rss_steering_prog;
+	s->progs[0].link = &obj->links.tun_rss_steering_prog;
+
+	s->data_sz = 7088;
+	s->data = (void *)"\
+\x7f\x45\x4c\x46\x02\x01\x01\0\0\0\0\0\0\0\0\0\x01\0\xf7\0\x01\0\0\0\0\0\0\0\0\
+\0\0\0\0\0\0\0\0\0\0\0\x30\x19\0\0\0\0\0\0\0\0\0\0\x40\0\0\0\0\0\x40\0\x0a\0\
+\x01\0\x7b\x1a\x38\xff\0\0\0\0\xb7\x01\0\0\0\0\0\0\x63\x1a\x4c\xff\0\0\0\0\xbf\
+\xa6\0\0\0\0\0\0\x07\x06\0\0\x4c\xff\xff\xff\x18\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\
+\0\xbf\x62\0\0\0\0\0\0\x85\0\0\0\x01\0\0\0\xbf\x07\0\0\0\0\0\0\x18\x01\0\0\0\0\
+\0\0\0\0\0\0\0\0\0\0\xbf\x62\0\0\0\0\0\0\x85\0\0\0\x01\0\0\0\xbf\x08\0\0\0\0\0\
+\0\x18\0\0\0\xff\xff\xff\xff\0\0\0\0\0\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f\0\0\0\0\0\xb7\x01\0\0\x01\0\0\0\x73\x1a\
+\x52\xff\0\0\0\0\xb7\x01\0\0\0\0\0\0\x7b\x1a\xd0\xff\0\0\0\0\xbf\xa3\0\0\0\0\0\
+\0\x07\x03\0\0\xd0\xff\xff\xff\x79\xa1\x38\xff\0\0\0\0\x79\xa2\x40\xff\0\0\0\0\
+\xb7\x04\0\0\x08\0\0\0\xb7\x05\0\0\x01\0\0\0\x85\0\0\0\x44\0\0\0\x69\xa1\xd0\
+\xff\0\0\0\0\x6b\x1a\x56\xff\0\0\0\0\x69\xa1\xd2\xff\0\0\0\0\x6b\x1a\x58\xff\0\
+\0\0\0\x71\xa1\x50\xff\0\0\0\0\x15\x01\x0f\0\0\0\0\0\x61\x71\x04\0\0\0\0\0\x71\
+\xa2\x53\xff\0\0\0\0\x15\x02\x41\0\0\0\0\0\xbf\x12\0\0\0\0\0\0\x57\x02\0\0\x02\
+\0\0\0\x15\x02\x3e\0\0\0\0\0\x61\xa1\x5c\xff\0\0\0\0\x63\x1a\xa0\xff\0\0\0\0\
+\x61\xa1\x60\xff\0\0\0\0\x63\x1a\xa4\xff\0\0\0\0\x69\xa1\x56\xff\0\0\0\0\x6b\
+\x1a\xa8\xff\0\0\0\0\x69\xa1\x58\xff\0\0\0\0\x6b\x1a\xaa\xff\0\0\0\0\x05\0\xf4\
+\0\0\0\0\0\x71\xa1\x51\xff\0\0\0\0\x15\x01\x5f\x01\0\0\0\0\x61\x71\x04\0\0\0\0\
+\0\x71\xa2\x53\xff\0\0\0\0\x15\x02\x3d\0\0\0\0\0\xbf\x12\0\0\0\0\0\0\x57\x02\0\
+\0\x10\0\0\0\x15\x02\x3a\0\0\0\0\0\xbf\xa2\0\0\0\0\0\0\x07\x02\0\0\x5c\xff\xff\
+\xff\x71\xa4\x54\xff\0\0\0\0\xbf\x23\0\0\0\0\0\0\x15\x04\x02\0\0\0\0\0\xbf\xa3\
+\0\0\0\0\0\0\x07\x03\0\0\x7c\xff\xff\xff\x67\x01\0\0\x38\0\0\0\xc7\x01\0\0\x38\
+\0\0\0\x65\x01\x01\0\xff\xff\xff\xff\xbf\x32\0\0\0\0\0\0\xbf\xa3\0\0\0\0\0\0\
+\x07\x03\0\0\x6c\xff\xff\xff\x71\xa5\x55\xff\0\0\0\0\xbf\x34\0\0\0\0\0\0\x15\
+\x05\x02\0\0\0\0\0\xbf\xa4\0\0\0\0\0\0\x07\x04\0\0\x8c\xff\xff\xff\x65\x01\x01\
+\0\xff\xff\xff\xff\xbf\x43\0\0\0\0\0\0\x61\x21\x04\0\0\0\0\0\x67\x01\0\0\x20\0\
+\0\0\x61\x24\0\0\0\0\0\0\x4f\x41\0\0\0\0\0\0\x7b\x1a\xa0\xff\0\0\0\0\x61\x21\
+\x08\0\0\0\0\0\x61\x22\x0c\0\0\0\0\0\x67\x02\0\0\x20\0\0\0\x4f\x12\0\0\0\0\0\0\
+\x7b\x2a\xa8\xff\0\0\0\0\x61\x31\0\0\0\0\0\0\x61\x32\x04\0\0\0\0\0\x61\x34\x08\
+\0\0\0\0\0\x61\x33\x0c\0\0\0\0\0\x69\xa5\x58\xff\0\0\0\0\x6b\x5a\xc2\xff\0\0\0\
+\0\x69\xa5\x56\xff\0\0\0\0\x6b\x5a\xc0\xff\0\0\0\0\x67\x03\0\0\x20\0\0\0\x4f\
+\x43\0\0\0\0\0\0\x7b\x3a\xb8\xff\0\0\0\0\x67\x02\0\0\x20\0\0\0\x4f\x12\0\0\0\0\
+\0\0\x7b\x2a\xb0\xff\0\0\0\0\x05\0\xbf\0\0\0\0\0\x71\xa2\x52\xff\0\0\0\0\x15\
+\x02\x04\0\0\0\0\0\xbf\x12\0\0\0\0\0\0\x57\x02\0\0\x04\0\0\0\x15\x02\x01\0\0\0\
+\0\0\x05\0\xbc\xff\0\0\0\0\x57\x01\0\0\x01\0\0\0\x15\x01\x24\x01\0\0\0\0\x61\
+\xa1\x5c\xff\0\0\0\0\x63\x1a\xa0\xff\0\0\0\0\x61\xa1\x60\xff\0\0\0\0\x63\x1a\
+\xa4\xff\0\0\0\0\x05\0\xb2\0\0\0\0\0\x71\xa2\x52\xff\0\0\0\0\x15\x02\x16\0\0\0\
+\0\0\xbf\x12\0\0\0\0\0\0\x57\x02\0\0\x20\0\0\0\x15\x02\x13\0\0\0\0\0\xbf\xa2\0\
+\0\0\0\0\0\x07\x02\0\0\x5c\xff\xff\xff\x71\xa4\x54\xff\0\0\0\0\xbf\x23\0\0\0\0\
+\0\0\x15\x04\x02\0\0\0\0\0\xbf\xa3\0\0\0\0\0\0\x07\x03\0\0\x7c\xff\xff\xff\x57\
+\x01\0\0\0\x01\0\0\x15\x01\x01\0\0\0\0\0\xbf\x32\0\0\0\0\0\0\xbf\xa3\0\0\0\0\0\
+\0\x07\x03\0\0\x6c\xff\xff\xff\x71\xa5\x55\xff\0\0\0\0\xbf\x34\0\0\0\0\0\0\x15\
+\x05\x02\0\0\0\0\0\xbf\xa4\0\0\0\0\0\0\x07\x04\0\0\x8c\xff\xff\xff\x15\x01\xc3\
+\xff\0\0\0\0\x05\0\xc1\xff\0\0\0\0\xbf\x12\0\0\0\0\0\0\x57\x02\0\0\x08\0\0\0\
+\x15\x02\x04\x01\0\0\0\0\xbf\xa2\0\0\0\0\0\0\x07\x02\0\0\x5c\xff\xff\xff\x71\
+\xa4\x54\xff\0\0\0\0\xbf\x23\0\0\0\0\0\0\x15\x04\x02\0\0\0\0\0\xbf\xa3\0\0\0\0\
+\0\0\x07\x03\0\0\x7c\xff\xff\xff\x57\x01\0\0\x40\0\0\0\x15\x01\x01\0\0\0\0\0\
+\xbf\x32\0\0\0\0\0\0\x61\x23\x04\0\0\0\0\0\x67\x03\0\0\x20\0\0\0\x61\x24\0\0\0\
+\0\0\0\x4f\x43\0\0\0\0\0\0\x7b\x3a\xa0\xff\0\0\0\0\x61\x23\x08\0\0\0\0\0\x61\
+\x22\x0c\0\0\0\0\0\x67\x02\0\0\x20\0\0\0\x4f\x32\0\0\0\0\0\0\x7b\x2a\xa8\xff\0\
+\0\0\0\x15\x01\x78\0\0\0\0\0\x71\xa1\x55\xff\0\0\0\0\x15\x01\x76\0\0\0\0\0\x61\
+\xa1\x98\xff\0\0\0\0\x67\x01\0\0\x20\0\0\0\x61\xa2\x94\xff\0\0\0\0\x4f\x21\0\0\
+\0\0\0\0\x7b\x1a\xb8\xff\0\0\0\0\x61\xa1\x90\xff\0\0\0\0\x67\x01\0\0\x20\0\0\0\
+\x61\xa2\x8c\xff\0\0\0\0\x05\0\x75\0\0\0\0\0\x15\x06\x54\xff\x87\0\0\0\x05\0\
+\x3e\0\0\0\0\0\x0f\x96\0\0\0\0\0\0\xbf\x62\0\0\0\0\0\0\x07\x02\0\0\x01\0\0\0\
+\x71\xa3\xff\xff\0\0\0\0\x67\x03\0\0\x03\0\0\0\x3d\x32\x22\0\0\0\0\0\x55\x01\
+\x0c\0\xc9\0\0\0\x79\xa1\x40\xff\0\0\0\0\x0f\x16\0\0\0\0\0\0\x07\x06\0\0\x02\0\
+\0\0\x79\xa1\x38\xff\0\0\0\0\xbf\x62\0\0\0\0\0\0\x79\xa3\x18\xff\0\0\0\0\xb7\
+\x04\0\0\x01\0\0\0\xb7\x05\0\0\x01\0\0\0\x85\0\0\0\x44\0\0\0\xb7\x01\0\0\x01\0\
+\0\0\x73\x1a\x54\xff\0\0\0\0\x05\0\x15\0\0\0\0\0\x07\x08\0\0\xff\xff\xff\xff\
+\xbf\x81\0\0\0\0\0\0\x67\x01\0\0\x20\0\0\0\x77\x01\0\0\x20\0\0\0\xbf\x69\0\0\0\
+\0\0\0\x15\x01\x0f\0\0\0\0\0\xbf\x92\0\0\0\0\0\0\x79\xa1\x40\xff\0\0\0\0\x0f\
+\x12\0\0\0\0\0\0\xbf\xa3\0\0\0\0\0\0\x07\x03\0\0\xf8\xff\xff\xff\xb7\x06\0\0\
+\x01\0\0\0\x79\xa1\x38\xff\0\0\0\0\xb7\x04\0\0\x02\0\0\0\xb7\x05\0\0\x01\0\0\0\
+\x85\0\0\0\x44\0\0\0\x71\xa1\xf8\xff\0\0\0\0\x15\x01\xdb\xff\0\0\0\0\x71\xa6\
+\xf9\xff\0\0\0\0\x07\x06\0\0\x02\0\0\0\x05\0\xd8\xff\0\0\0\0\x79\xa8\x30\xff\0\
+\0\0\0\x79\xa9\x28\xff\0\0\0\0\x71\xa1\xff\xff\0\0\0\0\x67\x01\0\0\x03\0\0\0\
+\x79\xa2\x40\xff\0\0\0\0\x0f\x12\0\0\0\0\0\0\x07\x02\0\0\x08\0\0\0\x7b\x2a\x40\
+\xff\0\0\0\0\x71\xa6\xfe\xff\0\0\0\0\x25\x06\x37\0\x3c\0\0\0\xb7\x01\0\0\x01\0\
+\0\0\x6f\x61\0\0\0\0\0\0\x18\x02\0\0\x01\0\0\0\0\0\0\0\0\x18\0\x1c\x5f\x21\0\0\
+\0\0\0\0\x55\x01\x01\0\0\0\0\0\x05\0\x30\0\0\0\0\0\x07\x07\0\0\x01\0\0\0\xbf\
+\x71\0\0\0\0\0\0\x67\x01\0\0\x20\0\0\0\x77\x01\0\0\x20\0\0\0\x55\x01\x02\0\x0b\
+\0\0\0\x79\xa7\x10\xff\0\0\0\0\x05\0\xda\xfe\0\0\0\0\xbf\xa3\0\0\0\0\0\0\x07\
+\x03\0\0\xfe\xff\xff\xff\x79\xa1\x38\xff\0\0\0\0\x79\xa2\x40\xff\0\0\0\0\xb7\
+\x04\0\0\x02\0\0\0\xb7\x05\0\0\x01\0\0\0\x85\0\0\0\x44\0\0\0\xbf\x61\0\0\0\0\0\
+\0\x15\x01\x1b\0\x3c\0\0\0\x55\x01\xe0\xff\x2b\0\0\0\xb7\x01\0\0\0\0\0\0\x63\
+\x1a\xf8\xff\0\0\0\0\xbf\xa3\0\0\0\0\0\0\x07\x03\0\0\xf8\xff\xff\xff\x79\xa6\
+\x38\xff\0\0\0\0\xbf\x61\0\0\0\0\0\0\x79\xa2\x40\xff\0\0\0\0\xb7\x04\0\0\x04\0\
+\0\0\xb7\x05\0\0\x01\0\0\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\0\x14\0\0\0\0\0\0\0\x40\0\0\0\x12\0\x03\0\0\0\0\0\0\0\0\
+\0\x20\x11\0\0\0\0\0\0\x28\0\0\0\0\0\0\0\x01\0\0\0\x31\0\0\0\x50\0\0\0\0\0\0\0\
+\x01\0\0\0\x33\0\0\0\xe0\x10\0\0\0\0\0\0\x01\0\0\0\x32\0\0\0\x1c\0\0\0\0\0\0\0\
+\x01\0\0\0\x2f\0\0\0\0\x74\x61\x70\x5f\x72\x73\x73\x5f\x6d\x61\x70\x5f\x74\x6f\
+\x65\x70\x6c\x69\x74\x7a\x5f\x6b\x65\x79\0\x2e\x74\x65\x78\x74\0\x6d\x61\x70\
+\x73\0\x74\x61\x70\x5f\x72\x73\x73\x5f\x6d\x61\x70\x5f\x63\x6f\x6e\x66\x69\x67\
+\x75\x72\x61\x74\x69\x6f\x6e\x73\0\x74\x75\x6e\x5f\x72\x73\x73\x5f\x73\x74\x65\
+\x65\x72\x69\x6e\x67\x5f\x70\x72\x6f\x67\0\x2e\x72\x65\x6c\x74\x75\x6e\x5f\x72\
+\x73\x73\x5f\x73\x74\x65\x65\x72\x69\x6e\x67\0\x5f\x6c\x69\x63\x65\x6e\x73\x65\
+\0\x2e\x72\x65\x6c\x2e\x65\x68\x5f\x66\x72\x61\x6d\x65\0\x74\x61\x70\x5f\x72\
+\x73\x73\x5f\x6d\x61\x70\x5f\x69\x6e\x64\x69\x72\x65\x63\x74\x69\x6f\x6e\x5f\
+\x74\x61\x62\x6c\x65\0\x72\x73\x73\x2e\x62\x70\x66\x2e\x63\0\x2e\x73\x74\x72\
+\x74\x61\x62\0\x2e\x73\x79\x6d\x74\x61\x62\0\x4c\x42\x42\x30\x5f\x39\0\x4c\x42\
+\x42\x30\x5f\x38\x39\0\x4c\x42\x42\x30\x5f\x37\x39\0\x4c\x42\x42\x30\x5f\x36\
+\x39\0\x4c\x42\x42\x30\x5f\x35\x39\0\x4c\x42\x42\x30\x5f\x34\x39\0\x4c\x42\x42\
+\x30\x5f\x33\x39\0\x4c\x42\x42\x30\x5f\x32\x39\0\x4c\x42\x42\x30\x5f\x38\0\x4c\
+\x42\x42\x30\x5f\x38\x38\0\x4c\x42\x42\x30\x5f\x35\x38\0\x4c\x42\x42\x30\x5f\
+\x33\x38\0\x4c\x42\x42\x30\x5f\x38\x37\0\x4c\x42\x42\x30\x5f\x36\x37\0\x4c\x42\
+\x42\x30\x5f\x34\x37\0\x4c\x42\x42\x30\x5f\x37\x36\0\x4c\x42\x42\x30\x5f\x35\
+\x36\0\x4c\x42\x42\x30\x5f\x32\x36\0\x4c\x42\x42\x30\x5f\x31\x36\0\x4c\x42\x42\
+\x30\x5f\x38\x35\0\x4c\x42\x42\x30\x5f\x36\x35\0\x4c\x42\x42\x30\x5f\x33\x35\0\
+\x4c\x42\x42\x30\x5f\x31\x35\0\x4c\x42\x42\x30\x5f\x34\0\x4c\x42\x42\x30\x5f\
+\x38\x34\0\x4c\x42\x42\x30\x5f\x37\x34\0\x4c\x42\x42\x30\x5f\x35\x34\0\x4c\x42\
+\x42\x30\x5f\x34\x34\0\x4c\x42\x42\x30\x5f\x33\x34\0\x4c\x42\x42\x30\x5f\x32\
+\x34\0\x4c\x42\x42\x30\x5f\x34\x33\0\x4c\x42\x42\x30\x5f\x33\x33\0\x4c\x42\x42\
+\x30\x5f\x32\x33\0\x4c\x42\x42\x30\x5f\x31\x33\0\x4c\x42\x42\x30\x5f\x38\x32\0\
+\x4c\x42\x42\x30\x5f\x32\x32\0\x4c\x42\x42\x30\x5f\x31\x32\0\x4c\x42\x42\x30\
+\x5f\x38\x31\0\x4c\x42\x42\x30\x5f\x37\x31\0\x4c\x42\x42\x30\x5f\x36\x31\0\x4c\
+\x42\x42\x30\x5f\x33\x31\0\x4c\x42\x42\x30\x5f\x38\x30\0\x4c\x42\x42\x30\x5f\
+\x36\x30\0\x4c\x42\x42\x30\x5f\x34\x30\0\x4c\x42\x42\x30\x5f\x33\x30\0\0\0\0\0\
+\0\0\0\0\0\0\0\0\0\0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0\0\0\x30\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x08\0\0\
+\0\0\0\0\0\0\0\0\0\0\0\0\0\x74\0\0\0\x09\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\
+\0\x17\0\0\0\0\0\0\x10\0\0\0\0\0\0\0\x09\0\0\0\x07\0\0\0\x08\0\0\0\0\0\0\0\x10\
+\0\0\0\0\0\0\0\xb2\0\0\0\x02\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\xd8\x11\0\0\
+\0\0\0\0\xf8\x04\0\0\0\0\0\0\x01\0\0\0\x30\0\0\0\x08\0\0\0\0\0\0\0\x18\0\0\0\0\
+\0\0\0";
+
+	return 0;
+err:
+	bpf_object__destroy_skeleton(s);
+	return -1;
+}
+
+#endif /* __RSS_BPF_SKEL_H__ */
diff --git a/ebpf/trace-events b/ebpf/trace-events
new file mode 100644
index 0000000000..411b1e2be3
--- /dev/null
+++ b/ebpf/trace-events
@@ -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"
diff --git a/ebpf/trace.h b/ebpf/trace.h
new file mode 100644
index 0000000000..ad570e6691
--- /dev/null
+++ b/ebpf/trace.h
@@ -0,0 +1,2 @@
+#include "trace/trace-ebpf.h"
+
diff --git a/meson.build b/meson.build
index 563688d682..27e41690e7 100644
--- a/meson.build
+++ b/meson.build
@@ -968,6 +968,13 @@ if not get_option('fuse_lseek').disabled()
   endif
 endif
 
+# libbpf
+libbpf = not_found
+if 'CONFIG_EBPF' in config_host
+  libbpf = cc.find_library('bpf', required: true)
+
+endif
+
 if get_option('cfi')
   cfi_flags=[]
   # Check for dependency on LTO
@@ -1685,6 +1692,7 @@ if have_system
     'backends',
     'backends/tpm',
     'chardev',
+    'ebpf',
     'hw/9pfs',
     'hw/acpi',
     'hw/alpha',
@@ -1850,6 +1858,9 @@ subdir('accel')
 subdir('plugins')
 subdir('bsd-user')
 subdir('linux-user')
+subdir('ebpf')
+
+common_ss.add(libbpf)
 
 bsd_user_ss.add(files('gdbstub.c'))
 specific_ss.add_all(when: 'CONFIG_BSD_USER', if_true: bsd_user_ss)
@@ -2415,6 +2426,7 @@ summary_info += {'vhost-user support': config_host.has_key('CONFIG_VHOST_USER')}
 summary_info += {'vhost-user-blk server support': have_vhost_user_blk_server}
 summary_info += {'vhost-user-fs support': config_host.has_key('CONFIG_VHOST_USER_FS')}
 summary_info += {'vhost-vdpa support': config_host.has_key('CONFIG_VHOST_VDPA')}
+summary_info += {'bpf support': config_host.has_key('CONFIG_EBPF')}
 summary_info += {'Trace backends':    config_host['TRACE_BACKENDS']}
 if config_host['TRACE_BACKENDS'].split().contains('simple')
   summary_info += {'Trace output file': config_host['CONFIG_TRACE_FILE'] + '-<pid>'}
@@ -2516,3 +2528,4 @@ if not supported_oses.contains(targetos)
   message('if you care about QEMU on this platform you should contact')
   message('us upstream at qemu-devel@nongnu.org.')
 endif
+
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net.
  2021-01-14 21:16 [RFC PATCH v3 0/6] eBPF RSS support for virtio-net Andrew Melnychenko
                   ` (4 preceding siblings ...)
  2021-01-14 21:16 ` [RFC PATCH v3 4/6] ebpf: Added eBPF RSS loader Andrew Melnychenko
@ 2021-01-14 21:16 ` Andrew Melnychenko
  2021-01-15  7:20   ` Jason Wang
  2021-01-14 21:16 ` [RFC PATCH v3 6/6] docs: Added eBPF documentation Andrew Melnychenko
  2021-01-15  7:27 ` [RFC PATCH v3 0/6] eBPF RSS support for virtio-net Jason Wang
  7 siblings, 1 reply; 20+ messages in thread
From: Andrew Melnychenko @ 2021-01-14 21:16 UTC (permalink / raw)
  To: jasowang, mst; +Cc: yan, yuri.benditovich, berrange, qemu-devel

From: Andrew <andrew@daynix.com>

When RSS is enabled the device tries to load the eBPF program
to select RX virtqueue in the TUN. If eBPF can be loaded
the RSS will function also with vhost (works with kernel 5.8 and later).
Software RSS is used as a fallback with vhost=off when eBPF can't be loaded
or when hash population requested by the guest.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
---
 hw/net/vhost_net.c             |   2 +
 hw/net/virtio-net.c            | 125 +++++++++++++++++++++++++++++++--
 include/hw/virtio/virtio-net.h |   4 ++
 net/vhost-vdpa.c               |   2 +
 4 files changed, 129 insertions(+), 4 deletions(-)

diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
index 24d555e764..16124f99c3 100644
--- a/hw/net/vhost_net.c
+++ b/hw/net/vhost_net.c
@@ -71,6 +71,8 @@ static const int user_feature_bits[] = {
     VIRTIO_NET_F_MTU,
     VIRTIO_F_IOMMU_PLATFORM,
     VIRTIO_F_RING_PACKED,
+    VIRTIO_NET_F_RSS,
+    VIRTIO_NET_F_HASH_REPORT,
 
     /* This bit implies RARP isn't sent by QEMU out of band */
     VIRTIO_NET_F_GUEST_ANNOUNCE,
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 09ceb02c9d..37016fc73a 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -691,6 +691,19 @@ static void virtio_net_set_queues(VirtIONet *n)
 
 static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue);
 
+static uint64_t fix_ebpf_vhost_features(uint64_t features)
+{
+    /* If vhost=on & CONFIG_EBPF doesn't set - disable RSS feature */
+    uint64_t ret = features;
+#ifndef CONFIG_EBPF
+    virtio_clear_feature(&ret, VIRTIO_NET_F_RSS);
+#endif
+    /* for now, there is no solution for populating the hash from eBPF */
+    virtio_clear_feature(&ret, VIRTIO_NET_F_HASH_REPORT);
+
+    return ret;
+}
+
 static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
                                         Error **errp)
 {
@@ -725,9 +738,9 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
         return features;
     }
 
-    virtio_clear_feature(&features, VIRTIO_NET_F_RSS);
-    virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT);
-    features = vhost_net_get_features(get_vhost_net(nc->peer), features);
+    features = fix_ebpf_vhost_features(
+            vhost_net_get_features(get_vhost_net(nc->peer), features));
+
     vdev->backend_features = features;
 
     if (n->mtu_bypass_backend &&
@@ -1151,12 +1164,79 @@ static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd,
     }
 }
 
+static void virtio_net_detach_epbf_rss(VirtIONet *n);
+
 static void virtio_net_disable_rss(VirtIONet *n)
 {
     if (n->rss_data.enabled) {
         trace_virtio_net_rss_disable();
     }
     n->rss_data.enabled = false;
+
+    virtio_net_detach_epbf_rss(n);
+}
+
+static bool virtio_net_attach_ebpf_to_backend(NICState *nic, int prog_fd)
+{
+    NetClientState *nc = qemu_get_peer(qemu_get_queue(nic), 0);
+    if (nc == NULL || nc->info->set_steering_ebpf == NULL) {
+        return false;
+    }
+
+    return nc->info->set_steering_ebpf(nc, prog_fd);
+}
+
+static void rss_data_to_rss_config(struct VirtioNetRssData *data,
+                                   struct EBPFRSSConfig *config)
+{
+    config->redirect = data->redirect;
+    config->populate_hash = data->populate_hash;
+    config->hash_types = data->hash_types;
+    config->indirections_len = data->indirections_len;
+    config->default_queue = data->default_queue;
+}
+
+static bool virtio_net_attach_epbf_rss(VirtIONet *n)
+{
+    struct EBPFRSSConfig config = {};
+
+    if (!ebpf_rss_is_loaded(&n->ebpf_rss)) {
+        return false;
+    }
+
+    rss_data_to_rss_config(&n->rss_data, &config);
+
+    if (!ebpf_rss_set_all(&n->ebpf_rss, &config,
+                          n->rss_data.indirections_table, n->rss_data.key)) {
+        return false;
+    }
+
+    if (!virtio_net_attach_ebpf_to_backend(n->nic, n->ebpf_rss.program_fd)) {
+        return false;
+    }
+
+    return true;
+}
+
+static void virtio_net_detach_epbf_rss(VirtIONet *n)
+{
+    virtio_net_attach_ebpf_to_backend(n->nic, -1);
+}
+
+static bool virtio_net_load_ebpf(VirtIONet *n)
+{
+    if (!virtio_net_attach_ebpf_to_backend(n->nic, -1)) {
+        /* backend does't support steering ebpf */
+        return false;
+    }
+
+    return ebpf_rss_load(&n->ebpf_rss);
+}
+
+static void virtio_net_unload_ebpf(VirtIONet *n)
+{
+    virtio_net_attach_ebpf_to_backend(n->nic, -1);
+    ebpf_rss_unload(&n->ebpf_rss);
 }
 
 static uint16_t virtio_net_handle_rss(VirtIONet *n,
@@ -1271,6 +1351,25 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n,
         goto error;
     }
     n->rss_data.enabled = true;
+
+    if (!n->rss_data.populate_hash) {
+        if (!virtio_net_attach_epbf_rss(n)) {
+            /* EBPF must be loaded for vhost */
+            if (get_vhost_net(qemu_get_queue(n->nic)->peer)) {
+                warn_report("Can't load eBPF RSS for vhost");
+                goto error;
+            }
+            /* fallback to software RSS */
+            warn_report("Can't load eBPF RSS - fallback to software RSS");
+            n->rss_data.enabled_software_rss = true;
+        }
+    } else {
+        /* use software RSS for hash populating */
+        /* and detach eBPF if was loaded before */
+        virtio_net_detach_epbf_rss(n);
+        n->rss_data.enabled_software_rss = true;
+    }
+
     trace_virtio_net_rss_enable(n->rss_data.hash_types,
                                 n->rss_data.indirections_len,
                                 temp.b);
@@ -1656,7 +1755,7 @@ static ssize_t virtio_net_receive_rcu(NetClientState *nc, const uint8_t *buf,
         return -1;
     }
 
-    if (!no_rss && n->rss_data.enabled) {
+    if (!no_rss && n->rss_data.enabled && n->rss_data.enabled_software_rss) {
         int index = virtio_net_process_rss(nc, buf, size);
         if (index >= 0) {
             NetClientState *nc2 = qemu_get_subqueue(n->nic, index);
@@ -2760,6 +2859,18 @@ static int virtio_net_post_load_device(void *opaque, int version_id)
     }
 
     if (n->rss_data.enabled) {
+        n->rss_data.enabled_software_rss = n->rss_data.populate_hash;
+        if (!n->rss_data.populate_hash) {
+            if (!virtio_net_attach_epbf_rss(n)) {
+                if (get_vhost_net(qemu_get_queue(n->nic)->peer)) {
+                    error_report("Can't post-load eBPF RSS for vhost");
+                } else {
+                    warn_report("Can't post-load eBPF RSS - fallback to software RSS");
+                    n->rss_data.enabled_software_rss = true;
+                }
+            }
+        }
+
         trace_virtio_net_rss_enable(n->rss_data.hash_types,
                                     n->rss_data.indirections_len,
                                     sizeof(n->rss_data.key));
@@ -3336,6 +3447,8 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
     n->qdev = dev;
 
     net_rx_pkt_init(&n->rx_pkt, false);
+
+    virtio_net_load_ebpf(n);
 }
 
 static void virtio_net_device_unrealize(DeviceState *dev)
@@ -3344,6 +3457,8 @@ static void virtio_net_device_unrealize(DeviceState *dev)
     VirtIONet *n = VIRTIO_NET(dev);
     int i, max_queues;
 
+    virtio_net_unload_ebpf(n);
+
     /* This will stop vhost backend if appropriate. */
     virtio_net_set_status(vdev, 0);
 
@@ -3386,6 +3501,8 @@ static void virtio_net_instance_init(Object *obj)
     device_add_bootindex_property(obj, &n->nic_conf.bootindex,
                                   "bootindex", "/ethernet-phy@0",
                                   DEVICE(n));
+
+    ebpf_rss_init(&n->ebpf_rss);
 }
 
 static int virtio_net_pre_save(void *opaque)
diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h
index 7e96d193aa..824a69c23f 100644
--- a/include/hw/virtio/virtio-net.h
+++ b/include/hw/virtio/virtio-net.h
@@ -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,
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index fe659ec9e2..8b14215549 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -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
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [RFC PATCH v3 6/6] docs: Added eBPF documentation.
  2021-01-14 21:16 [RFC PATCH v3 0/6] eBPF RSS support for virtio-net Andrew Melnychenko
                   ` (5 preceding siblings ...)
  2021-01-14 21:16 ` [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net Andrew Melnychenko
@ 2021-01-14 21:16 ` Andrew Melnychenko
  2021-01-15  7:24   ` Jason Wang
  2021-01-15  7:27 ` [RFC PATCH v3 0/6] eBPF RSS support for virtio-net Jason Wang
  7 siblings, 1 reply; 20+ messages in thread
From: Andrew Melnychenko @ 2021-01-14 21:16 UTC (permalink / raw)
  To: jasowang, mst; +Cc: yan, yuri.benditovich, berrange, qemu-devel

From: Andrew <andrew@daynix.com>

Also, added maintainers information.

Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
---
 MAINTAINERS       |   8 +++
 docs/ebpf_rss.rst | 125 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 133 insertions(+)
 create mode 100644 docs/ebpf_rss.rst

diff --git a/MAINTAINERS b/MAINTAINERS
index 4be087b88e..4aafdfce2c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3173,6 +3173,14 @@ S: Maintained
 F: hw/semihosting/
 F: include/hw/semihosting/
 
+EBPF:
+M: Jason Wang <jasowang@redhat.com>
+R: Andrew Melnychenko <andrew@daynix.com>
+R: Yuri Benditovich <yuri.benditovich@daynix.com>
+S: Maintained
+F: ebpf/*
+F: tools/ebpf/*
+
 Build and test automation
 -------------------------
 Build and test automation
diff --git a/docs/ebpf_rss.rst b/docs/ebpf_rss.rst
new file mode 100644
index 0000000000..5beecfe33f
--- /dev/null
+++ b/docs/ebpf_rss.rst
@@ -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 'linuxhdrs' in Makefile.ebpf to reflect the location of the kernel source tree
+
+        $ cd 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 tun_rss_steering.h. Returns 'true' on success. After that, program_fd can be used to set steering for TAP.
+- `ebpf_rss_set_all()` - sets values for eBPF maps. `indirections_table` length is in EBPFRSSConfig. `toeplitz_key` is VIRTIO_NET_RSS_MAX_KEY_SIZE aka 40 bytes array.
+- `ebpf_rss_unload()` - close all file descriptors and set ctx to NULL.
+
+Simplified eBPF RSS workflow:
+
+.. code:: C
+
+    struct EBPFRSSConfig config;
+    config.redirect = 1;
+    config.hash_types = VIRTIO_NET_RSS_HASH_TYPE_UDPv4 | VIRTIO_NET_RSS_HASH_TYPE_TCPv4;
+    config.indirections_len = VIRTIO_NET_RSS_MAX_TABLE_LEN;
+    config.default_queue = 0;
+
+    uint16_t table[VIRTIO_NET_RSS_MAX_TABLE_LEN] = {...};
+    uint8_t key[VIRTIO_NET_RSS_MAX_KEY_SIZE] = {...};
+
+    struct EBPFRSSContext ctx;
+    ebpf_rss_init(&ctx);
+    ebpf_rss_load(&ctx);
+    ebpf_rss_set_all(&ctx, &config, table, key);
+    if (net_client->info->set_steering_ebpf != NULL) {
+        net_client->info->set_steering_ebpf(net_client, ctx->program_fd);
+    }
+    ...
+    ebpf_unload(&ctx);
+
+
+NetClientState SetSteeringEBPF()
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+For now, `set_steering_ebpf()` method supported by Linux TAP NetClientState. The method requires an eBPF program file descriptor as an argument.
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [RFC PATCH v3 4/6] ebpf: Added eBPF RSS loader.
  2021-01-14 21:16 ` [RFC PATCH v3 4/6] ebpf: Added eBPF RSS loader Andrew Melnychenko
@ 2021-01-15  7:02   ` Jason Wang
  2021-01-19 14:53     ` Yuri Benditovich
  0 siblings, 1 reply; 20+ messages in thread
From: Jason Wang @ 2021-01-15  7:02 UTC (permalink / raw)
  To: Andrew Melnychenko, mst; +Cc: yan, yuri.benditovich, berrange, qemu-devel


On 2021/1/15 上午5:16, Andrew Melnychenko wrote:
> From: Andrew <andrew@daynix.com>
>
> Added function that loads RSS eBPF program.
> Added stub functions for RSS eBPF loader.
> Added meson and configuration options.
>
> By default, eBPF feature enabled if libbpf is present in the build system.
> libbpf checked in configuration shell script and meson script.
>
> Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
> Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
> ---
>   configure               |  33 ++++
>   ebpf/ebpf_rss-stub.c    |  40 ++++
>   ebpf/ebpf_rss.c         | 165 +++++++++++++++++
>   ebpf/ebpf_rss.h         |  44 +++++
>   ebpf/meson.build        |   1 +
>   ebpf/rss.bpf.skeleton.h | 397 ++++++++++++++++++++++++++++++++++++++++
>   ebpf/trace-events       |   4 +
>   ebpf/trace.h            |   2 +
>   meson.build             |  13 ++
>   9 files changed, 699 insertions(+)
>   create mode 100644 ebpf/ebpf_rss-stub.c
>   create mode 100644 ebpf/ebpf_rss.c
>   create mode 100644 ebpf/ebpf_rss.h
>   create mode 100644 ebpf/meson.build
>   create mode 100644 ebpf/rss.bpf.skeleton.h
>   create mode 100644 ebpf/trace-events
>   create mode 100644 ebpf/trace.h
>
> diff --git a/configure b/configure
> index 5860bdb77b..9d18e941f5 100755
> --- a/configure
> +++ b/configure
> @@ -342,6 +342,7 @@ vhost_vsock="$default_feature"
>   vhost_user="no"
>   vhost_user_blk_server="auto"
>   vhost_user_fs="$default_feature"
> +bpf=""
>   kvm="auto"
>   hax="auto"
>   hvf="auto"
> @@ -1236,6 +1237,10 @@ for opt do
>     ;;
>     --enable-membarrier) membarrier="yes"
>     ;;
> +  --disable-bpf) bpf="no"
> +  ;;
> +  --enable-bpf) bpf="yes"
> +  ;;
>     --disable-blobs) blobs="false"
>     ;;
>     --with-pkgversion=*) pkgversion="$optarg"
> @@ -1845,6 +1850,7 @@ disabled with --disable-FEATURE, default is enabled if available
>     vhost-user      vhost-user backend support
>     vhost-user-blk-server    vhost-user-blk server support
>     vhost-vdpa      vhost-vdpa kernel backend support
> +  bpf             BPF kernel support
>     spice           spice
>     rbd             rados block device (rbd)
>     libiscsi        iscsi support
> @@ -5057,6 +5063,30 @@ else
>       membarrier=no
>   fi
>   
> +##########################################
> +# check for usable bpf system call
> +if test "$bpf" = ""; then


This implies the bpf is enabled by default?


> +    have_bpf=no
> +    if test "$linux" = "yes" -a "$bigendian" != "yes"; then
> +        cat > $TMPC << EOF
> +    #include <stdlib.h>
> +    #include <bpf/libbpf.h>
> +    int main(void) {
> +        struct bpf_object *obj = NULL;
> +        bpf_object__load(obj);
> +        exit(0);
> +    }
> +EOF
> +        if compile_prog "" "-lbpf" ; then
> +            have_bpf=yes
> +            bpf=yes
> +        fi
> +    fi
> +    if test "$have_bpf" = "no"; then
> +      feature_not_found "bpf" "the libbpf is not available"
> +    fi
> +fi
> +
>   ##########################################
>   # check if rtnetlink.h exists and is useful
>   have_rtnetlink=no
> @@ -5905,6 +5935,9 @@ fi
>   if test "$membarrier" = "yes" ; then
>     echo "CONFIG_MEMBARRIER=y" >> $config_host_mak
>   fi
> +if test "$bpf" = "yes" -a "$bigendian" != "yes" -a "$linux" = "yes" ; then
> +  echo "CONFIG_EBPF=y" >> $config_host_mak
> +fi
>   if test "$signalfd" = "yes" ; then
>     echo "CONFIG_SIGNALFD=y" >> $config_host_mak
>   fi
> diff --git a/ebpf/ebpf_rss-stub.c b/ebpf/ebpf_rss-stub.c
> new file mode 100644
> index 0000000000..e71e229190
> --- /dev/null
> +++ b/ebpf/ebpf_rss-stub.c
> @@ -0,0 +1,40 @@
> +/*
> + * eBPF RSS stub file
> + *
> + * Developed by Daynix Computing LTD (http://www.daynix.com)
> + *
> + * Authors:
> + *  Yuri Benditovich <yuri.benditovich@daynix.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2.  See
> + * the COPYING file in the top-level directory.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "ebpf/ebpf_rss.h"


I wonder why not simply use #ifdef #else to exclude the rss functions.

If I read code correctly, this stub requires rss_is_loaded called before 
ebpf_rss_set_all(), so actually ebpf_rss_is_loaded serve the same as


> +
> +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)
> +{
> +
> +}
> diff --git a/ebpf/ebpf_rss.c b/ebpf/ebpf_rss.c
> new file mode 100644
> index 0000000000..f7f7102da5
> --- /dev/null
> +++ b/ebpf/ebpf_rss.c
> @@ -0,0 +1,165 @@
> +/*
> + * eBPF RSS loader
> + *
> + * Developed by Daynix Computing LTD (http://www.daynix.com)
> + *
> + * Authors:
> + *  Andrew Melnychenko <andrew@daynix.com>
> + *  Yuri Benditovich <yuri.benditovich@daynix.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2.  See
> + * the COPYING file in the top-level directory.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qemu/error-report.h"
> +
> +#include <bpf/libbpf.h>
> +#include <bpf/bpf.h>
> +
> +#include "hw/virtio/virtio-net.h" /* VIRTIO_NET_RSS_MAX_TABLE_LEN */
> +
> +#include "ebpf/ebpf_rss.h"
> +#include "ebpf/rss.bpf.skeleton.h"
> +#include "trace.h"
> +
> +void ebpf_rss_init(struct EBPFRSSContext *ctx)
> +{
> +    if (ctx != NULL) {
> +        ctx->obj = NULL;
> +    }
> +}
> +
> +bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx)
> +{
> +    return ctx != NULL && ctx->obj != NULL;
> +}
> +
> +bool ebpf_rss_load(struct EBPFRSSContext *ctx)
> +{
> +    struct rss_bpf *rss_bpf_ctx;
> +
> +    if (ctx == NULL) {
> +        return false;
> +    }
> +
> +    rss_bpf_ctx = rss_bpf__open();
> +    if (rss_bpf_ctx == NULL) {
> +        trace_ebpf_error("eBPF RSS", "can not open eBPF RSS object");
> +        goto l_issue;


Nit: it's not easy to infer what did "l" mean, it's probably better to 
use "error".

Thanks



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net.
  2021-01-14 21:16 ` [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net Andrew Melnychenko
@ 2021-01-15  7:20   ` Jason Wang
  2021-01-17  9:04     ` Yuri Benditovich
  0 siblings, 1 reply; 20+ messages in thread
From: Jason Wang @ 2021-01-15  7:20 UTC (permalink / raw)
  To: Andrew Melnychenko, mst; +Cc: yan, yuri.benditovich, berrange, qemu-devel


On 2021/1/15 上午5:16, Andrew Melnychenko wrote:
> From: Andrew <andrew@daynix.com>
>
> When RSS is enabled the device tries to load the eBPF program
> to select RX virtqueue in the TUN. If eBPF can be loaded
> the RSS will function also with vhost (works with kernel 5.8 and later).
> Software RSS is used as a fallback with vhost=off when eBPF can't be loaded
> or when hash population requested by the guest.
>
> Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
> Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
> ---
>   hw/net/vhost_net.c             |   2 +
>   hw/net/virtio-net.c            | 125 +++++++++++++++++++++++++++++++--
>   include/hw/virtio/virtio-net.h |   4 ++
>   net/vhost-vdpa.c               |   2 +
>   4 files changed, 129 insertions(+), 4 deletions(-)
>
> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> index 24d555e764..16124f99c3 100644
> --- a/hw/net/vhost_net.c
> +++ b/hw/net/vhost_net.c
> @@ -71,6 +71,8 @@ static const int user_feature_bits[] = {
>       VIRTIO_NET_F_MTU,
>       VIRTIO_F_IOMMU_PLATFORM,
>       VIRTIO_F_RING_PACKED,
> +    VIRTIO_NET_F_RSS,
> +    VIRTIO_NET_F_HASH_REPORT,
>   
>       /* This bit implies RARP isn't sent by QEMU out of band */
>       VIRTIO_NET_F_GUEST_ANNOUNCE,
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index 09ceb02c9d..37016fc73a 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -691,6 +691,19 @@ static void virtio_net_set_queues(VirtIONet *n)
>   
>   static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue);
>   
> +static uint64_t fix_ebpf_vhost_features(uint64_t features)
> +{
> +    /* If vhost=on & CONFIG_EBPF doesn't set - disable RSS feature */


I still think we should not clear feature silently. This may break 
migraiton if the feature is cleared on destination.


> +    uint64_t ret = features;
> +#ifndef CONFIG_EBPF
> +    virtio_clear_feature(&ret, VIRTIO_NET_F_RSS);
> +#endif
> +    /* for now, there is no solution for populating the hash from eBPF */
> +    virtio_clear_feature(&ret, VIRTIO_NET_F_HASH_REPORT);
> +
> +    return ret;
> +}
> +
>   static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
>                                           Error **errp)
>   {
> @@ -725,9 +738,9 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
>           return features;
>       }
>   
> -    virtio_clear_feature(&features, VIRTIO_NET_F_RSS);
> -    virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT);
> -    features = vhost_net_get_features(get_vhost_net(nc->peer), features);
> +    features = fix_ebpf_vhost_features(
> +            vhost_net_get_features(get_vhost_net(nc->peer), features));
> +
>       vdev->backend_features = features;
>   
>       if (n->mtu_bypass_backend &&
> @@ -1151,12 +1164,79 @@ static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd,
>       }
>   }
>   
> +static void virtio_net_detach_epbf_rss(VirtIONet *n);
> +
>   static void virtio_net_disable_rss(VirtIONet *n)
>   {
>       if (n->rss_data.enabled) {
>           trace_virtio_net_rss_disable();
>       }
>       n->rss_data.enabled = false;
> +
> +    virtio_net_detach_epbf_rss(n);
> +}
> +
> +static bool virtio_net_attach_ebpf_to_backend(NICState *nic, int prog_fd)
> +{
> +    NetClientState *nc = qemu_get_peer(qemu_get_queue(nic), 0);
> +    if (nc == NULL || nc->info->set_steering_ebpf == NULL) {
> +        return false;
> +    }
> +
> +    return nc->info->set_steering_ebpf(nc, prog_fd);
> +}
> +
> +static void rss_data_to_rss_config(struct VirtioNetRssData *data,
> +                                   struct EBPFRSSConfig *config)
> +{
> +    config->redirect = data->redirect;
> +    config->populate_hash = data->populate_hash;
> +    config->hash_types = data->hash_types;
> +    config->indirections_len = data->indirections_len;
> +    config->default_queue = data->default_queue;
> +}
> +
> +static bool virtio_net_attach_epbf_rss(VirtIONet *n)
> +{
> +    struct EBPFRSSConfig config = {};
> +
> +    if (!ebpf_rss_is_loaded(&n->ebpf_rss)) {
> +        return false;
> +    }
> +
> +    rss_data_to_rss_config(&n->rss_data, &config);
> +
> +    if (!ebpf_rss_set_all(&n->ebpf_rss, &config,
> +                          n->rss_data.indirections_table, n->rss_data.key)) {
> +        return false;
> +    }
> +
> +    if (!virtio_net_attach_ebpf_to_backend(n->nic, n->ebpf_rss.program_fd)) {
> +        return false;
> +    }
> +
> +    return true;
> +}
> +
> +static void virtio_net_detach_epbf_rss(VirtIONet *n)
> +{
> +    virtio_net_attach_ebpf_to_backend(n->nic, -1);
> +}
> +
> +static bool virtio_net_load_ebpf(VirtIONet *n)
> +{
> +    if (!virtio_net_attach_ebpf_to_backend(n->nic, -1)) {
> +        /* backend does't support steering ebpf */
> +        return false;
> +    }
> +
> +    return ebpf_rss_load(&n->ebpf_rss);
> +}
> +
> +static void virtio_net_unload_ebpf(VirtIONet *n)
> +{
> +    virtio_net_attach_ebpf_to_backend(n->nic, -1);
> +    ebpf_rss_unload(&n->ebpf_rss);
>   }
>   
>   static uint16_t virtio_net_handle_rss(VirtIONet *n,
> @@ -1271,6 +1351,25 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n,
>           goto error;
>       }
>       n->rss_data.enabled = true;
> +
> +    if (!n->rss_data.populate_hash) {
> +        if (!virtio_net_attach_epbf_rss(n)) {
> +            /* EBPF must be loaded for vhost */
> +            if (get_vhost_net(qemu_get_queue(n->nic)->peer)) {
> +                warn_report("Can't load eBPF RSS for vhost");
> +                goto error;


How about stop the vhost in this case?

Thanks




^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC PATCH v3 6/6] docs: Added eBPF documentation.
  2021-01-14 21:16 ` [RFC PATCH v3 6/6] docs: Added eBPF documentation Andrew Melnychenko
@ 2021-01-15  7:24   ` Jason Wang
  0 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-01-15  7:24 UTC (permalink / raw)
  To: Andrew Melnychenko, mst; +Cc: yan, yuri.benditovich, berrange, qemu-devel


On 2021/1/15 上午5:16, Andrew Melnychenko wrote:
> From: Andrew <andrew@daynix.com>
>
> Also, added maintainers information.
>
> Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
> Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
> ---
>   MAINTAINERS       |   8 +++
>   docs/ebpf_rss.rst | 125 ++++++++++++++++++++++++++++++++++++++++++++++
>   2 files changed, 133 insertions(+)
>   create mode 100644 docs/ebpf_rss.rst
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 4be087b88e..4aafdfce2c 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -3173,6 +3173,14 @@ S: Maintained
>   F: hw/semihosting/
>   F: include/hw/semihosting/
>   
> +EBPF:
> +M: Jason Wang <jasowang@redhat.com>
> +R: Andrew Melnychenko <andrew@daynix.com>
> +R: Yuri Benditovich <yuri.benditovich@daynix.com>
> +S: Maintained
> +F: ebpf/*
> +F: tools/ebpf/*


It's better to do this in another patch.

Thanks



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC PATCH v3 0/6] eBPF RSS support for virtio-net
  2021-01-14 21:16 [RFC PATCH v3 0/6] eBPF RSS support for virtio-net Andrew Melnychenko
                   ` (6 preceding siblings ...)
  2021-01-14 21:16 ` [RFC PATCH v3 6/6] docs: Added eBPF documentation Andrew Melnychenko
@ 2021-01-15  7:27 ` Jason Wang
  7 siblings, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-01-15  7:27 UTC (permalink / raw)
  To: Andrew Melnychenko, mst; +Cc: yan, yuri.benditovich, berrange, qemu-devel


On 2021/1/15 上午5:16, Andrew Melnychenko wrote:
> This set of patches introduces the usage of eBPF for packet steering
> and RSS hash calculation:
> * RSS(Receive Side Scaling) is used to distribute network packets to
> guest virtqueues by calculating packet hash
> * Additionally adding support for the usage of RSS with vhost
>
> The eBPF works on kernels 5.8+
> On earlier kerneld it fails to load and the RSS feature is reported
> only without vhost and implemented in 'in-qemu' software.
>
> Implementation notes:
> Linux TAP TUNSETSTEERINGEBPF ioctl was used to set the eBPF program.
> Added libbpf dependency and eBPF support.
> The eBPF program is part of the qemu and presented as an array
> of BPF ELF file data. The eBPF array file initially generated by bpftool.
> The compilation of eBPF is not part of QEMU build and can be done
> using provided Makefile.ebpf(need to adjust 'linuxhdrs').
> Added changes to virtio-net and vhost, primary eBPF RSS is used.
> 'in-qemu' RSS used in the case of hash population and as a fallback option.
> For vhost, the hash population feature is not reported to the guest.
>
> Please also see the documentation in PATCH 6/6.
>
> I am sending those patches as RFC to initiate the discussions and get
> feedback on the following points:
> * Fallback when eBPF is not supported by the kernel
> * Live migration to the kernel that doesn't have eBPF support
> * Integration with current QEMU build
> * Additional usage for eBPF for packet filtering
>
> Known issues:
> * hash population not supported by eBPF RSS: 'in-qemu' RSS used
> as a fallback, also, hash population feature is not reported to guests
> with vhost.


Looks good overall. I think a formal series could be posted for the next 
version.

Please see comments in the patch and I think we need to add a migration 
blocker if RSS is supported by virtio-net. (And implement migration in 
the future).

Thanks


>
> Changes since v1:
> * using libbpf instead of direct 'bpf' system call.
> * added libbpf dependency to the configure/meson scripts.
> * changed python script for eBPF .h file generation.
> * changed eBPF program - reading L3 proto from ethernet frame.
> * added TUNSETSTEERINGEBPF define for TUN.
> * changed the maintainer's info.
> * added license headers.
> * refactored code.Changes since v1:
> * using libbpf instead of direct 'bpf' system call.
> * added libbpf dependency to the configure/meson scripts.
> * changed python script for eBPF .h file generation.
> * changed eBPF program - reading L3 proto from ethernet frame.
> * added TUNSETSTEERINGEBPF define for TUN.
> * changed the maintainer's info.
> * added license headers.
> * refactored code.
>
> Changes since v2:
> * using bpftool for eBPF skeleton generation.
> * ebpf_rss is refactored to use skeleton generated by bpftool.
> * added/adjasted license in comment sections and in eBPF file.
> * rss.bpf.c and Makefile.ebpf moved to the tool/ebpf folder.
> * virtio-net eBPF rss refactored. Now eBPF initialized during realize().
>
> Andrew (6):
>    net/tap: Added TUNSETSTEERINGEBPF code.
>    net: Added SetSteeringEBPF method for NetClientState.
>    ebpf: Added eBPF RSS program.
>    ebpf: Added eBPF RSS loader.
>    virtio-net: Added eBPF RSS to virtio-net.
>    docs: Added eBPF documentation.
>
>   MAINTAINERS                    |   8 +
>   configure                      |  33 +++
>   docs/ebpf_rss.rst              | 125 ++++++++
>   ebpf/ebpf_rss-stub.c           |  40 +++
>   ebpf/ebpf_rss.c                | 165 +++++++++++
>   ebpf/ebpf_rss.h                |  44 +++
>   ebpf/meson.build               |   1 +
>   ebpf/rss.bpf.skeleton.h        | 397 ++++++++++++++++++++++++++
>   ebpf/trace-events              |   4 +
>   ebpf/trace.h                   |   2 +
>   hw/net/vhost_net.c             |   2 +
>   hw/net/virtio-net.c            | 125 +++++++-
>   include/hw/virtio/virtio-net.h |   4 +
>   include/net/net.h              |   2 +
>   meson.build                    |  13 +
>   net/tap-bsd.c                  |   5 +
>   net/tap-linux.c                |  13 +
>   net/tap-linux.h                |   1 +
>   net/tap-solaris.c              |   5 +
>   net/tap-stub.c                 |   5 +
>   net/tap.c                      |   9 +
>   net/tap_int.h                  |   1 +
>   net/vhost-vdpa.c               |   2 +
>   tools/ebpf/Makefile.ebpf       |  33 +++
>   tools/ebpf/rss.bpf.c           | 505 +++++++++++++++++++++++++++++++++
>   25 files changed, 1540 insertions(+), 4 deletions(-)
>   create mode 100644 docs/ebpf_rss.rst
>   create mode 100644 ebpf/ebpf_rss-stub.c
>   create mode 100644 ebpf/ebpf_rss.c
>   create mode 100644 ebpf/ebpf_rss.h
>   create mode 100644 ebpf/meson.build
>   create mode 100644 ebpf/rss.bpf.skeleton.h
>   create mode 100644 ebpf/trace-events
>   create mode 100644 ebpf/trace.h
>   create mode 100755 tools/ebpf/Makefile.ebpf
>   create mode 100644 tools/ebpf/rss.bpf.c
>



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net.
  2021-01-15  7:20   ` Jason Wang
@ 2021-01-17  9:04     ` Yuri Benditovich
  2021-01-18  3:16       ` Jason Wang
  0 siblings, 1 reply; 20+ messages in thread
From: Yuri Benditovich @ 2021-01-17  9:04 UTC (permalink / raw)
  To: Jason Wang
  Cc: Yan Vugenfirer, Andrew Melnychenko, Daniel P. Berrangé,
	qemu-devel, Michael S . Tsirkin

On Fri, Jan 15, 2021 at 9:20 AM Jason Wang <jasowang@redhat.com> wrote:
>
>
> On 2021/1/15 上午5:16, Andrew Melnychenko wrote:
> > From: Andrew <andrew@daynix.com>
> >
> > When RSS is enabled the device tries to load the eBPF program
> > to select RX virtqueue in the TUN. If eBPF can be loaded
> > the RSS will function also with vhost (works with kernel 5.8 and later).
> > Software RSS is used as a fallback with vhost=off when eBPF can't be loaded
> > or when hash population requested by the guest.
> >
> > Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
> > Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
> > ---
> >   hw/net/vhost_net.c             |   2 +
> >   hw/net/virtio-net.c            | 125 +++++++++++++++++++++++++++++++--
> >   include/hw/virtio/virtio-net.h |   4 ++
> >   net/vhost-vdpa.c               |   2 +
> >   4 files changed, 129 insertions(+), 4 deletions(-)
> >
> > diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> > index 24d555e764..16124f99c3 100644
> > --- a/hw/net/vhost_net.c
> > +++ b/hw/net/vhost_net.c
> > @@ -71,6 +71,8 @@ static const int user_feature_bits[] = {
> >       VIRTIO_NET_F_MTU,
> >       VIRTIO_F_IOMMU_PLATFORM,
> >       VIRTIO_F_RING_PACKED,
> > +    VIRTIO_NET_F_RSS,
> > +    VIRTIO_NET_F_HASH_REPORT,
> >
> >       /* This bit implies RARP isn't sent by QEMU out of band */
> >       VIRTIO_NET_F_GUEST_ANNOUNCE,
> > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> > index 09ceb02c9d..37016fc73a 100644
> > --- a/hw/net/virtio-net.c
> > +++ b/hw/net/virtio-net.c
> > @@ -691,6 +691,19 @@ static void virtio_net_set_queues(VirtIONet *n)
> >
> >   static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue);
> >
> > +static uint64_t fix_ebpf_vhost_features(uint64_t features)
> > +{
> > +    /* If vhost=on & CONFIG_EBPF doesn't set - disable RSS feature */
>
>
> I still think we should not clear feature silently. This may break
> migraiton if the feature is cleared on destination.

Do I understand it correctly that if we do not clear features silently
and implement a graceful drop to vhost=off when we can't do what we
need with vhost - then we do not need to add any migration blocker?

>
>
> > +    uint64_t ret = features;
> > +#ifndef CONFIG_EBPF
> > +    virtio_clear_feature(&ret, VIRTIO_NET_F_RSS);
> > +#endif
> > +    /* for now, there is no solution for populating the hash from eBPF */
> > +    virtio_clear_feature(&ret, VIRTIO_NET_F_HASH_REPORT);
> > +
> > +    return ret;
> > +}
> > +
> >   static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
> >                                           Error **errp)
> >   {
> > @@ -725,9 +738,9 @@ static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t features,
> >           return features;
> >       }
> >
> > -    virtio_clear_feature(&features, VIRTIO_NET_F_RSS);
> > -    virtio_clear_feature(&features, VIRTIO_NET_F_HASH_REPORT);
> > -    features = vhost_net_get_features(get_vhost_net(nc->peer), features);
> > +    features = fix_ebpf_vhost_features(
> > +            vhost_net_get_features(get_vhost_net(nc->peer), features));
> > +
> >       vdev->backend_features = features;
> >
> >       if (n->mtu_bypass_backend &&
> > @@ -1151,12 +1164,79 @@ static int virtio_net_handle_announce(VirtIONet *n, uint8_t cmd,
> >       }
> >   }
> >
> > +static void virtio_net_detach_epbf_rss(VirtIONet *n);
> > +
> >   static void virtio_net_disable_rss(VirtIONet *n)
> >   {
> >       if (n->rss_data.enabled) {
> >           trace_virtio_net_rss_disable();
> >       }
> >       n->rss_data.enabled = false;
> > +
> > +    virtio_net_detach_epbf_rss(n);
> > +}
> > +
> > +static bool virtio_net_attach_ebpf_to_backend(NICState *nic, int prog_fd)
> > +{
> > +    NetClientState *nc = qemu_get_peer(qemu_get_queue(nic), 0);
> > +    if (nc == NULL || nc->info->set_steering_ebpf == NULL) {
> > +        return false;
> > +    }
> > +
> > +    return nc->info->set_steering_ebpf(nc, prog_fd);
> > +}
> > +
> > +static void rss_data_to_rss_config(struct VirtioNetRssData *data,
> > +                                   struct EBPFRSSConfig *config)
> > +{
> > +    config->redirect = data->redirect;
> > +    config->populate_hash = data->populate_hash;
> > +    config->hash_types = data->hash_types;
> > +    config->indirections_len = data->indirections_len;
> > +    config->default_queue = data->default_queue;
> > +}
> > +
> > +static bool virtio_net_attach_epbf_rss(VirtIONet *n)
> > +{
> > +    struct EBPFRSSConfig config = {};
> > +
> > +    if (!ebpf_rss_is_loaded(&n->ebpf_rss)) {
> > +        return false;
> > +    }
> > +
> > +    rss_data_to_rss_config(&n->rss_data, &config);
> > +
> > +    if (!ebpf_rss_set_all(&n->ebpf_rss, &config,
> > +                          n->rss_data.indirections_table, n->rss_data.key)) {
> > +        return false;
> > +    }
> > +
> > +    if (!virtio_net_attach_ebpf_to_backend(n->nic, n->ebpf_rss.program_fd)) {
> > +        return false;
> > +    }
> > +
> > +    return true;
> > +}
> > +
> > +static void virtio_net_detach_epbf_rss(VirtIONet *n)
> > +{
> > +    virtio_net_attach_ebpf_to_backend(n->nic, -1);
> > +}
> > +
> > +static bool virtio_net_load_ebpf(VirtIONet *n)
> > +{
> > +    if (!virtio_net_attach_ebpf_to_backend(n->nic, -1)) {
> > +        /* backend does't support steering ebpf */
> > +        return false;
> > +    }
> > +
> > +    return ebpf_rss_load(&n->ebpf_rss);
> > +}
> > +
> > +static void virtio_net_unload_ebpf(VirtIONet *n)
> > +{
> > +    virtio_net_attach_ebpf_to_backend(n->nic, -1);
> > +    ebpf_rss_unload(&n->ebpf_rss);
> >   }
> >
> >   static uint16_t virtio_net_handle_rss(VirtIONet *n,
> > @@ -1271,6 +1351,25 @@ static uint16_t virtio_net_handle_rss(VirtIONet *n,
> >           goto error;
> >       }
> >       n->rss_data.enabled = true;
> > +
> > +    if (!n->rss_data.populate_hash) {
> > +        if (!virtio_net_attach_epbf_rss(n)) {
> > +            /* EBPF must be loaded for vhost */
> > +            if (get_vhost_net(qemu_get_queue(n->nic)->peer)) {
> > +                warn_report("Can't load eBPF RSS for vhost");
> > +                goto error;
>
>
> How about stop the vhost in this case?
>
> Thanks
>
>


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net.
  2021-01-17  9:04     ` Yuri Benditovich
@ 2021-01-18  3:16       ` Jason Wang
  2021-01-24  8:24         ` Yuri Benditovich
  0 siblings, 1 reply; 20+ messages in thread
From: Jason Wang @ 2021-01-18  3:16 UTC (permalink / raw)
  To: Yuri Benditovich
  Cc: Yan Vugenfirer, Andrew Melnychenko, Daniel P. Berrangé,
	qemu-devel, Michael S . Tsirkin


On 2021/1/17 下午5:04, Yuri Benditovich wrote:
> On Fri, Jan 15, 2021 at 9:20 AM Jason Wang<jasowang@redhat.com>  wrote:
>> On 2021/1/15 上午5:16, Andrew Melnychenko wrote:
>>> From: Andrew<andrew@daynix.com>
>>>
>>> When RSS is enabled the device tries to load the eBPF program
>>> to select RX virtqueue in the TUN. If eBPF can be loaded
>>> the RSS will function also with vhost (works with kernel 5.8 and later).
>>> Software RSS is used as a fallback with vhost=off when eBPF can't be loaded
>>> or when hash population requested by the guest.
>>>
>>> Signed-off-by: Yuri Benditovich<yuri.benditovich@daynix.com>
>>> Signed-off-by: Andrew Melnychenko<andrew@daynix.com>
>>> ---
>>>    hw/net/vhost_net.c             |   2 +
>>>    hw/net/virtio-net.c            | 125 +++++++++++++++++++++++++++++++--
>>>    include/hw/virtio/virtio-net.h |   4 ++
>>>    net/vhost-vdpa.c               |   2 +
>>>    4 files changed, 129 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
>>> index 24d555e764..16124f99c3 100644
>>> --- a/hw/net/vhost_net.c
>>> +++ b/hw/net/vhost_net.c
>>> @@ -71,6 +71,8 @@ static const int user_feature_bits[] = {
>>>        VIRTIO_NET_F_MTU,
>>>        VIRTIO_F_IOMMU_PLATFORM,
>>>        VIRTIO_F_RING_PACKED,
>>> +    VIRTIO_NET_F_RSS,
>>> +    VIRTIO_NET_F_HASH_REPORT,
>>>
>>>        /* This bit implies RARP isn't sent by QEMU out of band */
>>>        VIRTIO_NET_F_GUEST_ANNOUNCE,
>>> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
>>> index 09ceb02c9d..37016fc73a 100644
>>> --- a/hw/net/virtio-net.c
>>> +++ b/hw/net/virtio-net.c
>>> @@ -691,6 +691,19 @@ static void virtio_net_set_queues(VirtIONet *n)
>>>
>>>    static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue);
>>>
>>> +static uint64_t fix_ebpf_vhost_features(uint64_t features)
>>> +{
>>> +    /* If vhost=on & CONFIG_EBPF doesn't set - disable RSS feature */
>> I still think we should not clear feature silently. This may break
>> migraiton if the feature is cleared on destination.
> Do I understand it correctly that if we do not clear features silently
> and implement a graceful drop to vhost=off when we can't do what we
> need with vhost - then we do not need to add any migration blocker?


Yes. I think we won't go with migration blocker since we need support 
migration in the end.

Thanks


>



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC PATCH v3 4/6] ebpf: Added eBPF RSS loader.
  2021-01-15  7:02   ` Jason Wang
@ 2021-01-19 14:53     ` Yuri Benditovich
  2021-01-25  9:02       ` Jason Wang
  0 siblings, 1 reply; 20+ messages in thread
From: Yuri Benditovich @ 2021-01-19 14:53 UTC (permalink / raw)
  To: Jason Wang
  Cc: Yan Vugenfirer, Andrew Melnychenko, Daniel P. Berrangé,
	qemu-devel, Michael S . Tsirkin

On Fri, Jan 15, 2021 at 9:02 AM Jason Wang <jasowang@redhat.com> wrote:
>
>
> On 2021/1/15 上午5:16, Andrew Melnychenko wrote:
> > From: Andrew <andrew@daynix.com>
> >
> > Added function that loads RSS eBPF program.
> > Added stub functions for RSS eBPF loader.
> > Added meson and configuration options.
> >
> > By default, eBPF feature enabled if libbpf is present in the build system.
> > libbpf checked in configuration shell script and meson script.
> >
> > Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
> > Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
> > ---
> >   configure               |  33 ++++
> >   ebpf/ebpf_rss-stub.c    |  40 ++++
> >   ebpf/ebpf_rss.c         | 165 +++++++++++++++++
> >   ebpf/ebpf_rss.h         |  44 +++++
> >   ebpf/meson.build        |   1 +
> >   ebpf/rss.bpf.skeleton.h | 397 ++++++++++++++++++++++++++++++++++++++++
> >   ebpf/trace-events       |   4 +
> >   ebpf/trace.h            |   2 +
> >   meson.build             |  13 ++
> >   9 files changed, 699 insertions(+)
> >   create mode 100644 ebpf/ebpf_rss-stub.c
> >   create mode 100644 ebpf/ebpf_rss.c
> >   create mode 100644 ebpf/ebpf_rss.h
> >   create mode 100644 ebpf/meson.build
> >   create mode 100644 ebpf/rss.bpf.skeleton.h
> >   create mode 100644 ebpf/trace-events
> >   create mode 100644 ebpf/trace.h
> >
> > diff --git a/configure b/configure
> > index 5860bdb77b..9d18e941f5 100755
> > --- a/configure
> > +++ b/configure
> > @@ -342,6 +342,7 @@ vhost_vsock="$default_feature"
> >   vhost_user="no"
> >   vhost_user_blk_server="auto"
> >   vhost_user_fs="$default_feature"
> > +bpf=""
> >   kvm="auto"
> >   hax="auto"
> >   hvf="auto"
> > @@ -1236,6 +1237,10 @@ for opt do
> >     ;;
> >     --enable-membarrier) membarrier="yes"
> >     ;;
> > +  --disable-bpf) bpf="no"
> > +  ;;
> > +  --enable-bpf) bpf="yes"
> > +  ;;
> >     --disable-blobs) blobs="false"
> >     ;;
> >     --with-pkgversion=*) pkgversion="$optarg"
> > @@ -1845,6 +1850,7 @@ disabled with --disable-FEATURE, default is enabled if available
> >     vhost-user      vhost-user backend support
> >     vhost-user-blk-server    vhost-user-blk server support
> >     vhost-vdpa      vhost-vdpa kernel backend support
> > +  bpf             BPF kernel support
> >     spice           spice
> >     rbd             rados block device (rbd)
> >     libiscsi        iscsi support
> > @@ -5057,6 +5063,30 @@ else
> >       membarrier=no
> >   fi
> >
> > +##########################################
> > +# check for usable bpf system call
> > +if test "$bpf" = ""; then
>
>
> This implies the bpf is enabled by default?

Yes, assuming libbpf-devel present and bpf system call defined.

Any problem with it?

>
>
> > +    have_bpf=no
> > +    if test "$linux" = "yes" -a "$bigendian" != "yes"; then
> > +        cat > $TMPC << EOF
> > +    #include <stdlib.h>
> > +    #include <bpf/libbpf.h>
> > +    int main(void) {
> > +        struct bpf_object *obj = NULL;
> > +        bpf_object__load(obj);
> > +        exit(0);
> > +    }
> > +EOF
> > +        if compile_prog "" "-lbpf" ; then
> > +            have_bpf=yes
> > +            bpf=yes
> > +        fi
> > +    fi
> > +    if test "$have_bpf" = "no"; then
> > +      feature_not_found "bpf" "the libbpf is not available"
> > +    fi
> > +fi
> > +
> >   ##########################################
> >   # check if rtnetlink.h exists and is useful
> >   have_rtnetlink=no
> > @@ -5905,6 +5935,9 @@ fi
> >   if test "$membarrier" = "yes" ; then
> >     echo "CONFIG_MEMBARRIER=y" >> $config_host_mak
> >   fi
> > +if test "$bpf" = "yes" -a "$bigendian" != "yes" -a "$linux" = "yes" ; then
> > +  echo "CONFIG_EBPF=y" >> $config_host_mak
> > +fi
> >   if test "$signalfd" = "yes" ; then
> >     echo "CONFIG_SIGNALFD=y" >> $config_host_mak
> >   fi
> > diff --git a/ebpf/ebpf_rss-stub.c b/ebpf/ebpf_rss-stub.c
> > new file mode 100644
> > index 0000000000..e71e229190
> > --- /dev/null
> > +++ b/ebpf/ebpf_rss-stub.c
> > @@ -0,0 +1,40 @@
> > +/*
> > + * eBPF RSS stub file
> > + *
> > + * Developed by Daynix Computing LTD (http://www.daynix.com)
> > + *
> > + * Authors:
> > + *  Yuri Benditovich <yuri.benditovich@daynix.com>
> > + *
> > + * This work is licensed under the terms of the GNU GPL, version 2.  See
> > + * the COPYING file in the top-level directory.
> > + */
> > +
> > +#include "qemu/osdep.h"
> > +#include "ebpf/ebpf_rss.h"
>
>
> I wonder why not simply use #ifdef #else to exclude the rss functions.

Just to make the reading easier.

>
> If I read code correctly, this stub requires rss_is_loaded called before
> ebpf_rss_set_all(), so actually ebpf_rss_is_loaded serve the same as

Can you please get into details?
I think the stub does not require it, it just converts all the
ebpf_rss calls to nop at link time.
If I miss something please let us know, we'll fix it in v4.

>
>
> > +
> > +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)
> > +{
> > +
> > +}
> > diff --git a/ebpf/ebpf_rss.c b/ebpf/ebpf_rss.c
> > new file mode 100644
> > index 0000000000..f7f7102da5
> > --- /dev/null
> > +++ b/ebpf/ebpf_rss.c
> > @@ -0,0 +1,165 @@
> > +/*
> > + * eBPF RSS loader
> > + *
> > + * Developed by Daynix Computing LTD (http://www.daynix.com)
> > + *
> > + * Authors:
> > + *  Andrew Melnychenko <andrew@daynix.com>
> > + *  Yuri Benditovich <yuri.benditovich@daynix.com>
> > + *
> > + * This work is licensed under the terms of the GNU GPL, version 2.  See
> > + * the COPYING file in the top-level directory.
> > + */
> > +
> > +#include "qemu/osdep.h"
> > +#include "qemu/error-report.h"
> > +
> > +#include <bpf/libbpf.h>
> > +#include <bpf/bpf.h>
> > +
> > +#include "hw/virtio/virtio-net.h" /* VIRTIO_NET_RSS_MAX_TABLE_LEN */
> > +
> > +#include "ebpf/ebpf_rss.h"
> > +#include "ebpf/rss.bpf.skeleton.h"
> > +#include "trace.h"
> > +
> > +void ebpf_rss_init(struct EBPFRSSContext *ctx)
> > +{
> > +    if (ctx != NULL) {
> > +        ctx->obj = NULL;
> > +    }
> > +}
> > +
> > +bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx)
> > +{
> > +    return ctx != NULL && ctx->obj != NULL;
> > +}
> > +
> > +bool ebpf_rss_load(struct EBPFRSSContext *ctx)
> > +{
> > +    struct rss_bpf *rss_bpf_ctx;
> > +
> > +    if (ctx == NULL) {
> > +        return false;
> > +    }
> > +
> > +    rss_bpf_ctx = rss_bpf__open();
> > +    if (rss_bpf_ctx == NULL) {
> > +        trace_ebpf_error("eBPF RSS", "can not open eBPF RSS object");
> > +        goto l_issue;
>
>
> Nit: it's not easy to infer what did "l" mean, it's probably better to
> use "error".

ok, will be renamed, 'l' means 'load' probably

>
> Thanks
>


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net.
  2021-01-18  3:16       ` Jason Wang
@ 2021-01-24  8:24         ` Yuri Benditovich
  2021-01-24 11:33           ` Yuri Benditovich
  2021-01-25  8:59           ` Jason Wang
  0 siblings, 2 replies; 20+ messages in thread
From: Yuri Benditovich @ 2021-01-24  8:24 UTC (permalink / raw)
  To: Jason Wang
  Cc: Yan Vugenfirer, Andrew Melnychenko, Daniel P. Berrangé,
	qemu-devel, Michael S . Tsirkin

Hi Jason,

I've prepared a POC of graceful switch to 'vhost off' if respective
features are acked by the guest.
Such a way we do not need to silently clear RSS and hash report
features in case of 'vhost on'.
Can you please review it and provide your feedback?

I think the only open question is what to do with cases of vhost-user
and vhost-vdpa.

https://github.com/qemu/qemu/pull/105
This pull request is for reviews only.

Thanks in advance






On Mon, Jan 18, 2021 at 5:16 AM Jason Wang <jasowang@redhat.com> wrote:
>
>
> On 2021/1/17 下午5:04, Yuri Benditovich wrote:
> > On Fri, Jan 15, 2021 at 9:20 AM Jason Wang<jasowang@redhat.com>  wrote:
> >> On 2021/1/15 上午5:16, Andrew Melnychenko wrote:
> >>> From: Andrew<andrew@daynix.com>
> >>>
> >>> When RSS is enabled the device tries to load the eBPF program
> >>> to select RX virtqueue in the TUN. If eBPF can be loaded
> >>> the RSS will function also with vhost (works with kernel 5.8 and later).
> >>> Software RSS is used as a fallback with vhost=off when eBPF can't be loaded
> >>> or when hash population requested by the guest.
> >>>
> >>> Signed-off-by: Yuri Benditovich<yuri.benditovich@daynix.com>
> >>> Signed-off-by: Andrew Melnychenko<andrew@daynix.com>
> >>> ---
> >>>    hw/net/vhost_net.c             |   2 +
> >>>    hw/net/virtio-net.c            | 125 +++++++++++++++++++++++++++++++--
> >>>    include/hw/virtio/virtio-net.h |   4 ++
> >>>    net/vhost-vdpa.c               |   2 +
> >>>    4 files changed, 129 insertions(+), 4 deletions(-)
> >>>
> >>> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> >>> index 24d555e764..16124f99c3 100644
> >>> --- a/hw/net/vhost_net.c
> >>> +++ b/hw/net/vhost_net.c
> >>> @@ -71,6 +71,8 @@ static const int user_feature_bits[] = {
> >>>        VIRTIO_NET_F_MTU,
> >>>        VIRTIO_F_IOMMU_PLATFORM,
> >>>        VIRTIO_F_RING_PACKED,
> >>> +    VIRTIO_NET_F_RSS,
> >>> +    VIRTIO_NET_F_HASH_REPORT,
> >>>
> >>>        /* This bit implies RARP isn't sent by QEMU out of band */
> >>>        VIRTIO_NET_F_GUEST_ANNOUNCE,
> >>> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> >>> index 09ceb02c9d..37016fc73a 100644
> >>> --- a/hw/net/virtio-net.c
> >>> +++ b/hw/net/virtio-net.c
> >>> @@ -691,6 +691,19 @@ static void virtio_net_set_queues(VirtIONet *n)
> >>>
> >>>    static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue);
> >>>
> >>> +static uint64_t fix_ebpf_vhost_features(uint64_t features)
> >>> +{
> >>> +    /* If vhost=on & CONFIG_EBPF doesn't set - disable RSS feature */
> >> I still think we should not clear feature silently. This may break
> >> migraiton if the feature is cleared on destination.
> > Do I understand it correctly that if we do not clear features silently
> > and implement a graceful drop to vhost=off when we can't do what we
> > need with vhost - then we do not need to add any migration blocker?
>
>
> Yes. I think we won't go with migration blocker since we need support
> migration in the end.
>
> Thanks
>
>
> >
>


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net.
  2021-01-24  8:24         ` Yuri Benditovich
@ 2021-01-24 11:33           ` Yuri Benditovich
  2021-01-25  8:59           ` Jason Wang
  1 sibling, 0 replies; 20+ messages in thread
From: Yuri Benditovich @ 2021-01-24 11:33 UTC (permalink / raw)
  To: Jason Wang
  Cc: Yan Vugenfirer, Andrew Melnychenko, Daniel P. Berrangé,
	qemu-devel, Michael S . Tsirkin

On Sun, Jan 24, 2021 at 10:24 AM Yuri Benditovich
<yuri.benditovich@daynix.com> wrote:
>
> Hi Jason,
>
> I've prepared a POC of graceful switch to 'vhost off' if respective
> features are acked by the guest.
> Such a way we do not need to silently clear RSS and hash report
> features in case of 'vhost on'.
> Can you please review it and provide your feedback?
>
> I think the only open question is what to do with cases of vhost-user
> and vhost-vdpa.
>
> https://github.com/qemu/qemu/pull/105
> This pull request is for reviews only.

Unfortunately qemu github PR is closed for comments
This is the link to the same on Daynix repository

https://github.com/daynix/qemu/pull/1

>
> Thanks in advance
>
>
>
>
>
>
> On Mon, Jan 18, 2021 at 5:16 AM Jason Wang <jasowang@redhat.com> wrote:
> >
> >
> > On 2021/1/17 下午5:04, Yuri Benditovich wrote:
> > > On Fri, Jan 15, 2021 at 9:20 AM Jason Wang<jasowang@redhat.com>  wrote:
> > >> On 2021/1/15 上午5:16, Andrew Melnychenko wrote:
> > >>> From: Andrew<andrew@daynix.com>
> > >>>
> > >>> When RSS is enabled the device tries to load the eBPF program
> > >>> to select RX virtqueue in the TUN. If eBPF can be loaded
> > >>> the RSS will function also with vhost (works with kernel 5.8 and later).
> > >>> Software RSS is used as a fallback with vhost=off when eBPF can't be loaded
> > >>> or when hash population requested by the guest.
> > >>>
> > >>> Signed-off-by: Yuri Benditovich<yuri.benditovich@daynix.com>
> > >>> Signed-off-by: Andrew Melnychenko<andrew@daynix.com>
> > >>> ---
> > >>>    hw/net/vhost_net.c             |   2 +
> > >>>    hw/net/virtio-net.c            | 125 +++++++++++++++++++++++++++++++--
> > >>>    include/hw/virtio/virtio-net.h |   4 ++
> > >>>    net/vhost-vdpa.c               |   2 +
> > >>>    4 files changed, 129 insertions(+), 4 deletions(-)
> > >>>
> > >>> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> > >>> index 24d555e764..16124f99c3 100644
> > >>> --- a/hw/net/vhost_net.c
> > >>> +++ b/hw/net/vhost_net.c
> > >>> @@ -71,6 +71,8 @@ static const int user_feature_bits[] = {
> > >>>        VIRTIO_NET_F_MTU,
> > >>>        VIRTIO_F_IOMMU_PLATFORM,
> > >>>        VIRTIO_F_RING_PACKED,
> > >>> +    VIRTIO_NET_F_RSS,
> > >>> +    VIRTIO_NET_F_HASH_REPORT,
> > >>>
> > >>>        /* This bit implies RARP isn't sent by QEMU out of band */
> > >>>        VIRTIO_NET_F_GUEST_ANNOUNCE,
> > >>> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> > >>> index 09ceb02c9d..37016fc73a 100644
> > >>> --- a/hw/net/virtio-net.c
> > >>> +++ b/hw/net/virtio-net.c
> > >>> @@ -691,6 +691,19 @@ static void virtio_net_set_queues(VirtIONet *n)
> > >>>
> > >>>    static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue);
> > >>>
> > >>> +static uint64_t fix_ebpf_vhost_features(uint64_t features)
> > >>> +{
> > >>> +    /* If vhost=on & CONFIG_EBPF doesn't set - disable RSS feature */
> > >> I still think we should not clear feature silently. This may break
> > >> migraiton if the feature is cleared on destination.
> > > Do I understand it correctly that if we do not clear features silently
> > > and implement a graceful drop to vhost=off when we can't do what we
> > > need with vhost - then we do not need to add any migration blocker?
> >
> >
> > Yes. I think we won't go with migration blocker since we need support
> > migration in the end.
> >
> > Thanks
> >
> >
> > >
> >


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net.
  2021-01-24  8:24         ` Yuri Benditovich
  2021-01-24 11:33           ` Yuri Benditovich
@ 2021-01-25  8:59           ` Jason Wang
  1 sibling, 0 replies; 20+ messages in thread
From: Jason Wang @ 2021-01-25  8:59 UTC (permalink / raw)
  To: Yuri Benditovich
  Cc: Yan Vugenfirer, Andrew Melnychenko, Daniel P. Berrangé,
	qemu-devel, Michael S . Tsirkin


On 2021/1/24 下午4:24, Yuri Benditovich wrote:
> Hi Jason,
>
> I've prepared a POC of graceful switch to 'vhost off' if respective
> features are acked by the guest.
> Such a way we do not need to silently clear RSS and hash report
> features in case of 'vhost on'.
> Can you please review it and provide your feedback?
>
> I think the only open question is what to do with cases of vhost-user
> and vhost-vdpa.
>
> https://github.com/qemu/qemu/pull/105
> This pull request is for reviews only.
>
> Thanks in advance


Will review it sometime this week.

Thanks


>
>
>
>
>
>
> On Mon, Jan 18, 2021 at 5:16 AM Jason Wang <jasowang@redhat.com> wrote:
>>
>> On 2021/1/17 下午5:04, Yuri Benditovich wrote:
>>> On Fri, Jan 15, 2021 at 9:20 AM Jason Wang<jasowang@redhat.com>  wrote:
>>>> On 2021/1/15 上午5:16, Andrew Melnychenko wrote:
>>>>> From: Andrew<andrew@daynix.com>
>>>>>
>>>>> When RSS is enabled the device tries to load the eBPF program
>>>>> to select RX virtqueue in the TUN. If eBPF can be loaded
>>>>> the RSS will function also with vhost (works with kernel 5.8 and later).
>>>>> Software RSS is used as a fallback with vhost=off when eBPF can't be loaded
>>>>> or when hash population requested by the guest.
>>>>>
>>>>> Signed-off-by: Yuri Benditovich<yuri.benditovich@daynix.com>
>>>>> Signed-off-by: Andrew Melnychenko<andrew@daynix.com>
>>>>> ---
>>>>>     hw/net/vhost_net.c             |   2 +
>>>>>     hw/net/virtio-net.c            | 125 +++++++++++++++++++++++++++++++--
>>>>>     include/hw/virtio/virtio-net.h |   4 ++
>>>>>     net/vhost-vdpa.c               |   2 +
>>>>>     4 files changed, 129 insertions(+), 4 deletions(-)
>>>>>
>>>>> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
>>>>> index 24d555e764..16124f99c3 100644
>>>>> --- a/hw/net/vhost_net.c
>>>>> +++ b/hw/net/vhost_net.c
>>>>> @@ -71,6 +71,8 @@ static const int user_feature_bits[] = {
>>>>>         VIRTIO_NET_F_MTU,
>>>>>         VIRTIO_F_IOMMU_PLATFORM,
>>>>>         VIRTIO_F_RING_PACKED,
>>>>> +    VIRTIO_NET_F_RSS,
>>>>> +    VIRTIO_NET_F_HASH_REPORT,
>>>>>
>>>>>         /* This bit implies RARP isn't sent by QEMU out of band */
>>>>>         VIRTIO_NET_F_GUEST_ANNOUNCE,
>>>>> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
>>>>> index 09ceb02c9d..37016fc73a 100644
>>>>> --- a/hw/net/virtio-net.c
>>>>> +++ b/hw/net/virtio-net.c
>>>>> @@ -691,6 +691,19 @@ static void virtio_net_set_queues(VirtIONet *n)
>>>>>
>>>>>     static void virtio_net_set_multiqueue(VirtIONet *n, int multiqueue);
>>>>>
>>>>> +static uint64_t fix_ebpf_vhost_features(uint64_t features)
>>>>> +{
>>>>> +    /* If vhost=on & CONFIG_EBPF doesn't set - disable RSS feature */
>>>> I still think we should not clear feature silently. This may break
>>>> migraiton if the feature is cleared on destination.
>>> Do I understand it correctly that if we do not clear features silently
>>> and implement a graceful drop to vhost=off when we can't do what we
>>> need with vhost - then we do not need to add any migration blocker?
>>
>> Yes. I think we won't go with migration blocker since we need support
>> migration in the end.
>>
>> Thanks
>>
>>



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC PATCH v3 4/6] ebpf: Added eBPF RSS loader.
  2021-01-19 14:53     ` Yuri Benditovich
@ 2021-01-25  9:02       ` Jason Wang
  2021-01-25 10:52         ` Yuri Benditovich
  0 siblings, 1 reply; 20+ messages in thread
From: Jason Wang @ 2021-01-25  9:02 UTC (permalink / raw)
  To: Yuri Benditovich
  Cc: Yan Vugenfirer, Andrew Melnychenko, Daniel P. Berrangé,
	qemu-devel, Michael S . Tsirkin


On 2021/1/19 下午10:53, Yuri Benditovich wrote:
> On Fri, Jan 15, 2021 at 9:02 AM Jason Wang <jasowang@redhat.com> wrote:
>>
>> On 2021/1/15 上午5:16, Andrew Melnychenko wrote:
>>> From: Andrew <andrew@daynix.com>
>>>
>>> Added function that loads RSS eBPF program.
>>> Added stub functions for RSS eBPF loader.
>>> Added meson and configuration options.
>>>
>>> By default, eBPF feature enabled if libbpf is present in the build system.
>>> libbpf checked in configuration shell script and meson script.
>>>
>>> Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
>>> Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
>>> ---
>>>    configure               |  33 ++++
>>>    ebpf/ebpf_rss-stub.c    |  40 ++++
>>>    ebpf/ebpf_rss.c         | 165 +++++++++++++++++
>>>    ebpf/ebpf_rss.h         |  44 +++++
>>>    ebpf/meson.build        |   1 +
>>>    ebpf/rss.bpf.skeleton.h | 397 ++++++++++++++++++++++++++++++++++++++++
>>>    ebpf/trace-events       |   4 +
>>>    ebpf/trace.h            |   2 +
>>>    meson.build             |  13 ++
>>>    9 files changed, 699 insertions(+)
>>>    create mode 100644 ebpf/ebpf_rss-stub.c
>>>    create mode 100644 ebpf/ebpf_rss.c
>>>    create mode 100644 ebpf/ebpf_rss.h
>>>    create mode 100644 ebpf/meson.build
>>>    create mode 100644 ebpf/rss.bpf.skeleton.h
>>>    create mode 100644 ebpf/trace-events
>>>    create mode 100644 ebpf/trace.h
>>>
>>> diff --git a/configure b/configure
>>> index 5860bdb77b..9d18e941f5 100755
>>> --- a/configure
>>> +++ b/configure
>>> @@ -342,6 +342,7 @@ vhost_vsock="$default_feature"
>>>    vhost_user="no"
>>>    vhost_user_blk_server="auto"
>>>    vhost_user_fs="$default_feature"
>>> +bpf=""
>>>    kvm="auto"
>>>    hax="auto"
>>>    hvf="auto"
>>> @@ -1236,6 +1237,10 @@ for opt do
>>>      ;;
>>>      --enable-membarrier) membarrier="yes"
>>>      ;;
>>> +  --disable-bpf) bpf="no"
>>> +  ;;
>>> +  --enable-bpf) bpf="yes"
>>> +  ;;
>>>      --disable-blobs) blobs="false"
>>>      ;;
>>>      --with-pkgversion=*) pkgversion="$optarg"
>>> @@ -1845,6 +1850,7 @@ disabled with --disable-FEATURE, default is enabled if available
>>>      vhost-user      vhost-user backend support
>>>      vhost-user-blk-server    vhost-user-blk server support
>>>      vhost-vdpa      vhost-vdpa kernel backend support
>>> +  bpf             BPF kernel support
>>>      spice           spice
>>>      rbd             rados block device (rbd)
>>>      libiscsi        iscsi support
>>> @@ -5057,6 +5063,30 @@ else
>>>        membarrier=no
>>>    fi
>>>
>>> +##########################################
>>> +# check for usable bpf system call
>>> +if test "$bpf" = ""; then
>>
>> This implies the bpf is enabled by default?
> Yes, assuming libbpf-devel present and bpf system call defined.
>
> Any problem with it?


It means the configure will fail if libbpf is not installed. Consider 
libbpf is not very common at current stage. I think it's better to make 
it auto or disabled by default.


>
>>
>>> +    have_bpf=no
>>> +    if test "$linux" = "yes" -a "$bigendian" != "yes"; then
>>> +        cat > $TMPC << EOF
>>> +    #include <stdlib.h>
>>> +    #include <bpf/libbpf.h>
>>> +    int main(void) {
>>> +        struct bpf_object *obj = NULL;
>>> +        bpf_object__load(obj);
>>> +        exit(0);
>>> +    }
>>> +EOF
>>> +        if compile_prog "" "-lbpf" ; then
>>> +            have_bpf=yes
>>> +            bpf=yes
>>> +        fi
>>> +    fi
>>> +    if test "$have_bpf" = "no"; then
>>> +      feature_not_found "bpf" "the libbpf is not available"
>>> +    fi
>>> +fi
>>> +
>>>    ##########################################
>>>    # check if rtnetlink.h exists and is useful
>>>    have_rtnetlink=no
>>> @@ -5905,6 +5935,9 @@ fi
>>>    if test "$membarrier" = "yes" ; then
>>>      echo "CONFIG_MEMBARRIER=y" >> $config_host_mak
>>>    fi
>>> +if test "$bpf" = "yes" -a "$bigendian" != "yes" -a "$linux" = "yes" ; then
>>> +  echo "CONFIG_EBPF=y" >> $config_host_mak
>>> +fi
>>>    if test "$signalfd" = "yes" ; then
>>>      echo "CONFIG_SIGNALFD=y" >> $config_host_mak
>>>    fi
>>> diff --git a/ebpf/ebpf_rss-stub.c b/ebpf/ebpf_rss-stub.c
>>> new file mode 100644
>>> index 0000000000..e71e229190
>>> --- /dev/null
>>> +++ b/ebpf/ebpf_rss-stub.c
>>> @@ -0,0 +1,40 @@
>>> +/*
>>> + * eBPF RSS stub file
>>> + *
>>> + * Developed by Daynix Computing LTD (http://www.daynix.com)
>>> + *
>>> + * Authors:
>>> + *  Yuri Benditovich <yuri.benditovich@daynix.com>
>>> + *
>>> + * This work is licensed under the terms of the GNU GPL, version 2.  See
>>> + * the COPYING file in the top-level directory.
>>> + */
>>> +
>>> +#include "qemu/osdep.h"
>>> +#include "ebpf/ebpf_rss.h"
>>
>> I wonder why not simply use #ifdef #else to exclude the rss functions.
> Just to make the reading easier.
>
>> If I read code correctly, this stub requires rss_is_loaded called before
>> ebpf_rss_set_all(), so actually ebpf_rss_is_loaded serve the same as
> Can you please get into details?
> I think the stub does not require it, it just converts all the
> ebpf_rss calls to nop at link time.
> If I miss something please let us know, we'll fix it in v4.


I mean the current can not be used without checking rss_is_loaded(). So 
rss_is_loaded() is somehow a guard like macro.

I personally prefer #ifdef but it's not a must.

Thanks



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [RFC PATCH v3 4/6] ebpf: Added eBPF RSS loader.
  2021-01-25  9:02       ` Jason Wang
@ 2021-01-25 10:52         ` Yuri Benditovich
  0 siblings, 0 replies; 20+ messages in thread
From: Yuri Benditovich @ 2021-01-25 10:52 UTC (permalink / raw)
  To: Jason Wang
  Cc: Yan Vugenfirer, Andrew Melnychenko, Daniel P. Berrangé,
	qemu-devel, Michael S . Tsirkin

On Mon, Jan 25, 2021 at 11:03 AM Jason Wang <jasowang@redhat.com> wrote:
>
>
> On 2021/1/19 下午10:53, Yuri Benditovich wrote:
> > On Fri, Jan 15, 2021 at 9:02 AM Jason Wang <jasowang@redhat.com> wrote:
> >>
> >> On 2021/1/15 上午5:16, Andrew Melnychenko wrote:
> >>> From: Andrew <andrew@daynix.com>
> >>>
> >>> Added function that loads RSS eBPF program.
> >>> Added stub functions for RSS eBPF loader.
> >>> Added meson and configuration options.
> >>>
> >>> By default, eBPF feature enabled if libbpf is present in the build system.
> >>> libbpf checked in configuration shell script and meson script.
> >>>
> >>> Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
> >>> Signed-off-by: Andrew Melnychenko <andrew@daynix.com>
> >>> ---
> >>>    configure               |  33 ++++
> >>>    ebpf/ebpf_rss-stub.c    |  40 ++++
> >>>    ebpf/ebpf_rss.c         | 165 +++++++++++++++++
> >>>    ebpf/ebpf_rss.h         |  44 +++++
> >>>    ebpf/meson.build        |   1 +
> >>>    ebpf/rss.bpf.skeleton.h | 397 ++++++++++++++++++++++++++++++++++++++++
> >>>    ebpf/trace-events       |   4 +
> >>>    ebpf/trace.h            |   2 +
> >>>    meson.build             |  13 ++
> >>>    9 files changed, 699 insertions(+)
> >>>    create mode 100644 ebpf/ebpf_rss-stub.c
> >>>    create mode 100644 ebpf/ebpf_rss.c
> >>>    create mode 100644 ebpf/ebpf_rss.h
> >>>    create mode 100644 ebpf/meson.build
> >>>    create mode 100644 ebpf/rss.bpf.skeleton.h
> >>>    create mode 100644 ebpf/trace-events
> >>>    create mode 100644 ebpf/trace.h
> >>>
> >>> diff --git a/configure b/configure
> >>> index 5860bdb77b..9d18e941f5 100755
> >>> --- a/configure
> >>> +++ b/configure
> >>> @@ -342,6 +342,7 @@ vhost_vsock="$default_feature"
> >>>    vhost_user="no"
> >>>    vhost_user_blk_server="auto"
> >>>    vhost_user_fs="$default_feature"
> >>> +bpf=""
> >>>    kvm="auto"
> >>>    hax="auto"
> >>>    hvf="auto"
> >>> @@ -1236,6 +1237,10 @@ for opt do
> >>>      ;;
> >>>      --enable-membarrier) membarrier="yes"
> >>>      ;;
> >>> +  --disable-bpf) bpf="no"
> >>> +  ;;
> >>> +  --enable-bpf) bpf="yes"
> >>> +  ;;
> >>>      --disable-blobs) blobs="false"
> >>>      ;;
> >>>      --with-pkgversion=*) pkgversion="$optarg"
> >>> @@ -1845,6 +1850,7 @@ disabled with --disable-FEATURE, default is enabled if available
> >>>      vhost-user      vhost-user backend support
> >>>      vhost-user-blk-server    vhost-user-blk server support
> >>>      vhost-vdpa      vhost-vdpa kernel backend support
> >>> +  bpf             BPF kernel support
> >>>      spice           spice
> >>>      rbd             rados block device (rbd)
> >>>      libiscsi        iscsi support
> >>> @@ -5057,6 +5063,30 @@ else
> >>>        membarrier=no
> >>>    fi
> >>>
> >>> +##########################################
> >>> +# check for usable bpf system call
> >>> +if test "$bpf" = ""; then
> >>
> >> This implies the bpf is enabled by default?
> > Yes, assuming libbpf-devel present and bpf system call defined.
> >
> > Any problem with it?
>
>
> It means the configure will fail if libbpf is not installed. Consider
> libbpf is not very common at current stage. I think it's better to make
> it auto or disabled by default.
>
>
> >
> >>
> >>> +    have_bpf=no
> >>> +    if test "$linux" = "yes" -a "$bigendian" != "yes"; then
> >>> +        cat > $TMPC << EOF
> >>> +    #include <stdlib.h>
> >>> +    #include <bpf/libbpf.h>
> >>> +    int main(void) {
> >>> +        struct bpf_object *obj = NULL;
> >>> +        bpf_object__load(obj);
> >>> +        exit(0);
> >>> +    }
> >>> +EOF
> >>> +        if compile_prog "" "-lbpf" ; then
> >>> +            have_bpf=yes
> >>> +            bpf=yes
> >>> +        fi
> >>> +    fi
> >>> +    if test "$have_bpf" = "no"; then
> >>> +      feature_not_found "bpf" "the libbpf is not available"
> >>> +    fi

Yes, this is a mistake. These 3 lines are to be removed.
If libbpf is not installed, this should not fail the build.

> >>> +fi
> >>> +
> >>>    ##########################################
> >>>    # check if rtnetlink.h exists and is useful
> >>>    have_rtnetlink=no
> >>> @@ -5905,6 +5935,9 @@ fi
> >>>    if test "$membarrier" = "yes" ; then
> >>>      echo "CONFIG_MEMBARRIER=y" >> $config_host_mak
> >>>    fi
> >>> +if test "$bpf" = "yes" -a "$bigendian" != "yes" -a "$linux" = "yes" ; then
> >>> +  echo "CONFIG_EBPF=y" >> $config_host_mak
> >>> +fi
> >>>    if test "$signalfd" = "yes" ; then
> >>>      echo "CONFIG_SIGNALFD=y" >> $config_host_mak
> >>>    fi
> >>> diff --git a/ebpf/ebpf_rss-stub.c b/ebpf/ebpf_rss-stub.c
> >>> new file mode 100644
> >>> index 0000000000..e71e229190
> >>> --- /dev/null
> >>> +++ b/ebpf/ebpf_rss-stub.c
> >>> @@ -0,0 +1,40 @@
> >>> +/*
> >>> + * eBPF RSS stub file
> >>> + *
> >>> + * Developed by Daynix Computing LTD (http://www.daynix.com)
> >>> + *
> >>> + * Authors:
> >>> + *  Yuri Benditovich <yuri.benditovich@daynix.com>
> >>> + *
> >>> + * This work is licensed under the terms of the GNU GPL, version 2.  See
> >>> + * the COPYING file in the top-level directory.
> >>> + */
> >>> +
> >>> +#include "qemu/osdep.h"
> >>> +#include "ebpf/ebpf_rss.h"
> >>
> >> I wonder why not simply use #ifdef #else to exclude the rss functions.
> > Just to make the reading easier.
> >
> >> If I read code correctly, this stub requires rss_is_loaded called before
> >> ebpf_rss_set_all(), so actually ebpf_rss_is_loaded serve the same as
> > Can you please get into details?
> > I think the stub does not require it, it just converts all the
> > ebpf_rss calls to nop at link time.
> > If I miss something please let us know, we'll fix it in v4.
>
>
> I mean the current can not be used without checking rss_is_loaded(). So
> rss_is_loaded() is somehow a guard like macro.
>
> I personally prefer #ifdef but it's not a must.
>
> Thanks
>


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2021-01-25 10:53 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-14 21:16 [RFC PATCH v3 0/6] eBPF RSS support for virtio-net Andrew Melnychenko
2021-01-14 20:54 ` no-reply
2021-01-14 21:16 ` [RFC PATCH v3 1/6] net/tap: Added TUNSETSTEERINGEBPF code Andrew Melnychenko
2021-01-14 21:16 ` [RFC PATCH v3 2/6] net: Added SetSteeringEBPF method for NetClientState Andrew Melnychenko
2021-01-14 21:16 ` [RFC PATCH v3 3/6] ebpf: Added eBPF RSS program Andrew Melnychenko
2021-01-14 21:16 ` [RFC PATCH v3 4/6] ebpf: Added eBPF RSS loader Andrew Melnychenko
2021-01-15  7:02   ` Jason Wang
2021-01-19 14:53     ` Yuri Benditovich
2021-01-25  9:02       ` Jason Wang
2021-01-25 10:52         ` Yuri Benditovich
2021-01-14 21:16 ` [RFC PATCH v3 5/6] virtio-net: Added eBPF RSS to virtio-net Andrew Melnychenko
2021-01-15  7:20   ` Jason Wang
2021-01-17  9:04     ` Yuri Benditovich
2021-01-18  3:16       ` Jason Wang
2021-01-24  8:24         ` Yuri Benditovich
2021-01-24 11:33           ` Yuri Benditovich
2021-01-25  8:59           ` Jason Wang
2021-01-14 21:16 ` [RFC PATCH v3 6/6] docs: Added eBPF documentation Andrew Melnychenko
2021-01-15  7:24   ` Jason Wang
2021-01-15  7:27 ` [RFC PATCH v3 0/6] eBPF RSS support for virtio-net Jason Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).