linux-stable/mm
Peter Xu f1eb1bacfb mm/uffd: always wr-protect pte in pte|pmd_mkuffd_wp()
This patch is a cleanup to always wr-protect pte/pmd in mkuffd_wp paths.

The reasons I still think this patch is worthwhile, are:

  (1) It is a cleanup already; diffstat tells.

  (2) It just feels natural after I thought about this, if the pte is uffd
      protected, let's remove the write bit no matter what it was.

  (2) Since x86 is the only arch that supports uffd-wp, it also redefines
      pte|pmd_mkuffd_wp() in that it should always contain removals of
      write bits.  It means any future arch that want to implement uffd-wp
      should naturally follow this rule too.  It's good to make it a
      default, even if with vm_page_prot changes on VM_UFFD_WP.

  (3) It covers more than vm_page_prot.  So no chance of any potential
      future "accident" (like pte_mkdirty() sparc64 or loongarch, even
      though it just got its pte_mkdirty fixed <1 month ago).  It'll be
      fairly clear when reading the code too that we don't worry anything
      before a pte_mkuffd_wp() on uncertainty of the write bit.

We may call pte_wrprotect() one more time in some paths (e.g.  thp split),
but that should be fully local bitop instruction so the overhead should be
negligible.

Although this patch should logically also fix all the known issues on
uffd-wp too recently on page migration (not for numa hint recovery - that
may need another explcit pte_wrprotect), but this is not the plan for that
fix.  So no fixes, and stable doesn't need this.

Link: https://lkml.kernel.org/r/20221214201533.1774616-1-peterx@redhat.com
Signed-off-by: Peter Xu <peterx@redhat.com>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Ives van Hoorne <ives@codesandbox.io>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Nadav Amit <nadav.amit@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-01-18 17:12:37 -08:00
..
damon
kasan kasan: mark kasan_kunit_executing as static 2023-01-11 16:14:21 -08:00
kfence hardening updates for v6.2-rc1 2022-12-14 12:20:00 -08:00
kmsan kmsan: export kmsan_handle_urb 2022-12-21 14:31:52 -08:00
backing-dev.c
balloon_compaction.c
bootmem_info.c
cma_debug.c
cma_sysfs.c
cma.c
cma.h
compaction.c
debug_page_ref.c
debug_vm_pgtable.c
debug.c
dmapool.c
early_ioremap.c
fadvise.c mm/fadvise: use LLONG_MAX instead of -1 for eof 2022-12-11 18:12:11 -08:00
failslab.c
filemap.c filemap: convert replace_page_cache_page() to replace_page_cache_folio() 2022-12-11 18:12:12 -08:00
folio-compat.c folio-compat: remove lru_cache_add() 2022-12-11 18:12:13 -08:00
frontswap.c
gup_test.c mm/gup_test: free memory allocated via kvcalloc() using kvfree() 2022-12-15 16:37:48 -08:00
gup_test.h
gup.c New Feature: 2022-12-17 14:06:53 -06:00
highmem.c
hmm.c mm: Remove pointless barrier() after pmdp_get_lockless() 2022-12-15 10:37:27 -08:00
huge_memory.c mm/uffd: always wr-protect pte in pte|pmd_mkuffd_wp() 2023-01-18 17:12:37 -08:00
hugetlb_cgroup.c
hugetlb_vmemmap.c
hugetlb_vmemmap.h
hugetlb.c mm/uffd: always wr-protect pte in pte|pmd_mkuffd_wp() 2023-01-18 17:12:37 -08:00
hwpoison-inject.c
init-mm.c
internal.h mm: move folio_set_compound_order() to mm/internal.h 2023-01-18 17:12:36 -08:00
interval_tree.c
io-mapping.c
ioremap.c
Kconfig New Feature: 2022-12-17 14:06:53 -06:00
Kconfig.debug
khugepaged.c mm/MADV_COLLAPSE: don't expand collapse when vm_end is past requested end 2023-01-11 16:14:20 -08:00
kmemleak.c mm/kmemleak: use %pK to display kernel pointers in backtrace 2022-12-15 16:37:49 -08:00
ksm.c
list_lru.c
maccess.c
madvise.c mm: update mmap_sem comments to refer to mmap_lock 2023-01-11 16:14:22 -08:00
Makefile
mapping_dirty_helpers.c mm: Rename pmd_read_atomic() 2022-12-15 10:37:27 -08:00
memblock.c mm: Always release pages to the buddy allocator in memblock_free_late(). 2023-01-08 18:49:33 +02:00
memcontrol.c mm: memcg: fix swapcached stat accounting 2022-12-11 18:12:20 -08:00
memfd.c
memory_hotplug.c
memory-failure.c
memory-tiers.c
memory.c mm/uffd: always wr-protect pte in pte|pmd_mkuffd_wp() 2023-01-18 17:12:37 -08:00
mempolicy.c mm/mempolicy: fix memory leak in set_mempolicy_home_node system call 2022-12-21 14:31:51 -08:00
mempool.c
memremap.c
memtest.c
migrate_device.c
migrate.c MM patches for 6.2-rc1. 2022-12-13 19:29:45 -08:00
mincore.c
mlock.c
mm_init.c
mm_slot.h
mmap_lock.c
mmap.c mm: update mmap_sem comments to refer to mmap_lock 2023-01-11 16:14:22 -08:00
mmu_gather.c mm: mmu_gather: allow more than one batch of delayed rmaps 2022-12-11 18:12:21 -08:00
mmu_notifier.c
mmzone.c
mprotect.c mm/uffd: always wr-protect pte in pte|pmd_mkuffd_wp() 2023-01-18 17:12:37 -08:00
mremap.c mm, mremap: fix mremap() expanding vma with addr inside vma 2022-12-21 14:31:51 -08:00
msync.c
nommu.c nommu: fix split_vma() map_count error 2023-01-11 16:14:23 -08:00
oom_kill.c
page_alloc.c mm/page_alloc: update comments in __free_pages_ok() 2022-12-11 18:12:17 -08:00
page_counter.c
page_ext.c
page_idle.c
page_io.c
page_isolation.c
page_owner.c
page_poison.c
page_reporting.c
page_reporting.h
page_table_check.c
page_vma_mapped.c
page-writeback.c
pagewalk.c
percpu-internal.h
percpu-km.c
percpu-stats.c
percpu-vm.c
percpu.c
pgalloc-track.h
pgtable-generic.c
process_vm_access.c
ptdump.c
readahead.c
rmap.c mm,thp,rmap: fix races between updates of subpages_mapcount 2022-12-11 18:12:20 -08:00
rodata_test.c
secretmem.c
shmem.c mm/shmem: restore SHMEM_HUGE_DENY precedence over MADV_COLLAPSE 2023-01-11 16:14:20 -08:00
shrinker_debug.c
shuffle.c
shuffle.h
slab_common.c hardening updates for v6.2-rc1 2022-12-14 12:20:00 -08:00
slab.c
slab.h
slob.c
slub.c MM patches for 6.2-rc1. 2022-12-13 19:29:45 -08:00
sparse-vmemmap.c mm/sparse-vmemmap: generalise vmemmap_populate_hugepages() 2022-12-11 18:12:12 -08:00
sparse.c
swap_cgroup.c
swap_slots.c
swap_state.c
swap.c
swap.h
swapfile.c MM patches for 6.2-rc1. 2022-12-13 19:29:45 -08:00
truncate.c folio-compat: remove lru_cache_add() 2022-12-11 18:12:13 -08:00
usercopy.c
userfaultfd.c mm/uffd: always wr-protect pte in pte|pmd_mkuffd_wp() 2023-01-18 17:12:37 -08:00
util.c
vmalloc.c
vmpressure.c
vmscan.c New Feature: 2022-12-17 14:06:53 -06:00
vmstat.c
workingset.c folio-compat: remove lru_cache_add() 2022-12-11 18:12:13 -08:00
z3fold.c
zbud.c
zpool.c
zsmalloc.c
zswap.c