From: Hawkins Jiawei <yin31149@gmail.com>
To: jasowang@redhat.com, mst@redhat.com, eperezma@redhat.com
Cc: qemu-devel@nongnu.org, yin31149@gmail.com, 18801353760@163.com
Subject: [PATCH RFC 1/3] vdpa: Restore MAC address filtering state
Date: Thu, 22 Jun 2023 11:01:42 +0800 [thread overview]
Message-ID: <00f72fe154a882fd6dc15bc39e3a1ac63f9dadce.1687402580.git.yin31149@gmail.com> (raw)
In-Reply-To: <cover.1687402580.git.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>
---
net/vhost-vdpa.c | 39 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index ecfa8852b5..10264d3e96 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -651,8 +651,45 @@ static int vhost_vdpa_net_load_mac(VhostVDPAState *s, const VirtIONet *n)
if (unlikely(dev_written < 0)) {
return dev_written;
}
+ if (*s->status != VIRTIO_NET_OK) {
+ return -EINVAL;
+ }
+ }
+
+ if (virtio_vdev_has_feature(&n->parent_obj, VIRTIO_NET_F_CTRL_RX)) {
+ /* Load the MAC address filtering */
+ uint32_t uni_entries = n->mac_table.first_multi,
+ uni_macs_size = uni_entries * ETH_ALEN,
+ uni_size = sizeof(struct virtio_net_ctrl_mac) + uni_macs_size,
+ mul_entries = n->mac_table.in_use - uni_entries,
+ mul_macs_size = mul_entries * ETH_ALEN,
+ mul_size = sizeof(struct virtio_net_ctrl_mac) + mul_macs_size,
+ data_size = uni_size + mul_size;
+ void *data = g_malloc(data_size);
+ struct virtio_net_ctrl_mac *ctrl_mac;
+
+ /* Pack the non-multicast(unicast) MAC addresses */
+ ctrl_mac = data;
+ ctrl_mac->entries = cpu_to_le32(uni_entries);
+ memcpy(ctrl_mac->macs, n->mac_table.macs, uni_macs_size);
+
+ /* Pack the multicast MAC addresses */
+ ctrl_mac = data + uni_size;
+ ctrl_mac->entries = cpu_to_le32(mul_entries);
+ memcpy(ctrl_mac->macs, &n->mac_table.macs[uni_macs_size],
+ mul_macs_size);
+
+ ssize_t dev_written = vhost_vdpa_net_load_cmd(s, VIRTIO_NET_CTRL_MAC,
+ VIRTIO_NET_CTRL_MAC_TABLE_SET,
+ data, data_size);
+ g_free(data);
- return *s->status != VIRTIO_NET_OK;
+ if (unlikely(dev_written < 0)) {
+ return dev_written;
+ }
+ if (*s->status != VIRTIO_NET_OK) {
+ return -EINVAL;
+ }
}
return 0;
--
2.25.1
next prev parent reply other threads:[~2023-06-22 3:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-22 3:01 [PATCH RFC 0/3] Vhost-vdpa Shadow Virtqueue _F_CTRL_RX commands support Hawkins Jiawei
2023-06-22 3:01 ` Hawkins Jiawei [this message]
2023-06-25 10:37 ` [PATCH RFC 1/3] vdpa: Restore MAC address filtering state Eugenio Perez Martin
2023-06-26 8:40 ` Hawkins Jiawei
2023-06-22 3:01 ` [PATCH RFC 2/3] vdpa: Restore packet receive filtering state relative with _F_CTRL_RX feature Hawkins Jiawei
2023-06-25 10:56 ` Eugenio Perez Martin
2023-06-26 8:52 ` Hawkins Jiawei
2023-06-22 3:01 ` [PATCH RFC 3/3] vdpa: Allow VIRTIO_NET_F_CTRL_RX in SVQ Hawkins Jiawei
2023-06-25 10:51 ` Eugenio Perez Martin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=00f72fe154a882fd6dc15bc39e3a1ac63f9dadce.1687402580.git.yin31149@gmail.com \
--to=yin31149@gmail.com \
--cc=18801353760@163.com \
--cc=eperezma@redhat.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).