]> git.proxmox.com Git - pve-kernel.git/blob - patches/kernel/0119-x86-virt-Add-enum-for-hypervisors-to-replace-x86_hyp.patch
revert buggy SCSI error handler commit
[pve-kernel.git] / patches / kernel / 0119-x86-virt-Add-enum-for-hypervisors-to-replace-x86_hyp.patch
1 From fdde3f3305d4d393f39514cc098d1c4c2dd5634a Mon Sep 17 00:00:00 2001
2 From: Juergen Gross <jgross@suse.com>
3 Date: Thu, 9 Nov 2017 14:27:36 +0100
4 Subject: [PATCH 119/242] x86/virt: Add enum for hypervisors to replace
5 x86_hyper
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 CVE-2017-5754
11
12 The x86_hyper pointer is only used for checking whether a virtual
13 device is supporting the hypervisor the system is running on.
14
15 Use an enum for that purpose instead and drop the x86_hyper pointer.
16
17 Signed-off-by: Juergen Gross <jgross@suse.com>
18 Acked-by: Thomas Gleixner <tglx@linutronix.de>
19 Acked-by: Xavier Deguillard <xdeguillard@vmware.com>
20 Cc: Linus Torvalds <torvalds@linux-foundation.org>
21 Cc: Peter Zijlstra <peterz@infradead.org>
22 Cc: akataria@vmware.com
23 Cc: arnd@arndb.de
24 Cc: boris.ostrovsky@oracle.com
25 Cc: devel@linuxdriverproject.org
26 Cc: dmitry.torokhov@gmail.com
27 Cc: gregkh@linuxfoundation.org
28 Cc: haiyangz@microsoft.com
29 Cc: kvm@vger.kernel.org
30 Cc: kys@microsoft.com
31 Cc: linux-graphics-maintainer@vmware.com
32 Cc: linux-input@vger.kernel.org
33 Cc: moltmann@vmware.com
34 Cc: pbonzini@redhat.com
35 Cc: pv-drivers@vmware.com
36 Cc: rkrcmar@redhat.com
37 Cc: sthemmin@microsoft.com
38 Cc: virtualization@lists.linux-foundation.org
39 Cc: xen-devel@lists.xenproject.org
40 Link: http://lkml.kernel.org/r/20171109132739.23465-3-jgross@suse.com
41 Signed-off-by: Ingo Molnar <mingo@kernel.org>
42 (backported from commit 03b2a320b19f1424e9ac9c21696be9c60b6d0d93)
43 Signed-off-by: Andy Whitcroft <apw@canonical.com>
44 Signed-off-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
45 (cherry picked from commit c24b0a226fadfe1abe78fa568ff84fea6ecd7ca5)
46 Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
47 ---
48 arch/x86/include/asm/hypervisor.h | 23 ++++++++++++++---------
49 arch/x86/hyperv/hv_init.c | 2 +-
50 arch/x86/kernel/cpu/hypervisor.c | 12 +++++++++---
51 arch/x86/kernel/cpu/mshyperv.c | 6 +++---
52 arch/x86/kernel/cpu/vmware.c | 4 ++--
53 arch/x86/kernel/kvm.c | 4 ++--
54 arch/x86/xen/enlighten_hvm.c | 4 ++--
55 arch/x86/xen/enlighten_pv.c | 4 ++--
56 drivers/hv/vmbus_drv.c | 2 +-
57 drivers/input/mouse/vmmouse.c | 10 ++++------
58 drivers/misc/vmw_balloon.c | 2 +-
59 11 files changed, 41 insertions(+), 32 deletions(-)
60
61 diff --git a/arch/x86/include/asm/hypervisor.h b/arch/x86/include/asm/hypervisor.h
62 index 0eca7239a7aa..1b0a5abcd8ae 100644
63 --- a/arch/x86/include/asm/hypervisor.h
64 +++ b/arch/x86/include/asm/hypervisor.h
65 @@ -29,6 +29,16 @@
66 /*
67 * x86 hypervisor information
68 */
69 +
70 +enum x86_hypervisor_type {
71 + X86_HYPER_NATIVE = 0,
72 + X86_HYPER_VMWARE,
73 + X86_HYPER_MS_HYPERV,
74 + X86_HYPER_XEN_PV,
75 + X86_HYPER_XEN_HVM,
76 + X86_HYPER_KVM,
77 +};
78 +
79 struct hypervisor_x86 {
80 /* Hypervisor name */
81 const char *name;
82 @@ -36,6 +46,9 @@ struct hypervisor_x86 {
83 /* Detection routine */
84 uint32_t (*detect)(void);
85
86 + /* Hypervisor type */
87 + enum x86_hypervisor_type type;
88 +
89 /* init time callbacks */
90 struct x86_hyper_init init;
91
92 @@ -43,15 +56,7 @@ struct hypervisor_x86 {
93 struct x86_hyper_runtime runtime;
94 };
95
96 -extern const struct hypervisor_x86 *x86_hyper;
97 -
98 -/* Recognized hypervisors */
99 -extern const struct hypervisor_x86 x86_hyper_vmware;
100 -extern const struct hypervisor_x86 x86_hyper_ms_hyperv;
101 -extern const struct hypervisor_x86 x86_hyper_xen_pv;
102 -extern const struct hypervisor_x86 x86_hyper_xen_hvm;
103 -extern const struct hypervisor_x86 x86_hyper_kvm;
104 -
105 +extern enum x86_hypervisor_type x86_hyper_type;
106 extern void init_hypervisor_platform(void);
107 #else
108 static inline void init_hypervisor_platform(void) { }
109 diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
110 index ec7c9661743f..32fa894139d5 100644
111 --- a/arch/x86/hyperv/hv_init.c
112 +++ b/arch/x86/hyperv/hv_init.c
113 @@ -99,7 +99,7 @@ void hyperv_init(void)
114 u64 guest_id;
115 union hv_x64_msr_hypercall_contents hypercall_msr;
116
117 - if (x86_hyper != &x86_hyper_ms_hyperv)
118 + if (x86_hyper_type != X86_HYPER_MS_HYPERV)
119 return;
120
121 /*
122 diff --git a/arch/x86/kernel/cpu/hypervisor.c b/arch/x86/kernel/cpu/hypervisor.c
123 index 22226c1bf092..bea8d3e24f50 100644
124 --- a/arch/x86/kernel/cpu/hypervisor.c
125 +++ b/arch/x86/kernel/cpu/hypervisor.c
126 @@ -26,6 +26,12 @@
127 #include <asm/processor.h>
128 #include <asm/hypervisor.h>
129
130 +extern const struct hypervisor_x86 x86_hyper_vmware;
131 +extern const struct hypervisor_x86 x86_hyper_ms_hyperv;
132 +extern const struct hypervisor_x86 x86_hyper_xen_pv;
133 +extern const struct hypervisor_x86 x86_hyper_xen_hvm;
134 +extern const struct hypervisor_x86 x86_hyper_kvm;
135 +
136 static const __initconst struct hypervisor_x86 * const hypervisors[] =
137 {
138 #ifdef CONFIG_XEN_PV
139 @@ -41,8 +47,8 @@ static const __initconst struct hypervisor_x86 * const hypervisors[] =
140 #endif
141 };
142
143 -const struct hypervisor_x86 *x86_hyper;
144 -EXPORT_SYMBOL(x86_hyper);
145 +enum x86_hypervisor_type x86_hyper_type;
146 +EXPORT_SYMBOL(x86_hyper_type);
147
148 static inline const struct hypervisor_x86 * __init
149 detect_hypervisor_vendor(void)
150 @@ -87,6 +93,6 @@ void __init init_hypervisor_platform(void)
151 copy_array(&h->init, &x86_init.hyper, sizeof(h->init));
152 copy_array(&h->runtime, &x86_platform.hyper, sizeof(h->runtime));
153
154 - x86_hyper = h;
155 + x86_hyper_type = h->type;
156 x86_init.hyper.init_platform();
157 }
158 diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
159 index 9707e431da27..3672f1192119 100644
160 --- a/arch/x86/kernel/cpu/mshyperv.c
161 +++ b/arch/x86/kernel/cpu/mshyperv.c
162 @@ -252,9 +252,9 @@ static void __init ms_hyperv_init_platform(void)
163 #endif
164 }
165
166 -const __refconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
167 - .name = "Microsoft HyperV",
168 +const __initconst struct hypervisor_x86 x86_hyper_ms_hyperv = {
169 + .name = "Microsoft Hyper-V",
170 .detect = ms_hyperv_platform,
171 + .type = X86_HYPER_MS_HYPERV,
172 .init.init_platform = ms_hyperv_init_platform,
173 };
174 -EXPORT_SYMBOL(x86_hyper_ms_hyperv);
175 diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
176 index 4804c1d063c8..8e005329648b 100644
177 --- a/arch/x86/kernel/cpu/vmware.c
178 +++ b/arch/x86/kernel/cpu/vmware.c
179 @@ -205,10 +205,10 @@ static bool __init vmware_legacy_x2apic_available(void)
180 (eax & (1 << VMWARE_PORT_CMD_LEGACY_X2APIC)) != 0;
181 }
182
183 -const __refconst struct hypervisor_x86 x86_hyper_vmware = {
184 +const __initconst struct hypervisor_x86 x86_hyper_vmware = {
185 .name = "VMware",
186 .detect = vmware_platform,
187 + .type = X86_HYPER_VMWARE,
188 .init.init_platform = vmware_platform_setup,
189 .init.x2apic_available = vmware_legacy_x2apic_available,
190 };
191 -EXPORT_SYMBOL(x86_hyper_vmware);
192 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
193 index 54e373bfeab9..b65a51a24647 100644
194 --- a/arch/x86/kernel/kvm.c
195 +++ b/arch/x86/kernel/kvm.c
196 @@ -544,12 +544,12 @@ static uint32_t __init kvm_detect(void)
197 return kvm_cpuid_base();
198 }
199
200 -const struct hypervisor_x86 x86_hyper_kvm __refconst = {
201 +const __initconst struct hypervisor_x86 x86_hyper_kvm = {
202 .name = "KVM",
203 .detect = kvm_detect,
204 + .type = X86_HYPER_KVM,
205 .init.x2apic_available = kvm_para_available,
206 };
207 -EXPORT_SYMBOL_GPL(x86_hyper_kvm);
208
209 static __init int activate_jump_labels(void)
210 {
211 diff --git a/arch/x86/xen/enlighten_hvm.c b/arch/x86/xen/enlighten_hvm.c
212 index 7b1622089f96..754d5391d9fa 100644
213 --- a/arch/x86/xen/enlighten_hvm.c
214 +++ b/arch/x86/xen/enlighten_hvm.c
215 @@ -226,12 +226,12 @@ static uint32_t __init xen_platform_hvm(void)
216 return xen_cpuid_base();
217 }
218
219 -const struct hypervisor_x86 x86_hyper_xen_hvm = {
220 +const __initconst struct hypervisor_x86 x86_hyper_xen_hvm = {
221 .name = "Xen HVM",
222 .detect = xen_platform_hvm,
223 + .type = X86_HYPER_XEN_HVM,
224 .init.init_platform = xen_hvm_guest_init,
225 .init.x2apic_available = xen_x2apic_para_available,
226 .init.init_mem_mapping = xen_hvm_init_mem_mapping,
227 .runtime.pin_vcpu = xen_pin_vcpu,
228 };
229 -EXPORT_SYMBOL(x86_hyper_xen_hvm);
230 diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
231 index 4110fc9e5ee9..63c81154083b 100644
232 --- a/arch/x86/xen/enlighten_pv.c
233 +++ b/arch/x86/xen/enlighten_pv.c
234 @@ -1458,9 +1458,9 @@ static uint32_t __init xen_platform_pv(void)
235 return 0;
236 }
237
238 -const struct hypervisor_x86 x86_hyper_xen_pv = {
239 +const __initconst struct hypervisor_x86 x86_hyper_xen_pv = {
240 .name = "Xen PV",
241 .detect = xen_platform_pv,
242 + .type = X86_HYPER_XEN_PV,
243 .runtime.pin_vcpu = xen_pin_vcpu,
244 };
245 -EXPORT_SYMBOL(x86_hyper_xen_pv);
246 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
247 index 5ad627044dd1..8aca7613e482 100644
248 --- a/drivers/hv/vmbus_drv.c
249 +++ b/drivers/hv/vmbus_drv.c
250 @@ -1551,7 +1551,7 @@ static int __init hv_acpi_init(void)
251 {
252 int ret, t;
253
254 - if (x86_hyper != &x86_hyper_ms_hyperv)
255 + if (x86_hyper_type != X86_HYPER_MS_HYPERV)
256 return -ENODEV;
257
258 init_completion(&probe_event);
259 diff --git a/drivers/input/mouse/vmmouse.c b/drivers/input/mouse/vmmouse.c
260 index 0f586780ceb4..1ae5c1ef3f5b 100644
261 --- a/drivers/input/mouse/vmmouse.c
262 +++ b/drivers/input/mouse/vmmouse.c
263 @@ -316,11 +316,9 @@ static int vmmouse_enable(struct psmouse *psmouse)
264 /*
265 * Array of supported hypervisors.
266 */
267 -static const struct hypervisor_x86 *vmmouse_supported_hypervisors[] = {
268 - &x86_hyper_vmware,
269 -#ifdef CONFIG_KVM_GUEST
270 - &x86_hyper_kvm,
271 -#endif
272 +static enum x86_hypervisor_type vmmouse_supported_hypervisors[] = {
273 + X86_HYPER_VMWARE,
274 + X86_HYPER_KVM,
275 };
276
277 /**
278 @@ -331,7 +329,7 @@ static bool vmmouse_check_hypervisor(void)
279 int i;
280
281 for (i = 0; i < ARRAY_SIZE(vmmouse_supported_hypervisors); i++)
282 - if (vmmouse_supported_hypervisors[i] == x86_hyper)
283 + if (vmmouse_supported_hypervisors[i] == x86_hyper_type)
284 return true;
285
286 return false;
287 diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
288 index 1e688bfec567..9047c0a529b2 100644
289 --- a/drivers/misc/vmw_balloon.c
290 +++ b/drivers/misc/vmw_balloon.c
291 @@ -1271,7 +1271,7 @@ static int __init vmballoon_init(void)
292 * Check if we are running on VMware's hypervisor and bail out
293 * if we are not.
294 */
295 - if (x86_hyper != &x86_hyper_vmware)
296 + if (x86_hyper_type != X86_HYPER_VMWARE)
297 return -ENODEV;
298
299 for (is_2m_pages = 0; is_2m_pages < VMW_BALLOON_NUM_PAGE_SIZES;
300 --
301 2.14.2
302