Skip to content

Commit c7be17c

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Add device_block_translation() helper
If domain attaching to device fails, the IOMMU driver should bring the device to blocking DMA state. The upper layer is expected to recover it by attaching a new domain. Use device_block_translation() in the error path of dev_attach to make the behavior specific. The difference between device_block_translation() and the previous dmar_remove_one_dev_info() is that, in the scalable mode, it is the RID2PASID entry instead of context entry being cleared. As a result, enabling PCI capabilities is moved up. Signed-off-by: Lu Baolu <[email protected]> Reviewed-by: Kevin Tian <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent ec62b44 commit c7be17c

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ static LIST_HEAD(dmar_satc_units);
277277
#define for_each_rmrr_units(rmrr) \
278278
list_for_each_entry(rmrr, &dmar_rmrr_units, list)
279279

280-
static void dmar_remove_one_dev_info(struct device *dev);
280+
static void device_block_translation(struct device *dev);
281281

282282
int dmar_disabled = !IS_ENABLED(CONFIG_INTEL_IOMMU_DEFAULT_ON);
283283
int intel_iommu_sm = IS_ENABLED(CONFIG_INTEL_IOMMU_SCALABLE_MODE_DEFAULT_ON);
@@ -1400,7 +1400,7 @@ static void iommu_enable_pci_caps(struct device_domain_info *info)
14001400
{
14011401
struct pci_dev *pdev;
14021402

1403-
if (!info || !dev_is_pci(info->dev))
1403+
if (!dev_is_pci(info->dev))
14041404
return;
14051405

14061406
pdev = to_pci_dev(info->dev);
@@ -2045,7 +2045,6 @@ static int domain_context_mapping_one(struct dmar_domain *domain,
20452045
} else {
20462046
iommu_flush_write_buffer(iommu);
20472047
}
2048-
iommu_enable_pci_caps(info);
20492048

20502049
ret = 0;
20512050

@@ -2487,18 +2486,20 @@ static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev)
24872486
dev, PASID_RID2PASID);
24882487
if (ret) {
24892488
dev_err(dev, "Setup RID2PASID failed\n");
2490-
dmar_remove_one_dev_info(dev);
2489+
device_block_translation(dev);
24912490
return ret;
24922491
}
24932492
}
24942493

24952494
ret = domain_context_mapping(domain, dev);
24962495
if (ret) {
24972496
dev_err(dev, "Domain context map failed\n");
2498-
dmar_remove_one_dev_info(dev);
2497+
device_block_translation(dev);
24992498
return ret;
25002499
}
25012500

2501+
iommu_enable_pci_caps(info);
2502+
25022503
return 0;
25032504
}
25042505

@@ -4109,6 +4110,37 @@ static void dmar_remove_one_dev_info(struct device *dev)
41094110
info->domain = NULL;
41104111
}
41114112

4113+
/*
4114+
* Clear the page table pointer in context or pasid table entries so that
4115+
* all DMA requests without PASID from the device are blocked. If the page
4116+
* table has been set, clean up the data structures.
4117+
*/
4118+
static void device_block_translation(struct device *dev)
4119+
{
4120+
struct device_domain_info *info = dev_iommu_priv_get(dev);
4121+
struct intel_iommu *iommu = info->iommu;
4122+
unsigned long flags;
4123+
4124+
iommu_disable_dev_iotlb(info);
4125+
if (!dev_is_real_dma_subdevice(dev)) {
4126+
if (sm_supported(iommu))
4127+
intel_pasid_tear_down_entry(iommu, dev,
4128+
PASID_RID2PASID, false);
4129+
else
4130+
domain_context_clear(info);
4131+
}
4132+
4133+
if (!info->domain)
4134+
return;
4135+
4136+
spin_lock_irqsave(&info->domain->lock, flags);
4137+
list_del(&info->link);
4138+
spin_unlock_irqrestore(&info->domain->lock, flags);
4139+
4140+
domain_detach_iommu(info->domain, iommu);
4141+
info->domain = NULL;
4142+
}
4143+
41124144
static int md_domain_init(struct dmar_domain *domain, int guest_width)
41134145
{
41144146
int adjust_width;
@@ -4232,7 +4264,7 @@ static int intel_iommu_attach_device(struct iommu_domain *domain,
42324264
struct device_domain_info *info = dev_iommu_priv_get(dev);
42334265

42344266
if (info->domain)
4235-
dmar_remove_one_dev_info(dev);
4267+
device_block_translation(dev);
42364268
}
42374269

42384270
ret = prepare_domain_attach_device(domain, dev);

0 commit comments

Comments
 (0)