Skip to content

Commit 7db0d60

Browse files
siwliu-kernelmstsirkin
authored andcommitted
vhost-vdpa: introduce descriptor group backend feature
Userspace knows if the device has dedicated descriptor group or not by checking this feature bit. It's only exposed if the vdpa driver backend implements the .get_vq_desc_group() operation callback. Userspace trying to negotiate this feature when it or the dependent _F_IOTLB_ASID feature hasn't been exposed will result in an error. Signed-off-by: Si-Wei Liu <[email protected]> Acked-by: Eugenio Pérez <[email protected]> Acked-by: Jason Wang <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Reviewed-by: Si-Wei Liu <[email protected]> Tested-by: Si-Wei Liu <[email protected]> Tested-by: Lei Yang <[email protected]>
1 parent a72cac6 commit 7db0d60

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

drivers/vhost/vdpa.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,14 @@ static bool vhost_vdpa_can_resume(const struct vhost_vdpa *v)
389389
return ops->resume;
390390
}
391391

392+
static bool vhost_vdpa_has_desc_group(const struct vhost_vdpa *v)
393+
{
394+
struct vdpa_device *vdpa = v->vdpa;
395+
const struct vdpa_config_ops *ops = vdpa->config;
396+
397+
return ops->get_vq_desc_group;
398+
}
399+
392400
static long vhost_vdpa_get_features(struct vhost_vdpa *v, u64 __user *featurep)
393401
{
394402
struct vdpa_device *vdpa = v->vdpa;
@@ -690,6 +698,7 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
690698
if (copy_from_user(&features, featurep, sizeof(features)))
691699
return -EFAULT;
692700
if (features & ~(VHOST_VDPA_BACKEND_FEATURES |
701+
BIT_ULL(VHOST_BACKEND_F_DESC_ASID) |
693702
BIT_ULL(VHOST_BACKEND_F_SUSPEND) |
694703
BIT_ULL(VHOST_BACKEND_F_RESUME) |
695704
BIT_ULL(VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK)))
@@ -700,6 +709,12 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
700709
if ((features & BIT_ULL(VHOST_BACKEND_F_RESUME)) &&
701710
!vhost_vdpa_can_resume(v))
702711
return -EOPNOTSUPP;
712+
if ((features & BIT_ULL(VHOST_BACKEND_F_DESC_ASID)) &&
713+
!(features & BIT_ULL(VHOST_BACKEND_F_IOTLB_ASID)))
714+
return -EINVAL;
715+
if ((features & BIT_ULL(VHOST_BACKEND_F_DESC_ASID)) &&
716+
!vhost_vdpa_has_desc_group(v))
717+
return -EOPNOTSUPP;
703718
vhost_set_backend_features(&v->vdev, features);
704719
return 0;
705720
}
@@ -753,6 +768,8 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
753768
features |= BIT_ULL(VHOST_BACKEND_F_SUSPEND);
754769
if (vhost_vdpa_can_resume(v))
755770
features |= BIT_ULL(VHOST_BACKEND_F_RESUME);
771+
if (vhost_vdpa_has_desc_group(v))
772+
features |= BIT_ULL(VHOST_BACKEND_F_DESC_ASID);
756773
features |= vhost_vdpa_get_backend_features(v);
757774
if (copy_to_user(featurep, &features, sizeof(features)))
758775
r = -EFAULT;

include/uapi/linux/vhost_types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,5 +185,10 @@ struct vhost_vdpa_iova_range {
185185
* DRIVER_OK
186186
*/
187187
#define VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK 0x6
188+
/* Device may expose the virtqueue's descriptor area, driver area and
189+
* device area to a different group for ASID binding than where its
190+
* buffers may reside. Requires VHOST_BACKEND_F_IOTLB_ASID.
191+
*/
192+
#define VHOST_BACKEND_F_DESC_ASID 0x7
188193

189194
#endif

0 commit comments

Comments
 (0)