Skip to content

Commit a62f4ca

Browse files
KAGA-KOKObp3tk0v
authored andcommitted
x86/boot/32: De-uglify the 2/3 level paging difference in mk_early_pgtbl_32()
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
1 parent 1e2dd57 commit a62f4ca

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
@@ -69,41 +69,43 @@ asmlinkage __visible void __init __noreturn i386_start_kernel(void)
6969
* to the first kernel PMD. Note the upper half of each PMD or PTE are
7070
* always zero at this stage.
7171
*/
72-
void __init mk_early_pgtbl_32(void);
72+
#ifdef CONFIG_X86_PAE
73+
typedef pmd_t pl2_t;
74+
#define pl2_base initial_pg_pmd
75+
#define SET_PL2(val) { .pmd = (val), }
76+
#else
77+
typedef pgd_t pl2_t;
78+
#define pl2_base initial_page_table
79+
#define SET_PL2(val) { .pgd = (val), }
80+
#endif
7381

7482
void __init __no_stack_protector mk_early_pgtbl_32(void)
7583
{
76-
pte_t pte, *ptep;
77-
int i;
78-
unsigned long *ptr;
7984
/* Enough space to fit pagetables for the low memory linear map */
8085
const unsigned long limit = __pa_nodebug(_end) +
8186
(PAGE_TABLE_SIZE(LOWMEM_PAGES) << PAGE_SHIFT);
82-
#ifdef CONFIG_X86_PAE
83-
pmd_t pl2, *pl2p = (pmd_t *)__pa_nodebug(initial_pg_pmd);
84-
#define SET_PL2(pl2, val) { (pl2).pmd = (val); }
85-
#else
86-
pgd_t pl2, *pl2p = (pgd_t *)__pa_nodebug(initial_page_table);
87-
#define SET_PL2(pl2, val) { (pl2).pgd = (val); }
88-
#endif
87+
pte_t pte, *ptep = (pte_t *)__pa_nodebug(__brk_base);
88+
pl2_t *pl2p = (pl2_t *)__pa_nodebug(pl2_base);
89+
unsigned long *ptr;
90+
int i;
8991

90-
ptep = (pte_t *)__pa_nodebug(__brk_base);
9192
pte.pte = PTE_IDENT_ATTR;
9293

9394
while ((pte.pte & PTE_PFN_MASK) < limit) {
95+
pl2_t pl2 = SET_PL2((unsigned long)ptep | PDE_IDENT_ATTR);
9496

95-
SET_PL2(pl2, (unsigned long)ptep | PDE_IDENT_ATTR);
9697
*pl2p = pl2;
97-
#ifndef CONFIG_X86_PAE
98-
/* Kernel PDE entry */
99-
*(pl2p + ((PAGE_OFFSET >> PGDIR_SHIFT))) = pl2;
100-
#endif
98+
99+
if (!IS_ENABLED(CONFIG_X86_PAE)) {
100+
/* Kernel PDE entry */
101+
*(pl2p + ((PAGE_OFFSET >> PGDIR_SHIFT))) = pl2;
102+
}
103+
101104
for (i = 0; i < PTRS_PER_PTE; i++) {
102105
*ptep = pte;
103106
pte.pte += PAGE_SIZE;
104107
ptep++;
105108
}
106-
107109
pl2p++;
108110
}
109111

0 commit comments

Comments
 (0)