From: shengminghu512 <shengminghu512@qq.com>
To: tglx <tglx@linutronix.de>, mingo <mingo@redhat.com>,
bp <bp@alien8.de>, "dave.hansen" <dave.hansen@linux.intel.com>,
x86 <x86@kernel.org>
Cc: hpa <hpa@zytor.com>, broonie <broonie@kernel.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
"zhang.run" <zhang.run@zte.com.cn>,
"hu.shengming" <hu.shengming@zte.com.cn>
Subject: [PATCH v1] x86/boot: Use pgd_index(__START_KERNEL_map) instead of hardcoded 511
Date: Wed, 8 Oct 2025 22:43:00 +0800 [thread overview]
Message-ID: <tencent_AB982BDF5B2FBDD110C0ECB5A5474B9C4D0A@qq.com> (raw)
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
reply other threads:[~2025-10-08 14:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=tencent_AB982BDF5B2FBDD110C0ECB5A5474B9C4D0A@qq.com \
--to=shengminghu512@qq.com \
--cc=bp@alien8.de \
--cc=broonie@kernel.org \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=hu.shengming@zte.com.cn \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=zhang.run@zte.com.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®