ebpf: Added ebpf helper for libvirtd.
cover ebpf: Added ebpf helper for libvirtd.
Libvirt usually launches qemu with strict permissions. To enable eBPF RSS steering, qemu-ebpf-rss-helper was added.
Added property "ebpf_rss_fds" for "virtio-net" that allows to initialize eBPF RSS context with passed program & maps fds.
Added qemu-ebpf-rss-helper - simple helper that loads eBPF context and passes fds through unix socket. Libvirt should call the helper and pass fds to qemu through "ebpf_rss_fds" property.
Added explicit target OS check for libbpf dependency in meson. eBPF RSS works only with Linux TAP, so there is no reason to build eBPF loader/helper for non-Linux.
Changed Qemu updates eBPF maps to array mmaping. Mmaping allows bypassing unprivileged BPF map update. Also, instead of 3 maps (config, key and indirection table) there is one map that combines everything.
Added helper stamp. To check that helper was build with qemu, qemu would check helper symbols that should contain the stamp. It was done similar to qemu modules, but checking was performed by the helper's ELF parsing.
Overall, libvirt process should not be aware of the "interface" of eBPF RSS, it will not be aware of eBPF maps/program "type" and their quantity. That's why qemu and the helper should be from the same build and be "synchronized". Technically each qemu may have its own helper. That's why "query-helper-paths" qmp command was added. Qemu should return the path to the helper that suits and libvirt should use "that" helper for "that" emulator.
qmp sample:
C: { "execute": "query-helper-paths" }
S: { "return": [
{
"name": "qemu-ebpf-rss-helper",
"path": "/usr/local/libexec/qemu-ebpf-rss-helper"
}
]}
Changes since v1:
* Mmap() used instead if bpf_map_update_elem().
* Added helper stamp.
Andrew Melnychenko (5):
ebpf: Added eBPF initialization by fds and map update.
virtio-net: Added property to load eBPF RSS with fds.
qmp: Added the helper stamp check.
ebpf_rss_helper: Added helper for eBPF RSS.
qmp: Added qemu-ebpf-rss-path command.
ebpf/ebpf_rss-stub.c | 6 + ebpf/ebpf_rss.c | 120 ++++--- ebpf/ebpf_rss.h | 8 +- ebpf/qemu-ebpf-rss-helper.c | 130 +++++++ ebpf/rss.bpf.skeleton.h | 557 +++++++++++++++--------------- hw/net/virtio-net.c | 77 ++++- include/hw/virtio/virtio-net.h | 1 + meson.build | 47 ++- monitor/meson.build | 1 + monitor/qemu-helper-stamp-utils.c | 297 ++++++++++++++++ monitor/qemu-helper-stamp-utils.h | 24 ++ monitor/qmp-cmds.c | 32 ++ qapi/misc.json | 33 ++ tools/ebpf/rss.bpf.c | 67 ++-- 14 files changed, 990 insertions(+), 410 deletions(-) create mode 100644 ebpf/qemu-ebpf-rss-helper.c create mode 100644 monitor/qemu-helper-stamp-utils.c create mode 100644 monitor/qemu-helper-stamp-utils.h
Signature · 1 line
2.31.1
PATCH 1/5 ebpf: Added eBPF initialization by fds and map update.
RSS maps are combined into one array map.
Changed eBPF map updates through mmaped array.
eBPF RSS context may be initialized by program fd and map fd. virtio-net may provide fds passed by libvirt.
--- ebpf/ebpf_rss-stub.c | 6 + ebpf/ebpf_rss.c | 120 +++++---- ebpf/ebpf_rss.h | 8 +- ebpf/rss.bpf.skeleton.h | 557 +++++++++++++++++++--------------------- tools/ebpf/rss.bpf.c | 67 ++--- 5 files changed, 365 insertions(+), 393 deletions(-)
ebpf/ebpf_rss-stub.c +6 -0
@@ -28,6 +28,12 @@ bool ebpf_rss_load(struct EBPFRSSContext *ctx)return false; } +bool ebpf_rss_load_fds (struct EBPFRSSContext *ctx,int program_fd, +int config_fd,int toeplitz_fd,int table_fd) +{ +return false; +} +bool ebpf_rss_set_all (struct EBPFRSSContext *ctx,struct EBPFRSSConfig *config,uint16_t *indirections_table,uint8_t *toeplitz_key) {
ebpf/ebpf_rss.c +58 -62
176 lines not on this page · raw message
ebpf/ebpf_rss.h +6 -2
@@ -14,12 +14,13 @@#ifndef QEMU_EBPF_RSS_H #define QEMU_EBPF_RSS_H +#define EBPF_RSS_MAX_FDS 2 +struct EBPFRSSContext {void *obj;int program_fd;int map_configuration; -int map_toeplitz_key; -int map_indirections_table; +void *mmap_configuration; }; struct EBPFRSSConfig {
@@ -36,6 +37,9 @@ bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx);bool ebpf_rss_load (struct EBPFRSSContext *ctx); +bool ebpf_rss_load_fds (struct EBPFRSSContext *ctx,int program_fd, +int config_fd,int toeplitz_fd,int table_fd); +bool ebpf_rss_set_all (struct EBPFRSSContext *ctx,struct EBPFRSSConfig *config,uint16_t *indirections_table,uint8_t *toeplitz_key);
ebpf/rss.bpf.skeleton.h +269 -288
588 lines not on this page · raw message
tools/ebpf/rss.bpf.c +26 -41
116 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH 1/5] ebpf: Added eBPF initialization by fds and map update.
Quoted 17 lines · Andrew Melnychenko
ebpf/ebpf_rss.c +7
-7-static bool ebpf_rss_set_indirections_table (struct EBPFRSSContext *ctx, -uint16_t *indirections_table, -size_t len) -{ -uint32_t i =0 ; + ctx->program_fd = program_fd; + ctx->map_configuration = config_fd; -if (!ebpf_rss_is_loaded (ctx) || indirections_table ==NULL || - len >VIRTIO_NET_RSS_MAX_TABLE_LEN ) { + ctx->mmap_configuration =mmap (NULL , qemu_real_host_page_size, +PROT_READ |PROT_WRITE ,MAP_SHARED , + ctx->map_configuration,0 ); +if (ctx->mmap_configuration ==MAP_FAILED ) { +trace_ebpf_error ("eBPF RSS" ,"can not mmap eBPF configuration array" );return false; }
ebpf/ebpf_rss.c bool ebpf_rss_load(struct EBPFRSSContext *ctx) · line 111
Quoted 10 lines
ebpf/ebpf_rss.c +0
-9-for (; i < len; ++i) { -if (bpf_map_update_elem (ctx->map_indirections_table, &i, - indirections_table + i,0 ) <0 ) { -return false; - } - } -return true; -} -
It looks to me you want to drop syscall path for map updating completely. I think we'd better keep that for backward compatibility?
Thanks
Re: [PATCH 1/5] ebpf: Added eBPF initialization by fds and map update.
Hi,
Yes - to make the bpf() syscall capabilities are required, which libvirt have no intentions to give.
Does it make any sense to leave syscall if mmap works?
Quoted 39 lines · Jason Wang
Review
Quoted 2 lines · Andrew Melnychenko
(quoted diff) +0
-2-static bool ebpf_rss_set_indirections_table(struct EBPFRSSContext *ctx, - uint16_t
*indirections_table,ebpf/ebpf_rss.c bool ebpf_rss_load(struct EBPFRSSContext *ctx)
Quoted 13 lines
ebpf/ebpf_rss.c +7
-5- size_t len) -{ -uint32_t i =0 ; + ctx->program_fd = program_fd; + ctx->map_configuration = config_fd; -if (!ebpf_rss_is_loaded (ctx) || indirections_table ==NULL || - len >VIRTIO_NET_RSS_MAX_TABLE_LEN ) { + ctx->mmap_configuration =mmap (NULL , qemu_real_host_page_size, +PROT_READ |PROT_WRITE ,MAP_SHARED , + ctx->map_configuration,0 ); +if (ctx->mmap_configuration ==MAP_FAILED ) { + trace_ebpf_error("eBPF RSS", "can not mmap eBPF configurationarray");
ebpf/ebpf_rss.c bool ebpf_rss_load(struct EBPFRSSContext *ctx) · line 111
Quoted 12 lines
return false; }ebpf/ebpf_rss.c +0
-9-for (; i < len; ++i) { -if (bpf_map_update_elem (ctx->map_indirections_table, &i, - indirections_table + i,0 ) <0 ) { -return false; - } - } -return true; -} -It looks to me you want to drop syscall path for map updating completely. I think we'd better keep that for backward compatibility?
Thanks
PATCH 2/5 virtio-net: Added property to load eBPF RSS with fds.
In reply to Andrew MelnychenkoeBPF RSS program and maps now may be passed during initialization. Initially was implemented for libvirt to launch qemu without permissions.
--- hw/net/virtio-net.c | 77 ++++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 1 + 2 files changed, 74 insertions(+), 4 deletions(-)
hw/net/virtio-net.c +73 -4
@@ -41,6 +41,7 @@#include "sysemu/sysemu.h" #include "trace.h" #include "monitor/qdev.h" +#include "monitor/monitor.h" #include "hw/pci/pci.h" #include "net_rx_pkt.h" #include "hw/virtio/vhost.h"
@@ -1223,14 +1224,81 @@ 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) +static int virtio_net_get_ebpf_rss_fds (char *str,char *fds[],int nfds) { -if (!virtio_net_attach_ebpf_to_backend (n->nic,-1 )) { -/* backend does't support steering ebpf */ +char *ptr = str; +char *cur =NULL ; +size_t len =strlen (str); +int i =0 ; + +for (; i < nfds && ptr < str + len;) { + cur =strchr (ptr,':' ); + +if (cur ==NULL ) { + fds[i] =g_strdup (ptr); + }else { + fds[i] =g_strndup (ptr, cur - ptr); + } + + i++; +if (cur ==NULL ) { +break ; + }else { + ptr = cur +1 ; + } + } + +return i; +} + +static bool virtio_net_load_ebpf_fds (VirtIONet *n) +{ +char *fds_strs[EBPF_RSS_MAX_FDS ]; +int fds[EBPF_RSS_MAX_FDS ]; +int nfds; +int ret = false; +Error *errp; +int i =0 ; + +if (n ==NULL || !n->ebpf_rss_fds) {return false; } -return ebpf_rss_load (&n->ebpf_rss); + nfds =virtio_net_get_ebpf_rss_fds (n->ebpf_rss_fds, + fds_strs,EBPF_RSS_MAX_FDS ); +for (i =0 ; i < nfds; i++) { + fds[i] =monitor_fd_param (monitor_cur (), fds_strs[i], &errp); + } + +if (nfds ==EBPF_RSS_MAX_FDS ) { + ret =ebpf_rss_load_fds (&n->ebpf_rss, fds[0 ], fds[1 ], fds[2 ], fds[3 ]); + } + +if (!ret) { +for (i =0 ; i < nfds; i++) { +close (fds[i]); + } + } + +for (i =0 ; i < nfds; i++) { +g_free (fds_strs[i]); + } + +return ret; +} + +static bool virtio_net_load_ebpf (VirtIONet *n) +{ +bool ret = true; + +if (virtio_net_attach_ebpf_to_backend (n->nic,-1 )) { +if (!(n->ebpf_rss_fds + &&virtio_net_load_ebpf_fds (n))) { + ret =ebpf_rss_load (&n->ebpf_rss); + } + } + +return ret; }static void virtio_net_unload_ebpf (VirtIONet *n)
@@ -3605,6 +3673,7 @@ static Property virtio_net_properties[] = { VIRTIO_NET_F_RSS, false),DEFINE_PROP_BIT64 ("hash" , VirtIONet, host_features,VIRTIO_NET_F_HASH_REPORT , false), +DEFINE_PROP_STRING ("ebpf_rss_fds" , VirtIONet, ebpf_rss_fds),DEFINE_PROP_BIT64 ("guest_rsc_ext" , VirtIONet, host_features,VIRTIO_NET_F_RSC_EXT , false), DEFINE_PROP_UINT32("rsc_interval", VirtIONet, rsc_timeout,
include/hw/virtio/virtio-net.h +1 -0
@@ -213,6 +213,7 @@ struct VirtIONet {VirtioNetRssData rss_data;struct NetRxPkt *rx_pkt;struct EBPFRSSContext ebpf_rss; +char *ebpf_rss_fds; }; void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
Signature · 1 line
2.31.1
Re: [PATCH 2/5] virtio-net: Added property to load eBPF RSS with fds.
Quoted 120 lines · Andrew Melnychenko
eBPF RSS program and maps now may be passed during initialization. Initially was implemented for libvirt to launch qemu without permissions.
Signed-off-by Andrew Melnychenko <[email protected]>--- hw/net/virtio-net.c | 77 ++++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 1 + 2 files changed, 74 insertions(+), 4 deletions(-)hw/net/virtio-net.c +73
-4@@ -41,6 +41,7 @@#include "sysemu/sysemu.h" #include "trace.h" #include "monitor/qdev.h" +#include "monitor/monitor.h" #include "hw/pci/pci.h" #include "net_rx_pkt.h" #include "hw/virtio/vhost.h" @@ -1223,14 +1224,81 @@ 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) +static int virtio_net_get_ebpf_rss_fds (char *str,char *fds[],int nfds) { -if (!virtio_net_attach_ebpf_to_backend (n->nic,-1 )) { -/* backend does't support steering ebpf */ +char *ptr = str; +char *cur =NULL ; +size_t len =strlen (str); +int i =0 ; + +for (; i < nfds && ptr < str + len;) { + cur =strchr (ptr,':' ); + +if (cur ==NULL ) { + fds[i] =g_strdup (ptr); + }else { + fds[i] =g_strndup (ptr, cur - ptr); + } + + i++; +if (cur ==NULL ) { +break ; + }else { + ptr = cur +1 ; + } + } + +return i; +} + +static bool virtio_net_load_ebpf_fds (VirtIONet *n) +{ +char *fds_strs[EBPF_RSS_MAX_FDS ]; +int fds[EBPF_RSS_MAX_FDS ]; +int nfds; +int ret = false; +Error *errp; +int i =0 ; + +if (n ==NULL || !n->ebpf_rss_fds) {return false; } -return ebpf_rss_load (&n->ebpf_rss); + nfds =virtio_net_get_ebpf_rss_fds (n->ebpf_rss_fds, + fds_strs,EBPF_RSS_MAX_FDS ); +for (i =0 ; i < nfds; i++) { + fds[i] =monitor_fd_param (monitor_cur (), fds_strs[i], &errp); + } + +if (nfds ==EBPF_RSS_MAX_FDS ) { + ret =ebpf_rss_load_fds (&n->ebpf_rss, fds[0 ], fds[1 ], fds[2 ], fds[3 ]); + } + +if (!ret) { +for (i =0 ; i < nfds; i++) { +close (fds[i]); + } + } + +for (i =0 ; i < nfds; i++) { +g_free (fds_strs[i]); + } + +return ret; +} + +static bool virtio_net_load_ebpf (VirtIONet *n) +{ +bool ret = true; + +if (virtio_net_attach_ebpf_to_backend (n->nic,-1 )) { +if (!(n->ebpf_rss_fds + &&virtio_net_load_ebpf_fds (n))) { + ret =ebpf_rss_load (&n->ebpf_rss); + } + } + +return ret; }static void virtio_net_unload_ebpf (VirtIONet *n)@@ -3605,6 +3673,7 @@ static Property virtio_net_properties[] = { VIRTIO_NET_F_RSS, false),DEFINE_PROP_BIT64 ("hash" , VirtIONet, host_features,VIRTIO_NET_F_HASH_REPORT , false), +DEFINE_PROP_STRING ("ebpf_rss_fds" , VirtIONet, ebpf_rss_fds),DEFINE_PROP_BIT64 ("guest_rsc_ext" , VirtIONet, host_features,VIRTIO_NET_F_RSC_EXT , false), DEFINE_PROP_UINT32("rsc_interval", VirtIONet, rsc_timeout,include/hw/virtio/virtio-net.h +0
-0
include/hw/virtio/virtio-net.h struct VirtIONet { · line 216
Quoted 4 lines
include/hw/virtio/virtio-net.h +1
-0@@ -213,6 +213,7 @@ struct VirtIONet {VirtioNetRssData rss_data;struct NetRxPkt *rx_pkt;struct EBPFRSSContext ebpf_rss; +char *ebpf_rss_fds;
I wonder if it's better to use separated properties instead of implying an order here?
E.g "program_fd", "key_map_fd", "indirection_table_map_fd" etc.
Thanks
Quoted 3 lines
include/hw/virtio/virtio-net.h +0
-0}; void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
Re: [PATCH 2/5] virtio-net: Added property to load eBPF RSS with fds.
Hi,
Quoted 3 lines
I wonder if it's better to use separated properties instead of implying an order here?
Not really, technically RSS BPF interface may be changed (it's already changed after RFC).
And libvirt should use something unified, so it's better to use fd array. If any changes occur - those changes will be applied only for qemu and the helper.
Also, now all maps are combined in one configuration map.
Quoted 144 lines · Jason Wang
hw/net/virtio-net.c static void virtio_net_detach_epbf_rss(VirtIONet
Quoted 22 lines · Andrew Melnychenko
eBPF RSS program and maps now may be passed during initialization. Initially was implemented for libvirt to launch qemu without permissions.
Signed-off-by Andrew Melnychenko <[email protected]>--- hw/net/virtio-net.c | 77 ++++++++++++++++++++++++++++++++-- include/hw/virtio/virtio-net.h | 1 + 2 files changed, 74 insertions(+), 4 deletions(-)hw/net/virtio-net.c +1
-0@@ -41,6 +41,7 @@#include "sysemu/sysemu.h" #include "trace.h" #include "monitor/qdev.h" +#include "monitor/monitor.h" #include "hw/pci/pci.h" #include "net_rx_pkt.h" #include "hw/virtio/vhost.h" @@ -1223,14 +1224,81 @@ static void virtio_net_detach_epbf_rss(VirtIONet*n)
Quoted 45 lines
hw/net/virtio-net.c +36
-3virtio_net_attach_ebpf_to_backend (n->nic,-1 ); } -static bool virtio_net_load_ebpf (VirtIONet *n) +static int virtio_net_get_ebpf_rss_fds (char *str,char *fds[],int nfds) { -if (!virtio_net_attach_ebpf_to_backend (n->nic,-1 )) { -/* backend does't support steering ebpf */ +char *ptr = str; +char *cur =NULL ; +size_t len =strlen (str); +int i =0 ; + +for (; i < nfds && ptr < str + len;) { + cur =strchr (ptr,':' ); + +if (cur ==NULL ) { + fds[i] =g_strdup (ptr); + }else { + fds[i] =g_strndup (ptr, cur - ptr); + } + + i++; +if (cur ==NULL ) { +break ; + }else { + ptr = cur +1 ; + } + } + +return i; +} + +static bool virtio_net_load_ebpf_fds (VirtIONet *n) +{ +char *fds_strs[EBPF_RSS_MAX_FDS ]; +int fds[EBPF_RSS_MAX_FDS ]; +int nfds; +int ret = false; +Error *errp; +int i =0 ; + +if (n ==NULL || !n->ebpf_rss_fds) {return false; }hw/net/virtio-net.c static void virtio_net_detach_epbf_rss(VirtIONet *n)
Quoted 10 lines
hw/net/virtio-net.c +8
-1-return ebpf_rss_load (&n->ebpf_rss); + nfds =virtio_net_get_ebpf_rss_fds (n->ebpf_rss_fds, + fds_strs,EBPF_RSS_MAX_FDS ); +for (i =0 ; i < nfds; i++) { + fds[i] =monitor_fd_param (monitor_cur (), fds_strs[i], &errp); + } + +if (nfds ==EBPF_RSS_MAX_FDS ) { + ret = ebpf_rss_load_fds(&n->ebpf_rss, fds[0], fds[1], fds[2],fds[3]);
Review
Quoted 39 lines
hw/net/virtio-net.c +28
-0+ } + +if (!ret) { +for (i =0 ; i < nfds; i++) { +close (fds[i]); + } + } + +for (i =0 ; i < nfds; i++) { +g_free (fds_strs[i]); + } + +return ret; +} + +static bool virtio_net_load_ebpf (VirtIONet *n) +{ +bool ret = true; + +if (virtio_net_attach_ebpf_to_backend (n->nic,-1 )) { +if (!(n->ebpf_rss_fds + &&virtio_net_load_ebpf_fds (n))) { + ret =ebpf_rss_load (&n->ebpf_rss); + } + } + +return ret; }static void virtio_net_unload_ebpf (VirtIONet *n)@@ -3605,6 +3673,7 @@ static Property virtio_net_properties[] = { VIRTIO_NET_F_RSS, false),DEFINE_PROP_BIT64 ("hash" , VirtIONet, host_features,VIRTIO_NET_F_HASH_REPORT , false), +DEFINE_PROP_STRING ("ebpf_rss_fds" , VirtIONet, ebpf_rss_fds),DEFINE_PROP_BIT64 ("guest_rsc_ext" , VirtIONet, host_features,VIRTIO_NET_F_RSC_EXT , false), DEFINE_PROP_UINT32("rsc_interval", VirtIONet, rsc_timeout,(quoted diff) +0
-0
b/include/hw/virtio/virtio-net.hinclude/hw/virtio/virtio-net.h struct VirtIONet { · line 216
Quoted 8 lines
index
824a69c23f..993f2f3036100644include/hw/virtio/virtio-net.h +1
-0@@ -213,6 +213,7 @@ struct VirtIONet {VirtioNetRssData rss_data;struct NetRxPkt *rx_pkt;struct EBPFRSSContext ebpf_rss; +char *ebpf_rss_fds;I wonder if it's better to use separated properties instead of implying an order here?
E.g "
program_fd", "key_map_fd", "indirection_table_map_fd" etc.Thanks
Quoted 3 lines
include/hw/virtio/virtio-net.h +0
-0}; void virtio_net_set_netclient_name(VirtIONet *n, const char *name,
PATCH 3/5 qmp: Added the helper stamp check.
In reply to Andrew MelnychenkoAdded function to check the stamp in the helper.
eBPF helper should have a special symbol that generates during build. QEMU checks the helper and determinates that it fits, so the helper will produce proper output.
--- meson.build | 10 + monitor/meson.build | 1 + monitor/qemu-helper-stamp-utils.c | 297 ++++++++++++++++++++++++++++++ monitor/qemu-helper-stamp-utils.h | 24 +++ 4 files changed, 332 insertions(+) create mode 100644 monitor/qemu-helper-stamp-utils.c create mode 100644 monitor/qemu-helper-stamp-utils.h
meson.build +10 -0
@@ -1757,6 +1757,16 @@ foreach d : hx_headers endforeach genh += hxdep +helper_stamp = custom_target( + 'qemu-helper-stamp.h', + output : 'qemu-helper-stamp.h', + input : 'ebpf/rss.bpf.skeleton.h', + command : [python, '-c', 'import hashlib; print(\'#define QEMU_HELPER_STAMP qemuHelperStamp_{}\'.format(hashlib.sha1(open(\'@INPUT@\', \'rb\').read()).hexdigest()))'], + capture: true, +) + +genh += helper_stamp + ################### # Collect sources # ###################
monitor/meson.build +1 -0
@@ -5,5 +5,6 @@ softmmu_ss.add(files( 'hmp.c', )) softmmu_ss.add([spice_headers, files('qmp-cmds.c')]) +softmmu_ss.add(files('qemu-helper-stamp-utils.c')) specific_ss.add(when: 'CONFIG_SOFTMMU', if_true: [files('misc.c'), spice])
monitor/qemu-helper-stamp-utils.c new file +297 -0
297 lines not on this page · raw message
monitor/qemu-helper-stamp-utils.h new file +24 -0
@@ -0,0 +1,24 @@ +/* +* QEMU helper stamp check utils. +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +*/ + +#ifndef QEMU_QEMU_HELPER_STAMP_UTILS_H +#define QEMU_QEMU_HELPER_STAMP_UTILS_H + +#include "qemu-helper-stamp.h" /* generated stamp per build */ + +#define QEMU_HELPER_STAMP_STR stringify(QEMU_HELPER_STAMP) + +bool qemu_check_helper_stamp (const char *path,const char *stamp); + +char *qemu_find_helper (const char *name,bool check_stamp); + +#endif /* QEMU_QEMU_HELPER_STAMP_UTILS_H */
Signature · 1 line
2.31.1
PATCH 4/5 ebpf_rss_helper: Added helper for eBPF RSS.
In reply to Andrew MelnychenkoHelper program. Loads eBPF RSS program and maps and passes them through unix socket. Libvirt may launch this helper and pass eBPF fds to qemu virtio-net. Also, libbpf dependency now exclusively for Linux.
Libbpf is used for eBPF RSS steering, which is supported only by Linux TAP. There is no reason yet to build eBPF loader and helper for non Linux systems, even if libbpf is present.
--- ebpf/qemu-ebpf-rss-helper.c | 130 ++++++++++++++++++++++++++++++++++++ meson.build | 37 ++++++---- 2 files changed, 154 insertions(+), 13 deletions(-) create mode 100644 ebpf/qemu-ebpf-rss-helper.c
ebpf/qemu-ebpf-rss-helper.c new file +130 -0
@@ -0,0 +1,130 @@ +/* +* eBPF RSS Helper +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +* Description: This is helper program for libvirtd. +* It loads eBPF RSS program and passes fds through unix socket. +* Built by meson, target - 'qemu-ebpf-rss-helper'. +*/ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> +#include <getopt.h> +#include <memory.h> +#include <errno.h> +#include <sys/socket.h> + +#include "ebpf_rss.h" + +#include "qemu-helper-stamp.h" + +void QEMU_HELPER_STAMP (void ) {} + +static int send_fds (int socket,int *fds,int n) +{ +struct msghdr msg = {}; +struct cmsghdr *cmsg =NULL ; +char buf[CMSG_SPACE (n *sizeof (int ))]; +char dummy_buffer =0 ; +struct iovec io = { .iov_base = &dummy_buffer, + .iov_len =sizeof (dummy_buffer) }; + +memset (buf,0 ,sizeof (buf)); + + msg.msg_iov = &io; + msg.msg_iovlen =1 ; + msg.msg_control = buf; + msg.msg_controllen =sizeof (buf); + + cmsg =CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level =SOL_SOCKET ; + cmsg->cmsg_type =SCM_RIGHTS ; + cmsg->cmsg_len =CMSG_LEN (n *sizeof (int )); + +memcpy (CMSG_DATA (cmsg), fds, n *sizeof (int )); + +return sendmsg (socket, &msg,0 ); +} + +static void print_help_and_exit (const char *prog,int exitcode) +{ +fprintf (stderr,"%s - load eBPF RSS program for qemu and pass eBPF fds" +" through unix socket.\n" , prog); +fprintf (stderr,"\t--fd <num>, -f <num> - unix socket file descriptor" +" used to pass eBPF fds.\n" ); +fprintf (stderr,"\t--help, -h - this help.\n" ); +exit (exitcode); +} + +int main (int argc,char **argv) +{ +char *fd_string =NULL ; +int unix_fd =0 ; +struct EBPFRSSContext ctx = {}; +int fds[EBPF_RSS_MAX_FDS ] = {}; +int ret =-1 ; + +for (;;) { +int c; +static struct option long_options[] = { + {"help" , no_argument,0 ,'h' }, + {"fd" , required_argument,0 ,'f' }, + {0 ,0 ,0 ,0 } + }; + c =getopt_long (argc, argv,"hf:" , + long_options,NULL ); + +if (c ==-1 ) { +break ; + } + +switch (c) { +case 'f' : + fd_string = optarg; +break ; +case 'h' : +default : +print_help_and_exit (argv[0 ], + c =='h' ?EXIT_SUCCESS :EXIT_FAILURE ); + } + } + +if (!fd_string) { +fprintf (stderr,"Unix file descriptor not present.\n" ); +print_help_and_exit (argv[0 ],EXIT_FAILURE ); + } + + unix_fd =atoi (fd_string); + +if (!unix_fd) { +fprintf (stderr,"Unix file descriptor is invalid.\n" ); +return EXIT_FAILURE ; + } + +ebpf_rss_init (&ctx); +if (!ebpf_rss_load (&ctx)) { +fprintf (stderr,"Can't load ebpf.\n" ); +return EXIT_FAILURE ; + } + fds[0 ] = ctx.program_fd; + fds[1 ] = ctx.map_configuration; + + ret =send_fds (unix_fd, fds,EBPF_RSS_MAX_FDS ); +if (ret <0 ) { +fprintf (stderr,"Issue while sending fds: %s.\n" ,strerror (errno)); + } + +ebpf_rss_unload (&ctx); + +return ret <0 ?EXIT_FAILURE :EXIT_SUCCESS ; +} +
meson.build +24 -13
@@ -1033,19 +1033,22 @@ if not get_option('fuse_lseek').disabled() endif # libbpf -libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') -if libbpf.found() and not cc.links(''' - #include <bpf/libbpf.h> - int main(void) - { - bpf_object__destroy_skeleton(NULL); - return 0; - }''', dependencies: libbpf) - libbpf = not_found - if get_option('bpf').enabled() - error('libbpf skeleton test failed') - else - warning('libbpf skeleton test failed, disabling') +libbpf = not_found +if targetos == 'linux' + libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') + if libbpf.found() and not cc.links(''' + #include <bpf/libbpf.h> + int main(void) + { + bpf_object__destroy_skeleton(NULL); + return 0; + }''', dependencies: libbpf) + libbpf = not_found + if get_option('bpf').enabled() + error('libbpf skeleton test failed') + else + warning('libbpf skeleton test failed, disabling') + endif endif endif
@@ -2423,6 +2426,14 @@ if have_tools dependencies: [authz, crypto, io, qom, qemuutil, libcap_ng, mpathpersist], install: true) + + if libbpf.found() + executable('qemu-ebpf-rss-helper', files( + 'ebpf/qemu-ebpf-rss-helper.c', 'ebpf/ebpf_rss.c'), + dependencies: [qemuutil, libbpf, glib], + install: true, + install_dir: get_option('libexecdir')) + endif endif if 'CONFIG_IVSHMEM' in config_host
Signature · 1 line
2.31.1
Re: [PATCH 4/5] ebpf_rss_helper: Added helper for eBPF RSS.
Quoted 2 lines · Andrew Melnychenko
Helper program. Loads eBPF RSS program and maps and passes them through unix socket. Libvirt may launch this helper and pass eBPF fds to qemu virtio-net.
I wonder if this can be done as helper for TAP/bridge.
E.g it's the qemu to launch those helper with set-uid.
Then libvirt won't even need to care about that?
Quoted 167 lines
Also, libbpf dependency now exclusively for Linux.
Libbpf is used for eBPF RSS steering, which is supported only by Linux TAP. There is no reason yet to build eBPF loader and helper for non Linux systems, even if libbpf is present.Signed-off-by Andrew Melnychenko <[email protected]>--- ebpf/qemu-ebpf-rss-helper.c | 130 ++++++++++++++++++++++++++++++++++++ meson.build | 37 ++++++---- 2 files changed, 154 insertions(+), 13 deletions(-)create mode 100644
ebpf/qemu-ebpf-rss-helper.cebpf/qemu-ebpf-rss-helper.c new file +130
-0@@ -0,0 +1,130 @@ +/* +* eBPF RSS Helper +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +* Description: This is helper program for libvirtd. +* It loads eBPF RSS program and passes fds through unix socket. +* Built by meson, target - 'qemu-ebpf-rss-helper'. +*/ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> +#include <getopt.h> +#include <memory.h> +#include <errno.h> +#include <sys/socket.h> + +#include "ebpf_rss.h" + +#include "qemu-helper-stamp.h" + +void QEMU_HELPER_STAMP (void ) {} + +static int send_fds (int socket,int *fds,int n) +{ +struct msghdr msg = {}; +struct cmsghdr *cmsg =NULL ; +char buf[CMSG_SPACE (n *sizeof (int ))]; +char dummy_buffer =0 ; +struct iovec io = { .iov_base = &dummy_buffer, + .iov_len =sizeof (dummy_buffer) }; + +memset (buf,0 ,sizeof (buf)); + + msg.msg_iov = &io; + msg.msg_iovlen =1 ; + msg.msg_control = buf; + msg.msg_controllen =sizeof (buf); + + cmsg =CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level =SOL_SOCKET ; + cmsg->cmsg_type =SCM_RIGHTS ; + cmsg->cmsg_len =CMSG_LEN (n *sizeof (int )); + +memcpy (CMSG_DATA (cmsg), fds, n *sizeof (int )); + +return sendmsg (socket, &msg,0 ); +} + +static void print_help_and_exit (const char *prog,int exitcode) +{ +fprintf (stderr,"%s - load eBPF RSS program for qemu and pass eBPF fds" +" through unix socket.\n" , prog); +fprintf (stderr,"\t--fd <num>, -f <num> - unix socket file descriptor" +" used to pass eBPF fds.\n" ); +fprintf (stderr,"\t--help, -h - this help.\n" ); +exit (exitcode); +} + +int main (int argc,char **argv) +{ +char *fd_string =NULL ; +int unix_fd =0 ; +struct EBPFRSSContext ctx = {}; +int fds[EBPF_RSS_MAX_FDS ] = {}; +int ret =-1 ; + +for (;;) { +int c; +static struct option long_options[] = { + {"help" , no_argument,0 ,'h' }, + {"fd" , required_argument,0 ,'f' }, + {0 ,0 ,0 ,0 } + }; + c =getopt_long (argc, argv,"hf:" , + long_options,NULL ); + +if (c ==-1 ) { +break ; + } + +switch (c) { +case 'f' : + fd_string = optarg; +break ; +case 'h' : +default : +print_help_and_exit (argv[0 ], + c =='h' ?EXIT_SUCCESS :EXIT_FAILURE ); + } + } + +if (!fd_string) { +fprintf (stderr,"Unix file descriptor not present.\n" ); +print_help_and_exit (argv[0 ],EXIT_FAILURE ); + } + + unix_fd =atoi (fd_string); + +if (!unix_fd) { +fprintf (stderr,"Unix file descriptor is invalid.\n" ); +return EXIT_FAILURE ; + } + +ebpf_rss_init (&ctx); +if (!ebpf_rss_load (&ctx)) { +fprintf (stderr,"Can't load ebpf.\n" ); +return EXIT_FAILURE ; + } + fds[0 ] = ctx.program_fd; + fds[1 ] = ctx.map_configuration; + + ret =send_fds (unix_fd, fds,EBPF_RSS_MAX_FDS ); +if (ret <0 ) { +fprintf (stderr,"Issue while sending fds: %s.\n" ,strerror (errno)); + } + +ebpf_rss_unload (&ctx); + +return ret <0 ?EXIT_FAILURE :EXIT_SUCCESS ; +} +meson.build +0
-11@@ -1033,19 +1033,22 @@ if not get_option('fuse_lseek').disabled() endif # libbpf -libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') -if libbpf.found() and not cc.links(''' - #include <bpf/libbpf.h> - int main(void) - { - bpf_object__destroy_skeleton(NULL); - return 0; - }''', dependencies: libbpf) - libbpf = not_found - if get_option('bpf').enabled() - error('libbpf skeleton test failed')
meson.build if not get_option('fuse_lseek').disabled() · line 1043
Quoted 10 lines
meson.build +8
-2- else - warning('libbpf skeleton test failed, disabling') +libbpf = not_found +if targetos == 'linux' + libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') + if libbpf.found() and not cc.links(''' + #include <bpf/libbpf.h> + int main(void) + { + bpf_object__destroy_skeleton(NULL);
Do we need to test whether the bpf can do mmap() here?
Thanks
Quoted 26 lines
meson.build +16
-0+ return 0; + }''', dependencies: libbpf) + libbpf = not_found + if get_option('bpf').enabled() + error('libbpf skeleton test failed') + else + warning('libbpf skeleton test failed, disabling') + endif endif endif@@ -2423,6 +2426,14 @@ if have_tools dependencies: [authz, crypto, io, qom, qemuutil, libcap_ng, mpathpersist], install: true) + + if libbpf.found() + executable('qemu-ebpf-rss-helper', files( + 'ebpf/qemu-ebpf-rss-helper.c', 'ebpf/ebpf_rss.c'), + dependencies: [qemuutil, libbpf, glib], + install: true, + install_dir: get_option('libexecdir')) + endif endif if 'CONFIG_IVSHMEM' in config_host
Re: [PATCH 4/5] ebpf_rss_helper: Added helper for eBPF RSS.
Hi,
Quoted 2 lines
I wonder if this can be done as helper for TAP/bridge.
Well, it does already, libvirt may create TAP device and pass it in command line or using getfd qmp command.
E.g it's the qemu to launch those helper with set-uid.
Quoted 1 line
Then libvirt won't even need to care about that?
Yea, we may think about this routine in the future as a fallback.
Do we need to test whether the bpf can do mmap() here?
Quoted 1 line
I'm not sure that it's required.
Quoted 234 lines · Jason Wang
Quoted 1 line · Andrew Melnychenko
Helper program. Loads eBPF RSS program and maps and passes them through
unix socket.
Quoted 1 line
Libvirt may launch this helper and pass eBPF fds to qemu virtio-net.
I wonder if this can be done as helper for TAP/bridge.
E.g it's the qemu to launch those helper with set-uid.
Then libvirt won't even need to care about that?
Quoted 2 lines
Also, libbpf dependency now exclusively for Linux.
Libbpf is used for eBPF RSS steering, which is supported only by LinuxTAP.
Quoted 1 line
There is no reason yet to build eBPF loader and helper for non Linux
systems,
Quoted 18 lines
even if libbpf is present.
Signed-off-by Andrew Melnychenko <[email protected]>--- ebpf/qemu-ebpf-rss-helper.c | 130 ++++++++++++++++++++++++++++++++++++ meson.build | 37 ++++++---- 2 files changed, 154 insertions(+), 13 deletions(-)create mode 100644
ebpf/qemu-ebpf-rss-helper.cebpf/qemu-ebpf-rss-helper.c new file +3
-0@@ -0,0 +1,130 @@ +/* +* eBPF RSS Helper +* ebpf/qemu-ebpf-rss-helper.c line 13
Quoted 10 lines
ebpf/qemu-ebpf-rss-helper.c new file +10
-0+* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +* Description: This is helper program for libvirtd. +* It loads eBPF RSS program and passes fds through unix socket.
Quoted 37 lines
ebpf/qemu-ebpf-rss-helper.c new file +37
-0+* Built by meson, target - 'qemu-ebpf-rss-helper'. +*/ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> +#include <getopt.h> +#include <memory.h> +#include <errno.h> +#include <sys/socket.h> + +#include "ebpf_rss.h" + +#include "qemu-helper-stamp.h" + +void QEMU_HELPER_STAMP (void ) {} + +static int send_fds (int socket,int *fds,int n) +{ +struct msghdr msg = {}; +struct cmsghdr *cmsg =NULL ; +char buf[CMSG_SPACE (n *sizeof (int ))]; +char dummy_buffer =0 ; +struct iovec io = { .iov_base = &dummy_buffer, + .iov_len =sizeof (dummy_buffer) }; + +memset (buf,0 ,sizeof (buf)); + + msg.msg_iov = &io; + msg.msg_iovlen =1 ; + msg.msg_control = buf; + msg.msg_controllen =sizeof (buf); + + cmsg =CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level =SOL_SOCKET ; + cmsg->cmsg_type =SCM_RIGHTS ;ebpf/qemu-ebpf-rss-helper.c
Quoted 10 lines
ebpf/qemu-ebpf-rss-helper.c new file +10
-0+ cmsg->cmsg_len =CMSG_LEN (n *sizeof (int )); + +memcpy (CMSG_DATA (cmsg), fds, n *sizeof (int )); + +return sendmsg (socket, &msg,0 ); +} + +static void print_help_and_exit (const char *prog,int exitcode) +{ + fprintf(stderr, "%s - load eBPF RSS program for qemu and pass eBPFfds"
ebpf/qemu-ebpf-rss-helper.c line 62
Quoted 2 lines
ebpf/qemu-ebpf-rss-helper.c new file +2
-0+ " through unix socket.\n", prog); + fprintf(stderr, "\t--fd <num>, -f <num> - unix socket filedescriptor"
Quoted 51 lines
ebpf/qemu-ebpf-rss-helper.c new file +51
-0+ " used to pass eBPF fds.\n"); +fprintf (stderr,"\t--help, -h - this help.\n" ); +exit (exitcode); +} + +int main (int argc,char **argv) +{ +char *fd_string =NULL ; +int unix_fd =0 ; +struct EBPFRSSContext ctx = {}; +int fds[EBPF_RSS_MAX_FDS ] = {}; +int ret =-1 ; + +for (;;) { +int c; +static struct option long_options[] = { + {"help" , no_argument,0 ,'h' }, + {"fd" , required_argument,0 ,'f' }, + {0 ,0 ,0 ,0 } + }; + c =getopt_long (argc, argv,"hf:" , + long_options,NULL ); + +if (c ==-1 ) { +break ; + } + +switch (c) { +case 'f' : + fd_string = optarg; +break ; +case 'h' : +default : +print_help_and_exit (argv[0 ], + c =='h' ?EXIT_SUCCESS :EXIT_FAILURE ); + } + } + +if (!fd_string) { +fprintf (stderr,"Unix file descriptor not present.\n" ); +print_help_and_exit (argv[0 ],EXIT_FAILURE ); + } + + unix_fd =atoi (fd_string); + +if (!unix_fd) { +fprintf (stderr,"Unix file descriptor is invalid.\n" ); +return EXIT_FAILURE ; + } + +ebpf_rss_init (&ctx);ebpf/qemu-ebpf-rss-helper.c
Quoted 10 lines
ebpf/qemu-ebpf-rss-helper.c new file +10
-0+if (!ebpf_rss_load (&ctx)) { +fprintf (stderr,"Can't load ebpf.\n" ); +return EXIT_FAILURE ; + } + fds[0 ] = ctx.program_fd; + fds[1 ] = ctx.map_configuration; + + ret =send_fds (unix_fd, fds,EBPF_RSS_MAX_FDS ); +if (ret <0 ) { + fprintf(stderr, "Issue while sending fds: %s.\n",strerror(errno));
Quoted 12 lines
ebpf/qemu-ebpf-rss-helper.c new file +7
-0+ } + +ebpf_rss_unload (&ctx); + +return ret <0 ?EXIT_FAILURE :EXIT_SUCCESS ; +} +meson.build +0
-0meson.build if not get_option('fuse_lseek').disabled() · line 1036
Quoted 4 lines
meson.build +0
-1@@ -1033,19 +1033,22 @@ if not get_option('fuse_lseek').disabled() endif # libbpf -libbpf = dependency('libbpf', required: get_option('bpf'), method:'pkg-config')
Quoted 5 lines
meson.build +0
-5-if libbpf.found() and not cc.links(''' - #include <bpf/libbpf.h> - int main(void) - { - bpf_object__destroy_skeleton(NULL);meson.build if not get_option('fuse_lseek').disabled()
Quoted 10 lines
meson.build +3
-7- return 0; - }''', dependencies: libbpf) - libbpf = not_found - if get_option('bpf').enabled() - error('libbpf skeleton test failed') - else - warning('libbpf skeleton test failed, disabling') +libbpf = not_found +if targetos == 'linux' + libbpf = dependency('libbpf', required: get_option('bpf'), method:'pkg-config')
meson.build if not get_option('fuse_lseek').disabled() · line 1043
Quoted 5 lines
meson.build +5
-0+ if libbpf.found() and not cc.links(''' + #include <bpf/libbpf.h> + int main(void) + { + bpf_object__destroy_skeleton(NULL);Do we need to test whether the bpf can do
mmap()here?Thanks
Quoted 26 lines
meson.build +16
-0+ return 0; + }''', dependencies: libbpf) + libbpf = not_found + if get_option('bpf').enabled() + error('libbpf skeleton test failed') + else + warning('libbpf skeleton test failed, disabling') + endif endif endif@@ -2423,6 +2426,14 @@ if have_tools dependencies: [authz, crypto, io, qom, qemuutil, libcap_ng, mpathpersist], install: true) + + if libbpf.found() + executable('qemu-ebpf-rss-helper', files( + 'ebpf/qemu-ebpf-rss-helper.c', 'ebpf/ebpf_rss.c'), + dependencies: [qemuutil, libbpf, glib], + install: true, + install_dir: get_option('libexecdir')) + endif endif if 'CONFIG_IVSHMEM' in config_host
Re: [PATCH 4/5] ebpf_rss_helper: Added helper for eBPF RSS.
Quoted 8 lines · Andrew Melnichenko
Hi,
I wonder if this can be done as helper for TAP/bridge.
Well, it does already, libvirt may create TAP device and pass it in command line or using getfd qmp command.
E.g it's the qemu to launch those helper with set-uid.
Quoted 7 lines
Then libvirt won't even need to care about that?
Yea, we may think about this routine in the future as a fallback.
Do we need to test whether the bpf can do
mmap()here?I'm not sure that it's required.
I think it's for back-compatibility.
E.g current codes works without mmap(), and user will surprise that it wont' work after upgrading their qemu.
Thanks
Quoted 243 lines · On Fri, Aug 20, 2021 at 6:41 AM Jason Wang <[email protected]…
在 2021/7/13 下午11:37, Andrew Melnychenko 写道:
> Helper program. Loads eBPF RSS program and maps and passes them
through unix socket.
> Libvirt may launch this helper and pass eBPF fds to qemu virtio-net.
I wonder if this can be done as helper for TAP/bridge.
E.g it's the qemu to launch those helper with set-uid.
Then libvirt won't even need to care about that?
> Also, libbpf dependency now exclusively for Linux.
> Libbpf is used for eBPF RSS steering, which is supported only by
Linux TAP.
> There is no reason yet to build eBPF loader and helper for non
Linux systems,
> even if libbpf is present.
>
> Signed-off-by: Andrew Melnychenko <[email protected]
<mailto:[email protected]>>
> ---
> ebpf/qemu-ebpf-rss-helper.c | 130
++++++++++++++++++++++++++++++++++++
> meson.build | 37 ++++++----
> 2 files changed, 154 insertions(+), 13 deletions(-)
> create mode 100644 ebpf/qemu-ebpf-rss-helper.c
>
> diff --git a/ebpf/qemu-ebpf-rss-helper.c
b/ebpf/qemu-ebpf-rss-helper.c
> new file mode 100644
> index 0000000000..fe68758f57
> --- /dev/null
> +++ b/ebpf/qemu-ebpf-rss-helper.c
> @@ -0,0 +1,130 @@
> +/*
> + * eBPF RSS Helper
> + *
> + * Developed by Daynix Computing LTD (http://www.daynix.com
<http://www.daynix.com>)
> + *
> + * Authors:
> + * Andrew Melnychenko <[email protected]
<mailto:[email protected]>>
> + *
> + * This work is licensed under the terms of the GNU GPL,
version 2. See
> + * the COPYING file in the top-level directory.
> + *
> + * Description: This is helper program for libvirtd.
> + * It loads eBPF RSS program and passes fds
through unix socket.
> + * Built by meson, target - 'qemu-ebpf-rss-helper'.
> + */
> +
> +#include <stdio.h>
> +#include <stdint.h>
> +#include <stdlib.h>
> +#include <stdbool.h>
> +#include <getopt.h>
> +#include <memory.h>
> +#include <errno.h>
> +#include <sys/socket.h>
> +
> +#include "ebpf_rss.h"
> +
> +#include "qemu-helper-stamp.h"
> +
> +void QEMU_HELPER_STAMP(void) {}
> +
> +static int send_fds(int socket, int *fds, int n)
> +{
> + struct msghdr msg = {};
> + struct cmsghdr *cmsg = NULL;
> + char buf[CMSG_SPACE(n * sizeof(int))];
> + char dummy_buffer = 0;
> + struct iovec io = { .iov_base = &dummy_buffer,
> + .iov_len = sizeof(dummy_buffer) };
> +
> + memset(buf, 0, sizeof(buf));
> +
> + msg.msg_iov = &io;
> + msg.msg_iovlen = 1;
> + msg.msg_control = buf;
> + msg.msg_controllen = sizeof(buf);
> +
> + cmsg = CMSG_FIRSTHDR(&msg);
> + cmsg->cmsg_level = SOL_SOCKET;
> + cmsg->cmsg_type = SCM_RIGHTS;
> + cmsg->cmsg_len = CMSG_LEN(n * sizeof(int));
> +
> + memcpy(CMSG_DATA(cmsg), fds, n * sizeof(int));
> +
> + return sendmsg(socket, &msg, 0);
> +}
> +
> +static void print_help_and_exit(const char *prog, int exitcode)
> +{
> + fprintf(stderr, "%s - load eBPF RSS program for qemu and
pass eBPF fds"
> + " through unix socket.\n", prog);
> + fprintf(stderr, "\t--fd <num>, -f <num> - unix socket file
descriptor"
> + " used to pass eBPF fds.\n");
> + fprintf(stderr, "\t--help, -h - this help.\n");
> + exit(exitcode);
> +}
> +
> +int main(int argc, char **argv)
> +{
> + char *fd_string = NULL;
> + int unix_fd = 0;
> + struct EBPFRSSContext ctx = {};
> + int fds[EBPF_RSS_MAX_FDS] = {};
> + int ret = -1;
> +
> + for (;;) {
> + int c;
> + static struct option long_options[] = {
> + {"help", no_argument, 0, 'h'},
> + {"fd", required_argument, 0, 'f'},
> + {0, 0, 0, 0}
> + };
> + c = getopt_long(argc, argv, "hf:",
> + long_options, NULL);
> +
> + if (c == -1) {
> + break;
> + }
> +
> + switch (c) {
> + case 'f':
> + fd_string = optarg;
> + break;
> + case 'h':
> + default:
> + print_help_and_exit(argv[0],
> + c == 'h' ? EXIT_SUCCESS : EXIT_FAILURE);
> + }
> + }
> +
> + if (!fd_string) {
> + fprintf(stderr, "Unix file descriptor not present.\n");
> + print_help_and_exit(argv[0], EXIT_FAILURE);
> + }
> +
> + unix_fd = atoi(fd_string);
> +
> + if (!unix_fd) {
> + fprintf(stderr, "Unix file descriptor is invalid.\n");
> + return EXIT_FAILURE;
> + }
> +
> + ebpf_rss_init(&ctx);
> + if (!ebpf_rss_load(&ctx)) {
> + fprintf(stderr, "Can't load ebpf.\n");
> + return EXIT_FAILURE;
> + }
> + fds[0] = ctx.program_fd;
> + fds[1] = ctx.map_configuration;
> +
> + ret = send_fds(unix_fd, fds, EBPF_RSS_MAX_FDS);
> + if (ret < 0) {
> + fprintf(stderr, "Issue while sending fds: %s.\n",
strerror(errno));
> + }
> +
> + ebpf_rss_unload(&ctx);
> +
> + return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
> +}
> +
> diff --git a/meson.build b/meson.build
> index 257e51d91b..913aa1fee5 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -1033,19 +1033,22 @@ if not get_option('fuse_lseek').disabled()
> endif
>
> # libbpf
> -libbpf = dependency('libbpf', required: get_option('bpf'),
method: 'pkg-config')
> -if libbpf.found() and not cc.links('''
> - #include <bpf/libbpf.h>
> - int main(void)
> - {
> - bpf_object__destroy_skeleton(NULL);
> - return 0;
> - }''', dependencies: libbpf)
> - libbpf = not_found
> - if get_option('bpf').enabled()
> - error('libbpf skeleton test failed')
> - else
> - warning('libbpf skeleton test failed, disabling')
> +libbpf = not_found
> +if targetos == 'linux'
> + libbpf = dependency('libbpf', required: get_option('bpf'),
method: 'pkg-config')
> + if libbpf.found() and not cc.links('''
> + #include <bpf/libbpf.h>
> + int main(void)
> + {
> + bpf_object__destroy_skeleton(NULL);
Do we need to test whether the bpf can do mmap() here?
Thanks
> + return 0;
> + }''', dependencies: libbpf)
> + libbpf = not_found
> + if get_option('bpf').enabled()
> + error('libbpf skeleton test failed')
> + else
> + warning('libbpf skeleton test failed, disabling')
> + endif
> endif
> endif
>
> @@ -2423,6 +2426,14 @@ if have_tools
> dependencies: [authz, crypto, io, qom, qemuutil,
> libcap_ng, mpathpersist],
> install: true)
> +
> + if libbpf.found()
> + executable('qemu-ebpf-rss-helper', files(
> + 'ebpf/qemu-ebpf-rss-helper.c',
'ebpf/ebpf_rss.c'),
> + dependencies: [qemuutil, libbpf, glib],
> + install: true,
> + install_dir: get_option('libexecdir'))
> + endif
> endif
>
> if 'CONFIG_IVSHMEM' in config_hostRe: [PATCH 4/5] ebpf_rss_helper: Added helper for eBPF RSS.
In reply to Jason WangQuoted 7 lines · Jason Wang
Quoted 2 lines · Andrew Melnychenko
Helper program. Loads eBPF RSS program and maps and passes them through unix socket. Libvirt may launch this helper and pass eBPF fds to qemu virtio-net.
Quoted 6 lines
I wonder if this can be done as helper for TAP/bridge.
E.g it's the qemu to launch those helper with set-uid.
Then libvirt won't even need to care about that?
There are pros and cons for such a solution with set-uid. From my point of view one of the cons is that set-uid is efficient only at install time so the coexistence of different qemu builds (and different helpers for each one) is kind of problematic. With the current solution this does not present any problem: the developer can have several different builds, each one automatically has its own helper and there is no conflict between these builds and between these builds and installed qemu package. Changing the 'emulator' in the libvirt profile automatically brings the proper helper to work.
Quoted 212 lines
Quoted 168 lines
Also, libbpf dependency now exclusively for Linux.
Libbpf is used for eBPF RSS steering, which is supported only by Linux TAP. There is no reason yet to build eBPF loader and helper for non Linux systems, even if libbpf is present.Signed-off-by Andrew Melnychenko <[email protected]>--- ebpf/qemu-ebpf-rss-helper.c | 130 ++++++++++++++++++++++++++++++++++++ meson.build | 37 ++++++---- 2 files changed, 154 insertions(+), 13 deletions(-)create mode 100644
ebpf/qemu-ebpf-rss-helper.cebpf/qemu-ebpf-rss-helper.c new file +130
-0@@ -0,0 +1,130 @@ +/* +* eBPF RSS Helper +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +* Description: This is helper program for libvirtd. +* It loads eBPF RSS program and passes fds through unix socket. +* Built by meson, target - 'qemu-ebpf-rss-helper'. +*/ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> +#include <getopt.h> +#include <memory.h> +#include <errno.h> +#include <sys/socket.h> + +#include "ebpf_rss.h" + +#include "qemu-helper-stamp.h" + +void QEMU_HELPER_STAMP (void ) {} + +static int send_fds (int socket,int *fds,int n) +{ +struct msghdr msg = {}; +struct cmsghdr *cmsg =NULL ; +char buf[CMSG_SPACE (n *sizeof (int ))]; +char dummy_buffer =0 ; +struct iovec io = { .iov_base = &dummy_buffer, + .iov_len =sizeof (dummy_buffer) }; + +memset (buf,0 ,sizeof (buf)); + + msg.msg_iov = &io; + msg.msg_iovlen =1 ; + msg.msg_control = buf; + msg.msg_controllen =sizeof (buf); + + cmsg =CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level =SOL_SOCKET ; + cmsg->cmsg_type =SCM_RIGHTS ; + cmsg->cmsg_len =CMSG_LEN (n *sizeof (int )); + +memcpy (CMSG_DATA (cmsg), fds, n *sizeof (int )); + +return sendmsg (socket, &msg,0 ); +} + +static void print_help_and_exit (const char *prog,int exitcode) +{ +fprintf (stderr,"%s - load eBPF RSS program for qemu and pass eBPF fds" +" through unix socket.\n" , prog); +fprintf (stderr,"\t--fd <num>, -f <num> - unix socket file descriptor" +" used to pass eBPF fds.\n" ); +fprintf (stderr,"\t--help, -h - this help.\n" ); +exit (exitcode); +} + +int main (int argc,char **argv) +{ +char *fd_string =NULL ; +int unix_fd =0 ; +struct EBPFRSSContext ctx = {}; +int fds[EBPF_RSS_MAX_FDS ] = {}; +int ret =-1 ; + +for (;;) { +int c; +static struct option long_options[] = { + {"help" , no_argument,0 ,'h' }, + {"fd" , required_argument,0 ,'f' }, + {0 ,0 ,0 ,0 } + }; + c =getopt_long (argc, argv,"hf:" , + long_options,NULL ); + +if (c ==-1 ) { +break ; + } + +switch (c) { +case 'f' : + fd_string = optarg; +break ; +case 'h' : +default : +print_help_and_exit (argv[0 ], + c =='h' ?EXIT_SUCCESS :EXIT_FAILURE ); + } + } + +if (!fd_string) { +fprintf (stderr,"Unix file descriptor not present.\n" ); +print_help_and_exit (argv[0 ],EXIT_FAILURE ); + } + + unix_fd =atoi (fd_string); + +if (!unix_fd) { +fprintf (stderr,"Unix file descriptor is invalid.\n" ); +return EXIT_FAILURE ; + } + +ebpf_rss_init (&ctx); +if (!ebpf_rss_load (&ctx)) { +fprintf (stderr,"Can't load ebpf.\n" ); +return EXIT_FAILURE ; + } + fds[0 ] = ctx.program_fd; + fds[1 ] = ctx.map_configuration; + + ret =send_fds (unix_fd, fds,EBPF_RSS_MAX_FDS ); +if (ret <0 ) { +fprintf (stderr,"Issue while sending fds: %s.\n" ,strerror (errno)); + } + +ebpf_rss_unload (&ctx); + +return ret <0 ?EXIT_FAILURE :EXIT_SUCCESS ; +} +meson.build +0
-11@@ -1033,19 +1033,22 @@ if not get_option('fuse_lseek').disabled() endif # libbpf -libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') -if libbpf.found() and not cc.links(''' - #include <bpf/libbpf.h> - int main(void) - { - bpf_object__destroy_skeleton(NULL); - return 0; - }''', dependencies: libbpf) - libbpf = not_found - if get_option('bpf').enabled() - error('libbpf skeleton test failed')meson.build if not get_option('fuse_lseek').disabled() · line 1043
Quoted 10 lines
meson.build +8
-2- else - warning('libbpf skeleton test failed, disabling') +libbpf = not_found +if targetos == 'linux' + libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') + if libbpf.found() and not cc.links(''' + #include <bpf/libbpf.h> + int main(void) + { + bpf_object__destroy_skeleton(NULL);Do we need to test whether the bpf can do
mmap()here?Thanks
Quoted 26 lines
meson.build +16
-0+ return 0; + }''', dependencies: libbpf) + libbpf = not_found + if get_option('bpf').enabled() + error('libbpf skeleton test failed') + else + warning('libbpf skeleton test failed, disabling') + endif endif endif@@ -2423,6 +2426,14 @@ if have_tools dependencies: [authz, crypto, io, qom, qemuutil, libcap_ng, mpathpersist], install: true) + + if libbpf.found() + executable('qemu-ebpf-rss-helper', files( + 'ebpf/qemu-ebpf-rss-helper.c', 'ebpf/ebpf_rss.c'), + dependencies: [qemuutil, libbpf, glib], + install: true, + install_dir: get_option('libexecdir')) + endif endif if 'CONFIG_IVSHMEM' in config_host
Re: [PATCH 4/5] ebpf_rss_helper: Added helper for eBPF RSS.
Quoted 12 lines · Yuri Benditovich
Quoted 11 lines · Jason Wang
Quoted 2 lines · Andrew Melnychenko
Helper program. Loads eBPF RSS program and maps and passes them through unix socket. Libvirt may launch this helper and pass eBPF fds to qemu virtio-net.
I wonder if this can be done as helper for TAP/bridge.
E.g it's the qemu to launch those helper with set-uid.
Then libvirt won't even need to care about that?
Quoted 10 lines
There are pros and cons for such a solution with set-uid.
From my point of view one of the cons is that set-uid is efficient
only at install time so the coexistence of different qemu builds (and different helpers for each one) is kind of problematic. With the current solution this does not present any problem: the developer can have several different builds, each one automatically has its own helper and there is no conflict between these builds and between these builds and installed qemu package. Changing the 'emulator' in the libvirt profile automatically brings the proper helper to work.
I'm not sure I get you here. We can still have default/sample helper to make sure it works for different builds.
If we can avoid the involvement of libvirt, that would be better.
Thanks
Quoted 210 lines
Quoted 210 lines
Quoted 168 lines
Also, libbpf dependency now exclusively for Linux.
Libbpf is used for eBPF RSS steering, which is supported only by Linux TAP. There is no reason yet to build eBPF loader and helper for non Linux systems, even if libbpf is present.Signed-off-by Andrew Melnychenko <[email protected]>--- ebpf/qemu-ebpf-rss-helper.c | 130 ++++++++++++++++++++++++++++++++++++ meson.build | 37 ++++++---- 2 files changed, 154 insertions(+), 13 deletions(-)create mode 100644
ebpf/qemu-ebpf-rss-helper.cebpf/qemu-ebpf-rss-helper.c new file +130
-0@@ -0,0 +1,130 @@ +/* +* eBPF RSS Helper +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +* Description: This is helper program for libvirtd. +* It loads eBPF RSS program and passes fds through unix socket. +* Built by meson, target - 'qemu-ebpf-rss-helper'. +*/ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> +#include <getopt.h> +#include <memory.h> +#include <errno.h> +#include <sys/socket.h> + +#include "ebpf_rss.h" + +#include "qemu-helper-stamp.h" + +void QEMU_HELPER_STAMP (void ) {} + +static int send_fds (int socket,int *fds,int n) +{ +struct msghdr msg = {}; +struct cmsghdr *cmsg =NULL ; +char buf[CMSG_SPACE (n *sizeof (int ))]; +char dummy_buffer =0 ; +struct iovec io = { .iov_base = &dummy_buffer, + .iov_len =sizeof (dummy_buffer) }; + +memset (buf,0 ,sizeof (buf)); + + msg.msg_iov = &io; + msg.msg_iovlen =1 ; + msg.msg_control = buf; + msg.msg_controllen =sizeof (buf); + + cmsg =CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level =SOL_SOCKET ; + cmsg->cmsg_type =SCM_RIGHTS ; + cmsg->cmsg_len =CMSG_LEN (n *sizeof (int )); + +memcpy (CMSG_DATA (cmsg), fds, n *sizeof (int )); + +return sendmsg (socket, &msg,0 ); +} + +static void print_help_and_exit (const char *prog,int exitcode) +{ +fprintf (stderr,"%s - load eBPF RSS program for qemu and pass eBPF fds" +" through unix socket.\n" , prog); +fprintf (stderr,"\t--fd <num>, -f <num> - unix socket file descriptor" +" used to pass eBPF fds.\n" ); +fprintf (stderr,"\t--help, -h - this help.\n" ); +exit (exitcode); +} + +int main (int argc,char **argv) +{ +char *fd_string =NULL ; +int unix_fd =0 ; +struct EBPFRSSContext ctx = {}; +int fds[EBPF_RSS_MAX_FDS ] = {}; +int ret =-1 ; + +for (;;) { +int c; +static struct option long_options[] = { + {"help" , no_argument,0 ,'h' }, + {"fd" , required_argument,0 ,'f' }, + {0 ,0 ,0 ,0 } + }; + c =getopt_long (argc, argv,"hf:" , + long_options,NULL ); + +if (c ==-1 ) { +break ; + } + +switch (c) { +case 'f' : + fd_string = optarg; +break ; +case 'h' : +default : +print_help_and_exit (argv[0 ], + c =='h' ?EXIT_SUCCESS :EXIT_FAILURE ); + } + } + +if (!fd_string) { +fprintf (stderr,"Unix file descriptor not present.\n" ); +print_help_and_exit (argv[0 ],EXIT_FAILURE ); + } + + unix_fd =atoi (fd_string); + +if (!unix_fd) { +fprintf (stderr,"Unix file descriptor is invalid.\n" ); +return EXIT_FAILURE ; + } + +ebpf_rss_init (&ctx); +if (!ebpf_rss_load (&ctx)) { +fprintf (stderr,"Can't load ebpf.\n" ); +return EXIT_FAILURE ; + } + fds[0 ] = ctx.program_fd; + fds[1 ] = ctx.map_configuration; + + ret =send_fds (unix_fd, fds,EBPF_RSS_MAX_FDS ); +if (ret <0 ) { +fprintf (stderr,"Issue while sending fds: %s.\n" ,strerror (errno)); + } + +ebpf_rss_unload (&ctx); + +return ret <0 ?EXIT_FAILURE :EXIT_SUCCESS ; +} +meson.build +0
-11@@ -1033,19 +1033,22 @@ if not get_option('fuse_lseek').disabled() endif # libbpf -libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') -if libbpf.found() and not cc.links(''' - #include <bpf/libbpf.h> - int main(void) - { - bpf_object__destroy_skeleton(NULL); - return 0; - }''', dependencies: libbpf) - libbpf = not_found - if get_option('bpf').enabled() - error('libbpf skeleton test failed')meson.build if not get_option('fuse_lseek').disabled() · line 1043
Quoted 10 lines
meson.build +8
-2- else - warning('libbpf skeleton test failed, disabling') +libbpf = not_found +if targetos == 'linux' + libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') + if libbpf.found() and not cc.links(''' + #include <bpf/libbpf.h> + int main(void) + { + bpf_object__destroy_skeleton(NULL);Do we need to test whether the bpf can do
mmap()here?Thanks
Quoted 26 lines
meson.build +16
-0+ return 0; + }''', dependencies: libbpf) + libbpf = not_found + if get_option('bpf').enabled() + error('libbpf skeleton test failed') + else + warning('libbpf skeleton test failed, disabling') + endif endif endif@@ -2423,6 +2426,14 @@ if have_tools dependencies: [authz, crypto, io, qom, qemuutil, libcap_ng, mpathpersist], install: true) + + if libbpf.found() + executable('qemu-ebpf-rss-helper', files( + 'ebpf/qemu-ebpf-rss-helper.c', 'ebpf/ebpf_rss.c'), + dependencies: [qemuutil, libbpf, glib], + install: true, + install_dir: get_option('libexecdir')) + endif endif if 'CONFIG_IVSHMEM' in config_host
Re: [PATCH 4/5] ebpf_rss_helper: Added helper for eBPF RSS.
Hi,
Quoted 5 lines
I think it's for back-compatibility.
E.g current codes works without
mmap(), and user will surprise that it wont' work after upgrading their qemu.
Well, the current code would require additional capabilities with "kernel.unprivileged_bpf_disabled=1", which may be possible on RedHat systems.
Technically we may have mmap test which will show that mmap for BPF_MAP_TYPE_ARRAY works, but on the target system, we will know it only in runtime.
If I'm not mistaken, mmap for BPF_MAP_TYPE_ARRAY was added before kernel 5.4 and our bpf program requires kernel 5.8+.
So, there are no reasons to add bpf() update map as a fallback for mmap().
Quoted 257 lines · Jason Wang
Quoted 4 lines · Yuri Benditovich
Quoted 3 lines · Jason Wang
Quoted 1 line · Andrew Melnychenko
Helper program. Loads eBPF RSS program and maps and passes them
through unix socket.
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Libvirt may launch this helper and pass eBPF fds to qemu virtio-net.
I wonder if this can be done as helper for TAP/bridge.
E.g it's the qemu to launch those helper with set-uid.
Then libvirt won't even need to care about that?
Quoted 10 lines
There are pros and cons for such a solution with set-uid.
From my point of view one of the cons is that set-uid is efficient
only at install time so the coexistence of different qemu builds (and different helpers for each one) is kind of problematic. With the current solution this does not present any problem: the developer can have several different builds, each one automatically has its own helper and there is no conflict between these builds and between these builds and installed qemu package. Changing the 'emulator' in the libvirt profile automatically brings the proper helper to work.I'm not sure I get you here. We can still have default/sample helper to make sure it works for different builds.
If we can avoid the involvement of libvirt, that would be better.
Thanks
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Also, libbpf dependency now exclusively for Linux.
Libbpf is used for eBPF RSS steering, which is supported only by LinuxTAP.
Quoted 1 line
Quoted 1 line
Quoted 1 line
There is no reason yet to build eBPF loader and helper for non Linux
systems,
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
even if libbpf is present.
Signed-off-by Andrew Melnychenko <[email protected]>--- ebpf/qemu-ebpf-rss-helper.c | 130++++++++++++++++++++++++++++++++++++
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
meson.build | 37 ++++++---- 2 files changed, 154 insertions(+), 13 deletions(-)create mode 100644
ebpf/qemu-ebpf-rss-helper.cQuoted 15 lines
Quoted 7 lines
Quoted 7 lines
ebpf/qemu-ebpf-rss-helper.c new file +1
-0@@ -0,0 +1,130 @@ +/* Quoted 8 lines
ebpf/qemu-ebpf-rss-helper.c
Quoted 8 lines
ebpf/qemu-ebpf-rss-helper.c new file +8
-0+* eBPF RSS Helper +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See
Quoted 4 lines
Quoted 4 lines
ebpf/qemu-ebpf-rss-helper.c
Quoted 4 lines
ebpf/qemu-ebpf-rss-helper.c new file +4
-0+* the COPYING file in the top-level directory. +* +* Description: This is helper program for libvirtd. +* It loads eBPF RSS program and passes fds through unix socket.
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
ebpf/qemu-ebpf-rss-helper.c new file +39
-0+* Built by meson, target - 'qemu-ebpf-rss-helper'. +*/ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> +#include <getopt.h> +#include <memory.h> +#include <errno.h> +#include <sys/socket.h> + +#include "ebpf_rss.h" + +#include "qemu-helper-stamp.h" + +void QEMU_HELPER_STAMP (void ) {} + +static int send_fds (int socket,int *fds,int n) +{ +struct msghdr msg = {}; +struct cmsghdr *cmsg =NULL ; +char buf[CMSG_SPACE (n *sizeof (int ))]; +char dummy_buffer =0 ; +struct iovec io = { .iov_base = &dummy_buffer, + .iov_len =sizeof (dummy_buffer) }; + +memset (buf,0 ,sizeof (buf)); + + msg.msg_iov = &io; + msg.msg_iovlen =1 ; + msg.msg_control = buf; + msg.msg_controllen =sizeof (buf); + + cmsg =CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level =SOL_SOCKET ; + cmsg->cmsg_type =SCM_RIGHTS ; + cmsg->cmsg_len =CMSG_LEN (n *sizeof (int )); +Quoted 8 lines
Quoted 8 lines
ebpf/qemu-ebpf-rss-helper.c
Quoted 8 lines
ebpf/qemu-ebpf-rss-helper.c new file +8
-0+memcpy (CMSG_DATA (cmsg), fds, n *sizeof (int )); + +return sendmsg (socket, &msg,0 ); +} + +static void print_help_and_exit (const char *prog,int exitcode) +{ + fprintf(stderr, "%s - load eBPF RSS program for qemu and passeBPF fds"
Quoted 2 lines
Quoted 2 lines
ebpf/qemu-ebpf-rss-helper.c line 62
Quoted 2 lines
ebpf/qemu-ebpf-rss-helper.c new file +2
-0+ " through unix socket.\n", prog); + fprintf(stderr, "\t--fd <num>, -f <num> - unix socket filedescriptor"
Quoted 53 lines
Quoted 53 lines
Quoted 53 lines
ebpf/qemu-ebpf-rss-helper.c new file +53
-0+ " used to pass eBPF fds.\n"); +fprintf (stderr,"\t--help, -h - this help.\n" ); +exit (exitcode); +} + +int main (int argc,char **argv) +{ +char *fd_string =NULL ; +int unix_fd =0 ; +struct EBPFRSSContext ctx = {}; +int fds[EBPF_RSS_MAX_FDS ] = {}; +int ret =-1 ; + +for (;;) { +int c; +static struct option long_options[] = { + {"help" , no_argument,0 ,'h' }, + {"fd" , required_argument,0 ,'f' }, + {0 ,0 ,0 ,0 } + }; + c =getopt_long (argc, argv,"hf:" , + long_options,NULL ); + +if (c ==-1 ) { +break ; + } + +switch (c) { +case 'f' : + fd_string = optarg; +break ; +case 'h' : +default : +print_help_and_exit (argv[0 ], + c =='h' ?EXIT_SUCCESS :EXIT_FAILURE ); + } + } + +if (!fd_string) { +fprintf (stderr,"Unix file descriptor not present.\n" ); +print_help_and_exit (argv[0 ],EXIT_FAILURE ); + } + + unix_fd =atoi (fd_string); + +if (!unix_fd) { +fprintf (stderr,"Unix file descriptor is invalid.\n" ); +return EXIT_FAILURE ; + } + +ebpf_rss_init (&ctx); +if (!ebpf_rss_load (&ctx)) { +fprintf (stderr,"Can't load ebpf.\n" );Quoted 8 lines
Quoted 8 lines
ebpf/qemu-ebpf-rss-helper.c
Quoted 8 lines
ebpf/qemu-ebpf-rss-helper.c new file +8
-0+return EXIT_FAILURE ; + } + fds[0 ] = ctx.program_fd; + fds[1 ] = ctx.map_configuration; + + ret =send_fds (unix_fd, fds,EBPF_RSS_MAX_FDS ); +if (ret <0 ) { + fprintf(stderr, "Issue while sending fds: %s.\n",strerror(errno));
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
ebpf/qemu-ebpf-rss-helper.c new file +7
-0+ } + +ebpf_rss_unload (&ctx); + +return ret <0 ?EXIT_FAILURE :EXIT_SUCCESS ; +} +meson.build +0
-0@@ -1033,19 +1033,22 @@ if not get_option('fuse_lseek').disabled() endifQuoted 2 lines
Quoted 2 lines
meson.build if not get_option('fuse_lseek').disabled() · line 1036
Quoted 2 lines
meson.build +0
-1# libbpf -libbpf = dependency('libbpf', required: get_option('bpf'), method:'pkg-config')
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
meson.build +0
-7-if libbpf.found() and not cc.links(''' - #include <bpf/libbpf.h> - int main(void) - { - bpf_object__destroy_skeleton(NULL); - return 0; - }''', dependencies: libbpf)Quoted 8 lines
Quoted 8 lines
meson.build if not get_option('fuse_lseek').disabled()
Quoted 8 lines
meson.build +3
-5- libbpf = not_found - if get_option('bpf').enabled() - error('libbpf skeleton test failed') - else - warning('libbpf skeleton test failed, disabling') +libbpf = not_found +if targetos == 'linux' + libbpf = dependency('libbpf', required: get_option('bpf'), method:'pkg-config')
Quoted 37 lines
Quoted 37 lines
meson.build if not get_option('fuse_lseek').disabled() · line 1043
Quoted 5 lines
meson.build +5
-0+ if libbpf.found() and not cc.links(''' + #include <bpf/libbpf.h> + int main(void) + { + bpf_object__destroy_skeleton(NULL);Do we need to test whether the bpf can do
mmap()here?Thanks
Quoted 26 lines
meson.build +16
-0+ return 0; + }''', dependencies: libbpf) + libbpf = not_found + if get_option('bpf').enabled() + error('libbpf skeleton test failed') + else + warning('libbpf skeleton test failed, disabling') + endif endif endif@@ -2423,6 +2426,14 @@ if have_tools dependencies: [authz, crypto, io, qom, qemuutil, libcap_ng, mpathpersist], install: true) + + if libbpf.found() + executable('qemu-ebpf-rss-helper', files( + 'ebpf/qemu-ebpf-rss-helper.c', 'ebpf/ebpf_rss.c'), + dependencies: [qemuutil, libbpf, glib], + install: true, + install_dir: get_option('libexecdir')) + endif endif if 'CONFIG_IVSHMEM' in config_host
Re: [PATCH 4/5] ebpf_rss_helper: Added helper for eBPF RSS.
Quoted 11 lines · Andrew Melnichenko
Hi,
Quoted 5 lines
I think it's for back-compatibility.
E.g current codes works without
mmap(), and user will surprise that it wont' work after upgrading their qemu.Well, the current code would require additional capabilities with "kernel.unprivileged_bpf_disabled=1", which may be possible on RedHat systems. Technically we may have mmap test which will show that mmap for
BPF_MAP_TYPE_ARRAYworks, but on the target system, we will know it only in runtime. If I'm not mistaken, mmap forBPF_MAP_TYPE_ARRAYwas added before kernel 5.4 and our bpf program requires kernel 5.8+.
Ok, if this is the case, please explain this in the commit log.
Btw, any reason that 5.8 is required for our bpf program?
Thanks
Quoted 249 lines
So, there are no reasons to add
bpf()update map as a fallback formmap().Quoted 246 lines · Jason Wang
Quoted 12 lines · Yuri Benditovich
Quoted 11 lines · Jason Wang
Quoted 2 lines · Andrew Melnychenko
Helper program. Loads eBPF RSS program and maps and passes them through unix socket. Libvirt may launch this helper and pass eBPF fds to qemu virtio-net.
I wonder if this can be done as helper for TAP/bridge.
E.g it's the qemu to launch those helper with set-uid.
Then libvirt won't even need to care about that?
Quoted 10 lines
There are pros and cons for such a solution with set-uid.
From my point of view one of the cons is that set-uid is efficient
only at install time so the coexistence of different qemu builds (and different helpers for each one) is kind of problematic. With the current solution this does not present any problem: the developer can have several different builds, each one automatically has its own helper and there is no conflict between these builds and between these builds and installed qemu package. Changing the 'emulator' in the libvirt profile automatically brings the proper helper to work.I'm not sure I get you here. We can still have default/sample helper to make sure it works for different builds.
If we can avoid the involvement of libvirt, that would be better.
Thanks
Quoted 210 lines
Quoted 210 lines
Quoted 168 lines
Also, libbpf dependency now exclusively for Linux.
Libbpf is used for eBPF RSS steering, which is supported only by Linux TAP. There is no reason yet to build eBPF loader and helper for non Linux systems, even if libbpf is present.Signed-off-by Andrew Melnychenko <[email protected]>--- ebpf/qemu-ebpf-rss-helper.c | 130 ++++++++++++++++++++++++++++++++++++ meson.build | 37 ++++++---- 2 files changed, 154 insertions(+), 13 deletions(-)create mode 100644
ebpf/qemu-ebpf-rss-helper.cebpf/qemu-ebpf-rss-helper.c new file +130
-0@@ -0,0 +1,130 @@ +/* +* eBPF RSS Helper +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +* Description: This is helper program for libvirtd. +* It loads eBPF RSS program and passes fds through unix socket. +* Built by meson, target - 'qemu-ebpf-rss-helper'. +*/ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> +#include <getopt.h> +#include <memory.h> +#include <errno.h> +#include <sys/socket.h> + +#include "ebpf_rss.h" + +#include "qemu-helper-stamp.h" + +void QEMU_HELPER_STAMP (void ) {} + +static int send_fds (int socket,int *fds,int n) +{ +struct msghdr msg = {}; +struct cmsghdr *cmsg =NULL ; +char buf[CMSG_SPACE (n *sizeof (int ))]; +char dummy_buffer =0 ; +struct iovec io = { .iov_base = &dummy_buffer, + .iov_len =sizeof (dummy_buffer) }; + +memset (buf,0 ,sizeof (buf)); + + msg.msg_iov = &io; + msg.msg_iovlen =1 ; + msg.msg_control = buf; + msg.msg_controllen =sizeof (buf); + + cmsg =CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level =SOL_SOCKET ; + cmsg->cmsg_type =SCM_RIGHTS ; + cmsg->cmsg_len =CMSG_LEN (n *sizeof (int )); + +memcpy (CMSG_DATA (cmsg), fds, n *sizeof (int )); + +return sendmsg (socket, &msg,0 ); +} + +static void print_help_and_exit (const char *prog,int exitcode) +{ +fprintf (stderr,"%s - load eBPF RSS program for qemu and pass eBPF fds" +" through unix socket.\n" , prog); +fprintf (stderr,"\t--fd <num>, -f <num> - unix socket file descriptor" +" used to pass eBPF fds.\n" ); +fprintf (stderr,"\t--help, -h - this help.\n" ); +exit (exitcode); +} + +int main (int argc,char **argv) +{ +char *fd_string =NULL ; +int unix_fd =0 ; +struct EBPFRSSContext ctx = {}; +int fds[EBPF_RSS_MAX_FDS ] = {}; +int ret =-1 ; + +for (;;) { +int c; +static struct option long_options[] = { + {"help" , no_argument,0 ,'h' }, + {"fd" , required_argument,0 ,'f' }, + {0 ,0 ,0 ,0 } + }; + c =getopt_long (argc, argv,"hf:" , + long_options,NULL ); + +if (c ==-1 ) { +break ; + } + +switch (c) { +case 'f' : + fd_string = optarg; +break ; +case 'h' : +default : +print_help_and_exit (argv[0 ], + c =='h' ?EXIT_SUCCESS :EXIT_FAILURE ); + } + } + +if (!fd_string) { +fprintf (stderr,"Unix file descriptor not present.\n" ); +print_help_and_exit (argv[0 ],EXIT_FAILURE ); + } + + unix_fd =atoi (fd_string); + +if (!unix_fd) { +fprintf (stderr,"Unix file descriptor is invalid.\n" ); +return EXIT_FAILURE ; + } + +ebpf_rss_init (&ctx); +if (!ebpf_rss_load (&ctx)) { +fprintf (stderr,"Can't load ebpf.\n" ); +return EXIT_FAILURE ; + } + fds[0 ] = ctx.program_fd; + fds[1 ] = ctx.map_configuration; + + ret =send_fds (unix_fd, fds,EBPF_RSS_MAX_FDS ); +if (ret <0 ) { +fprintf (stderr,"Issue while sending fds: %s.\n" ,strerror (errno)); + } + +ebpf_rss_unload (&ctx); + +return ret <0 ?EXIT_FAILURE :EXIT_SUCCESS ; +} +meson.build +0
-11@@ -1033,19 +1033,22 @@ if not get_option('fuse_lseek').disabled() endif # libbpf -libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') -if libbpf.found() and not cc.links(''' - #include <bpf/libbpf.h> - int main(void) - { - bpf_object__destroy_skeleton(NULL); - return 0; - }''', dependencies: libbpf) - libbpf = not_found - if get_option('bpf').enabled() - error('libbpf skeleton test failed')meson.build if not get_option('fuse_lseek').disabled() · line 1043
Quoted 10 lines
meson.build +8
-2- else - warning('libbpf skeleton test failed, disabling') +libbpf = not_found +if targetos == 'linux' + libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') + if libbpf.found() and not cc.links(''' + #include <bpf/libbpf.h> + int main(void) + { + bpf_object__destroy_skeleton(NULL);Do we need to test whether the bpf can do
mmap()here?Thanks
Quoted 26 lines
meson.build +16
-0+ return 0; + }''', dependencies: libbpf) + libbpf = not_found + if get_option('bpf').enabled() + error('libbpf skeleton test failed') + else + warning('libbpf skeleton test failed, disabling') + endif endif endif@@ -2423,6 +2426,14 @@ if have_tools dependencies: [authz, crypto, io, qom, qemuutil, libcap_ng, mpathpersist], install: true) + + if libbpf.found() + executable('qemu-ebpf-rss-helper', files( + 'ebpf/qemu-ebpf-rss-helper.c', 'ebpf/ebpf_rss.c'), + dependencies: [qemuutil, libbpf, glib], + install: true, + install_dir: get_option('libexecdir')) + endif endif if 'CONFIG_IVSHMEM' in config_host
Re: [PATCH 4/5] ebpf_rss_helper: Added helper for eBPF RSS.
In reply to Jason WangQuoted 27 lines · Jason Wang
Quoted 12 lines · Yuri Benditovich
Quoted 11 lines · Jason Wang
Quoted 2 lines · Andrew Melnychenko
Helper program. Loads eBPF RSS program and maps and passes them through unix socket. Libvirt may launch this helper and pass eBPF fds to qemu virtio-net.
I wonder if this can be done as helper for TAP/bridge.
E.g it's the qemu to launch those helper with set-uid.
Then libvirt won't even need to care about that?
Quoted 10 lines
There are pros and cons for such a solution with set-uid.
From my point of view one of the cons is that set-uid is efficient
only at install time so the coexistence of different qemu builds (and different helpers for each one) is kind of problematic. With the current solution this does not present any problem: the developer can have several different builds, each one automatically has its own helper and there is no conflict between these builds and between these builds and installed qemu package. Changing the 'emulator' in the libvirt profile automatically brings the proper helper to work.
Quoted 4 lines
I'm not sure I get you here. We can still have default/sample helper to make sure it works for different builds.
If we can avoid the involvement of libvirt, that would be better.
Hi Jason,
Indeed I did not get the idea, can you please explain it in more details (as detailed as possible to avoid future misunderstanding), especially how exactly we can use the set-uid and what is the 'default' helper. We also would prefer to do everything from qemu but we do not see how we can do that.
Our main points (what should be addressed):
- qemu should be able to load ebpf and use the maps when it runs from libvirt (without special caps) and standalone (with caps)
- it is possible that there are different qemu builds on the machine, one of them might be installed, their ebpf's might be different and the interface between qemu and ebpf (exact content of maps and number of maps)
- qemu configures the RSS dynamically according to the commands provided by the guest
Thanks in advance
Yuri
Quoted 215 lines
Thanks
Quoted 210 lines
Quoted 210 lines
Quoted 168 lines
Also, libbpf dependency now exclusively for Linux.
Libbpf is used for eBPF RSS steering, which is supported only by Linux TAP. There is no reason yet to build eBPF loader and helper for non Linux systems, even if libbpf is present.Signed-off-by Andrew Melnychenko <[email protected]>--- ebpf/qemu-ebpf-rss-helper.c | 130 ++++++++++++++++++++++++++++++++++++ meson.build | 37 ++++++---- 2 files changed, 154 insertions(+), 13 deletions(-)create mode 100644
ebpf/qemu-ebpf-rss-helper.cebpf/qemu-ebpf-rss-helper.c new file +130
-0@@ -0,0 +1,130 @@ +/* +* eBPF RSS Helper +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +* Description: This is helper program for libvirtd. +* It loads eBPF RSS program and passes fds through unix socket. +* Built by meson, target - 'qemu-ebpf-rss-helper'. +*/ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> +#include <getopt.h> +#include <memory.h> +#include <errno.h> +#include <sys/socket.h> + +#include "ebpf_rss.h" + +#include "qemu-helper-stamp.h" + +void QEMU_HELPER_STAMP (void ) {} + +static int send_fds (int socket,int *fds,int n) +{ +struct msghdr msg = {}; +struct cmsghdr *cmsg =NULL ; +char buf[CMSG_SPACE (n *sizeof (int ))]; +char dummy_buffer =0 ; +struct iovec io = { .iov_base = &dummy_buffer, + .iov_len =sizeof (dummy_buffer) }; + +memset (buf,0 ,sizeof (buf)); + + msg.msg_iov = &io; + msg.msg_iovlen =1 ; + msg.msg_control = buf; + msg.msg_controllen =sizeof (buf); + + cmsg =CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level =SOL_SOCKET ; + cmsg->cmsg_type =SCM_RIGHTS ; + cmsg->cmsg_len =CMSG_LEN (n *sizeof (int )); + +memcpy (CMSG_DATA (cmsg), fds, n *sizeof (int )); + +return sendmsg (socket, &msg,0 ); +} + +static void print_help_and_exit (const char *prog,int exitcode) +{ +fprintf (stderr,"%s - load eBPF RSS program for qemu and pass eBPF fds" +" through unix socket.\n" , prog); +fprintf (stderr,"\t--fd <num>, -f <num> - unix socket file descriptor" +" used to pass eBPF fds.\n" ); +fprintf (stderr,"\t--help, -h - this help.\n" ); +exit (exitcode); +} + +int main (int argc,char **argv) +{ +char *fd_string =NULL ; +int unix_fd =0 ; +struct EBPFRSSContext ctx = {}; +int fds[EBPF_RSS_MAX_FDS ] = {}; +int ret =-1 ; + +for (;;) { +int c; +static struct option long_options[] = { + {"help" , no_argument,0 ,'h' }, + {"fd" , required_argument,0 ,'f' }, + {0 ,0 ,0 ,0 } + }; + c =getopt_long (argc, argv,"hf:" , + long_options,NULL ); + +if (c ==-1 ) { +break ; + } + +switch (c) { +case 'f' : + fd_string = optarg; +break ; +case 'h' : +default : +print_help_and_exit (argv[0 ], + c =='h' ?EXIT_SUCCESS :EXIT_FAILURE ); + } + } + +if (!fd_string) { +fprintf (stderr,"Unix file descriptor not present.\n" ); +print_help_and_exit (argv[0 ],EXIT_FAILURE ); + } + + unix_fd =atoi (fd_string); + +if (!unix_fd) { +fprintf (stderr,"Unix file descriptor is invalid.\n" ); +return EXIT_FAILURE ; + } + +ebpf_rss_init (&ctx); +if (!ebpf_rss_load (&ctx)) { +fprintf (stderr,"Can't load ebpf.\n" ); +return EXIT_FAILURE ; + } + fds[0 ] = ctx.program_fd; + fds[1 ] = ctx.map_configuration; + + ret =send_fds (unix_fd, fds,EBPF_RSS_MAX_FDS ); +if (ret <0 ) { +fprintf (stderr,"Issue while sending fds: %s.\n" ,strerror (errno)); + } + +ebpf_rss_unload (&ctx); + +return ret <0 ?EXIT_FAILURE :EXIT_SUCCESS ; +} +meson.build +0
-11@@ -1033,19 +1033,22 @@ if not get_option('fuse_lseek').disabled() endif # libbpf -libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') -if libbpf.found() and not cc.links(''' - #include <bpf/libbpf.h> - int main(void) - { - bpf_object__destroy_skeleton(NULL); - return 0; - }''', dependencies: libbpf) - libbpf = not_found - if get_option('bpf').enabled() - error('libbpf skeleton test failed')meson.build if not get_option('fuse_lseek').disabled() · line 1043
Quoted 10 lines
meson.build +8
-2- else - warning('libbpf skeleton test failed, disabling') +libbpf = not_found +if targetos == 'linux' + libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') + if libbpf.found() and not cc.links(''' + #include <bpf/libbpf.h> + int main(void) + { + bpf_object__destroy_skeleton(NULL);Do we need to test whether the bpf can do
mmap()here?Thanks
Quoted 26 lines
meson.build +16
-0+ return 0; + }''', dependencies: libbpf) + libbpf = not_found + if get_option('bpf').enabled() + error('libbpf skeleton test failed') + else + warning('libbpf skeleton test failed, disabling') + endif endif endif@@ -2423,6 +2426,14 @@ if have_tools dependencies: [authz, crypto, io, qom, qemuutil, libcap_ng, mpathpersist], install: true) + + if libbpf.found() + executable('qemu-ebpf-rss-helper', files( + 'ebpf/qemu-ebpf-rss-helper.c', 'ebpf/ebpf_rss.c'), + dependencies: [qemuutil, libbpf, glib], + install: true, + install_dir: get_option('libexecdir')) + endif endif if 'CONFIG_IVSHMEM' in config_host
Re: [PATCH 4/5] ebpf_rss_helper: Added helper for eBPF RSS.
Quoted 34 lines · Yuri Benditovich
Quoted 27 lines · Jason Wang
Quoted 12 lines · Yuri Benditovich
Quoted 11 lines · Jason Wang
Quoted 2 lines · Andrew Melnychenko
Helper program. Loads eBPF RSS program and maps and passes them through unix socket. Libvirt may launch this helper and pass eBPF fds to qemu virtio-net.
I wonder if this can be done as helper for TAP/bridge.
E.g it's the qemu to launch those helper with set-uid.
Then libvirt won't even need to care about that?
Quoted 10 lines
There are pros and cons for such a solution with set-uid.
From my point of view one of the cons is that set-uid is efficient
only at install time so the coexistence of different qemu builds (and different helpers for each one) is kind of problematic. With the current solution this does not present any problem: the developer can have several different builds, each one automatically has its own helper and there is no conflict between these builds and between these builds and installed qemu package. Changing the 'emulator' in the libvirt profile automatically brings the proper helper to work.Quoted 4 lines
I'm not sure I get you here. We can still have default/sample helper to make sure it works for different builds.
If we can avoid the involvement of libvirt, that would be better.
Quoted 7 lines
Hi Jason,
Indeed I did not get the idea, can you please explain it in more details (as detailed as possible to avoid future misunderstanding), especially how exactly we can use the set-uid and what is the 'default' helper. We also would prefer to do everything from qemu but we do not see how we can do that.
Something like:
1) -netdev tap,rss_helper=/path/to/name
2) having a sample/default helper implemented in Qemu
3) we can introduce something special path like "default", then if -netdev tap,rss_helper="default" is specified, qemu will use the sample helper
So we have:
1) set set-uid for the helper
2) libvirt may just choose to launch the default helper
Quoted 4 lines
Our main points (what should be addressed):
- qemu should be able to load ebpf and use the maps when it runs from libvirt (without special caps) and standalone (with caps)
This is solved by leaving the privileged operations to the helper with set-uid.
Quoted 4 lines
- it is possible that there are different qemu builds on the machine, one of them might be installed, their ebpf's might be different and the interface between qemu and ebpf (exact content of maps and number of maps)
We can use different helpers in this way.
Quoted 2 lines
- qemu configures the RSS dynamically according to the commands provided by the guest
Consider we decided to use mmap() based maps, this is not an issue.
Or am I missing something?
Thanks
Quoted 220 lines
Thanks in advance
YuriQuoted 215 lines
Thanks
Quoted 210 lines
Quoted 210 lines
Quoted 168 lines
Also, libbpf dependency now exclusively for Linux.
Libbpf is used for eBPF RSS steering, which is supported only by Linux TAP. There is no reason yet to build eBPF loader and helper for non Linux systems, even if libbpf is present.Signed-off-by Andrew Melnychenko <[email protected]>--- ebpf/qemu-ebpf-rss-helper.c | 130 ++++++++++++++++++++++++++++++++++++ meson.build | 37 ++++++---- 2 files changed, 154 insertions(+), 13 deletions(-)create mode 100644
ebpf/qemu-ebpf-rss-helper.cebpf/qemu-ebpf-rss-helper.c new file +130
-0@@ -0,0 +1,130 @@ +/* +* eBPF RSS Helper +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +* Description: This is helper program for libvirtd. +* It loads eBPF RSS program and passes fds through unix socket. +* Built by meson, target - 'qemu-ebpf-rss-helper'. +*/ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> +#include <getopt.h> +#include <memory.h> +#include <errno.h> +#include <sys/socket.h> + +#include "ebpf_rss.h" + +#include "qemu-helper-stamp.h" + +void QEMU_HELPER_STAMP (void ) {} + +static int send_fds (int socket,int *fds,int n) +{ +struct msghdr msg = {}; +struct cmsghdr *cmsg =NULL ; +char buf[CMSG_SPACE (n *sizeof (int ))]; +char dummy_buffer =0 ; +struct iovec io = { .iov_base = &dummy_buffer, + .iov_len =sizeof (dummy_buffer) }; + +memset (buf,0 ,sizeof (buf)); + + msg.msg_iov = &io; + msg.msg_iovlen =1 ; + msg.msg_control = buf; + msg.msg_controllen =sizeof (buf); + + cmsg =CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level =SOL_SOCKET ; + cmsg->cmsg_type =SCM_RIGHTS ; + cmsg->cmsg_len =CMSG_LEN (n *sizeof (int )); + +memcpy (CMSG_DATA (cmsg), fds, n *sizeof (int )); + +return sendmsg (socket, &msg,0 ); +} + +static void print_help_and_exit (const char *prog,int exitcode) +{ +fprintf (stderr,"%s - load eBPF RSS program for qemu and pass eBPF fds" +" through unix socket.\n" , prog); +fprintf (stderr,"\t--fd <num>, -f <num> - unix socket file descriptor" +" used to pass eBPF fds.\n" ); +fprintf (stderr,"\t--help, -h - this help.\n" ); +exit (exitcode); +} + +int main (int argc,char **argv) +{ +char *fd_string =NULL ; +int unix_fd =0 ; +struct EBPFRSSContext ctx = {}; +int fds[EBPF_RSS_MAX_FDS ] = {}; +int ret =-1 ; + +for (;;) { +int c; +static struct option long_options[] = { + {"help" , no_argument,0 ,'h' }, + {"fd" , required_argument,0 ,'f' }, + {0 ,0 ,0 ,0 } + }; + c =getopt_long (argc, argv,"hf:" , + long_options,NULL ); + +if (c ==-1 ) { +break ; + } + +switch (c) { +case 'f' : + fd_string = optarg; +break ; +case 'h' : +default : +print_help_and_exit (argv[0 ], + c =='h' ?EXIT_SUCCESS :EXIT_FAILURE ); + } + } + +if (!fd_string) { +fprintf (stderr,"Unix file descriptor not present.\n" ); +print_help_and_exit (argv[0 ],EXIT_FAILURE ); + } + + unix_fd =atoi (fd_string); + +if (!unix_fd) { +fprintf (stderr,"Unix file descriptor is invalid.\n" ); +return EXIT_FAILURE ; + } + +ebpf_rss_init (&ctx); +if (!ebpf_rss_load (&ctx)) { +fprintf (stderr,"Can't load ebpf.\n" ); +return EXIT_FAILURE ; + } + fds[0 ] = ctx.program_fd; + fds[1 ] = ctx.map_configuration; + + ret =send_fds (unix_fd, fds,EBPF_RSS_MAX_FDS ); +if (ret <0 ) { +fprintf (stderr,"Issue while sending fds: %s.\n" ,strerror (errno)); + } + +ebpf_rss_unload (&ctx); + +return ret <0 ?EXIT_FAILURE :EXIT_SUCCESS ; +} +meson.build +0
-11@@ -1033,19 +1033,22 @@ if not get_option('fuse_lseek').disabled() endif # libbpf -libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') -if libbpf.found() and not cc.links(''' - #include <bpf/libbpf.h> - int main(void) - { - bpf_object__destroy_skeleton(NULL); - return 0; - }''', dependencies: libbpf) - libbpf = not_found - if get_option('bpf').enabled() - error('libbpf skeleton test failed')meson.build if not get_option('fuse_lseek').disabled() · line 1043
Quoted 10 lines
meson.build +8
-2- else - warning('libbpf skeleton test failed, disabling') +libbpf = not_found +if targetos == 'linux' + libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') + if libbpf.found() and not cc.links(''' + #include <bpf/libbpf.h> + int main(void) + { + bpf_object__destroy_skeleton(NULL);Do we need to test whether the bpf can do
mmap()here?Thanks
Quoted 26 lines
meson.build +16
-0+ return 0; + }''', dependencies: libbpf) + libbpf = not_found + if get_option('bpf').enabled() + error('libbpf skeleton test failed') + else + warning('libbpf skeleton test failed, disabling') + endif endif endif@@ -2423,6 +2426,14 @@ if have_tools dependencies: [authz, crypto, io, qom, qemuutil, libcap_ng, mpathpersist], install: true) + + if libbpf.found() + executable('qemu-ebpf-rss-helper', files( + 'ebpf/qemu-ebpf-rss-helper.c', 'ebpf/ebpf_rss.c'), + dependencies: [qemuutil, libbpf, glib], + install: true, + install_dir: get_option('libexecdir')) + endif endif if 'CONFIG_IVSHMEM' in config_host
Re: [PATCH 4/5] ebpf_rss_helper: Added helper for eBPF RSS.
Quoted 37 lines · Jason Wang
Quoted 34 lines · Yuri Benditovich
Quoted 31 lines · Jason Wang
Quoted 12 lines · Yuri Benditovich
Quoted 11 lines · Jason Wang
Quoted 2 lines · Andrew Melnychenko
Helper program. Loads eBPF RSS program and maps and passes them through unix socket. Libvirt may launch this helper and pass eBPF fds to qemu virtio-net.
I wonder if this can be done as helper for TAP/bridge.
E.g it's the qemu to launch those helper with set-uid.
Then libvirt won't even need to care about that?
Quoted 10 lines
There are pros and cons for such a solution with set-uid.
From my point of view one of the cons is that set-uid is efficient
only at install time so the coexistence of different qemu builds (and different helpers for each one) is kind of problematic. With the current solution this does not present any problem: the developer can have several different builds, each one automatically has its own helper and there is no conflict between these builds and between these builds and installed qemu package. Changing the 'emulator' in the libvirt profile automatically brings the proper helper to work.I'm not sure I get you here. We can still have default/sample helper to make sure it works for different builds.
If we can avoid the involvement of libvirt, that would be better.
Quoted 9 lines
Quoted 7 lines
Hi Jason,
Indeed I did not get the idea, can you please explain it in more details (as detailed as possible to avoid future misunderstanding), especially how exactly we can use the set-uid and what is the 'default' helper. We also would prefer to do everything from qemu but we do not see how we can do that.
Some more questions to understand the idea better:
Quoted 3 lines
Something like:
1) -netdev tap,rss_helper=/path/to/name
So, on each editing of 'emulator' in the xml the helper path should be set manually or be default?
Quoted 1 line
2) having a sample/default helper implemented in Qemu
Does it mean the default helper is the code in the qemu (without running additional executable, like it does today) or this is qemu itself with dedicated command line?
As far as I remember Daniel had strong objections of ever running qemu with capabilities
Quoted 3 lines
3) we can introduce something special path like "default", then if -netdev tap,rss_helper="default" is specified, qemu will use the sample helper
Probably this is not so important but the rss helper and rss in general has no relation to netdev, much more they are related to virtio-net
Quoted 3 lines
So we have:
1) set set-uid for the helper
Who and when does set-uid to the helper binary? Only installer or libvirt can do that, correct?
Quoted 1 line
2) libvirt may just choose to launch the default helper
All this discussion is to avoid launching the helper from libvirt, correct?
Quoted 245 lines
Quoted 5 lines
Our main points (what should be addressed):
- qemu should be able to load ebpf and use the maps when it runs from libvirt (without special caps) and standalone (with caps)This is solved by leaving the privileged operations to the helper with set-uid.
Quoted 4 lines
- it is possible that there are different qemu builds on the machine, one of them might be installed, their ebpf's might be different and the interface between qemu and ebpf (exact content of maps and number of maps)
We can use different helpers in this way.
Quoted 2 lines
- qemu configures the RSS dynamically according to the commands provided by the guest
Consider we decided to use
mmap()based maps, this is not an issue.Or am I missing something?
Thanks
Quoted 220 lines
Thanks in advance
YuriQuoted 215 lines
Thanks
Quoted 210 lines
Quoted 210 lines
Quoted 168 lines
Also, libbpf dependency now exclusively for Linux.
Libbpf is used for eBPF RSS steering, which is supported only by Linux TAP. There is no reason yet to build eBPF loader and helper for non Linux systems, even if libbpf is present.Signed-off-by Andrew Melnychenko <[email protected]>--- ebpf/qemu-ebpf-rss-helper.c | 130 ++++++++++++++++++++++++++++++++++++ meson.build | 37 ++++++---- 2 files changed, 154 insertions(+), 13 deletions(-)create mode 100644
ebpf/qemu-ebpf-rss-helper.cebpf/qemu-ebpf-rss-helper.c new file +130
-0@@ -0,0 +1,130 @@ +/* +* eBPF RSS Helper +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +* Description: This is helper program for libvirtd. +* It loads eBPF RSS program and passes fds through unix socket. +* Built by meson, target - 'qemu-ebpf-rss-helper'. +*/ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> +#include <getopt.h> +#include <memory.h> +#include <errno.h> +#include <sys/socket.h> + +#include "ebpf_rss.h" + +#include "qemu-helper-stamp.h" + +void QEMU_HELPER_STAMP (void ) {} + +static int send_fds (int socket,int *fds,int n) +{ +struct msghdr msg = {}; +struct cmsghdr *cmsg =NULL ; +char buf[CMSG_SPACE (n *sizeof (int ))]; +char dummy_buffer =0 ; +struct iovec io = { .iov_base = &dummy_buffer, + .iov_len =sizeof (dummy_buffer) }; + +memset (buf,0 ,sizeof (buf)); + + msg.msg_iov = &io; + msg.msg_iovlen =1 ; + msg.msg_control = buf; + msg.msg_controllen =sizeof (buf); + + cmsg =CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level =SOL_SOCKET ; + cmsg->cmsg_type =SCM_RIGHTS ; + cmsg->cmsg_len =CMSG_LEN (n *sizeof (int )); + +memcpy (CMSG_DATA (cmsg), fds, n *sizeof (int )); + +return sendmsg (socket, &msg,0 ); +} + +static void print_help_and_exit (const char *prog,int exitcode) +{ +fprintf (stderr,"%s - load eBPF RSS program for qemu and pass eBPF fds" +" through unix socket.\n" , prog); +fprintf (stderr,"\t--fd <num>, -f <num> - unix socket file descriptor" +" used to pass eBPF fds.\n" ); +fprintf (stderr,"\t--help, -h - this help.\n" ); +exit (exitcode); +} + +int main (int argc,char **argv) +{ +char *fd_string =NULL ; +int unix_fd =0 ; +struct EBPFRSSContext ctx = {}; +int fds[EBPF_RSS_MAX_FDS ] = {}; +int ret =-1 ; + +for (;;) { +int c; +static struct option long_options[] = { + {"help" , no_argument,0 ,'h' }, + {"fd" , required_argument,0 ,'f' }, + {0 ,0 ,0 ,0 } + }; + c =getopt_long (argc, argv,"hf:" , + long_options,NULL ); + +if (c ==-1 ) { +break ; + } + +switch (c) { +case 'f' : + fd_string = optarg; +break ; +case 'h' : +default : +print_help_and_exit (argv[0 ], + c =='h' ?EXIT_SUCCESS :EXIT_FAILURE ); + } + } + +if (!fd_string) { +fprintf (stderr,"Unix file descriptor not present.\n" ); +print_help_and_exit (argv[0 ],EXIT_FAILURE ); + } + + unix_fd =atoi (fd_string); + +if (!unix_fd) { +fprintf (stderr,"Unix file descriptor is invalid.\n" ); +return EXIT_FAILURE ; + } + +ebpf_rss_init (&ctx); +if (!ebpf_rss_load (&ctx)) { +fprintf (stderr,"Can't load ebpf.\n" ); +return EXIT_FAILURE ; + } + fds[0 ] = ctx.program_fd; + fds[1 ] = ctx.map_configuration; + + ret =send_fds (unix_fd, fds,EBPF_RSS_MAX_FDS ); +if (ret <0 ) { +fprintf (stderr,"Issue while sending fds: %s.\n" ,strerror (errno)); + } + +ebpf_rss_unload (&ctx); + +return ret <0 ?EXIT_FAILURE :EXIT_SUCCESS ; +} +meson.build +0
-11@@ -1033,19 +1033,22 @@ if not get_option('fuse_lseek').disabled() endif # libbpf -libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') -if libbpf.found() and not cc.links(''' - #include <bpf/libbpf.h> - int main(void) - { - bpf_object__destroy_skeleton(NULL); - return 0; - }''', dependencies: libbpf) - libbpf = not_found - if get_option('bpf').enabled() - error('libbpf skeleton test failed')meson.build if not get_option('fuse_lseek').disabled() · line 1043
Quoted 10 lines
meson.build +8
-2- else - warning('libbpf skeleton test failed, disabling') +libbpf = not_found +if targetos == 'linux' + libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') + if libbpf.found() and not cc.links(''' + #include <bpf/libbpf.h> + int main(void) + { + bpf_object__destroy_skeleton(NULL);Do we need to test whether the bpf can do
mmap()here?Thanks
Quoted 26 lines
meson.build +16
-0+ return 0; + }''', dependencies: libbpf) + libbpf = not_found + if get_option('bpf').enabled() + error('libbpf skeleton test failed') + else + warning('libbpf skeleton test failed, disabling') + endif endif endif@@ -2423,6 +2426,14 @@ if have_tools dependencies: [authz, crypto, io, qom, qemuutil, libcap_ng, mpathpersist], install: true) + + if libbpf.found() + executable('qemu-ebpf-rss-helper', files( + 'ebpf/qemu-ebpf-rss-helper.c', 'ebpf/ebpf_rss.c'), + dependencies: [qemuutil, libbpf, glib], + install: true, + install_dir: get_option('libexecdir')) + endif endif if 'CONFIG_IVSHMEM' in config_host
Re: [PATCH 4/5] ebpf_rss_helper: Added helper for eBPF RSS.
Quoted 48 lines · Yuri Benditovich
Quoted 37 lines · Jason Wang
Quoted 34 lines · Yuri Benditovich
Quoted 31 lines · Jason Wang
Quoted 12 lines · Yuri Benditovich
Quoted 11 lines · Jason Wang
Quoted 2 lines · Andrew Melnychenko
Helper program. Loads eBPF RSS program and maps and passes them through unix socket. Libvirt may launch this helper and pass eBPF fds to qemu virtio-net.
I wonder if this can be done as helper for TAP/bridge.
E.g it's the qemu to launch those helper with set-uid.
Then libvirt won't even need to care about that?
Quoted 10 lines
There are pros and cons for such a solution with set-uid.
From my point of view one of the cons is that set-uid is efficient
only at install time so the coexistence of different qemu builds (and different helpers for each one) is kind of problematic. With the current solution this does not present any problem: the developer can have several different builds, each one automatically has its own helper and there is no conflict between these builds and between these builds and installed qemu package. Changing the 'emulator' in the libvirt profile automatically brings the proper helper to work.I'm not sure I get you here. We can still have default/sample helper to make sure it works for different builds.
If we can avoid the involvement of libvirt, that would be better.
Quoted 9 lines
Quoted 7 lines
Hi Jason,
Indeed I did not get the idea, can you please explain it in more details (as detailed as possible to avoid future misunderstanding), especially how exactly we can use the set-uid and what is the 'default' helper. We also would prefer to do everything from qemu but we do not see how we can do that.
Quoted 7 lines
Some more questions to understand the idea better:
Quoted 3 lines
Something like:
1) -netdev tap,rss_helper=/path/to/name
So, on each editing of 'emulator' in the xml the helper path should be set manually or be default?
It could done manually, or we can have a default path.
Quoted 5 lines
Quoted 2 lines
2) having a sample/default helper implemented in Qemu
Does it mean the default helper is the code in the qemu (without running additional executable, like it does today)
Yes.
or this is qemu
Quoted 3 lines
itself with dedicated command line?
As far as I remember Daniel had strong objections of ever running qemu with capabilities
Qemu won't run with capabilities but the helper.
Quoted 8 lines
Quoted 4 lines
3) we can introduce something special path like "default", then if -netdev tap,rss_helper="default" is specified, qemu will use the sample helper
Probably this is not so important but the rss helper and rss in general has no relation to netdev, much more they are related to virtio-net
So I think the reason for this is that we currently only support eBPF/RSS for tap.
Quoted 6 lines
Quoted 4 lines
So we have:
1) set set-uid for the helperWho and when does set-uid to the helper binary? Only installer or libvirt can do that, correct?
Yes, it could be done the installer, or other system provision tools.
Quoted 3 lines
Quoted 2 lines
2) libvirt may just choose to launch the default helper
All this discussion is to avoid launching the helper from libvirt, correct?
Sorry, it's a typo. I meant, libvirt launch qemu, and then qemu will launch the helper.
Thanks
Quoted 247 lines
Quoted 246 lines
Quoted 6 lines
Our main points (what should be addressed):
- qemu should be able to load ebpf and use the maps when it runs from libvirt (without special caps) and standalone (with caps)This is solved by leaving the privileged operations to the helper with set-uid.
Quoted 4 lines
- it is possible that there are different qemu builds on the machine, one of them might be installed, their ebpf's might be different and the interface between qemu and ebpf (exact content of maps and number of maps)
We can use different helpers in this way.
Quoted 2 lines
- qemu configures the RSS dynamically according to the commands provided by the guest
Consider we decided to use
mmap()based maps, this is not an issue.Or am I missing something?
Thanks
Quoted 220 lines
Thanks in advance
YuriQuoted 215 lines
Thanks
Quoted 210 lines
Quoted 210 lines
Quoted 168 lines
Also, libbpf dependency now exclusively for Linux.
Libbpf is used for eBPF RSS steering, which is supported only by Linux TAP. There is no reason yet to build eBPF loader and helper for non Linux systems, even if libbpf is present.Signed-off-by Andrew Melnychenko <[email protected]>--- ebpf/qemu-ebpf-rss-helper.c | 130 ++++++++++++++++++++++++++++++++++++ meson.build | 37 ++++++---- 2 files changed, 154 insertions(+), 13 deletions(-)create mode 100644
ebpf/qemu-ebpf-rss-helper.cebpf/qemu-ebpf-rss-helper.c new file +130
-0@@ -0,0 +1,130 @@ +/* +* eBPF RSS Helper +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +* Description: This is helper program for libvirtd. +* It loads eBPF RSS program and passes fds through unix socket. +* Built by meson, target - 'qemu-ebpf-rss-helper'. +*/ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> +#include <getopt.h> +#include <memory.h> +#include <errno.h> +#include <sys/socket.h> + +#include "ebpf_rss.h" + +#include "qemu-helper-stamp.h" + +void QEMU_HELPER_STAMP (void ) {} + +static int send_fds (int socket,int *fds,int n) +{ +struct msghdr msg = {}; +struct cmsghdr *cmsg =NULL ; +char buf[CMSG_SPACE (n *sizeof (int ))]; +char dummy_buffer =0 ; +struct iovec io = { .iov_base = &dummy_buffer, + .iov_len =sizeof (dummy_buffer) }; + +memset (buf,0 ,sizeof (buf)); + + msg.msg_iov = &io; + msg.msg_iovlen =1 ; + msg.msg_control = buf; + msg.msg_controllen =sizeof (buf); + + cmsg =CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level =SOL_SOCKET ; + cmsg->cmsg_type =SCM_RIGHTS ; + cmsg->cmsg_len =CMSG_LEN (n *sizeof (int )); + +memcpy (CMSG_DATA (cmsg), fds, n *sizeof (int )); + +return sendmsg (socket, &msg,0 ); +} + +static void print_help_and_exit (const char *prog,int exitcode) +{ +fprintf (stderr,"%s - load eBPF RSS program for qemu and pass eBPF fds" +" through unix socket.\n" , prog); +fprintf (stderr,"\t--fd <num>, -f <num> - unix socket file descriptor" +" used to pass eBPF fds.\n" ); +fprintf (stderr,"\t--help, -h - this help.\n" ); +exit (exitcode); +} + +int main (int argc,char **argv) +{ +char *fd_string =NULL ; +int unix_fd =0 ; +struct EBPFRSSContext ctx = {}; +int fds[EBPF_RSS_MAX_FDS ] = {}; +int ret =-1 ; + +for (;;) { +int c; +static struct option long_options[] = { + {"help" , no_argument,0 ,'h' }, + {"fd" , required_argument,0 ,'f' }, + {0 ,0 ,0 ,0 } + }; + c =getopt_long (argc, argv,"hf:" , + long_options,NULL ); + +if (c ==-1 ) { +break ; + } + +switch (c) { +case 'f' : + fd_string = optarg; +break ; +case 'h' : +default : +print_help_and_exit (argv[0 ], + c =='h' ?EXIT_SUCCESS :EXIT_FAILURE ); + } + } + +if (!fd_string) { +fprintf (stderr,"Unix file descriptor not present.\n" ); +print_help_and_exit (argv[0 ],EXIT_FAILURE ); + } + + unix_fd =atoi (fd_string); + +if (!unix_fd) { +fprintf (stderr,"Unix file descriptor is invalid.\n" ); +return EXIT_FAILURE ; + } + +ebpf_rss_init (&ctx); +if (!ebpf_rss_load (&ctx)) { +fprintf (stderr,"Can't load ebpf.\n" ); +return EXIT_FAILURE ; + } + fds[0 ] = ctx.program_fd; + fds[1 ] = ctx.map_configuration; + + ret =send_fds (unix_fd, fds,EBPF_RSS_MAX_FDS ); +if (ret <0 ) { +fprintf (stderr,"Issue while sending fds: %s.\n" ,strerror (errno)); + } + +ebpf_rss_unload (&ctx); + +return ret <0 ?EXIT_FAILURE :EXIT_SUCCESS ; +} +meson.build +0
-11@@ -1033,19 +1033,22 @@ if not get_option('fuse_lseek').disabled() endif # libbpf -libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') -if libbpf.found() and not cc.links(''' - #include <bpf/libbpf.h> - int main(void) - { - bpf_object__destroy_skeleton(NULL); - return 0; - }''', dependencies: libbpf) - libbpf = not_found - if get_option('bpf').enabled() - error('libbpf skeleton test failed')meson.build if not get_option('fuse_lseek').disabled() · line 1043
Quoted 10 lines
meson.build +8
-2- else - warning('libbpf skeleton test failed, disabling') +libbpf = not_found +if targetos == 'linux' + libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') + if libbpf.found() and not cc.links(''' + #include <bpf/libbpf.h> + int main(void) + { + bpf_object__destroy_skeleton(NULL);Do we need to test whether the bpf can do
mmap()here?Thanks
Quoted 26 lines
meson.build +16
-0+ return 0; + }''', dependencies: libbpf) + libbpf = not_found + if get_option('bpf').enabled() + error('libbpf skeleton test failed') + else + warning('libbpf skeleton test failed, disabling') + endif endif endif@@ -2423,6 +2426,14 @@ if have_tools dependencies: [authz, crypto, io, qom, qemuutil, libcap_ng, mpathpersist], install: true) + + if libbpf.found() + executable('qemu-ebpf-rss-helper', files( + 'ebpf/qemu-ebpf-rss-helper.c', 'ebpf/ebpf_rss.c'), + dependencies: [qemuutil, libbpf, glib], + install: true, + install_dir: get_option('libexecdir')) + endif endif if 'CONFIG_IVSHMEM' in config_host
Re: [PATCH 4/5] ebpf_rss_helper: Added helper for eBPF RSS.
Quoted 62 lines · Jason Wang
Quoted 48 lines · Yuri Benditovich
Quoted 37 lines · Jason Wang
Quoted 34 lines · Yuri Benditovich
Quoted 31 lines · Jason Wang
Quoted 12 lines · Yuri Benditovich
Quoted 11 lines · Jason Wang
Quoted 2 lines · Andrew Melnychenko
Helper program. Loads eBPF RSS program and maps and passes them through unix socket. Libvirt may launch this helper and pass eBPF fds to qemu virtio-net.
I wonder if this can be done as helper for TAP/bridge.
E.g it's the qemu to launch those helper with set-uid.
Then libvirt won't even need to care about that?
Quoted 10 lines
There are pros and cons for such a solution with set-uid.
From my point of view one of the cons is that set-uid is efficient
only at install time so the coexistence of different qemu builds (and different helpers for each one) is kind of problematic. With the current solution this does not present any problem: the developer can have several different builds, each one automatically has its own helper and there is no conflict between these builds and between these builds and installed qemu package. Changing the 'emulator' in the libvirt profile automatically brings the proper helper to work.I'm not sure I get you here. We can still have default/sample helper to make sure it works for different builds.
If we can avoid the involvement of libvirt, that would be better.
Quoted 9 lines
Quoted 7 lines
Hi Jason,
Indeed I did not get the idea, can you please explain it in more details (as detailed as possible to avoid future misunderstanding), especially how exactly we can use the set-uid and what is the 'default' helper. We also would prefer to do everything from qemu but we do not see how we can do that.
Quoted 7 lines
Some more questions to understand the idea better:
Quoted 3 lines
Something like:
1) -netdev tap,rss_helper=/path/to/name
So, on each editing of 'emulator' in the xml the helper path should be set manually or be default?
It could done manually, or we can have a default path.
Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
2) having a sample/default helper implemented in Qemu
Does it mean the default helper is the code in the qemu (without running additional executable, like it does today)
Yes.
If the "default helper" is just a keyword and it is like what we have today (i.e. part of qemu) it can't work under libvirt and should never be used by libvirt.
Quoted 7 lines
or this is qemu
Quoted 3 lines
itself with dedicated command line?
As far as I remember Daniel had strong objections of ever running qemu with capabilitiesQemu won't run with capabilities but the helper.
So under libvirt the helper is always separate executable and not "default helper"
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
3) we can introduce something special path like "default", then if -netdev tap,rss_helper="default" is specified, qemu will use the sample helper
Quoted 6 lines
Quoted 3 lines
Probably this is not so important but the rss helper and rss in general has no relation to netdev, much more they are related to virtio-net
So I think the reason for this is that we currently only support eBPF/RSS for tap.
This is just because only tap supports respective ioctls.
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
So we have:
1) set set-uid for the helperWho and when does set-uid to the helper binary? Only installer or libvirt can do that, correct?
Yes, it could be done the installer, or other system provision tools.
So this changes the rule of the game: currently libvirt runs helpers that require privileges and qemu runs helpers that do not require any privileges (like TPM).
If we follow your suggestion - only for RSS we will create the helper that must be used with set-uid.
Who are stakeholders we need to have a consensus with?
Quoted 258 lines
Quoted 4 lines
Quoted 3 lines
2) libvirt may just choose to launch the default helper
All this discussion is to avoid launching the helper from libvirt, correct?
Sorry, it's a typo. I meant, libvirt launch qemu, and then qemu will launch the helper.
Thanks
Quoted 247 lines
Quoted 246 lines
Quoted 6 lines
Our main points (what should be addressed):
- qemu should be able to load ebpf and use the maps when it runs from libvirt (without special caps) and standalone (with caps)This is solved by leaving the privileged operations to the helper with set-uid.
Quoted 4 lines
- it is possible that there are different qemu builds on the machine, one of them might be installed, their ebpf's might be different and the interface between qemu and ebpf (exact content of maps and number of maps)
We can use different helpers in this way.
Quoted 2 lines
- qemu configures the RSS dynamically according to the commands provided by the guest
Consider we decided to use
mmap()based maps, this is not an issue.Or am I missing something?
Thanks
Quoted 220 lines
Thanks in advance
YuriQuoted 215 lines
Thanks
Quoted 210 lines
Quoted 210 lines
Quoted 168 lines
Also, libbpf dependency now exclusively for Linux.
Libbpf is used for eBPF RSS steering, which is supported only by Linux TAP. There is no reason yet to build eBPF loader and helper for non Linux systems, even if libbpf is present.Signed-off-by Andrew Melnychenko <[email protected]>--- ebpf/qemu-ebpf-rss-helper.c | 130 ++++++++++++++++++++++++++++++++++++ meson.build | 37 ++++++---- 2 files changed, 154 insertions(+), 13 deletions(-)create mode 100644
ebpf/qemu-ebpf-rss-helper.cebpf/qemu-ebpf-rss-helper.c new file +130
-0@@ -0,0 +1,130 @@ +/* +* eBPF RSS Helper +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +* Description: This is helper program for libvirtd. +* It loads eBPF RSS program and passes fds through unix socket. +* Built by meson, target - 'qemu-ebpf-rss-helper'. +*/ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> +#include <getopt.h> +#include <memory.h> +#include <errno.h> +#include <sys/socket.h> + +#include "ebpf_rss.h" + +#include "qemu-helper-stamp.h" + +void QEMU_HELPER_STAMP (void ) {} + +static int send_fds (int socket,int *fds,int n) +{ +struct msghdr msg = {}; +struct cmsghdr *cmsg =NULL ; +char buf[CMSG_SPACE (n *sizeof (int ))]; +char dummy_buffer =0 ; +struct iovec io = { .iov_base = &dummy_buffer, + .iov_len =sizeof (dummy_buffer) }; + +memset (buf,0 ,sizeof (buf)); + + msg.msg_iov = &io; + msg.msg_iovlen =1 ; + msg.msg_control = buf; + msg.msg_controllen =sizeof (buf); + + cmsg =CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level =SOL_SOCKET ; + cmsg->cmsg_type =SCM_RIGHTS ; + cmsg->cmsg_len =CMSG_LEN (n *sizeof (int )); + +memcpy (CMSG_DATA (cmsg), fds, n *sizeof (int )); + +return sendmsg (socket, &msg,0 ); +} + +static void print_help_and_exit (const char *prog,int exitcode) +{ +fprintf (stderr,"%s - load eBPF RSS program for qemu and pass eBPF fds" +" through unix socket.\n" , prog); +fprintf (stderr,"\t--fd <num>, -f <num> - unix socket file descriptor" +" used to pass eBPF fds.\n" ); +fprintf (stderr,"\t--help, -h - this help.\n" ); +exit (exitcode); +} + +int main (int argc,char **argv) +{ +char *fd_string =NULL ; +int unix_fd =0 ; +struct EBPFRSSContext ctx = {}; +int fds[EBPF_RSS_MAX_FDS ] = {}; +int ret =-1 ; + +for (;;) { +int c; +static struct option long_options[] = { + {"help" , no_argument,0 ,'h' }, + {"fd" , required_argument,0 ,'f' }, + {0 ,0 ,0 ,0 } + }; + c =getopt_long (argc, argv,"hf:" , + long_options,NULL ); + +if (c ==-1 ) { +break ; + } + +switch (c) { +case 'f' : + fd_string = optarg; +break ; +case 'h' : +default : +print_help_and_exit (argv[0 ], + c =='h' ?EXIT_SUCCESS :EXIT_FAILURE ); + } + } + +if (!fd_string) { +fprintf (stderr,"Unix file descriptor not present.\n" ); +print_help_and_exit (argv[0 ],EXIT_FAILURE ); + } + + unix_fd =atoi (fd_string); + +if (!unix_fd) { +fprintf (stderr,"Unix file descriptor is invalid.\n" ); +return EXIT_FAILURE ; + } + +ebpf_rss_init (&ctx); +if (!ebpf_rss_load (&ctx)) { +fprintf (stderr,"Can't load ebpf.\n" ); +return EXIT_FAILURE ; + } + fds[0 ] = ctx.program_fd; + fds[1 ] = ctx.map_configuration; + + ret =send_fds (unix_fd, fds,EBPF_RSS_MAX_FDS ); +if (ret <0 ) { +fprintf (stderr,"Issue while sending fds: %s.\n" ,strerror (errno)); + } + +ebpf_rss_unload (&ctx); + +return ret <0 ?EXIT_FAILURE :EXIT_SUCCESS ; +} +meson.build +0
-11@@ -1033,19 +1033,22 @@ if not get_option('fuse_lseek').disabled() endif # libbpf -libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') -if libbpf.found() and not cc.links(''' - #include <bpf/libbpf.h> - int main(void) - { - bpf_object__destroy_skeleton(NULL); - return 0; - }''', dependencies: libbpf) - libbpf = not_found - if get_option('bpf').enabled() - error('libbpf skeleton test failed')meson.build if not get_option('fuse_lseek').disabled() · line 1043
Quoted 10 lines
meson.build +8
-2- else - warning('libbpf skeleton test failed, disabling') +libbpf = not_found +if targetos == 'linux' + libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') + if libbpf.found() and not cc.links(''' + #include <bpf/libbpf.h> + int main(void) + { + bpf_object__destroy_skeleton(NULL);Do we need to test whether the bpf can do
mmap()here?Thanks
Quoted 26 lines
meson.build +16
-0+ return 0; + }''', dependencies: libbpf) + libbpf = not_found + if get_option('bpf').enabled() + error('libbpf skeleton test failed') + else + warning('libbpf skeleton test failed, disabling') + endif endif endif@@ -2423,6 +2426,14 @@ if have_tools dependencies: [authz, crypto, io, qom, qemuutil, libcap_ng, mpathpersist], install: true) + + if libbpf.found() + executable('qemu-ebpf-rss-helper', files( + 'ebpf/qemu-ebpf-rss-helper.c', 'ebpf/ebpf_rss.c'), + dependencies: [qemuutil, libbpf, glib], + install: true, + install_dir: get_option('libexecdir')) + endif endif if 'CONFIG_IVSHMEM' in config_host
Re: [PATCH 4/5] ebpf_rss_helper: Added helper for eBPF RSS.
Quoted 64 lines · Yuri Benditovich
Quoted 62 lines · Jason Wang
Quoted 48 lines · Yuri Benditovich
Quoted 37 lines · Jason Wang
Quoted 34 lines · Yuri Benditovich
Quoted 31 lines · Jason Wang
Quoted 12 lines · Yuri Benditovich
Quoted 11 lines · Jason Wang
Quoted 2 lines · Andrew Melnychenko
Helper program. Loads eBPF RSS program and maps and passes them through unix socket. Libvirt may launch this helper and pass eBPF fds to qemu virtio-net.
I wonder if this can be done as helper for TAP/bridge.
E.g it's the qemu to launch those helper with set-uid.
Then libvirt won't even need to care about that?
Quoted 10 lines
There are pros and cons for such a solution with set-uid.
From my point of view one of the cons is that set-uid is efficient
only at install time so the coexistence of different qemu builds (and different helpers for each one) is kind of problematic. With the current solution this does not present any problem: the developer can have several different builds, each one automatically has its own helper and there is no conflict between these builds and between these builds and installed qemu package. Changing the 'emulator' in the libvirt profile automatically brings the proper helper to work.I'm not sure I get you here. We can still have default/sample helper to make sure it works for different builds.
If we can avoid the involvement of libvirt, that would be better.
Quoted 9 lines
Quoted 7 lines
Hi Jason,
Indeed I did not get the idea, can you please explain it in more details (as detailed as possible to avoid future misunderstanding), especially how exactly we can use the set-uid and what is the 'default' helper. We also would prefer to do everything from qemu but we do not see how we can do that.
Quoted 7 lines
Some more questions to understand the idea better:
Quoted 3 lines
Something like:
1) -netdev tap,rss_helper=/path/to/name
So, on each editing of 'emulator' in the xml the helper path should be set manually or be default?
It could done manually, or we can have a default path.
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
2) having a sample/default helper implemented in Qemu
Does it mean the default helper is the code in the qemu (without running additional executable, like it does today)
Yes.
If the "default helper" is just a keyword and it is like what we have today (i.e. part of qemu)
Yes, it's something like "-netdev tap,script=no"
Quoted 2 lines
it can't work under libvirt and should never
be used by libvirt.
Any reason for this?
Quoted 9 lines
Quoted 7 lines
or this is qemu
Quoted 3 lines
itself with dedicated command line?
As far as I remember Daniel had strong objections of ever running qemu with capabilitiesQemu won't run with capabilities but the helper.
So under libvirt the helper is always separate executable and not "default helper"
That's fine, we can ship the helper as an independent package I think.
Quoted 21 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
3) we can introduce something special path like "default", then if -netdev tap,rss_helper="default" is specified, qemu will use the sample helper
Quoted 6 lines
Quoted 3 lines
Probably this is not so important but the rss helper and rss in general has no relation to netdev, much more they are related to virtio-net
So I think the reason for this is that we currently only support eBPF/RSS for tap.
This is just because only tap supports respective ioctls.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
So we have:
1) set set-uid for the helper
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Who and when does set-uid to the helper binary? Only installer or libvirt can do that, correct?
Yes, it could be done the installer, or other system provision tools.
So this changes the rule of the game: currently libvirt runs helpers that require privileges and qemu runs helpers that do not require any privileges (like TPM).
I don't understand here, if the helper doesn't need any privilege, why not do that in qemu itself?
Quoted 3 lines
If we follow your suggestion - only for RSS we will create the helper that must be used with set-uid.
Who are stakeholders we need to have a consensus with?
I think we need inputs from libvirt guys. Daniel, any idea on this?
Thanks
Quoted 260 lines
Quoted 259 lines
Quoted 5 lines
Quoted 4 lines
2) libvirt may just choose to launch the default helper
All this discussion is to avoid launching the helper from libvirt, correct?
Sorry, it's a typo. I meant, libvirt launch qemu, and then qemu will launch the helper.
Thanks
Quoted 247 lines
Quoted 246 lines
Quoted 6 lines
Our main points (what should be addressed):
- qemu should be able to load ebpf and use the maps when it runs from libvirt (without special caps) and standalone (with caps)This is solved by leaving the privileged operations to the helper with set-uid.
Quoted 4 lines
- it is possible that there are different qemu builds on the machine, one of them might be installed, their ebpf's might be different and the interface between qemu and ebpf (exact content of maps and number of maps)
We can use different helpers in this way.
Quoted 2 lines
- qemu configures the RSS dynamically according to the commands provided by the guest
Consider we decided to use
mmap()based maps, this is not an issue.Or am I missing something?
Thanks
Quoted 220 lines
Thanks in advance
YuriQuoted 215 lines
Thanks
Quoted 210 lines
Quoted 210 lines
Quoted 168 lines
Also, libbpf dependency now exclusively for Linux.
Libbpf is used for eBPF RSS steering, which is supported only by Linux TAP. There is no reason yet to build eBPF loader and helper for non Linux systems, even if libbpf is present.Signed-off-by Andrew Melnychenko <[email protected]>--- ebpf/qemu-ebpf-rss-helper.c | 130 ++++++++++++++++++++++++++++++++++++ meson.build | 37 ++++++---- 2 files changed, 154 insertions(+), 13 deletions(-)create mode 100644
ebpf/qemu-ebpf-rss-helper.cebpf/qemu-ebpf-rss-helper.c new file +130
-0@@ -0,0 +1,130 @@ +/* +* eBPF RSS Helper +* +* Developed by Daynix Computing LTD (http://www.daynix.com) +* +* Authors: +* Andrew Melnychenko <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2. See +* the COPYING file in the top-level directory. +* +* Description: This is helper program for libvirtd. +* It loads eBPF RSS program and passes fds through unix socket. +* Built by meson, target - 'qemu-ebpf-rss-helper'. +*/ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <stdbool.h> +#include <getopt.h> +#include <memory.h> +#include <errno.h> +#include <sys/socket.h> + +#include "ebpf_rss.h" + +#include "qemu-helper-stamp.h" + +void QEMU_HELPER_STAMP (void ) {} + +static int send_fds (int socket,int *fds,int n) +{ +struct msghdr msg = {}; +struct cmsghdr *cmsg =NULL ; +char buf[CMSG_SPACE (n *sizeof (int ))]; +char dummy_buffer =0 ; +struct iovec io = { .iov_base = &dummy_buffer, + .iov_len =sizeof (dummy_buffer) }; + +memset (buf,0 ,sizeof (buf)); + + msg.msg_iov = &io; + msg.msg_iovlen =1 ; + msg.msg_control = buf; + msg.msg_controllen =sizeof (buf); + + cmsg =CMSG_FIRSTHDR (&msg); + cmsg->cmsg_level =SOL_SOCKET ; + cmsg->cmsg_type =SCM_RIGHTS ; + cmsg->cmsg_len =CMSG_LEN (n *sizeof (int )); + +memcpy (CMSG_DATA (cmsg), fds, n *sizeof (int )); + +return sendmsg (socket, &msg,0 ); +} + +static void print_help_and_exit (const char *prog,int exitcode) +{ +fprintf (stderr,"%s - load eBPF RSS program for qemu and pass eBPF fds" +" through unix socket.\n" , prog); +fprintf (stderr,"\t--fd <num>, -f <num> - unix socket file descriptor" +" used to pass eBPF fds.\n" ); +fprintf (stderr,"\t--help, -h - this help.\n" ); +exit (exitcode); +} + +int main (int argc,char **argv) +{ +char *fd_string =NULL ; +int unix_fd =0 ; +struct EBPFRSSContext ctx = {}; +int fds[EBPF_RSS_MAX_FDS ] = {}; +int ret =-1 ; + +for (;;) { +int c; +static struct option long_options[] = { + {"help" , no_argument,0 ,'h' }, + {"fd" , required_argument,0 ,'f' }, + {0 ,0 ,0 ,0 } + }; + c =getopt_long (argc, argv,"hf:" , + long_options,NULL ); + +if (c ==-1 ) { +break ; + } + +switch (c) { +case 'f' : + fd_string = optarg; +break ; +case 'h' : +default : +print_help_and_exit (argv[0 ], + c =='h' ?EXIT_SUCCESS :EXIT_FAILURE ); + } + } + +if (!fd_string) { +fprintf (stderr,"Unix file descriptor not present.\n" ); +print_help_and_exit (argv[0 ],EXIT_FAILURE ); + } + + unix_fd =atoi (fd_string); + +if (!unix_fd) { +fprintf (stderr,"Unix file descriptor is invalid.\n" ); +return EXIT_FAILURE ; + } + +ebpf_rss_init (&ctx); +if (!ebpf_rss_load (&ctx)) { +fprintf (stderr,"Can't load ebpf.\n" ); +return EXIT_FAILURE ; + } + fds[0 ] = ctx.program_fd; + fds[1 ] = ctx.map_configuration; + + ret =send_fds (unix_fd, fds,EBPF_RSS_MAX_FDS ); +if (ret <0 ) { +fprintf (stderr,"Issue while sending fds: %s.\n" ,strerror (errno)); + } + +ebpf_rss_unload (&ctx); + +return ret <0 ?EXIT_FAILURE :EXIT_SUCCESS ; +} +meson.build +0
-11@@ -1033,19 +1033,22 @@ if not get_option('fuse_lseek').disabled() endif # libbpf -libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') -if libbpf.found() and not cc.links(''' - #include <bpf/libbpf.h> - int main(void) - { - bpf_object__destroy_skeleton(NULL); - return 0; - }''', dependencies: libbpf) - libbpf = not_found - if get_option('bpf').enabled() - error('libbpf skeleton test failed')meson.build if not get_option('fuse_lseek').disabled() · line 1043
Quoted 10 lines
meson.build +8
-2- else - warning('libbpf skeleton test failed, disabling') +libbpf = not_found +if targetos == 'linux' + libbpf = dependency('libbpf', required: get_option('bpf'), method: 'pkg-config') + if libbpf.found() and not cc.links(''' + #include <bpf/libbpf.h> + int main(void) + { + bpf_object__destroy_skeleton(NULL);Do we need to test whether the bpf can do
mmap()here?Thanks
Quoted 26 lines
meson.build +16
-0+ return 0; + }''', dependencies: libbpf) + libbpf = not_found + if get_option('bpf').enabled() + error('libbpf skeleton test failed') + else + warning('libbpf skeleton test failed, disabling') + endif endif endif@@ -2423,6 +2426,14 @@ if have_tools dependencies: [authz, crypto, io, qom, qemuutil, libcap_ng, mpathpersist], install: true) + + if libbpf.found() + executable('qemu-ebpf-rss-helper', files( + 'ebpf/qemu-ebpf-rss-helper.c', 'ebpf/ebpf_rss.c'), + dependencies: [qemuutil, libbpf, glib], + install: true, + install_dir: get_option('libexecdir')) + endif endif if 'CONFIG_IVSHMEM' in config_host
PATCH 5/5 qmp: Added qemu-ebpf-rss-path command.
In reply to Andrew MelnychenkoNew qmp command to query ebpf helper.
It's crucial that qemu and helper are in sync and in touch. Technically helper should pass eBPF fds that qemu may accept. And different qemu's builds may have different eBPF programs and helpers. Qemu returns helper that should "fit" to virtio-net.
--- monitor/qmp-cmds.c | 32 ++++++++++++++++++++++++++++++++ qapi/misc.json | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+)
monitor/qmp-cmds.c +32 -0
@@ -40,6 +40,7 @@#include "qapi/qmp/qerror.h" #include "hw/mem/memory-device.h" #include "hw/acpi/acpi_dev_interface.h" +#include "qemu-helper-stamp-utils.h" NameInfo *qmp_query_name (Error **errp) {
@@ -351,3 +352,34 @@ void qmp_display_reload(DisplayReloadOptions *arg, Error **errp)abort (); } } + +HelperPathList *qmp_query_helper_paths (Error **errp) +{ +HelperPathList *ret =NULL ; +struct { +const char *helper; +bool check_stamp; + } helpers_list[] = { +#ifdef CONFIG_EBPF + {"qemu-ebpf-rss-helper" , true }, +#endif + {"qemu-pr-helper" , false }, + {"qemu-bridge-helper" , false }, + {NULL , false }, + }, *helper_iter; + helper_iter = helpers_list; + +for (; helper_iter->helper !=NULL ; ++helper_iter) { +char *path =qemu_find_helper (helper_iter->helper, + helper_iter->check_stamp); +if (path) { +HelperPath *helper =g_new0 (HelperPath,1 ); + helper->name =g_strdup (helper_iter->helper); + helper->path = path; + +QAPI_LIST_PREPEND (ret, helper); + } + } + +return ret; +}
qapi/misc.json +33 -0
@@ -519,3 +519,36 @@ 'data': { '*option': 'str' }, 'returns': ['CommandLineOptionInfo'], 'allow-preconfig': true } + +## +# @HelperPath: +# +# Name of the helper and binary location. +## +{ 'struct': 'HelperPath', + 'data': {'name': 'str', 'path': 'str'} } + +## +# @query-helper-paths: +# +# Query helper paths. Initially, this command was added for +# qemu-ebpf-rss-helper. The qemu would check "the stamp" and +# returns proper helper. +# +# Returns: list of object that contains name and path for helper. +# +# Since: 6.1 +# +# Example: +# +# -> { "execute": "query-helper-paths" } +# <- { "return": [ +# { +# "name": "qemu-ebpf-rss-helper", +# "path": "/usr/local/libexec/qemu-ebpf-rss-helper" +# } +# ] +# } +# +## +{ 'command': 'query-helper-paths', 'returns': ['HelperPath'] }
Signature · 1 line
2.31.1
Re: [PATCH 5/5] qmp: Added qemu-ebpf-rss-path command.
Quoted 7 lines · Andrew Melnychenko
New qmp command to query ebpf helper.
It's crucial that qemu and helper are in sync and in touch. Technically helper should pass eBPF fds that qemu may accept. And different qemu's builds may have different eBPF programs and helpers. Qemu returns helper that should "fit" to virtio-net.Signed-off-by Andrew Melnychenko <[email protected]>
[...]
Quoted 31 lines
qapi/misc.json +23
-0@@ -519,3 +519,36 @@ 'data': { '*option': 'str' }, 'returns': ['CommandLineOptionInfo'], 'allow-preconfig': true } + +## +# @HelperPath: +# +# Name of the helper and binary location. +## +{ 'struct': 'HelperPath', + 'data': {'name': 'str', 'path': 'str'} } + +## +# @query-helper-paths: +# +# Query helper paths. Initially, this command was added for +# qemu-ebpf-rss-helper. The qemu would check "the stamp" and +# returns proper helper. +# +# Returns: list of object that contains name and path for helper. +# +# Since: 6.1 +# +# Example: +# +# -> { "execute": "query-helper-paths" }
qapi/misc.json line 554
Quoted 10 lines
qapi/misc.json +10
-0+# <- { "return": [ +# { +# "name": "qemu-ebpf-rss-helper", +# "path": "/usr/local/libexec/qemu-ebpf-rss-helper" +# } +# ] +# } +# +## +{ 'command': 'query-helper-paths', 'returns': ['HelperPath'] }
Hmm.
I understand the desire to help management applications to use the right helper. But I'm not sure this command is actually useful. The helper may or may not be installed at the path compiled into QEMU.
What happens when you use the wrong helper?
Even if we conclude this is the right approach for this helper, we still need to review the other helpers to see which of them we should have query-helper-paths cover.
Re: [PATCH 5/5] qmp: Added qemu-ebpf-rss-path command.
Hi,
Quoted 2 lines
The helper may or may not be installed at the path compiled into QEMU.
Yes, so the helper will not be called - QEMU will try to initiate eBPF RSS or use "in-qemu" RSS.
What happens when you use the wrong helper?
Quoted 1 line
UB - in most cases, eBPF program will work with wrong configurations. That's why the stamp was added.
query-helper-paths checks the stamp only for RSS helper.
Quoted 68 lines · Markus Armbruster
Quoted 7 lines · Andrew Melnychenko
New qmp command to query ebpf helper.
It's crucial that qemu and helper are in sync and in touch. Technically helper should pass eBPF fds that qemu may accept. And different qemu's builds may have different eBPF programs and helpers. Qemu returns helper that should "fit" to virtio-net.Signed-off-by Andrew Melnychenko <[email protected]>[...]
Quoted 31 lines
qapi/misc.json +23
-0@@ -519,3 +519,36 @@ 'data': { '*option': 'str' }, 'returns': ['CommandLineOptionInfo'], 'allow-preconfig': true } + +## +# @HelperPath: +# +# Name of the helper and binary location. +## +{ 'struct': 'HelperPath', + 'data': {'name': 'str', 'path': 'str'} } + +## +# @query-helper-paths: +# +# Query helper paths. Initially, this command was added for +# qemu-ebpf-rss-helper. The qemu would check "the stamp" and +# returns proper helper. +# +# Returns: list of object that contains name and path for helper. +# +# Since: 6.1 +# +# Example: +# +# -> { "execute": "query-helper-paths" }qapi/misc.json line 554
Quoted 10 lines
qapi/misc.json +10
-0+# <- { "return": [ +# { +# "name": "qemu-ebpf-rss-helper", +# "path": "/usr/local/libexec/qemu-ebpf-rss-helper" +# } +# ] +# } +# +## +{ 'command': 'query-helper-paths', 'returns': ['HelperPath'] }Hmm.
I understand the desire to help management applications to use the right helper. But I'm not sure this command is actually useful. The helper may or may not be installed at the path compiled into QEMU.
What happens when you use the wrong helper?
Even if we conclude this is the right approach for this helper, we still need to review the other helpers to see which of them we should have query-helper-paths cover.
Re: [PATCH 5/5] qmp: Added qemu-ebpf-rss-path command.
Quoted 6 lines · Andrew Melnichenko
Hi,
Quoted 2 lines
The helper may or may not be installed at the path compiled into QEMU.
Yes, so the helper will not be called - QEMU will try to initiate eBPF RSS or use "in-qemu" RSS.
My point is: the proposed command's mission is to help the management application run the right helper. However, its advice is *unreliable*. It may point to the wrong helper, or to nothing at all. The right helper may still exist elsewhere.
I suspect you're trying to address the problem at the wrong level.
Similar versioning issues exist with other helpers. We've been doing fine without QEMU providing unreliable advice on where they might sit in the file system. What makes this one different?
Quoted 6 lines
Quoted 2 lines
What happens when you use the wrong helper?
UB - in most cases, eBPF program will work with wrong configurations. That's why the stamp was added.
query-helper-paths checks the stamp only for RSS helper.
I have no idea what you're talking about :)
My best guess is that you're trying to tell me that attempting to work with the wrong helper will fail cleanly due to some stamp check. That would be nice.
Re: [PATCH 5/5] qmp: Added qemu-ebpf-rss-path command.
Hi,
Yes, the stamp check was added.
So the qemu emulator should return a suitable RSS BPF helper or nothing. Each qemu emulator may have a different helper that suits it. So, the idea is to ask for the helper from qemu.
Quoted 35 lines · Markus Armbruster
Quoted 5 lines · Andrew Melnichenko
Hi,
Quoted 2 lines
The helper may or may not be installed at the path compiled into QEMU.
Yes, so the helper will not be called - QEMU will try to initiate eBPF
RSS
Quoted 1 line
or use "in-qemu" RSS.
My point is: the proposed command's mission is to help the management application run the right helper. However, its advice is *unreliable*. It may point to the wrong helper, or to nothing at all. The right helper may still exist elsewhere.
I suspect you're trying to address the problem at the wrong level.
Similar versioning issues exist with other helpers. We've been doing fine without QEMU providing unreliable advice on where they might sit in the file system. What makes this one different?
Quoted 6 lines
Quoted 2 lines
What happens when you use the wrong helper?
UB - in most cases, eBPF program will work with wrong configurations. That's why the stamp was added.
query-helper-paths checks the stamp only for RSS helper.
I have no idea what you're talking about :)
My best guess is that you're trying to tell me that attempting to work with the wrong helper will fail cleanly due to some stamp check. That would be nice.
Re: [PATCH 5/5] qmp: Added qemu-ebpf-rss-path command.
Quoted 5 lines · Andrew Melnichenko
Hi,
Yes, the stamp check was added.
So the qemu emulator should return a suitable RSS BPF helper or nothing. Each qemu emulator may have a different helper that suits it. So, the idea is to ask for the helper from qemu.
Please answer the question below.
Quoted 18 lines · Markus Armbruster
Quoted 16 lines
Quoted 5 lines · Andrew Melnichenko
Hi,
Quoted 2 lines
The helper may or may not be installed at the path compiled into QEMU.
Yes, so the helper will not be called - QEMU will try to initiate eBPF
RSS
Quoted 1 line
or use "in-qemu" RSS.
My point is: the proposed command's mission is to help the management application run the right helper. However, its advice is *unreliable*. It may point to the wrong helper, or to nothing at all. The right helper may still exist elsewhere.
Quoted 5 lines
Quoted 5 lines
I suspect you're trying to address the problem at the wrong level.
Similar versioning issues exist with other helpers. We've been doing fine without QEMU providing unreliable advice on where they might sit in the file system. What makes this one different?
This one.
Quoted 14 lines
Quoted 14 lines
Quoted 6 lines
Quoted 2 lines
What happens when you use the wrong helper?
UB - in most cases, eBPF program will work with wrong configurations. That's why the stamp was added.
query-helper-paths checks the stamp only for RSS helper.
I have no idea what you're talking about :)
My best guess is that you're trying to tell me that attempting to work with the wrong helper will fail cleanly due to some stamp check. That would be nice.
Re: [PATCH 5/5] qmp: Added qemu-ebpf-rss-path command.
In reply to Markus ArmbrusterQuoted 7 lines · Markus Armbruster
Quoted 4 lines · Andrew Melnichenko
Hi,
Quoted 2 lines
The helper may or may not be installed at the path compiled into QEMU.
Quoted 7 lines
Quoted 2 lines
Yes, so the helper will not be called - QEMU will try to initiate eBPF RSS or use "in-qemu" RSS.
My point is: the proposed command's mission is to help the management application run the right helper. However, its advice is *unreliable*. It may point to the wrong helper, or to nothing at all. The right helper may still exist elsewhere.
Hi Markus,
Indeed the intention of this command is to return the proper helper. Especially in the case of RSS helper this is *reliable* advice and it points to the helper that was built together with QEMU, i.e. with the same headers.
This was discussed earlier, for example in
https://lists.nongnu.org/archive/html/qemu-devel/2021-06/msg02248.html
Quoted 2 lines
I suspect you're trying to address the problem at the wrong level.
What is the proper solution for the problem from your point of view?
Quoted 4 lines
Similar versioning issues exist with other helpers. We've been doing fine without QEMU providing unreliable advice on where they might sit in the file system. What makes this one different?
This one is required to be *fully synchronized* with the existing build of QEMU. Other helpers are probably less restrictive and do not have common structures definitions with the QEMU, otherwise they would face the same problem.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
What happens when you use the wrong helper?
Our intention is that libvirt should never use the wrong RSS helper. But it does not have any ability to check which helper is compatible with the QEMU.
QEMU can easily recognize the correct one.
Quoted 12 lines
Quoted 5 lines
Quoted 1 line
UB - in most cases, eBPF program will work with wrong configurations. That's why the stamp was added.
query-helper-paths checks the stamp only for RSS helper.
I have no idea what you're talking about :)
My best guess is that you're trying to tell me that attempting to work with the wrong helper will fail cleanly due to some stamp check. That would be nice.
Re: [PATCH 5/5] qmp: Added qemu-ebpf-rss-path command.
Quoted 25 lines · Yuri Benditovich
Quoted 7 lines · Markus Armbruster
Quoted 4 lines · Andrew Melnichenko
Hi,
Quoted 2 lines
The helper may or may not be installed at the path compiled into QEMU.
Quoted 7 lines
Quoted 2 lines
Yes, so the helper will not be called - QEMU will try to initiate eBPF RSS or use "in-qemu" RSS.
My point is: the proposed command's mission is to help the management application run the right helper. However, its advice is *unreliable*. It may point to the wrong helper, or to nothing at all. The right helper may still exist elsewhere.
Hi Markus,
Indeed the intention of this command is to return the proper helper. Especially in the case of RSS helper this is *reliable* advice and it points to the helper that was built together with QEMU, i.e. with the same headers.
This was discussed earlier, for example in
https://lists.nongnu.org/archive/html/qemu-devel/2021-06/msg02248.htmlQuoted 1 line
Quoted 3 lines
Quoted 1 line
I suspect you're trying to address the problem at the wrong level.
What is the proper solution for the problem from your point of view?
I'll explain in more detail, but first I'd like you to answer my question below.
Quoted 10 lines
Quoted 3 lines
Similar versioning issues exist with other helpers. We've been doing fine without QEMU providing unreliable advice on where they might sit in the file system. What makes this one different?
This one is required to be *fully synchronized* with the existing build of QEMU. Other helpers are probably less restrictive and do not have common structures definitions with the QEMU, otherwise they would face the same problem.
Quoted 1 line
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
What happens when you use the wrong helper?
Our intention is that libvirt should never use the wrong RSS helper. But it does not have any ability to check which helper is compatible with the QEMU.
QEMU can easily recognize the correct one.
You did not actually answer my question :)
So let's try again: if libvirt does use the wrong RSS helper, how does the system behave?
Quoted 12 lines
Quoted 12 lines
Quoted 5 lines
Quoted 1 line
UB - in most cases, eBPF program will work with wrong configurations. That's why the stamp was added.
query-helper-paths checks the stamp only for RSS helper.
I have no idea what you're talking about :)
My best guess is that you're trying to tell me that attempting to work with the wrong helper will fail cleanly due to some stamp check. That would be nice.
Re: [PATCH 5/5] qmp: Added qemu-ebpf-rss-path command.
Quoted 52 lines · Markus Armbruster
Quoted 25 lines · Yuri Benditovich
Quoted 7 lines · Markus Armbruster
Quoted 4 lines · Andrew Melnichenko
Hi,
Quoted 2 lines
The helper may or may not be installed at the path compiled into QEMU.
Quoted 7 lines
Quoted 2 lines
Yes, so the helper will not be called - QEMU will try to initiate eBPF RSS or use "in-qemu" RSS.
My point is: the proposed command's mission is to help the management application run the right helper. However, its advice is *unreliable*. It may point to the wrong helper, or to nothing at all. The right helper may still exist elsewhere.
Hi Markus,
Indeed the intention of this command is to return the proper helper. Especially in the case of RSS helper this is *reliable* advice and it points to the helper that was built together with QEMU, i.e. with the same headers.
This was discussed earlier, for example in
https://lists.nongnu.org/archive/html/qemu-devel/2021-06/msg02248.htmlQuoted 1 line
Quoted 3 lines
Quoted 1 line
I suspect you're trying to address the problem at the wrong level.
What is the proper solution for the problem from your point of view?
I'll explain in more detail, but first I'd like you to answer my question below.
Quoted 10 lines
Quoted 3 lines
Similar versioning issues exist with other helpers. We've been doing fine without QEMU providing unreliable advice on where they might sit in the file system. What makes this one different?
This one is required to be *fully synchronized* with the existing build of QEMU. Other helpers are probably less restrictive and do not have common structures definitions with the QEMU, otherwise they would face the same problem.
Quoted 1 line
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
What happens when you use the wrong helper?
Our intention is that libvirt should never use the wrong RSS helper. But it does not have any ability to check which helper is compatible with the QEMU.
QEMU can easily recognize the correct one.
Quoted 4 lines
You did not actually answer my question :)
So let's try again: if libvirt does use the wrong RSS helper, how does the system behave?
The receive-side scaling may work incorrectly, i.e. finally may move incoming packets to a virtqueue different than expected one.
Quoted 14 lines
Quoted 13 lines
Quoted 13 lines
Quoted 6 lines
Quoted 2 lines
UB - in most cases, eBPF program will work with wrong configurations. That's why the stamp was added.
query-helper-paths checks the stamp only for RSS helper.
I have no idea what you're talking about :)
My best guess is that you're trying to tell me that attempting to work with the wrong helper will fail cleanly due to some stamp check. That would be nice.
Re: [PATCH 5/5] qmp: Added qemu-ebpf-rss-path command.
Quoted 53 lines · Yuri Benditovich
Quoted 52 lines · Markus Armbruster
Quoted 25 lines · Yuri Benditovich
Quoted 7 lines · Markus Armbruster
Quoted 4 lines · Andrew Melnichenko
Hi,
Quoted 2 lines
The helper may or may not be installed at the path compiled into QEMU.
Quoted 7 lines
Quoted 2 lines
Yes, so the helper will not be called - QEMU will try to initiate eBPF RSS or use "in-qemu" RSS.
My point is: the proposed command's mission is to help the management application run the right helper. However, its advice is *unreliable*. It may point to the wrong helper, or to nothing at all. The right helper may still exist elsewhere.
Hi Markus,
Indeed the intention of this command is to return the proper helper. Especially in the case of RSS helper this is *reliable* advice and it points to the helper that was built together with QEMU, i.e. with the same headers.
This was discussed earlier, for example in
https://lists.nongnu.org/archive/html/qemu-devel/2021-06/msg02248.htmlQuoted 1 line
Quoted 3 lines
Quoted 1 line
I suspect you're trying to address the problem at the wrong level.
What is the proper solution for the problem from your point of view?
I'll explain in more detail, but first I'd like you to answer my question below.
Quoted 16 lines
Quoted 3 lines
Similar versioning issues exist with other helpers. We've been doing fine without QEMU providing unreliable advice on where they might sit in the file system. What makes this one different?
This one is required to be *fully synchronized* with the existing build of QEMU. Other helpers are probably less restrictive and do not have common structures definitions with the QEMU, otherwise they would face the same problem.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
What happens when you use the wrong helper?
Our intention is that libvirt should never use the wrong RSS helper. But it does not have any ability to check which helper is compatible with the QEMU.
QEMU can easily recognize the correct one.
Quoted 7 lines
Quoted 4 lines
You did not actually answer my question :)
So let's try again: if libvirt does use the wrong RSS helper, how does the system behave?
The receive-side scaling may work incorrectly, i.e. finally may move incoming packets to a virtqueue different than expected one.
Then I'm confused about the purpose of "the stamp" mentioned below. Can you enlighten me?
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 7 lines
Quoted 3 lines
UB - in most cases, eBPF program will work with wrong configurations. That's why the stamp was added.
query-helper-paths checks the stamp only for RSS helper.
I have no idea what you're talking about :)
My best guess is that you're trying to tell me that attempting to work with the wrong helper will fail cleanly due to some stamp check. That would be nice.
Re: [PATCH 5/5] qmp: Added qemu-ebpf-rss-path command.
Quoted 58 lines · Markus Armbruster
Quoted 55 lines · Yuri Benditovich
Quoted 54 lines · Markus Armbruster
Quoted 25 lines · Yuri Benditovich
Quoted 7 lines · Markus Armbruster
Quoted 4 lines · Andrew Melnichenko
Hi,
Quoted 2 lines
The helper may or may not be installed at the path compiled into QEMU.
Quoted 7 lines
Quoted 2 lines
Yes, so the helper will not be called - QEMU will try to initiate eBPF RSS or use "in-qemu" RSS.
My point is: the proposed command's mission is to help the management application run the right helper. However, its advice is *unreliable*. It may point to the wrong helper, or to nothing at all. The right helper may still exist elsewhere.
Hi Markus,
Indeed the intention of this command is to return the proper helper. Especially in the case of RSS helper this is *reliable* advice and it points to the helper that was built together with QEMU, i.e. with the same headers.
This was discussed earlier, for example in
https://lists.nongnu.org/archive/html/qemu-devel/2021-06/msg02248.htmlQuoted 1 line
Quoted 3 lines
Quoted 1 line
I suspect you're trying to address the problem at the wrong level.
What is the proper solution for the problem from your point of view?
I'll explain in more detail, but first I'd like you to answer my question below.
Quoted 10 lines
Quoted 3 lines
Similar versioning issues exist with other helpers. We've been doing fine without QEMU providing unreliable advice on where they might sit in the file system. What makes this one different?
This one is required to be *fully synchronized* with the existing build of QEMU. Other helpers are probably less restrictive and do not have common structures definitions with the QEMU, otherwise they would face the same problem.
Quoted 1 line
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
What happens when you use the wrong helper?
Our intention is that libvirt should never use the wrong RSS helper. But it does not have any ability to check which helper is compatible with the QEMU.
QEMU can easily recognize the correct one.You did not actually answer my question :)
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
So let's try again: if libvirt does use the wrong RSS helper, how does the system behave?
The receive-side scaling may work incorrectly, i.e. finally may move incoming packets to a virtqueue different than expected one.
Then I'm confused about the purpose of "the stamp" mentioned below. Can you enlighten me?
The stamp is a string (common for qemu executable and RSS helper executable during build) that qemu can later retrieve from the helper in run-time and ensure this helper is fully compatible with this build of qemu (in terms of eBPF operation). The helper is built with the same C headers (related to ebpf operation) as the qemu, the qemu is able to receive file descriptors created by the helper (of ebpf program and ebpf data structure's maps) from libvirt and deal with them as if it has created them.
Quoted 15 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 8 lines
Quoted 4 lines
UB - in most cases, eBPF program will work with wrong configurations. That's why the stamp was added.
query-helper-paths checks the stamp only for RSS helper.
I have no idea what you're talking about :)
My best guess is that you're trying to tell me that attempting to work with the wrong helper will fail cleanly due to some stamp check. That would be nice.
Re: [PATCH 5/5] qmp: Added qemu-ebpf-rss-path command.
Quoted 5 lines · Yuri Benditovich
Quoted 4 lines · Markus Armbruster
Quoted 1 line · Yuri Benditovich
On Mon, Aug 30, 2021 at 9:10 AM Markus Armbruster <[email protected]> wrote:
[...]
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
So let's try again: if libvirt does use the wrong RSS helper, how does the system behave?
The receive-side scaling may work incorrectly, i.e. finally may move incoming packets to a virtqueue different than expected one.
Then I'm confused about the purpose of "the stamp" mentioned below. Can you enlighten me?
Quoted 8 lines
The stamp is a string (common for qemu executable and RSS helper executable during build) that qemu can later retrieve from the helper in run-time and ensure this helper is fully compatible with this build of qemu (in terms of eBPF operation). The helper is built with the same C headers (related to ebpf operation) as the qemu, the qemu is able to receive file descriptors created by the helper (of ebpf program and ebpf data structure's maps) from libvirt and deal with them as if it has created them.
Thanks.
I tried to apply your series to check a few of my assumptions, but I'm getting conflicts. Got something I could git-pull?
[...]
Re: [PATCH 5/5] qmp: Added qemu-ebpf-rss-path command.
Hi,
Quoted 2 lines
Got something I could git-pull?
I can share some links for tests:
https://github.com/daynix/qemu/tree/HelperEBPFv3 - qemu with helper
https://github.com/daynix/libvirt/tree/RSS_RFC_v1 - libvirt with RSS
Quoted 39 lines · Markus Armbruster
Quoted 1 line · Yuri Benditovich
On Mon, Aug 30, 2021 at 11:14 AM Markus Armbruster <[email protected]>
Quoted 4 lines · wrote:
Quoted 4 lines
Quoted 1 line · Yuri Benditovich
On Mon, Aug 30, 2021 at 9:10 AM Markus Armbruster <[email protected]>
wrote:
[...]
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
So let's try again: if libvirt does use the wrong RSS helper, how
does
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
the system behave?
The receive-side scaling may work incorrectly, i.e. finally may move incoming packets to a virtqueue different than expected one.
Then I'm confused about the purpose of "the stamp" mentioned below. Can you enlighten me?
Quoted 8 lines
The stamp is a string (common for qemu executable and RSS helper executable during build) that qemu can later retrieve from the helper in run-time and ensure this helper is fully compatible with this build of qemu (in terms of eBPF operation). The helper is built with the same C headers (related to ebpf operation) as the qemu, the qemu is able to receive file descriptors created by the helper (of ebpf program and ebpf data structure's maps) from libvirt and deal with them as if it has created them.
Thanks.
I tried to apply your series to check a few of my assumptions, but I'm getting conflicts. Got something I could git-pull?
[...]
Re: [PATCH 5/5] qmp: Added qemu-ebpf-rss-path command.
Quoted 7 lines · Andrew Melnichenko
Hi,
Quoted 2 lines
Got something I could git-pull?
I can share some links for tests:
https://github.com/daynix/qemu/tree/HelperEBPFv3 - qemu with helper
https://github.com/daynix/libvirt/tree/RSS_RFC_v1 - libvirt with RSS
Thanks!
I get a few warnings. I'm copying the ones from Clang:
../hw/net/virtio-net.c:1274:63: warning: array index 2 is past the end of the array (which contains 2 elements) [-Warray-bounds]
ret = ebpf_rss_load_fds(&n->ebpf_rss, fds[0], fds[1], fds[2], fds[3]);
^ ~
../hw/net/virtio-net.c:1257:5: note: array 'fds' declared here
int fds[EBPF_RSS_MAX_FDS];
^
../hw/net/virtio-net.c:1274:71: warning: array index 3 is past the end of the array (which contains 2 elements) [-Warray-bounds]
ret = ebpf_rss_load_fds(&n->ebpf_rss, fds[0], fds[1], fds[2], fds[3]);
^ ~
../hw/net/virtio-net.c:1257:5: note: array 'fds' declared here
int fds[EBPF_RSS_MAX_FDS];
^../ebpf/qemu-ebpf-rss-helper.c:30:6: warning: no previous prototype for function 'qemuHelperStamp_a59ff8818a819adc85c28504b7961bdf89f0d9c0' [-Wmissing-prototypes] void QEMU_HELPER_STAMP(void) {}
^
./qemu-helper-stamp.h:1:27: note: expanded from macro 'QEMU_HELPER_STAMP'
#define QEMU_HELPER_STAMP qemuHelperStamp_a59ff8818a819adc85c28504b7961bdf89f0d9c0
^../ebpf/qemu-ebpf-rss-helper.c:30:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void QEMU_HELPER_STAMP(void) {}
^
static
A message that is not in the archive (sent off-list or not yet received): CABcq3pGzs=RqLCuu70KyWt7W6T=qEhihK6v=iHJyfuGqiN_Q+A@mail.gmail.com
A message that is not in the archive (sent off-list or not yet received): CAOEp5Oc_uUn2nJq+B+SK-iQSo5udyUTirWHS5=8N0JxerRaz7A@mail.gmail.com
Re: [PATCH 5/5] qmp: Added qemu-ebpf-rss-path command.
Hi,
Quoted 4 lines
Ther first two are bogus. /work/armbru/tmp/inst-qemu/... is where "make install" would put things. I last ran "make install" almost three months ago.
The stamp check is implemented only for the RSS helper. Qemu looks for a helper first in HelpDir, then next to the binary.
Bridge/PR helpers found in "inst-qemu" according to build configuration. To be more strict, for the next patch we may return only ebpf helper in the list. Other helpers may be added later with stamp check.
It's still unreliable in the sense of "may not
Quoted 2 lines
find the helper"
Ok, I see the problem.
Here I can propose possible solutions:
1. Add the argument to QMP request - the path(s) where the qemu should look for helper by priority: argument path, installation dir, qemu's dir. And return an array of all possible helpers binaries.
2. Retrieve the stamp from QMP request, so Libvirt may check the stamp by itself.
3. Set suid bit to helper and pass the helper's path to the qemu, so qemu may run it by itself.
Searching the ELF symbol table requires ELF. I suspect your meson.build
Quoted 4 lines
doesn't reflect that.
It also requires the symbol table to be present. Statically linked
Quoted 2 lines
programs don't have one, if I remember correctly.
Well, qemu-ebpf-rss-helper is only for Linux and expectations are to have ELF binaries.
The helper builds dynamically linked with libbpf.so at least.
Management applications run qemu-system-FOO and helpers. They know
Quoted 6 lines
where to find qemu-system-FOO. It stands to reason that they also know where to find the matching helpers. I fail to see why they need help from qemu-system-FOO via QMP. Even if they need help, qemu-system-FOO can't give it, because it cannot know for sure. It is wherever the system administrator / distro put it.
We may have several different qemu builds which may require different rss helpers.
Domain with a custom emulator:
Quoted 5 lines
* <devices> <emulator>/path_to_my_awesome_qemu_with_custom_bpf/qemu-system-FOO</emulator> *
Libvirt would gather properties of that qemu and we need to provide the proper helper for it.
The "default" helper from libvirt configure may not suit the qemu. So the idea is to ask the qemu itself where is a possible helper. So Libvirt may use only <emulator> without additional changes in XML document.
So we need to solve next cases:
- System admin or distributor places the qemu and helpers in InstallPath. Libvirt uses installed qemu and helpers. No hints from qemu are required.
- Libvirt uses custom qemu <emulator>. Libvirt doesn't know where is the helper
that was built with custom qemu. Qemu if finds the helper - verifies the stamp, to make sure.
- Custom-built qemu is installed in the configured path(proper prefix etc.). Libvirt may
use that emulator but don't know where is the helper - qemu knows and may provide a hint.
There are much easier ways for that than searching through ELF symbol
Quoted 3 lines
tables. Have a command line option to print it. For qemu-system-FOO, you can also have a QMP command to query it.
The stamp was added in a similar way as qemu modules(special symbol, checked during load).
Also, checking the stamp without running is a good security measure.
I get a few warnings. I'm copying the ones from Clang:
Quoted 1 line
Thank you, I'll fix them in v2 patches with rebased tree.
Re: [PATCH 5/5] qmp: Added qemu-ebpf-rss-path command.
In reply to Yuri BenditovichQuoted 24 lines · Yuri Benditovich
Quoted 23 lines · Markus Armbruster
Quoted 20 lines · Yuri Benditovich
Quoted 19 lines · Markus Armbruster
Quoted 16 lines · Yuri Benditovich
Quoted 14 lines · Markus Armbruster
Quoted 6 lines · Andrew Melnichenko
Hi,
Quoted 2 lines
The helper may or may not be installed at the path compiled into QEMU.
Yes, so the helper will not be called - QEMU will try to initiate eBPF RSS or use "in-qemu" RSS.
My point is: the proposed command's mission is to help the management application run the right helper. However, its advice is *unreliable*. It may point to the wrong helper, or to nothing at all. The right helper may still exist elsewhere.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Hi Markus,
Indeed the intention of this command is to return the proper helper. Especially in the case of RSS helper this is *reliable* advice and it points to the helper that was built together with QEMU, i.e. with the same headers.
In my testing, the patch fails at providing reliable advice.
I did a "git fetch https://github.com/daynix/qemu HelperEBPFv3", rebased the result to master, build the thing, ran qemu-system-x86_64 right from the build tree, tried query-helper-paths and got
{"return": [
{"name": "qemu-bridge-helper",
"path": "/work/armbru/tmp/inst-qemu/libexec/qemu-bridge-helper"},
{"name": "qemu-pr-helper",
"path": "/work/armbru/tmp/inst-qemu/libexec/qemu-pr-helper"},
{"name": "qemu-ebpf-rss-helper",
"path": "/work/armbru/qemu/bld-x86/qemu-ebpf-rss-helper"}]}Ther first two are bogus. /work/armbru/tmp/inst-qemu/... is where "make install" would put things. I last ran "make install" almost three months ago.
The last one is accurate in this particular scenario. More on why below.
It won't be in a deployment where the actual installation paths do not match the ones we told configure at build time. Yes, people do that. Please read my entire reply before you comment on this paragraph.
Quoted 39 lines
Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 7 lines
This was discussed earlier, for example in
https://lists.nongnu.org/archive/html/qemu-devel/2021-06/msg02248.htmlQuoted 2 lines
I suspect you're trying to address the problem at the wrong level.
What is the proper solution for the problem from your point of view?
I'll explain in more detail, but first I'd like you to answer my question below.
Quoted 10 lines
Quoted 3 lines
Similar versioning issues exist with other helpers. We've been doing fine without QEMU providing unreliable advice on where they might sit in the file system. What makes this one different?
This one is required to be *fully synchronized* with the existing build of QEMU. Other helpers are probably less restrictive and do not have common structures definitions with the QEMU, otherwise they would face the same problem.
Quoted 1 line
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
What happens when you use the wrong helper?
Our intention is that libvirt should never use the wrong RSS helper. But it does not have any ability to check which helper is compatible with the QEMU.
QEMU can easily recognize the correct one.You did not actually answer my question :)
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
So let's try again: if libvirt does use the wrong RSS helper, how does the system behave?
The receive-side scaling may work incorrectly, i.e. finally may move incoming packets to a virtqueue different than expected one.
Then I'm confused about the purpose of "the stamp" mentioned below. Can you enlighten me?
Quoted 8 lines
The stamp is a string (common for qemu executable and RSS helper executable during build) that qemu can later retrieve from the helper in run-time and ensure this helper is fully compatible with this build of qemu (in terms of eBPF operation). The helper is built with the same C headers (related to ebpf operation) as the qemu, the qemu is able to receive file descriptors created by the helper (of ebpf program and ebpf data structure's maps) from libvirt and deal with them as if it has created them.
query-helper-paths looks for the helper a number of locations, and reports the first one. This is fundamentally unrealiable.
For qemu-ebpf-rss-helper, it additionally searches for a stamp symbol in the ELF symbol table. That's what makes it reliable in the sense of "won't report crap". It's still unreliable in the sense of "may not find the helper", see above.
Searching the ELF symbol table requires ELF. I suspect your meson.build doesn't reflect that.
It also requires the symbol table to be present. Statically linked programs don't have one, if I remember correctly.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 5 lines
Quoted 1 line
UB - in most cases, eBPF program will work with wrong configurations. That's why the stamp was added.
query-helper-paths checks the stamp only for RSS helper.
I have no idea what you're talking about :)
My best guess is that you're trying to tell me that attempting to work with the wrong helper will fail cleanly due to some stamp check. That would be nice.
Looks like my best guess was correct.
Let's take a step back.
Management applications run qemu-system-FOO and helpers. They know where to find qemu-system-FOO. It stands to reason that they also know where to find the matching helpers. I fail to see why they need help from qemu-system-FOO via QMP. Even if they need help, qemu-system-FOO can't give it, because it cannot know for sure. It is wherever the system administrator / distro put it.
When the system administrator / distro put stuff in unusual places, they get to configure the programs that use it. In this case, that's the management application.
How QEMU may be able to help is refuse to run with the wrong helper.
If qemu-system-FOO talks directly to the helper, you can have the helper present the stamp for qemu-system-FOO to accept or reject. Or vice versa, doesn't matter.
Or you can provide means for the management application to retrieve a stamp from all programs involved, so it can fail unless they match. There are much easier ways for that than searching through ELF symbol tables. Have a command line option to print it. For qemu-system-FOO, you can also have a QMP command to query it.
ping
Quoted 77 lines · Andrew Melnychenko
Libvirt usually launches qemu with strict permissions. To enable eBPF RSS steering, qemu-ebpf-rss-helper was added.
Added property "
ebpf_rss_fds" for "virtio-net" that allows to initialize eBPF RSS context with passed program & maps fds.Added qemu-ebpf-rss-helper - simple helper that loads eBPF context and passes fds through unix socket. Libvirt should call the helper and pass fds to qemu through "
ebpf_rss_fds" property.Added explicit target OS check for libbpf dependency in meson. eBPF RSS works only with Linux TAP, so there is no reason to build eBPF loader/helper for non-Linux.
Changed Qemu updates eBPF maps to array mmaping. Mmaping allows bypassing unprivileged BPF map update. Also, instead of 3 maps (config, key and indirection table) there is one map that combines everything.
Added helper stamp. To check that helper was build with qemu, qemu would check helper symbols that should contain the stamp. It was done similar to qemu modules, but checking was performed by the helper's ELF parsing.
Overall, libvirt process should not be aware of the "interface" of eBPF RSS, it will not be aware of eBPF maps/program "type" and their quantity. That's why qemu and the helper should be from the same build and be "synchronized". Technically each qemu may have its own helper. That's why "query-helper-paths" qmp command was added. Qemu should return the path to the helper that suits and libvirt should use "that" helper for "that" emulator.
qmp sample:
C: { "execute": "query-helper-paths" }
S: { "return": [{ "name": "qemu-ebpf-rss-helper", "path": "/usr/local/libexec/qemu-ebpf-rss-helper" } ]}
Changes since v1:
*Mmap()used instead ifbpf_map_update_elem().
* Added helper stamp.Andrew Melnychenko (5):
ebpf: Added eBPF initialization by fds and map update.
virtio-net: Added property to load eBPF RSS with fds.
qmp: Added the helper stamp check.
ebpf_rss_helper: Added helper for eBPF RSS.
qmp: Added qemu-ebpf-rss-path command.ebpf/ebpf_rss-stub.c | 6 + ebpf/ebpf_rss.c | 120 ++++--- ebpf/ebpf_rss.h | 8 +- ebpf/qemu-ebpf-rss-helper.c | 130 +++++++ ebpf/rss.bpf.skeleton.h | 557 +++++++++++++++--------------- hw/net/virtio-net.c | 77 ++++- include/hw/virtio/virtio-net.h | 1 + meson.build | 47 ++- monitor/meson.build | 1 + monitor/qemu-helper-stamp-utils.c | 297 ++++++++++++++++ monitor/qemu-helper-stamp-utils.h | 24 ++ monitor/qmp-cmds.c | 32 ++ qapi/misc.json | 33 ++ tools/ebpf/rss.bpf.c | 67 ++-- 14 files changed, 990 insertions(+), 410 deletions(-) create mode 100644 ebpf/qemu-ebpf-rss-helper.c create mode 100644 monitor/qemu-helper-stamp-utils.c create mode 100644 monitor/qemu-helper-stamp-utils.h--
2.31.1
Jason,
Can you please review the series?
Thanks,
Yuri
Quoted 81 lines · Andrew Melnichenko
ping
Quoted 77 lines · Andrew Melnychenko
Libvirt usually launches qemu with strict permissions. To enable eBPF RSS steering, qemu-ebpf-rss-helper was added.
Added property "
ebpf_rss_fds" for "virtio-net" that allows to initialize eBPF RSS context with passed program & maps fds.Added qemu-ebpf-rss-helper - simple helper that loads eBPF context and passes fds through unix socket. Libvirt should call the helper and pass fds to qemu through "
ebpf_rss_fds" property.Added explicit target OS check for libbpf dependency in meson. eBPF RSS works only with Linux TAP, so there is no reason to build eBPF loader/helper for non-Linux.
Changed Qemu updates eBPF maps to array mmaping. Mmaping allows bypassing unprivileged BPF map update. Also, instead of 3 maps (config, key and indirection table) there is one map that combines everything.
Added helper stamp. To check that helper was build with qemu, qemu would check helper symbols that should contain the stamp. It was done similar to qemu modules, but checking was performed by the helper's ELF parsing.
Overall, libvirt process should not be aware of the "interface" of eBPF RSS, it will not be aware of eBPF maps/program "type" and their quantity. That's why qemu and the helper should be from the same build and be "synchronized". Technically each qemu may have its own helper. That's why "query-helper-paths" qmp command was added. Qemu should return the path to the helper that suits and libvirt should use "that" helper for "that" emulator.
qmp sample:
C: { "execute": "query-helper-paths" }
S: { "return": [{ "name": "qemu-ebpf-rss-helper", "path": "/usr/local/libexec/qemu-ebpf-rss-helper" } ]}
Changes since v1:
*Mmap()used instead ifbpf_map_update_elem().
* Added helper stamp.Andrew Melnychenko (5):
ebpf: Added eBPF initialization by fds and map update.
virtio-net: Added property to load eBPF RSS with fds.
qmp: Added the helper stamp check.
ebpf_rss_helper: Added helper for eBPF RSS.
qmp: Added qemu-ebpf-rss-path command.ebpf/ebpf_rss-stub.c | 6 + ebpf/ebpf_rss.c | 120 ++++--- ebpf/ebpf_rss.h | 8 +- ebpf/qemu-ebpf-rss-helper.c | 130 +++++++ ebpf/rss.bpf.skeleton.h | 557 +++++++++++++++--------------- hw/net/virtio-net.c | 77 ++++- include/hw/virtio/virtio-net.h | 1 + meson.build | 47 ++- monitor/meson.build | 1 + monitor/qemu-helper-stamp-utils.c | 297 ++++++++++++++++ monitor/qemu-helper-stamp-utils.h | 24 ++ monitor/qmp-cmds.c | 32 ++ qapi/misc.json | 33 ++ tools/ebpf/rss.bpf.c | 67 ++-- 14 files changed, 990 insertions(+), 410 deletions(-) create mode 100644 ebpf/qemu-ebpf-rss-helper.c create mode 100644 monitor/qemu-helper-stamp-utils.c create mode 100644 monitor/qemu-helper-stamp-utils.h--
2.31.1
Quoted 3 lines · Yuri Benditovich
Jason,
Can you please review the series?
WIll do it this week.
Thanks
Quoted 87 lines
Thanks,
YuriQuoted 81 lines · Andrew Melnichenko
ping
Quoted 77 lines · Andrew Melnychenko
Libvirt usually launches qemu with strict permissions. To enable eBPF RSS steering, qemu-ebpf-rss-helper was added.
Added property "
ebpf_rss_fds" for "virtio-net" that allows to initialize eBPF RSS context with passed program & maps fds.Added qemu-ebpf-rss-helper - simple helper that loads eBPF context and passes fds through unix socket. Libvirt should call the helper and pass fds to qemu through "
ebpf_rss_fds" property.Added explicit target OS check for libbpf dependency in meson. eBPF RSS works only with Linux TAP, so there is no reason to build eBPF loader/helper for non-Linux.
Changed Qemu updates eBPF maps to array mmaping. Mmaping allows bypassing unprivileged BPF map update. Also, instead of 3 maps (config, key and indirection table) there is one map that combines everything.
Added helper stamp. To check that helper was build with qemu, qemu would check helper symbols that should contain the stamp. It was done similar to qemu modules, but checking was performed by the helper's ELF parsing.
Overall, libvirt process should not be aware of the "interface" of eBPF RSS, it will not be aware of eBPF maps/program "type" and their quantity. That's why qemu and the helper should be from the same build and be "synchronized". Technically each qemu may have its own helper. That's why "query-helper-paths" qmp command was added. Qemu should return the path to the helper that suits and libvirt should use "that" helper for "that" emulator.
qmp sample:
C: { "execute": "query-helper-paths" }
S: { "return": [{ "name": "qemu-ebpf-rss-helper", "path": "/usr/local/libexec/qemu-ebpf-rss-helper" } ]}
Changes since v1:
*Mmap()used instead ifbpf_map_update_elem().
* Added helper stamp.Andrew Melnychenko (5):
ebpf: Added eBPF initialization by fds and map update.
virtio-net: Added property to load eBPF RSS with fds.
qmp: Added the helper stamp check.
ebpf_rss_helper: Added helper for eBPF RSS.
qmp: Added qemu-ebpf-rss-path command.ebpf/ebpf_rss-stub.c | 6 + ebpf/ebpf_rss.c | 120 ++++--- ebpf/ebpf_rss.h | 8 +- ebpf/qemu-ebpf-rss-helper.c | 130 +++++++ ebpf/rss.bpf.skeleton.h | 557 +++++++++++++++--------------- hw/net/virtio-net.c | 77 ++++- include/hw/virtio/virtio-net.h | 1 + meson.build | 47 ++- monitor/meson.build | 1 + monitor/qemu-helper-stamp-utils.c | 297 ++++++++++++++++ monitor/qemu-helper-stamp-utils.h | 24 ++ monitor/qmp-cmds.c | 32 ++ qapi/misc.json | 33 ++ tools/ebpf/rss.bpf.c | 67 ++-- 14 files changed, 990 insertions(+), 410 deletions(-) create mode 100644 ebpf/qemu-ebpf-rss-helper.c create mode 100644 monitor/qemu-helper-stamp-utils.c create mode 100644 monitor/qemu-helper-stamp-utils.h--
2.31.1
Quoted 43 lines · Andrew Melnychenko
Libvirt usually launches qemu with strict permissions. To enable eBPF RSS steering, qemu-ebpf-rss-helper was added.
Added property "
ebpf_rss_fds" for "virtio-net" that allows to initialize eBPF RSS context with passed program & maps fds.Added qemu-ebpf-rss-helper - simple helper that loads eBPF context and passes fds through unix socket. Libvirt should call the helper and pass fds to qemu through "
ebpf_rss_fds" property.Added explicit target OS check for libbpf dependency in meson. eBPF RSS works only with Linux TAP, so there is no reason to build eBPF loader/helper for non-Linux.
Changed Qemu updates eBPF maps to array mmaping. Mmaping allows bypassing unprivileged BPF map update. Also, instead of 3 maps (config, key and indirection table) there is one map that combines everything.
Added helper stamp. To check that helper was build with qemu, qemu would check helper symbols that should contain the stamp. It was done similar to qemu modules, but checking was performed by the helper's ELF parsing.
Overall, libvirt process should not be aware of the "interface" of eBPF RSS, it will not be aware of eBPF maps/program "type" and their quantity. That's why qemu and the helper should be from the same build and be "synchronized". Technically each qemu may have its own helper. That's why "query-helper-paths" qmp command was added. Qemu should return the path to the helper that suits and libvirt should use "that" helper for "that" emulator.
qmp sample:
C: { "execute": "query-helper-paths" }
S: { "return": [{ "name": "qemu-ebpf-rss-helper", "path": "/usr/local/libexec/qemu-ebpf-rss-helper" } ] }
Quoted 2 lines
Changes since v1:
*Mmap()used instead ifbpf_map_update_elem().
Some questions:
1) Is the mmap() part a stable ABI?
2) Is there a change that we may use other kinds of bpf map that can be mmaped?
3) What's the advantages of using bpf mmap() over the rx-filter-event?
Thanks
Quoted 28 lines
* Added helper stamp.
Andrew Melnychenko (5):
ebpf: Added eBPF initialization by fds and map update.
virtio-net: Added property to load eBPF RSS with fds.
qmp: Added the helper stamp check.
ebpf_rss_helper: Added helper for eBPF RSS.
qmp: Added qemu-ebpf-rss-path command.ebpf/ebpf_rss-stub.c | 6 + ebpf/ebpf_rss.c | 120 ++++--- ebpf/ebpf_rss.h | 8 +- ebpf/qemu-ebpf-rss-helper.c | 130 +++++++ ebpf/rss.bpf.skeleton.h | 557 +++++++++++++++--------------- hw/net/virtio-net.c | 77 ++++- include/hw/virtio/virtio-net.h | 1 + meson.build | 47 ++- monitor/meson.build | 1 + monitor/qemu-helper-stamp-utils.c | 297 ++++++++++++++++ monitor/qemu-helper-stamp-utils.h | 24 ++ monitor/qmp-cmds.c | 32 ++ qapi/misc.json | 33 ++ tools/ebpf/rss.bpf.c | 67 ++-- 14 files changed, 990 insertions(+), 410 deletions(-)create mode 100644
ebpf/qemu-ebpf-rss-helper.ccreate mode 100644monitor/qemu-helper-stamp-utils.ccreate mode 100644monitor/qemu-helper-stamp-utils.h