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

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