Skip to content

Commit 4e8ee7d

Browse files
committed
ARM: SMP: use idmap_pgd for mapping MMU enable during secondary booting
The ARM SMP booting code allocates a temporary set of page tables containing an identity mapping of the kernel image and provides this to secondary CPUs for initial booting. In reality, we only need to include the __turn_mmu_on function in the identity mapping since the rest of the kernel is executing from virtual addresses after this point. This patch adds __turn_mmu_on to the .idmap.text section, allowing the SMP booting code to use the idmap_pgd directly and not have to populate its own set of page table. As a result of this patch, we can make the identity_mapping_add function static (since it is only used within mm/idmap.c) and also remove the identity_mapping_del function. The identity map population is moved to an early initcall so that it is setup in time for secondary CPU bringup. Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 72662e0 commit 4e8ee7d

4 files changed

Lines changed: 6 additions & 66 deletions

File tree

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
extern pgd_t *idmap_pgd;
1111

12-
void identity_mapping_add(pgd_t *, unsigned long, unsigned long);
13-
void identity_mapping_del(pgd_t *, unsigned long, unsigned long);
14-
1512
void setup_mm_for_reboot(void);
1613

1714
#endif /* __ASM_IDMAP_H */

‎arch/arm/kernel/head.S‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ ENDPROC(__enable_mmu)
398398
* other registers depend on the function called upon completion
399399
*/
400400
.align 5
401-
__turn_mmu_on:
401+
.pushsection .idmap.text, "ax"
402+
ENTRY(__turn_mmu_on)
402403
mov r0, r0
403404
mcr p15, 0, r0, c1, c0, 0 @ write control reg
404405
mrc p15, 0, r3, c0, c0, 0 @ read id reg
@@ -407,6 +408,7 @@ __turn_mmu_on:
407408
mov pc, r3
408409
__turn_mmu_on_end:
409410
ENDPROC(__turn_mmu_on)
411+
.popsection
410412

411413

412414
#ifdef CONFIG_SMP_ON_UP

‎arch/arm/kernel/smp.c‎

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ int __cpuinit __cpu_up(unsigned int cpu)
6262
{
6363
struct cpuinfo_arm *ci = &per_cpu(cpu_data, cpu);
6464
struct task_struct *idle = ci->idle;
65-
pgd_t *pgd;
6665
int ret;
6766

6867
/*
@@ -84,30 +83,12 @@ int __cpuinit __cpu_up(unsigned int cpu)
8483
init_idle(idle, cpu);
8584
}
8685

87-
/*
88-
* Allocate initial page tables to allow the new CPU to
89-
* enable the MMU safely. This essentially means a set
90-
* of our "standard" page tables, with the addition of
91-
* a 1:1 mapping for the physical address of the kernel.
92-
*/
93-
pgd = pgd_alloc(&init_mm);
94-
if (!pgd)
95-
return -ENOMEM;
96-
97-
if (PHYS_OFFSET != PAGE_OFFSET) {
98-
#ifndef CONFIG_HOTPLUG_CPU
99-
identity_mapping_add(pgd, __pa(__init_begin), __pa(__init_end));
100-
#endif
101-
identity_mapping_add(pgd, __pa(_stext), __pa(_etext));
102-
identity_mapping_add(pgd, __pa(_sdata), __pa(_edata));
103-
}
104-
10586
/*
10687
* We need to tell the secondary core where to find
10788
* its stack and the page tables.
10889
*/
10990
secondary_data.stack = task_stack_page(idle) + THREAD_START_SP;
110-
secondary_data.pgdir = virt_to_phys(pgd);
91+
secondary_data.pgdir = virt_to_phys(idmap_pgd);
11192
secondary_data.swapper_pg_dir = virt_to_phys(swapper_pg_dir);
11293
__cpuc_flush_dcache_area(&secondary_data, sizeof(secondary_data));
11394
outer_clean_range(__pa(&secondary_data), __pa(&secondary_data + 1));
@@ -143,16 +124,6 @@ int __cpuinit __cpu_up(unsigned int cpu)
143124
secondary_data.stack = NULL;
144125
secondary_data.pgdir = 0;
145126

146-
if (PHYS_OFFSET != PAGE_OFFSET) {
147-
#ifndef CONFIG_HOTPLUG_CPU
148-
identity_mapping_del(pgd, __pa(__init_begin), __pa(__init_end));
149-
#endif
150-
identity_mapping_del(pgd, __pa(_stext), __pa(_etext));
151-
identity_mapping_del(pgd, __pa(_sdata), __pa(_edata));
152-
}
153-
154-
pgd_free(&init_mm, pgd);
155-
156127
return ret;
157128
}
158129

‎arch/arm/mm/idmap.c‎

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static void idmap_add_pud(pgd_t *pgd, unsigned long addr, unsigned long end,
3232
} while (pud++, addr = next, addr != end);
3333
}
3434

35-
void identity_mapping_add(pgd_t *pgd, unsigned long addr, unsigned long end)
35+
static void identity_mapping_add(pgd_t *pgd, unsigned long addr, unsigned long end)
3636
{
3737
unsigned long prot, next;
3838

@@ -47,36 +47,6 @@ void identity_mapping_add(pgd_t *pgd, unsigned long addr, unsigned long end)
4747
} while (pgd++, addr = next, addr != end);
4848
}
4949

50-
#ifdef CONFIG_SMP
51-
static void idmap_del_pmd(pud_t *pud, unsigned long addr, unsigned long end)
52-
{
53-
pmd_t *pmd = pmd_offset(pud, addr);
54-
pmd_clear(pmd);
55-
}
56-
57-
static void idmap_del_pud(pgd_t *pgd, unsigned long addr, unsigned long end)
58-
{
59-
pud_t *pud = pud_offset(pgd, addr);
60-
unsigned long next;
61-
62-
do {
63-
next = pud_addr_end(addr, end);
64-
idmap_del_pmd(pud, addr, next);
65-
} while (pud++, addr = next, addr != end);
66-
}
67-
68-
void identity_mapping_del(pgd_t *pgd, unsigned long addr, unsigned long end)
69-
{
70-
unsigned long next;
71-
72-
pgd += pgd_index(addr);
73-
do {
74-
next = pgd_addr_end(addr, end);
75-
idmap_del_pud(pgd, addr, next);
76-
} while (pgd++, addr = next, addr != end);
77-
}
78-
#endif
79-
8050
extern char __idmap_text_start[], __idmap_text_end[];
8151

8252
static int __init init_static_idmap(void)
@@ -97,7 +67,7 @@ static int __init init_static_idmap(void)
9767

9868
return 0;
9969
}
100-
arch_initcall(init_static_idmap);
70+
early_initcall(init_static_idmap);
10171

10272
/*
10373
* In order to soft-boot, we need to switch to a 1:1 mapping for the

0 commit comments

Comments
 (0)