You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
iommu: Prevent RESV_DIRECT devices from blocking domains
The IOMMU_RESV_DIRECT flag indicates that a memory region must be mapped
1:1 at all times. This means that the region must always be accessible to
the device, even if the device is attached to a blocking domain. This is
equal to saying that IOMMU_RESV_DIRECT flag prevents devices from being
attached to blocking domains.
This also implies that devices that implement RESV_DIRECT regions will be
prevented from being assigned to user space since taking the DMA ownership
immediately switches to a blocking domain.
The rule of preventing devices with the IOMMU_RESV_DIRECT regions from
being assigned to user space has existed in the Intel IOMMU driver for
a long time. Now, this rule is being lifted up to a general core rule,
as other architectures like AMD and ARM also have RMRR-like reserved
regions. This has been discussed in the community mailing list and refer
to below link for more details.
Other places using unmanaged domains for kernel DMA must follow the
iommu_get_resv_regions() and setup IOMMU_RESV_DIRECT - we do not restrict
them in the core code.
Cc: Robin Murphy <[email protected]>
Cc: Alex Williamson <[email protected]>
Cc: Kevin Tian <[email protected]>
Signed-off-by: Jason Gunthorpe <[email protected]>
Link: https://lore.kernel.org/linux-iommu/BN9PR11MB5276E84229B5BD952D78E9598C639@BN9PR11MB5276.namprd11.prod.outlook.com
Signed-off-by: Lu Baolu <[email protected]>
Reviewed-by: Jason Gunthorpe <[email protected]>
Acked-by: Joerg Roedel <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Joerg Roedel <[email protected]>
if (WARN_ON_ONCE(iommu_is_dma_domain(domain) && !pg_size))
967
+
return-EINVAL;
968
+
971
969
iommu_get_resv_regions(dev, &mappings);
972
970
973
971
/* We need to consider overlapping regions for different devices */
974
972
list_for_each_entry(entry, &mappings, list) {
975
973
dma_addr_tstart, end, addr;
976
974
size_tmap_size=0;
977
975
978
-
start=ALIGN(entry->start, pg_size);
979
-
end=ALIGN(entry->start+entry->length, pg_size);
976
+
if(entry->type==IOMMU_RESV_DIRECT)
977
+
dev->iommu->require_direct=1;
980
978
981
-
if (entry->type!=IOMMU_RESV_DIRECT&&
982
-
entry->type!=IOMMU_RESV_DIRECT_RELAXABLE)
979
+
if ((entry->type!=IOMMU_RESV_DIRECT&&
980
+
entry->type!=IOMMU_RESV_DIRECT_RELAXABLE) ||
981
+
!iommu_is_dma_domain(domain))
983
982
continue;
984
983
984
+
start=ALIGN(entry->start, pg_size);
985
+
end=ALIGN(entry->start+entry->length, pg_size);
986
+
985
987
for (addr=start; addr <= end; addr+=pg_size) {
986
988
phys_addr_tphys_addr;
987
989
@@ -2122,6 +2124,21 @@ static int __iommu_device_set_domain(struct iommu_group *group,
2122
2124
{
2123
2125
intret;
2124
2126
2127
+
/*
2128
+
* If the device requires IOMMU_RESV_DIRECT then we cannot allow
2129
+
* the blocking domain to be attached as it does not contain the
2130
+
* required 1:1 mapping. This test effectively excludes the device
2131
+
* being used with iommu_group_claim_dma_owner() which will block
2132
+
* vfio and iommufd as well.
2133
+
*/
2134
+
if (dev->iommu->require_direct&&
2135
+
(new_domain->type==IOMMU_DOMAIN_BLOCKED||
2136
+
new_domain==group->blocking_domain)) {
2137
+
dev_warn(dev,
2138
+
"Firmware has requested this device have a 1:1 IOMMU mapping, rejecting configuring the device without a 1:1 mapping. Contact your platform vendor.\n");
0 commit comments