Skip to content

Commit 0723f1d

Browse files
eugpermarmstsirkin
authored andcommitted
vhost-vdpa: introduce SUSPEND backend feature bit
Userland knows if it can suspend the device or not by checking this feature bit. It's only offered if the vdpa driver backend implements the suspend() operation callback, and to offer it or userland to ack it if the backend does not offer that callback is an error. Signed-off-by: Eugenio Pérez <eperezma@redhat.com> Message-Id: <20220810171512.2343333-3-eperezma@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
1 parent 848ecea commit 0723f1d

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

drivers/vhost/vdpa.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,14 @@ static long vhost_vdpa_set_config(struct vhost_vdpa *v,
347347
return 0;
348348
}
349349

350+
static bool vhost_vdpa_can_suspend(const struct vhost_vdpa *v)
351+
{
352+
struct vdpa_device *vdpa = v->vdpa;
353+
const struct vdpa_config_ops *ops = vdpa->config;
354+
355+
return ops->suspend;
356+
}
357+
350358
static long vhost_vdpa_get_features(struct vhost_vdpa *v, u64 __user *featurep)
351359
{
352360
struct vdpa_device *vdpa = v->vdpa;
@@ -577,7 +585,11 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
577585
if (cmd == VHOST_SET_BACKEND_FEATURES) {
578586
if (copy_from_user(&features, featurep, sizeof(features)))
579587
return -EFAULT;
580-
if (features & ~VHOST_VDPA_BACKEND_FEATURES)
588+
if (features & ~(VHOST_VDPA_BACKEND_FEATURES |
589+
BIT_ULL(VHOST_BACKEND_F_SUSPEND)))
590+
return -EOPNOTSUPP;
591+
if ((features & BIT_ULL(VHOST_BACKEND_F_SUSPEND)) &&
592+
!vhost_vdpa_can_suspend(v))
581593
return -EOPNOTSUPP;
582594
vhost_set_backend_features(&v->vdev, features);
583595
return 0;
@@ -628,6 +640,8 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
628640
break;
629641
case VHOST_GET_BACKEND_FEATURES:
630642
features = VHOST_VDPA_BACKEND_FEATURES;
643+
if (vhost_vdpa_can_suspend(v))
644+
features |= BIT_ULL(VHOST_BACKEND_F_SUSPEND);
631645
if (copy_to_user(featurep, &features, sizeof(features)))
632646
r = -EFAULT;
633647
break;

include/uapi/linux/vhost_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,7 @@ struct vhost_vdpa_iova_range {
161161
* message
162162
*/
163163
#define VHOST_BACKEND_F_IOTLB_ASID 0x3
164+
/* Device can be suspended */
165+
#define VHOST_BACKEND_F_SUSPEND 0x4
164166

165167
#endif

0 commit comments

Comments
 (0)