Skip to content

s390/mm: Batch PTE updates in lazy MMU mode

Alexander Gordeev linux-mm linux-s390 lkml llvm oe-kbuild-all sashiko-reviews 8 versions – Applied

Status from this message: Applied, thanks!

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v8 Latest15 patches 4 repliesApplied
  2. v74 patches 19 repliesSuperseded
  3. v64 patches 0 repliesSuperseded
Earlier versions · 5
VersionPostedPatchesRepliesStatus
v54 patches2 repliesSuperseded
v44 patches3 repliesSuperseded
v37 patches0 repliesSuperseded
v26 patches23 repliesSuperseded
v1 RFC2 patches14 repliesSuperseded

Changes in v8 from the cover letter

- CPUHP_BP_PREPARE_DYN hotplug event is used to (de-)allocate per-cpu data
- lazy_mmu_enabled static key is used to indicate the lazy mmu mode availability
- is_lazy_mmu_active() is implemented using CLIY alternative
- lazy_mmu_count lowcore variable is turned 1 byte to allow CLIY alternative

Patches in v8 Applied

#Subject and filesSizeRepliesApplied
1/15mm: introduce hw_pte_t for PTE table storageMAINTAINERS include/linux/pgtable_types.h mm/Kconfig+21 -00 replies
2/15mm: rename pointers to software PTE values as ptentpinclude/linux/pagewalk.h mm/ksm.c mm/madvise.c+5 -50 replies
3/15mm: use hw_pte_t for generic PTE table storagefs/hugetlbfs/inode.c fs/proc/task_mmu.c include/asm-generic/hugetlb.h +53 more+410 -3560 replies
4/15mm: convert PTE table entries in ptep_get()include/linux/pgtable.h include/linux/pgtable_types.h+3 -10 replies
5/15mm: convert PTE table entry to pteinclude/linux/hugetlb.h+2 -10 replies
6/15mm: add hw_pte_val for HW PTE storageinclude/linux/pgtable_types.h+4 -00 replies
7/15mm/kasan: use hw_pte_t for the early shadow PTE tableinclude/linux/kasan.h mm/kasan/init.c mm/ptdump.c+3 -30 replies
8/15drm/i915: use hw_pte_t for PTE range callbacksdrivers/gpu/drm/i915/gem/selftests/i915_gem_mman.c drivers/gpu/drm/i915/i915_mm.c+4 -40 replies
9/15xen: use hw_pte_t for PTE range callbacksdrivers/xen/gntdev.c drivers/xen/privcmd.c drivers/xen/xenbus/xenbus_client.c +1 more+5 -50 replies
10/15s390/mm: Cleanup pXXp_flush_lazy() routinesarch/s390/mm/pgtable.c+2 -22 replies
11/15s390: Distinguish hardware and software PTEsarch/s390/Kconfig arch/s390/boot/startup.c arch/s390/boot/vmem.c +14 more+112 -1011 reply
12/15mm: Make lazy MMU mode context-awarefs/proc/task_mmu.c include/linux/pgtable.h mm/madvise.c +4 more+60 -140 replies
13/15s390/mm: Batch PTE updates in lazy MMU modearch/s390/Kconfig arch/s390/include/asm/lowcore.h arch/s390/include/asm/pgtable.h +3 more+583 -241 reply
14/15mm/kasan: Introduce helpers for lazy MMU mode sanitizerinclude/linux/kasan.h mm/kasan/common.c mm/kasan/kasan.h +1 more+36 -20 replies
15/15s390/mm: Lazy MMU mode sanitizerarch/s390/include/asm/pgtable.h arch/s390/mm/lazy_mmu.c+29 -40 replies

Reviews trailers per patch

5 of 15 patches have a Reviewed-by or Acked-by.

PatchDavid Hildenbrand (Arm)Juergen GrossKevin BrodskyGerald Schaefer
1/15A-b
2/15A-b
3/15
4/15
5/15
6/15
7/15
8/15
9/15R-b
10/15R-b
11/15
12/15A-b R-b
13/15
14/15
15/15

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v8 thread

Cover letter [PATCH v8 00/15] s390/mm: Batch PTE updates in lazy MMU mode

Hi All,

This is v8 of the batched PTE updates in lazy MMU mode rework.

Patches 1-9 are a prerequisite series [1] backported from mm-new to master. It is only posted to facilitate the follow-up s390 lazy MMU rework review.

Patch 10 is a cleanup that could be picked independently and is a prerequisite to patch 11

Patch 11 is the s390 variant of the ARM64 series [2] and provides hw_pte_t type enablement

Patches 12,13 are the lazy MMU mode implementation and the main objective of this rework.

Patches 14,15 are an additional KASAN-based lazy-PTE guard mechanism.

1. https://lore.kernel.org/linux-mm/[email protected]/
2. https://lore.kernel.org/all/[email protected]/

