page_64.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _ASM_X86_PAGE_64_H
  3. #define _ASM_X86_PAGE_64_H
  4. #include <asm/page_64_types.h>
  5. #ifndef __ASSEMBLY__
  6. #include <asm/cpufeatures.h>
  7. #include <asm/alternative.h>
  8. #include <linux/kmsan-checks.h>
  9. /* duplicated to the one in bootmem.h */
  10. extern unsigned long max_pfn;
  11. extern unsigned long phys_base;
  12. extern unsigned long page_offset_base;
  13. extern unsigned long vmalloc_base;
  14. extern unsigned long vmemmap_base;
  15. static __always_inline unsigned long __phys_addr_nodebug(unsigned long x)
  16. {
  17. unsigned long y = x - __START_KERNEL_map;
  18. /* use the carry flag to determine if x was < __START_KERNEL_map */
  19. x = y + ((x > y) ? phys_base : (__START_KERNEL_map - PAGE_OFFSET));
  20. return x;
  21. }
  22. #ifdef CONFIG_DEBUG_VIRTUAL
  23. extern unsigned long __phys_addr(unsigned long);
  24. extern unsigned long __phys_addr_symbol(unsigned long);
  25. #else
  26. #define __phys_addr(x) __phys_addr_nodebug(x)
  27. #define __phys_addr_symbol(x) \
  28. ((unsigned long)(x) - __START_KERNEL_map + phys_base)
  29. #endif
  30. #define __phys_reloc_hide(x) (x)
  31. #ifdef CONFIG_FLATMEM
  32. #define pfn_valid(pfn) ((pfn) < max_pfn)
  33. #endif
  34. void clear_page_orig(void *page);
  35. void clear_page_rep(void *page);
  36. void clear_page_erms(void *page);
  37. static inline void clear_page(void *page)
  38. {
  39. /*
  40. * Clean up KMSAN metadata for the page being cleared. The assembly call
  41. * below clobbers @page, so we perform unpoisoning before it.
  42. */
  43. kmsan_unpoison_memory(page, PAGE_SIZE);
  44. alternative_call_2(clear_page_orig,
  45. clear_page_rep, X86_FEATURE_REP_GOOD,
  46. clear_page_erms, X86_FEATURE_ERMS,
  47. "=D" (page),
  48. "0" (page)
  49. : "cc", "memory", "rax", "rcx");
  50. }
  51. void copy_page(void *to, void *from);
  52. #ifdef CONFIG_X86_5LEVEL
  53. /*
  54. * User space process size. This is the first address outside the user range.
  55. * There are a few constraints that determine this:
  56. *
  57. * On Intel CPUs, if a SYSCALL instruction is at the highest canonical
  58. * address, then that syscall will enter the kernel with a
  59. * non-canonical return address, and SYSRET will explode dangerously.
  60. * We avoid this particular problem by preventing anything
  61. * from being mapped at the maximum canonical address.
  62. *
  63. * On AMD CPUs in the Ryzen family, there's a nasty bug in which the
  64. * CPUs malfunction if they execute code from the highest canonical page.
  65. * They'll speculate right off the end of the canonical space, and
  66. * bad things happen. This is worked around in the same way as the
  67. * Intel problem.
  68. *
  69. * With page table isolation enabled, we map the LDT in ... [stay tuned]
  70. */
  71. static __always_inline unsigned long task_size_max(void)
  72. {
  73. unsigned long ret;
  74. alternative_io("movq %[small],%0","movq %[large],%0",
  75. X86_FEATURE_LA57,
  76. "=r" (ret),
  77. [small] "i" ((1ul << 47)-PAGE_SIZE),
  78. [large] "i" ((1ul << 56)-PAGE_SIZE));
  79. return ret;
  80. }
  81. #endif /* CONFIG_X86_5LEVEL */
  82. #endif /* !__ASSEMBLY__ */
  83. #ifdef CONFIG_X86_VSYSCALL_EMULATION
  84. # define __HAVE_ARCH_GATE_AREA 1
  85. #endif
  86. #endif /* _ASM_X86_PAGE_64_H */