[PATCH V2 6/7] vhost-vdpa: VHOST_BACKEND_F_IOTLB_REMAP

From: Steve Sistare
Date: Fri Jul 12 2024 - 09:20:33 EST


Add the VHOST_BACKEND_F_IOTLB_REMAP backend capability, which indicates
that VHOST_IOTLB_REMAP is supported.

If VHOST_BACKEND_F_IOTLB_REMAP is advertised, then the user must call
VHOST_IOTLB_REMAP after ownership of a device is transferred to a new
process via VHOST_NEW_OWNER. Disabling the feature during negotiation
does not negate this requirement.

Signed-off-by: Steve Sistare <steven.sistare@xxxxxxxxxx>
---
drivers/vhost/vdpa.c | 8 +++++++-
include/uapi/linux/vhost_types.h | 2 ++
2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index 51f71c45c4a9..1ec1f1382fd7 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -826,7 +826,8 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
BIT_ULL(VHOST_BACKEND_F_SUSPEND) |
BIT_ULL(VHOST_BACKEND_F_RESUME) |
BIT_ULL(VHOST_BACKEND_F_ENABLE_AFTER_DRIVER_OK) |
- BIT_ULL(VHOST_BACKEND_F_NEW_OWNER)))
+ BIT_ULL(VHOST_BACKEND_F_NEW_OWNER) |
+ BIT_ULL(VHOST_BACKEND_F_IOTLB_REMAP)))
return -EOPNOTSUPP;
if ((features & BIT_ULL(VHOST_BACKEND_F_SUSPEND)) &&
!vhost_vdpa_can_suspend(v))
@@ -1267,11 +1268,16 @@ static int vhost_vdpa_process_iotlb_remap(struct vhost_vdpa *v,
u64 start = msg->iova;
u64 last = start + msg->size - 1;
struct vhost_iotlb_map *map;
+ u64 features;
int r = 0;

if (msg->perm || !msg->size)
return -EINVAL;

+ features = ops->get_backend_features(vdpa);
+ if (!(features & BIT_ULL(VHOST_BACKEND_F_IOTLB_REMAP)))
+ return -EOPNOTSUPP;
+
map = vhost_iotlb_itree_first(iotlb, start, last);
if (!map)
return -ENOENT;
diff --git a/include/uapi/linux/vhost_types.h b/include/uapi/linux/vhost_types.h
index 35908315ff55..7e79e9bd0f7b 100644
--- a/include/uapi/linux/vhost_types.h
+++ b/include/uapi/linux/vhost_types.h
@@ -203,5 +203,7 @@ struct vhost_vdpa_iova_range {
#define VHOST_BACKEND_F_IOTLB_PERSIST 0x8
/* Supports VHOST_NEW_OWNER */
#define VHOST_BACKEND_F_NEW_OWNER 0x9
+/* Supports VHOST_IOTLB_REMAP */
+#define VHOST_BACKEND_F_IOTLB_REMAP 0xa

#endif
--
2.39.3