* [PATCH] vhost-user: send SET_STATUS 0 after GET_VRING_BASE
@ 2023-04-20 13:07 Stefan Hajnoczi
2023-04-21 5:30 ` Yajun Wu
2023-04-21 5:39 ` Michael S. Tsirkin
0 siblings, 2 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2023-04-20 13:07 UTC (permalink / raw)
To: qemu-devel; +Cc: Michael S. Tsirkin, Stefan Hajnoczi, Cindy Lu
Setting the VIRTIO Device Status Field to 0 resets the device. The
device's state is lost, including the vring configuration.
vhost-user.c currently sends SET_STATUS 0 before GET_VRING_BASE. This
risks confusion about the lifetime of the vhost-user state (e.g. vring
last_avail_idx) across VIRTIO device reset.
Eugenio Pérez <eperezma@redhat.com> adjusted the order for vhost-vdpa.c
in commit c3716f260bff ("vdpa: move vhost reset after get vring base")
and in that commit description suggested doing the same for vhost-user
in the future.
Go ahead and adjust vhost-user.c now. I ran various online code searches
to identify vhost-user backends implementing SET_STATUS. It seems only
DPDK implements SET_STATUS and Yajun Wu <yajunw@nvidia.com> has
confirmed that it is safe to make this change.
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Cindy Lu <lulu@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
hw/virtio/vhost-user.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index e5285df4ba..2d40b1b3e7 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -2677,10 +2677,20 @@ static int vhost_user_dev_start(struct vhost_dev *dev, bool started)
VIRTIO_CONFIG_S_DRIVER |
VIRTIO_CONFIG_S_DRIVER_OK);
} else {
- return vhost_user_set_status(dev, 0);
+ return 0;
}
}
+static void vhost_user_reset_status(struct vhost_dev *dev)
+{
+ /* Set device status only for last queue pair */
+ if (dev->vq_index + dev->nvqs != dev->vq_index_end) {
+ return;
+ }
+
+ vhost_user_set_status(dev, 0);
+}
+
const VhostOps user_ops = {
.backend_type = VHOST_BACKEND_TYPE_USER,
.vhost_backend_init = vhost_user_backend_init,
@@ -2716,4 +2726,5 @@ const VhostOps user_ops = {
.vhost_get_inflight_fd = vhost_user_get_inflight_fd,
.vhost_set_inflight_fd = vhost_user_set_inflight_fd,
.vhost_dev_start = vhost_user_dev_start,
+ .vhost_reset_status = vhost_user_reset_status,
};
--
2.39.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] vhost-user: send SET_STATUS 0 after GET_VRING_BASE
2023-04-20 13:07 [PATCH] vhost-user: send SET_STATUS 0 after GET_VRING_BASE Stefan Hajnoczi
@ 2023-04-21 5:30 ` Yajun Wu
2023-05-01 20:26 ` Stefan Hajnoczi
2023-04-21 5:39 ` Michael S. Tsirkin
1 sibling, 1 reply; 4+ messages in thread
From: Yajun Wu @ 2023-04-21 5:30 UTC (permalink / raw)
To: Stefan Hajnoczi, qemu-devel; +Cc: Michael S. Tsirkin, Cindy Lu
On 4/20/2023 9:07 PM, Stefan Hajnoczi wrote:
>
> Setting the VIRTIO Device Status Field to 0 resets the device. The
> device's state is lost, including the vring configuration.
>
> vhost-user.c currently sends SET_STATUS 0 before GET_VRING_BASE. This
> risks confusion about the lifetime of the vhost-user state (e.g. vring
> last_avail_idx) across VIRTIO device reset.
>
> Eugenio Pérez <eperezma@redhat.com> adjusted the order for vhost-vdpa.c
> in commit c3716f260bff ("vdpa: move vhost reset after get vring base")
> and in that commit description suggested doing the same for vhost-user
> in the future.
>
> Go ahead and adjust vhost-user.c now. I ran various online code searches
> to identify vhost-user backends implementing SET_STATUS. It seems only
> DPDK implements SET_STATUS and Yajun Wu <yajunw@nvidia.com> has
> confirmed that it is safe to make this change.
>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: Cindy Lu <lulu@redhat.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> hw/virtio/vhost-user.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> index e5285df4ba..2d40b1b3e7 100644
> --- a/hw/virtio/vhost-user.c
> +++ b/hw/virtio/vhost-user.c
> @@ -2677,10 +2677,20 @@ static int vhost_user_dev_start(struct vhost_dev *dev, bool started)
> VIRTIO_CONFIG_S_DRIVER |
> VIRTIO_CONFIG_S_DRIVER_OK);
> } else {
> - return vhost_user_set_status(dev, 0);
> + return 0;
> }
> }
>
> +static void vhost_user_reset_status(struct vhost_dev *dev)
> +{
> + /* Set device status only for last queue pair */
> + if (dev->vq_index + dev->nvqs != dev->vq_index_end) {
> + return;
> + }
> +
> + vhost_user_set_status(dev, 0);
> +}
> +
> const VhostOps user_ops = {
> .backend_type = VHOST_BACKEND_TYPE_USER,
> .vhost_backend_init = vhost_user_backend_init,
> @@ -2716,4 +2726,5 @@ const VhostOps user_ops = {
> .vhost_get_inflight_fd = vhost_user_get_inflight_fd,
> .vhost_set_inflight_fd = vhost_user_set_inflight_fd,
> .vhost_dev_start = vhost_user_dev_start,
> + .vhost_reset_status = vhost_user_reset_status,
> };
> --
> 2.39.2
>
Thank you for this fix.
Can you add protocol feature bit check, just like we do in
vhost_user_dev_start?
if (!virtio_has_feature(dev->protocol_features,
VHOST_USER_PROTOCOL_F_STATUS)) {
return 0;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] vhost-user: send SET_STATUS 0 after GET_VRING_BASE
2023-04-20 13:07 [PATCH] vhost-user: send SET_STATUS 0 after GET_VRING_BASE Stefan Hajnoczi
2023-04-21 5:30 ` Yajun Wu
@ 2023-04-21 5:39 ` Michael S. Tsirkin
1 sibling, 0 replies; 4+ messages in thread
From: Michael S. Tsirkin @ 2023-04-21 5:39 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: qemu-devel, Cindy Lu
On Thu, Apr 20, 2023 at 09:07:06AM -0400, Stefan Hajnoczi wrote:
> Setting the VIRTIO Device Status Field to 0 resets the device. The
> device's state is lost, including the vring configuration.
>
> vhost-user.c currently sends SET_STATUS 0 before GET_VRING_BASE. This
> risks confusion about the lifetime of the vhost-user state (e.g. vring
> last_avail_idx) across VIRTIO device reset.
>
> Eugenio Pérez <eperezma@redhat.com> adjusted the order for vhost-vdpa.c
> in commit c3716f260bff ("vdpa: move vhost reset after get vring base")
> and in that commit description suggested doing the same for vhost-user
> in the future.
>
> Go ahead and adjust vhost-user.c now. I ran various online code searches
> to identify vhost-user backends implementing SET_STATUS. It seems only
> DPDK implements SET_STATUS and Yajun Wu <yajunw@nvidia.com> has
> confirmed that it is safe to make this change.
Fixes tag?
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Cc: Cindy Lu <lulu@redhat.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
> hw/virtio/vhost-user.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> index e5285df4ba..2d40b1b3e7 100644
> --- a/hw/virtio/vhost-user.c
> +++ b/hw/virtio/vhost-user.c
> @@ -2677,10 +2677,20 @@ static int vhost_user_dev_start(struct vhost_dev *dev, bool started)
> VIRTIO_CONFIG_S_DRIVER |
> VIRTIO_CONFIG_S_DRIVER_OK);
> } else {
> - return vhost_user_set_status(dev, 0);
> + return 0;
> }
> }
>
> +static void vhost_user_reset_status(struct vhost_dev *dev)
> +{
> + /* Set device status only for last queue pair */
> + if (dev->vq_index + dev->nvqs != dev->vq_index_end) {
> + return;
> + }
> +
> + vhost_user_set_status(dev, 0);
> +}
> +
> const VhostOps user_ops = {
> .backend_type = VHOST_BACKEND_TYPE_USER,
> .vhost_backend_init = vhost_user_backend_init,
> @@ -2716,4 +2726,5 @@ const VhostOps user_ops = {
> .vhost_get_inflight_fd = vhost_user_get_inflight_fd,
> .vhost_set_inflight_fd = vhost_user_set_inflight_fd,
> .vhost_dev_start = vhost_user_dev_start,
> + .vhost_reset_status = vhost_user_reset_status,
> };
> --
> 2.39.2
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] vhost-user: send SET_STATUS 0 after GET_VRING_BASE
2023-04-21 5:30 ` Yajun Wu
@ 2023-05-01 20:26 ` Stefan Hajnoczi
0 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2023-05-01 20:26 UTC (permalink / raw)
To: Yajun Wu; +Cc: qemu-devel, Michael S. Tsirkin, Cindy Lu
[-- Attachment #1: Type: text/plain, Size: 2903 bytes --]
On Fri, Apr 21, 2023 at 01:30:48PM +0800, Yajun Wu wrote:
>
> On 4/20/2023 9:07 PM, Stefan Hajnoczi wrote:
> >
> > Setting the VIRTIO Device Status Field to 0 resets the device. The
> > device's state is lost, including the vring configuration.
> >
> > vhost-user.c currently sends SET_STATUS 0 before GET_VRING_BASE. This
> > risks confusion about the lifetime of the vhost-user state (e.g. vring
> > last_avail_idx) across VIRTIO device reset.
> >
> > Eugenio Pérez <eperezma@redhat.com> adjusted the order for vhost-vdpa.c
> > in commit c3716f260bff ("vdpa: move vhost reset after get vring base")
> > and in that commit description suggested doing the same for vhost-user
> > in the future.
> >
> > Go ahead and adjust vhost-user.c now. I ran various online code searches
> > to identify vhost-user backends implementing SET_STATUS. It seems only
> > DPDK implements SET_STATUS and Yajun Wu <yajunw@nvidia.com> has
> > confirmed that it is safe to make this change.
> >
> > Cc: Michael S. Tsirkin <mst@redhat.com>
> > Cc: Cindy Lu <lulu@redhat.com>
> > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> > ---
> > hw/virtio/vhost-user.c | 13 ++++++++++++-
> > 1 file changed, 12 insertions(+), 1 deletion(-)
> >
> > diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
> > index e5285df4ba..2d40b1b3e7 100644
> > --- a/hw/virtio/vhost-user.c
> > +++ b/hw/virtio/vhost-user.c
> > @@ -2677,10 +2677,20 @@ static int vhost_user_dev_start(struct vhost_dev *dev, bool started)
> > VIRTIO_CONFIG_S_DRIVER |
> > VIRTIO_CONFIG_S_DRIVER_OK);
> > } else {
> > - return vhost_user_set_status(dev, 0);
> > + return 0;
> > }
> > }
> >
> > +static void vhost_user_reset_status(struct vhost_dev *dev)
> > +{
> > + /* Set device status only for last queue pair */
> > + if (dev->vq_index + dev->nvqs != dev->vq_index_end) {
> > + return;
> > + }
> > +
> > + vhost_user_set_status(dev, 0);
> > +}
> > +
> > const VhostOps user_ops = {
> > .backend_type = VHOST_BACKEND_TYPE_USER,
> > .vhost_backend_init = vhost_user_backend_init,
> > @@ -2716,4 +2726,5 @@ const VhostOps user_ops = {
> > .vhost_get_inflight_fd = vhost_user_get_inflight_fd,
> > .vhost_set_inflight_fd = vhost_user_set_inflight_fd,
> > .vhost_dev_start = vhost_user_dev_start,
> > + .vhost_reset_status = vhost_user_reset_status,
> > };
> > --
> > 2.39.2
> >
> Thank you for this fix.
>
> Can you add protocol feature bit check, just like we do in
> vhost_user_dev_start?
>
> if (!virtio_has_feature(dev->protocol_features,
> VHOST_USER_PROTOCOL_F_STATUS)) {
> return 0;
> }
Sure, will fix in v2.
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-05-01 20:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-20 13:07 [PATCH] vhost-user: send SET_STATUS 0 after GET_VRING_BASE Stefan Hajnoczi
2023-04-21 5:30 ` Yajun Wu
2023-05-01 20:26 ` Stefan Hajnoczi
2023-04-21 5:39 ` Michael S. Tsirkin
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).