linux-stable/mm
Mina Almasry d84cf06e3d mm, hugetlb: fix simple resv_huge_pages underflow on UFFDIO_COPY
The userfaultfd hugetlb tests cause a resv_huge_pages underflow.  This
happens when hugetlb_mcopy_atomic_pte() is called with !is_continue on
an index for which we already have a page in the cache.  When this
happens, we allocate a second page, double consuming the reservation,
and then fail to insert the page into the cache and return -EEXIST.

To fix this, we first check if there is a page in the cache which
already consumed the reservation, and return -EEXIST immediately if so.

There is still a rare condition where we fail to copy the page contents
AND race with a call for hugetlb_no_page() for this index and again we
will underflow resv_huge_pages.  That is fixed in a more complicated
patch not targeted for -stable.

Test:

  Hacked the code locally such that resv_huge_pages underflows produce a
  warning, then:

  ./tools/testing/selftests/vm/userfaultfd hugetlb_shared 10
	2 /tmp/kokonut_test/huge/userfaultfd_test && echo test success
  ./tools/testing/selftests/vm/userfaultfd hugetlb 10
	2 /tmp/kokonut_test/huge/userfaultfd_test && echo test success

Both tests succeed and produce no warnings.  After the test runs number
of free/resv hugepages is correct.

[mike.kravetz@oracle.com: changelog fixes]

Link: https://lkml.kernel.org/r/20210528004649.85298-1-almasrymina@google.com
Fixes: 8fb5debc5f ("userfaultfd: hugetlbfs: add hugetlb_mcopy_atomic_pte for userfaultfd support")
Signed-off-by: Mina Almasry <almasrymina@google.com>
Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-06-05 08:58:12 -07:00
..
kasan mm/kasan/init.c: fix doc warning 2021-06-05 08:58:11 -07:00
kfence kfence: use TASK_IDLE when awaiting allocation 2021-06-05 08:58:11 -07:00
backing-dev.c
balloon_compaction.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
cleancache.c
cma.c
cma.h
cma_debug.c
cma_sysfs.c
compaction.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
debug.c
debug_page_ref.c
debug_vm_pgtable.c mm/debug_vm_pgtable: fix alignment for pmd/pud_advanced_tests() 2021-06-05 08:58:11 -07:00
dmapool.c
early_ioremap.c
fadvise.c
failslab.c
filemap.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
frontswap.c mm/mempool: minor coding style tweaks 2021-05-05 11:27:27 -07:00
gup.c Revert "mm/gup: check page posion status for coredump." 2021-05-22 15:09:07 -10:00
gup_test.c selftests/vm: gup_test: test faulting in kernel, and verify pinnable pages 2021-05-05 11:27:26 -07:00
gup_test.h selftests/vm: gup_test: fix test flag 2021-05-05 11:27:26 -07:00
highmem.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
hmm.c
huge_memory.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
hugetlb.c mm, hugetlb: fix simple resv_huge_pages underflow on UFFDIO_COPY 2021-06-05 08:58:12 -07:00
hugetlb_cgroup.c
hwpoison-inject.c
init-mm.c
internal.h Revert "mm/gup: check page posion status for coredump." 2021-05-22 15:09:07 -10:00
interval_tree.c
io-mapping.c
ioremap.c mm/ioremap: fix iomap_max_page_shift 2021-05-14 19:41:32 -07:00
Kconfig mm,memory_hotplug: allocate memmap from the added memory range 2021-05-05 11:27:26 -07:00
Kconfig.debug
khugepaged.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
kmemleak.c
ksm.c ksm: revert "use GET_KSM_PAGE_NOLOCK to get ksm page in remove_rmap_item_from_tree()" 2021-05-14 19:41:32 -07:00
list_lru.c
maccess.c
madvise.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
Makefile mm,memory_hotplug: add kernel boot option to enable memmap_on_memory 2021-05-05 11:27:27 -07:00
mapping_dirty_helpers.c
memblock.c
memcontrol.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
memfd.c
memory-failure.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
memory.c Revert "MIPS: make userspace mapping young by default" 2021-06-05 08:58:11 -07:00
memory_hotplug.c mm/mempool: minor coding style tweaks 2021-05-05 11:27:27 -07:00
mempolicy.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
mempool.c mm/mempool: minor coding style tweaks 2021-05-05 11:27:27 -07:00
memremap.c
memtest.c
migrate.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
mincore.c
mlock.c mm/mempool: minor coding style tweaks 2021-05-05 11:27:27 -07:00
mm_init.c
mmap.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
mmap_lock.c
mmu_gather.c
mmu_notifier.c
mmzone.c
mprotect.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
mremap.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
msync.c
nommu.c mm/vmalloc: remove vwrite() 2021-05-07 00:26:34 -07:00
oom_kill.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
page-writeback.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
page_alloc.c mm/page_alloc: fix counting of free pages after take off from buddy 2021-06-05 08:58:11 -07:00
page_counter.c
page_ext.c
page_idle.c
page_io.c
page_isolation.c
page_owner.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
page_poison.c
page_reporting.c
page_reporting.h
page_vma_mapped.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
pagewalk.c
percpu-internal.h mm: fix typos in comments 2021-05-07 00:26:35 -07:00
percpu-km.c
percpu-stats.c
percpu-vm.c
percpu.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
pgalloc-track.h mm: fix typos in comments 2021-05-07 00:26:35 -07:00
pgtable-generic.c
process_vm_access.c mm/process_vm_access.c: remove duplicate include 2021-05-05 11:27:27 -07:00
ptdump.c
readahead.c
rmap.c mm: fix some typos and code style problems 2021-05-07 00:26:33 -07:00
rodata_test.c
shmem.c userfaultfd: release page in error path to avoid BUG_ON 2021-05-14 19:41:32 -07:00
shuffle.c
shuffle.h mm/shuffle: fix section mismatch warning 2021-05-22 15:09:07 -10:00
slab.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
slab.h
slab_common.c mm, slub: move slub_debug static key enabling outside slab_mutex 2021-05-14 19:41:32 -07:00
slob.c
slub.c kasan: slab: always reset the tag in get_freepointer_safe() 2021-05-22 15:09:07 -10:00
sparse-vmemmap.c
sparse.c mm/mempool: minor coding style tweaks 2021-05-05 11:27:27 -07:00
swap.c mm: fix some typos and code style problems 2021-05-07 00:26:33 -07:00
swap_cgroup.c
swap_slots.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
swap_state.c mm: fix some typos and code style problems 2021-05-07 00:26:33 -07:00
swapfile.c mm/mempool: minor coding style tweaks 2021-05-05 11:27:27 -07:00
truncate.c
usercopy.c
userfaultfd.c userfaultfd: hugetlbfs: fix new flag usage in error path 2021-05-22 15:09:07 -10:00
util.c mm/util.c: fix typo 2021-05-05 11:27:25 -07:00
vmacache.c
vmalloc.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
vmpressure.c
vmscan.c mm/mempool: minor coding style tweaks 2021-05-05 11:27:27 -07:00
vmstat.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
workingset.c
z3fold.c mm: fix some typos and code style problems 2021-05-07 00:26:33 -07:00
zbud.c
zpool.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
zsmalloc.c mm: fix typos in comments 2021-05-07 00:26:35 -07:00
zswap.c mm/zswap.c: switch from strlcpy to strscpy 2021-05-05 11:27:27 -07:00