Skip to contentSkip to conversation

vhost/net: Clear the pending messages when the backend is removed

PATCH In review Eric Auger 2 participants 5 messages Jan 17, 2023 – Jan 29, 2023

Subsystems (5)
lore
Share & tools
lore

Eric Auger

author
#0 lore raw

cover vhost/net: Clear the pending messages when the backend is removed

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/[email protected]/

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(-)
Signature · 6 lines
2.31.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
author
#1 lore raw

PATCH 1/2 vhost: Remove the enabled parameter from vhost_init_device_iotlb

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

---
 drivers/vhost/net.c   | 2 +-
 drivers/vhost/vhost.c | 2 +-
 drivers/vhost/vhost.h | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/vhost/net.c +1 -1
index 9af19b0cf3b7..135e23254a26 100644
@@ -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;
 	}
 
drivers/vhost/vhost.c +1 -1
index cbe72bfd2f1f..34458e203716 100644
@@ -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;
drivers/vhost/vhost.h +1 -1
index d9109107af08..4bfa10e52297 100644
@@ -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);
Signature · 6 lines
2.31.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
author
#2 lore raw

PATCH 2/2 vhost/net: Clear the pending messages when the backend is removed

In reply to Eric Auger

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.

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(-)
drivers/vhost/net.c +3 -0
index 135e23254a26..383f8f2ae131 100644
@@ -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;
drivers/vhost/vhost.c +2 -1
index 34458e203716..f11bdbe4c2c5 100644
@@ -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)
 {
drivers/vhost/vhost.h +1 -0
index 4bfa10e52297..1647b750169c 100644
@@ -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,
Signature · 6 lines
2.31.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
author
#3 lore raw
In reply to Eric Auger

Hi,

Quoted 6 lines · Eric Auger

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.

Quoted 8 lines

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

Quoted 9 lines

Best Regards

Eric

History:
[1] RFC: [RFC] vhost: Clear the pending messages on vhost_init_device_iotlb()
https://lore.kernel.org/all/[email protected]/

Quoted 9 lines

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
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#4 lore raw
Quoted 15 lines · Eric Auger

Hi,

Quoted 12 lines · Eric Auger

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].

Quoted 8 lines
Quoted 2 lines

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.

Quoted 13 lines
Quoted 13 lines

Best Regards

Eric

History:
[1] RFC: [RFC] vhost: Clear the pending messages on vhost_init_device_iotlb()
https://lore.kernel.org/all/[email protected]/

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

Quoted 5 lines
Quoted 5 lines
 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
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization