Thread (45 messages) 45 messages, 6 authors, 2024-01-11

Re: [RFC v1 3/8] vhost: Add 3 new uapi to support iommufd

From: Cindy Lu <hidden>
Date: 2023-11-07 06:58:45
Also in: lkml

On Mon, Nov 6, 2023 at 3:30 PM Jason Wang [off-list ref] wrote:
On Sat, Nov 4, 2023 at 1:17 AM Cindy Lu [off-list ref] wrote:
quoted
VHOST_VDPA_SET_IOMMU_FD: bind the device to iommufd device

VDPA_DEVICE_ATTACH_IOMMUFD_AS: Attach a vdpa device to an iommufd
address space specified by IOAS id.

VDPA_DEVICE_DETACH_IOMMUFD_AS: Detach a vdpa device
from the iommufd address space

Signed-off-by: Cindy Lu <redacted>
---
[...]
quoted
diff --git a/include/uapi/linux/vhost.h b/include/uapi/linux/vhost.h
index f5c48b61ab62..07e1b2c443ca 100644
--- a/include/uapi/linux/vhost.h
+++ b/include/uapi/linux/vhost.h
@@ -219,4 +219,70 @@
  */
 #define VHOST_VDPA_RESUME              _IO(VHOST_VIRTIO, 0x7E)

+/* vhost_vdpa_set_iommufd
+ * Input parameters:
+ * @iommufd: file descriptor from /dev/iommu; pass -1 to unset
+ * @iommufd_ioasid: IOAS identifier returned from ioctl(IOMMU_IOAS_ALLOC)
+ * Output parameters:
+ * @out_dev_id: device identifier
+ */
+struct vhost_vdpa_set_iommufd {
+       __s32 iommufd;
+       __u32 iommufd_ioasid;
+       __u32 out_dev_id;
+};
+
+#define VHOST_VDPA_SET_IOMMU_FD \
+       _IOW(VHOST_VIRTIO, 0x7F, struct vhost_vdpa_set_iommufd)
+
+/*
+ * VDPA_DEVICE_ATTACH_IOMMUFD_AS -
+ * _IOW(VHOST_VIRTIO, 0x7f, struct vdpa_device_attach_iommufd_as)
+ *
+ * Attach a vdpa device to an iommufd address space specified by IOAS
+ * id.
+ *
+ * Available only after a device has been bound to iommufd via
+ * VHOST_VDPA_SET_IOMMU_FD
+ *
+ * Undo by VDPA_DEVICE_DETACH_IOMMUFD_AS or device fd close.
+ *
+ * @argsz:     user filled size of this data.
+ * @flags:     must be 0.
+ * @ioas_id:   Input the target id which can represent an ioas
+ *             allocated via iommufd subsystem.
+ *
+ * Return: 0 on success, -errno on failure.
+ */
+struct vdpa_device_attach_iommufd_as {
+       __u32 argsz;
+       __u32 flags;
+       __u32 ioas_id;
+};
I think we need to map ioas to vDPA AS, so there should be an ASID
from the view of vDPA?

Thanks
The qemu will have a structure save and  maintain this information,So
I didn't add this
 in kernel,we can add this but maybe only for check?
this in
Thanks
Cindy
quoted
+
+#define VDPA_DEVICE_ATTACH_IOMMUFD_AS \
+       _IOW(VHOST_VIRTIO, 0x82, struct vdpa_device_attach_iommufd_as)
+
+/*
+ * VDPA_DEVICE_DETACH_IOMMUFD_AS
+ *
+ * Detach a vdpa device from the iommufd address space it has been
+ * attached to. After it, device should be in a blocking DMA state.
+ *
+ * Available only after a device has been bound to iommufd via
+ * VHOST_VDPA_SET_IOMMU_FD
+ *
+ * @argsz:     user filled size of this data.
+ * @flags:     must be 0.
+ *
+ * Return: 0 on success, -errno on failure.
+ */
+struct vdpa_device_detach_iommufd_as {
+       __u32 argsz;
+       __u32 flags;
+};
+
+#define VDPA_DEVICE_DETACH_IOMMUFD_AS \
+       _IOW(VHOST_VIRTIO, 0x83, struct vdpa_device_detach_iommufd_as)
+
 #endif
--
2.34.3
  
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help