0030-x86-paravirt-Remove-no-longer-used-paravirt-function.patch 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. From bbb647f65a627420f8c3351b34d14490a9878509 Mon Sep 17 00:00:00 2001
  2. From: Juergen Gross <[email protected]>
  3. Date: Mon, 4 Sep 2017 12:25:27 +0200
  4. Subject: [PATCH 030/242] x86/paravirt: Remove no longer used paravirt
  5. functions
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. CVE-2017-5754
  10. With removal of lguest some of the paravirt functions are no longer
  11. needed:
  12. ->read_cr4()
  13. ->store_idt()
  14. ->set_pmd_at()
  15. ->set_pud_at()
  16. ->pte_update()
  17. Remove them.
  18. Signed-off-by: Juergen Gross <[email protected]>
  19. Cc: Linus Torvalds <[email protected]>
  20. Cc: Peter Zijlstra <[email protected]>
  21. Cc: Thomas Gleixner <[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. Link: http://lkml.kernel.org/r/[email protected]
  30. Signed-off-by: Ingo Molnar <[email protected]>
  31. (cherry picked from commit 87930019c713873a1c3b9bd55dde46e81f70c8f1)
  32. Signed-off-by: Andy Whitcroft <[email protected]>
  33. Signed-off-by: Kleber Sacilotto de Souza <[email protected]>
  34. (cherry picked from commit edf3ab0080a6e79a300753e66929b0b7499eaec5)
  35. Signed-off-by: Fabian Grünbichler <[email protected]>
  36. ---
  37. arch/x86/include/asm/desc.h | 3 +--
  38. arch/x86/include/asm/paravirt.h | 37 -----------------------------------
  39. arch/x86/include/asm/paravirt_types.h | 9 ---------
  40. arch/x86/include/asm/pgtable.h | 27 ++++---------------------
  41. arch/x86/include/asm/special_insns.h | 10 +++++-----
  42. arch/x86/kernel/paravirt.c | 5 -----
  43. arch/x86/kvm/vmx.c | 2 +-
  44. arch/x86/mm/pgtable.c | 7 +------
  45. arch/x86/xen/enlighten_pv.c | 2 --
  46. arch/x86/xen/mmu_pv.c | 2 --
  47. 10 files changed, 12 insertions(+), 92 deletions(-)
  48. diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
  49. index 57e502a4e92f..f995e5a09136 100644
  50. --- a/arch/x86/include/asm/desc.h
  51. +++ b/arch/x86/include/asm/desc.h
  52. @@ -120,7 +120,6 @@ static inline int desc_empty(const void *ptr)
  53. #define load_ldt(ldt) asm volatile("lldt %0"::"m" (ldt))
  54. #define store_gdt(dtr) native_store_gdt(dtr)
  55. -#define store_idt(dtr) native_store_idt(dtr)
  56. #define store_tr(tr) (tr = native_store_tr())
  57. #define load_TLS(t, cpu) native_load_tls(t, cpu)
  58. @@ -241,7 +240,7 @@ static inline void native_store_gdt(struct desc_ptr *dtr)
  59. asm volatile("sgdt %0":"=m" (*dtr));
  60. }
  61. -static inline void native_store_idt(struct desc_ptr *dtr)
  62. +static inline void store_idt(struct desc_ptr *dtr)
  63. {
  64. asm volatile("sidt %0":"=m" (*dtr));
  65. }
  66. diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
  67. index c25dd22f7c70..12deec722cf0 100644
  68. --- a/arch/x86/include/asm/paravirt.h
  69. +++ b/arch/x86/include/asm/paravirt.h
  70. @@ -71,11 +71,6 @@ static inline void write_cr3(unsigned long x)
  71. PVOP_VCALL1(pv_mmu_ops.write_cr3, x);
  72. }
  73. -static inline unsigned long __read_cr4(void)
  74. -{
  75. - return PVOP_CALL0(unsigned long, pv_cpu_ops.read_cr4);
  76. -}
  77. -
  78. static inline void __write_cr4(unsigned long x)
  79. {
  80. PVOP_VCALL1(pv_cpu_ops.write_cr4, x);
  81. @@ -228,10 +223,6 @@ static inline void set_ldt(const void *addr, unsigned entries)
  82. {
  83. PVOP_VCALL2(pv_cpu_ops.set_ldt, addr, entries);
  84. }
  85. -static inline void store_idt(struct desc_ptr *dtr)
  86. -{
  87. - PVOP_VCALL1(pv_cpu_ops.store_idt, dtr);
  88. -}
  89. static inline unsigned long paravirt_store_tr(void)
  90. {
  91. return PVOP_CALL0(unsigned long, pv_cpu_ops.store_tr);
  92. @@ -365,12 +356,6 @@ static inline void paravirt_release_p4d(unsigned long pfn)
  93. PVOP_VCALL1(pv_mmu_ops.release_p4d, pfn);
  94. }
  95. -static inline void pte_update(struct mm_struct *mm, unsigned long addr,
  96. - pte_t *ptep)
  97. -{
  98. - PVOP_VCALL3(pv_mmu_ops.pte_update, mm, addr, ptep);
  99. -}
  100. -
  101. static inline pte_t __pte(pteval_t val)
  102. {
  103. pteval_t ret;
  104. @@ -472,28 +457,6 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,
  105. PVOP_VCALL4(pv_mmu_ops.set_pte_at, mm, addr, ptep, pte.pte);
  106. }
  107. -static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
  108. - pmd_t *pmdp, pmd_t pmd)
  109. -{
  110. - if (sizeof(pmdval_t) > sizeof(long))
  111. - /* 5 arg words */
  112. - pv_mmu_ops.set_pmd_at(mm, addr, pmdp, pmd);
  113. - else
  114. - PVOP_VCALL4(pv_mmu_ops.set_pmd_at, mm, addr, pmdp,
  115. - native_pmd_val(pmd));
  116. -}
  117. -
  118. -static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
  119. - pud_t *pudp, pud_t pud)
  120. -{
  121. - if (sizeof(pudval_t) > sizeof(long))
  122. - /* 5 arg words */
  123. - pv_mmu_ops.set_pud_at(mm, addr, pudp, pud);
  124. - else
  125. - PVOP_VCALL4(pv_mmu_ops.set_pud_at, mm, addr, pudp,
  126. - native_pud_val(pud));
  127. -}
  128. -
  129. static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
  130. {
  131. pmdval_t val = native_pmd_val(pmd);
  132. diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
  133. index 6b64fc6367f2..42873edd9f9d 100644
  134. --- a/arch/x86/include/asm/paravirt_types.h
  135. +++ b/arch/x86/include/asm/paravirt_types.h
  136. @@ -107,7 +107,6 @@ struct pv_cpu_ops {
  137. unsigned long (*read_cr0)(void);
  138. void (*write_cr0)(unsigned long);
  139. - unsigned long (*read_cr4)(void);
  140. void (*write_cr4)(unsigned long);
  141. #ifdef CONFIG_X86_64
  142. @@ -119,8 +118,6 @@ struct pv_cpu_ops {
  143. void (*load_tr_desc)(void);
  144. void (*load_gdt)(const struct desc_ptr *);
  145. void (*load_idt)(const struct desc_ptr *);
  146. - /* store_gdt has been removed. */
  147. - void (*store_idt)(struct desc_ptr *);
  148. void (*set_ldt)(const void *desc, unsigned entries);
  149. unsigned long (*store_tr)(void);
  150. void (*load_tls)(struct thread_struct *t, unsigned int cpu);
  151. @@ -245,12 +242,6 @@ struct pv_mmu_ops {
  152. void (*set_pte_at)(struct mm_struct *mm, unsigned long addr,
  153. pte_t *ptep, pte_t pteval);
  154. void (*set_pmd)(pmd_t *pmdp, pmd_t pmdval);
  155. - void (*set_pmd_at)(struct mm_struct *mm, unsigned long addr,
  156. - pmd_t *pmdp, pmd_t pmdval);
  157. - void (*set_pud_at)(struct mm_struct *mm, unsigned long addr,
  158. - pud_t *pudp, pud_t pudval);
  159. - void (*pte_update)(struct mm_struct *mm, unsigned long addr,
  160. - pte_t *ptep);
  161. pte_t (*ptep_modify_prot_start)(struct mm_struct *mm, unsigned long addr,
  162. pte_t *ptep);
  163. diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
  164. index 77037b6f1caa..bb8e9ea7deb4 100644
  165. --- a/arch/x86/include/asm/pgtable.h
  166. +++ b/arch/x86/include/asm/pgtable.h
  167. @@ -43,8 +43,6 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
  168. #else /* !CONFIG_PARAVIRT */
  169. #define set_pte(ptep, pte) native_set_pte(ptep, pte)
  170. #define set_pte_at(mm, addr, ptep, pte) native_set_pte_at(mm, addr, ptep, pte)
  171. -#define set_pmd_at(mm, addr, pmdp, pmd) native_set_pmd_at(mm, addr, pmdp, pmd)
  172. -#define set_pud_at(mm, addr, pudp, pud) native_set_pud_at(mm, addr, pudp, pud)
  173. #define set_pte_atomic(ptep, pte) \
  174. native_set_pte_atomic(ptep, pte)
  175. @@ -75,8 +73,6 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
  176. #define pte_clear(mm, addr, ptep) native_pte_clear(mm, addr, ptep)
  177. #define pmd_clear(pmd) native_pmd_clear(pmd)
  178. -#define pte_update(mm, addr, ptep) do { } while (0)
  179. -
  180. #define pgd_val(x) native_pgd_val(x)
  181. #define __pgd(x) native_make_pgd(x)
  182. @@ -965,31 +961,18 @@ static inline void native_set_pte_at(struct mm_struct *mm, unsigned long addr,
  183. native_set_pte(ptep, pte);
  184. }
  185. -static inline void native_set_pmd_at(struct mm_struct *mm, unsigned long addr,
  186. - pmd_t *pmdp , pmd_t pmd)
  187. +static inline void set_pmd_at(struct mm_struct *mm, unsigned long addr,
  188. + pmd_t *pmdp, pmd_t pmd)
  189. {
  190. native_set_pmd(pmdp, pmd);
  191. }
  192. -static inline void native_set_pud_at(struct mm_struct *mm, unsigned long addr,
  193. - pud_t *pudp, pud_t pud)
  194. +static inline void set_pud_at(struct mm_struct *mm, unsigned long addr,
  195. + pud_t *pudp, pud_t pud)
  196. {
  197. native_set_pud(pudp, pud);
  198. }
  199. -#ifndef CONFIG_PARAVIRT
  200. -/*
  201. - * Rules for using pte_update - it must be called after any PTE update which
  202. - * has not been done using the set_pte / clear_pte interfaces. It is used by
  203. - * shadow mode hypervisors to resynchronize the shadow page tables. Kernel PTE
  204. - * updates should either be sets, clears, or set_pte_atomic for P->P
  205. - * transitions, which means this hook should only be called for user PTEs.
  206. - * This hook implies a P->P protection or access change has taken place, which
  207. - * requires a subsequent TLB flush.
  208. - */
  209. -#define pte_update(mm, addr, ptep) do { } while (0)
  210. -#endif
  211. -
  212. /*
  213. * We only update the dirty/accessed state if we set
  214. * the dirty bit by hand in the kernel, since the hardware
  215. @@ -1017,7 +1000,6 @@ static inline pte_t ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
  216. pte_t *ptep)
  217. {
  218. pte_t pte = native_ptep_get_and_clear(ptep);
  219. - pte_update(mm, addr, ptep);
  220. return pte;
  221. }
  222. @@ -1044,7 +1026,6 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm,
  223. unsigned long addr, pte_t *ptep)
  224. {
  225. clear_bit(_PAGE_BIT_RW, (unsigned long *)&ptep->pte);
  226. - pte_update(mm, addr, ptep);
  227. }
  228. #define flush_tlb_fix_spurious_fault(vma, address) do { } while (0)
  229. diff --git a/arch/x86/include/asm/special_insns.h b/arch/x86/include/asm/special_insns.h
  230. index 9efaabf5b54b..a24dfcf79f4a 100644
  231. --- a/arch/x86/include/asm/special_insns.h
  232. +++ b/arch/x86/include/asm/special_insns.h
  233. @@ -135,6 +135,11 @@ static inline void native_wbinvd(void)
  234. extern asmlinkage void native_load_gs_index(unsigned);
  235. +static inline unsigned long __read_cr4(void)
  236. +{
  237. + return native_read_cr4();
  238. +}
  239. +
  240. #ifdef CONFIG_PARAVIRT
  241. #include <asm/paravirt.h>
  242. #else
  243. @@ -173,11 +178,6 @@ static inline void write_cr3(unsigned long x)
  244. native_write_cr3(x);
  245. }
  246. -static inline unsigned long __read_cr4(void)
  247. -{
  248. - return native_read_cr4();
  249. -}
  250. -
  251. static inline void __write_cr4(unsigned long x)
  252. {
  253. native_write_cr4(x);
  254. diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
  255. index a14df9eecfed..19a3e8f961c7 100644
  256. --- a/arch/x86/kernel/paravirt.c
  257. +++ b/arch/x86/kernel/paravirt.c
  258. @@ -327,7 +327,6 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
  259. .set_debugreg = native_set_debugreg,
  260. .read_cr0 = native_read_cr0,
  261. .write_cr0 = native_write_cr0,
  262. - .read_cr4 = native_read_cr4,
  263. .write_cr4 = native_write_cr4,
  264. #ifdef CONFIG_X86_64
  265. .read_cr8 = native_read_cr8,
  266. @@ -343,7 +342,6 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
  267. .set_ldt = native_set_ldt,
  268. .load_gdt = native_load_gdt,
  269. .load_idt = native_load_idt,
  270. - .store_idt = native_store_idt,
  271. .store_tr = native_store_tr,
  272. .load_tls = native_load_tls,
  273. #ifdef CONFIG_X86_64
  274. @@ -411,8 +409,6 @@ struct pv_mmu_ops pv_mmu_ops __ro_after_init = {
  275. .set_pte = native_set_pte,
  276. .set_pte_at = native_set_pte_at,
  277. .set_pmd = native_set_pmd,
  278. - .set_pmd_at = native_set_pmd_at,
  279. - .pte_update = paravirt_nop,
  280. .ptep_modify_prot_start = __ptep_modify_prot_start,
  281. .ptep_modify_prot_commit = __ptep_modify_prot_commit,
  282. @@ -424,7 +420,6 @@ struct pv_mmu_ops pv_mmu_ops __ro_after_init = {
  283. .pmd_clear = native_pmd_clear,
  284. #endif
  285. .set_pud = native_set_pud,
  286. - .set_pud_at = native_set_pud_at,
  287. .pmd_val = PTE_IDENT,
  288. .make_pmd = PTE_IDENT,
  289. diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
  290. index 7b447d126d17..dd4996a96c71 100644
  291. --- a/arch/x86/kvm/vmx.c
  292. +++ b/arch/x86/kvm/vmx.c
  293. @@ -5174,7 +5174,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
  294. vmcs_write16(HOST_SS_SELECTOR, __KERNEL_DS); /* 22.2.4 */
  295. vmcs_write16(HOST_TR_SELECTOR, GDT_ENTRY_TSS*8); /* 22.2.4 */
  296. - native_store_idt(&dt);
  297. + store_idt(&dt);
  298. vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
  299. vmx->host_idt_base = dt.address;
  300. diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
  301. index 508a708eb9a6..942391b5b639 100644
  302. --- a/arch/x86/mm/pgtable.c
  303. +++ b/arch/x86/mm/pgtable.c
  304. @@ -426,10 +426,8 @@ int ptep_set_access_flags(struct vm_area_struct *vma,
  305. {
  306. int changed = !pte_same(*ptep, entry);
  307. - if (changed && dirty) {
  308. + if (changed && dirty)
  309. *ptep = entry;
  310. - pte_update(vma->vm_mm, address, ptep);
  311. - }
  312. return changed;
  313. }
  314. @@ -486,9 +484,6 @@ int ptep_test_and_clear_young(struct vm_area_struct *vma,
  315. ret = test_and_clear_bit(_PAGE_BIT_ACCESSED,
  316. (unsigned long *) &ptep->pte);
  317. - if (ret)
  318. - pte_update(vma->vm_mm, addr, ptep);
  319. -
  320. return ret;
  321. }
  322. diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c
  323. index ae2a2e2d6362..69b9deff7e5c 100644
  324. --- a/arch/x86/xen/enlighten_pv.c
  325. +++ b/arch/x86/xen/enlighten_pv.c
  326. @@ -1038,7 +1038,6 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
  327. .read_cr0 = xen_read_cr0,
  328. .write_cr0 = xen_write_cr0,
  329. - .read_cr4 = native_read_cr4,
  330. .write_cr4 = xen_write_cr4,
  331. #ifdef CONFIG_X86_64
  332. @@ -1073,7 +1072,6 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = {
  333. .alloc_ldt = xen_alloc_ldt,
  334. .free_ldt = xen_free_ldt,
  335. - .store_idt = native_store_idt,
  336. .store_tr = xen_store_tr,
  337. .write_ldt_entry = xen_write_ldt_entry,
  338. diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c
  339. index cab28cf2cffb..5f61b7e2e6b2 100644
  340. --- a/arch/x86/xen/mmu_pv.c
  341. +++ b/arch/x86/xen/mmu_pv.c
  342. @@ -2430,8 +2430,6 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
  343. .flush_tlb_single = xen_flush_tlb_single,
  344. .flush_tlb_others = xen_flush_tlb_others,
  345. - .pte_update = paravirt_nop,
  346. -
  347. .pgd_alloc = xen_pgd_alloc,
  348. .pgd_free = xen_pgd_free,
  349. --
  350. 2.14.2