[PATCH v7 0/4] s390/mm: Batch PTE updates in lazy MMU mode
Alexander Gordeev <[email protected]>
| Newsgroups | org.kernel.vger.linux-s390,org.kernel.vger.linux-kernel,org.kvack.linux-mm |
|---|---|
| Message-ID | <[email protected]> |
Hi All! This is v7 of the batched PTE updates in lazy MMU mode rework. The presented implementation sets up per-cpu caches in the s390-specific hotplug callbacks as opposed to CPUHP_BP_PREPARE_DYN hooks. I like this approach better, since the boot CPU setup is architecture-specific anyway and the whole SMP-related lowcore initialization is handled in one place. Heiko Carstens requested some mechanism that would rule out direct dereferencing of PTE pointers, which otherwise would bypass the per- cpu cache on s390 and lead to catastrophic results. To address this request a sparse rework was suggested: https://lore.kernel.org/linux-mm/[email protected]/ But an altenative (huge) MM rework looks as a superior solution: https://lore.kernel.org/linux-mm/[email protected]/ https://lore.kernel.org/linux-mm/[email protected]/ 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 sizes unaligned on KASAN_GRANULE_SIZE [5] 4. https://lore.kernel.org/linux-s390/[email protected]/T/#md98724bd3b66d0a0711deb6089fa541f420566d8 5. https://lore.kernel.org/linux-s390/[email protected]/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/[email protected]/#r 3. https://lore.kernel.org/linux-s390/[email protected]/ Changes since v3: - all prerequisite patches are landed in -next and removed from the series Changes since v2: - lazy_mmu_mode_enable_for_pte_range() renamed to lazy_mmu_mode_enable_with_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_range() - 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.ibm.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. Alexander Gordeev (4): 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 arch/s390/Kconfig | 1 + arch/s390/include/asm/lazy_mmu.h | 9 + arch/s390/include/asm/lowcore.h | 2 +- arch/s390/include/asm/pgtable.h | 157 ++++++++++-- arch/s390/kernel/setup.c | 2 + arch/s390/kernel/smp.c | 7 + arch/s390/mm/Makefile | 1 + arch/s390/mm/lazy_mmu.c | 418 +++++++++++++++++++++++++++++++ arch/s390/mm/pgtable.c | 8 +- fs/proc/task_mmu.c | 2 +- include/linux/kasan.h | 19 +- include/linux/pgtable.h | 46 ++++ mm/kasan/common.c | 14 ++ mm/kasan/kasan.h | 2 + mm/kasan/report_generic.c | 3 + mm/madvise.c | 8 +- mm/memory.c | 8 +- mm/mprotect.c | 2 +- mm/mremap.c | 2 +- mm/vmalloc.c | 6 +- 20 files changed, 678 insertions(+), 39 deletions(-) create mode 100644 arch/s390/include/asm/lazy_mmu.h create mode 100644 arch/s390/mm/lazy_mmu.c -- 2.53.0