diff mbox series

[RFC,v2,1/2] vdpa: Restore packet receive filtering state relative with _F_CTRL_RX_EXTRA feature

Message ID 66ec4d7e3a680de645043d0331ab65940154f2b8.1688365324.git.yin31149@gmail.com (mailing list archive)
State New, archived
Headers show
Series Vhost-vdpa Shadow Virtqueue _F_CTRL_RX_EXTRA commands support | expand

Commit Message

Hawkins Jiawei July 3, 2023, 6:59 a.m. UTC
This patch refactors vhost_vdpa_net_load_rx() to
restore the packet receive filtering state in relation to
VIRTIO_NET_F_CTRL_RX_EXTRA feature at device's startup.

Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
---
v2:
  - avoid sending CVQ command in default state suggested by Eugenio

v1: https://lists.nongnu.org/archive/html/qemu-devel/2023-06/msg04957.html

 net/vhost-vdpa.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)
diff mbox series

Patch

diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 0410a52043..4919e18208 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -890,6 +890,88 @@  static int vhost_vdpa_net_load_rx(VhostVDPAState *s,
         }
     }
 
+    if (virtio_vdev_has_feature(&n->parent_obj, VIRTIO_NET_F_CTRL_RX_EXTRA)) {
+        /* Load the all-unicast mode */
+        on = n->alluni;
+        if (on != 0) {
+            /*
+             * According to virtio_net_reset(), device turns all-unicast mode
+             * off by default.
+             *
+             * Therefore, there is no need to send this CVQ command if the
+             * driver also sets all-unicast mode off, which aligns with
+             * the device's defaults.
+             *
+             * Note that the device's defaults can mismatch the driver's
+             * configuration only at live migration.
+             */
+            r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_ALLUNI, on);
+            if (r < 0) {
+                return r;
+            }
+        }
+
+        /* Load the non-multicast mode */
+        on = n->nomulti;
+        if (on != 0) {
+            /*
+             * According to virtio_net_reset(), device turns non-multicast mode
+             * off by default.
+             *
+             * Therefore, there is no need to send this CVQ command if the
+             * driver also sets non-multicast mode off, which aligns with
+             * the device's defaults.
+             *
+             * Note that the device's defaults can mismatch the driver's
+             * configuration only at live migration.
+             */
+            r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_NOMULTI, on);
+            if (r < 0) {
+                return r;
+            }
+        }
+
+        /* Load the non-unicast mode */
+        on = n->nouni;
+        if (on != 0) {
+            /*
+             * According to virtio_net_reset(), device turns non-unicast mode
+             * off by default.
+             *
+             * Therefore, there is no need to send this CVQ command if the
+             * driver also sets non-unicast mode off, which aligns with
+             * the device's defaults.
+             *
+             * Note that the device's defaults can mismatch the driver's
+             * configuration only at live migration.
+             */
+            r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_NOUNI, on);
+            if (r < 0) {
+                return r;
+            }
+        }
+
+        /* Load the non-broadcast mode */
+        on = n->nobcast;
+        if (on != 0) {
+            /*
+             * According to virtio_net_reset(), device turns non-broadcast mode
+             * off by default.
+             *
+             * Therefore, there is no need to send this CVQ command if the
+             * driver also sets non-broadcast mode off, which aligns with
+             * the device's defaults.
+             *
+             * Note that the device's defaults can mismatch the driver's
+             * configuration only at live migration.
+             */
+            r = vhost_vdpa_net_load_rx_mode(s, VIRTIO_NET_CTRL_RX_NOBCAST, on);
+            if (r < 0) {
+                return r;
+            }
+        }
+    }
+
     return 0;
 }