Skip to content

Commit f345a01

Browse files
eugpermarmstsirkin
authored andcommitted
vhost-vdpa: uAPI to suspend the device
The ioctl adds support for suspending the device from userspace. This is a must before getting virtqueue indexes (base) for live migration, since the device could modify them after userland gets them. There are individual ways to perform that action for some devices (VHOST_NET_SET_BACKEND, VHOST_VSOCK_SET_RUNNING, ...) but there was no way to perform it for any vhost device (and, in particular, vhost-vdpa). After a successful return of the ioctl call the device must not process more virtqueue descriptors. The device can answer to read or writes of config fields as if it were not suspended. In particular, writing to "queue_enable" with a value of 1 will not make the device start processing buffers of the virtqueue. Signed-off-by: Eugenio Pérez <eperezma@redhat.com> Message-Id: <20220810171512.2343333-4-eperezma@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 0723f1d commit f345a01

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

drivers/vhost/vdpa.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,22 @@ static long vhost_vdpa_get_vqs_count(struct vhost_vdpa *v, u32 __user *argp)
478478
return 0;
479479
}
480480

481+
/* After a successful return of ioctl the device must not process more
482+
* virtqueue descriptors. The device can answer to read or writes of config
483+
* fields as if it were not suspended. In particular, writing to "queue_enable"
484+
* with a value of 1 will not make the device start processing buffers.
485+
*/
486+
static long vhost_vdpa_suspend(struct vhost_vdpa *v)
487+
{
488+
struct vdpa_device *vdpa = v->vdpa;
489+
const struct vdpa_config_ops *ops = vdpa->config;
490+
491+
if (!ops->suspend)
492+
return -EOPNOTSUPP;
493+
494+
return ops->suspend(vdpa);
495+
}
496+
481497
static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,
482498
void __user *argp)
483499
{
@@ -654,6 +670,9 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
654670
case VHOST_VDPA_GET_VQS_COUNT:
655671
r = vhost_vdpa_get_vqs_count(v, argp);
656672
break;
673+
case VHOST_VDPA_SUSPEND:
674+
r = vhost_vdpa_suspend(v);
675+
break;
657676
default:
658677
r = vhost_dev_ioctl(&v->vdev, cmd, argp);
659678
if (r == -ENOIOCTLCMD)

include/uapi/linux/vhost.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,13 @@
171171
#define VHOST_VDPA_SET_GROUP_ASID _IOW(VHOST_VIRTIO, 0x7C, \
172172
struct vhost_vring_state)
173173

174+
/* Suspend a device so it does not process virtqueue requests anymore
175+
*
176+
* After the return of ioctl the device must preserve all the necessary state
177+
* (the virtqueue vring base plus the possible device specific states) that is
178+
* required for restoring in the future. The device must not change its
179+
* configuration after that point.
180+
*/
181+
#define VHOST_VDPA_SUSPEND _IO(VHOST_VIRTIO, 0x7D)
182+
174183
#endif

0 commit comments

Comments
 (0)