virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] vhost/net: Clear the pending messages when the backend is removed
@ 2023-01-17 15:15 Eric Auger
  2023-01-17 15:15 ` [PATCH 1/2] vhost: Remove the enabled parameter from vhost_init_device_iotlb Eric Auger
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Eric Auger @ 2023-01-17 15:15 UTC (permalink / raw)
  To: eric.auger.pro, eric.auger, mst, jasowang, kvm, netdev, virtualization
  Cc: lvivier

When the vhost iotlb is used along with a guest virtual iommu
and the guest gets rebooted, some MISS messages may have been
recorded just before the reboot and spuriously executed by
the virtual iommu after the reboot. This is due to the fact
the pending messages are not cleared.

As vhost does not have any explicit reset user API,
VHOST_NET_SET_BACKEND looks a reasonable point where to clear
the pending messages, in case the backend is removed (fd = -1).

This version is a follow-up on the discussions held in [1].

The first patch removes an unused 'enabled' parameter in
vhost_init_device_iotlb().

Best Regards

Eric

History:
[1] RFC: [RFC] vhost: Clear the pending messages on vhost_init_device_iotlb()
https://lore.kernel.org/all/20221107203431.368306-1-eric.auger@redhat.com/

Eric Auger (2):
  vhost: Remove the enabled parameter from vhost_init_device_iotlb
  vhost/net: Clear the pending messages when the backend is removed

 drivers/vhost/net.c   | 5 ++++-
 drivers/vhost/vhost.c | 5 +++--
 drivers/vhost/vhost.h | 3 ++-
 3 files changed, 9 insertions(+), 4 deletions(-)

-- 
2.31.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] vhost: Remove the enabled parameter from vhost_init_device_iotlb
  2023-01-17 15:15 [PATCH 0/2] vhost/net: Clear the pending messages when the backend is removed Eric Auger
@ 2023-01-17 15:15 ` Eric Auger
  2023-01-17 15:15 ` [PATCH 2/2] vhost/net: Clear the pending messages when the backend is removed Eric Auger
  2023-01-29 17:58 ` [PATCH 0/2] " Eric Auger
  2 siblings, 0 replies; 5+ messages in thread
From: Eric Auger @ 2023-01-17 15:15 UTC (permalink / raw)
  To: eric.auger.pro, eric.auger, mst, jasowang, kvm, netdev, virtualization
  Cc: lvivier

The 'enabled' parameter is not used by the function. Remove it.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
Reported-by: Michael S. Tsirkin <mst@redhat.com>
---
 drivers/vhost/net.c   | 2 +-
 drivers/vhost/vhost.c | 2 +-
 drivers/vhost/vhost.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 9af19b0cf3b7..135e23254a26 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -1642,7 +1642,7 @@ static int vhost_net_set_features(struct vhost_net *n, u64 features)
 		goto out_unlock;
 
 	if ((features & (1ULL << VIRTIO_F_ACCESS_PLATFORM))) {
-		if (vhost_init_device_iotlb(&n->dev, true))
+		if (vhost_init_device_iotlb(&n->dev))
 			goto out_unlock;
 	}
 
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index cbe72bfd2f1f..34458e203716 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -1729,7 +1729,7 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *arg
 }
 EXPORT_SYMBOL_GPL(vhost_vring_ioctl);
 
