linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-arm-kernel@lists.infradead.org
Cc: Ard Biesheuvel <ardb@kernel.org>, Marc Zyngier <maz@kernel.org>,
	Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Kees Cook <keescook@chromium.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Mark Brown <broonie@kernel.org>,
	Anshuman Khandual <anshuman.khandual@arm.com>
Subject: [PATCH v7 31/33] arm64: mmu: Retire SWAPPER_BLOCK_xxx and related constants
Date: Fri, 11 Nov 2022 18:11:59 +0100	[thread overview]
Message-ID: <20221111171201.2088501-32-ardb@kernel.org> (raw)
In-Reply-To: <20221111171201.2088501-1-ardb@kernel.org>

Initially, the kernel mapping as well as the ID map used block mappings
on 4k pagesize configurations, but this hasn't been the case for a long
time.

Currently, only the initial ID map uses the larger granularity, to
simplify the early mapping code, which is implemented in assembler. The
permanent ID map as well as the kernel mapping (which is now created
only once) always map the kernel down to pages.

This means the SWAPPER_BLOCK_xxx and related constants are no longer
named appropriately, so let's rename them to INIT_IDMAP_BLOCK_xxx
instead.

Get rid of a stale comment while at it.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 arch/arm64/include/asm/kernel-pgtable.h | 60 +++++++-------------
 arch/arm64/kernel/head.S                | 36 ++++++------
 arch/arm64/mm/proc.S                    |  2 +-
 3 files changed, 40 insertions(+), 58 deletions(-)

diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/asm/kernel-pgtable.h
index ed0db7fc0022d34e..4278cd088347fefd 100644
--- a/arch/arm64/include/asm/kernel-pgtable.h
+++ b/arch/arm64/include/asm/kernel-pgtable.h
@@ -19,28 +19,13 @@
  * 64K (section size = 512M).
  */
 #ifdef CONFIG_ARM64_4K_PAGES
-#define ARM64_KERNEL_USES_PMD_MAPS 1
+#define INIT_IDMAP_USES_PMD_MAPS	1
+#define INIT_IDMAP_TABLE_LEVELS		(CONFIG_PGTABLE_LEVELS - 1)
 #else
-#define ARM64_KERNEL_USES_PMD_MAPS 0
+#define INIT_IDMAP_USES_PMD_MAPS	0
+#define INIT_IDMAP_TABLE_LEVELS		(CONFIG_PGTABLE_LEVELS)
 #endif
 
-/*
- * The idmap and swapper page tables need some space reserved in the kernel
- * image. Both require pgd, pud (4 levels only) and pmd tables to (section)
- * map the kernel. With the 64K page configuration, swapper and idmap need to
- * map to pte level. The swapper also maps the FDT (see __create_page_tables
- * for more information). Note that the number of ID map translation levels
- * could be increased on the fly if system RAM is out of reach for the default
- * VA range, so pages required to map highest possible PA are reserved in all
- * cases.
- */
-#if ARM64_KERNEL_USES_PMD_MAPS
-#define SWAPPER_PGTABLE_LEVELS	(CONFIG_PGTABLE_LEVELS - 1)
-#else
-#define SWAPPER_PGTABLE_LEVELS	(CONFIG_PGTABLE_LEVELS)
-#endif
-
-
 /*
  * If KASLR is enabled, then an offset K is added to the kernel address
  * space. The bottom 21 bits of this offset are zero to guarantee 2MB
@@ -69,14 +54,14 @@
 
 #define EARLY_PGDS(vstart, vend, add) (EARLY_ENTRIES(vstart, vend, PGDIR_SHIFT, add))
 
-#if SWAPPER_PGTABLE_LEVELS > 3
+#if INIT_IDMAP_TABLE_LEVELS > 3
 #define EARLY_PUDS(vstart, vend, add) (EARLY_ENTRIES(vstart, vend, PUD_SHIFT, add))
 #else
 #define EARLY_PUDS(vstart, vend, add) (0)
 #endif
 
-#if SWAPPER_PGTABLE_LEVELS > 2
-#define EARLY_PMDS(vstart, vend, add) (EARLY_ENTRIES(vstart, vend, SWAPPER_TABLE_SHIFT, add))
+#if INIT_IDMAP_TABLE_LEVELS > 2
+#define EARLY_PMDS(vstart, vend, add) (EARLY_ENTRIES(vstart, vend, INIT_IDMAP_TABLE_SHIFT, add))
 #else
 #define EARLY_PMDS(vstart, vend, add) (0)
 #endif
@@ -93,23 +78,23 @@
 #else
 #define INIT_IDMAP_DIR_SIZE	(INIT_IDMAP_DIR_PAGES * PAGE_SIZE)
 #endif
-#define INIT_IDMAP_DIR_PAGES	EARLY_PAGES(KIMAGE_VADDR, _end + MAX_FDT_SIZE + SWAPPER_BLOCK_SIZE, 1)
+#define INIT_IDMAP_DIR_PAGES	EARLY_PAGES(KIMAGE_VADDR, _end + MAX_FDT_SIZE + INIT_IDMAP_BLOCK_SIZE, 1)
 
 /* Initial memory map size */
