1 |
From 7ebb5f8e001037efbdf18afabbbebf71bd98825e Mon Sep 17 00:00:00 2001 |
2 |
From: Lu Baolu <baolu.lu@linux.intel.com> |
3 |
Date: Wed, 21 Sep 2022 10:40:53 +0800 |
4 |
Subject: Revert "iommu/vt-d: Fix possible recursive locking in |
5 |
intel_iommu_init()" |
6 |
|
7 |
This reverts commit 9cd4f1434479f1ac25c440c421fbf52069079914. |
8 |
|
9 |
Some issues were reported on the original commit. Some thunderbolt devices |
10 |
don't work anymore due to the following DMA fault. |
11 |
|
12 |
DMAR: DRHD: handling fault status reg 2 |
13 |
DMAR: [INTR-REMAP] Request device [09:00.0] fault index 0x8080 |
14 |
[fault reason 0x25] |
15 |
Blocked a compatibility format interrupt request |
16 |
|
17 |
Bring it back for now to avoid functional regression. |
18 |
|
19 |
Fixes: 9cd4f1434479f ("iommu/vt-d: Fix possible recursive locking in intel_iommu_init()") |
20 |
Link: https://lore.kernel.org/linux-iommu/485A6EA5-6D58-42EA-B298-8571E97422DE@getmailspring.com/ |
21 |
Link: https://bugzilla.kernel.org/show_bug.cgi?id=216497 |
22 |
Cc: Mika Westerberg <mika.westerberg@linux.intel.com> |
23 |
Cc: <stable@vger.kernel.org> # 5.19.x |
24 |
Reported-and-tested-by: George Hilliard <thirtythreeforty@gmail.com> |
25 |
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> |
26 |
Link: https://lore.kernel.org/r/20220920081701.3453504-1-baolu.lu@linux.intel.com |
27 |
Signed-off-by: Joerg Roedel <jroedel@suse.de> |
28 |
--- |
29 |
drivers/iommu/intel/dmar.c | 7 ------- |
30 |
drivers/iommu/intel/iommu.c | 27 +++++++++++++++++++++++++-- |
31 |
include/linux/dmar.h | 4 +--- |
32 |
3 files changed, 26 insertions(+), 12 deletions(-) |
33 |
|
34 |
diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c |
35 |
index 497c912ad9e13..5a8f780e7ffd8 100644 |
36 |
--- a/drivers/iommu/intel/dmar.c |
37 |
+++ b/drivers/iommu/intel/dmar.c |
38 |
@@ -2349,13 +2349,6 @@ static int dmar_device_hotplug(acpi_handle handle, bool insert) |
39 |
if (!dmar_in_use()) |
40 |
return 0; |
41 |
|
42 |
- /* |
43 |
- * It's unlikely that any I/O board is hot added before the IOMMU |
44 |
- * subsystem is initialized. |
45 |
- */ |
46 |
- if (IS_ENABLED(CONFIG_INTEL_IOMMU) && !intel_iommu_enabled) |
47 |
- return -EOPNOTSUPP; |
48 |
- |
49 |
if (dmar_detect_dsm(handle, DMAR_DSM_FUNC_DRHD)) { |
50 |
tmp = handle; |
51 |
} else { |
52 |
diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c |
53 |
index 1f2cd43cf9bcf..64d30895a4c8f 100644 |
54 |
--- a/drivers/iommu/intel/iommu.c |
55 |
+++ b/drivers/iommu/intel/iommu.c |
56 |
@@ -3019,7 +3019,13 @@ static int __init init_dmars(void) |
57 |
|
58 |
#ifdef CONFIG_INTEL_IOMMU_SVM |
59 |
if (pasid_supported(iommu) && ecap_prs(iommu->ecap)) { |
60 |
+ /* |
61 |
+ * Call dmar_alloc_hwirq() with dmar_global_lock held, |
62 |
+ * could cause possible lock race condition. |
63 |
+ */ |
64 |
+ up_write(&dmar_global_lock); |
65 |
ret = intel_svm_enable_prq(iommu); |
66 |
+ down_write(&dmar_global_lock); |
67 |
if (ret) |
68 |
goto free_iommu; |
69 |
} |
70 |
@@ -3932,6 +3938,7 @@ int __init intel_iommu_init(void) |
71 |
force_on = (!intel_iommu_tboot_noforce && tboot_force_iommu()) || |
72 |
platform_optin_force_iommu(); |
73 |
|
74 |
+ down_write(&dmar_global_lock); |
75 |
if (dmar_table_init()) { |
76 |
if (force_on) |
77 |
panic("tboot: Failed to initialize DMAR table\n"); |
78 |
@@ -3944,6 +3951,16 @@ int __init intel_iommu_init(void) |
79 |
goto out_free_dmar; |
80 |
} |
81 |
|
82 |
+ up_write(&dmar_global_lock); |
83 |
+ |
84 |
+ /* |
85 |
+ * The bus notifier takes the dmar_global_lock, so lockdep will |
86 |
+ * complain later when we register it under the lock. |
87 |
+ */ |
88 |
+ dmar_register_bus_notifier(); |
89 |
+ |
90 |
+ down_write(&dmar_global_lock); |
91 |
+ |
92 |
if (!no_iommu) |
93 |
intel_iommu_debugfs_init(); |
94 |
|
95 |
@@ -3988,9 +4005,11 @@ int __init intel_iommu_init(void) |
96 |
pr_err("Initialization failed\n"); |
97 |
goto out_free_dmar; |
98 |
} |
99 |
+ up_write(&dmar_global_lock); |
100 |
|
101 |
init_iommu_pm_ops(); |
102 |
|
103 |
+ down_read(&dmar_global_lock); |
104 |
for_each_active_iommu(iommu, drhd) { |
105 |
/* |
106 |
* The flush queue implementation does not perform |
107 |
@@ -4008,11 +4027,13 @@ int __init intel_iommu_init(void) |
108 |
"%s", iommu->name); |
109 |
iommu_device_register(&iommu->iommu, &intel_iommu_ops, NULL); |
110 |
} |
111 |
+ up_read(&dmar_global_lock); |
112 |
|
113 |
bus_set_iommu(&pci_bus_type, &intel_iommu_ops); |
114 |
if (si_domain && !hw_pass_through) |
115 |
register_memory_notifier(&intel_iommu_memory_nb); |
116 |
|
117 |
+ down_read(&dmar_global_lock); |
118 |
if (probe_acpi_namespace_devices()) |
119 |
pr_warn("ACPI name space devices didn't probe correctly\n"); |
120 |
|
121 |
@@ -4023,15 +4044,17 @@ int __init intel_iommu_init(void) |
122 |
|
123 |
iommu_disable_protect_mem_regions(iommu); |
124 |
} |
125 |
+ up_read(&dmar_global_lock); |
126 |
|
127 |
- intel_iommu_enabled = 1; |
128 |
- dmar_register_bus_notifier(); |
129 |
pr_info("Intel(R) Virtualization Technology for Directed I/O\n"); |
130 |
|
131 |
+ intel_iommu_enabled = 1; |
132 |
+ |
133 |
return 0; |
134 |
|
135 |
out_free_dmar: |
136 |
intel_iommu_free_dmars(); |
137 |
+ up_write(&dmar_global_lock); |
138 |
return ret; |
139 |
} |
140 |
|
141 |
diff --git a/include/linux/dmar.h b/include/linux/dmar.h |
142 |
index 8917a32173c4e..d81a51978d013 100644 |
143 |
--- a/include/linux/dmar.h |
144 |
+++ b/include/linux/dmar.h |
145 |
@@ -65,7 +65,6 @@ struct dmar_pci_notify_info { |
146 |
|
147 |
extern struct rw_semaphore dmar_global_lock; |
148 |
extern struct list_head dmar_drhd_units; |
149 |
-extern int intel_iommu_enabled; |
150 |
|
151 |
#define for_each_drhd_unit(drhd) \ |
152 |
list_for_each_entry_rcu(drhd, &dmar_drhd_units, list, \ |
153 |
@@ -89,8 +88,7 @@ extern int intel_iommu_enabled; |
154 |
static inline bool dmar_rcu_check(void) |
155 |
{ |
156 |
return rwsem_is_locked(&dmar_global_lock) || |
157 |
- system_state == SYSTEM_BOOTING || |
158 |
- (IS_ENABLED(CONFIG_INTEL_IOMMU) && !intel_iommu_enabled); |
159 |
+ system_state == SYSTEM_BOOTING; |
160 |
} |
161 |
|
162 |
#define dmar_rcu_dereference(p) rcu_dereference_check((p), dmar_rcu_check()) |
163 |
-- |
164 |
cgit |
165 |
|