From: Eric Curtin <ericcurtin17@gmail.com>
To: linux-arm-kernel@lists.infradead.org
Cc: Eric Curtin <eric.curtin@docker.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Marc Zyngier <maz@kernel.org>, Oliver Upton <oupton@kernel.org>,
Fuad Tabba <fuad.tabba@linux.dev>,
Joey Gouly <joey.gouly@arm.com>,
Steffen Eiden <seiden@linux.ibm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Zenghui Yu <yuzenghui@huawei.com>,
kvmarm@lists.linux.dev
Subject: [RFC PATCH v2 36/43] arm64: Convert remaining page-size switches to if/else
Date: Tue, 1 Dec 2026 01:52:08 +0000 [thread overview]
Message-ID: <20261201015240.1017259-37-ericcurtin17@gmail.com> (raw)
In-Reply-To: <20261201015240.1017259-1-ericcurtin17@gmail.com>
From: Eric Curtin <eric.curtin@docker.com>
With boot-time page size selection PMD_SIZE, PUD_SIZE, PAGE_SIZE and the
CONT_*_SIZE values are not constants, so they cannot be case labels in a
switch statement, and PAGE_SHIFT cannot be used in a preprocessor
conditional.
Convert the remaining switches on those sizes to if/else chains in
__flush_hugetlb_tlb_range(), __set_ptes_anysz(),
__ptep_get_and_clear_anysz() and __ptep_set_access_flags_anysz(). In the
nVHE hypervisor, replace the "#if PAGE_SHIFT < 16" selection of the
fixblock slot with a HAS_FIXBLOCK C expression, so that
create_fixblock() and hyp_fixblock_map()/unmap() choose at run time
between the fixblock and the fixmap. Align __bss_pgtbl to PAGE_SIZE_MAX
so that statically allocated page tables are aligned for any selectable
page size.
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
(cherry picked from commit e39ee24baa88970efb2d8cc4f088715f28a6001f)
---
arch/arm64/include/asm/hugetlb.h | 15 ++++++---------
arch/arm64/include/asm/linkage.h | 2 +-
arch/arm64/include/asm/pgtable.h | 24 ++++++++----------------
arch/arm64/kvm/hyp/nvhe/mm.c | 30 ++++++++++++++----------------
arch/arm64/mm/fault.c | 12 ++++--------
5 files changed, 33 insertions(+), 50 deletions(-)
diff --git a/arch/arm64/include/asm/hugetlb.h b/arch/arm64/include/asm/hugetlb.h
index d038ff14d16c..b8487e8c9cf8 100644
--- a/arch/arm64/include/asm/hugetlb.h
+++ b/arch/arm64/include/asm/hugetlb.h
@@ -73,20 +73,17 @@ static inline void __flush_hugetlb_tlb_range(struct vm_area_struct *vma,
unsigned long stride,
tlbf_t flags)
{
- switch (stride) {
#ifndef __PAGETABLE_PMD_FOLDED
- case PUD_SIZE:
+ if (stride == PUD_SIZE) {
__flush_tlb_range(vma, start, end, PUD_SIZE, 1, flags);
- break;
+ return;
+ }
#endif
- case CONT_PMD_SIZE:
- case PMD_SIZE:
+ if (stride == CONT_PMD_SIZE || stride == PMD_SIZE) {
__flush_tlb_range(vma, start, end, PMD_SIZE, 2, flags);
- break;
- case CONT_PTE_SIZE:
+ } else if (stride == CONT_PTE_SIZE) {
__flush_tlb_range(vma, start, end, PAGE_SIZE, 3, flags);
- break;
- default:
+ } else {
__flush_tlb_range(vma, start, end, PAGE_SIZE, TLBI_TTL_UNKNOWN, flags);
}
}
diff --git a/arch/arm64/include/asm/linkage.h b/arch/arm64/include/asm/linkage.h
index d1f7a16729d2..2eb3c0f933e3 100644
--- a/arch/arm64/include/asm/linkage.h
+++ b/arch/arm64/include/asm/linkage.h
@@ -45,6 +45,6 @@
#define _THIS_IP_ ({ unsigned long __ip; asm volatile("adr %0, ." : "=r" (__ip)); __ip; })
-#define __bss_pgtbl __section(".bss..pgtbl") __aligned(PAGE_SIZE)
+#define __bss_pgtbl __section(".bss..pgtbl") __aligned(PAGE_SIZE_MAX)
#endif
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index c625fe7f8452..7cdff90a3b7e 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -635,21 +635,17 @@ static inline void __set_ptes_anysz(struct mm_struct *mm, unsigned long addr,
{
unsigned long stride = pgsize >> PAGE_SHIFT;
- switch (pgsize) {
- case PAGE_SIZE:
+ if (pgsize == PAGE_SIZE) {
page_table_check_ptes_set(mm, addr, ptep, pte, nr);
- break;
- case PMD_SIZE:
+ } else if (pgsize == PMD_SIZE) {
page_table_check_pmds_set(mm, addr, (pmd_t *)ptep,
pte_pmd(pte), nr);
- break;
#ifndef __PAGETABLE_PMD_FOLDED
- case PUD_SIZE:
+ } else if (pgsize == PUD_SIZE) {
page_table_check_puds_set(mm, addr, (pud_t *)ptep,
pte_pud(pte), nr);
- break;
#endif
- default:
+ } else {
VM_WARN_ON(1);
}
@@ -1360,19 +1356,15 @@ static inline pte_t __ptep_get_and_clear_anysz(struct mm_struct *mm,
{
pte_t pte = __pte(xchg_relaxed(&pte_val(*ptep), 0));
- switch (pgsize) {
- case PAGE_SIZE:
+ if (pgsize == PAGE_SIZE) {
page_table_check_pte_clear(mm, address, pte);
- break;
- case PMD_SIZE:
+ } else if (pgsize == PMD_SIZE) {
page_table_check_pmd_clear(mm, address, pte_pmd(pte));
- break;
#ifndef __PAGETABLE_PMD_FOLDED
- case PUD_SIZE:
+ } else if (pgsize == PUD_SIZE) {
page_table_check_pud_clear(mm, address, pte_pud(pte));
- break;
#endif
- default:
+ } else {
VM_WARN_ON(1);
}
diff --git a/arch/arm64/kvm/hyp/nvhe/mm.c b/arch/arm64/kvm/hyp/nvhe/mm.c
index 83b74c5223c3..ede688d8a5f1 100644
--- a/arch/arm64/kvm/hyp/nvhe/mm.c
+++ b/arch/arm64/kvm/hyp/nvhe/mm.c
@@ -391,15 +391,12 @@ static int create_fixmap_slot(u64 addr, u64 cpu)
return kvm_pgtable_walk(&pkvm_pgtable, addr, PAGE_SIZE, &walker);
}
-#if PAGE_SHIFT < 16
-#define HAS_FIXBLOCK
+#define HAS_FIXBLOCK (PAGE_SHIFT < 16)
static struct hyp_fixmap_slot hyp_fixblock_slot;
static DEFINE_HYP_SPINLOCK(hyp_fixblock_lock);
-#endif
static int create_fixblock(void)
{
-#ifdef HAS_FIXBLOCK
struct kvm_pgtable_walker walker = {
.cb = __create_fixmap_slot_cb,
.flags = KVM_PGTABLE_WALK_LEAF,
@@ -409,6 +406,9 @@ static int create_fixblock(void)
phys_addr_t phys;
int ret, i;
+ if (!HAS_FIXBLOCK)
+ return 0;
+
/* Find a RAM phys address, PMD aligned */
for (i = 0; i < hyp_memblock_nr; i++) {
phys = ALIGN(hyp_memory[i].base, PMD_SIZE);
@@ -435,31 +435,29 @@ static int create_fixblock(void)
hyp_spin_unlock(&pkvm_pgd_lock);
return ret;
-#else
- return 0;
-#endif
}
void *hyp_fixblock_map(phys_addr_t phys, size_t *size)
{
-#ifdef HAS_FIXBLOCK
+ if (!HAS_FIXBLOCK) {
+ *size = PAGE_SIZE;
+ return hyp_fixmap_map(phys);
+ }
+
*size = PMD_SIZE;
hyp_spin_lock(&hyp_fixblock_lock);
return fixmap_map_slot(&hyp_fixblock_slot, phys) + offset_in_page(phys);
-#else
- *size = PAGE_SIZE;
- return hyp_fixmap_map(phys);
-#endif
}
void hyp_fixblock_unmap(void)
{
-#ifdef HAS_FIXBLOCK
+ if (!HAS_FIXBLOCK) {
+ hyp_fixmap_unmap();
+ return;
+ }
+
fixmap_clear_slot(&hyp_fixblock_slot);
hyp_spin_unlock(&hyp_fixblock_lock);
-#else
- hyp_fixmap_unmap();
-#endif
}
int hyp_create_fixmap(void)
diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c
index b22736853fcd..0880f6456b49 100644
--- a/arch/arm64/mm/fault.c
+++ b/arch/arm64/mm/fault.c
@@ -253,19 +253,15 @@ int __ptep_set_access_flags_anysz(struct vm_area_struct *vma,
* flush_tlb_fix_spurious_fault().
*/
if (dirty) {
- switch (pgsize) {
- case PAGE_SIZE:
+ if (pgsize == PAGE_SIZE) {
level = 3;
- break;
- case PMD_SIZE:
+ } else if (pgsize == PMD_SIZE) {
level = 2;
- break;
#ifndef __PAGETABLE_PMD_FOLDED
- case PUD_SIZE:
+ } else if (pgsize == PUD_SIZE) {
level = 1;
- break;
#endif
- default:
+ } else {
level = TLBI_TTL_UNKNOWN;
WARN_ON(1);
}
next prev parent reply other threads:[~2026-12-01 1:53 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 1:51 [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Eric Curtin
2026-12-01 1:51 ` Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 01/43] mm: Add macros ahead of supporting boot-time page size selection Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 02/43] vmlinux.lds: Align page-aligned sections to PAGE_SIZE_MAX Eric Curtin
2026-12-02 2:34 ` sashiko-bot
2026-12-01 1:51 ` [RFC PATCH v2 03/43] mm: page_frag: Use PAGE_SIZE_MIN/MAX limits in page_frag_cache Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 04/43] mm: page_frag: Add _MIN/_MAX variants of PAGE_FRAG_CACHE_MAX_SIZE Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 05/43] mm: Avoid split pmd ptl if pmd level is run-time folded Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 06/43] mm/vmstat: Use THREAD_SIZE_MAX for the KSTACK_* counters Eric Curtin
2026-12-02 2:34 ` sashiko-bot
2026-12-01 1:51 ` [RFC PATCH v2 07/43] fork: Permit boot-time THREAD_SIZE determination Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 08/43] cgroup: Use DEFINE_GLOBAL_PAGE_SIZE_VAR for the kernfs_ops tables Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 09/43] bpf: Do not embed page-aligned members in struct bpf_ringbuf Eric Curtin
2026-12-02 2:34 ` sashiko-bot
2026-12-01 1:51 ` [RFC PATCH v2 10/43] PM: hibernate: Do not size swap structures to exactly PAGE_SIZE Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 11/43] perf/core: Handle a boot-time PAGE_SIZE in format attrs and mlock Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 12/43] KVM: Check struct kvm_run against PAGE_SIZE_MIN Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 13/43] crash: Check crash_notes size " Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 14/43] arm64: Make INIT_DIR_SIZE and INIT_IDMAP_DIR_SIZE usable from C Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 15/43] arm64: pi: Pass the early pgtable allocation limit to map_range() Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 16/43] arm64: Introduce macros required for boot-time page size selection Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 17/43] arm64: Parameterise early pgtable size macros by page shift Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 18/43] arm64: Add arm64.pagesize= command line override Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 19/43] arm64: pi: Select the page size at runtime during early boot Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 20/43] arm64: pi: Clear the FDT ptes on every remap in map_fdt() Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 21/43] arm64: Test PAGE_SIZE instead of CONFIG_ARM64_*K_PAGES Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 22/43] arm64: Align image sections to PAGE_SIZE_MAX Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 23/43] arm64: Map the trampoline rodata at its aligned offset Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 24/43] arm64: fixmap: Size slots and page tables for PAGE_SIZE_MIN Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 25/43] arm64: Size and align the zero page and FDT ptes for PAGE_SIZE_MAX Eric Curtin
2026-12-01 1:51 ` [RFC PATCH v2 26/43] arm64: Convert KVM and hugetlb size switches to if/else Eric Curtin
2026-12-02 2:34 ` sashiko-bot
2026-12-01 1:51 ` [RFC PATCH v2 27/43] arm64: mm: Make page size dependent BUILD_BUG_ON() checks runtime Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 28/43] arm64: cpufeature: Add capabilities for the page size in use Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 29/43] arm64: Look up the page size at runtime in assembly code Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 30/43] arm64: Support runtime folding of the pmd level Eric Curtin
2026-12-02 2:34 ` sashiko-bot
2026-12-01 1:52 ` [RFC PATCH v2 31/43] arm64: Support runtime folding in idmap_kpti_install_ng_mappings Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 32/43] arm64: Patch TRAMP_VALIAS into instructions at boot Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 33/43] arm64: Determine THREAD_SIZE at boot time Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 34/43] mm/damon/lru_sort: Initialise the stub access pattern at boot Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 35/43] mm/zsmalloc: Size static limits for the worst-case page size Eric Curtin
2026-12-01 1:52 ` Eric Curtin [this message]
2026-12-02 2:34 ` [RFC PATCH v2 36/43] arm64: Convert remaining page-size switches to if/else sashiko-bot
2026-12-01 1:52 ` [RFC PATCH v2 37/43] vdso: Lay out the data pages in VDSO_PAGE_SIZE units Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 38/43] mm: Use fixed sizes for shmem str_dup and swap cache PFN bits Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 39/43] crash: Size the vmcoreinfo page array for the smallest page size Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 40/43] arm64: Size kasan and pKVM stacktrace arrays for PAGE_SIZE_MAX Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 41/43] exit: Use THREAD_SIZE_MAX for lowest_to_date Eric Curtin
2026-12-01 1:52 ` [RFC PATCH v2 42/43] tracing: Use PAGE_SIZE_MIN/MAX in the uprobe check and undefsyms page Eric Curtin
2026-12-01 13:15 ` Masami Hiramatsu (Google)
2026-12-01 1:52 ` [RFC PATCH v2 43/43] arm64: Enable boot-time page size selection Eric Curtin
2026-12-02 2:34 ` sashiko-bot
2026-12-01 10:41 ` [RFC PATCH v2 00/43] Boot-time page size selection for arm64 (core) Lorenzo Stoakes (ARM)
2026-12-01 10:41 ` Lorenzo Stoakes (ARM)
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=20261201015240.1017259-37-ericcurtin17@gmail.com \
--to=ericcurtin17@gmail.com \
--cc=catalin.marinas@arm.com \
--cc=eric.curtin@docker.com \
--cc=fuad.tabba@linux.dev \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=seiden@linux.ibm.com \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/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.