-#if ARM64_KERNEL_USES_PMD_MAPS
-#define SWAPPER_BLOCK_SHIFT	PMD_SHIFT
-#define SWAPPER_BLOCK_SIZE	PMD_SIZE
-#define SWAPPER_TABLE_SHIFT	PUD_SHIFT
+#if INIT_IDMAP_USES_PMD_MAPS
+#define INIT_IDMAP_BLOCK_SHIFT	PMD_SHIFT
+#define INIT_IDMAP_BLOCK_SIZE	PMD_SIZE
+#define INIT_IDMAP_TABLE_SHIFT	PUD_SHIFT
 #else
-#define SWAPPER_BLOCK_SHIFT	PAGE_SHIFT
-#define SWAPPER_BLOCK_SIZE	PAGE_SIZE
-#define SWAPPER_TABLE_SHIFT	PMD_SHIFT
+#define INIT_IDMAP_BLOCK_SHIFT	PAGE_SHIFT
+#define INIT_IDMAP_BLOCK_SIZE	PAGE_SIZE
+#define INIT_IDMAP_TABLE_SHIFT	PMD_SHIFT
 #endif
 
 /* The number of segments in the kernel image (text, rodata, inittext, initdata, data+bss) */
 #define KERNEL_SEGMENT_COUNT	5
 
-#if SWAPPER_BLOCK_SIZE > SEGMENT_ALIGN
+#if INIT_IDMAP_BLOCK_SIZE > SEGMENT_ALIGN
 #define EARLY_SEGMENT_EXTRA_PAGES (KERNEL_SEGMENT_COUNT + 1)
 #else
 #define EARLY_SEGMENT_EXTRA_PAGES 0
@@ -118,15 +103,12 @@
 /*
  * Initial memory map attributes.
  */
-#define SWAPPER_PTE_FLAGS	(PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)
-#define SWAPPER_PMD_FLAGS	(PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S)
-
-#if ARM64_KERNEL_USES_PMD_MAPS
-#define SWAPPER_RW_MMUFLAGS	(PMD_ATTRINDX(MT_NORMAL) | SWAPPER_PMD_FLAGS)
-#define SWAPPER_RX_MMUFLAGS	(SWAPPER_RW_MMUFLAGS | PMD_SECT_RDONLY)
+#if INIT_IDMAP_USES_PMD_MAPS
+#define INIT_IDMAP_RW_MMUFLAGS	(PMD_ATTRINDX(MT_NORMAL) | PMD_TYPE_SECT | PMD_SECT_AF | PMD_SECT_S)
+#define INIT_IDMAP_RX_MMUFLAGS	(INIT_IDMAP_RW_MMUFLAGS | PMD_SECT_RDONLY)
 #else
