Skip to content

Commit c76431e

Browse files
committed
Merge tag 'x86_mm_for_v6.19_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 mm updates from Borislav Petkov: - Use the proper accessors when reading CR3 as part of the page level transitions (5-level to 4-level, the use case being kexec) so that only the physical address in CR3 is picked up and not flags which are above the physical mask shift - Clean up and unify __phys_addr_symbol() definitions * tag 'x86_mm_for_v6.19_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: efi/libstub: Fix page table access in 5-level to 4-level paging transition x86/boot: Fix page table access in 5-level to 4-level paging transition x86/mm: Unify __phys_addr_symbol()
2 parents a9a10e9 + 8436112 commit c76431e

4 files changed

Lines changed: 20 additions & 20 deletions

File tree

arch/x86/boot/compressed/pgtable_64.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <asm/bootparam.h>
44
#include <asm/bootparam_utils.h>
55
#include <asm/e820/types.h>
6+
#include <asm/pgtable.h>
67
#include <asm/processor.h>
78
#include "../string.h"
89
#include "efi.h"
@@ -168,9 +169,10 @@ asmlinkage void configure_5level_paging(struct boot_params *bp, void *pgtable)
168169
* For 4- to 5-level paging transition, set up current CR3 as
169170
* the first and the only entry in a new top-level page table.
170171
*/
171-
*trampoline_32bit = __native_read_cr3() | _PAGE_TABLE_NOENC;
172+
*trampoline_32bit = native_read_cr3_pa() | _PAGE_TABLE_NOENC;
172173
} else {
173-
unsigned long src;
174+
u64 *new_cr3;
175+
pgd_t *pgdp;
174176

175177
/*
176178
* For 5- to 4-level paging transition, copy page table pointed
@@ -180,8 +182,9 @@ asmlinkage void configure_5level_paging(struct boot_params *bp, void *pgtable)
180182
* We cannot just point to the page table from trampoline as it
181183
* may be above 4G.
182184
*/
183-
src = *(unsigned long *)__native_read_cr3() & PAGE_MASK;
184-
memcpy(trampoline_32bit, (void *)src, PAGE_SIZE);
185+
pgdp = (pgd_t *)native_read_cr3_pa();
186+
new_cr3 = (u64 *)(native_pgd_val(pgdp[0]) & PTE_PFN_MASK);
187+
memcpy(trampoline_32bit, new_cr3, PAGE_SIZE);
185188
}
186189

187190
toggle_la57(trampoline_32bit);

arch/x86/include/asm/page_64.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <asm/alternative.h>
1010

1111
#include <linux/kmsan-checks.h>
12+
#include <linux/mmdebug.h>
1213

1314
/* duplicated to the one in bootmem.h */
1415
extern unsigned long max_pfn;
@@ -31,13 +32,20 @@ static __always_inline unsigned long __phys_addr_nodebug(unsigned long x)
3132

3233
#ifdef CONFIG_DEBUG_VIRTUAL
3334
extern unsigned long __phys_addr(unsigned long);
34-
extern unsigned long __phys_addr_symbol(unsigned long);
3535
#else
3636
#define __phys_addr(x) __phys_addr_nodebug(x)
37-
#define __phys_addr_symbol(x) \
38-
((unsigned long)(x) - __START_KERNEL_map + phys_base)
3937
#endif
4038

39+
static inline unsigned long __phys_addr_symbol(unsigned long x)
40+
{
41+
unsigned long y = x - __START_KERNEL_map;
42+
43+
/* only check upper bounds since lower bounds will trigger carry */
44+
VIRTUAL_BUG_ON(y >= KERNEL_IMAGE_SIZE);
45+
46+
return y + phys_base;
47+
}
48+
4149
#define __phys_reloc_hide(x) (x)
4250

4351
void clear_page_orig(void *page);

arch/x86/mm/physaddr.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,6 @@ unsigned long __phys_addr(unsigned long x)
3131
return x;
3232
}
3333
EXPORT_SYMBOL(__phys_addr);
34-
35-
unsigned long __phys_addr_symbol(unsigned long x)
36-
{
37-
unsigned long y = x - __START_KERNEL_map;
38-
39-
/* only check upper bounds since lower bounds will trigger carry */
40-
VIRTUAL_BUG_ON(y >= KERNEL_IMAGE_SIZE);
41-
42-
return y + phys_base;
43-
}
44-
EXPORT_SYMBOL(__phys_addr_symbol);
4534
#endif
4635

4736
bool __virt_addr_valid(unsigned long x)

drivers/firmware/efi/libstub/x86-5lvl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void efi_5level_switch(void)
6666
bool have_la57 = native_read_cr4() & X86_CR4_LA57;
6767
bool need_toggle = want_la57 ^ have_la57;
6868
u64 *pgt = (void *)la57_toggle + PAGE_SIZE;
69-
u64 *cr3 = (u64 *)__native_read_cr3();
69+
pgd_t *cr3 = (pgd_t *)native_read_cr3_pa();
7070
u64 *new_cr3;
7171

7272
if (!la57_toggle || !need_toggle)
@@ -82,7 +82,7 @@ void efi_5level_switch(void)
8282
new_cr3[0] = (u64)cr3 | _PAGE_TABLE_NOENC;
8383
} else {
8484
/* take the new root table pointer from the current entry #0 */
85-
new_cr3 = (u64 *)(cr3[0] & PAGE_MASK);
85+
new_cr3 = (u64 *)(native_pgd_val(cr3[0]) & PTE_PFN_MASK);
8686

8787
/* copy the new root table if it is not 32-bit addressable */
8888
if ((u64)new_cr3 > U32_MAX)

0 commit comments

Comments
 (0)