Skip to content

Commit c7e1944

Browse files
dtatuleamstsirkin
authored andcommitted
vdpa: Track device suspended state
Set vdpa device suspended state on successful suspend. Clear it on successful resume and reset. The state will be locked by the vhost_vdpa mutex. The mutex is taken during suspend, resume and reset in vhost_vdpa_unlocked_ioctl. The exception is vhost_vdpa_open which does a device reset but that should be safe because it can only happen before the other ops. Signed-off-by: Dragos Tatulea <dtatulea@nvidia.com> Suggested-by: Eugenio Pérez <eperezma@redhat.com> Message-Id: <20231225134210.151540-2-dtatulea@nvidia.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 95e7249 commit c7e1944

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

drivers/vhost/vdpa.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct vhost_vdpa {
5959
int in_batch;
6060
struct vdpa_iova_range range;
6161
u32 batch_asid;
62+
bool suspended;
6263
};
6364

6465
static DEFINE_IDA(vhost_vdpa_ida);
@@ -232,6 +233,8 @@ static int _compat_vdpa_reset(struct vhost_vdpa *v)
232233
struct vdpa_device *vdpa = v->vdpa;
233234
u32 flags = 0;
234235

236+
v->suspended = false;
237+
235238
if (v->vdev.vqs) {
236239
flags |= !vhost_backend_has_feature(v->vdev.vqs[0],
237240
VHOST_BACKEND_F_IOTLB_PERSIST) ?
@@ -590,11 +593,16 @@ static long vhost_vdpa_suspend(struct vhost_vdpa *v)
590593
{
591594
struct vdpa_device *vdpa = v->vdpa;
592595
const struct vdpa_config_ops *ops = vdpa->config;
596+
int ret;
593597

594598
if (!ops->suspend)
595599
return -EOPNOTSUPP;
596600

597-
return ops->suspend(vdpa);
601+
ret = ops->suspend(vdpa);
602+
if (!ret)
603+
v->suspended = true;
604+
605+
return ret;
598606
}
599607

600608
/* After a successful return of this ioctl the device resumes processing
@@ -605,11 +613,16 @@ static long vhost_vdpa_resume(struct vhost_vdpa *v)
605613
{
606614
struct vdpa_device *vdpa = v->vdpa;
607615
const struct vdpa_config_ops *ops = vdpa->config;
616+
int ret;
608617

609618
if (!ops->resume)
610619
return -EOPNOTSUPP;
611620

612-
return ops->resume(vdpa);
621+
ret = ops->resume(vdpa);
622+
if (!ret)
623+
v->suspended = false;
624+
625+
return ret;
613626
}
614627

615628
static long vhost_vdpa_vring_ioctl(struct vhost_vdpa *v, unsigned int cmd,

0 commit comments

Comments
 (0)