Skip to content

Commit

Permalink
vhost/net: Clear the pending messages when the backend is removed
Browse files Browse the repository at this point in the history
[ Upstream commit 9526f9a ]

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: 6b1e6cc ("vhost: new device IOTLB API")
Message-Id: <20230117151518.44725-3-eric.auger@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
eauger authored and gregkh committed Feb 9, 2023
1 parent 0b49da8 commit ccbe22d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions drivers/vhost/net.c
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion drivers/vhost/vhost.c
Expand Up @@ -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;

Expand All @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions drivers/vhost/vhost.h
Expand Up @@ -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,
Expand Down

0 comments on commit ccbe22d

Please sign in to comment.