[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 59/66] vdpa: Restore MAC address filtering state
From: |
Michael S. Tsirkin |
Subject: |
[PULL 59/66] vdpa: Restore MAC address filtering state |
Date: |
Mon, 10 Jul 2023 19:05:14 -0400 |
From: Hawkins Jiawei <yin31149@gmail.com>
This patch refactors vhost_vdpa_net_load_mac() to
restore the MAC address filtering state at device's startup.
Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
Message-Id:
<4b9550c14bc8c98c8f48e04dbf3d3ac41489d3fd.1688743107.git.yin31149@gmail.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
net/vhost-vdpa.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index e192217a96..126afbc7a5 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -666,6 +666,58 @@ static int vhost_vdpa_net_load_mac(VhostVDPAState *s,
const VirtIONet *n)
}
}
+ /*
+ * According to VirtIO standard, "The device MUST have an
+ * empty MAC filtering table on reset.".
+ *
+ * Therefore, there is no need to send this CVQ command if the
+ * driver also sets an empty MAC filter table, which aligns with
+ * the device's defaults.
+ *
+ * Note that the device's defaults can mismatch the driver's
+ * configuration only at live migration.
+ */
+ if (!virtio_vdev_has_feature(&n->parent_obj, VIRTIO_NET_F_CTRL_RX) ||
+ n->mac_table.in_use == 0) {
+ return 0;
+ }
+
+ uint32_t uni_entries = n->mac_table.first_multi,
+ uni_macs_size = uni_entries * ETH_ALEN,
+ mul_entries = n->mac_table.in_use - uni_entries,
+ mul_macs_size = mul_entries * ETH_ALEN;
+ struct virtio_net_ctrl_mac uni = {
+ .entries = cpu_to_le32(uni_entries),
+ };
+ struct virtio_net_ctrl_mac mul = {
+ .entries = cpu_to_le32(mul_entries),
+ };
+ const struct iovec data[] = {
+ {
+ .iov_base = &uni,
+ .iov_len = sizeof(uni),
+ }, {
+ .iov_base = n->mac_table.macs,
+ .iov_len = uni_macs_size,
+ }, {
+ .iov_base = &mul,
+ .iov_len = sizeof(mul),
+ }, {
+ .iov_base = &n->mac_table.macs[uni_macs_size],
+ .iov_len = mul_macs_size,
+ },
+ };
+ ssize_t dev_written = vhost_vdpa_net_load_cmd(s,
+ VIRTIO_NET_CTRL_MAC,
+ VIRTIO_NET_CTRL_MAC_TABLE_SET,
+ data, ARRAY_SIZE(data));
+ if (unlikely(dev_written < 0)) {
+ return dev_written;
+ }
+ if (*s->status != VIRTIO_NET_OK) {
+ return -EIO;
+ }
+
return 0;
}
--
MST
- [PULL 49/66] vdpa: Fix possible use-after-free for VirtQueueElement, (continued)
[PULL 59/66] vdpa: Restore MAC address filtering state,
Michael S. Tsirkin <=
[PULL 57/66] pcie: Specify 0 for ARI next function numbers, Michael S. Tsirkin, 2023/07/10
[PULL 54/66] include/hw/virtio: add kerneldoc for virtio_init, Michael S. Tsirkin, 2023/07/10
[PULL 45/66] hw/pci: warn when PCIe device is plugged into non-zero slot of downstream port, Michael S. Tsirkin, 2023/07/10
[PULL 55/66] include/hw/virtio: document some more usage of notifiers, Michael S. Tsirkin, 2023/07/10
[PULL 60/66] vdpa: Restore packet receive filtering state relative with _F_CTRL_RX feature, Michael S. Tsirkin, 2023/07/10
[PULL 58/66] vdpa: Use iovec for vhost_vdpa_net_load_cmd(), Michael S. Tsirkin, 2023/07/10
[PULL 62/66] vdpa: Accessing CVQ header through its structure, Michael S. Tsirkin, 2023/07/10
[PULL 56/66] pcie: Use common ARI next function number, Michael S. Tsirkin, 2023/07/10
[PULL 61/66] vhost: Fix false positive out-of-bounds, Michael S. Tsirkin, 2023/07/10
[PULL 63/66] vdpa: Avoid forwarding large CVQ command failures, Michael S. Tsirkin, 2023/07/10