Changes since v7:
- CPUHP_BP_PREPARE_DYN hotplug event is used to (de-)allocate per-cpu data
- lazy_mmu_enabled static key is used to indicate the lazy mmu mode availability
- is_lazy_mmu_active() is implemented using CLIY alternative
- lazy_mmu_count lowcore variable is turned 1 byte to allow CLIY alternative

Changes since v6:
- bottom-halves are disabled on entering and leaving the lazy mmu mode

Changes since v5:
- IPTE optimization is not applied to secure guests [4]
- __kasan_(un)poison_pte() are marked as EXPORT_SYMBOL_GPL() [5]
- PTE table poisoning is not applied to architectures with PTE entry size= s
unaligned on KASAN_GRANULE_SIZE [5]
4. https://lore.kernel.org/linux-s390/cover.1783945507.git.agordeev@linux=
.ibm.com/T/#md98724bd3b66d0a0711deb6089fa541f420566d8
5. https://lore.kernel.org/linux-s390/cover.1783945507.git.agordeev@linux=
.ibm.com/T/#m9c8b31b4863416732d0cbbc5f5f63290db4522c1

Changes since v4:
- verified that a presumable sashiko performance regression finding [2] although appears valid does not really degrade performance
- applied sashiko suggestion [3] and added "direct-pte-access" kasan bug = type
2. https://lore.kernel.org/linux-s390/20260623062703.269982B28-agordeev@l=
inux.ibm.com/#r
3. https://lore.kernel.org/linux-s390/20260623061321.269982A64-agordeev@l=
inux.ibm.com/

Changes since v3:
- all prerequisite patches are landed in -next and removed from the serie= s

Changes since v2:
- lazy_mmu_mode_enable_for_pte_range() renamed to lazy_mmu_mode_enable_wi= th_ptes()
(David Hildenbrand)
- patch "mm/pgtable: Fix bogus comment to clear_not_present_full_ptes()" is dropped (David Hildenbrand)
- direct PTE dereferencing KASAN sanitizer added (Heiko Carstens)
- CONFIG_IPTE_BATCH option is dropped (Heiko Carstens)
- PTE_POISON changed from zero to 0x800 (Heiko Carstens)
- allocate per-cpu caches on CPU hot-plug (Heiko Carstens)
- introduced a lowcore field for fast lazy mode checking (Heiko Carstens)
- few minor code changes (Heiko Carstens)

Changes since v1:
- lazy_mmu_mode_enable_pte() renamed to lazy_mmu_mode_enable_for_pte_rang= e()
- lazy_mmu_mode_enable_for_pte_range() semantics clarified
- some sashiko comments addressed [1] including one bug fix [1]
- patches 2-4 added
1. https://sashiko.dev/#/patchset/cover.1774420056.git.agordeev%40linux.i=
bm.com

This series addresses an s390-specific aspect of how page table entries are modified. In many cases, changing a valid PTE (for example, setting or clearing a hardware bit) requires issuing an Invalidate Page Table Entry (IPTE) instruction beforehand.

A disadvantage of the IPTE instruction is that it may initiate a machine-wide quiesce state. This state acts as an expensive global hardware lock and should be avoided whenever possible.

Currently, IPTE is invoked for each individual PTE update in most code paths. However, the instruction itself supports invalidating multiple PTEs at once, covering up to 256 entries. Using this capability can significantly reduce the number of quiesce events, with a positive impact on overall system performance. At present, this feature is not utilized.

An effort was therefore made to identify kernel code paths that update large numbers of consecutive PTEs. Such updates can be batched and handled by a single IPTE invocation, leveraging the hardware support described above.

A natural candidate for this optimization is page-table walkers that change attributes of memory ranges and thus modify contiguous ranges of PTEs. Many memory-management system calls enter lazy MMU mode while updating such ranges.

This lazy MMU mode can be leveraged to build on the already existing infrastructure and implement a software-level lazy MMU mechanism, allowing expensive PTE invalidations on s390 to be batched.

Thanks!

Alexander Gordeev (6):
s390/mm: Cleanup pXXp_flush_lazy() routines
s390: Distinguish hardware and software PTEs
mm: Make lazy MMU mode context-aware
s390/mm: Batch PTE updates in lazy MMU mode mm/kasan: Introduce helpers for lazy MMU mode sanitizer s390/mm: Lazy MMU mode sanitizer

