From: Ard Biesheuvel <ardb@kernel.org>
To: linux-efi@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org, keescook@chromium.org,
mark.rutland@arm.com, catalin.marinas@arm.com,
Ard Biesheuvel <ardb@kernel.org>
Subject: [RFC PATCH v2 04/18] arm64: head: cover entire kernel image in ID map
Date: Wed, 30 Mar 2022 17:41:51 +0200 [thread overview]
Message-ID: <20220330154205.2483167-5-ardb@kernel.org> (raw)
In-Reply-To: <20220330154205.2483167-1-ardb@kernel.org>
As a first step towards avoiding the need to create, tear down and
recreate the kernel virtual mapping with MMU and caches disabled, start
by expanding the ID map so it covers the page tables as well as all
executable code. This will allow us to populate the page tables with the
MMU and caches on, and call KASLR init code before setting up the
virtual mapping.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
arch/arm64/include/asm/kernel-pgtable.h | 2 +-
arch/arm64/kernel/head.S | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h
index 96dc0f7da258..b62200a9456e 100644
--- a/arch/arm64/include/asm/kernel-pgtable.h
+++ b/arch/arm64/include/asm/kernel-pgtable.h
@@ -87,7 +87,7 @@
+ EARLY_PUDS((vstart), (vend)) /* each PUD needs a next level page table */ \
+ EARLY_PMDS((vstart), (vend))) /* each PMD needs a next level page table */
#define INIT_DIR_SIZE (PAGE_SIZE * EARLY_PAGES(KIMAGE_VADDR, _end))
-#define IDMAP_DIR_SIZE (IDMAP_PGTABLE_LEVELS * PAGE_SIZE)
+#define IDMAP_DIR_SIZE INIT_DIR_SIZE
/* Initial memory map size */
#if ARM64_KERNEL_USES_PMD_MAPS
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index 275cd14a70c2..727561972e4a 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -287,7 +287,7 @@ SYM_FUNC_END(clear_page_tables)
SYM_FUNC_START_LOCAL(create_idmap)
adrp x0, idmap_pg_dir
- adrp x3, __idmap_text_start // __pa(__idmap_text_start)
+ adrp x3, _text // __pa(_text)
#ifdef CONFIG_ARM64_VA_BITS_52
mrs_s x6, SYS_ID_AA64MMFR2_EL1
@@ -312,10 +312,10 @@ SYM_FUNC_START_LOCAL(create_idmap)
* Calculate the maximum allowed value for TCR_EL1.T0SZ so that the
* entire ID map region can be mapped. As T0SZ == (64 - #bits used),
* this number conveniently equals the number of leading zeroes in
- * the physical address of __idmap_text_end.
+ * the physical address of _end.
*/
mov x4, PTRS_PER_PGD
- adrp x5, __idmap_text_end
+ adrp x5, _end
clz x5, x5
cmp x5, TCR_T0SZ(VA_BITS_MIN) // default T0SZ small enough?
b.ge 1f // .. then skip VA range extension
@@ -351,7 +351,7 @@ SYM_FUNC_START_LOCAL(create_idmap)
mov x4, #1 << (PHYS_MASK_SHIFT - PGDIR_SHIFT)
#endif
1:
- adr_l x6, __idmap_text_end // __pa(__idmap_text_end)
+ adr_l x6, _end // __pa(_end)
mov x7, SWAPPER_MM_MMUFLAGS
map_memory x0, x1, x3, x6, x7, x3, x4, x10, x11, x12, x13, x14
@@ -884,7 +884,7 @@ SYM_FUNC_START_LOCAL(__primary_switch)
msr sctlr_el1, x20 // disable the MMU
isb
bl clear_page_tables
- bl create_kernel_mapping // recreate kernel mapping
+ bl create_kernel_mapping // Recreate kernel mapping
tlbi vmalle1 // Remove any stale TLB entries
dsb nsh
--
2.30.2
next prev parent reply other threads:[~2022-03-30 15:42 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-30 15:41 [RFC PATCH v2 00/18] arm64: efi: leave MMU and caches on at boot Ard Biesheuvel
2022-03-30 15:41 ` [RFC PATCH v2 01/18] arm64: head: drop idmap_ptrs_per_pgd Ard Biesheuvel
2022-03-30 15:41 ` [RFC PATCH v2 02/18] arm64: head: split off idmap creation code Ard Biesheuvel
2022-03-30 15:41 ` [RFC PATCH v2 03/18] arm64: kernel: drop unnecessary PoC cache clean+invalidate Ard Biesheuvel
2022-03-30 15:41 ` Ard Biesheuvel [this message]
2022-03-30 15:41 ` [RFC PATCH v2 05/18] arm64: head: factor out TTBR1 assignment into a macro Ard Biesheuvel
2022-03-30 15:41 ` [RFC PATCH v2 06/18] arm64: head: populate kernel page tables with MMU and caches on Ard Biesheuvel
2022-03-30 15:41 ` [RFC PATCH v2 07/18] arm64: kaslr: deal with init called with VA randomization enabled Ard Biesheuvel
2022-03-30 15:41 ` [RFC PATCH v2 08/18] arm64: setup: defer R/O remapping of FDT Ard Biesheuvel
2022-03-30 15:41 ` [RFC PATCH v2 09/18] arm64: head: relocate kernel only a single time if KASLR is enabled Ard Biesheuvel
2022-03-30 15:41 ` [RFC PATCH v2 10/18] arm64: head: record the MMU state at primary entry Ard Biesheuvel
2022-03-30 15:41 ` [RFC PATCH v2 11/18] arm64: mm: make vabits_actual a build time constant if possible Ard Biesheuvel
2022-03-30 15:41 ` [RFC PATCH v2 12/18] arm64: head: avoid cache invalidation when entering with the MMU on Ard Biesheuvel
2022-03-30 15:42 ` [RFC PATCH v2 13/18] arm64: head: record CPU boot mode after enabling the MMU Ard Biesheuvel
2022-03-30 15:42 ` [RFC PATCH v2 14/18] arm64: head: clean the ID map page to the PoC Ard Biesheuvel
2022-03-30 15:42 ` [RFC PATCH v2 15/18] arm64: lds: move idmap_pg_dir out of .rodata Ard Biesheuvel
2022-03-30 15:42 ` [RFC PATCH v2 16/18] efi: libstub: pass image handle to handle_kernel_image() Ard Biesheuvel
2022-03-30 15:42 ` [RFC PATCH v2 17/18] efi/arm64: libstub: run image in place if randomized by the loader Ard Biesheuvel
2022-03-30 15:42 ` [RFC PATCH v2 18/18] arm64: efi/libstub: enter with the MMU on if executing in place Ard Biesheuvel
2022-03-31 15:37 ` [RFC PATCH v2 00/18] arm64: efi: leave MMU and caches on at boot Mark Rutland
2022-03-31 16:20 ` Ard Biesheuvel
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=20220330154205.2483167-5-ardb@kernel.org \
--to=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=keescook@chromium.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-efi@vger.kernel.org \
--cc=mark.rutland@arm.com \
/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;
as well as URLs for NNTP newsgroup(s).