Skip to content

Commit 320302b

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Restore context entry setup order for aliased devices
Commit 2031c46 ("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: 2031c46 ("iommu/vt-d: Add support for static identity domain") Closes: https://lore.kernel.org/all/4dada48a-c5dd-4c30-9c85-5b03b0aa01f0@bfh.ch/ Cc: stable@vger.kernel.org Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Yi Liu <yi.l.liu@intel.com> Link: https://lore.kernel.org/r/20250514060523.2862195-1-baolu.lu@linux.intel.com Link: https://lore.kernel.org/r/20250520075849.755012-2-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent f3fe7e1 commit 320302b

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,6 +1808,7 @@ static int dmar_domain_attach_device(struct dmar_domain *domain,
18081808
return ret;
18091809

18101810
info->domain = domain;
1811+
info->domain_attached = true;
18111812
spin_lock_irqsave(&domain->lock, flags);
18121813
list_add(&info->link, &domain->devices);
18131814
spin_unlock_irqrestore(&domain->lock, flags);
@@ -3204,6 +3205,10 @@ void device_block_translation(struct device *dev)
32043205
struct intel_iommu *iommu = info->iommu;
32053206
unsigned long flags;
32063207

3208+
/* Device in DMA blocking state. Noting to do. */
3209+
if (!info->domain_attached)
3210+
return;
3211+
32073212
if (info->domain)
32083213
cache_tag_unassign_domain(info->domain, dev, IOMMU_NO_PASID);
32093214

@@ -3215,6 +3220,9 @@ void device_block_translation(struct device *dev)
32153220
domain_context_clear(info);
32163221
}
32173222

3223+
/* Device now in DMA blocking state. */
3224+
info->domain_attached = false;
3225+
32183226
if (!info->domain)
32193227
return;
32203228

@@ -4298,6 +4306,9 @@ static int identity_domain_attach_dev(struct iommu_domain *domain, struct device
42984306
else
42994307
ret = device_setup_pass_through(dev);
43004308

4309+
if (!ret)
4310+
info->domain_attached = true;
4311+
43014312
return ret;
43024313
}
43034314

drivers/iommu/intel/iommu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ struct device_domain_info {
775775
u8 ats_supported:1;
776776
u8 ats_enabled:1;
777777
u8 dtlb_extra_inval:1; /* Quirk for devices need extra flush */
778+
u8 domain_attached:1; /* Device has domain attached */
778779
u8 ats_qdep;
779780
unsigned int iopf_refcount;
780781
struct device *dev; /* it's NULL for PCIe-to-PCI bridge */

drivers/iommu/intel/nested.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ static int intel_nested_attach_dev(struct iommu_domain *domain,
2727
unsigned long flags;
2828
int ret = 0;
2929

30-
if (info->domain)
31-
device_block_translation(dev);
30+
device_block_translation(dev);
3231

3332
if (iommu->agaw < dmar_domain->s2_domain->agaw) {
3433
dev_err_ratelimited(dev, "Adjusted guest address width not compatible\n");
@@ -62,6 +61,7 @@ static int intel_nested_attach_dev(struct iommu_domain *domain,
6261
goto unassign_tag;
6362

6463
info->domain = dmar_domain;
64+
info->domain_attached = true;
6565
spin_lock_irqsave(&dmar_domain->lock, flags);
6666
list_add(&info->link, &dmar_domain->devices);
6767
spin_unlock_irqrestore(&dmar_domain->lock, flags);

0 commit comments

Comments
 (0)