]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
vhost-vdpa: clean iotlb map during reset for older userspace
authorSi-Wei Liu <si-wei.liu@oracle.com>
Sat, 21 Oct 2023 09:25:17 +0000 (02:25 -0700)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 1 Nov 2023 13:20:00 +0000 (09:20 -0400)
Using .compat_reset op from the previous patch, the buggy .reset
behaviour can be kept as-is on older userspace apps, which don't ack the
IOTLB_PERSIST backend feature. As this compatibility quirk is limited to
those drivers that used to be buggy in the past, it won't affect change
the behaviour or affect ABI on the setups with API compliant driver.

The separation of .compat_reset from the regular .reset allows
vhost-vdpa able to know which driver had broken behaviour before, so it
can apply the corresponding compatibility quirk to the individual driver
whenever needed.  Compared to overloading the existing .reset with
flags, .compat_reset won't cause any extra burden to the implementation
of every compliant driver.

[mst: squashed in two fixup commits]

Message-Id: <1697880319-4937-6-git-send-email-si-wei.liu@oracle.com>
Message-Id: <1698102863-21122-1-git-send-email-si-wei.liu@oracle.com>
Reported-by: Dragos Tatulea <dtatulea@nvidia.com>
Tested-by: Dragos Tatulea <dtatulea@nvidia.com>
Message-Id: <1698275594-19204-1-git-send-email-si-wei.liu@oracle.com>
Reported-by: Lei Yang <leiyang@redhat.com>
Signed-off-by: Si-Wei Liu <si-wei.liu@oracle.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Tested-by: Lei Yang <leiyang@redhat.com>
drivers/vhost/vdpa.c
drivers/virtio/virtio_vdpa.c
include/linux/vdpa.h

index acc7c74ba7d6ae71d6b0102c963cca78acf7bfca..30df5c58db73a846dc3c58ad821201694869a348 100644 (file)
@@ -227,13 +227,24 @@ static void vhost_vdpa_unsetup_vq_irq(struct vhost_vdpa *v, u16 qid)
        irq_bypass_unregister_producer(&vq->call_ctx.producer);
 }
 
-static int vhost_vdpa_reset(struct vhost_vdpa *v)
+static int _compat_vdpa_reset(struct vhost_vdpa *v)
 {
        struct vdpa_device *vdpa = v->vdpa;
+       u32 flags = 0;
 
-       v->in_batch = 0;
+       if (v->vdev.vqs) {
+               flags |= !vhost_backend_has_feature(v->vdev.vqs[0],
+                                                   VHOST_BACKEND_F_IOTLB_PERSIST) ?
+                        VDPA_RESET_F_CLEAN_MAP : 0;
+       }
+
+       return vdpa_reset(vdpa, flags);
+}
 
-       return vdpa_reset(vdpa);
+static int vhost_vdpa_reset(struct vhost_vdpa *v)
+{
+       v->in_batch = 0;
+       return _compat_vdpa_reset(v);
 }
 
 static long vhost_vdpa_bind_mm(struct vhost_vdpa *v)
@@ -312,7 +323,7 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp)
                        vhost_vdpa_unsetup_vq_irq(v, i);
 
        if (status == 0) {
-               ret = vdpa_reset(vdpa);
+               ret = _compat_vdpa_reset(v);
                if (ret)
                        return ret;
        } else
@@ -1344,6 +1355,7 @@ static void vhost_vdpa_cleanup(struct vhost_vdpa *v)
        vhost_vdpa_free_domain(v);
        vhost_dev_cleanup(&v->vdev);
        kfree(v->vdev.vqs);
+       v->vdev.vqs = NULL;
 }
 
 static int vhost_vdpa_open(struct inode *inode, struct file *filep)
index 06ce6d8c2e00473bea0df046f296b3ad17838f65..8d63e5923d245b2eef2c7a51e9456b96b9636ca4 100644 (file)
@@ -100,7 +100,7 @@ static void virtio_vdpa_reset(struct virtio_device *vdev)
 {
        struct vdpa_device *vdpa = vd_get_vdpa(vdev);
 
-       vdpa_reset(vdpa);
+       vdpa_reset(vdpa, 0);
 }
 
 static bool virtio_vdpa_notify(struct virtqueue *vq)
index 6b8cbf75712dfcb77d00cf1c870c9ca711d8351b..db15ac07f8a6a453bfbe35df555eea6efc83e0d8 100644 (file)
@@ -519,14 +519,17 @@ static inline struct device *vdpa_get_dma_dev(struct vdpa_device *vdev)
        return vdev->dma_dev;
 }
 
-static inline int vdpa_reset(struct vdpa_device *vdev)
+static inline int vdpa_reset(struct vdpa_device *vdev, u32 flags)
 {
        const struct vdpa_config_ops *ops = vdev->config;
        int ret;
 
        down_write(&vdev->cf_lock);
        vdev->features_valid = false;
-       ret = ops->reset(vdev);
+       if (ops->compat_reset && flags)
+               ret = ops->compat_reset(vdev, flags);
+       else
+               ret = ops->reset(vdev);
        up_write(&vdev->cf_lock);
        return ret;
 }