History

Revert "iommu/vt-d: Fix possible recursive locking in intel_iommu_init()"

This reverts commit 9cd4f1434479f1ac25c440c421fbf52069079914. Some issues were reported on the original commit. Some thunderbolt devices don't work anymore due to the following DMA fault. DMAR: DRHD: handling fault status reg 2 DMAR: [INTR-REMAP] Request device [09:00.0] fault index 0x8080 [fault reason 0x25] Blocked a compatibility format interrupt request Bring it back for now to avoid functional regression.

Lu Baolu committed 4 years ago

Commit 7ebb5f81 parent 521a5473 files · +26 −12Browse files

Unified · Split

3 files
  1. drivers/iommu/intel/dmar.c +0 −7
  2. drivers/iommu/intel/iommu.c +25 −2
  3. include/linux/dmar.h +1 −3
drivers/iommu/intel/dmar.c+0−7
@@ -2349,13 +2349,6 @@ static int dmar_device_hotplug(acpi_handle handle, bool insert) · 2348 unmodified lines
23492349 if (!dmar_in_use())
23502350 return 0;
23512351
2352− /*
2353− * It's unlikely that any I/O board is hot added before the IOMMU
2354− * subsystem is initialized.
2355− */
2356− if (IS_ENABLED(CONFIG_INTEL_IOMMU) && !intel_iommu_enabled)
2357− return -EOPNOTSUPP;
2358−
23592352 if (dmar_detect_dsm(handle, DMAR_DSM_FUNC_DRHD)) {
23602353 tmp = handle;
23612354 } else {
drivers/iommu/intel/iommu.c+25−2
@@ -3019,7 +3019,13 @@ static int __init init_dmars(void) · 3018 unmodified lines
30193019
30203020 #ifdef CONFIG_INTEL_IOMMU_SVM
30213021 if (pasid_supported(iommu) && ecap_prs(iommu->ecap)) {
3022+ /*
3023+ * Call dmar_alloc_hwirq() with dmar_global_lock held,
3024+ * could cause possible lock race condition.
3025+ */
3026+ up_write(&dmar_global_lock);
30223027 ret = intel_svm_enable_prq(iommu);
3028+ down_write(&dmar_global_lock);
30233029 if (ret)
30243030 goto free_iommu;
30253031 }
@@ -3932,6 +3938,7 @@ int __init intel_iommu_init(void) · 906 unmodified lines
39323938 force_on = (!intel_iommu_tboot_noforce && tboot_force_iommu()) ||
39333939 platform_optin_force_iommu();
39343940
3941+ down_write(&dmar_global_lock);
39353942 if (dmar_table_init()) {
39363943 if (force_on)
39373944 panic("tboot: Failed to initialize DMAR table\n");
@@ -3944,6 +3951,16 @@ int __init intel_iommu_init(void) · 6 unmodified lines
39443951 goto out_free_dmar;
39453952 }
39463953
3954+ up_write(&dmar_global_lock);
3955+
3956+ /*
3957+ * The bus notifier takes the dmar_global_lock, so lockdep will
3958+ * complain later when we register it under the lock.
3959+ */
3960+ dmar_register_bus_notifier();
3961+
3962+ down_write(&dmar_global_lock);
3963+
39473964 if (!no_iommu)
39483965 intel_iommu_debugfs_init();
39493966
@@ -3988,9 +4005,11 @@ int __init intel_iommu_init(void) · 38 unmodified lines
39884005 pr_err("Initialization failed\n");
39894006 goto out_free_dmar;
39904007 }
4008+ up_write(&dmar_global_lock);
39914009
39924010 init_iommu_pm_ops();
39934011
4012+ down_read(&dmar_global_lock);
39944013 for_each_active_iommu(iommu, drhd) {
39954014 /*
39964015 * The flush queue implementation does not perform
@@ -4008,11 +4027,13 @@ int __init intel_iommu_init(void) · 11 unmodified lines
40084027 "%s", iommu->name);
40094028 iommu_device_register(&iommu->iommu, &intel_iommu_ops, NULL);
40104029 }
4030+ up_read(&dmar_global_lock);
40114031
40124032 bus_set_iommu(&pci_bus_type, &intel_iommu_ops);
40134033 if (si_domain && !hw_pass_through)
40144034 register_memory_notifier(&intel_iommu_memory_nb);
40154035
4036+ down_read(&dmar_global_lock);
40164037 if (probe_acpi_namespace_devices())
40174038 pr_warn("ACPI name space devices didn't probe correctly\n");
40184039
@@ -4023,15 +4044,17 @@ int __init intel_iommu_init(void) · 4 unmodified lines
40234044
40244045 iommu_disable_protect_mem_regions(iommu);
40254046 }
4047+ up_read(&dmar_global_lock);
40264048
4027− intel_iommu_enabled = 1;
4028− dmar_register_bus_notifier();
40294049 pr_info("Intel(R) Virtualization Technology for Directed I/O\n");
40304050
4051+ intel_iommu_enabled = 1;
4052+
40314053 return 0;
40324054
40334055 out_free_dmar:
40344056 intel_iommu_free_dmars();
4057+ up_write(&dmar_global_lock);
40354058 return ret;
40364059 }
40374060
include/linux/dmar.h+1−3
@@ -65,7 +65,6 @@ struct dmar_pci_notify_info { · 64 unmodified lines
6565
6666 extern struct rw_semaphore dmar_global_lock;
6767 extern struct list_head dmar_drhd_units;
68−extern int intel_iommu_enabled;
6968
7069 #define for_each_drhd_unit(drhd) \
7170 list_for_each_entry_rcu(drhd, &dmar_drhd_units, list, \
@@ -89,8 +88,7 @@ extern int intel_iommu_enabled; · 17 unmodified lines
8988 static inline bool dmar_rcu_check(void)
9089 {
9190 return rwsem_is_locked(&dmar_global_lock) ||
92− system_state == SYSTEM_BOOTING ||
93− (IS_ENABLED(CONFIG_INTEL_IOMMU) && !intel_iommu_enabled);
91+ system_state == SYSTEM_BOOTING;
9492 }
9593
9694 #define dmar_rcu_dereference(p) rcu_dereference_check((p), dmar_rcu_check())