Simplify special kernel page table handling
Get series with b4
b4 am [email protected] change-id 20260611-remove_pgtable_cdtor-3b123938f8cdVersions newest first
- v1 Latest22 patches 28 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/22 | mm: drop unused __mm_flags_set_mask_bits_word()include/ | +0 | 1 reply | |
| 2/22 | mm: move mm_flags helpers to mm_types.hinclude/ include/ | +30 | 1 reply | |
| 3/22 | mm: introduce MMF_KERNEL flag and set it for init_mminclude/ mm/ | +11 | 13 replies | |
| 4/22 | mm: use mm_is_kernel() in generic page table codeinclude/ include/ mm/ +2 more | +22 | 3 replies | |
| 5/22 | arm64: mm: use mm_is_kernel() for kernel mm checksarch/ arch/ arch/ | +7 | 0 replies | |
| 6/22 | loongarch: mm: use mm_is_kernel() in switch_mm_irqs_off()arch/ | +1 | 0 replies | |
| 7/22 | parisc: mm: use mm_is_kernel() for kernel mm checksarch/ arch/ arch/ | +3 | 0 replies | |
| 8/22 | powerpc: mm: use mm_is_kernel() for kernel mm checksarch/ arch/ arch/ +1 more | +4 | 0 replies | |
| 9/22 | s390: mm: use mm_is_kernel() for kernel mm checksarch/ arch/ arch/ | +6 | 0 replies | |
| 10/22 | sparc: mm: use mm_is_kernel() for kernel mm checksarch/ arch/ arch/ +1 more | +5 | 0 replies | |
| 11/22 | um: mm: use mm_is_kernel() in TLB syncarch/ | +1 | 0 replies | |
| 12/22 | x86/mm: use mm_is_kernel() for kernel mm checksarch/ arch/ arch/ | +10 | 1 reply | |
| 13/22 | mm: account page table pages when allocatedinclude/ | +7 | 0 replies | |
| 14/22 | mm: set page table page type when allocatedinclude/ | +2 | 4 replies | |
| 15/22 | mm: only initialise pt_share_count for user pgtablesinclude/ | +6 | 2 replies | |
| 16/22 | efi: mark efi_mm as a kernel mmdrivers/ | +1 | 0 replies | |
| 17/22 | mm: pagewalk: drop redundant address check for kernel mm walksmm/ | +2 | 1 reply | |
| 18/22 | arm64: mm: drop explicit mm_is_efi() check in contptearch/ | +9 | 0 replies | |
| 19/22 | x86/tboot: mark tboot_mm as a kernel mmarch/ | +2 | 1 reply | |
| 20/22 | arm64: mm: drop ctor/dtor calls for kernel page tablesarch/ | +23 | 0 replies | |
| 21/22 | arm: mm: drop ctor call for kernel page tablesarch/ | +1 | 0 replies | |
| 22/22 | riscv: mm: drop ctor/dtor calls for kernel page tablesarch/ | +14 | 0 replies |
Reviews trailers per patch
3 of 22 patches have a Reviewed-by or Acked-by.
| Patch | David Hildenbrand (Arm) |
|---|---|
| 1/22 | A-b |
| 2/22 | A-b |
| 3/22 | |
| 4/22 | |
| 5/22 | |
| 6/22 | |
| 7/22 | |
| 8/22 | |
| 9/22 | |
| 10/22 | |
| 11/22 | |
| 12/22 | |
| 13/22 | |
| 14/22 | |
| 15/22 | A-b |
| 16/22 | |
| 17/22 | |
| 18/22 | |
| 19/22 | |
| 20/22 | |
| 21/22 | |
| 22/22 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH 00/22] Simplify special kernel page table handling
Page table constructors and destructors were originally introduced specifically for user PTE pages. Over time, their use became more widespread, and starting from v6.16 they are called at all levels and for both user and kernel page tables [1]. Or so I thought. Turns out, we still have various special kernel page tables where the ctor/dtor are not called; vmemmap page tables is one such case.
Looking closer, we do not actually need per-level ctors for kernel page tables. In fact we do not need ctors for them at all, because nothing is specific to kernel page tables in the ctor/dtor and nowadays they should be allocated with pagetable_alloc().
Here's the plan: all the generic page table handling moves to pagetable_{alloc,free}(). Whatever is left is specific to user page tables; the ctor/dtor are only called for user page tables at the required levels (PTE/PMD), and renamed to make that clear.
Doing this will allow us to remove a good amount of special casing, but there's quite a bit of churn to get there. Here's what this series does:
1. Introduce the concept of "kernel mm" and replace most comparisons with &init_mm with a flag check (patch 1-12); no functional change so far.
2. Move the page table accounting/type setting to pagetable_{alloc,free} (patch 13-15). Kernel mm's do not need to call the ctor/dtor any more.
3. Mark special mm's (efi_mm, tboot_mm on x86) as kernel mm's (patch 16-19). They now abide by the same rules as init_mm, which means in particular that split page table locks are no longer used.
4. Remove the ctor/dtor calls (now no-ops) for special kernel page tables on arm/arm64/riscv (patch 20-22).
[1] https://lore.kernel.org/all/[email protected]/
---
I stopped there for part 1 to keep it digestible. Part 2 will then ensure that the ctor/dtor are only called for user PTE/PMD pages and rename them accordingly. This is comparatively simpler but also involves a lot of churn.
This series was suggested in reaction to [2]; removing dtor calls entirely for kernel page tables systematically solves such issues.
Worth noting that some comparisons against &init_mm have been left untouched, as they are truly specific to init_mm. Reviewers are encouraged to take a look at the remaining cases:
$ git grep -nE '([=!]= *&init_mm|&init_mm *[=!]=)'
Documentation/mm/active_mm.rst:78: if (current->mm == &init_mm)
Documentation/translations/zh_CN/mm/active_mm.rst:76: if (current->mm == &init_mm)
arch/arm/include/asm/mmu_context.h:144: if (mm != &init_mm)
arch/arm64/include/asm/mmu_context.h:100: if (mm != &init_mm && !system_uses_ttbr0_pan())
arch/arm64/include/asm/mmu_context.h:210: if (mm == &init_mm)
arch/arm64/include/asm/mmu_context.h:242: if (next == &init_mm) {
arch/arm64/mm/fault.c:121: if (mm == &init_mm)
arch/arm64/mm/fault.c:139: if (mm == &init_mm) {
arch/arm64/mm/fault.c:154: mm == &init_mm ? "swapper" : "user", PAGE_SIZE / SZ_1K,
arch/arm64/mm/mmu.c:997: BUG_ON(mm == &init_mm);
arch/powerpc/xmon/xmon.c:3314: if (mm == &init_mm)
arch/riscv/mm/fault.c:42: mm == &init_mm ? (u64)__pa_symbol(mm->pgd) : virt_to_phys(mm->pgd));
kernel/cpu.c:917: WARN_ON(mm != &init_mm);
kernel/fork.c:725: BUG_ON(mm == &init_mm);
kernel/sched/core.c:8390: if (mm != &init_mm) {
mm/ptdump.c:182: if (mm != &init_mm)
mm/ptdump.c:191: if (mm != &init_mm)Testing:
* Built all modified architectures
* arm64
- mm kselftests (FVP)
- Hot adding/removing memory + memory-hotplug kselftests (QEMU)
- Reading /sys/kernel/debug/{efi,kernel}_page_tables
- Reading from /sys/firmware/efi/efivars/
*riscv
- memory-hotplug kselftests (QEMU)
* x86
- mm kselftests (lkvm)
- tboot page table setup using a fake tboot shared page (QEMU)
- CONFIG_EFI_PGT_DUMP=y (QEMU)
Patches based on mm-unstable.
[2] https://lore.kernel.org/all/[email protected]/
---
To: [email protected]
Cc: Andrew Morton <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Lorenzo Stoakes <[email protected]>
Cc: "Liam R. Howlett" <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Cc: Mike Rapoport <[email protected]>
Cc: Suren Baghdasaryan <[email protected]>
Cc: Michal Hocko <[email protected]>
Cc: Pasha Tatashin <[email protected]>
---
Kevin Brodsky (22):
mm: drop unused __mm_flags_set_mask_bits_word()
mm: move mm_flags helpers to mm_types.h
mm: introduce MMF_KERNEL flag and set it for init_mm
mm: use mm_is_kernel() in generic page table code
arm64: mm: use mm_is_kernel() for kernel mm checks
loongarch: mm: use mm_is_kernel() in switch_mm_irqs_off()
parisc: mm: use mm_is_kernel() for kernel mm checks
powerpc: mm: use mm_is_kernel() for kernel mm checks
s390: mm: use mm_is_kernel() for kernel mm checks
sparc: mm: use mm_is_kernel() for kernel mm checks
um: mm: use mm_is_kernel() in TLB sync
x86/mm: use mm_is_kernel() for kernel mm checks
mm: account page table pages when allocated
mm: set page table page type when allocated
mm: only initialise pt_share_count for user pgtables
efi: mark efi_mm as a kernel mm
mm: pagewalk: drop redundant address check for kernel mm walks
arm64: mm: drop explicit mm_is_efi() check in contpte x86/tboot: mark tboot_mm as a kernel mm
arm64: mm: drop ctor/dtor calls for kernel page tables
arm: mm: drop ctor call for kernel page tables
riscv: mm: drop ctor/dtor calls for kernel page tables
arch/arm/mm/mmu.c | 3 +- arch/arm64/include/asm/pgalloc.h | 10 ++-- arch/arm64/mm/contpte.c | 26 ++++------ arch/arm64/mm/hugetlbpage.c | 2 +- arch/arm64/mm/mmu.c | 82 +++++++++----------------------- arch/loongarch/include/asm/mmu_context.h | 2 +- arch/parisc/include/asm/mmu_context.h | 2 +- arch/parisc/include/asm/pgalloc.h | 2 +- arch/parisc/include/asm/tlbflush.h | 2 +- arch/powerpc/include/asm/pgalloc.h | 2 +- arch/powerpc/mm/book3s64/pgtable.c | 2 +- arch/powerpc/mm/mmu_context.c | 2 +- arch/powerpc/mm/pgtable.c | 2 +- arch/riscv/mm/init.c | 63 ++++++------------------ arch/s390/include/asm/mmu_context.h | 2 +- arch/s390/include/asm/pgtable.h | 6 +-- arch/s390/mm/pgalloc.c | 4 +- arch/sparc/include/asm/mmu_context_64.h | 2 +- arch/sparc/include/asm/pgtable_64.h | 6 +-- arch/sparc/mm/init_64.c | 2 +- arch/sparc/mm/tlb.c | 2 +- arch/um/kernel/tlb.c | 2 +- arch/x86/include/asm/tlbflush.h | 8 ++-- arch/x86/kernel/tboot.c | 4 +- arch/x86/mm/pgtable.c | 2 +- arch/x86/mm/tlb.c | 9 ++-- drivers/firmware/efi/efi.c | 1 + include/asm-generic/pgalloc.h | 16 +++---- include/linux/mm.h | 69 +++++++-------------------- include/linux/mm_types.h | 52 +++++++++++++++----- mm/init-mm.c | 1 + mm/memory.c | 6 +-- mm/page_table_check.c | 14 +++--- mm/pagewalk.c | 7 +-- 34 files changed, 163 insertions(+), 254 deletions(-)
---
base-commit: a531f0cf705af3374388eafe4115f651c625d8db
change-id: 20260611-remove_pgtable_cdtor-3b123938f8cd