0025-x86-paravirt-xen-Remove-xen_patch.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. From e61e24c7ee0d773230646650659c34ffc5316520 Mon Sep 17 00:00:00 2001
  2. From: Juergen Gross <[email protected]>
  3. Date: Wed, 16 Aug 2017 19:31:56 +0200
  4. Subject: [PATCH 025/242] x86/paravirt/xen: Remove xen_patch()
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. CVE-2017-5754
  9. Xen's paravirt patch function xen_patch() does some special casing for
  10. irq_ops functions to apply relocations when those functions can be
  11. patched inline instead of calls.
  12. Unfortunately none of the special case function replacements is small
  13. enough to be patched inline, so the special case never applies.
  14. As xen_patch() will call paravirt_patch_default() in all cases it can
  15. be just dropped. xen-asm.h doesn't seem necessary without xen_patch()
  16. as the only thing left in it would be the definition of XEN_EFLAGS_NMI
  17. used only once. So move that definition and remove xen-asm.h.
  18. Signed-off-by: Juergen Gross <[email protected]>
  19. Reviewed-by: Josh Poimboeuf <[email protected]>
  20. Cc: Linus Torvalds <[email protected]>
  21. Cc: Peter Zijlstra <[email protected]>
  22. Cc: Thomas Gleixner <[email protected]>
  23. Cc: [email protected]
  24. Cc: [email protected]
  25. Cc: [email protected]
  26. Cc: [email protected]
  27. Link: http://lkml.kernel.org/r/[email protected]
  28. Signed-off-by: Ingo Molnar <[email protected]>
  29. (cherry picked from commit edcb5cf84f05e5d2e2af25422a72ccde359fcca9)
  30. Signed-off-by: Andy Whitcroft <[email protected]>
  31. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  32. (cherry picked from commit c96c9c712136a9e24a7aaf0aac4c149eee01bd8e)
  33. Signed-off-by: Fabian Grünbichler <[email protected]>
  34. ---
  35. arch/x86/xen/xen-asm.h | 12 ---------
  36. arch/x86/xen/xen-ops.h | 15 +++---------
  37. arch/x86/xen/enlighten_pv.c | 59 +--------------------------------------------
  38. arch/x86/xen/xen-asm.S | 26 +++++---------------
  39. arch/x86/xen/xen-asm_32.S | 27 ++++-----------------
  40. arch/x86/xen/xen-asm_64.S | 20 ++++-----------
  41. 6 files changed, 21 insertions(+), 138 deletions(-)
  42. delete mode 100644 arch/x86/xen/xen-asm.h
  43. diff --git a/arch/x86/xen/xen-asm.h b/arch/x86/xen/xen-asm.h
  44. deleted file mode 100644
  45. index 465276467a47..000000000000
  46. --- a/arch/x86/xen/xen-asm.h
  47. +++ /dev/null
  48. @@ -1,12 +0,0 @@
  49. -#ifndef _XEN_XEN_ASM_H
  50. -#define _XEN_XEN_ASM_H
  51. -
  52. -#include <linux/linkage.h>
  53. -
  54. -#define RELOC(x, v) .globl x##_reloc; x##_reloc=v
  55. -#define ENDPATCH(x) .globl x##_end; x##_end=.
  56. -
  57. -/* Pseudo-flag used for virtual NMI, which we don't implement yet */
  58. -#define XEN_EFLAGS_NMI 0x80000000
  59. -
  60. -#endif
  61. diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
  62. index 0d5004477db6..70301ac0d414 100644
  63. --- a/arch/x86/xen/xen-ops.h
  64. +++ b/arch/x86/xen/xen-ops.h
  65. @@ -129,17 +129,10 @@ static inline void __init xen_efi_init(void)
  66. }
  67. #endif
  68. -/* Declare an asm function, along with symbols needed to make it
  69. - inlineable */
  70. -#define DECL_ASM(ret, name, ...) \
  71. - __visible ret name(__VA_ARGS__); \
  72. - extern char name##_end[] __visible; \
  73. - extern char name##_reloc[] __visible
  74. -
  75. -DECL_ASM(void, xen_irq_enable_direct, void);
  76. -DECL_ASM(void, xen_irq_disable_direct, void);
  77. -DECL_ASM(unsigned long, xen_save_fl_direct, void);
  78. -DECL_ASM(void, xen_restore_fl_direct, unsigned long);
  79. +__visible void xen_irq_enable_direct(void);
  80. +__visible void xen_irq_disable_direct(void);
  81. +__visible unsigned long xen_save_fl_direct(void);
  82. +__visible void xen_restore_fl_direct(unsigned long);
  83. /* These are not functions, and cannot be called normally */
  84. __visible void xen_iret(void);
  85. diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
  86. index df1921751aa5..6c279c8f0a0e 100644
  87. --- a/arch/x86/xen/enlighten_pv.c
  88. +++ b/arch/x86/xen/enlighten_pv.c
  89. @@ -988,59 +988,6 @@ void __ref xen_setup_vcpu_info_placement(void)
  90. }
  91. }
  92. -static unsigned xen_patch(u8 type, u16 clobbers, void *insnbuf,
  93. - unsigned long addr, unsigned len)
  94. -{
  95. - char *start, *end, *reloc;
  96. - unsigned ret;
  97. -
  98. - start = end = reloc = NULL;
  99. -
  100. -#define SITE(op, x) \
  101. - case PARAVIRT_PATCH(op.x): \
  102. - if (xen_have_vcpu_info_placement) { \
  103. - start = (char *)xen_##x##_direct; \
  104. - end = xen_##x##_direct_end; \
  105. - reloc = xen_##x##_direct_reloc; \
  106. - } \
  107. - goto patch_site
  108. -
  109. - switch (type) {
  110. - SITE(pv_irq_ops, irq_enable);
  111. - SITE(pv_irq_ops, irq_disable);
  112. - SITE(pv_irq_ops, save_fl);
  113. - SITE(pv_irq_ops, restore_fl);
  114. -#undef SITE
  115. -
  116. - patch_site:
  117. - if (start == NULL || (end-start) > len)
  118. - goto default_patch;
  119. -
  120. - ret = paravirt_patch_insns(insnbuf, len, start, end);
  121. -
  122. - /* Note: because reloc is assigned from something that
  123. - appears to be an array, gcc assumes it's non-null,
  124. - but doesn't know its relationship with start and
  125. - end. */
  126. - if (reloc > start && reloc < end) {
  127. - int reloc_off = reloc - start;
  128. - long *relocp = (long *)(insnbuf + reloc_off);
  129. - long delta = start - (char *)addr;
  130. -
  131. - *relocp += delta;
  132. - }
  133. - break;
  134. -
  135. - default_patch:
  136. - default:
  137. - ret = paravirt_patch_default(type, clobbers, insnbuf,
  138. - addr, len);
  139. - break;
  140. - }
  141. -
  142. - return ret;
  143. -}
  144. -
  145. static const struct pv_info xen_info __initconst = {
  146. .shared_kernel_pmd = 0,
  147. @@ -1050,10 +997,6 @@ static const struct pv_info xen_info __initconst = {
  148. .name = "Xen",
  149. };
  150. -static const struct pv_init_ops xen_init_ops __initconst = {
  151. - .patch = xen_patch,
  152. -};
  153. -
  154. static const struct pv_cpu_ops xen_cpu_ops __initconst = {
  155. .cpuid = xen_cpuid,
  156. @@ -1251,7 +1194,7 @@ asmlinkage __visible void __init xen_start_kernel(void)
  157. /* Install Xen paravirt ops */
  158. pv_info = xen_info;
  159. - pv_init_ops = xen_init_ops;
  160. + pv_init_ops.patch = paravirt_patch_default;
  161. pv_cpu_ops = xen_cpu_ops;
  162. x86_platform.get_nmi_reason = xen_get_nmi_reason;
  163. diff --git a/arch/x86/xen/xen-asm.S b/arch/x86/xen/xen-asm.S
  164. index eff224df813f..dcd31fa39b5d 100644
  165. --- a/arch/x86/xen/xen-asm.S
  166. +++ b/arch/x86/xen/xen-asm.S
  167. @@ -1,14 +1,8 @@
  168. /*
  169. - * Asm versions of Xen pv-ops, suitable for either direct use or
  170. - * inlining. The inline versions are the same as the direct-use
  171. - * versions, with the pre- and post-amble chopped off.
  172. - *
  173. - * This code is encoded for size rather than absolute efficiency, with
  174. - * a view to being able to inline as much as possible.
  175. + * Asm versions of Xen pv-ops, suitable for direct use.
  176. *
  177. * We only bother with direct forms (ie, vcpu in percpu data) of the
  178. - * operations here; the indirect forms are better handled in C, since
  179. - * they're generally too large to inline anyway.
  180. + * operations here; the indirect forms are better handled in C.
  181. */
  182. #include <asm/asm-offsets.h>
  183. @@ -16,7 +10,7 @@
  184. #include <asm/processor-flags.h>
  185. #include <asm/frame.h>
  186. -#include "xen-asm.h"
  187. +#include <linux/linkage.h>
  188. /*
  189. * Enable events. This clears the event mask and tests the pending
  190. @@ -38,13 +32,11 @@ ENTRY(xen_irq_enable_direct)
  191. testb $0xff, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_pending
  192. jz 1f
  193. -2: call check_events
  194. + call check_events
  195. 1:
  196. -ENDPATCH(xen_irq_enable_direct)
  197. FRAME_END
  198. ret
  199. ENDPROC(xen_irq_enable_direct)
  200. - RELOC(xen_irq_enable_direct, 2b+1)
  201. /*
  202. @@ -53,10 +45,8 @@ ENDPATCH(xen_irq_enable_direct)
  203. */
  204. ENTRY(xen_irq_disable_direct)
  205. movb $1, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask
  206. -ENDPATCH(xen_irq_disable_direct)
  207. ret
  208. - ENDPROC(xen_irq_disable_direct)
  209. - RELOC(xen_irq_disable_direct, 0)
  210. +ENDPROC(xen_irq_disable_direct)
  211. /*
  212. * (xen_)save_fl is used to get the current interrupt enable status.
  213. @@ -71,10 +61,8 @@ ENTRY(xen_save_fl_direct)
  214. testb $0xff, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_mask
  215. setz %ah
  216. addb %ah, %ah
  217. -ENDPATCH(xen_save_fl_direct)
  218. ret
  219. ENDPROC(xen_save_fl_direct)
  220. - RELOC(xen_save_fl_direct, 0)
  221. /*
  222. @@ -101,13 +89,11 @@ ENTRY(xen_restore_fl_direct)
  223. /* check for unmasked and pending */
  224. cmpw $0x0001, PER_CPU_VAR(xen_vcpu_info) + XEN_vcpu_info_pending
  225. jnz 1f
  226. -2: call check_events
  227. + call check_events
  228. 1:
  229. -ENDPATCH(xen_restore_fl_direct)
  230. FRAME_END
  231. ret
  232. ENDPROC(xen_restore_fl_direct)
  233. - RELOC(xen_restore_fl_direct, 2b+1)
  234. /*
  235. diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
  236. index feb6d40a0860..1200e262a116 100644
  237. --- a/arch/x86/xen/xen-asm_32.S
  238. +++ b/arch/x86/xen/xen-asm_32.S
  239. @@ -1,14 +1,8 @@
  240. /*
  241. - * Asm versions of Xen pv-ops, suitable for either direct use or
  242. - * inlining. The inline versions are the same as the direct-use
  243. - * versions, with the pre- and post-amble chopped off.
  244. - *
  245. - * This code is encoded for size rather than absolute efficiency, with
  246. - * a view to being able to inline as much as possible.
  247. + * Asm versions of Xen pv-ops, suitable for direct use.
  248. *
  249. * We only bother with direct forms (ie, vcpu in pda) of the
  250. - * operations here; the indirect forms are better handled in C, since
  251. - * they're generally too large to inline anyway.
  252. + * operations here; the indirect forms are better handled in C.
  253. */
  254. #include <asm/thread_info.h>
  255. @@ -18,21 +12,10 @@
  256. #include <xen/interface/xen.h>
  257. -#include "xen-asm.h"
  258. +#include <linux/linkage.h>
  259. -/*
  260. - * Force an event check by making a hypercall, but preserve regs
  261. - * before making the call.
  262. - */
  263. -check_events:
  264. - push %eax
  265. - push %ecx
  266. - push %edx
  267. - call xen_force_evtchn_callback
  268. - pop %edx
  269. - pop %ecx
  270. - pop %eax
  271. - ret
  272. +/* Pseudo-flag used for virtual NMI, which we don't implement yet */
  273. +#define XEN_EFLAGS_NMI 0x80000000
  274. /*
  275. * This is run where a normal iret would be run, with the same stack setup:
  276. diff --git a/arch/x86/xen/xen-asm_64.S b/arch/x86/xen/xen-asm_64.S
  277. index c5fee2680abc..3a3b6a211584 100644
  278. --- a/arch/x86/xen/xen-asm_64.S
  279. +++ b/arch/x86/xen/xen-asm_64.S
  280. @@ -1,14 +1,8 @@
  281. /*
  282. - * Asm versions of Xen pv-ops, suitable for either direct use or
  283. - * inlining. The inline versions are the same as the direct-use
  284. - * versions, with the pre- and post-amble chopped off.
  285. - *
  286. - * This code is encoded for size rather than absolute efficiency, with
  287. - * a view to being able to inline as much as possible.
  288. + * Asm versions of Xen pv-ops, suitable for direct use.
  289. *
  290. * We only bother with direct forms (ie, vcpu in pda) of the
  291. - * operations here; the indirect forms are better handled in C, since
  292. - * they're generally too large to inline anyway.
  293. + * operations here; the indirect forms are better handled in C.
  294. */
  295. #include <asm/errno.h>
  296. @@ -20,7 +14,7 @@
  297. #include <xen/interface/xen.h>
  298. -#include "xen-asm.h"
  299. +#include <linux/linkage.h>
  300. ENTRY(xen_adjust_exception_frame)
  301. mov 8+0(%rsp), %rcx
  302. @@ -46,9 +40,7 @@ hypercall_iret = hypercall_page + __HYPERVISOR_iret * 32
  303. */
  304. ENTRY(xen_iret)
  305. pushq $0
  306. -1: jmp hypercall_iret
  307. -ENDPATCH(xen_iret)
  308. -RELOC(xen_iret, 1b+1)
  309. + jmp hypercall_iret
  310. ENTRY(xen_sysret64)
  311. /*
  312. @@ -65,9 +57,7 @@ ENTRY(xen_sysret64)
  313. pushq %rcx
  314. pushq $VGCF_in_syscall
  315. -1: jmp hypercall_iret
  316. -ENDPATCH(xen_sysret64)
  317. -RELOC(xen_sysret64, 1b+1)
  318. + jmp hypercall_iret
  319. /*
  320. * Xen handles syscall callbacks much like ordinary exceptions, which
  321. --
  322. 2.14.2