arm64: mm: provide idmap pointer to cpu_replace_ttbr1()
authorArd Biesheuvel <ardb@kernel.org>
Fri, 24 Jun 2022 15:06:40 +0000 (17:06 +0200)
committerWill Deacon <will@kernel.org>
Fri, 24 Jun 2022 16:18:10 +0000 (17:18 +0100)
In preparation for changing the way we initialize the permanent ID map,
update cpu_replace_ttbr1() so we can use it with the initial ID map as
well.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20220624150651.1358849-11-ardb@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/include/asm/mmu_context.h
arch/arm64/kernel/cpufeature.c
arch/arm64/kernel/suspend.c
arch/arm64/mm/kasan_init.c
arch/arm64/mm/mmu.c

index 7b387c3b312ab55162342692e1c8df533721f879..c7ccd82db1d24bb3b8a3dfe7b95ff25bde59dc70 100644 (file)
@@ -105,13 +105,18 @@ static inline void cpu_uninstall_idmap(void)
                cpu_switch_mm(mm->pgd, mm);
 }
 
-static inline void cpu_install_idmap(void)
+static inline void __cpu_install_idmap(pgd_t *idmap)
 {
        cpu_set_reserved_ttbr0();
        local_flush_tlb_all();
        cpu_set_idmap_tcr_t0sz();
 
-       cpu_switch_mm(lm_alias(idmap_pg_dir), &init_mm);
+       cpu_switch_mm(lm_alias(idmap), &init_mm);
+}
+
+static inline void cpu_install_idmap(void)
+{
+       __cpu_install_idmap(idmap_pg_dir);
 }
 
 /*
@@ -142,7 +147,7 @@ static inline void cpu_install_ttbr0(phys_addr_t ttbr0, unsigned long t0sz)
  * Atomically replaces the active TTBR1_EL1 PGD with a new VA-compatible PGD,
  * avoiding the possibility of conflicting TLB entries being allocated.
  */
-static inline void __nocfi cpu_replace_ttbr1(pgd_t *pgdp)
+static inline void __nocfi cpu_replace_ttbr1(pgd_t *pgdp, pgd_t *idmap)
 {
        typedef void (ttbr_replace_func)(phys_addr_t);
        extern ttbr_replace_func idmap_cpu_replace_ttbr1;
@@ -165,7 +170,7 @@ static inline void __nocfi cpu_replace_ttbr1(pgd_t *pgdp)
 
        replace_phys = (void *)__pa_symbol(function_nocfi(idmap_cpu_replace_ttbr1));
 
-       cpu_install_idmap();
+       __cpu_install_idmap(idmap);
        replace_phys(ttbr1);
        cpu_uninstall_idmap();
 }
index 8d88433de81da0a0ecf890f8328433fa4a0c4d9a..a97913d1970991eefe2e1a7912fe997382d7c4db 100644 (file)
@@ -3218,7 +3218,7 @@ subsys_initcall_sync(init_32bit_el0_mask);
 
 static void __maybe_unused cpu_enable_cnp(struct arm64_cpu_capabilities const *cap)
 {
-       cpu_replace_ttbr1(lm_alias(swapper_pg_dir));
+       cpu_replace_ttbr1(lm_alias(swapper_pg_dir), idmap_pg_dir);
 }
 
 /*
index 2b0887e58a7c4df64cf6cedf7968fd305cf99283..9135fe0f3df536f4fe77832f2758ed5815c877b1 100644 (file)
@@ -52,7 +52,7 @@ void notrace __cpu_suspend_exit(void)
 
        /* Restore CnP bit in TTBR1_EL1 */
        if (system_supports_cnp())
-               cpu_replace_ttbr1(lm_alias(swapper_pg_dir));
+               cpu_replace_ttbr1(lm_alias(swapper_pg_dir), idmap_pg_dir);
 
        /*
         * PSTATE was not saved over suspend/resume, re-enable any detected
index c12cd700598f50252ae79fc7c0d2bf2e3d004a62..e969e68de005fd2abf0aee91d51a03fc4e2eeebd 100644 (file)
@@ -236,7 +236,7 @@ static void __init kasan_init_shadow(void)
         */
        memcpy(tmp_pg_dir, swapper_pg_dir, sizeof(tmp_pg_dir));
        dsb(ishst);
-       cpu_replace_ttbr1(lm_alias(tmp_pg_dir));
+       cpu_replace_ttbr1(lm_alias(tmp_pg_dir), idmap_pg_dir);
 
        clear_pgds(KASAN_SHADOW_START, KASAN_SHADOW_END);
 
@@ -280,7 +280,7 @@ static void __init kasan_init_shadow(void)
                                PAGE_KERNEL_RO));
 
        memset(kasan_early_shadow_page, KASAN_SHADOW_INIT, PAGE_SIZE);
-       cpu_replace_ttbr1(lm_alias(swapper_pg_dir));
+       cpu_replace_ttbr1(lm_alias(swapper_pg_dir), idmap_pg_dir);
 }
 
 static void __init kasan_init_depth(void)
index 63732ca0ccf55f0c903cfa30a5a9b82591091890..8cbc87dcaad39c7bb91698fd5da43808d2ab8a40 100644 (file)
@@ -777,7 +777,7 @@ void __init paging_init(void)
 
        pgd_clear_fixmap();
 
-       cpu_replace_ttbr1(lm_alias(swapper_pg_dir));
+       cpu_replace_ttbr1(lm_alias(swapper_pg_dir), idmap_pg_dir);
        init_mm.pgd = swapper_pg_dir;
 
        memblock_phys_free(__pa_symbol(init_pg_dir),