Skip to contentSkip to conversation

iommu/vt-d: Restore context entry setup order for aliased devices

PATCH In review Lu Baolu 3 participants 4 messages May 14, 2025 – May 16, 2025

Subsystems (2)
lore
Share & tools
lore

Lu Baolu

author maintainer
#0 lore raw

PATCH 1/1 iommu/vt-d: Restore context entry setup order for aliased devices

Commit 2031c469f816 ("iommu/vt-d: Add support for static identity domain") changed the context entry setup during domain attachment from a set-and-check policy to a clear-and-reset approach. This inadvertently introduced a regression affecting PCI aliased devices behind PCIe-to-PCI bridges.

Specifically, keyboard and touchpad stopped working on several Apple Macbooks with below messages:

kernel: platform pxa2xx-spi.3: Adding to iommu group 20
kernel: input: Apple SPI Keyboard as /devices/pci0000:00/0000:00:1e.3/pxa2xx-spi.3/spi_master/spi2/spi-APP000D:00/input/input0
kernel: DMAR: DRHD: handling fault status reg 3
kernel: DMAR: [DMA Read NO_PASID] Request device [00:1e.3] fault addr 0xffffa000 [fault reason 0x06] PTE Read access is not set
kernel: DMAR: DRHD: handling fault status reg 3
kernel: DMAR: [DMA Read NO_PASID] Request device [00:1e.3] fault addr 0xffffa000 [fault reason 0x06] PTE Read access is not set
kernel: applespi spi-APP000D:00: Error writing to device: 01 0e 00 00
kernel: DMAR: DRHD: handling fault status reg 3
kernel: DMAR: [DMA Read NO_PASID] Request device [00:1e.3] fault addr 0xffffa000 [fault reason 0x06] PTE Read access is not set
kernel: DMAR: DRHD: handling fault status reg 3
kernel: applespi spi-APP000D:00: Error writing to device: 01 0e 00 00

Fix this by restoring the previous context setup order.

Fixes 2031c469f816 ("iommu/vt-d: Add support for static identity domain")
---
 drivers/iommu/intel/iommu.c  | 11 +++++++++++
 drivers/iommu/intel/iommu.h  |  1 +
 drivers/iommu/intel/nested.c |  4 ++--
 3 files changed, 14 insertions(+), 2 deletions(-)
drivers/iommu/intel/iommu.c +11 -0
index 49530d5d8c85..7aa3932251b2 100644
@@ -1809,6 +1809,7 @@ static int dmar_domain_attach_device(struct dmar_domain *domain,
 		return ret;
 
 	info->domain = domain;
+	info->domain_attached = true;
 	spin_lock_irqsave(&domain->lock, flags);
 	list_add(&info->link, &domain->devices);
 	spin_unlock_irqrestore(&domain->lock, flags);
@@ -3206,6 +3207,10 @@ void device_block_translation(struct device *dev)
 	struct intel_iommu *iommu = info->iommu;
 	unsigned long flags;
 
+	/* Device in DMA blocking state. Noting to do. */
+	if (!info->domain_attached)
+		return;
+
 	if (info->domain)
 		cache_tag_unassign_domain(info->domain, dev, IOMMU_NO_PASID);
 
@@ -3217,6 +3222,9 @@ void device_block_translation(struct device *dev)
 			domain_context_clear(info);
 	}
 
+	/* Device now in DMA blocking state. */
+	info->domain_attached = false;
+
 	if (!info->domain)
 		return;
 
@@ -4302,6 +4310,9 @@ static int identity_domain_attach_dev(struct iommu_domain *domain, struct device
 	else
 		ret = device_setup_pass_through(dev);
 
+	if (!ret)
+		info->domain_attached = true;
+
 	return ret;
 }
 
