svn commit: r365296 - in head/sys/arm64: arm64 include
Andrew Turner
andrew at FreeBSD.org
Thu Sep 3 10:11:13 UTC 2020
Author: andrew
Date: Thu Sep 3 10:11:12 2020
New Revision: 365296
URL: https://svnweb.freebsd.org/changeset/base/365296
Log:
Switch to an empty ttbr0 pagetable when the MMU is enabled
We don't need these pagetables after the early boot. Remove the chance we
write to memory we didn't expect to and remove architectural undefined
behaviour.
Reviewed by: alc (earlier version), mmel
Sponsored by: Innovate UK
Differential Revision: https://reviews.freebsd.org/D22606
Modified:
head/sys/arm64/arm64/locore.S
head/sys/arm64/arm64/machdep.c
head/sys/arm64/include/machdep.h
Modified: head/sys/arm64/arm64/locore.S
==============================================================================
--- head/sys/arm64/arm64/locore.S Thu Sep 3 09:09:44 2020 (r365295)
+++ head/sys/arm64/arm64/locore.S Thu Sep 3 10:11:12 2020 (r365296)
@@ -128,6 +128,9 @@ _start:
/* Enable the mmu */
bl start_mmu
+ /* Load the new ttbr0 pagetable */
+ adr x27, pagetable_l0_ttbr0
+
/* Jump to the virtual address space */
ldr x15, .Lvirtdone
br x15
@@ -166,6 +169,7 @@ virtdone:
str x25, [x0, #BP_KERN_STACK]
str x24, [x0, #BP_KERN_L0PT]
str x23, [x0, #BP_BOOT_EL]
+ str x27, [x0, 40] /* kern_ttbr0 */
/* trace back starts here */
mov fp, #0
@@ -204,11 +208,14 @@ ENTRY(mpentry)
/* Load the kernel page table */
adr x24, pagetable_l0_ttbr1
/* Load the identity page table */
- adr x27, pagetable_l0_ttbr0
+ adr x27, pagetable_l0_ttbr0_boostrap
/* Enable the mmu */
bl start_mmu
+ /* Load the new ttbr0 pagetable */
+ adr x27, pagetable_l0_ttbr0
+
/* Jump to the virtual address space */
ldr x15, =mp_virtdone
br x15
@@ -218,6 +225,16 @@ mp_virtdone:
ldr x4, =bootstack
ldr x4, [x4]
mov sp, x4
+
+ /* Load the kernel ttbr0 pagetable */
+ msr ttbr0_el1, x27
+ isb
+
+ /* Invalidate the TLB */
+ tlbi vmalle1
+ dsb sy
+ isb
+
b init_secondary
END(mpentry)
#endif
@@ -760,10 +777,13 @@ abort:
//.section .init_pagetable
.align 12 /* 4KiB aligned */
/*
- * 3 initial tables (in the following order):
+ * 6 initial tables (in the following order):
* L2 for kernel (High addresses)
* L1 for kernel
- * L1 for user (Low addresses)
+ * L0 for kernel
+ * L1 bootstrap for user (Low addresses)
+ * L0 bootstrap for user
+ * L0 for user
*/
pagetable:
.space PAGE_SIZE
@@ -771,7 +791,9 @@ pagetable_l1_ttbr1:
.space PAGE_SIZE
pagetable_l0_ttbr1:
.space PAGE_SIZE
-pagetable_l1_ttbr0:
+pagetable_l1_ttbr0_bootstrap:
+ .space PAGE_SIZE
+pagetable_l0_ttbr0_boostrap:
.space PAGE_SIZE
pagetable_l0_ttbr0:
.space PAGE_SIZE
Modified: head/sys/arm64/arm64/machdep.c
==============================================================================
--- head/sys/arm64/arm64/machdep.c Thu Sep 3 09:09:44 2020 (r365295)
+++ head/sys/arm64/arm64/machdep.c Thu Sep 3 10:11:12 2020 (r365296)
@@ -1235,6 +1235,8 @@ initarm(struct arm64_bootparams *abp)
valid = bus_probe();
cninit();
+ set_ttbr0(abp->kern_ttbr0);
+ cpu_tlb_flushID();
if (!valid)
panic("Invalid bus configuration: %s",
Modified: head/sys/arm64/include/machdep.h
==============================================================================
--- head/sys/arm64/include/machdep.h Thu Sep 3 09:09:44 2020 (r365295)
+++ head/sys/arm64/include/machdep.h Thu Sep 3 10:11:12 2020 (r365296)
@@ -37,6 +37,7 @@ struct arm64_bootparams {
uint64_t kern_delta;
vm_offset_t kern_stack;
vm_offset_t kern_l0pt; /* L1 page table for the kernel */
+ vm_paddr_t kern_ttbr0;
int boot_el; /* EL the kernel booted from */
int pad;
};
More information about the svn-src-all
mailing list