Eric Auger
2023-Jan-17 15:15 UTC
[PATCH 0/2] 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/20221107203431.368306-1-eric.auger at 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
Eric Auger
2023-Jan-17 15:15 UTC
[PATCH 1/2] vhost: Remove the enabled parameter from vhost_init_device_iotlb
The 'enabled' parameter is not used by the function. Remove it. Signed-off-by: Eric Auger <eric.auger at redhat.com> Reported-by: Michael S. Tsirkin <mst at 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
Eric Auger
2023-Jan-17 15:15 UTC
[PATCH 2/2] 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. 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 at redhat.com> Suggested-by: Jason Wang <jasowang at 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
Eric Auger
2023-Jan-29 17:58 UTC
[PATCH 0/2] vhost/net: Clear the pending messages when the backend is removed
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 at 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(-) >