-#define SWAPPER_RW_MMUFLAGS	(PTE_ATTRINDX(MT_NORMAL) | SWAPPER_PTE_FLAGS)
-#define SWAPPER_RX_MMUFLAGS	(SWAPPER_RW_MMUFLAGS | PTE_RDONLY)
+#define INIT_IDMAP_RW_MMUFLAGS	(PTE_ATTRINDX(MT_NORMAL) | PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)
+#define INIT_IDMAP_RX_MMUFLAGS	(INIT_IDMAP_RW_MMUFLAGS | PTE_RDONLY)
 #endif
 
 /*
diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S
index 6e730a0be1e8196d..3bc96ef82f0f74e4 100644
--- a/arch/arm64/kernel/head.S
+++ b/arch/arm64/kernel/head.S
@@ -214,23 +214,23 @@ SYM_CODE_END(preserve_boot_args)
 	populate_entries \tbl, \rtbl, \istart, \iend, #PMD_TYPE_TABLE, #PAGE_SIZE, \tmp
 	mov \tbl, \sv
 
-#if SWAPPER_PGTABLE_LEVELS > 3
+#if INIT_IDMAP_TABLE_LEVELS > 3
 	compute_indices \vstart, \vend, #PUD_SHIFT, #(PAGE_SHIFT - 3), \istart, \iend, \count
 	mov \sv, \rtbl
 	populate_entries \tbl, \rtbl, \istart, \iend, #PMD_TYPE_TABLE, #PAGE_SIZE, \tmp
 	mov \tbl, \sv
 #endif
 
-#if SWAPPER_PGTABLE_LEVELS > 2
-	compute_indices \vstart, \vend, #SWAPPER_TABLE_SHIFT, #(PAGE_SHIFT - 3), \istart, \iend, \count
+#if INIT_IDMAP_TABLE_LEVELS > 2
+	compute_indices \vstart, \vend, #INIT_IDMAP_TABLE_SHIFT, #(PAGE_SHIFT - 3), \istart, \iend, \count
 	mov \sv, \rtbl
 	populate_entries \tbl, \rtbl, \istart, \iend, #PMD_TYPE_TABLE, #PAGE_SIZE, \tmp
 	mov \tbl, \sv
 #endif
 
-	compute_indices \vstart, \vend, #SWAPPER_BLOCK_SHIFT, #(PAGE_SHIFT - 3), \istart, \iend, \count
-	bic \rtbl, \phys, #SWAPPER_BLOCK_SIZE - 1
-	populate_entries \tbl, \rtbl, \istart, \iend, \flags, #SWAPPER_BLOCK_SIZE, \tmp
+	compute_indices \vstart, \vend, #INIT_IDMAP_BLOCK_SHIFT, #(PAGE_SHIFT - 3), \istart, \iend, \count
+	bic \rtbl, \phys, #INIT_IDMAP_BLOCK_SIZE - 1
+	populate_entries \tbl, \rtbl, \istart, \iend, \flags, #INIT_IDMAP_BLOCK_SIZE, \tmp
 	.endm
 
 /*
@@ -317,8 +317,8 @@ SYM_FUNC_START_LOCAL(create_idmap)
 #endif
 	adrp	x0, init_idmap_pg_dir
 	adrp	x3, _text
-	adrp	x6, _end + MAX_FDT_SIZE + SWAPPER_BLOCK_SIZE
-	mov	x7, SWAPPER_RX_MMUFLAGS
+	adrp	x6, _end + MAX_FDT_SIZE + INIT_IDMAP_BLOCK_SIZE
+	mov	x7, INIT_IDMAP_RX_MMUFLAGS
 
 	map_memory x0, x1, x3, x6, x7, x3, IDMAP_PGD_ORDER, x10, x11, x12, x13, x14, EXTRA_SHIFT
 
@@ -326,20 +326,20 @@ SYM_FUNC_START_LOCAL(create_idmap)
 	adrp	x1, _text
 	adrp	x2, __bss_start
 	adrp	x3, _end
-	bic	x4, x2, #SWAPPER_BLOCK_SIZE - 1
-	mov	x5, SWAPPER_RW_MMUFLAGS
-	mov	x6, #SWAPPER_BLOCK_SHIFT
+	bic	x4, x2, #INIT_IDMAP_BLOCK_SIZE - 1
+	mov	x5, INIT_IDMAP_RW_MMUFLAGS
+	mov	x6, #INIT_IDMAP_BLOCK_SHIFT
 	bl	remap_region
 
 	/* Remap the FDT after the kernel image */
 	adrp	x1, _text
