From: Shengming Hu <shengminghu512@qq.com>
Date: Wed, 8 Oct 2025 21:46:03 +0800
Subject: [PATCH v1] x86/boot: Use pgd_index(__START_KERNEL_map) instead of
hardcoded 511
The index 511 is used to set up the kernel high mapping in the
top-level page table.
Replacing the magic number with pgd_index(__START_KERNEL_map)
improves code readability and future-proofs the code against
possible changes in paging structure.
Signed-off-by: Shengming Hu <shengminghu512@qq.com>
---
arch/x86/kernel/head64.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index fd28b53db..65d4c485a 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -286,7 +286,9 @@ asmlinkage __visible void __init __noreturn x86_64_start_kernel(char * real_mode
load_ucode_bsp();
/* set init_top_pgt kernel high mapping*/
- init_top_pgt[511] = early_top_pgt[511];
+ unsigned int kernel_pgd = pgd_index(__START_KERNEL_map);
+
+ init_top_pgt[kernel_pgd] = early_top_pgt[kernel_pgd];
x86_64_start_reservations(real_mode_data);
}
--
2.34.1