To support iommufd, vdpa needs to save the ioas_id and the ASID, which need to be shared between all vhost_vdpa devices. So Add a pointer in VirtIODevice.
vdpa device need to init it when the dev start, Add all the vdpa device will read/write this same ptr. TODO: need to add a lock for read and write Signed-off-by: Cindy Lu <l...@redhat.com> --- include/hw/virtio/vhost-vdpa.h | 23 +++++++++++++++++++++++ include/hw/virtio/virtio.h | 5 +++++ 2 files changed, 28 insertions(+) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 7997f09a8d..309d4ffc70 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -18,6 +18,10 @@ #include "hw/virtio/vhost-shadow-virtqueue.h" #include "hw/virtio/virtio.h" #include "standard-headers/linux/vhost_types.h" +//#include "sysemu/iommufd.h" +#include "qemu/osdep.h" +#include "sysemu/sysemu.h" + /* * ASID dedicated to map guest's addresses. If SVQ is disabled it maps GPA to @@ -30,6 +34,8 @@ typedef struct VhostVDPAHostNotifier { void *addr; } VhostVDPAHostNotifier; +typedef struct IOMMUFDBackend IOMMUFDBackend; + typedef struct vhost_vdpa { int device_fd; int index; @@ -51,6 +57,23 @@ typedef struct vhost_vdpa { VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; + +typedef struct vdpa_iommufd { + IOMMUFDBackend *iommufd; + struct vhost_dev *dev; + /*ioas_id get from IOMMUFD, iommufd need to use this id to map,unmap*/ + uint32_t ioas_id; + /*ASID used for vq*/ + uint32_t asid; + __u32 devid; /*not use */ + __u32 hwptid; /*not use*/ + AddressSpace *as; + struct vdpa_iommufd *next; + // QLIST_ENTRY(vdpa_iommufd) iommufd_next; + +} VDPAIOMMUFDState; + + int vhost_vdpa_get_iova_range(int fd, struct vhost_vdpa_iova_range *iova_range); int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 77c6c55929..36b4783466 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -152,6 +152,11 @@ struct VirtIODevice uint8_t device_endian; bool use_guest_notifier_mask; AddressSpace *dma_as; + /*this is an ptr point to struct vdpa_iommufd, will change to QLIST if + * needed*/ + /*in this struct saved the ioas_id/ASID that we need to use in iommufd + map/unmap, this ioas_id/ASID will share between vqs,so we add the ptr here*/ + void *iommufd_ptr; QLIST_HEAD(, VirtQueue) *vector_queues; QTAILQ_ENTRY(VirtIODevice) next; EventNotifier config_notifier; -- 2.34.3