mm, mmu_notifier: annotate mmu notifiers with blockable invalidate callbacks
authorDavid Rientjes <[email protected]>
Thu, 1 Feb 2018 00:18:32 +0000 (16:18 -0800)
committerLinus Torvalds <[email protected]>
Thu, 1 Feb 2018 01:18:38 +0000 (17:18 -0800)
commit5ff7091f5a2ca1b7b642ca0dbdede8f693a56926
treeaeacdbfded7dd7db9f70766124e45f569ddd4097
parent3b454ad35043dfbd3b5d2bb92b0991d6342afb44
mm, mmu_notifier: annotate mmu notifiers with blockable invalidate callbacks

Commit 4d4bbd8526a8 ("mm, oom_reaper: skip mm structs with mmu
notifiers") prevented the oom reaper from unmapping private anonymous
memory with the oom reaper when the oom victim mm had mmu notifiers
registered.

The rationale is that doing mmu_notifier_invalidate_range_{start,end}()
around the unmap_page_range(), which is needed, can block and the oom
killer will stall forever waiting for the victim to exit, which may not
be possible without reaping.

That concern is real, but only true for mmu notifiers that have
blockable invalidate_range_{start,end}() callbacks.  This patch adds a
"flags" field to mmu notifier ops that can set a bit to indicate that
these callbacks do not block.

The implementation is steered toward an expensive slowpath, such as
after the oom reaper has grabbed mm->mmap_sem of a still alive oom
victim.

[[email protected]: mmu_notifier_invalidate_range_end() can also call the invalidate_range() must not block, fix comment]
Link: http://lkml.kernel.org/r/[email protected]
[[email protected]: make mm_has_blockable_invalidate_notifiers() return bool, use rwsem_is_locked()]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: David Rientjes <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Acked-by: Paolo Bonzini <[email protected]>
Acked-by: Christian König <[email protected]>
Acked-by: Dimitri Sivanich <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Oded Gabbay <[email protected]>
Cc: Alex Deucher <[email protected]>
Cc: David Airlie <[email protected]>
Cc: Joerg Roedel <[email protected]>
Cc: Doug Ledford <[email protected]>
Cc: Jani Nikula <[email protected]>
Cc: Mike Marciniszyn <[email protected]>
Cc: Sean Hefty <[email protected]>
Cc: Boris Ostrovsky <[email protected]>
Cc: Jérôme Glisse <[email protected]>
Cc: Radim Krčmář <[email protected]>
Signed-off-by: David Rientjes <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
drivers/infiniband/hw/hfi1/mmu_rb.c
drivers/iommu/amd_iommu_v2.c
drivers/iommu/intel-svm.c
drivers/misc/sgi-gru/grutlbpurge.c
include/linux/mmu_notifier.h
mm/mmu_notifier.c
virt/kvm/kvm_main.c