From: mark.rutland@arm.com (Mark Rutland)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCHv2 04/18] arm64: unify idmap removal
Date: Mon, 4 Jan 2016 17:56:37 +0000 [thread overview]
Message-ID: <1451930211-22460-5-git-send-email-mark.rutland@arm.com> (raw)
In-Reply-To: <1451930211-22460-1-git-send-email-mark.rutland@arm.com>
We currently open-code the removal of the idmap and restoration of the
current task's MMU state in a few places.
Before introducing yet more copies of this sequence, unify these to call
a new helper, cpu_uninstall_idmap.
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Jeremy Linton <jeremy.linton@arm.com>
Cc: Laura Abbott <labbott@fedoraproject.org>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
---
arch/arm64/include/asm/mmu_context.h | 25 +++++++++++++++++++++++++
arch/arm64/kernel/setup.c | 1 +
arch/arm64/kernel/smp.c | 4 +---
arch/arm64/kernel/suspend.c | 20 ++++----------------
arch/arm64/mm/mmu.c | 4 +---
5 files changed, 32 insertions(+), 22 deletions(-)
diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h
index 600eacb..b1b2514 100644
--- a/arch/arm64/include/asm/mmu_context.h
+++ b/arch/arm64/include/asm/mmu_context.h
@@ -27,6 +27,7 @@
#include <asm-generic/mm_hooks.h>
#include <asm/cputype.h>
#include <asm/pgtable.h>
+#include <asm/tlbflush.h>
#ifdef CONFIG_PID_IN_CONTEXTIDR
static inline void contextidr_thread_switch(struct task_struct *next)
@@ -90,6 +91,30 @@ static inline void cpu_set_default_tcr_t0sz(void)
}
/*
+ * Remove the idmap from TTBR0_EL1 and install the pgd of the active mm.
+ *
+ * The idmap lives in the same VA range as userspace, but uses global entries
+ * and may use a different TCR_EL1.T0SZ. To avoid issues resulting from
+ * speculative TLB fetches, we must temporarily install the reserved page
+ * tables while we invalidate the TLBs and set up the correct TCR_EL1.T0SZ.
+ *
+ * If current is a not a user task, the mm covers the TTBR1_EL1 page tables,
+ * which should not be installed in TTBR0_EL1. In this case we can leave the
+ * reserved page tables in place.
+ */
+static inline void cpu_uninstall_idmap(void)
+{
+ struct mm_struct *mm = current->active_mm;
+
+ cpu_set_reserved_ttbr0();
+ local_flush_tlb_all();
+ cpu_set_default_tcr_t0sz();
+
+ if (mm != &init_mm)
+ cpu_switch_mm(mm->pgd, mm);
+}
+
+/*
* It would be nice to return ASIDs back to the allocator, but unfortunately
* that introduces a race with a generation rollover where we could erroneously
* free an ASID allocated in a future generation. We could workaround this by
diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c
index 8119479..f6621ba 100644
--- a/arch/arm64/kernel/setup.c
+++ b/arch/arm64/kernel/setup.c
@@ -62,6 +62,7 @@
#include <asm/memblock.h>
#include <asm/efi.h>
#include <asm/xen/hypervisor.h>
+#include <asm/mmu_context.h>
phys_addr_t __fdt_pointer __initdata;
diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c
index b1adc51..68e7f79 100644
--- a/arch/arm64/kernel/smp.c
+++ b/arch/arm64/kernel/smp.c
@@ -149,9 +149,7 @@ asmlinkage void secondary_start_kernel(void)
* TTBR0 is only used for the identity mapping at this stage. Make it
* point to zero page to avoid speculatively fetching new entries.
*/
- cpu_set_reserved_ttbr0();
- local_flush_tlb_all();
- cpu_set_default_tcr_t0sz();
+ cpu_uninstall_idmap();
preempt_disable();
trace_hardirqs_off();
diff --git a/arch/arm64/kernel/suspend.c b/arch/arm64/kernel/suspend.c
index 1095aa4..6605539 100644
--- a/arch/arm64/kernel/suspend.c
+++ b/arch/arm64/kernel/suspend.c
@@ -60,7 +60,6 @@ void __init cpu_suspend_set_dbg_restorer(void (*hw_bp_restore)(void *))
*/
int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
{
- struct mm_struct *mm = current->active_mm;
int ret;
unsigned long flags;
@@ -87,22 +86,11 @@ int cpu_suspend(unsigned long arg, int (*fn)(unsigned long))
ret = __cpu_suspend_enter(arg, fn);
if (ret == 0) {
/*
- * We are resuming from reset with TTBR0_EL1 set to the
- * idmap to enable the MMU; set the TTBR0 to the reserved
- * page tables to prevent speculative TLB allocations, flush
- * the local tlb and set the default tcr_el1.t0sz so that
- * the TTBR0 address space set-up is properly restored.
- * If the current active_mm != &init_mm we entered cpu_suspend
- * with mappings in TTBR0 that must be restored, so we switch
- * them back to complete the address space configuration
- * restoration before returning.
+ * We are resuming from reset with the idmap active in TTBR0_EL1.
+ * We must uninstall the idmap and restore the expected MMU
+ * state before we can possibly return to userspace.
*/
- cpu_set_reserved_ttbr0();
- local_flush_tlb_all();
- cpu_set_default_tcr_t0sz();
-
- if (mm != &init_mm)
- cpu_switch_mm(mm->pgd, mm);
+ cpu_uninstall_idmap();
/*
* Restore per-cpu offset before any kernel
diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c
index cdbf055..e85a719 100644
--- a/arch/arm64/mm/mmu.c
+++ b/arch/arm64/mm/mmu.c
@@ -468,9 +468,7 @@ void __init paging_init(void)
* TTBR0 is only used for the identity mapping at this stage. Make it
* point to zero page to avoid speculatively fetching new entries.
*/
- cpu_set_reserved_ttbr0();
- local_flush_tlb_all();
- cpu_set_default_tcr_t0sz();
+ cpu_uninstall_idmap();
}
/*
--
1.9.1
next prev parent reply other threads:[~2016-01-04 17:56 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-04 17:56 [PATCHv2 00/18] arm64: mm: rework page table creation Mark Rutland
2016-01-04 17:56 ` [PATCHv2 01/18] asm-generic: make __set_fixmap_offset a static inline Mark Rutland
2016-01-19 11:55 ` Mark Rutland
2016-01-19 14:11 ` Arnd Bergmann
2016-01-19 14:18 ` Mark Rutland
2016-01-28 15:10 ` Will Deacon
2016-01-04 17:56 ` [PATCHv2 02/18] arm64: mm: specialise pagetable allocators Mark Rutland
2016-01-04 17:56 ` [PATCHv2 03/18] arm64: mm: place empty_zero_page in bss Mark Rutland
2016-01-04 17:56 ` Mark Rutland [this message]
2016-01-04 17:56 ` [PATCHv2 05/18] arm64: unmap idmap earlier Mark Rutland
2016-01-04 17:56 ` [PATCHv2 06/18] arm64: add function to install the idmap Mark Rutland
2016-01-04 17:56 ` [PATCHv2 07/18] arm64: mm: add code to safely replace TTBR1_EL1 Mark Rutland
2016-01-05 15:22 ` Catalin Marinas
2016-01-05 15:45 ` Mark Rutland
2016-01-04 17:56 ` [PATCHv2 08/18] arm64: kasan: avoid TLB conflicts Mark Rutland
2016-01-04 17:56 ` [PATCHv2 09/18] arm64: mm: move pte_* macros Mark Rutland
2016-01-04 17:56 ` [PATCHv2 10/18] arm64: mm: add functions to walk page tables by PA Mark Rutland
2016-01-04 17:56 ` [PATCHv2 11/18] arm64: mm: avoid redundant __pa(__va(x)) Mark Rutland
2016-01-04 17:56 ` [PATCHv2 12/18] arm64: mm: add __{pud,pgd}_populate Mark Rutland
2016-01-04 17:56 ` [PATCHv2 13/18] arm64: mm: add functions to walk tables in fixmap Mark Rutland
2016-01-04 22:49 ` Laura Abbott
2016-01-05 11:08 ` Mark Rutland
2016-01-04 17:56 ` [PATCHv2 14/18] arm64: mm: use fixmap when creating page tables Mark Rutland
2016-01-04 22:38 ` Laura Abbott
2016-01-05 10:40 ` Mark Rutland
2016-01-04 17:56 ` [PATCHv2 15/18] arm64: mm: allocate pagetables anywhere Mark Rutland
2016-01-04 17:56 ` [PATCHv2 16/18] arm64: mm: allow passing a pgdir to alloc_init_* Mark Rutland
2016-01-04 17:56 ` [PATCHv2 17/18] arm64: ensure _stext and _etext are page-aligned Mark Rutland
2016-01-04 17:56 ` [PATCHv2 18/18] arm64: mm: create new fine-grained mappings at boot Mark Rutland
2016-01-05 1:08 ` [PATCHv2 00/18] arm64: mm: rework page table creation Laura Abbott
2016-01-05 11:54 ` Mark Rutland
2016-01-05 18:36 ` Laura Abbott
2016-01-05 18:58 ` Mark Rutland
2016-01-05 19:17 ` Laura Abbott
2016-01-06 11:10 ` Mark Rutland
2016-01-08 19:15 ` Mark Rutland
2016-01-06 10:24 ` Catalin Marinas
2016-01-06 11:36 ` Mark Rutland
2016-01-06 14:23 ` Ard Biesheuvel
2016-01-18 14:47 ` Ard Biesheuvel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1451930211-22460-5-git-send-email-mark.rutland@arm.com \
--to=mark.rutland@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).