iommu: Enable per-device SSID space for SVA
Subsystems (2)
RFC PATCH 1/1 iommu: Enable per-device SSID space for SVA
For SVA, the IOMMU core always allocates PASID from the global PASID space. The use of this global PASID space comes from the limitation of the ENQCMD instruction in Intel CPUs that it fetches its PASID operand from IA32_PASID, which is per-task.
Due to this nature, SVA with ARM SMMU v3 has been found not working in our environment when other modules/devices compete for PASID. The environment looks as follows:
- The device is not a PCIe device.
- The device is to use SVA.
- The supported SSID/PASID space is very small for the device; only 1 to 3 SSIDs are supported.
- There is a custom way of transmitting the SSID from the kernel to the device.
With this setup, when other modules have allocated all the PASIDs that our device is expected to use from the global PASID space via APIs like iommu_alloc_global_pasid() or iommu_sva_bind_device(), SVA binding to our device fails due to the lack of available PASIDs.
Since SSID/PASID is supported per-SID in ARM SMMU v3, this commit leverages the fact and lifts the use of the global PASID space if possible. What it does includes:
- Introduce a new IOMMU capability IOMMU_CAP_PER_DEV_PASID_SPACE, which represents whether the IOMMU supports an independent PASID space per- device, not shared across devices. ARM SMMU v3 is the case.
- Open a new API iommu_attach_device_pasid_any() to allocate any available PASID and attach an IOMMU domain to it.
- Opt out the use of the global PASID space for SVA if the IOMMU has that capability, and use the new API to allocate a PASID in that case.
---
v1: Request comments for this approach, other possible approaches and/or
other aspects to consider more. Code is not sanitized and commits are not separated appropriately in this version.
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 2 + drivers/iommu/iommu-sva.c | 44 +++++++---- drivers/iommu/iommu.c | 85 ++++++++++++++++++++- include/linux/iommu.h | 5 ++ 4 files changed, 121 insertions(+), 15 deletions(-)
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +2 -0
@@ -2494,6 +2494,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_PER_DEV_PASID_SPACE : +return true;default :return false; }
drivers/iommu/iommu-sva.c +30 -14
75 lines not on this page · raw message
drivers/iommu/iommu.c +84 -1
97 lines not on this page · raw message
include/linux/iommu.h +5 -0
@@ -271,6 +271,7 @@ enum iommu_cap {*/ IOMMU_CAP_DEFERRED_FLUSH ,IOMMU_CAP_DIRTY_TRACKING ,/* IOMMU supports dirty tracking */ + IOMMU_CAP_PER_DEV_PASID_SPACE, /* IOMMU supports per-device PASID space */ };/* These are the possible reserved region types */
@@ -1136,6 +1137,7 @@ struct iommu_sva {struct iommu_mm_data {u32 pasid; +bool pasid_global;struct mm_struct *mm;struct list_head sva_domains;struct list_head mm_list_elm;
@@ -1184,6 +1186,9 @@ void iommu_device_release_dma_owner(struct device *dev);int iommu_attach_device_pasid (struct iommu_domain *domain,struct device *dev,ioasid_t pasid,struct iommu_attach_handle *handle); +int iommu_attach_device_pasid_any (struct iommu_domain *domain, +struct device *dev,ioasid_t *pasid, +struct iommu_attach_handle *handle);void iommu_detach_device_pasid (struct iommu_domain *domain,struct device *dev,ioasid_t pasid);ioasid_t iommu_alloc_global_pasid (struct device *dev);
Signature · 1 line
2.54.0.545.g6539524ca2-goog
Quoted 33 lines
For SVA, the IOMMU core always allocates PASID from the global PASID space. The use of this global PASID space comes from the limitation of the ENQCMD instruction in Intel CPUs that it fetches its PASID operand from
IA32_PASID, which is per-task.Due to this nature, SVA with ARM SMMU v3 has been found not working in our environment when other modules/devices compete for PASID. The environment looks as follows:
- The device is not a PCIe device.
- The device is to use SVA.
- The supported SSID/PASID space is very small for the device; only 1 to 3 SSIDs are supported.
- There is a custom way of transmitting the SSID from the kernel to the device.With this setup, when other modules have allocated all the PASIDs that our device is expected to use from the global PASID space via APIs like
iommu_alloc_global_pasid()oriommu_sva_bind_device(), SVA binding to our device fails due to the lack of available PASIDs.Since SSID/PASID is supported per-SID in ARM SMMU v3, this commit leverages the fact and lifts the use of the global PASID space if possible. What it does includes:
- Introduce a new IOMMU capability
IOMMU_CAP_PER_DEV_PASID_SPACE, which represents whether the IOMMU supports an independent PASID space per- device, not shared across devices. ARM SMMU v3 is the case.
- Open a new APIiommu_attach_device_pasid_any()to allocate any available PASID and attach an IOMMU domain to it.
- Opt out the use of the global PASID space for SVA if the IOMMU has that capability, and use the new API to allocate a PASID in that case.
Quoted 1 line
Signed-off-by Joonwon Kang <[email protected]>
Please disregard this RFC as I have sent a new one with more recipients.
Thanks,
Joonwon Kang