Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/pgtable: Move two more functions from pgtable_64.h to pgtable.h

These two functions are required for PTI on 32 bit:

* pgdp_maps_userspace()
* pgd_large()

Also re-implement pgdp_maps_userspace() so that it will work on 64 and 32
bit kernels.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Pavel Machek <pavel@ucw.cz>
Cc: "H . Peter Anvin" <hpa@zytor.com>
Cc: linux-mm@kvack.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: David Laight <David.Laight@aculab.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: Eduardo Valentin <eduval@amazon.com>
Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: Will Deacon <will.deacon@arm.com>
Cc: aliguori@amazon.com
Cc: daniel.gruss@iaik.tugraz.at
Cc: hughd@google.com
Cc: keescook@google.com
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Waiman Long <llong@redhat.com>
Cc: "David H . Gutteridge" <dhgutteridge@sympatico.ca>
Cc: joro@8bytes.org
Link: https://lkml.kernel.org/r/1531906876-13451-21-git-send-email-joro@8bytes.org

authored by

Joerg Roedel and committed by
Thomas Gleixner
76e258ad fcbbd977

+21 -38
+3
arch/x86/include/asm/pgtable-2level_types.h
··· 35 35 36 36 #define PTRS_PER_PTE 1024 37 37 38 + /* This covers all VMSPLIT_* and VMSPLIT_*_OPT variants */ 39 + #define PGD_KERNEL_START (CONFIG_PAGE_OFFSET >> PGDIR_SHIFT) 40 + 38 41 #endif /* _ASM_X86_PGTABLE_2LEVEL_DEFS_H */
+1
arch/x86/include/asm/pgtable-3level_types.h
··· 46 46 #define PTRS_PER_PTE 512 47 47 48 48 #define MAX_POSSIBLE_PHYSMEM_BITS 36 49 + #define PGD_KERNEL_START (CONFIG_PAGE_OFFSET >> PGDIR_SHIFT) 49 50 50 51 #endif /* _ASM_X86_PGTABLE_3LEVEL_DEFS_H */
+15
arch/x86/include/asm/pgtable.h
··· 1177 1177 } 1178 1178 } 1179 1179 #endif 1180 + /* 1181 + * Page table pages are page-aligned. The lower half of the top 1182 + * level is used for userspace and the top half for the kernel. 1183 + * 1184 + * Returns true for parts of the PGD that map userspace and 1185 + * false for the parts that map the kernel. 1186 + */ 1187 + static inline bool pgdp_maps_userspace(void *__ptr) 1188 + { 1189 + unsigned long ptr = (unsigned long)__ptr; 1190 + 1191 + return (((ptr & ~PAGE_MASK) / sizeof(pgd_t)) < PGD_KERNEL_START); 1192 + } 1193 + 1194 + static inline int pgd_large(pgd_t pgd) { return 0; } 1180 1195 1181 1196 #ifdef CONFIG_PAGE_TABLE_ISOLATION 1182 1197 /*
-2
arch/x86/include/asm/pgtable_32.h
··· 34 34 void paging_init(void); 35 35 void sync_initial_page_table(void); 36 36 37 - static inline int pgd_large(pgd_t pgd) { return 0; } 38 - 39 37 /* 40 38 * Define this if things work differently on an i386 and an i486: 41 39 * it will (on an i486) warn about kernel memory accesses that are
-36
arch/x86/include/asm/pgtable_64.h
··· 132 132 #endif 133 133 } 134 134 135 - /* 136 - * Page table pages are page-aligned. The lower half of the top 137 - * level is used for userspace and the top half for the kernel. 138 - * 139 - * Returns true for parts of the PGD that map userspace and 140 - * false for the parts that map the kernel. 141 - */ 142 - static inline bool pgdp_maps_userspace(void *__ptr) 143 - { 144 - unsigned long ptr = (unsigned long)__ptr; 145 - 146 - return (ptr & ~PAGE_MASK) < (PAGE_SIZE / 2); 147 - } 148 - 149 - #ifdef CONFIG_PAGE_TABLE_ISOLATION 150 - pgd_t __pti_set_user_pgtbl(pgd_t *pgdp, pgd_t pgd); 151 - 152 - /* 153 - * Take a PGD location (pgdp) and a pgd value that needs to be set there. 154 - * Populates the user and returns the resulting PGD that must be set in 155 - * the kernel copy of the page tables. 156 - */ 157 - static inline pgd_t pti_set_user_pgtbl(pgd_t *pgdp, pgd_t pgd) 158 - { 159 - if (!static_cpu_has(X86_FEATURE_PTI)) 160 - return pgd; 161 - return __pti_set_user_pgtbl(pgdp, pgd); 162 - } 163 - #else 164 - static inline pgd_t pti_set_user_pgtbl(pgd_t *pgdp, pgd_t pgd) 165 - { 166 - return pgd; 167 - } 168 - #endif 169 - 170 135 static inline void native_set_p4d(p4d_t *p4dp, p4d_t p4d) 171 136 { 172 137 pgd_t pgd; ··· 171 206 /* 172 207 * Level 4 access. 173 208 */ 174 - static inline int pgd_large(pgd_t pgd) { return 0; } 175 209 #define mk_kernel_pgd(address) __pgd((address) | _KERNPG_TABLE) 176 210 177 211 /* PUD - Level3 access */
+2
arch/x86/include/asm/pgtable_64_types.h
··· 153 153 154 154 #define EARLY_DYNAMIC_PAGE_TABLES 64 155 155 156 + #define PGD_KERNEL_START ((PAGE_SIZE / 2) / sizeof(pgd_t)) 157 + 156 158 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */