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