Skip to contentSkip to conversation

iommu/vt-d: Fix incorrect pci_for_each_dma_alias() for non-PCI devices

PATCH In review Lu Baolu 2 participants 4 messages Oct 12, 2024 – Oct 14, 2024

Subsystems (3)
lore
Share & tools
lore

Lu Baolu

author maintainer
#0 lore raw

PATCH 1/1 iommu/vt-d: Fix incorrect pci_for_each_dma_alias() for non-PCI devices

Previously, the domain_context_clear() function incorrectly called pci_for_each_dma_alias() to set up context entries for non-PCI devices. This could lead to kernel hangs or other unexpected behavior.

Add a check to only call pci_for_each_dma_alias() for PCI devices. For non-PCI devices, domain_context_clear_one() is called directly.

Fixes 9a16ab9d6402 ("iommu/vt-d: Make context clearing consistent with context mapping")
---
 drivers/iommu/intel/iommu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/intel/iommu.c +3 -1
index 9f6b0780f2ef..e860bc9439a2 100644
@@ -3340,8 +3340,10 @@ static int domain_context_clear_one_cb(struct pci_dev *pdev, u16 alias, void *op
  */
 static void domain_context_clear(struct device_domain_info *info)
 {
-	if (!dev_is_pci(info->dev))
+	if (!dev_is_pci(info->dev)) {
 		domain_context_clear_one(info, info->bus, info->devfn);
+		return;
+	}
 
 	pci_for_each_dma_alias(to_pci_dev(info->dev),
 			       &domain_context_clear_one_cb, info);
Signature · 1 line
2.43.0
#1 lore raw

[+cc Marcin, Thorsten]

Quoted 9 lines · Lu Baolu

Previously, the domain_context_clear() function incorrectly called pci_for_each_dma_alias() to set up context entries for non-PCI devices. This could lead to kernel hangs or other unexpected behavior.

Add a check to only call pci_for_each_dma_alias() for PCI devices. For non-PCI devices, domain_context_clear_one() is called directly.

Likely the same problem reported earlier by Marcin at
https://bugzilla.kernel.org/show_bug.cgi?id=219349

Thanks to Thorsten for pointing this out.

Quoted 26 lines
Fixes 9a16ab9d6402 ("iommu/vt-d: Make context clearing consistent with context mapping")
---
 drivers/iommu/intel/iommu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iommu/intel/iommu.c +3 -1
index 9f6b0780f2ef..e860bc9439a2 100644
@@ -3340,8 +3340,10 @@ static int domain_context_clear_one_cb(struct pci_dev *pdev, u16 alias, void *op
  */
 static void domain_context_clear(struct device_domain_info *info)
 {
-	if (!dev_is_pci(info->dev))
+	if (!dev_is_pci(info->dev)) {
 		domain_context_clear_one(info, info->bus, info->devfn);
+		return;
+	}
 
 	pci_for_each_dma_alias(to_pci_dev(info->dev),
 			       &domain_context_clear_one_cb, info);
Signature · 1 line
2.43.0
author maintainer
#2 lore raw
In reply to Lu Baolu
Quoted 7 lines · Lu Baolu

Previously, the domain_context_clear() function incorrectly called pci_for_each_dma_alias() to set up context entries for non-PCI devices. This could lead to kernel hangs or other unexpected behavior.

Add a check to only call pci_for_each_dma_alias() for PCI devices. For non-PCI devices, domain_context_clear_one() is called directly.

Quoted 8 lines
Fixes 9a16ab9d6402 ("iommu/vt-d: Make context clearing consistent with context mapping")
---
  drivers/iommu/intel/iommu.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

Queued for v6.12-rc.

Thanks,
baolu

#3 lore raw

[+cc Marcin]

Quoted 17 lines · Baolu Lu
Quoted 7 lines · Lu Baolu

Previously, the domain_context_clear() function incorrectly called pci_for_each_dma_alias() to set up context entries for non-PCI devices. This could lead to kernel hangs or other unexpected behavior.

Add a check to only call pci_for_each_dma_alias() for PCI devices. For non-PCI devices, domain_context_clear_one() is called directly.

Quoted 8 lines
Fixes 9a16ab9d6402 ("iommu/vt-d: Make context clearing consistent with context mapping")
---
  drivers/iommu/intel/iommu.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 1 line

Queued for v6.12-rc.

Please include information about Marcin's report as well (assuming it is the same problem). Marcin did a LOT of work to report and bisect this, so both should be acknowledged here.

See https://bugzilla.kernel.org/show_bug.cgi?id=219349

Bjorn