diff mbox series

[v2,4/4] virtio-net: Remove fallback from ebpf-rss-fds

Message ID 20240708-auto-v2-4-f4908b953f05@daynix.com (mailing list archive)
State New, archived
Headers show
Series virtio-net: Convert feature properties to OnOffAuto | expand

Commit Message

Akihiko Odaki July 8, 2024, 7:38 a.m. UTC
If ebpf-rss-fds is specified but we fail to use, we should not fall
back to loading eBPF programs by ourselves as such makes the situation
complicated.

Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
 hw/net/virtio-net.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

Comments

Daniel P. Berrangé July 10, 2024, 2:16 p.m. UTC | #1
On Mon, Jul 08, 2024 at 04:38:09PM +0900, Akihiko Odaki wrote:
> If ebpf-rss-fds is specified but we fail to use, we should not fall
> back to loading eBPF programs by ourselves as such makes the situation
> complicated.
> 
> Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
> ---
>  hw/net/virtio-net.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index e779ba2df428..075c91f037d1 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -1396,15 +1396,9 @@ exit:
>  
>  static bool virtio_net_load_ebpf(VirtIONet *n)
>  {
> -    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);
> -        }
> -    }
> -
> -    return ret;
> +    return virtio_net_attach_ebpf_to_backend(n->nic, -1) &&
> +           (n->ebpf_rss_fds ? virtio_net_load_ebpf_fds(n) :
> +                              ebpf_rss_load(&n->ebpf_rss));
>  }
>  
>  static void virtio_net_unload_ebpf(VirtIONet *n)

The eventual caller has an Error object that needs to be filled with
error details, not warn_report().

IMHO this patch needs to look like this:


diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 9c7e85caea..c7fd52bbe9 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1314,21 +1314,21 @@ 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);
+                                  errp);
         if (fds[i] < 0) {
             ret = false;
             goto exit;
@@ -1347,14 +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))) {
+        if (n->ebpf_rss_fds)
+            ret = virtio_net_load_ebpf_fds(n, errp);
+        else
             ret = ebpf_rss_load(&n->ebpf_rss);
-        }
     }
 
     return ret;
@@ -3750,7 +3751,7 @@ 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);
+        virtio_net_load_ebpf(n, errp);
     }
 }
 

With regards,
Daniel
diff mbox series

Patch

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index e779ba2df428..075c91f037d1 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -1396,15 +1396,9 @@  exit:
 
 static bool virtio_net_load_ebpf(VirtIONet *n)
 {
-    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);
-        }
-    }
-
-    return ret;
+    return virtio_net_attach_ebpf_to_backend(n->nic, -1) &&
+           (n->ebpf_rss_fds ? virtio_net_load_ebpf_fds(n) :
+                              ebpf_rss_load(&n->ebpf_rss));
 }
 
 static void virtio_net_unload_ebpf(VirtIONet *n)