iommu: Report effective PCIe ATS support status
Subsystems (5)
v2 cover iommu: Report effective PCIe ATS support status
Hi,
Changes from v1:
https://lore.kernel.org/all/[email protected]/
- Addressed feedback and picked up R-by tags. Thanks!
- Inverted flag to IOMMU_CAP_PCI_ATS_SUPPORTED for IOMMU drivers(patch #1).
- Updated comments and commit messages to clarify the semantics.
---
PCIe ATS may be disabled by platform firmware, root complex limitations, or host kernel policy, even when a device advertises the ATS capability in its PCI config space.
Userspace currently cannot determine whether ATS is effectively supported for a device. This may lead to incorrect assumptions when ATS appears present in PCI config space but is disabled by the platform, e.g., in use cases such as VFIO device pass-through.
This series introduces a new IOMMU capability, IOMMU_CAP_PCI_ATS_SUPPORTED, to allow drivers to report the effective ATS decision for a device. It also extends iommufd to expose this information via IOMMU_GET_HW_INFO.
For UAPI compatibility, the iommufd interface exposes this as a negative capability, IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED. On older kernels the flag will be absent, and userspace will retain the existing behaviour (i.e. assume ATS is usable if advertised via PCIe CAP).
Please see the related QEMU discussion for SMMUv3 accelerator use case here[0].
Please take a look and let me know.
Thanks,
Shameer
Shameer Kolothum (2):
iommu: Add device ATS supported capability
iommufd: Report ATS not supported status via IOMMU_GET_HW_INFO
include/linux/iommu.h | 2 ++ include/uapi/linux/iommufd.h | 4 ++++ drivers/iommu/amd/iommu.c | 6 ++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 3 +++ drivers/iommu/intel/iommu.c | 2 ++ drivers/iommu/iommufd/device.c | 4 ++++ 6 files changed, 21 insertions(+)
Signature · 1 line
2.43.0
PATCH v2 1/2 iommu: Add device ATS supported capability
PCIe ATS may be disabled by platform firmware, root complex limitations, or kernel policy even when a device advertises the ATS capability in its PCI configuration space.
Add a new IOMMU_CAP_PCI_ATS_SUPPORTED capability to allow IOMMU drivers to report the effective ATS decision for a device.
When this capability is true for a device, ATS may be enabled for that device, but it does not imply that ATS is currently enabled.
A subsequent patch will extend iommufd to expose the effective ATS status to userspace.
--- include/linux/iommu.h | 2 ++ drivers/iommu/amd/iommu.c | 6 ++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 3 +++ drivers/iommu/intel/iommu.c | 2 ++ 4 files changed, 13 insertions(+)
include/linux/iommu.h +2 -0
@@ -271,6 +271,8 @@ enum iommu_cap {*/ IOMMU_CAP_DEFERRED_FLUSH ,IOMMU_CAP_DIRTY_TRACKING ,/* IOMMU supports dirty tracking */ +/* ATS is supported and may be enabled for this device */ + IOMMU_CAP_PCI_ATS_SUPPORTED, };/* These are the possible reserved region types */
drivers/iommu/amd/iommu.c +6 -0
@@ -2985,6 +2985,12 @@ static bool amd_iommu_capable(struct device *dev, enum iommu_cap cap)return amd_iommu_hd_support (iommu); } +case IOMMU_CAP_PCI_ATS_SUPPORTED : { +struct iommu_dev_data *dev_data =dev_iommu_priv_get (dev); + +return amd_iommu_iotlb_sup && + (dev_data->flags &AMD_IOMMU_DEVICE_FLAG_ATS_SUP ); + }default :break ; }
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +3 -0
@@ -107,6 +107,7 @@ static const char * const event_class_str[] = { };static int arm_smmu_alloc_cd_tables (struct arm_smmu_master *master); +static bool arm_smmu_ats_supported (struct arm_smmu_master *master);static void parse_driver_options (struct arm_smmu_device *smmu) {
@@ -2494,6 +2495,8 @@ static bool arm_smmu_capable(struct device *dev, enum iommu_cap cap)return true;case IOMMU_CAP_DIRTY_TRACKING :return arm_smmu_dbm_capable (master->smmu); +case IOMMU_CAP_PCI_ATS_SUPPORTED : +return arm_smmu_ats_supported (master);default :return false; }
drivers/iommu/intel/iommu.c +2 -0
@@ -3220,6 +3220,8 @@ static bool intel_iommu_capable(struct device *dev, enum iommu_cap cap)return ecap_sc_support (info->iommu->ecap);case IOMMU_CAP_DIRTY_TRACKING :return ssads_supported (info->iommu); +case IOMMU_CAP_PCI_ATS_SUPPORTED : +return info->ats_supported;default :return false; }
Signature · 1 line
2.43.0
PATCH v2 2/2 iommufd: Report ATS not supported status via IOMMU_GET_HW_INFO
In reply to Shameer KolothumIf the IOMMU driver reports that ATS is not supported for a device, set the IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED flag in the returned hardware capabilities.
This uses a negative flag for UAPI compatibility. Existing userspace assumes ATS is supported if no flag is present. This also ensures that new userspace works correctly on both old and new kernels, where a zero value implies ATS support.
When this flag is set, ATS cannot be used for the device. When it is clear, ATS may be enabled when an appropriate HWPT is attached.
--- include/uapi/linux/iommufd.h | 4 ++++ drivers/iommu/iommufd/device.c | 4 ++++ 2 files changed, 8 insertions(+)
include/uapi/linux/iommufd.h +4 -0
@@ -695,11 +695,15 @@ enum iommu_hw_info_type {* @IOMMU_HW_CAP_PCI_PASID_PRIV: Privileged Mode Supported, user ignores it * when the struct * iommu_hw_info::out_max_pasid_log2 is zero. +* @IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED: ATS is not supported or cannot be used +* on this device (absence implies ATS +* may be enabled) */ enum iommufd_hw_capabilities {IOMMU_HW_CAP_DIRTY_TRACKING =1 <<0 ,IOMMU_HW_CAP_PCI_PASID_EXEC =1 <<1 ,IOMMU_HW_CAP_PCI_PASID_PRIV =1 <<2 , +IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED =1 <<3 , };/**
drivers/iommu/iommufd/device.c +4 -0
@@ -1624,6 +1624,10 @@ int iommufd_get_hw_info(struct iommufd_ucmd *ucmd)if (device_iommu_capable (idev->dev,IOMMU_CAP_DIRTY_TRACKING )) cmd->out_capabilities |=IOMMU_HW_CAP_DIRTY_TRACKING ; +/* Report when ATS cannot be used for this device */ +if (!device_iommu_capable (idev->dev,IOMMU_CAP_PCI_ATS_SUPPORTED )) + cmd->out_capabilities |=IOMMU_HW_CAP_PCI_ATS_NOT_SUPPORTED ; + cmd->out_max_pasid_log2 =0 ;/* * Currently, all iommu drivers enable PASID in the probe_device()
Signature · 1 line
2.43.0
Quoted 11 lines · Shameer Kolothum
Shameer Kolothum (2):
iommu: Add device ATS supported capability
iommufd: Report ATS not supported status viaIOMMU_GET_HW_INFOinclude/linux/iommu.h | 2 ++ include/uapi/linux/iommufd.h | 4 ++++ drivers/iommu/amd/iommu.c | 6 ++++++ drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 3 +++ drivers/iommu/intel/iommu.c | 2 ++ drivers/iommu/iommufd/device.c | 4 ++++ 6 files changed, 21 insertions(+)
Applied, thanks.