Muhammad Usama Anjum (9):
mm: introduce hw_pte_t for PTE table storage
mm: rename pointers to software PTE values as ptentp
mm: use hw_pte_t for generic PTE table storage
mm: convert PTE table entries in ptep_get()
mm: convert PTE table entry to pte
mm: add hw_pte_val for HW PTE storage mm/kasan: use hw_pte_t for the early shadow PTE table drm/i915: use hw_pte_t for PTE range callbacks
xen: use hw_pte_t for PTE range callbacks

 MAINTAINERS                                   |   1 +
 arch/s390/Kconfig                             |   2 +
 arch/s390/boot/startup.c                      |   2 +-
 arch/s390/boot/vmem.c                         |  17 +-
 arch/s390/include/asm/gmap_helpers.h          |   2 +-
 arch/s390/include/asm/hugetlb.h               |  18 +-
 arch/s390/include/asm/lowcore.h               |   3 +-
 arch/s390/include/asm/maccess.h               |   2 +-
 arch/s390/include/asm/page.h                  |   3 +-
 arch/s390/include/asm/pgalloc.h               |   6 +-
 arch/s390/include/asm/pgtable.h               | 215 +++++++--
 arch/s390/kernel/uv.c                         |   4 +-
 arch/s390/kvm/s390/pv.c                       |   2 +-
 arch/s390/mm/Makefile                         |   2 +-
 arch/s390/mm/gmap_helpers.c                   |  18 +-
 arch/s390/mm/hugetlbpage.c                    |  20 +-
 arch/s390/mm/lazy_mmu.c                       | 449 ++++++++++++++++++
 arch/s390/mm/maccess.c                        |   2 +-
 arch/s390/mm/pageattr.c                       |  10 +-
 arch/s390/mm/pgtable.c                        |  34 +-
 arch/s390/mm/vmem.c                           |  26 +-
 .../drm/i915/gem/selftests/i915_gem_mman.c    |   4 +-
 drivers/gpu/drm/i915/i915_mm.c                |   4 +-
 drivers/xen/gntdev.c                          |   2 +-
 drivers/xen/privcmd.c                         |   2 +-
 drivers/xen/xenbus/xenbus_client.c            |   2 +-
 drivers/xen/xlate_mmu.c                       |   4 +-
 fs/hugetlbfs/inode.c                          |   3 +-
 fs/proc/task_mmu.c                            |  35 +-
 include/asm-generic/hugetlb.h                 |  15 +-
 include/asm-generic/pgalloc.h                 |   6 +-
 include/asm-generic/tlb.h                     |   5 +-
 include/linux/hugetlb.h                       |  53 ++-
 include/linux/kasan.h                         |  21 +-
 include/linux/mm.h                            |  26 +-
 include/linux/page_table_check.h              |  10 +-
 include/linux/pagewalk.h                      |  10 +-
 include/linux/pgtable.h                       | 127 +++--
 include/linux/pgtable_types.h                 |  23 +
 include/linux/rmap.h                          |   2 +-
 include/linux/swapops.h                       |   6 +-
 include/linux/vmalloc.h                       |   4 +-
 include/trace/events/xen.h                    |  10 +-
 kernel/bpf/arena.c                            |   9 +-
 kernel/events/core.c                          |   3 +-
 mm/Kconfig                                    |   3 +
 mm/damon/ops-common.c                         |   2 +-
 mm/damon/ops-common.h                         |   2 +-
 mm/damon/vaddr.c                              |  20 +-
 mm/debug_vm_pgtable.c                         |   2 +-
 mm/filemap.c                                  |   4 +-
 mm/gup.c                                      |   9 +-
 mm/highmem.c                                  |  15 +-
 mm/hmm.c                                      |   6 +-
 mm/huge_memory.c                              |   4 +-
 mm/hugetlb.c                                  |  60 +--
 mm/hugetlb_vmemmap.c                          |  13 +-
 mm/internal.h                                 |  16 +-
 mm/kasan/common.c                             |  14 +
 mm/kasan/init.c                               |  14 +-
 mm/kasan/kasan.h                              |   2 +
 mm/kasan/report_generic.c                     |   3 +
 mm/kasan/shadow.c                             |   6 +-
 mm/khugepaged.c                               |  50 +-
 mm/ksm.c                                      |  11 +-
 mm/madvise.c                                  |  26 +-
 mm/mapping_dirty_helpers.c                    |   4 +-
 mm/memory-failure.c                           |   6 +-
 mm/memory.c                                   |  86 ++--
 mm/mempolicy.c                                |   4 +-
 mm/migrate.c                                  |   4 +-
 mm/migrate_device.c                           |   4 +-
 mm/mincore.c                                  |   4 +-
 mm/mlock.c                                    |   4 +-
 mm/mprotect.c                                 |  21 +-
 mm/mremap.c                                   |   6 +-
 mm/page_table_check.c                         |   4 +-
 mm/pagewalk.c                                 |   9 +-
 mm/percpu.c                                   |   2 +-
 mm/pgtable-generic.c                          |  20 +-
 mm/ptdump.c                                   |   4 +-
 mm/rmap.c                                     |   6 +-
 mm/sparse-vmemmap.c                           |  22 +-
 mm/swap_state.c                               |   3 +-
 mm/swapfile.c                                 |   5 +-
 mm/userfaultfd.c                              |  32 +-
 mm/util.c                                     |   2 +-
 mm/vmalloc.c                                  |  17 +-
 mm/vmscan.c                                   |   6 +-
 89 files changed, 1269 insertions(+), 512 deletions(-)
 create mode 100644 arch/s390/mm/lazy_mmu.c
 create mode 100644 include/linux/pgtable_types.h
Signature · 1 line
2.53.0