Skip to contentSkip to conversation

iommu/vt-d: Check identity map for hot-added devices

PATCH In review Lu Baolu 2 participants 4 messages Feb 25, 2019 – Mar 1, 2019 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Lu Baolu

author
#0 lore raw

PATCH 1/1 iommu/vt-d: Check identity map for hot-added devices

The Intel IOMMU driver will put devices into a static identity mapped domain during boot if the kernel parameter "iommu=pt" is used. That means the IOMMU hardware will translate a DMA address into the same memory address.

Unfortunately, hot-added devices are not subject to this. That results in some devices not working properly after hot added. A quick way to reproduce this issue is to boot a system with

iommu=pt

and, remove then readd the pci device with

echo 1 > /sys/bus/pci/devices/[pci_source_id]/remove echo 1 > /sys/bus/pci/rescan

You will find the identity mapped domain was replaced with a normal domain.

---
 drivers/iommu/intel-iommu.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/iommu/intel-iommu.c +12 -9
index af23cfc2a05e..4f77657a9c25 100644
@@ -4564,16 +4564,19 @@ static int device_notifier(struct notifier_block *nb,
 	if (iommu_dummy(dev))
 		return 0;
 
-	if (action != BUS_NOTIFY_REMOVED_DEVICE)
-		return 0;
-
-	domain = find_domain(dev);
-	if (!domain)
-		return 0;
+	if (action == BUS_NOTIFY_REMOVED_DEVICE) {
+		domain = find_domain(dev);
+		if (!domain)
+			return 0;
 
-	dmar_remove_one_dev_info(dev);
-	if (!domain_type_is_vm_or_si(domain) && list_empty(&domain->devices))
-		domain_exit(domain);
+		dmar_remove_one_dev_info(dev);
+		if (!domain_type_is_vm_or_si(domain) &&
+		    list_empty(&domain->devices))
+			domain_exit(domain);
+	} else if (action == BUS_NOTIFY_ADD_DEVICE) {
+		if (iommu_should_identity_map(dev, 1))
+			domain_add_dev_info(si_domain, dev);
+	}
 
 	return 0;
 }
Signature · 1 line
2.17.1
maintainer
#1 lore raw
Quoted 2 lines · Lu Baolu
 drivers/iommu/intel-iommu.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

Added a Fixes: tag and applied the patch, thanks.

A message that is not in the archive (sent off-list or not yet received): [email protected]

maintainer
#3 lore raw

Hi Sasha,

Thanks for the heads-up!

Quoted 9 lines · Sasha Levin

Hi,

[This is an automated email]

This commit has been processed because it contains a -stable tag. The stable tag indicates that it's relevant for the following trees: all

The bot has tested the following trees: v4.20.12, v4.19.25, v4.14.103, v4.9.160, v4.4.176, v3.18.136.

Lu Baolu, can you please check for which stable trees this commit is relevant and provide the backports of the patch (with dependencies if necessary) to the relevant stable trees?

Thanks,

Joerg

author
#4 lore raw

Hi Joerg,

Quoted 12 lines · Joerg Roedel

Hi Sasha,

Thanks for the heads-up!

Quoted 7 lines · Sasha Levin

Hi,

[This is an automated email]

This commit has been processed because it contains a -stable tag. The stable tag indicates that it's relevant for the following trees: all

Quoted 7 lines
Quoted 2 lines

The bot has tested the following trees: v4.20.12, v4.19.25, v4.14.103, v4.9.160, v4.4.176, v3.18.136.

Lu Baolu, can you please check for which stable trees this commit is relevant and provide the backports of the patch (with dependencies if necessary) to the relevant stable trees?

Sure. Actually, I am doing this.

Best regards,
Lu Baolu