[PATCH] x86/pci-dma: swiotlb: Fix a regression since 5.19.0 about iommu=soft kernel parameter

Julien ROBIN posted 1 patch 1 month, 2 weeks ago
There is a newer version of this series
arch/x86/kernel/pci-dma.c | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
[PATCH] x86/pci-dma: swiotlb: Fix a regression since 5.19.0 about iommu=soft kernel parameter
Posted by Julien ROBIN 1 month, 2 weeks ago
The following patch fixes a regression introduced since linux-5.19.0 about
kernel parameter "iommu=soft" which, according to kernel-parameters.txt,
is expected to enable the use of software bounce buffering (SWIOTLB) and to
prevent the usage of an available hardware IOMMU.

Since linux-5.19.0 however, iommu=soft doesn't prevent anymore the usage of
hardware IOMMU implementations, and at least when an AMD GART IOMMU is
available, SWIOTLB even gets disabled by "amd_gart_64.c" despite the
iommu=soft parameter.

The issue is fixed by adding an "x86_soft_iommu_only" variable which is set
when the iommu=soft parameter is found and processed.
If the variable is set, hardware IOMMU detection and allocation is skipped,
as these detection and allocation functions could overwrite both
x86_init.iommu.iommu_init and x86_platform.iommu_shutdown for later
initialization and shutdown of these hardware IOMMU implementations.

When the iommu=soft parameter isn't provided however, the behavior of the
kernel is left untouched by this patch.

Patch applies from 5.19.0 to 6.19.0, based on mainline as of 2026-02-12.
Successfully tested this fix with iommu=soft parameter on linux-6.1.163 and
linux-6.19.0 on a Gigabyte 990FXA-UD3 based computer.

Tested the fix and iommu=soft parameter on linux-6.19 on these 4 machines:
Gigabyte 990FXA-UD3 motherboard based computer (AMD FX9590 CPU)
Asus TUF B550-PLUS motherboard based computer (AMD Ryzen 5 3700X CPU)
HP Victus 16-s1034nf / 8C9C laptop (AMD Ryzen 5 8645HS CPU)
Asus X550JK laptop (Intel Core i5-4200H CPU)

On the 1st this successfully disables AMD GART IOMMU and enables SWIOTLB.
On the 2nd this allows disabling AMD-Vi but SWIOTLB was already enabled.
Same for the 3rd one.
On the 4th there was no hardware IOMMU enabled, and SWIOTLB was already
enabled too: no resulting change for this laptop.

Signed-off-by: Julien ROBIN <julien.robin28@free.fr>
---
 arch/x86/kernel/pci-dma.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c
index 6267363e0189..c8762d4f8d54 100644
--- a/arch/x86/kernel/pci-dma.c
+++ b/arch/x86/kernel/pci-dma.c
@@ -34,6 +34,7 @@ int force_iommu __read_mostly = 0;
 int iommu_merge __read_mostly = 0;
 
 int no_iommu __read_mostly;
+int x86_soft_iommu_only __read_mostly;
 /* Set this to 1 if there is a HW IOMMU in the system */
 int iommu_detected __read_mostly = 0;
 
@@ -102,9 +103,15 @@ void __init pci_iommu_alloc(void)
 		return;
 	}
 	pci_swiotlb_detect();
-	gart_iommu_hole_init();
-	amd_iommu_detect();
-	detect_intel_iommu();
+
+	if (x86_soft_iommu_only)
+		pr_info("PCI-DMA: skipping hardware IOMMU detection and allocation\n");
+	else {
+		gart_iommu_hole_init();
+		amd_iommu_detect();
+		detect_intel_iommu();
+	}
+
 	swiotlb_init(x86_swiotlb_enable, x86_swiotlb_flags);
 }
 
@@ -151,8 +158,10 @@ static __init int iommu_setup(char *p)
 			return 1;
 		}
 #ifdef CONFIG_SWIOTLB
-		if (!strncmp(p, "soft", 4))
+		if (!strncmp(p, "soft", 4)) {
 			x86_swiotlb_enable = true;
+			x86_soft_iommu_only = 1;
+		}
 #endif
 		if (!strncmp(p, "pt", 2))
 			iommu_set_default_passthrough(true);
Re: [PATCH] x86/pci-dma: swiotlb: Fix a regression since 5.19.0 about iommu=soft kernel parameter
Posted by kernel test robot 1 month, 2 weeks ago
Hi Julien,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tip/master]
[also build test WARNING on tip/x86/core tip/auto-latest linus/master v6.19 next-20260212]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Julien-ROBIN/x86-pci-dma-swiotlb-Fix-a-regression-since-5-19-0-about-iommu-soft-kernel-parameter/20260213-122547
base:   tip/master
patch link:    https://lore.kernel.org/r/16c95f65-17ee-4bbd-99b3-93406a7801c4%40free.fr
patch subject: [PATCH] x86/pci-dma: swiotlb: Fix a regression since 5.19.0 about iommu=soft kernel parameter
config: i386-randconfig-r132-20260213 (https://download.01.org/0day-ci/archive/20260213/202602132218.jy0N4aRs-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260213/202602132218.jy0N4aRs-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602132218.jy0N4aRs-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> arch/x86/kernel/pci-dma.c:37:5: sparse: sparse: symbol 'x86_soft_iommu_only' was not declared. Should it be static?

vim +/x86_soft_iommu_only +37 arch/x86/kernel/pci-dma.c

    35	
    36	int no_iommu __read_mostly;
  > 37	int x86_soft_iommu_only __read_mostly;
    38	/* Set this to 1 if there is a HW IOMMU in the system */
    39	int iommu_detected __read_mostly = 0;
    40	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH] x86/pci-dma: swiotlb: Fix a regression since 5.19.0 about iommu=soft kernel parameter
Posted by Julien ROBIN 1 month, 2 weeks ago
Hi kernel test robot and other folks,

Yes, my mistake, 'x86_soft_iommu_only' should have been static; I did the mistake by doing like what I saw around (but the new variable isn't used outside of its 'pci-dma.c' file). Sorry for having done this mistake in a so small patch.

I'll be sending a corrected version of this patch quickly.

Best regards,
Julien ROBIN


On 13/02/2026 3:51 PM, kernel test robot wrote:
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> [...]
> 
> sparse warnings: (new ones prefixed by >>)
>>> arch/x86/kernel/pci-dma.c:37:5: sparse: sparse: symbol 'x86_soft_iommu_only' was not declared. Should it be static?