Skip to content

Commit c5a5dc4

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Don't switch off swiotlb if bounce page is used
The bounce page implementation depends on swiotlb. Hence, don't switch off swiotlb if the system has untrusted devices or could potentially be hot-added with any untrusted devices. Cc: Ashok Raj <[email protected]> Cc: Jacob Pan <[email protected]> Cc: Kevin Tian <[email protected]> Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Joerg Roedel <[email protected]>
1 parent e5e04d0 commit c5a5dc4

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

drivers/iommu/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ config INTEL_IOMMU
182182
select IOMMU_IOVA
183183
select NEED_DMA_MAP_STATE
184184
select DMAR_TABLE
185+
select SWIOTLB
185186
help
186187
DMA remapping (DMAR) devices support enables independent address
187188
translations for Direct Memory Access (DMA) from devices.

drivers/iommu/intel-iommu.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4547,22 +4547,20 @@ const struct attribute_group *intel_iommu_groups[] = {
45474547
NULL,
45484548
};
45494549

4550-
static int __init platform_optin_force_iommu(void)
4550+
static inline bool has_untrusted_dev(void)
45514551
{
45524552
struct pci_dev *pdev = NULL;
4553-
bool has_untrusted_dev = false;
45544553

4555-
if (!dmar_platform_optin() || no_platform_optin)
4556-
return 0;
4554+
for_each_pci_dev(pdev)
4555+
if (pdev->untrusted)
4556+
return true;
45574557

4558-
for_each_pci_dev(pdev) {
4559-
if (pdev->untrusted) {
4560-
has_untrusted_dev = true;
4561-
break;
4562-
}
4563-
}
4558+
return false;
4559+
}
45644560

4565-
if (!has_untrusted_dev)
4561+
static int __init platform_optin_force_iommu(void)
4562+
{
4563+
if (!dmar_platform_optin() || no_platform_optin || !has_untrusted_dev())
45664564
return 0;
45674565

45684566
if (no_iommu || dmar_disabled)
@@ -4576,9 +4574,6 @@ static int __init platform_optin_force_iommu(void)
45764574
iommu_identity_mapping |= IDENTMAP_ALL;
45774575

45784576
dmar_disabled = 0;
4579-
#if defined(CONFIG_X86) && defined(CONFIG_SWIOTLB)
4580-
swiotlb = 0;
4581-
#endif
45824577
no_iommu = 0;
45834578

45844579
return 1;
@@ -4718,7 +4713,14 @@ int __init intel_iommu_init(void)
47184713
up_write(&dmar_global_lock);
47194714

47204715
#if defined(CONFIG_X86) && defined(CONFIG_SWIOTLB)
4721-
swiotlb = 0;
4716+
/*
4717+
* If the system has no untrusted device or the user has decided
4718+
* to disable the bounce page mechanisms, we don't need swiotlb.
4719+
* Mark this and the pre-allocated bounce pages will be released
4720+
* later.
4721+
*/
4722+
if (!has_untrusted_dev() || intel_no_bounce)
4723+
swiotlb = 0;
47224724
#endif
47234725
dma_ops = &intel_dma_ops;
47244726

0 commit comments

Comments
 (0)