Skip to content

Commit 3ee0fc5

Browse files
author
Russell King
committed
Merge branch 'kexec/idmap' of git://git.kernel.org/pub/scm/linux/kernel/git/will/linux into devel-stable
2 parents deee6d5 + 4e8ee7d commit 3ee0fc5

32 files changed

Lines changed: 140 additions & 89 deletions

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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 setup_mm_for_reboot(void);
13+
14+
#endif /* __ASM_IDMAP_H */

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

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

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

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

355352
#endif /* CONFIG_MMU */

‎arch/arm/kernel/head.S‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ __create_page_tables:
170170
* Create identity mapping to cater for __enable_mmu.
171171
* This identity mapping will be removed by paging_init().
172172
*/
173-
adr r0, __enable_mmu_loc
173+
adr r0, __turn_mmu_on_loc
174174
ldmia r0, {r3, r5, r6}
175175
sub r0, r0, r3 @ virt->phys offset
176-
add r5, r5, r0 @ phys __enable_mmu
177-
add r6, r6, r0 @ phys __enable_mmu_end
176+
add r5, r5, r0 @ phys __turn_mmu_on
177+
add r6, r6, r0 @ phys __turn_mmu_on_end
178178
mov r5, r5, lsr #SECTION_SHIFT
179179
mov r6, r6, lsr #SECTION_SHIFT
180180

@@ -287,10 +287,10 @@ __create_page_tables:
287287
ENDPROC(__create_page_tables)
288288
.ltorg
289289
.align
290-
__enable_mmu_loc:
290+
__turn_mmu_on_loc:
291291
.long .
292-
.long __enable_mmu
293-
.long __enable_mmu_end
292+
.long __turn_mmu_on
293+
.long __turn_mmu_on_end
294294

295295
#if defined(CONFIG_SMP)
296296
__CPUINIT
@@ -398,15 +398,17 @@ 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
405406
mov r3, r3
406407
mov r3, r13
407408
mov pc, r3
408-
__enable_mmu_end:
409+
__turn_mmu_on_end:
409410
ENDPROC(__turn_mmu_on)
411+
.popsection
410412

411413

412414
#ifdef CONFIG_SMP_ON_UP

‎arch/arm/kernel/sleep.S‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ ENDPROC(cpu_suspend_abort)
5454
* r0 = control register value
5555
*/
5656
.align 5
57+
.pushsection .idmap.text,"ax"
5758
ENTRY(cpu_resume_mmu)
5859
ldr r3, =cpu_resume_after_mmu
5960
mcr p15, 0, r0, c1, c0, 0 @ turn on MMU, I-cache, etc
@@ -62,6 +63,7 @@ ENTRY(cpu_resume_mmu)
6263
mov r0, r0
6364
mov pc, r3 @ jump to virtual address
6465
ENDPROC(cpu_resume_mmu)
66+
.popsection
6567
cpu_resume_after_mmu:
6668
bl cpu_init @ restore the und/abt/irq banked regs
6769
mov r0, #0 @ return zero on success

‎arch/arm/kernel/smp.c‎

