0119-x86-virt-Add-enum-for-hypervisors-to-replace-x86_hyp.patch 9.9 KB

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