Skip to content

Commit 99dcade

Browse files
Fenghua YuDavid Woodhouse
authored andcommitted
intel-iommu: Support PCIe hot-plug
To support PCIe hot plug in IOMMU, we register a notifier to respond to device change action. When the notifier gets BUS_NOTIFY_UNBOUND_DRIVER, it removes the device from its DMAR domain. A hot added device will be added into an IOMMU domain when it first does IOMMU op. So there is no need to add more code for hot add. Without the patch, after a hot-remove, a hot-added device on the same slot will not work. Signed-off-by: Fenghua Yu <fenghua.yu@intel.com> Tested-by: Yinghai Lu <yinghai@kernel.org> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent e8bb910 commit 99dcade

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

drivers/pci/intel-iommu.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3215,6 +3215,33 @@ static int __init init_iommu_sysfs(void)
32153215
}
32163216
#endif /* CONFIG_PM */
32173217

3218+
/*
3219+
* Here we only respond to action of unbound device from driver.
3220+
*
3221+
* Added device is not attached to its DMAR domain here yet. That will happen
3222+
* when mapping the device to iova.
3223+
*/
3224+
static int device_notifier(struct notifier_block *nb,
3225+
unsigned long action, void *data)
3226+
{
3227+
struct device *dev = data;
3228+
struct pci_dev *pdev = to_pci_dev(dev);
3229+
struct dmar_domain *domain;
3230+
3231+
domain = find_domain(pdev);
3232+
if (!domain)
3233+
return 0;
3234+
3235+
if (action == BUS_NOTIFY_UNBOUND_DRIVER && !iommu_pass_through)
3236+
domain_remove_one_dev_info(domain, pdev);
3237+
3238+
return 0;
3239+
}
3240+
3241+
static struct notifier_block device_nb = {
3242+
.notifier_call = device_notifier,
3243+
};
3244+
32183245
int __init intel_iommu_init(void)
32193246
{
32203247
int ret = 0;
@@ -3267,6 +3294,8 @@ int __init intel_iommu_init(void)
32673294

32683295
register_iommu(&intel_iommu_ops);
32693296

3297+
bus_register_notifier(&pci_bus_type, &device_nb);
3298+
32703299
return 0;
32713300
}
32723301

0 commit comments

Comments
 (0)