Lines changed: 2 additions & 30 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>
@@ -61,7 +62,6 @@ int __cpuinit __cpu_up(unsigned int cpu)
6162
{
6263
struct cpuinfo_arm *ci = &per_cpu(cpu_data, cpu);
6364
struct task_struct *idle = ci->idle;
64-
pgd_t *pgd;
6565
int ret;
6666

6767
/*
@@ -83,30 +83,12 @@ int __cpuinit __cpu_up(unsigned int cpu)
8383
init_idle(idle, cpu);
8484
}
8585

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

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

‎arch/arm/kernel/suspend.c‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#include <linux/init.h>
22

3+
#include <asm/idmap.h>
34
#include <asm/pgalloc.h>
45
#include <asm/pgtable.h>
56
#include <asm/memory.h>
67
#include <asm/suspend.h>
78
#include <asm/tlbflush.h>
89

9-
static pgd_t *suspend_pgd;
10-
1110
extern int __cpu_suspend(unsigned long, int (*)(unsigned long));
1211
extern void cpu_resume_mmu(void);
1312

@@ -21,7 +20,7 @@ void __cpu_suspend_save(u32 *ptr, u32 ptrsz, u32 sp, u32 *save_ptr)
2120
*save_ptr = virt_to_phys(ptr);
2221

2322
/* This must correspond to the LDM in cpu_resume() assembly */
24-
*ptr++ = virt_to_phys(suspend_pgd);
23+
*ptr++ = virt_to_phys(idmap_pgd);
2524
*ptr++ = sp;
2625
*ptr++ = virt_to_phys(cpu_do_resume);
2726

@@ -42,7 +41,7 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
4241
struct mm_struct *mm = current->active_mm;
4342
int ret;
4443

45-
if (!suspend_pgd)
44+
if (!idmap_pgd)
4645
return -EINVAL;
4746

4847
/*
@@ -59,14 +58,3 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
5958

6059
return ret;
6160
}
62-
63-
static int __init cpu_suspend_init(void)
64-
{
65-
suspend_pgd = pgd_alloc(&init_mm);
66-
if (suspend_pgd) {
67-
unsigned long addr = virt_to_phys(cpu_resume_mmu);
68-
identity_mapping_add(suspend_pgd, addr, addr + SECTION_SIZE);
69-
}
70-
return suspend_pgd ? 0 : -ENOMEM;
71-
}
72-
core_initcall(cpu_suspend_init);

‎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: 30 additions & 33 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)
@@ -28,7 +32,7 @@ static void idmap_add_pud(pgd_t *pgd, unsigned long addr, unsigned long end,
2832
} while (pud++, addr = next, addr != end);
2933
}
3034

31-
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)
3236
{
3337
unsigned long prot, next;
3438

@@ -43,48 +47,41 @@ void identity_mapping_add(pgd_t *pgd, unsigned long addr, unsigned long end)
4347
} while (pgd++, addr = next, addr != end);
4448
}
4549

46-
#ifdef CONFIG_SMP
47-
static void idmap_del_pmd(pud_t *pud, unsigned long addr, unsigned long end)
48-
{
49-
pmd_t *pmd = pmd_offset(pud, addr);
50-
pmd_clear(pmd);
51-
}
50+
extern char __idmap_text_start[], __idmap_text_end[];
5251

53-
static void idmap_del_pud(pgd_t *pgd, unsigned long addr, unsigned long end)
52+
static int __init init_static_idmap(void)
5453
{
55-
pud_t *pud = pud_offset(pgd, addr);
56-
unsigned long next;
54+
phys_addr_t idmap_start, idmap_end;
5755

58-
do {
59-
next = pud_addr_end(addr, end);
60-
idmap_del_pmd(pud, addr, next);
61-
} while (pud++, addr = next, addr != end);
62-
}
56+
idmap_pgd = pgd_alloc(&init_mm);
57+
if (!idmap_pgd)
58+
return -ENOMEM;
6359

64-
void identity_mapping_del(pgd_t *pgd, unsigned long addr, unsigned long end)
65-
{
66-
unsigned long next;
60+
/* Add an identity mapping for the physical address of the section. */
61+
idmap_start = virt_to_phys((void *)__idmap_text_start);
62+
idmap_end = virt_to_phys((void *)__idmap_text_end);
6763

68-
pgd += pgd_index(addr);
69-
do {
70-
next = pgd_addr_end(addr, end);
71-
idmap_del_pud(pgd, addr, next);
72-
} while (pgd++, addr = next, addr != end);
64+
pr_info("Setting up static identity map for 0x%llx - 0x%llx\n",
65+
(long long)idmap_start, (long long)idmap_end);
66+
identity_mapping_add(idmap_pgd, idmap_start, idmap_end);
67+
68+
return 0;
7369
}
74-
#endif
70+
early_initcall(init_static_idmap);
7571

7672
/*
77-
* In order to soft-boot, we need to insert a 1:1 mapping in place of
78-
* the user-mode pages. This will then ensure that we have predictable
79-
* results when turning the mmu off
73+
* In order to soft-boot, we need to switch to a 1:1 mapping for the
74+
* cpu_reset functions. This will then ensure that we have predictable
75+
* results when turning off the mmu.
8076
*/
8177
void setup_mm_for_reboot(void)
8278
{
83-
/*
84-
* We need to access to user-mode page tables here. For kernel threads
85-
* we don't have any user-mode mappings so we use the context that we
86-
* "borrowed".
87-
*/
88-
identity_mapping_add(current->active_mm->pgd, 0, TASK_SIZE);
79+
/* Clean and invalidate L1. */
80+
flush_cache_all();
81+
82+
/* Switch to the identity mapping. */
83+
cpu_switch_mm(idmap_pgd, &init_mm);
84+
85+
/* Flush the TLB. */
8986
local_flush_tlb_all();
9087
}

‎arch/arm/mm/proc-arm1020.S‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ ENTRY(cpu_arm1020_proc_fin)
9595
* loc: location to jump to for soft reset
9696
*/
9797
.align 5
98+
.pushsection .idmap.text, "ax"
9899
ENTRY(cpu_arm1020_reset)
99100
mov ip, #0
100101
mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
@@ -107,6 +108,8 @@ ENTRY(cpu_arm1020_reset)
107108
bic ip, ip, #0x1100 @ ...i...s........
108109
mcr p15, 0, ip, c1, c0, 0 @ ctrl register
109110
mov pc, r0
111+
ENDPROC(cpu_arm1020_reset)
112+
.popsection
110113

111114
/*
112115
* cpu_arm1020_do_idle()

‎arch/arm/mm/proc-arm1020e.S‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ ENTRY(cpu_arm1020e_proc_fin)
9595
* loc: location to jump to for soft reset
9696
*/
9797
.align 5
98+
.pushsection .idmap.text, "ax"
9899
ENTRY(cpu_arm1020e_reset)
99100
mov ip, #0
100101
mcr p15, 0, ip, c7, c7, 0 @ invalidate I,D caches
@@ -107,6 +108,8 @@ ENTRY(cpu_arm1020e_reset)
107108
bic ip, ip, #0x1100 @ ...i...s........
108109
mcr p15, 0, ip, c1, c0, 0 @ ctrl register
109110
mov pc, r0
111+
ENDPROC(cpu_arm1020e_reset)
112+
.popsection
110113

111114
/*
112115
* cpu_arm1020e_do_idle()

0 commit comments

Comments
 (0)