0161-x86-paravirt-Provide-a-way-to-check-for-hypervisors.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. From 75ea12fecab1f4af63b39227509bf706b3faf21d Mon Sep 17 00:00:00 2001
  2. From: Thomas Gleixner <[email protected]>
  3. Date: Mon, 4 Dec 2017 15:07:31 +0100
  4. Subject: [PATCH 161/242] x86/paravirt: Provide a way to check for hypervisors
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. There is no generic way to test whether a kernel is running on a specific
  10. hypervisor. But that's required to prevent the upcoming user address space
  11. separation feature in certain guest modes.
  12. Make the hypervisor type enum unconditionally available and provide a
  13. helper function which allows to test for a specific type.
  14. Signed-off-by: Thomas Gleixner <[email protected]>
  15. Reviewed-by: Juergen Gross <[email protected]>
  16. Cc: Andy Lutomirski <[email protected]>
  17. Cc: Boris Ostrovsky <[email protected]>
  18. Cc: Borislav Petkov <[email protected]>
  19. Cc: Borislav Petkov <[email protected]>
  20. Cc: Brian Gerst <[email protected]>
  21. Cc: Dave Hansen <[email protected]>
  22. Cc: Dave Hansen <[email protected]>
  23. Cc: David Laight <[email protected]>
  24. Cc: Denys Vlasenko <[email protected]>
  25. Cc: Eduardo Valentin <[email protected]>
  26. Cc: Greg KH <[email protected]>
  27. Cc: H. Peter Anvin <[email protected]>
  28. Cc: Josh Poimboeuf <[email protected]>
  29. Cc: Linus Torvalds <[email protected]>
  30. Cc: Peter Zijlstra <[email protected]>
  31. Cc: Rik van Riel <[email protected]>
  32. Cc: Will Deacon <[email protected]>
  33. Cc: [email protected]
  34. Cc: [email protected]
  35. Cc: [email protected]
  36. Cc: [email protected]
  37. Link: https://lkml.kernel.org/r/[email protected]
  38. Signed-off-by: Ingo Molnar <[email protected]>
  39. (cherry picked from commit 79cc74155218316b9a5d28577c7077b2adba8e58)
  40. Signed-off-by: Andy Whitcroft <[email protected]>
  41. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  42. (cherry picked from commit 9f637574068f1ffdaded1cd1f408917582594b36)
  43. Signed-off-by: Fabian Grünbichler <[email protected]>
  44. ---
  45. arch/x86/include/asm/hypervisor.h | 25 +++++++++++++++----------
  46. 1 file changed, 15 insertions(+), 10 deletions(-)
  47. diff --git a/arch/x86/include/asm/hypervisor.h b/arch/x86/include/asm/hypervisor.h
  48. index 1b0a5abcd8ae..96aa6b9884dc 100644
  49. --- a/arch/x86/include/asm/hypervisor.h
  50. +++ b/arch/x86/include/asm/hypervisor.h
  51. @@ -20,16 +20,7 @@
  52. #ifndef _ASM_X86_HYPERVISOR_H
  53. #define _ASM_X86_HYPERVISOR_H
  54. -#ifdef CONFIG_HYPERVISOR_GUEST
  55. -
  56. -#include <asm/kvm_para.h>
  57. -#include <asm/x86_init.h>
  58. -#include <asm/xen/hypervisor.h>
  59. -
  60. -/*
  61. - * x86 hypervisor information
  62. - */
  63. -
  64. +/* x86 hypervisor types */
  65. enum x86_hypervisor_type {
  66. X86_HYPER_NATIVE = 0,
  67. X86_HYPER_VMWARE,
  68. @@ -39,6 +30,12 @@ enum x86_hypervisor_type {
  69. X86_HYPER_KVM,
  70. };
  71. +#ifdef CONFIG_HYPERVISOR_GUEST
  72. +
  73. +#include <asm/kvm_para.h>
  74. +#include <asm/x86_init.h>
  75. +#include <asm/xen/hypervisor.h>
  76. +
  77. struct hypervisor_x86 {
  78. /* Hypervisor name */
  79. const char *name;
  80. @@ -58,7 +55,15 @@ struct hypervisor_x86 {
  81. extern enum x86_hypervisor_type x86_hyper_type;
  82. extern void init_hypervisor_platform(void);
  83. +static inline bool hypervisor_is_type(enum x86_hypervisor_type type)
  84. +{
  85. + return x86_hyper_type == type;
  86. +}
  87. #else
  88. static inline void init_hypervisor_platform(void) { }
  89. +static inline bool hypervisor_is_type(enum x86_hypervisor_type type)
  90. +{
  91. + return type == X86_HYPER_NATIVE;
  92. +}
  93. #endif /* CONFIG_HYPERVISOR_GUEST */
  94. #endif /* _ASM_X86_HYPERVISOR_H */
  95. --
  96. 2.14.2