Commit 4989764d authored by Jason Gunthorpe's avatar Jason Gunthorpe
Browse files

iommu: Add IOMMU_CAP_ENFORCE_CACHE_COHERENCY

This queries if a domain linked to a device should expect to support
enforce_cache_coherency() so iommufd can negotiate the rules for when a
domain should be shared or not.

For iommufd a device that declares IOMMU_CAP_ENFORCE_CACHE_COHERENCY will
not be attached to a domain that does not support it.

Link: https://lore.kernel.org/r/1-v6-a196d26f289e+11787-iommufd_jgg@nvidia.com


Reviewed-by: default avatarLu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Tested-by: default avatarNicolin Chen <nicolinc@nvidia.com>
Tested-by: default avatarYi Liu <yi.l.liu@intel.com>
Tested-by: default avatarLixiao Yang <lixiao.yang@intel.com>
Tested-by: default avatarMatthew Rosato <mjrosato@linux.ibm.com>
Tested-by: default avatarYu He <yu.he@intel.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 69e61ede
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -2278,6 +2278,8 @@ static bool amd_iommu_capable(struct device *dev, enum iommu_cap cap)
		return false;
		return false;
	case IOMMU_CAP_PRE_BOOT_PROTECTION:
	case IOMMU_CAP_PRE_BOOT_PROTECTION:
		return amdr_ivrs_remap_support;
		return amdr_ivrs_remap_support;
	case IOMMU_CAP_ENFORCE_CACHE_COHERENCY:
		return true;
	default:
	default:
		break;
		break;
	}
	}
+11 −5
Original line number Original line Diff line number Diff line
@@ -4450,15 +4450,21 @@ static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain)


static bool intel_iommu_capable(struct device *dev, enum iommu_cap cap)
static bool intel_iommu_capable(struct device *dev, enum iommu_cap cap)
{
{
	if (cap == IOMMU_CAP_CACHE_COHERENCY)
	struct device_domain_info *info = dev_iommu_priv_get(dev);

	switch (cap) {
	case IOMMU_CAP_CACHE_COHERENCY:
		return true;
		return true;
	if (cap == IOMMU_CAP_INTR_REMAP)
	case IOMMU_CAP_INTR_REMAP:
		return irq_remapping_enabled == 1;
		return irq_remapping_enabled == 1;
	if (cap == IOMMU_CAP_PRE_BOOT_PROTECTION)
	case IOMMU_CAP_PRE_BOOT_PROTECTION:
		return dmar_platform_optin();
		return dmar_platform_optin();

	case IOMMU_CAP_ENFORCE_CACHE_COHERENCY:
		return ecap_sc_support(info->iommu->ecap);
	default:
		return false;
		return false;
	}
	}
}


static struct iommu_device *intel_iommu_probe_device(struct device *dev)
static struct iommu_device *intel_iommu_probe_device(struct device *dev)
{
{
+5 −0
Original line number Original line Diff line number Diff line
@@ -124,6 +124,11 @@ enum iommu_cap {
	IOMMU_CAP_NOEXEC,		/* IOMMU_NOEXEC flag */
	IOMMU_CAP_NOEXEC,		/* IOMMU_NOEXEC flag */
	IOMMU_CAP_PRE_BOOT_PROTECTION,	/* Firmware says it used the IOMMU for
	IOMMU_CAP_PRE_BOOT_PROTECTION,	/* Firmware says it used the IOMMU for
					   DMA protection and we should too */
					   DMA protection and we should too */
	/*
	 * Per-device flag indicating if enforce_cache_coherency() will work on
	 * this device.
	 */
	IOMMU_CAP_ENFORCE_CACHE_COHERENCY,
};
};


/* These are the possible reserved region types */
/* These are the possible reserved region types */