Skip to content

Commit 1000dcc

Browse files
jgunthorpejoergroedel
authored andcommitted
iommu: Allow IOMMU_RESV_DIRECT to work on ARM
For now several ARM drivers do not allow mappings to be created until a domain is attached. This means they do not technically support IOMMU_RESV_DIRECT as it requires the 1:1 maps to work continuously. Currently if the platform requests these maps on ARM systems they are silently ignored. Work around this by trying again to establish the direct mappings after the domain is attached if the pre-attach attempt failed. In the long run the drivers will be fixed to fully setup domains when they are created without waiting for attachment. Reviewed-by: Lu Baolu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Tested-by: Heiko Stuebner <[email protected]> Tested-by: Niklas Schnelle <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent d99be00 commit 1000dcc

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

drivers/iommu/iommu.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,6 +2842,7 @@ static int iommu_setup_default_domain(struct iommu_group *group,
28422842
struct iommu_domain *old_dom = group->default_domain;
28432843
struct group_device *gdev;
28442844
struct iommu_domain *dom;
2845+
bool direct_failed;
28452846
int req_type;
28462847
int ret;
28472848

@@ -2875,8 +2876,15 @@ static int iommu_setup_default_domain(struct iommu_group *group,
28752876
* mapped before their device is attached, in order to guarantee
28762877
* continuity with any FW activity
28772878
*/
2878-
for_each_group_device(group, gdev)
2879-
iommu_create_device_direct_mappings(dom, gdev->dev);
2879+
direct_failed = false;
2880+
for_each_group_device(group, gdev) {
2881+
if (iommu_create_device_direct_mappings(dom, gdev->dev)) {
2882+
direct_failed = true;
2883+
dev_warn_once(
2884+
gdev->dev->iommu->iommu_dev->dev,
2885+
"IOMMU driver was not able to establish FW requested direct mapping.");
2886+
}
2887+
}
28802888

28812889
/* We must set default_domain early for __iommu_device_set_domain */
28822890
group->default_domain = dom;
@@ -2900,6 +2908,27 @@ static int iommu_setup_default_domain(struct iommu_group *group,
29002908
}
29012909
}
29022910

2911+
/*
2912+
* Drivers are supposed to allow mappings to be installed in a domain
2913+
* before device attachment, but some don't. Hack around this defect by
2914+
* trying again after attaching. If this happens it means the device
2915+
* will not continuously have the IOMMU_RESV_DIRECT map.
2916+
*/
2917+
if (direct_failed) {
2918+
for_each_group_device(group, gdev) {
2919+
ret = iommu_create_device_direct_mappings(dom, gdev->dev);
2920+
if (ret)
2921+
goto err_restore;
2922+
}
2923+
}
2924+
2925+
err_restore:
2926+
if (old_dom) {
2927+
__iommu_group_set_domain_internal(
2928+
group, old_dom, IOMMU_SET_DOMAIN_MUST_SUCCEED);
2929+
iommu_domain_free(dom);
2930+
old_dom = NULL;
2931+
}
29032932
out_free:
29042933
if (old_dom)
29052934
iommu_domain_free(old_dom);

0 commit comments

Comments
 (0)