[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <b53a0e6996f35e8cc5b216a174ec2b3c58e30860.1682673543.git.houwenlong.hwl@antgroup.com>
Date: Fri, 28 Apr 2023 17:51:20 +0800
From: "Hou Wenlong" <houwenlong.hwl@...group.com>
To: linux-kernel@...r.kernel.org
Cc: "Thomas Garnier" <thgarnie@...omium.org>,
"Lai Jiangshan" <jiangshan.ljs@...group.com>,
"Kees Cook" <keescook@...omium.org>,
"Hou Wenlong" <houwenlong.hwl@...group.com>,
"Thomas Gleixner" <tglx@...utronix.de>,
"Ingo Molnar" <mingo@...hat.com>, "Borislav Petkov" <bp@...en8.de>,
"Dave Hansen" <dave.hansen@...ux.intel.com>, <x86@...nel.org>,
"H. Peter Anvin" <hpa@...or.com>,
"Juergen Gross" <jgross@...e.com>,
"Anshuman Khandual" <anshuman.khandual@....com>,
"Mike Rapoport" <rppt@...nel.org>,
"Josh Poimboeuf" <jpoimboe@...nel.org>,
"Pasha Tatashin" <pasha.tatashin@...een.com>
Subject: [PATCH RFC 40/43] x86/boot: Fill kernel image puds dynamically
For PIE kernel, it could be randomized in any address. Later, kernel
image would be moved down the top 2G, so fille kernel image puds
dynamically.
Signed-off-by: Hou Wenlong <houwenlong.hwl@...group.com>
Cc: Thomas Garnier <thgarnie@...omium.org>a
Cc: Lai Jiangshan <jiangshan.ljs@...group.com>
Cc: Kees Cook <keescook@...omium.org>
---
arch/x86/kernel/head64.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
index 8295b547b64f..c5cd61aab8ae 100644
--- a/arch/x86/kernel/head64.c
+++ b/arch/x86/kernel/head64.c
@@ -239,8 +239,18 @@ unsigned long __head __startup_64(unsigned long physaddr,
}
pud = fixup_pointer(&level3_kernel_pgt, physaddr);
- pud[510] += load_delta;
- pud[511] += load_delta;
+ if (IS_ENABLED(CONFIG_X86_PIE)) {
+ pud[510] = 0;
+ pud[511] = 0;
+
+ i = pud_index(text_base);
+ pgtable_flags = _KERNPG_TABLE_NOENC - __START_KERNEL_map + load_delta;
+ pud[i] = pgtable_flags + SYM_ABS_VAL(level2_kernel_pgt);
+ pud[i + 1] = pgtable_flags + SYM_ABS_VAL(level2_fixmap_pgt);
+ } else {
+ pud[510] += load_delta;
+ pud[511] += load_delta;
+ }
pmd = fixup_pointer(level2_fixmap_pgt, physaddr);
for (i = FIXMAP_PMD_TOP; i > FIXMAP_PMD_TOP - FIXMAP_PMD_NUM; i--)
--
2.31.1
Powered by blists - more mailing lists