Skip to content

Commit 8d6acfe

Browse files
mrutland-armgregkh
authored andcommitted
arm64: consistently use reserved_pg_dir
[ Upstream commit 833be85 ] Depending on configuration options and specific code paths, we either use the empty_zero_page or the configuration-dependent reserved_ttbr0 as a reserved value for TTBR{0,1}_EL1. To simplify this code, let's always allocate and use the same reserved_pg_dir, replacing reserved_ttbr0. Note that this is allocated (and hence pre-zeroed), and is also marked as read-only in the kernel Image mapping. Keeping this separate from the empty_zero_page potentially helps with robustness as the empty_zero_page is used in a number of cases where a failure to map it read-only could allow it to become corrupted. The (presently unused) swapper_pg_end symbol is also removed, and comments are added wherever we rely on the offsets between the pre-allocated pg_dirs to keep these cases easily identifiable. Signed-off-by: Mark Rutland <mark.rutland@arm.com> Cc: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20201103102229.8542-1-mark.rutland@arm.com Signed-off-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f1f30b3 commit 8d6acfe

9 files changed

Lines changed: 17 additions & 22 deletions

File tree

‎arch/arm64/include/asm/asm-uaccess.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
.macro __uaccess_ttbr0_disable, tmp1
1616
mrs \tmp1, ttbr1_el1 // swapper_pg_dir
1717
bic \tmp1, \tmp1, #TTBR_ASID_MASK
18-
sub \tmp1, \tmp1, #RESERVED_TTBR0_SIZE // reserved_ttbr0 just before swapper_pg_dir
18+
sub \tmp1, \tmp1, #PAGE_SIZE // reserved_pg_dir just before swapper_pg_dir
1919
msr ttbr0_el1, \tmp1 // set reserved TTBR0_EL1
2020
isb
21-
add \tmp1, \tmp1, #RESERVED_TTBR0_SIZE
21+
add \tmp1, \tmp1, #PAGE_SIZE
2222
msr ttbr1_el1, \tmp1 // set reserved ASID
2323
isb
2424
.endm

‎arch/arm64/include/asm/kernel-pgtable.h‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@
8989
#define INIT_DIR_SIZE (PAGE_SIZE * EARLY_PAGES(KIMAGE_VADDR, _end))
9090
#define IDMAP_DIR_SIZE (IDMAP_PGTABLE_LEVELS * PAGE_SIZE)
9191

92-
#ifdef CONFIG_ARM64_SW_TTBR0_PAN
93-
#define RESERVED_TTBR0_SIZE (PAGE_SIZE)
94-
#else
95-
#define RESERVED_TTBR0_SIZE (0)
96-
#endif
97-
9892
/* Initial memory map size */
9993
#if ARM64_SWAPPER_USES_SECTION_MAPS
10094
#define SWAPPER_BLOCK_SHIFT SECTION_SHIFT

‎arch/arm64/include/asm/mmu_context.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ static inline void contextidr_thread_switch(struct task_struct *next)
3636
}
3737