-int vhost_init_device_iotlb(struct vhost_dev *d, bool enabled)
+int vhost_init_device_iotlb(struct vhost_dev *d)
 {
 	struct vhost_iotlb *niotlb, *oiotlb;
 	int i;
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index d9109107af08..4bfa10e52297 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -221,7 +221,7 @@ ssize_t vhost_chr_read_iter(struct vhost_dev *dev, struct iov_iter *to,
 			    int noblock);
 ssize_t vhost_chr_write_iter(struct vhost_dev *dev,
 			     struct iov_iter *from);
-int vhost_init_device_iotlb(struct vhost_dev *d, bool enabled);
+int vhost_init_device_iotlb(struct vhost_dev *d);
 
 void vhost_iotlb_map_free(struct vhost_iotlb *iotlb,
 			  struct vhost_iotlb_map *map);
-- 
2.31.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] vhost/net: Clear the pending messages when the backend is removed
  2023-01-17 15:15 [PATCH 0/2] vhost/net: Clear the pending messages when the backend is removed Eric Auger
  2023-01-17 15:15 ` [PATCH 1/2] vhost: Remove the enabled parameter from vhost_init_device_iotlb Eric Auger
@ 2023-01-17 15:15 ` Eric Auger
  2023-01-29 17:58 ` [PATCH 0/2] " Eric Auger
  2 siblings, 0 replies; 5+ messages in thread
From: Eric Auger @ 2023-01-17 15:15 UTC (permalink / raw)
  To: eric.auger.pro, eric.auger, mst, jasowang, kvm, netdev, virtualization
  Cc: lvivier

When the vhost iotlb is used along with a guest virtual iommu
and the guest gets rebooted, some MISS messages may have been
recorded just before the reboot and spuriously executed by
the virtual iommu after the reboot.

As vhost does not have any explicit reset user API,
VHOST_NET_SET_BACKEND looks a reasonable point where to clear
the pending messages, in case the backend is removed.

Export vhost_clear_msg() and call it in vhost_net_set_backend()
when fd == -1.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
Suggested-by: Jason Wang <jasowang@redhat.com>
Fixes: 6b1e6cc7855b0 ("vhost: new device IOTLB API")

---

Without this patch, with QEMU virtio-iommu, on reboot, we get
spurious messages such as

qemu-kvm: virtio_iommu_translate no mapping for 0xff732800 for sid=1536
---
 drivers/vhost/net.c   | 3 +++
 drivers/vhost/vhost.c | 3 ++-
 drivers/vhost/vhost.h | 1 +
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
index 135e23254a26..383f8f2ae131 100644
--- a/drivers/vhost/net.c
+++ b/drivers/vhost/net.c
@@ -1511,6 +1511,9 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
 	nvq = &n->vqs[index];
 	mutex_lock(&vq->mutex);
 
+	if (fd == -1)
+		vhost_clear_msg(&n->dev);
+
 	/* Verify that ring has been setup correctly. */
 	if (!vhost_vq_access_ok(vq)) {
 		r = -EFAULT;
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
index 34458e203716..f11bdbe4c2c5 100644
--- a/drivers/vhost/vhost.c
+++ b/drivers/vhost/vhost.c
@@ -661,7 +661,7 @@ void vhost_dev_stop(struct vhost_dev *dev)
 }
 EXPORT_SYMBOL_GPL(vhost_dev_stop);
 
-static void vhost_clear_msg(struct vhost_dev *dev)
+void vhost_clear_msg(struct vhost_dev *dev)
 {
 	struct vhost_msg_node *node, *n;
 
@@ -679,6 +679,7 @@ static void vhost_clear_msg(struct vhost_dev *dev)
 
 	spin_unlock(&dev->iotlb_lock);
 }
+EXPORT_SYMBOL_GPL(vhost_clear_msg);
 
 void vhost_dev_cleanup(struct vhost_dev *dev)
 {
diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h
index 4bfa10e52297..1647b750169c 100644
--- a/drivers/vhost/vhost.h
+++ b/drivers/vhost/vhost.h
@@ -181,6 +181,7 @@ long vhost_dev_ioctl(struct vhost_dev *, unsigned int ioctl, void __user *argp);
 long vhost_vring_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp);
 bool vhost_vq_access_ok(struct vhost_virtqueue *vq);
 bool vhost_log_access_ok(struct vhost_dev *);
+void vhost_clear_msg(struct vhost_dev *dev);
 
 int vhost_get_vq_desc(struct vhost_virtqueue *,
 		      struct iovec iov[], unsigned int iov_count,
-- 
2.31.1

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] vhost/net: Clear the pending messages when the backend is removed
  2023-01-17 15:15 [PATCH 0/2] vhost/net: Clear the pending messages when the backend is removed Eric Auger
  2023-01-17 15:15 ` [PATCH 1/2] vhost: Remove the enabled parameter from vhost_init_device_iotlb Eric Auger
  2023-01-17 15:15 ` [PATCH 2/2] vhost/net: Clear the pending messages when the backend is removed Eric Auger
@ 2023-01-29 17:58 ` Eric Auger
  2023-01-29 22:33   ` Michael S. Tsirkin
  2 siblings, 1 reply; 5+ messages in thread
From: Eric Auger @ 2023-01-29 17:58 UTC (permalink / raw)
  To: eric.auger.pro, mst, jasowang, kvm, netdev, virtualization; +Cc: lvivier

Hi,

On 1/17/23 16:15, Eric Auger wrote:
> When the vhost iotlb is used along with a guest virtual iommu
> and the guest gets rebooted, some MISS messages may have been
> recorded just before the reboot and spuriously executed by
> the virtual iommu after the reboot. This is due to the fact
> the pending messages are not cleared.
>
> As vhost does not have any explicit reset user API,
> VHOST_NET_SET_BACKEND looks a reasonable point where to clear
> the pending messages, in case the backend is removed (fd = -1).
>
> This version is a follow-up on the discussions held in [1].
>
> The first patch removes an unused 'enabled' parameter in
> vhost_init_device_iotlb().

Gentle Ping. Does it look a reasonable fix now?

Thanks

Eric
>
> Best Regards
>
> Eric
>
> History:
> [1] RFC: [RFC] vhost: Clear the pending messages on vhost_init_device_iotlb()
> https://lore.kernel.org/all/20221107203431.368306-1-eric.auger@redhat.com/
>
> Eric Auger (2):
>   vhost: Remove the enabled parameter from vhost_init_device_iotlb
>   vhost/net: Clear the pending messages when the backend is removed
>
>  drivers/vhost/net.c   | 5 ++++-
>  drivers/vhost/vhost.c | 5 +++--
>  drivers/vhost/vhost.h | 3 ++-
>  3 files changed, 9 insertions(+), 4 deletions(-)
>

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] vhost/net: Clear the pending messages when the backend is removed
  2023-01-29 17:58 ` [PATCH 0/2] " Eric Auger
