All of lore.kernel.org
 help / color / mirror / Atom feed
From: mark.rutland@arm.com (Mark Rutland)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCHv2 08/18] arm64: kasan: avoid TLB conflicts
Date: Mon,  4 Jan 2016 17:56:41 +0000	[thread overview]
Message-ID: <1451930211-22460-9-git-send-email-mark.rutland@arm.com> (raw)
In-Reply-To: <1451930211-22460-1-git-send-email-mark.rutland@arm.com>

The page table modification performed during the KASAN init risks the
allocation of conflicting TLB entries, as it swaps a set of valid global
entries for another without suitable TLB maintenance.

The presence of conflicting TLB entries can result in the delivery of
synchronous TLB conflict aborts, or may result in the use of erroneous
data being returned in response to a TLB lookup. This can affect
explicit data accesses from software as well as translations performed
asynchronously (e.g. as part of page table walks or speculative I-cache
fetches), and can therefore result in a wide variety of problems.

To avoid this, use cpu_replace_ttbr1 to swap the page tables. This
ensures that when the new tables are installed there are no stale
entries from the old tables which may conflict. As all updates are made
to the tables while they are not active, the updates themselves are
safe.

At the same time, add the missing barrier to ensure that the tmp_pg_dir
entries updated via memcpy are visible to the page table walkers at the
point the tmp_pg_dir is installed. All other page table updates made as
part of KASAN initialisation have the requisite barriers due to the use
of the standard page table accessors.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.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: Will Deacon <will.deacon@arm.com>
---
 arch/arm64/mm/kasan_init.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/arch/arm64/mm/kasan_init.c b/arch/arm64/mm/kasan_init.c
index cf038c7..3e3d280 100644
--- a/arch/arm64/mm/kasan_init.c
+++ b/arch/arm64/mm/kasan_init.c
@@ -16,6 +16,7 @@
 #include <linux/memblock.h>
 #include <linux/start_kernel.h>
 
+#include <asm/mmu_context.h>
 #include <asm/page.h>
 #include <asm/pgalloc.h>
 #include <asm/pgtable.h>
@@ -108,15 +109,6 @@ static void __init clear_pgds(unsigned long start,
 		set_pgd(pgd_offset_k(start), __pgd(0));
 }
 
-static void __init cpu_set_ttbr1(unsigned long ttbr1)
-{
-	asm(
-	"	msr	ttbr1_el1, %0\n"
-	"	isb"
-	:
-	: "r" (ttbr1));
-}
-
 void __init kasan_init(void)
 {
 	struct memblock_region *reg;
@@ -129,8 +121,8 @@ void __init kasan_init(void)
 	 * setup will be finished.
 	 */
 	memcpy(tmp_pg_dir, swapper_pg_dir, sizeof(tmp_pg_dir));
-	cpu_set_ttbr1(__pa(tmp_pg_dir));
-	flush_tlb_all();
+	dsb(ishst);
+	cpu_replace_ttbr1(tmp_pg_dir);
 
 	clear_pgds(KASAN_SHADOW_START, KASAN_SHADOW_END);
 
@@ -156,8 +148,7 @@ void __init kasan_init(void)
 	}
 
 	memset(kasan_zero_page, 0, PAGE_SIZE);
-	cpu_set_ttbr1(__pa(swapper_pg_dir));
-	flush_tlb_all();
+	cpu_replace_ttbr1(swapper_pg_dir);
 
 	/* At this point kasan is fully initialized. Enable error messages */
 	init_task.kasan_depth = 0;
-- 
1.9.1

  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 ` [PATCHv2 04/18] arm64: unify idmap removal Mark Rutland
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 ` Mark Rutland [this message]
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-9-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.