Skip to content

Commit 0c89e2a

Browse files
eugpermarmstsirkin
authored andcommitted
vdpa_sim: Implement suspend vdpa op
Implement suspend operation for vdpa_sim devices, so vhost-vdpa will offer that backend feature and userspace can effectively suspend the device. This is a must before get 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). Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Signed-off-by: Eugenio Pérez <eperezma@redhat.com> Message-Id: <20220810171512.2343333-5-eperezma@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent f345a01 commit 0c89e2a

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

drivers/vdpa/vdpa_sim/vdpa_sim.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ static void vdpasim_do_reset(struct vdpasim *vdpasim)
107107
for (i = 0; i < vdpasim->dev_attr.nas; i++)
108108
vhost_iotlb_reset(&vdpasim->iommu[i]);
109109

110+
vdpasim->running = true;
110111
spin_unlock(&vdpasim->iommu_lock);
111112

112113
vdpasim->features = 0;
@@ -505,6 +506,17 @@ static int vdpasim_reset(struct vdpa_device *vdpa)
505506
return 0;
506507
}
507508

509+
static int vdpasim_suspend(struct vdpa_device *vdpa)
510+
{
511+
struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
512+
513+
spin_lock(&vdpasim->lock);
514+
vdpasim->running = false;
515+
spin_unlock(&vdpasim->lock);
516+
517+
return 0;
518+
}
519+
508520
static size_t vdpasim_get_config_size(struct vdpa_device *vdpa)
509521
{
510522
struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
@@ -694,6 +706,7 @@ static const struct vdpa_config_ops vdpasim_config_ops = {
694706
.get_status = vdpasim_get_status,
695707
.set_status = vdpasim_set_status,
696708
.reset = vdpasim_reset,
709+
.suspend = vdpasim_suspend,
697710
.get_config_size = vdpasim_get_config_size,
698711
.get_config = vdpasim_get_config,
699712
.set_config = vdpasim_set_config,
@@ -726,6 +739,7 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = {
726739
.get_status = vdpasim_get_status,
727740
.set_status = vdpasim_set_status,
728741
.reset = vdpasim_reset,
742+
.suspend = vdpasim_suspend,
729743
.get_config_size = vdpasim_get_config_size,
730744
.get_config = vdpasim_get_config,
731745
.set_config = vdpasim_set_config,

drivers/vdpa/vdpa_sim/vdpa_sim.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct vdpasim {
6666
u32 generation;
6767
u64 features;
6868
u32 groups;
69+
bool running;
6970
/* spinlock to synchronize iommu table */
7071
spinlock_t iommu_lock;
7172
};

drivers/vdpa/vdpa_sim/vdpa_sim_blk.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ static void vdpasim_blk_work(struct work_struct *work)
213213
if (!(vdpasim->status & VIRTIO_CONFIG_S_DRIVER_OK))
214214
goto out;
215215

216+
if (!vdpasim->running)
217+
goto out;
218+
216219
for (i = 0; i < VDPASIM_BLK_VQ_NUM; i++) {
217220
struct vdpasim_virtqueue *vq = &vdpasim->vqs[i];
218221
int reqs = 0;

drivers/vdpa/vdpa_sim/vdpa_sim_net.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ static void vdpasim_net_work(struct work_struct *work)
154154

155155
spin_lock(&vdpasim->lock);
156156

157+
if (!vdpasim->running)
158+
goto out;
159+
157160
if (!(vdpasim->status & VIRTIO_CONFIG_S_DRIVER_OK))
158161
goto out;
159162

0 commit comments

Comments
 (0)