@ 2023-01-29 22:33   ` Michael S. Tsirkin
  0 siblings, 0 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2023-01-29 22:33 UTC (permalink / raw)
  To: Eric Auger; +Cc: lvivier, kvm, netdev, virtualization, eric.auger.pro

On Sun, Jan 29, 2023 at 06:58:09PM +0100, Eric Auger wrote:
> Hi,
> 
> On 1/17/23 16:15, Eric Auger wrote:
> > When the vhost iotlb is used along with a guest virtual iommu
> > and the guest gets rebooted, some MISS messages may have been
> > recorded just before the reboot and spuriously executed by
> > the virtual iommu after the reboot. This is due to the fact
> > the pending messages are not cleared.
> >
> > As vhost does not have any explicit reset user API,
> > VHOST_NET_SET_BACKEND looks a reasonable point where to clear
> > the pending messages, in case the backend is removed (fd = -1).
> >
> > This version is a follow-up on the discussions held in [1].
> >
> > The first patch removes an unused 'enabled' parameter in
> > vhost_init_device_iotlb().
> 
> Gentle Ping. Does it look a reasonable fix now?
> 
> Thanks
> 
> Eric

Yes I applied this - giving it a bit of time in next.

> >
> > Best Regards
> >
> > Eric
> >
> > History:
> > [1] RFC: [RFC] vhost: Clear the pending messages on vhost_init_device_iotlb()
> > https://lore.kernel.org/all/20221107203431.368306-1-eric.auger@redhat.com/
> >
> > Eric Auger (2):
> >   vhost: Remove the enabled parameter from vhost_init_device_iotlb
> >   vhost/net: Clear the pending messages when the backend is removed
> >
> >  drivers/vhost/net.c   | 5 ++++-
> >  drivers/vhost/vhost.c | 5 +++--
> >  drivers/vhost/vhost.h | 3 ++-
> >  3 files changed, 9 insertions(+), 4 deletions(-)
> >

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-01-29 22:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-17 15:15 [PATCH 0/2] vhost/net: Clear the pending messages when the backend is removed Eric Auger
2023-01-17 15:15 ` [PATCH 1/2] vhost: Remove the enabled parameter from vhost_init_device_iotlb Eric Auger
2023-01-17 15:15 ` [PATCH 2/2] vhost/net: Clear the pending messages when the backend is removed Eric Auger
2023-01-29 17:58 ` [PATCH 0/2] " Eric Auger
2023-01-29 22:33   ` 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).