Skip to content

Commit f80ac35

Browse files
KAGA-KOKOopsiff
authored andcommitted
x86/boot/32: De-uglify the 2/3 level paging difference in mk_early_pgtbl_32()
stable inclusion from stable-v6.6.82 category: bugfix bugzilla: deepin-community#665 commit a62f4ca upstream Move the ifdeffery out of the function and use proper typedefs to make it work for both 2 and 3 level paging. No functional change. [ bp: Move mk_early_pgtbl_32() declaration into a header. ] Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20231017211722.111059491@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit fa23256)
1 parent 3557b79 commit f80ac35

2 files changed

Lines changed: 21 additions & 18 deletions

File tree

arch/x86/include/asm/setup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ void clear_bss(void);
126126
#ifdef __i386__
127127

128128
asmlinkage void __init __noreturn i386_start_kernel(void);
129+
void __init mk_early_pgtbl_32(void);
129130

130131
#else
131132
asmlinkage void __init __noreturn x86_64_start_kernel(char *real_mode);

arch/x86/kernel/head32.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,41 +72,43 @@ asmlinkage __visible void __init __noreturn i386_start_kernel(void)
7272
* to the first kernel PMD. Note the upper half of each PMD or PTE are
7373
* always zero at this stage.
7474
*/
75-
void __init mk_early_pgtbl_32(void);
75+
#ifdef CONFIG_X86_PAE
76+
typedef pmd_t pl2_t;
77+
#define pl2_base initial_pg_pmd
78+
#define SET_PL2(val) { .pmd = (val), }
79+
#else
80+
typedef pgd_t pl2_t;
81+
#define pl2_base initial_page_table
82+
#define SET_PL2(val) { .pgd = (val), }
83+
#endif
7684

7785
void __init __no_stack_protector mk_early_pgtbl_32(void)
7886
{
79-
pte_t pte, *ptep;
80-
int i;
81-
unsigned long *ptr;
8287
/* Enough space to fit pagetables for the low memory linear map */
8388
const unsigned long limit = __pa_nodebug(_end) +
8489
(PAGE_TABLE_SIZE(LOWMEM_PAGES) << PAGE_SHIFT);
85-
#ifdef CONFIG_X86_PAE
86-
pmd_t pl2, *pl2p = (pmd_t *)__pa_nodebug(initial_pg_pmd);
87-
#define SET_PL2(pl2, val) { (pl2).pmd = (val); }
88-
#else
89-
pgd_t pl2, *pl2p = (pgd_t *)__pa_nodebug(initial_page_table);
90-
#define SET_PL2(pl2, val) { (pl2).pgd = (val); }
91-
#endif
90+
pte_t pte, *ptep = (pte_t *)__pa_nodebug(__brk_base);
91+
pl2_t *pl2p = (pl2_t *)__pa_nodebug(pl2_base);
92+
unsigned long *ptr;
93+
int i;
9294

93-
ptep = (pte_t *)__pa_nodebug(__brk_base);
9495
pte.pte = PTE_IDENT_ATTR;
9596

9697
while ((pte.pte & PTE_PFN_MASK) < limit) {
98+
pl2_t pl2 = SET_PL2((unsigned long)ptep | PDE_IDENT_ATTR);
9799

98-
SET_PL2(pl2, (unsigned long)ptep | PDE_IDENT_ATTR);
99100
*pl2p = pl2;
100-
#ifndef CONFIG_X86_PAE
101-
/* Kernel PDE entry */
102-
*(pl2p + ((PAGE_OFFSET >> PGDIR_SHIFT))) = pl2;
103-
#endif
101+
102+
if (!IS_ENABLED(CONFIG_X86_PAE)) {
103+
/* Kernel PDE entry */
104+
*(pl2p + ((PAGE_OFFSET >> PGDIR_SHIFT))) = pl2;
105+
}
106+
104107
for (i = 0; i < PTRS_PER_PTE; i++) {
105108
*ptep = pte;
106109
pte.pte += PAGE_SIZE;
107110
ptep++;
108111
}
109-
110112
pl2p++;
111113
}
112114

0 commit comments

Comments
 (0)