From: Eugenio Perez Martin <eperezma@redhat.com>
To: Hawkins Jiawei <yin31149@gmail.com>
Cc: jasowang@redhat.com, mst@redhat.com, qemu-devel@nongnu.org,
18801353760@163.com
Subject: Re: [PATCH RFC 1/3] vdpa: Restore MAC address filtering state
Date: Sun, 25 Jun 2023 12:37:05 +0200 [thread overview]
Message-ID: <CAJaqyWcS+WN4vyKb4gNLarUsFKbt3hgQ5e9vDe2bGWSz3bue2g@mail.gmail.com> (raw)
In-Reply-To: <00f72fe154a882fd6dc15bc39e3a1ac63f9dadce.1687402580.git.yin31149@gmail.com>
On Thu, Jun 22, 2023 at 5:02 AM Hawkins Jiawei <yin31149@gmail.com> wrote:
>
> 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;
> + }
I think this part should go in its individual patch, explaining why it
is needed and with corresponding Fixes tag.
> + }
> +
> + 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);
If we keep this part, please use g_autofree here [1].
But I think it is not worth copying all the data actually. Maybe it is
worth it to convert vhost_vdpa_net_load_cmd to const iovec?
Thanks!
[1] https://www.qemu.org/docs/master/devel/style#automatic-memory-deallocation
> + 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-25 10:38 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 ` [PATCH RFC 1/3] vdpa: Restore MAC address filtering state Hawkins Jiawei
2023-06-25 10:37 ` Eugenio Perez Martin [this message]
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=CAJaqyWcS+WN4vyKb4gNLarUsFKbt3hgQ5e9vDe2bGWSz3bue2g@mail.gmail.com \
--to=eperezma@redhat.com \
--cc=18801353760@163.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=yin31149@gmail.com \
/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).