Skip to content

Commit bc91df5

Browse files
siwliu-kernelmstsirkin
authored andcommitted
vhost-vdpa: clean iotlb map during reset for older userspace
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: <[email protected]> Message-Id: <[email protected]> Reported-by: Dragos Tatulea <[email protected]> Tested-by: Dragos Tatulea <[email protected]> Message-Id: <[email protected]> Reported-by: Lei Yang <[email protected]> Signed-off-by: Si-Wei Liu <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Tested-by: Lei Yang <[email protected]>
1 parent a26f2e4 commit bc91df5

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

drivers/vhost/vdpa.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,24 @@ static void vhost_vdpa_unsetup_vq_irq(struct vhost_vdpa *v, u16 qid)
227227
irq_bypass_unregister_producer(&vq->call_ctx.producer);
228228
}
229229

230-
static int vhost_vdpa_reset(struct vhost_vdpa *v)
230+
static int _compat_vdpa_reset(struct vhost_vdpa *v)
231231
{
232232
struct vdpa_device *vdpa = v->vdpa;
233+
u32 flags = 0;
233234

234-
v->in_batch = 0;
235+
if (v->vdev.vqs) {
236+
flags |= !vhost_backend_has_feature(v->vdev.vqs[0],
237+
VHOST_BACKEND_F_IOTLB_PERSIST) ?
238+
VDPA_RESET_F_CLEAN_MAP : 0;
239+
}
240+
241+
return vdpa_reset(vdpa, flags);
242+
}
235243

236-
return vdpa_reset(vdpa);
244+
static int vhost_vdpa_reset(struct vhost_vdpa *v)
245+
{
246+
v->in_batch = 0;
247+
return _compat_vdpa_reset(v);
237248
}
238249

239250
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)
312323
vhost_vdpa_unsetup_vq_irq(v, i);
313324

314325
if (status == 0) {
315-
ret = vdpa_reset(vdpa);
326+
ret = _compat_vdpa_reset(v);
316327
if (ret)
317328
return ret;
318329
} else
@@ -1344,6 +1355,7 @@ static void vhost_vdpa_cleanup(struct vhost_vdpa *v)
13441355
vhost_vdpa_free_domain(v);
13451356
vhost_dev_cleanup(&v->vdev);
13461357
kfree(v->vdev.vqs);
1358+
v->vdev.vqs = NULL;
13471359
}
13481360

13491361
static int vhost_vdpa_open(struct inode *inode, struct file *filep)

drivers/virtio/virtio_vdpa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static void virtio_vdpa_reset(struct virtio_device *vdev)
100100
{
101101
struct vdpa_device *vdpa = vd_get_vdpa(vdev);
102102

103-
vdpa_reset(vdpa);
103+
vdpa_reset(vdpa, 0);
104104
}
105105

106106
static bool virtio_vdpa_notify(struct virtqueue *vq)

include/linux/vdpa.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,14 +519,17 @@ static inline struct device *vdpa_get_dma_dev(struct vdpa_device *vdev)
519519
return vdev->dma_dev;
520520
}
521521

522-
static inline int vdpa_reset(struct vdpa_device *vdev)
522+
static inline int vdpa_reset(struct vdpa_device *vdev, u32 flags)
523523
{
524524
const struct vdpa_config_ops *ops = vdev->config;
525525
int ret;
526526

527527
down_write(&vdev->cf_lock);
528528
vdev->features_valid = false;
529-
ret = ops->reset(vdev);
529+
if (ops->compat_reset && flags)
530+
ret = ops->compat_reset(vdev, flags);
531+
else
532+
ret = ops->reset(vdev);
530533
up_write(&vdev->cf_lock);
531534
return ret;
532535
}

0 commit comments

Comments
 (0)