From: "Michael S. Tsirkin" <mst@redhat.com>
To: huangy81@chinatelecom.cn
Cc: qemu-devel <qemu-devel@nongnu.org>,
"Jason Wang" <jasowang@redhat.com>,
"Stefano Garzarella" <sgarzare@redhat.com>,
"Raphael Norwitz" <raphael.norwitz@nutanix.com>,
"Guoyi Tu" <tugy@chinatelecom.cn>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: Re: [PATCH v3 2/2] vhost-net: Fix the virtio features negotiation flaw
Date: Thu, 10 Nov 2022 14:17:31 -0500 [thread overview]
Message-ID: <20221110141415-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <2560bb4e8cabc550da07162c520aff3669a8f56f.1667136717.git.huangy81@chinatelecom.cn>
On Sun, Oct 30, 2022 at 09:52:39PM +0800, huangy81@chinatelecom.cn wrote:
> From: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
>
> Save the acked_features once it be configured by guest
> virtio driver so it can't miss any features.
>
> Note that this patch also change the features saving logic
> in chr_closed_bh, which originally backup features no matter
> whether the features are 0 or not, but now do it only if
> features aren't 0.
>
> As to reset acked_features to 0 if needed, Qemu always
> keeping the backup acked_features up-to-date, and save the
> acked_features after virtio_net_set_features in advance,
> including reset acked_features to 0, so the behavior is
> also covered.
>
> Signed-off-by: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
> Signed-off-by: Guoyi Tu <tugy@chinatelecom.cn>
> ---
> hw/net/vhost_net.c | 9 +++++++++
> hw/net/virtio-net.c | 5 +++++
> include/net/vhost_net.h | 2 ++
> net/vhost-user.c | 6 +-----
> 4 files changed, 17 insertions(+), 5 deletions(-)
>
> diff --git a/hw/net/vhost_net.c b/hw/net/vhost_net.c
> index d28f8b9..2bffc27 100644
> --- a/hw/net/vhost_net.c
> +++ b/hw/net/vhost_net.c
> @@ -141,6 +141,15 @@ uint64_t vhost_net_get_acked_features(VHostNetState *net)
> return net->dev.acked_features;
> }
>
> +void vhost_net_save_acked_features(NetClientState *nc)
> +{
> + if (nc->info->type != NET_CLIENT_DRIVER_VHOST_USER) {
> + return;
> + }
> +
> + vhost_user_save_acked_features(nc, false);
> +}
> +
> static int vhost_net_get_fd(NetClientState *backend)
> {
> switch (backend->info->type) {
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index e9f696b..5f8f788 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -924,6 +924,11 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features)
> continue;
> }
> vhost_net_ack_features(get_vhost_net(nc->peer), features);
> + /*
> + * keep acked_features in NetVhostUserState up-to-date so it
> + * can't miss any features configured by guest virtio driver.
> + */
> + vhost_net_save_acked_features(nc->peer);
> }
>
> if (virtio_has_feature(features, VIRTIO_NET_F_CTRL_VLAN)) {
So when do you want to ack features but *not* save them?
Is the effect of this patch, fundamentally, that guest features
from virtio are always copied to vhost-user?
Do we even need an extra copy in vhost user then?
all this came in with:
commit a463215b087c41d7ca94e51aa347cde523831873
Author: Marc-André Lureau <marcandre.lureau@redhat.com>
Date: Mon Jun 6 18:45:05 2016 +0200
vhost-net: save & restore vhost-user acked features
Marc-André do you remember why we have a copy of features in vhost-user
and not just reuse the features from virtio?
> diff --git a/include/net/vhost_net.h b/include/net/vhost_net.h
> index 387e913..3a5579b 100644
> --- a/include/net/vhost_net.h
> +++ b/include/net/vhost_net.h
> @@ -46,6 +46,8 @@ int vhost_set_vring_enable(NetClientState * nc, int enable);
>
> uint64_t vhost_net_get_acked_features(VHostNetState *net);
>
> +void vhost_net_save_acked_features(NetClientState *nc);
> +
> int vhost_net_set_mtu(struct vhost_net *net, uint16_t mtu);
>
> #endif
> diff --git a/net/vhost-user.c b/net/vhost-user.c
> index 74f349c..c512cc9 100644
> --- a/net/vhost-user.c
> +++ b/net/vhost-user.c
> @@ -258,11 +258,7 @@ static void chr_closed_bh(void *opaque)
> s = DO_UPCAST(NetVhostUserState, nc, ncs[0]);
>
> for (i = queues -1; i >= 0; i--) {
> - s = DO_UPCAST(NetVhostUserState, nc, ncs[i]);
> -
> - if (s->vhost_net) {
> - s->acked_features = vhost_net_get_acked_features(s->vhost_net);
> - }
> + vhost_user_save_acked_features(ncs[i], false);
> }
>
> qmp_set_link(name, false, &err);
> --
> 1.8.3.1
next prev parent reply other threads:[~2022-11-10 19:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-30 13:52 [PATCH v3 0/2] Fix the virtio features negotiation flaw huangy81
2022-10-30 13:52 ` [PATCH v3 1/2] vhost-user: Refactor vhost acked features saving huangy81
2022-11-10 18:56 ` Michael S. Tsirkin
2022-11-11 12:24 ` Hyman Huang
2022-10-30 13:52 ` [PATCH v3 2/2] vhost-net: Fix the virtio features negotiation flaw huangy81
2022-11-10 19:00 ` Michael S. Tsirkin
2022-11-11 18:37 ` Hyman
2022-11-11 18:49 ` Hyman
2022-11-10 19:17 ` Michael S. Tsirkin [this message]
2022-11-14 15:35 ` Hyman
2022-11-14 15:48 ` Michael S. Tsirkin
2022-11-10 18:53 ` [PATCH v3 0/2] " Michael S. Tsirkin
2022-11-11 6:46 ` Hyman Huang
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=20221110141415-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=huangy81@chinatelecom.cn \
--cc=jasowang@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=raphael.norwitz@nutanix.com \
--cc=sgarzare@redhat.com \
--cc=tugy@chinatelecom.cn \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.