3838
/*
39-
* Set TTBR0 to empty_zero_page. No translations will be possible via TTBR0.
39+
* Set TTBR0 to reserved_pg_dir. No translations will be possible via TTBR0.
4040
*/
4141
static inline void cpu_set_reserved_ttbr0(void)
4242
{
43-
unsigned long ttbr = phys_to_ttbr(__pa_symbol(empty_zero_page));
43+
unsigned long ttbr = phys_to_ttbr(__pa_symbol(reserved_pg_dir));
4444

4545
write_sysreg(ttbr, ttbr0_el1);
4646
isb();
@@ -192,7 +192,7 @@ static inline void update_saved_ttbr0(struct task_struct *tsk,
192192
return;
193193

194194
if (mm == &init_mm)
195-
ttbr = __pa_symbol(empty_zero_page);
195+
ttbr = __pa_symbol(reserved_pg_dir);
196196
else
197197
ttbr = virt_to_phys(mm->pgd) | ASID(mm) << 48;
198198

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
530530
extern pgd_t idmap_pg_dir[PTRS_PER_PGD];
531531
extern pgd_t idmap_pg_end[];
532532
extern pgd_t tramp_pg_dir[PTRS_PER_PGD];
533+
extern pgd_t reserved_pg_dir[PTRS_PER_PGD];
533534

534535
extern void set_swapper_pgd(pgd_t *pgdp, pgd_t pgd);
535536

‎arch/arm64/include/asm/uaccess.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ static inline void __uaccess_ttbr0_disable(void)
113113
local_irq_save(flags);
114114
ttbr = read_sysreg(ttbr1_el1);
115115
ttbr &= ~TTBR_ASID_MASK;
116-
/* reserved_ttbr0 placed before swapper_pg_dir */
117-
write_sysreg(ttbr - RESERVED_TTBR0_SIZE, ttbr0_el1);
116+
/* reserved_pg_dir placed before swapper_pg_dir */
117+
write_sysreg(ttbr - PAGE_SIZE, ttbr0_el1);
118118
isb();
119119
/* Set reserved ASID */
120120
write_sysreg(ttbr, ttbr1_el1);

‎arch/arm64/kernel/entry.S‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,9 +770,10 @@ SYM_CODE_END(ret_to_user)
770770
*/
771771
.pushsection ".entry.tramp.text", "ax"
772772

773+
// Move from tramp_pg_dir to swapper_pg_dir
773774
.macro tramp_map_kernel, tmp
774775
mrs \tmp, ttbr1_el1
775-
add \tmp, \tmp, #(PAGE_SIZE + RESERVED_TTBR0_SIZE)
776+
add \tmp, \tmp, #(2 * PAGE_SIZE)
776777
bic \tmp, \tmp, #USER_ASID_FLAG
777778
msr ttbr1_el1, \tmp
778779
#ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003
@@ -789,9 +790,10 @@ alternative_else_nop_endif
789790
#endif /* CONFIG_QCOM_FALKOR_ERRATUM_1003 */
790791
.endm
791792

793+
// Move from swapper_pg_dir to tramp_pg_dir
792794
.macro tramp_unmap_kernel, tmp
793795
mrs \tmp, ttbr1_el1
794-
sub \tmp, \tmp, #(PAGE_SIZE + RESERVED_TTBR0_SIZE)
796+
sub \tmp, \tmp, #(2 * PAGE_SIZE)
795797
orr \tmp, \tmp, #USER_ASID_FLAG
796798
msr ttbr1_el1, \tmp
797799
/*

‎arch/arm64/kernel/setup.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p)
366366
* faults in case uaccess_enable() is inadvertently called by the init
367367
* thread.
368368
*/
369-
init_task.thread_info.ttbr0 = __pa_symbol(empty_zero_page);
369+
init_task.thread_info.ttbr0 = __pa_symbol(reserved_pg_dir);
370370
#endif
371371

372372
if (boot_args[1] || boot_args[2] || boot_args[3]) {

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,11 @@ SECTIONS
164164
. += PAGE_SIZE;
165165
#endif
166166

167-
#ifdef CONFIG_ARM64_SW_TTBR0_PAN
168-
reserved_ttbr0 = .;
169-
. += RESERVED_TTBR0_SIZE;
170-
#endif
167+
reserved_pg_dir = .;
168+
. += PAGE_SIZE;
169+
171170
swapper_pg_dir = .;
172171
. += PAGE_SIZE;
173-
swapper_pg_end = .;
174172

175173
. = ALIGN(SEGMENT_ALIGN);
176174
__init_begin = .;

‎arch/arm64/mm/proc.S‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ SYM_FUNC_END(cpu_do_resume)
168168
.pushsection ".idmap.text", "awx"
169169

170170
.macro __idmap_cpu_set_reserved_ttbr1, tmp1, tmp2
171-
adrp \tmp1, empty_zero_page
171+
adrp \tmp1, reserved_pg_dir
172172
phys_to_ttbr \tmp2, \tmp1
173173
offset_ttbr1 \tmp2, \tmp1
174174
msr ttbr1_el1, \tmp2

0 commit comments

Comments
 (0)