Report fatal errors from failure with pre-opened eBPF RSS FDs
cover Report fatal errors from failure with pre-opened eBPF RSS FDs
The virtio-net code for eBPF RSS is still ignoring errors when failing to load the eBPF RSS program passed in by the mgmt app via pre-opened FDs.
This series re-factors the eBPF common code so that it actually reports using "Error" objects. Then it makes virtio-net treat a failure to load pre-opened FDs as a fatal problem. When doing speculative opening of eBPF FDs, QEMU merely prints a warning, and allows the software fallback to continue.
Trace event coverage is significantly expanded to make this all much more debuggable too.
Daniel P. Berrangé (5):
hw/net: fix typo s/epbf/ebpf/ in virtio-net
ebpf: drop redundant parameter checks in static methods
ebpf: add formal error reporting to all APIs hw/net: report errors from failing to use eBPF RSS FDs
ebpf: improve trace event coverage to all key operations
ebpf/ebpf_rss.c | 118 ++++++++++++++++++++++++++++---------------- ebpf/ebpf_rss.h | 10 ++-- ebpf/trace-events | 6 ++- hw/net/virtio-net.c | 53 +++++++++++++------- 4 files changed, 123 insertions(+), 64 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/5 hw/net: fix typo s/epbf/ebpf/ in virtio-net
--- hw/net/virtio-net.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
hw/net/virtio-net.c +5 -5
@@ -1253,7 +1253,7 @@ static void rss_data_to_rss_config(struct VirtioNetRssData *data, config->default_queue = data->default_queue; } -static bool virtio_net_attach_epbf_rss (VirtIONet *n) +static bool virtio_net_attach_ebpf_rss (VirtIONet *n) {struct EBPFRSSConfig config = {};
@@ -1275,7 +1275,7 @@ static bool virtio_net_attach_epbf_rss(VirtIONet *n)return true; } -static void virtio_net_detach_epbf_rss (VirtIONet *n) +static void virtio_net_detach_ebpf_rss (VirtIONet *n) {virtio_net_attach_ebpf_to_backend (n->nic,-1 ); }
@@ -1285,8 +1285,8 @@ static void virtio_net_commit_rss_config(VirtIONet *n)if (n->rss_data.enabled) { n->rss_data.enabled_software_rss = n->rss_data.populate_hash;if (n->rss_data.populate_hash) { -virtio_net_detach_epbf_rss (n); - }else if (!virtio_net_attach_epbf_rss (n)) { +virtio_net_detach_ebpf_rss (n); + }else if (!virtio_net_attach_ebpf_rss (n)) {if (get_vhost_net (qemu_get_queue (n->nic)->peer)) {warn_report ("Can't load eBPF RSS for vhost" ); }else {
@@ -1299,7 +1299,7 @@ static void virtio_net_commit_rss_config(VirtIONet *n) n->rss_data.indirections_len, sizeof(n->rss_data.key)); }else { -virtio_net_detach_epbf_rss (n); +virtio_net_detach_ebpf_rss (n);trace_virtio_net_rss_disable (); } }
Signature · 1 line
2.45.2
Re: [PATCH 1/5] hw/net: fix typo s/epbf/ebpf/ in virtio-net
Quoted 4 lines · Daniel P. Berrangé
Signed-off-by Daniel P. Berrangé <[email protected]>--- hw/net/virtio-net.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
PATCH 2/5 ebpf: drop redundant parameter checks in static methods
In reply to Daniel P. BerrangéVarious static methods have checks on their parameters which were already checked immediately before the method was invoked. Drop these redundat checks to simplify the following commit which adds formal error reporting.
--- ebpf/ebpf_rss.c | 32 +++++--------------------------- 1 file changed, 5 insertions(+), 27 deletions(-)
ebpf/ebpf_rss.c +5 -27
@@ -49,10 +49,6 @@ bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx)static bool ebpf_rss_mmap (struct EBPFRSSContext *ctx) { -if (!ebpf_rss_is_loaded (ctx)) { -return false; - } - ctx->mmap_configuration =mmap (NULL ,qemu_real_host_page_size (),PROT_READ |PROT_WRITE ,MAP_SHARED , ctx->map_configuration,0 );
@@ -90,10 +86,6 @@ toeplitz_fail:static void ebpf_rss_munmap (struct EBPFRSSContext *ctx) { -if (!ebpf_rss_is_loaded (ctx)) { -return ; - } -munmap (ctx->mmap_indirections_table,qemu_real_host_page_size ());munmap (ctx->mmap_toeplitz_key,qemu_real_host_page_size ());munmap (ctx->mmap_configuration,qemu_real_host_page_size ());
@@ -177,15 +169,10 @@ bool ebpf_rss_load_fds(struct EBPFRSSContext *ctx, int program_fd,return true; } -static bool ebpf_rss_set_config (struct EBPFRSSContext *ctx, +static void ebpf_rss_set_config (struct EBPFRSSContext *ctx,struct EBPFRSSConfig *config) { -if (!ebpf_rss_is_loaded (ctx)) { -return false; - } -memcpy (ctx->mmap_configuration, config,sizeof (*config)); -return true; } static bool ebpf_rss_set_indirections_table(struct EBPFRSSContext *ctx,
@@ -194,8 +181,7 @@ static bool ebpf_rss_set_indirections_table(struct EBPFRSSContext *ctx, {char *cursor = ctx->mmap_indirections_table; -if (!ebpf_rss_is_loaded (ctx) || indirections_table ==NULL || - len >VIRTIO_NET_RSS_MAX_TABLE_LEN ) { +if (len >VIRTIO_NET_RSS_MAX_TABLE_LEN ) {return false; }
@@ -207,20 +193,16 @@ static bool ebpf_rss_set_indirections_table(struct EBPFRSSContext *ctx,return true; } -static bool ebpf_rss_set_toepliz_key (struct EBPFRSSContext *ctx, +static void ebpf_rss_set_toepliz_key (struct EBPFRSSContext *ctx,uint8_t *toeplitz_key) {/* prepare toeplitz key */ uint8_t toe[VIRTIO_NET_RSS_MAX_KEY_SIZE ] = {}; -if (!ebpf_rss_is_loaded (ctx) || toeplitz_key ==NULL ) { -return false; - }memcpy (toe, toeplitz_key,VIRTIO_NET_RSS_MAX_KEY_SIZE ); *(uint32_t *)toe =ntohl (*(uint32_t *)toe);memcpy (ctx->mmap_toeplitz_key, toe,VIRTIO_NET_RSS_MAX_KEY_SIZE ); -return true; } bool ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config,
@@ -231,18 +213,14 @@ bool ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config,return false; } -if (!ebpf_rss_set_config (ctx, config)) { -return false; - } +ebpf_rss_set_config (ctx, config);if (!ebpf_rss_set_indirections_table (ctx, indirections_table, config->indirections_len)) {return false; } -if (!ebpf_rss_set_toepliz_key (ctx, toeplitz_key)) { -return false; - } +ebpf_rss_set_toepliz_key (ctx, toeplitz_key);return true; }
Signature · 1 line
2.45.2
PATCH 3/5 ebpf: add formal error reporting to all APIs
In reply to Daniel P. BerrangéThe eBPF code is currently reporting error messages through trace events. Trace events are fine for debugging, but they are not to be considered the primary error reporting mechanism, as their output is inaccessible to callers.
This adds an "Error **errp" parameter to all methods which have important error scenarios to report to the caller.
--- ebpf/ebpf_rss.c | 59 ++++++++++++++++++++++++++++++++++++--------- ebpf/ebpf_rss.h | 10 +++++--- hw/net/virtio-net.c | 7 +++--- 3 files changed, 59 insertions(+), 17 deletions(-)
ebpf/ebpf_rss.c +48 -11
@@ -47,13 +47,14 @@ bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx)return ctx !=NULL && (ctx->obj !=NULL || ctx->program_fd !=-1 ); } -static bool ebpf_rss_mmap (struct EBPFRSSContext *ctx) +static bool ebpf_rss_mmap (struct EBPFRSSContext *ctx,Error **errp) { 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" ); +error_setg (errp,"Unable to map eBPF configuration array" );return false; } ctx->mmap_toeplitz_key = mmap(NULL, qemu_real_host_page_size(),
@@ -61,6 +62,7 @@ static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) ctx->map_toeplitz_key, 0);if (ctx->mmap_toeplitz_key ==MAP_FAILED ) {trace_ebpf_error ("eBPF RSS" ,"can not mmap eBPF toeplitz key" ); +error_setg (errp,"Unable to map eBPF toeplitz array" ); goto toeplitz_fail; } ctx->mmap_indirections_table = mmap(NULL, qemu_real_host_page_size(),
@@ -68,6 +70,7 @@ static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) ctx->map_indirections_table, 0);if (ctx->mmap_indirections_table ==MAP_FAILED ) {trace_ebpf_error ("eBPF RSS" ,"can not mmap eBPF indirection table" ); +error_setg (errp,"Unable to map eBPF indirection array" ); goto indirection_fail; }
@@ -95,7 +98,7 @@ static void ebpf_rss_munmap(struct EBPFRSSContext *ctx) ctx->mmap_indirections_table =NULL ; } -bool ebpf_rss_load (struct EBPFRSSContext *ctx) +bool ebpf_rss_load (struct EBPFRSSContext *ctx,Error **errp) {struct rss_bpf *rss_bpf_ctx;
@@ -106,6 +109,7 @@ bool ebpf_rss_load(struct EBPFRSSContext *ctx) rss_bpf_ctx =rss_bpf__open ();if (rss_bpf_ctx ==NULL ) {trace_ebpf_error ("eBPF RSS" ,"can not open eBPF RSS object" ); +error_setg (errp,"Unable to open eBPF RSS object" ); goto error; }
@@ -113,6 +117,7 @@ bool ebpf_rss_load(struct EBPFRSSContext *ctx)if (rss_bpf__load (rss_bpf_ctx)) {trace_ebpf_error ("eBPF RSS" ,"can not load RSS program" ); +error_setg (errp,"Unable to load eBPF program" ); goto error; }
@@ -126,7 +131,7 @@ bool ebpf_rss_load(struct EBPFRSSContext *ctx) ctx->map_toeplitz_key =bpf_map__fd ( rss_bpf_ctx->maps.tap_rss_map_toeplitz_key); -if (!ebpf_rss_mmap (ctx)) { +if (!ebpf_rss_mmap (ctx, errp)) { goto error; }
@@ -143,13 +148,28 @@ error: }bool ebpf_rss_load_fds (struct EBPFRSSContext *ctx,int program_fd, -int config_fd,int toeplitz_fd,int table_fd) +int config_fd,int toeplitz_fd,int table_fd, +Error **errp) {if (ebpf_rss_is_loaded (ctx)) { +error_setg (errp,"eBPF program is already loaded" );return false; } -if (program_fd <0 || config_fd <0 || toeplitz_fd <0 || table_fd <0 ) { +if (program_fd <0 ) { +error_setg (errp,"eBPF program FD is not open" ); +return false; + } +if (config_fd <0 ) { +error_setg (errp,"eBPF config FD is not open" ); +return false; + } +if (toeplitz_fd <0 ) { +error_setg (errp,"eBPF toeplitz FD is not open" ); +return false; + } +if (table_fd <0 ) { +error_setg (errp,"eBPF indirection FD is not open" );return false; }
@@ -158,7 +178,7 @@ bool ebpf_rss_load_fds(struct EBPFRSSContext *ctx, int program_fd, ctx->map_toeplitz_key = toeplitz_fd; ctx->map_indirections_table = table_fd; -if (!ebpf_rss_mmap (ctx)) { +if (!ebpf_rss_mmap (ctx, errp)) { ctx->program_fd =-1 ; ctx->map_configuration =-1 ; ctx->map_toeplitz_key =-1 ;
@@ -177,11 +197,14 @@ static void ebpf_rss_set_config(struct EBPFRSSContext *ctx,static bool ebpf_rss_set_indirections_table (struct EBPFRSSContext *ctx,uint16_t *indirections_table, -size_t len) +size_t len, +Error **errp) {char *cursor = ctx->mmap_indirections_table;if (len >VIRTIO_NET_RSS_MAX_TABLE_LEN ) { +error_setg (errp,"Indirections table length %zu exceeds limit %d" , + len,VIRTIO_NET_RSS_MAX_TABLE_LEN );return false; }
@@ -206,17 +229,31 @@ static void ebpf_rss_set_toepliz_key(struct EBPFRSSContext *ctx, }bool ebpf_rss_set_all (struct EBPFRSSContext *ctx,struct EBPFRSSConfig *config, -uint16_t *indirections_table,uint8_t *toeplitz_key) +uint16_t *indirections_table,uint8_t *toeplitz_key, +Error **errp) { -if (!ebpf_rss_is_loaded (ctx) || config ==NULL || - indirections_table ==NULL || toeplitz_key ==NULL ) { +if (!ebpf_rss_is_loaded (ctx)) { +error_setg (errp,"eBPF program is not loaded" ); +return false; + } +if (config ==NULL ) { +error_setg (errp,"eBPF config table is NULL" ); +return false; + } +if (indirections_table ==NULL ) { +error_setg (errp,"eBPF indirections table is NULL" ); +return false; + } +if (toeplitz_key ==NULL ) { +error_setg (errp,"eBPF toeplitz key is NULL" );return false; }ebpf_rss_set_config (ctx, config);if (!ebpf_rss_set_indirections_table (ctx, indirections_table, - config->indirections_len)) { + config->indirections_len, + errp)) {return false; }
ebpf/ebpf_rss.h +7 -3
@@ -14,6 +14,8 @@#ifndef QEMU_EBPF_RSS_H #define QEMU_EBPF_RSS_H +#include "qapi/error.h" +#define EBPF_RSS_MAX_FDS 4 struct EBPFRSSContext {
@@ -41,13 +43,15 @@ void ebpf_rss_init(struct EBPFRSSContext *ctx);bool ebpf_rss_is_loaded (struct EBPFRSSContext *ctx); -bool ebpf_rss_load (struct EBPFRSSContext *ctx); +bool ebpf_rss_load (struct EBPFRSSContext *ctx,Error **errp);bool ebpf_rss_load_fds (struct EBPFRSSContext *ctx,int program_fd, -int config_fd,int toeplitz_fd,int table_fd); +int config_fd,int toeplitz_fd,int table_fd, +Error **errp);bool ebpf_rss_set_all (struct EBPFRSSContext *ctx,struct EBPFRSSConfig *config, -uint16_t *indirections_table,uint8_t *toeplitz_key); +uint16_t *indirections_table,uint8_t *toeplitz_key, +Error **errp);void ebpf_rss_unload (struct EBPFRSSContext *ctx);
hw/net/virtio-net.c +4 -3
@@ -1264,7 +1264,8 @@ static bool virtio_net_attach_ebpf_rss(VirtIONet *n)rss_data_to_rss_config (&n->rss_data, &config);if (!ebpf_rss_set_all (&n->ebpf_rss, &config, - n->rss_data.indirections_table, n->rss_data.key)) { + n->rss_data.indirections_table, n->rss_data.key, +NULL )) {return false; }
@@ -1335,7 +1336,7 @@ static bool virtio_net_load_ebpf_fds(VirtIONet *n) } } - ret =ebpf_rss_load_fds (&n->ebpf_rss, fds[0 ], fds[1 ], fds[2 ], fds[3 ]); + ret =ebpf_rss_load_fds (&n->ebpf_rss, fds[0 ], fds[1 ], fds[2 ], fds[3 ],NULL ); exit:if (!ret) {
@@ -1353,7 +1354,7 @@ static bool virtio_net_load_ebpf(VirtIONet *n)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); + ret =ebpf_rss_load (&n->ebpf_rss,NULL ); } }
Signature · 1 line
2.45.2
Re: [PATCH 3/5] ebpf: add formal error reporting to all APIs
Quoted 44 lines · Daniel P. Berrangé
The eBPF code is currently reporting error messages through trace events. Trace events are fine for debugging, but they are not to be considered the primary error reporting mechanism, as their output is inaccessible to callers.
This adds an "Error **errp" parameter to all methods which have important error scenarios to report to the caller.
Signed-off-by Daniel P. Berrangé <[email protected]>--- ebpf/ebpf_rss.c | 59 ++++++++++++++++++++++++++++++++++++--------- ebpf/ebpf_rss.h | 10 +++++--- hw/net/virtio-net.c | 7 +++--- 3 files changed, 59 insertions(+), 17 deletions(-)ebpf/ebpf_rss.c +3
-1@@ -47,13 +47,14 @@ bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx)return ctx !=NULL && (ctx->obj !=NULL || ctx->program_fd !=-1 ); } -static bool ebpf_rss_mmap (struct EBPFRSSContext *ctx) +static bool ebpf_rss_mmap (struct EBPFRSSContext *ctx,Error **errp) { 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" ); +error_setg (errp,"Unable to map eBPF configuration array" );return false; } ctx->mmap_toeplitz_key = mmap(NULL, qemu_real_host_page_size(),@@ -61,6 +62,7 @@ static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) ctx->map_toeplitz_key, 0);if (ctx->mmap_toeplitz_key ==MAP_FAILED ) {trace_ebpf_error ("eBPF RSS" ,"can not mmap eBPF toeplitz key" ); +error_setg (errp,"Unable to map eBPF toeplitz array" ); goto toeplitz_fail; } ctx->mmap_indirections_table = mmap(NULL, qemu_real_host_page_size(),
ebpf/ebpf_rss.c static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) · line 73
Quoted 4 lines
ebpf/ebpf_rss.c +1
-0@@ -68,6 +70,7 @@ static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) ctx->map_indirections_table, 0);if (ctx->mmap_indirections_table ==MAP_FAILED ) {trace_ebpf_error ("eBPF RSS" ,"can not mmap eBPF indirection table" ); +error_setg (errp,"Unable to map eBPF indirection array" );
Aren't these trace_ebpf_error() calls redundant now?
Quoted 2 lines
ebpf/ebpf_rss.c +0
-0goto indirection_fail; }
Re: [PATCH 3/5] ebpf: add formal error reporting to all APIs
Quoted 42 lines · Philippe Mathieu-Daudé
Quoted 41 lines · Daniel P. Berrangé
The eBPF code is currently reporting error messages through trace events. Trace events are fine for debugging, but they are not to be considered the primary error reporting mechanism, as their output is inaccessible to callers.
This adds an "Error **errp" parameter to all methods which have important error scenarios to report to the caller.
Signed-off-by Daniel P. Berrangé <[email protected]>--- ebpf/ebpf_rss.c | 59 ++++++++++++++++++++++++++++++++++++--------- ebpf/ebpf_rss.h | 10 +++++--- hw/net/virtio-net.c | 7 +++--- 3 files changed, 59 insertions(+), 17 deletions(-)ebpf/ebpf_rss.c +3
-1@@ -47,13 +47,14 @@ bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx)return ctx !=NULL && (ctx->obj !=NULL || ctx->program_fd !=-1 ); } -static bool ebpf_rss_mmap (struct EBPFRSSContext *ctx) +static bool ebpf_rss_mmap (struct EBPFRSSContext *ctx,Error **errp) { 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" ); +error_setg (errp,"Unable to map eBPF configuration array" );return false; } ctx->mmap_toeplitz_key = mmap(NULL, qemu_real_host_page_size(),@@ -61,6 +62,7 @@ static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) ctx->map_toeplitz_key, 0);if (ctx->mmap_toeplitz_key ==MAP_FAILED ) {trace_ebpf_error ("eBPF RSS" ,"can not mmap eBPF toeplitz key" ); +error_setg (errp,"Unable to map eBPF toeplitz array" ); goto toeplitz_fail; }
Quoted 8 lines
ebpf/ebpf_rss.c static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) · line 73
Quoted 6 lines
ebpf/ebpf_rss.c +1
-0ctx->mmap_indirections_table = mmap(NULL, qemu_real_host_page_size(),@@ -68,6 +70,7 @@ static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) ctx->map_indirections_table, 0);if (ctx->mmap_indirections_table ==MAP_FAILED ) {trace_ebpf_error ("eBPF RSS" ,"can not mmap eBPF indirection table" ); +error_setg (errp,"Unable to map eBPF indirection array" );Aren't these
trace_ebpf_error()calls redundant now?
Yes & no. Errors propagated up the call stack don't get included in any trace output, and so if a caller doesn't log them anywhere they can thus be invisible to someone just looking at trace output.
I could remove them all from the eBPF code though, and put a single trace event in the hw/net/virtio-net.c file instead ? Bit of a bike shed colouring exercise to decide which is best though.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH 3/5] ebpf: add formal error reporting to all APIs
Quoted 52 lines · Daniel P. Berrangé
Quoted 42 lines · Philippe Mathieu-Daudé
Quoted 41 lines · Daniel P. Berrangé
The eBPF code is currently reporting error messages through trace events. Trace events are fine for debugging, but they are not to be considered the primary error reporting mechanism, as their output is inaccessible to callers.
This adds an "Error **errp" parameter to all methods which have important error scenarios to report to the caller.
Signed-off-by Daniel P. Berrangé <[email protected]>--- ebpf/ebpf_rss.c | 59 ++++++++++++++++++++++++++++++++++++--------- ebpf/ebpf_rss.h | 10 +++++--- hw/net/virtio-net.c | 7 +++--- 3 files changed, 59 insertions(+), 17 deletions(-)ebpf/ebpf_rss.c +3
-1@@ -47,13 +47,14 @@ bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx)return ctx !=NULL && (ctx->obj !=NULL || ctx->program_fd !=-1 ); } -static bool ebpf_rss_mmap (struct EBPFRSSContext *ctx) +static bool ebpf_rss_mmap (struct EBPFRSSContext *ctx,Error **errp) { 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" ); +error_setg (errp,"Unable to map eBPF configuration array" );return false; } ctx->mmap_toeplitz_key = mmap(NULL, qemu_real_host_page_size(),@@ -61,6 +62,7 @@ static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) ctx->map_toeplitz_key, 0);if (ctx->mmap_toeplitz_key ==MAP_FAILED ) {trace_ebpf_error ("eBPF RSS" ,"can not mmap eBPF toeplitz key" ); +error_setg (errp,"Unable to map eBPF toeplitz array" ); goto toeplitz_fail; }Quoted 8 lines
ebpf/ebpf_rss.c static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) · line 73
Quoted 6 lines
ebpf/ebpf_rss.c +1
-0ctx->mmap_indirections_table = mmap(NULL, qemu_real_host_page_size(),@@ -68,6 +70,7 @@ static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) ctx->map_indirections_table, 0);if (ctx->mmap_indirections_table ==MAP_FAILED ) {trace_ebpf_error ("eBPF RSS" ,"can not mmap eBPF indirection table" ); +error_setg (errp,"Unable to map eBPF indirection array" );Aren't these
trace_ebpf_error()calls redundant now?
Quoted 7 lines
Yes & no. Errors propagated up the call stack don't get included in any trace output, and so if a caller doesn't log them anywhere they can thus be invisible to someone just looking at trace output.
I could remove them all from the eBPF code though, and put a single trace event in the
hw/net/virtio-net.cfile instead ? Bit of a bike shed colouring exercise to decide which is best though.
No problem, I'm fine with this patch.
Note from experience (although pre-existing in this patch), trace events can be very verbose, and a what makes them powerful is we can filter particular ones. The following pattern isn't practical to filter:
trace_foo_error(const char *error_msg);
While a bit tedious to add, having a single trace event per error is way more useful.
Regards,
Phil.
Re: [PATCH 3/5] ebpf: add formal error reporting to all APIs
Quoted 63 lines · Philippe Mathieu-Daudé
Quoted 54 lines · Daniel P. Berrangé
Quoted 44 lines · Philippe Mathieu-Daudé
Quoted 43 lines · Daniel P. Berrangé
The eBPF code is currently reporting error messages through trace events. Trace events are fine for debugging, but they are not to be considered the primary error reporting mechanism, as their output is inaccessible to callers.
This adds an "Error **errp" parameter to all methods which have important error scenarios to report to the caller.
Signed-off-by Daniel P. Berrangé <[email protected]>---
ebpf/ebpf_rss.c | 59
++++++++++++++++++++++++++++++++++++---------
ebpf/ebpf_rss.h | 10 +++++---
hw/net/virtio-net.c| 7 +++---3 files changed, 59 insertions(+), 17 deletions(-)ebpf/ebpf_rss.c +0
-0@@ -47,13 +47,14 @@ bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx)return ctx != NULL && (
ctx->obj!= NULL ||ctx->program_fd!= -1);
}ebpf/ebpf_rss.c +1
-1-static bool ebpf_rss_mmap (struct EBPFRSSContext *ctx) +static bool ebpf_rss_mmap (struct EBPFRSSContext *ctx,Error **errp){
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"); +error_setg(errp, "Unable to map eBPF configuration array"); return false;
}
ctx->mmap_toeplitz_key= mmap(NULL,qemu_real_host_page_size(),ebpf/ebpf_rss.c +1
-0@@ -61,6 +62,7 @@ static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) ctx->map_toeplitz_key, 0); if (ctx->mmap_toeplitz_key == MAP_FAILED) { trace_ebpf_error("eBPF RSS", "can not mmap eBPF toeplitz key"); + error_setg(errp, "Unable to map eBPF toeplitz array"); goto toeplitz_fail; }Quoted 8 lines
ebpf/ebpf_rss.c static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) · line 73
Quoted 6 lines
ebpf/ebpf_rss.c +1
-0ctx->mmap_indirections_table = mmap(NULL, qemu_real_host_page_size(),@@ -68,6 +70,7 @@ static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) ctx->map_indirections_table, 0); if (ctx->mmap_indirections_table == MAP_FAILED) { trace_ebpf_error("eBPF RSS", "can not mmap eBPF indirection table"); + error_setg(errp, "Unable to map eBPF indirection array");Aren't these
trace_ebpf_error()calls redundant now?Quoted 7 lines
Yes & no. Errors propagated up the call stack don't get included in any trace output, and so if a caller doesn't log them anywhere they can thus be invisible to someone just looking at trace output.
I could remove them all from the eBPF code though, and put a single trace event in the
hw/net/virtio-net.cfile instead ? Bit of a bike shed colouring exercise to decide which is best though.
Quoted 8 lines
No problem, I'm fine with this patch.
Note from experience (although pre-existing in this patch), trace events can be very verbose, and a what makes them powerful is we can filter particular ones. The following pattern isn't practical to filter:
trace_foo_error(const char *error_msg);
I guess I meant:
trace_foo_error(const char *const error_msg);
(where the string is known at build time).
Quoted 6 lines
While a bit tedious to add, having a single trace event per error is way more useful.
Regards,
Phil.
Re: [PATCH 3/5] ebpf: add formal error reporting to all APIs
In reply to Philippe Mathieu-DaudéQuoted 68 lines · Philippe Mathieu-Daudé
Quoted 52 lines · Daniel P. Berrangé
Quoted 42 lines · Philippe Mathieu-Daudé
Quoted 41 lines · Daniel P. Berrangé
The eBPF code is currently reporting error messages through trace events. Trace events are fine for debugging, but they are not to be considered the primary error reporting mechanism, as their output is inaccessible to callers.
This adds an "Error **errp" parameter to all methods which have important error scenarios to report to the caller.
Signed-off-by Daniel P. Berrangé <[email protected]>--- ebpf/ebpf_rss.c | 59 ++++++++++++++++++++++++++++++++++++--------- ebpf/ebpf_rss.h | 10 +++++--- hw/net/virtio-net.c | 7 +++--- 3 files changed, 59 insertions(+), 17 deletions(-)ebpf/ebpf_rss.c +3
-1@@ -47,13 +47,14 @@ bool ebpf_rss_is_loaded(struct EBPFRSSContext *ctx)return ctx !=NULL && (ctx->obj !=NULL || ctx->program_fd !=-1 ); } -static bool ebpf_rss_mmap (struct EBPFRSSContext *ctx) +static bool ebpf_rss_mmap (struct EBPFRSSContext *ctx,Error **errp) { 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" ); +error_setg (errp,"Unable to map eBPF configuration array" );return false; } ctx->mmap_toeplitz_key = mmap(NULL, qemu_real_host_page_size(),@@ -61,6 +62,7 @@ static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) ctx->map_toeplitz_key, 0);if (ctx->mmap_toeplitz_key ==MAP_FAILED ) {trace_ebpf_error ("eBPF RSS" ,"can not mmap eBPF toeplitz key" ); +error_setg (errp,"Unable to map eBPF toeplitz array" ); goto toeplitz_fail; }Quoted 8 lines
ebpf/ebpf_rss.c static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) · line 73
Quoted 6 lines
ebpf/ebpf_rss.c +1
-0ctx->mmap_indirections_table = mmap(NULL, qemu_real_host_page_size(),@@ -68,6 +70,7 @@ static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx) ctx->map_indirections_table, 0);if (ctx->mmap_indirections_table ==MAP_FAILED ) {trace_ebpf_error ("eBPF RSS" ,"can not mmap eBPF indirection table" ); +error_setg (errp,"Unable to map eBPF indirection array" );Aren't these
trace_ebpf_error()calls redundant now?Quoted 7 lines
Yes & no. Errors propagated up the call stack don't get included in any trace output, and so if a caller doesn't log them anywhere they can thus be invisible to someone just looking at trace output.
I could remove them all from the eBPF code though, and put a single trace event in the
hw/net/virtio-net.cfile instead ? Bit of a bike shed colouring exercise to decide which is best though.No problem, I'm fine with this patch.
Note from experience (although pre-existing in this patch), trace events can be very verbose, and a what makes them powerful is we can filter particular ones. The following pattern isn't practical to filter:
Quoted 4 lines
trace_foo_error(const char *error_msg);While a bit tedious to add, having a single trace event per error is way more useful.
Yeah, I agree with you on that. I should look at changing it to add distinct error probes.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH 4/5 hw/net: report errors from failing to use eBPF RSS FDs
In reply to Daniel P. BerrangéIf the user/mgmt app passed in a set of pre-opened FDs for eBPF RSS, then it is expecting QEMU to use them. Any failure to do so must be considered a fatal error and propagated back up the stack, otherwise deployment mistakes will not be detectable in a prompt manner. When not using pre-opened FDs, then eBPF RSS is tried on a "best effort" basis only and thus fallback to software RSS is valid.
--- hw/net/virtio-net.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-)
hw/net/virtio-net.c +28 -12
@@ -1315,28 +1315,27 @@ static void virtio_net_disable_rss(VirtIONet *n)virtio_net_commit_rss_config (n); } -static bool virtio_net_load_ebpf_fds (VirtIONet *n) +static bool virtio_net_load_ebpf_fds (VirtIONet *n,Error **errp) {int fds[EBPF_RSS_MAX_FDS ] = { [0 ...EBPF_RSS_MAX_FDS -1 ] =-1 };int ret = true;int i =0 ;if (n->nr_ebpf_rss_fds !=EBPF_RSS_MAX_FDS ) { -warn_report ("Expected %d file descriptors but got %d" , -EBPF_RSS_MAX_FDS , n->nr_ebpf_rss_fds); -return false; - } +error_setg (errp,"Expected %d file descriptors but got %d" , +EBPF_RSS_MAX_FDS , n->nr_ebpf_rss_fds); +return false; + }for (i =0 ; i < n->nr_ebpf_rss_fds; i++) { - fds[i] =monitor_fd_param (monitor_cur (), n->ebpf_rss_fds[i], - &error_warn); + fds[i] =monitor_fd_param (monitor_cur (), n->ebpf_rss_fds[i], errp);if (fds[i] <0 ) { ret = false; goto exit; } } - ret =ebpf_rss_load_fds (&n->ebpf_rss, fds[0 ], fds[1 ], fds[2 ], fds[3 ],NULL ); + ret =ebpf_rss_load_fds (&n->ebpf_rss, fds[0 ], fds[1 ], fds[2 ], fds[3 ], errp); exit:if (!ret) {
@@ -1348,13 +1347,15 @@ exit:return ret; } -static bool virtio_net_load_ebpf (VirtIONet *n) +static bool virtio_net_load_ebpf (VirtIONet *n,Error **errp) {bool ret = false;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,NULL ); +if (n->ebpf_rss_fds) { + ret =virtio_net_load_ebpf_fds (n, errp); + }else { + ret =ebpf_rss_load (&n->ebpf_rss, errp); } }
@@ -3760,7 +3761,22 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)net_rx_pkt_init (&n->rx_pkt);if (virtio_has_feature (n->host_features,VIRTIO_NET_F_RSS )) { -virtio_net_load_ebpf (n); +Error *err =NULL ; +if (!virtio_net_load_ebpf (n, &err)) { +/* +* If user explicitly gave QEMU RSS FDs to use, then +* failing to use them must be considered a fatal +* error. If no RSS FDs were provided, QEMU is trying +* eBPF on a "best effort" basis only, so report a +* warning and allow fallback to software RSS. +*/ +if (n->ebpf_rss_fds) { +error_propagate (errp, err); + }else { +warn_report ("unable to load eBPF RSS: %s" ,error_get_pretty (err)); +error_free (err); + } + } } }
Signature · 1 line
2.45.2
PATCH 5/5 ebpf: improve trace event coverage to all key operations
In reply to Daniel P. BerrangéThe existing error trace event is renamed to have a name prefix matching its source file & to remove the redundant first arg that adds no useful information.
--- ebpf/ebpf_rss.c | 29 ++++++++++++++++++++++++----- ebpf/trace-events | 6 +++++- 2 files changed, 29 insertions(+), 6 deletions(-)
ebpf/ebpf_rss.c +24 -5
@@ -53,7 +53,7 @@ static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx, Error **errp)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" ); +trace_ebpf_rss_error (ctx,"can not mmap eBPF configuration array" );error_setg (errp,"Unable to map eBPF configuration array" );return false; }
@@ -61,7 +61,7 @@ static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx, Error **errp)PROT_READ |PROT_WRITE ,MAP_SHARED , ctx->map_toeplitz_key, 0);if (ctx->mmap_toeplitz_key ==MAP_FAILED ) { -trace_ebpf_error ("eBPF RSS" ,"can not mmap eBPF toeplitz key" ); +trace_ebpf_rss_error (ctx,"can not mmap eBPF toeplitz key" );error_setg (errp,"Unable to map eBPF toeplitz array" ); goto toeplitz_fail; }
@@ -69,11 +69,15 @@ static bool ebpf_rss_mmap(struct EBPFRSSContext *ctx, Error **errp)PROT_READ |PROT_WRITE ,MAP_SHARED , ctx->map_indirections_table, 0);if (ctx->mmap_indirections_table ==MAP_FAILED ) { -trace_ebpf_error ("eBPF RSS" ,"can not mmap eBPF indirection table" ); +trace_ebpf_rss_error (ctx,"can not mmap eBPF indirection table" );error_setg (errp,"Unable to map eBPF indirection array" ); goto indirection_fail; } +trace_ebpf_rss_mmap (ctx, + ctx->mmap_configuration, + ctx->mmap_toeplitz_key, + ctx->mmap_indirections_table);return true; indirection_fail:
@@ -108,7 +112,7 @@ bool ebpf_rss_load(struct EBPFRSSContext *ctx, Error **errp) rss_bpf_ctx =rss_bpf__open ();if (rss_bpf_ctx ==NULL ) { -trace_ebpf_error ("eBPF RSS" ,"can not open eBPF RSS object" ); +trace_ebpf_rss_error (ctx,"can not open eBPF RSS object" );error_setg (errp,"Unable to open eBPF RSS object" ); goto error; }
@@ -116,7 +120,7 @@ bool ebpf_rss_load(struct EBPFRSSContext *ctx, Error **errp)bpf_program__set_type (rss_bpf_ctx->progs.tun_rss_steering_prog,BPF_PROG_TYPE_SOCKET_FILTER );if (rss_bpf__load (rss_bpf_ctx)) { -trace_ebpf_error ("eBPF RSS" ,"can not load RSS program" ); +trace_ebpf_rss_error (ctx,"can not load RSS program" );error_setg (errp,"Unable to load eBPF program" ); goto error; }
@@ -131,6 +135,11 @@ bool ebpf_rss_load(struct EBPFRSSContext *ctx, Error **errp) ctx->map_toeplitz_key =bpf_map__fd ( rss_bpf_ctx->maps.tap_rss_map_toeplitz_key); +trace_ebpf_rss_load (ctx, + ctx->program_fd, + ctx->map_configuration, + ctx->map_indirections_table, + ctx->map_toeplitz_key);if (!ebpf_rss_mmap (ctx, errp)) { goto error; }
@@ -178,6 +187,12 @@ bool ebpf_rss_load_fds(struct EBPFRSSContext *ctx, int program_fd, ctx->map_toeplitz_key = toeplitz_fd; ctx->map_indirections_table = table_fd; +trace_ebpf_rss_load (ctx, + ctx->program_fd, + ctx->map_configuration, + ctx->map_indirections_table, + ctx->map_toeplitz_key); +if (!ebpf_rss_mmap (ctx, errp)) { ctx->program_fd =-1 ; ctx->map_configuration =-1 ;
@@ -259,6 +274,8 @@ bool ebpf_rss_set_all(struct EBPFRSSContext *ctx, struct EBPFRSSConfig *config,ebpf_rss_set_toepliz_key (ctx, toeplitz_key); +trace_ebpf_rss_set_data (ctx, config, indirections_table, toeplitz_key); +return true; }
@@ -268,6 +285,8 @@ void ebpf_rss_unload(struct EBPFRSSContext *ctx)return ; } +trace_ebpf_rss_unload (ctx); +ebpf_rss_munmap (ctx);if (ctx->obj) {
ebpf/trace-events +5 -1
@@ -1,4 +1,8 @@ # See docs/devel/tracing.rst for syntax documentation. # ebpf-rss.c -ebpf_error(const char *s1, const char *s2) "error in %s: %s" +ebpf_rss_error(void *ctx, const char *s) "ctx=%p error=%s" +ebpf_rss_load(void *ctx, int progfd, int cfgfd, int toepfd, int indirfd) "ctx=%p program-fd=%d config-fd=%d toeplitz-fd=%d indirection-fd=%d" +ebpf_rss_mmap(void *ctx, void *cfgptr, void *toepptr, void *indirptr) "ctx=%p config-ptr=%p toeplitz-ptr=%p indirection-ptr=%p" +ebpf_rss_unload(void *ctx) "rss unload ctx=%p" +ebpf_rss_set_data(void *ctx, void *cfgptr, void *toepptr, void *indirptr) "ctx=%p config-ptr=%p toeplitz-ptr=%p indirection-ptr=%p"
Signature · 1 line
2.45.2