From: "Liu, Yi L" <yi.l.liu@xxxxxxxxxxxxxxx> This patch adds VFIO_IOMMU_BIND_GUEST_STAGE ioctl which aims at passing the virtual iommu guest configuration to the VFIO driver downto to the iommu subsystem. Signed-off-by: Jacob Pan <jacob.jun.pan@xxxxxxxxxxxxxxx> Signed-off-by: Liu, Yi L <yi.l.liu@xxxxxxxxxxxxxxx> Signed-off-by: Eric Auger <eric.auger@xxxxxxxxxx> --- for SMMUV3 S1 config data passing the device parameter is not needed. --- drivers/vfio/vfio_iommu_type1.c | 56 +++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/vfio.h | 8 ++++++ 2 files changed, 64 insertions(+) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index d9fd318..83c7f96 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -1673,6 +1673,48 @@ static int vfio_domains_have_iommu_cache(struct vfio_iommu *iommu) return ret; } +struct vfio_iommu_task { + struct iommu_domain *domain; + void *payload; +}; + +static int bind_guest_stage_fn(struct device *dev, void *data) +{ + struct vfio_iommu_type1_bind_guest_stage *ustruct; + struct vfio_iommu_task *task = data; + + ustruct = task->payload; + return iommu_bind_guest_stage(task->domain, dev, &ustruct->config); +} + +static int vfio_iommu_dispatch_task(struct vfio_iommu *iommu, void *data, + int (*fn)(struct device *, void *)) +{ + int ret = 0; + struct vfio_domain *d; + struct vfio_group *g; + struct vfio_iommu_task task; + + task.payload = data; + + mutex_lock(&iommu->lock); + + list_for_each_entry(d, &iommu->domain_list, next) { + list_for_each_entry(g, &d->group_list, next) { + if (g->iommu_group != NULL) { + task.domain = d->domain; + ret = iommu_group_for_each_dev( + g->iommu_group, &task, fn); + if (ret != 0) + break; + } + } + } + + mutex_unlock(&iommu->lock); + return ret; +} + static long vfio_iommu_type1_ioctl(void *iommu_data, unsigned int cmd, unsigned long arg) { @@ -1743,6 +1785,20 @@ static long vfio_iommu_type1_ioctl(void *iommu_data, return copy_to_user((void __user *)arg, &unmap, minsz) ? -EFAULT : 0; + } else if (cmd == VFIO_IOMMU_BIND_GUEST_STAGE) { + struct vfio_iommu_type1_bind_guest_stage ustruct; + + minsz = offsetofend(struct vfio_iommu_type1_bind_guest_stage, + config); + + if (copy_from_user(&ustruct, (void __user *)arg, minsz)) + return -EFAULT; + + if (ustruct.argsz < minsz || ustruct.flags) + return -EINVAL; + + return vfio_iommu_dispatch_task(iommu, (u8 *)&ustruct, + bind_guest_stage_fn); } return -ENOTTY; diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 1aa7b82..a5801ed 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -14,6 +14,7 @@ #include <linux/types.h> #include <linux/ioctl.h> +#include <linux/iommu.h> #define VFIO_API_VERSION 0 @@ -665,6 +666,13 @@ struct vfio_iommu_type1_dma_unmap { #define VFIO_IOMMU_ENABLE _IO(VFIO_TYPE, VFIO_BASE + 15) #define VFIO_IOMMU_DISABLE _IO(VFIO_TYPE, VFIO_BASE + 16) +struct vfio_iommu_type1_bind_guest_stage { + __u32 argsz; + __u32 flags; + struct iommu_guest_stage_config config; +}; +#define VFIO_IOMMU_BIND_GUEST_STAGE _IO(VFIO_TYPE, VFIO_BASE + 22) + /* -------- Additional API for SPAPR TCE (Server POWERPC) IOMMU -------- */ /* -- 2.5.5 _______________________________________________ kvmarm mailing list kvmarm@xxxxxxxxxxxxxxxxxxxxx https://lists.cs.columbia.edu/mailman/listinfo/kvmarm