Skip to content

Commit 4989764

Browse files
committed
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: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Tested-by: Nicolin Chen <nicolinc@nvidia.com> Tested-by: Yi Liu <yi.l.liu@intel.com> Tested-by: Lixiao Yang <lixiao.yang@intel.com> Tested-by: Matthew Rosato <mjrosato@linux.ibm.com> Tested-by: Yu He <yu.he@intel.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 69e61ed commit 4989764

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

drivers/iommu/amd/iommu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2278,6 +2278,8 @@ static bool amd_iommu_capable(struct device *dev, enum iommu_cap cap)
22782278
return false;
22792279
case IOMMU_CAP_PRE_BOOT_PROTECTION:
22802280
return amdr_ivrs_remap_support;
2281+
case IOMMU_CAP_ENFORCE_CACHE_COHERENCY:
2282+
return true;
22812283
default:
22822284
break;
22832285
}

drivers/iommu/intel/iommu.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4450,14 +4450,20 @@ static bool intel_iommu_enforce_cache_coherency(struct iommu_domain *domain)
44504450

44514451
static bool intel_iommu_capable(struct device *dev, enum iommu_cap cap)
44524452
{
4453-
if (cap == IOMMU_CAP_CACHE_COHERENCY)
4453+
struct device_domain_info *info = dev_iommu_priv_get(dev);
4454+
4455+
switch (cap) {
4456+
case IOMMU_CAP_CACHE_COHERENCY:
44544457
return true;
4455-
if (cap == IOMMU_CAP_INTR_REMAP)
4458+
case IOMMU_CAP_INTR_REMAP:
44564459
return irq_remapping_enabled == 1;
4457-
if (cap == IOMMU_CAP_PRE_BOOT_PROTECTION)
4460+
case IOMMU_CAP_PRE_BOOT_PROTECTION:
44584461
return dmar_platform_optin();
4459-
4460-
return false;
4462+
case IOMMU_CAP_ENFORCE_CACHE_COHERENCY:
4463+
return ecap_sc_support(info->iommu->ecap);
4464+
default:
4465+
return false;
4466+
}
44614467
}
44624468

44634469
static struct iommu_device *intel_iommu_probe_device(struct device *dev)

include/linux/iommu.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ enum iommu_cap {
124124
IOMMU_CAP_NOEXEC, /* IOMMU_NOEXEC flag */
125125
IOMMU_CAP_PRE_BOOT_PROTECTION, /* Firmware says it used the IOMMU for
126126
DMA protection and we should too */
127+
/*
128+
* Per-device flag indicating if enforce_cache_coherency() will work on
129+
* this device.
130+
*/
131+
IOMMU_CAP_ENFORCE_CACHE_COHERENCY,
127132
};
128133

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

0 commit comments

Comments
 (0)