Skip to content

Commit 8903826

Browse files
committed
ARM: idmap: populate identity map pgd at init time using .init.text
When disabling and re-enabling the MMU, it is necessary to take out an identity mapping for the code that manipulates the SCTLR in order to avoid it disappearing from under our feet. This is useful when soft rebooting and returning from CPU suspend. This patch allocates a set of page tables during boot and populates them with an identity mapping for the .idmap.text section. This means that users of the identity map do not need to manage their own pgd and can instead annotate their functions with __idmap or, in the case of assembly code, place them in the correct section. Acked-by: Dave Martin <dave.martin@linaro.org> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Tested-by: Lorenzo Pieralisi <Lorenzo.Pieralisi@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent ba8bb18 commit 8903826

5 files changed

Lines changed: 51 additions & 3 deletions

File tree

‎arch/arm/include/asm/idmap.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef __ASM_IDMAP_H
2+
#define __ASM_IDMAP_H
3+
4+
#include <linux/compiler.h>
5+
#include <asm/pgtable.h>
6+
7+
/* Tag a function as requiring to be executed via an identity mapping. */
8+
#define __idmap __section(.idmap.text) noinline notrace
9+
10+
extern pgd_t *idmap_pgd;
11+
12+
void identity_mapping_add(pgd_t *, unsigned long, unsigned long);
13+
void identity_mapping_del(pgd_t *, unsigned long, unsigned long);
14+
15+
void setup_mm_for_reboot(void);
16+
17+
#endif /* __ASM_IDMAP_H */

‎arch/arm/include/asm/pgtable.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,6 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
346346

347347
#define pgtable_cache_init() do { } while (0)
348348

349-
void identity_mapping_add(pgd_t *, unsigned long, unsigned long);
350-
void identity_mapping_del(pgd_t *, unsigned long, unsigned long);
351-
352349
#endif /* !__ASSEMBLY__ */
353350

354351
#endif /* CONFIG_MMU */

‎arch/arm/kernel/smp.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <asm/cpu.h>
3232
#include <asm/cputype.h>
3333
#include <asm/exception.h>
34+
#include <asm/idmap.h>
3435
#include <asm/topology.h>
3536
#include <asm/mmu_context.h>
3637
#include <asm/pgtable.h>

‎arch/arm/kernel/vmlinux.lds.S‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
*(.proc.info.init) \
1414
VMLINUX_SYMBOL(__proc_info_end) = .;
1515

16+
#define IDMAP_TEXT \
17+
ALIGN_FUNCTION(); \
18+
VMLINUX_SYMBOL(__idmap_text_start) = .; \
19+
*(.idmap.text) \
20+
VMLINUX_SYMBOL(__idmap_text_end) = .;
21+
1622
#ifdef CONFIG_HOTPLUG_CPU
1723
#define ARM_CPU_DISCARD(x)
1824
#define ARM_CPU_KEEP(x) x
@@ -92,6 +98,7 @@ SECTIONS
9298
SCHED_TEXT
9399
LOCK_TEXT
94100
KPROBES_TEXT
101+
IDMAP_TEXT
95102
#ifdef CONFIG_MMU
96103
*(.fixup)
97104
#endif

‎arch/arm/mm/idmap.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#include <linux/kernel.h>
22

33
#include <asm/cputype.h>
4+
#include <asm/idmap.h>
45
#include <asm/pgalloc.h>
56
#include <asm/pgtable.h>
7+
#include <asm/sections.h>
8+
9+
pgd_t *idmap_pgd;
610

711
static void idmap_add_pmd(pud_t *pud, unsigned long addr, unsigned long end,
812
unsigned long prot)
@@ -73,6 +77,28 @@ void identity_mapping_del(pgd_t *pgd, unsigned long addr, unsigned long end)
7377
}
7478
#endif
7579

80+
extern char __idmap_text_start[], __idmap_text_end[];
81+
82+
static int __init init_static_idmap(void)
83+
{
84+
phys_addr_t idmap_start, idmap_end;
85+
86+
idmap_pgd = pgd_alloc(&init_mm);
87+
if (!idmap_pgd)
88+
return -ENOMEM;
89+
90+
/* Add an identity mapping for the physical address of the section. */
91+
idmap_start = virt_to_phys((void *)__idmap_text_start);
92+
idmap_end = virt_to_phys((void *)__idmap_text_end);
93+
94+
pr_info("Setting up static identity map for 0x%llx - 0x%llx\n",
95+
(long long)idmap_start, (long long)idmap_end);
96+
identity_mapping_add(idmap_pgd, idmap_start, idmap_end);
97+
98+
return 0;
99+
}
100+
arch_initcall(init_static_idmap);
101+
76102
/*
77103
* In order to soft-boot, we need to insert a 1:1 mapping in place of
78104
* the user-mode pages. This will then ensure that we have predictable

0 commit comments

Comments
 (0)