Apply the common device IOTLB teardown when userspace clears VIRTIO_F_ACCESS_PLATFORM. This drops stale translations and avoids rebuilding an existing IOTLB during feature updates that keep ACCESS_PLATFORM enabled. The transition invalidates cached vring access even with an attached backend. The backend remains attached, but userspace must configure the vring addresses for the new address mode after a successful live transition. Fixes: 6b1e6cc7855b ("vhost: new device IOTLB API") Link: https://lore.kernel.org/all/20260726141158.1652386-1-physicalmtea@gmail.com/ Signed-off-by: Jia Jia --- drivers/vhost/net.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 77b59f49bddb..64671cf77a35 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -1673,6 +1673,7 @@ static long vhost_net_reset_owner(struct vhost_net *n) static int vhost_net_set_features(struct vhost_net *n, const u64 *features) { size_t vhost_hlen, sock_hlen, hdr_len; + int ret = -EFAULT; int i; hdr_len = virtio_features_test_bit(features, VIRTIO_NET_F_MRG_RXBUF) || @@ -1701,8 +1702,11 @@ static int vhost_net_set_features(struct vhost_net *n, const u64 *features) goto out_unlock; if (virtio_features_test_bit(features, VIRTIO_F_ACCESS_PLATFORM)) { - if (vhost_init_device_iotlb(&n->dev)) + ret = vhost_init_device_iotlb(&n->dev); + if (ret) goto out_unlock; + } else { + vhost_clear_device_iotlb(&n->dev); } for (i = 0; i < VHOST_NET_VQ_MAX; ++i) { @@ -1718,7 +1722,7 @@ static int vhost_net_set_features(struct vhost_net *n, const u64 *features) out_unlock: mutex_unlock(&n->dev.mutex); - return -EFAULT; + return ret; } static long vhost_net_set_owner(struct vhost_net *n)