drivers/iommu/intel/iommu.h +1 -0
index cbfb8bb4c94a..3ddbcc603de2 100644
@@ -774,6 +774,7 @@ struct device_domain_info {
 	u8 ats_supported:1;
 	u8 ats_enabled:1;
 	u8 dtlb_extra_inval:1;	/* Quirk for devices need extra flush */
+	u8 domain_attached:1;	/* Device has domain attached */
 	u8 ats_qdep;
 	unsigned int iopf_refcount;
 	struct device *dev; /* it's NULL for PCIe-to-PCI bridge */
drivers/iommu/intel/nested.c +2 -2
index d2a94025d0a0..fc312f649f9e 100644
@@ -27,8 +27,7 @@ static int intel_nested_attach_dev(struct iommu_domain *domain,
 	unsigned long flags;
 	int ret = 0;
 
-	if (info->domain)
-		device_block_translation(dev);
+	device_block_translation(dev);
 
 	if (iommu->agaw < dmar_domain->s2_domain->agaw) {
 		dev_err_ratelimited(dev, "Adjusted guest address width not compatible\n");
@@ -66,6 +65,7 @@ static int intel_nested_attach_dev(struct iommu_domain *domain,
 		goto disable_iopf;
 
 	info->domain = dmar_domain;
+	info->domain_attached = true;
 	spin_lock_irqsave(&dmar_domain->lock, flags);
 	list_add(&info->link, &dmar_domain->devices);
 	spin_unlock_irqrestore(&dmar_domain->lock, flags);
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 29 lines

From: Lu Baolu <[email protected]>
Sent: Wednesday, May 14, 2025 2:05 PM

Commit 2031c469f816 ("iommu/vt-d: Add support for static identity domain") changed the context entry setup during domain attachment from a set-and-check policy to a clear-and-reset approach. This inadvertently introduced a regression affecting PCI aliased devices behind PCIe-to-PCI bridges.

Specifically, keyboard and touchpad stopped working on several Apple Macbooks with below messages:

kernel: platform pxa2xx-spi.3: Adding to iommu group 20
kernel: input: Apple SPI Keyboard as /devices/pci0000:00/0000:00:1e.3/pxa2xx-spi.3/spi_master/spi2/spi-
APP000D:00/input/input0
kernel: DMAR: DRHD: handling fault status reg 3
kernel: DMAR: [DMA Read NO_PASID] Request device [00:1e.3] fault addr 0xffffa000 [fault reason 0x06] PTE Read access is not set
kernel: DMAR: DRHD: handling fault status reg 3
kernel: DMAR: [DMA Read NO_PASID] Request device [00:1e.3] fault addr 0xffffa000 [fault reason 0x06] PTE Read access is not set
kernel: applespi spi-APP000D:00: Error writing to device: 01 0e 00 00
kernel: DMAR: DRHD: handling fault status reg 3
kernel: DMAR: [DMA Read NO_PASID] Request device [00:1e.3] fault addr 0xffffa000 [fault reason 0x06] PTE Read access is not set
kernel: DMAR: DRHD: handling fault status reg 3
kernel: applespi spi-APP000D:00: Error writing to device: 01 0e 00 00

Quoted 6 lines

Fix this by restoring the previous context setup order.

Fixes 2031c469f816 ("iommu/vt-d: Add support for static identity domain")

[email protected]/

Reviewed-by on v1 1/1
#2 lore raw
In reply to Lu Baolu

Hi Baolu,

Quoted 5 lines · Lu Baolu

Commit 2031c469f816 ("iommu/vt-d: Add support for static identity domain") changed the context entry setup during domain attachment from a set-and-check policy to a clear-and-reset approach. This inadvertently introduced a regression affecting PCI aliased devices behind PCIe-to-PCI bridges.

I got what the patch does. But just bit confused on the above description. I didn't see the commit 2031c469f816 mentioned any policy thing on the context entry setup. To me, the problem looks to be that the info->domain is no more accurate to be used for checking if any domain is attached after the above commit. Maybe I missed something. feel free correct me.

Quoted 90 lines

Specifically, keyboard and touchpad stopped working on several Apple Macbooks with below messages:

kernel: platform pxa2xx-spi.3: Adding to iommu group 20
kernel: input: Apple SPI Keyboard as /devices/pci0000:00/0000:00:1e.3/pxa2xx-spi.3/spi_master/spi2/spi-APP000D:00/input/input0
kernel: DMAR: DRHD: handling fault status reg 3
kernel: DMAR: [DMA Read NO_PASID] Request device [00:1e.3] fault addr 0xffffa000 [fault reason 0x06] PTE Read access is not set
kernel: DMAR: DRHD: handling fault status reg 3
kernel: DMAR: [DMA Read NO_PASID] Request device [00:1e.3] fault addr 0xffffa000 [fault reason 0x06] PTE Read access is not set
kernel: applespi spi-APP000D:00: Error writing to device: 01 0e 00 00
kernel: DMAR: DRHD: handling fault status reg 3
kernel: DMAR: [DMA Read NO_PASID] Request device [00:1e.3] fault addr 0xffffa000 [fault reason 0x06] PTE Read access is not set
kernel: DMAR: DRHD: handling fault status reg 3
kernel: applespi spi-APP000D:00: Error writing to device: 01 0e 00 00

Fix this by restoring the previous context setup order.

Fixes 2031c469f816 ("iommu/vt-d: Add support for static identity domain")
---
  drivers/iommu/intel/iommu.c  | 11 +++++++++++
  drivers/iommu/intel/iommu.h  |  1 +
  drivers/iommu/intel/nested.c |  4 ++--
  3 files changed, 14 insertions(+), 2 deletions(-)
drivers/iommu/intel/iommu.c +11 -0
index 49530d5d8c85..7aa3932251b2 100644
@@ -1809,6 +1809,7 @@ static int dmar_domain_attach_device(struct dmar_domain *domain,
  		return ret;
 
  	info->domain = domain;
+	info->domain_attached = true;
  	spin_lock_irqsave(&domain->lock, flags);
  	list_add(&info->link, &domain->devices);
  	spin_unlock_irqrestore(&domain->lock, flags);
@@ -3206,6 +3207,10 @@ void device_block_translation(struct device *dev)
  	struct intel_iommu *iommu = info->iommu;
  	unsigned long flags;
 
+	/* Device in DMA blocking state. Noting to do. */
+	if (!info->domain_attached)
+		return;
+
  	if (info->domain)
  		cache_tag_unassign_domain(info->domain, dev, IOMMU_NO_PASID);
 
@@ -3217,6 +3222,9 @@ void device_block_translation(struct device *dev)
  			domain_context_clear(info);
  	}
 
+	/* Device now in DMA blocking state. */
+	info->domain_attached = false;
+
  	if (!info->domain)
  		return;
 
@@ -4302,6 +4310,9 @@ static int identity_domain_attach_dev(struct iommu_domain *domain, struct device
  	else
  		ret = device_setup_pass_through(dev);
 
+	if (!ret)
+		info->domain_attached = true;
+
  	return ret;
  }
 
drivers/iommu/intel/iommu.h +1 -0
index cbfb8bb4c94a..3ddbcc603de2 100644
@@ -774,6 +774,7 @@ struct device_domain_info {
  	u8 ats_supported:1;
  	u8 ats_enabled:1;
  	u8 dtlb_extra_inval:1;	/* Quirk for devices need extra flush */
+	u8 domain_attached:1;	/* Device has domain attached */
  	u8 ats_qdep;
  	unsigned int iopf_refcount;
  	struct device *dev; /* it's NULL for PCIe-to-PCI bridge */
drivers/iommu/intel/nested.c +0 -0
index d2a94025d0a0..fc312f649f9e 100644

drivers/iommu/intel/nested.c static int intel_nested_attach_dev(struct iommu_domain *domain, · line 30

Quoted 6 lines
drivers/iommu/intel/nested.c +1 -2
@@ -27,8 +27,7 @@ static int intel_nested_attach_dev(struct iommu_domain *domain,
  	unsigned long flags;
  	int ret = 0;
 
-	if (info->domain)
-		device_block_translation(dev);
+	device_block_translation(dev);

good catch. :)

drivers/iommu/intel/nested.c static int intel_nested_attach_dev(struct iommu_domain *domain, · line 71

Quoted 10 lines
drivers/iommu/intel/nested.c +1 -0
  	if (iommu->agaw < dmar_domain->s2_domain->agaw) {
  		dev_err_ratelimited(dev, "Adjusted guest address width not compatible\n");
@@ -66,6 +65,7 @@ static int intel_nested_attach_dev(struct iommu_domain *domain,
  		goto disable_iopf;
 
  	info->domain = dmar_domain;
+	info->domain_attached = true;
  	spin_lock_irqsave(&dmar_domain->lock, flags);
  	list_add(&info->link, &dmar_domain->devices);
  	spin_unlock_irqrestore(&dmar_domain->lock, flags);

LGTM.

Regards,
Yi Liu

author maintainer
#3 lore raw
Quoted 8 lines · Yi Liu
Quoted 5 lines · Lu Baolu

Commit 2031c469f816 ("iommu/vt-d: Add support for static identity domain") changed the context entry setup during domain attachment from a set-and-check policy to a clear-and-reset approach. This inadvertently introduced a regression affecting PCI aliased devices behind PCIe-to-PCI bridges.

Quoted 5 lines

I got what the patch does. But just bit confused on the above description. I didn't see the commit 2031c469f816 mentioned any policy thing on the context entry setup.  To me, the problem looks to be that the info->domain is no more accurate to be used for checking if any domain is attached after the above commit. Maybe I missed something. feel free correct me.

The problem was introduced by below change:

drivers/iommu/intel/iommu.c +1 -3
@@ -3691,11 +3691,9 @@ int prepare_domain_attach_device(struct iommu_domain *domain,
 static int intel_iommu_attach_device(struct iommu_domain *domain,
                                     struct device *dev)
 {
-       struct device_domain_info *info = dev_iommu_priv_get(dev);
        int ret;
 
-       if (info->domain)
-               device_block_translation(dev);
+       device_block_translation(dev);
 

And after the introduction of static identity domain, "info->domain == NULL" doesn't mean no domain attaching to device anymore. So this patch uses a specific flag bit to indicate this.

Thanks,
baolu