Skip to content

Commit ec62b44

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Allocate pasid table in device probe path
Whether or not a domain is attached to the device, the pasid table should always be valid as long as it has been probed. This moves the pasid table allocation from the domain attaching device path to device probe path and frees it in the device release path. 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 eb70814 commit ec62b44

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

drivers/iommu/intel/iommu.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,13 +2475,6 @@ static int domain_add_dev_info(struct dmar_domain *domain, struct device *dev)
24752475

24762476
/* PASID table is mandatory for a PCI device in scalable mode. */
24772477
if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) {
2478-
ret = intel_pasid_alloc_table(dev);
2479-
if (ret) {
2480-
dev_err(dev, "PASID table allocation failed\n");
2481-
dmar_remove_one_dev_info(dev);
2482-
return ret;
2483-
}
2484-
24852478
/* Setup the PASID entry for requests without PASID: */
24862479
if (hw_pass_through && domain_type_is_si(domain))
24872480
ret = intel_pasid_setup_pass_through(iommu, domain,
@@ -4106,7 +4099,6 @@ static void dmar_remove_one_dev_info(struct device *dev)
41064099

41074100
iommu_disable_dev_iotlb(info);
41084101
domain_context_clear(info);
4109-
intel_pasid_free_table(info->dev);
41104102
}
41114103

41124104
spin_lock_irqsave(&domain->lock, flags);
@@ -4466,6 +4458,7 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev)
44664458
struct device_domain_info *info;
44674459
struct intel_iommu *iommu;
44684460
u8 bus, devfn;
4461+
int ret;
44694462

44704463
iommu = device_to_iommu(dev, &bus, &devfn);
44714464
if (!iommu || !iommu->iommu.ops)
@@ -4509,6 +4502,16 @@ static struct iommu_device *intel_iommu_probe_device(struct device *dev)
45094502

45104503
dev_iommu_priv_set(dev, info);
45114504

4505+
if (sm_supported(iommu) && !dev_is_real_dma_subdevice(dev)) {
4506+
ret = intel_pasid_alloc_table(dev);
4507+
if (ret) {
4508+
dev_err(dev, "PASID table allocation failed\n");
4509+
dev_iommu_priv_set(dev, NULL);
4510+
kfree(info);
4511+
return ERR_PTR(ret);
4512+
}
4513+
}
4514+
45124515
return &iommu->iommu;
45134516
}
45144517

@@ -4517,6 +4520,7 @@ static void intel_iommu_release_device(struct device *dev)
45174520
struct device_domain_info *info = dev_iommu_priv_get(dev);
45184521

45194522
dmar_remove_one_dev_info(dev);
4523+
intel_pasid_free_table(dev);
45204524
dev_iommu_priv_set(dev, NULL);
45214525
kfree(info);
45224526
set_dma_ops(dev, NULL);

0 commit comments

Comments
 (0)