-	adrp	x22, _end + SWAPPER_BLOCK_SIZE
-	bic	x2, x22, #SWAPPER_BLOCK_SIZE - 1
-	bfi	x22, x21, #0, #SWAPPER_BLOCK_SHIFT		// remapped FDT address
-	add	x3, x2, #MAX_FDT_SIZE + SWAPPER_BLOCK_SIZE
-	bic	x4, x21, #SWAPPER_BLOCK_SIZE - 1
-	mov	x5, SWAPPER_RW_MMUFLAGS
-	mov	x6, #SWAPPER_BLOCK_SHIFT
+	adrp	x22, _end + INIT_IDMAP_BLOCK_SIZE
+	bic	x2, x22, #INIT_IDMAP_BLOCK_SIZE - 1
+	bfi	x22, x21, #0, #INIT_IDMAP_BLOCK_SHIFT		// remapped FDT address
+	add	x3, x2, #MAX_FDT_SIZE + INIT_IDMAP_BLOCK_SIZE
+	bic	x4, x21, #INIT_IDMAP_BLOCK_SIZE - 1
+	mov	x5, INIT_IDMAP_RW_MMUFLAGS
+	mov	x6, #INIT_IDMAP_BLOCK_SHIFT
 	bl	remap_region
 
 	/*
diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S
index f0db2c05e797aeed..b596a39394ba5363 100644
--- a/arch/arm64/mm/proc.S
+++ b/arch/arm64/mm/proc.S
@@ -206,7 +206,7 @@ SYM_FUNC_ALIAS(__pi_idmap_cpu_replace_ttbr1, idmap_cpu_replace_ttbr1)
 
 #ifdef CONFIG_UNMAP_KERNEL_AT_EL0
 
-#define KPTI_NG_PTE_FLAGS	(PTE_ATTRINDX(MT_NORMAL) | SWAPPER_PTE_FLAGS)
+#define KPTI_NG_PTE_FLAGS  (PTE_ATTRINDX(MT_NORMAL) | PTE_TYPE_PAGE | PTE_AF | PTE_SHARED)
 
 	.pushsection ".idmap.text", "awx"
 
-- 
2.35.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2022-11-11 17:36 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-11 17:11 [PATCH v7 00/33] arm64: robustify boot sequence and add support for WXN Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 01/33] arm64: mm: Avoid SWAPPER_BLOCK_xxx constants in FDT fixmap logic Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 02/33] arm64: mm: Avoid swapper block size when choosing vmemmap granularity Ard Biesheuvel
2022-11-24  5:11   ` Anshuman Khandual
2022-11-11 17:11 ` [PATCH v7 03/33] arm64: kaslr: don't pretend KASLR is enabled if offset < MIN_KIMG_ALIGN Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 04/33] arm64: kaslr: drop special case for ThunderX in kaslr_requires_kpti() Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 05/33] arm64: kernel: Disable latent_entropy GCC plugin in early C runtime Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 06/33] arm64: kernel: Add relocation check to code built under pi/ Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 07/33] arm64: kernel: Don't rely on objcopy to make code under pi/ __init Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 08/33] arm64: head: move relocation handling to C code Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 09/33] arm64: Turn kaslr_feature_override into a generic SW feature override Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 10/33] arm64: idreg-override: Omit non-NULL checks for override pointer Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 11/33] arm64: idreg-override: Use relative references to override variables Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 12/33] arm64: idreg-override: Use relative references to filter routines Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 13/33] arm64: idreg-override: Avoid parameq() and parameqn() Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 14/33] arm64: idreg-override: avoid strlen() to check for empty strings Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 15/33] arm64: idreg-override: Avoid sprintf() for simple string concatenation Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 16/33] arm64: idreg_override: Avoid kstrtou64() to parse a single hex digit Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 17/33] arm64: idreg-override: Move to early mini C runtime Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 18/33] arm64: kernel: Remove early fdt remap code Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 19/33] arm64: head: Clear BSS and the kernel page tables in one go Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 20/33] arm64: Move feature overrides into the BSS section Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 21/33] arm64: head: Run feature override detection before mapping the kernel Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 22/33] arm64: head: move dynamic shadow call stack patching into early C runtime Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 23/33] arm64: kaslr: Use feature override instead of parsing the cmdline again Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 24/33] arm64: idreg-override: Create a pseudo feature for rodata=off Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 25/33] arm64: head: allocate more pages for the kernel mapping Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 26/33] arm64: head: move memstart_offset_seed handling to C code Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 27/33] arm64: head: Move early kernel mapping routines into " Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 28/33] arm64: mm: avoid fixmap for early swapper_pg_dir updates Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 29/33] arm64: mm: omit redundant remap of kernel image Ard Biesheuvel
2022-11-11 17:11 ` [PATCH v7 30/33] arm64: Revert "mm: provide idmap pointer to cpu_replace_ttbr1()" Ard Biesheuvel
2022-11-11 17:11 ` Ard Biesheuvel [this message]
2022-11-11 17:12 ` [PATCH v7 32/33] mm: add arch hook to validate mmap() prot flags Ard Biesheuvel
2022-11-11 17:12 ` [PATCH v7 33/33] arm64: mm: add support for WXN memory translation attribute 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=20221111171201.2088501-32-ardb@kernel.org \
    --to=ardb@kernel.org \
    --cc=anshuman.khandual@arm.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=keescook@chromium.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=will@kernel.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).