In the vfio/mdev use case of aux-domain, the subdevices are created from the physical devices with IOMMU_DEV_FEAT_AUX enabled and the aux-domains are attached to the subdevices through the iommu_ops.aux_attach_dev() interface.
Current iommu_ops.aux_at(de)tach_dev() design only takes the aux-domain and the physical device as the parameters, this is insufficient if we want the vendor iommu drivers to learn the knowledge about relationships between the aux-domains and the subdevices. Add a @subdev parameter to iommu_ops.aux_at(de)tach_dev() interfaces so that a subdevice could be opt-in. Signed-off-by: Lu Baolu <baolu...@linux.intel.com> --- drivers/iommu/intel/iommu.c | 10 ++++++---- drivers/iommu/iommu.c | 26 +++++++++++++++++--------- include/linux/iommu.h | 6 ++++-- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 1b7d390beb68..86142ce32f21 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -5353,8 +5353,9 @@ static int intel_iommu_attach_device(struct iommu_domain *domain, return domain_add_dev_info(to_dmar_domain(domain), dev); } -static int intel_iommu_aux_attach_device(struct iommu_domain *domain, - struct device *dev) +static int +intel_iommu_aux_attach_device(struct iommu_domain *domain, + struct device *dev, struct device *subdev) { int ret; @@ -5374,8 +5375,9 @@ static void intel_iommu_detach_device(struct iommu_domain *domain, dmar_remove_one_dev_info(dev); } -static void intel_iommu_aux_detach_device(struct iommu_domain *domain, - struct device *dev) +static void +intel_iommu_aux_detach_device(struct iommu_domain *domain, struct device *dev, + struct device *subdev) { aux_domain_remove_dev(to_dmar_domain(domain), dev); } diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 6c14c88cd525..4c6e94682327 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -2714,7 +2714,7 @@ bool iommu_dev_feature_enabled(struct device *dev, enum iommu_dev_features feat) EXPORT_SYMBOL_GPL(iommu_dev_feature_enabled); /* - * Aux-domain specific attach/detach. + * Aux-domain specific interfaces. * * Only works if iommu_dev_feature_enabled(dev, IOMMU_DEV_FEAT_AUX) returns * true. Also, as long as domains are attached to a device through this @@ -2722,36 +2722,44 @@ EXPORT_SYMBOL_GPL(iommu_dev_feature_enabled); * (iommu_detach_device() can't fail, so we fail when trying to re-attach). * This should make us safe against a device being attached to a guest as a * whole while there are still pasid users on it (aux and sva). + * + * Some physical devices can be configured to generate several subdevices. + * The modern IOMMUs support the identification and isolation of these + * subdevices. Hence they could be passed through to users space. VFIO/mdev + * provides a generic framework for subdevice passthrough. Below interfaces + * support such use case. Generally, among the parameters of the following + * aux-domain specific functions, @physdev represents a physical device, + * and @subdev represents a subdevice. */ -int iommu_aux_attach_device(struct iommu_domain *domain, struct device *dev) +int iommu_aux_attach_device(struct iommu_domain *domain, struct device *physdev) { int ret = -ENODEV; if (domain->ops->aux_attach_dev) - ret = domain->ops->aux_attach_dev(domain, dev); + ret = domain->ops->aux_attach_dev(domain, physdev, NULL); if (!ret) - trace_attach_device_to_domain(dev); + trace_attach_device_to_domain(physdev); return ret; } EXPORT_SYMBOL_GPL(iommu_aux_attach_device); -void iommu_aux_detach_device(struct iommu_domain *domain, struct device *dev) +void iommu_aux_detach_device(struct iommu_domain *domain, struct device *physdev) { if (domain->ops->aux_detach_dev) { - domain->ops->aux_detach_dev(domain, dev); - trace_detach_device_from_domain(dev); + domain->ops->aux_detach_dev(domain, physdev, NULL); + trace_detach_device_from_domain(physdev); } } EXPORT_SYMBOL_GPL(iommu_aux_detach_device); -int iommu_aux_get_pasid(struct iommu_domain *domain, struct device *dev) +int iommu_aux_get_pasid(struct iommu_domain *domain, struct device *physdev) { int ret = -ENODEV; if (domain->ops->aux_get_pasid) - ret = domain->ops->aux_get_pasid(domain, dev); + ret = domain->ops->aux_get_pasid(domain, physdev); return ret; } diff --git a/include/linux/iommu.h b/include/linux/iommu.h index 2ad26d8b4ab9..56297b4bbd0e 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -279,8 +279,10 @@ struct iommu_ops { int (*dev_disable_feat)(struct device *dev, enum iommu_dev_features f); /* Aux-domain specific attach/detach entries */ - int (*aux_attach_dev)(struct iommu_domain *domain, struct device *dev); - void (*aux_detach_dev)(struct iommu_domain *domain, struct device *dev); + int (*aux_attach_dev)(struct iommu_domain *domain, struct device *physdev, + struct device *subdev); + void (*aux_detach_dev)(struct iommu_domain *domain, struct device *physdev, + struct device *subdev); int (*aux_get_pasid)(struct iommu_domain *domain, struct device *dev); struct iommu_sva *(*sva_bind)(struct device *dev, struct mm_struct *mm, -- 2.17.1 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu