linux/arch/um/include/asm
Minchan Kim 99baac21e4 mm: fix MADV_[FREE|DONTNEED] TLB flush miss problem
Nadav reported parallel MADV_DONTNEED on same range has a stale TLB
problem and Mel fixed it[1] and found same problem on MADV_FREE[2].

Quote from Mel Gorman:
 "The race in question is CPU 0 running madv_free and updating some PTEs
  while CPU 1 is also running madv_free and looking at the same PTEs.
  CPU 1 may have writable TLB entries for a page but fail the pte_dirty
  check (because CPU 0 has updated it already) and potentially fail to
  flush.

  Hence, when madv_free on CPU 1 returns, there are still potentially
  writable TLB entries and the underlying PTE is still present so that a
  subsequent write does not necessarily propagate the dirty bit to the
  underlying PTE any more. Reclaim at some unknown time at the future
  may then see that the PTE is still clean and discard the page even
  though a write has happened in the meantime. I think this is possible
  but I could have missed some protection in madv_free that prevents it
  happening."

This patch aims for solving both problems all at once and is ready for
other problem with KSM, MADV_FREE and soft-dirty story[3].

TLB batch API(tlb_[gather|finish]_mmu] uses [inc|dec]_tlb_flush_pending
and mmu_tlb_flush_pending so that when tlb_finish_mmu is called, we can
catch there are parallel threads going on.  In that case, forcefully,
flush TLB to prevent for user to access memory via stale TLB entry
although it fail to gather page table entry.

I confirmed this patch works with [4] test program Nadav gave so this
patch supersedes "mm: Always flush VMA ranges affected by zap_page_range
v2" in current mmotm.

NOTE:

This patch modifies arch-specific TLB gathering interface(x86, ia64,
s390, sh, um).  It seems most of architecture are straightforward but
s390 need to be careful because tlb_flush_mmu works only if
mm->context.flush_mm is set to non-zero which happens only a pte entry
really is cleared by ptep_get_and_clear and friends.  However, this
problem never changes the pte entries but need to flush to prevent
memory access from stale tlb.

[1] http://lkml.kernel.org/r/20170725101230.5v7gvnjmcnkzzql3@techsingularity.net
[2] http://lkml.kernel.org/r/20170725100722.2dxnmgypmwnrfawp@suse.de
[3] http://lkml.kernel.org/r/BD3A0EBE-ECF4-41D4-87FA-C755EA9AB6BD@gmail.com
[4] https://patchwork.kernel.org/patch/9861621/

[minchan@kernel.org: decrease tlb flush pending count in tlb_finish_mmu]
  Link: http://lkml.kernel.org/r/20170808080821.GA31730@bbox
Link: http://lkml.kernel.org/r/20170802000818.4760-7-namit@vmware.com
Signed-off-by: Minchan Kim <minchan@kernel.org>
Signed-off-by: Nadav Amit <namit@vmware.com>
Reported-by: Nadav Amit <namit@vmware.com>
Reported-by: Mel Gorman <mgorman@techsingularity.net>
Acked-by: Mel Gorman <mgorman@techsingularity.net>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Hugh Dickins <hughd@google.com>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Nadav Amit <nadav.amit@gmail.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-08-10 15:54:07 -07:00
..
Kbuild add asm-generic/extable.h 2017-03-27 20:27:28 -04:00
a.out-core.h
bugs.h
cache.h
common.lds.S um: v2: Use generic NOTES macro 2017-07-10 22:58:02 +02:00
dma.h um: get rid of pointless include "..." where include <...> will do 2012-10-09 22:28:45 +02:00
fixmap.h um: Remove broken highmem support 2015-04-13 21:01:02 +02:00
hardirq.h um: Do not change hard IRQ flags in soft IRQ processing 2016-01-10 21:49:48 +01:00
io.h um: add dummy ioremap and iounmap functions 2017-07-05 23:43:14 +02:00
irq.h
irqflags.h um: Use asm-generic/irqflags.h 2016-08-04 00:18:04 +02:00
kmap_types.h um: remove km_type definitions 2012-07-24 15:27:31 +08:00
kvm_para.h kvmclock: Add functions to check if the host has stopped the vm 2012-04-08 12:48:59 +03:00
mmu.h um: get rid of pointless include "..." where include <...> will do 2012-10-09 22:28:45 +02:00
mmu_context.h mm/gup: Drop the arch_pte_access_permitted() MMU callback 2017-03-18 09:48:01 +01:00
page.h um: asm/page.h: remove the pte_high member from struct pte_t 2016-02-05 18:10:40 -08:00
pgalloc.h um: remove pointless include of asm/fixmap.h from asm/pgtable.h 2012-03-25 00:29:55 +01:00
pgtable-2level.h arch, mm: convert all architectures to use 5level-fixup.h 2017-03-09 11:48:47 -08:00
pgtable-3level.h arch, mm: convert all architectures to use 5level-fixup.h 2017-03-09 11:48:47 -08:00
pgtable.h um: kill pfn_t 2016-01-15 17:56:32 -08:00
processor-generic.h arch: remove unused macro/function thread_saved_pc() 2017-06-28 16:13:57 -07:00
ptrace-generic.h um: Define PTRACE_OLDSETOPTIONS 2015-11-06 22:49:09 +01:00
sections.h um: Use char[] for linker script address declarations 2015-05-31 13:14:06 +02:00
setup.h
smp.h um: Remove broken SMP support 2015-04-13 21:00:58 +02:00
stacktrace.h um: Add support for CONFIG_STACKTRACE 2014-10-13 21:46:25 +02:00
syscall-generic.h um: Add full asm/syscall.h support 2016-01-10 21:49:49 +01:00
sysrq.h um: move sysrq.h out of include/shared 2012-10-09 22:28:19 +02:00
thread_info.h um: Add seccomp support 2016-01-10 21:49:49 +01:00
timex.h
tlb.h mm: fix MADV_[FREE|DONTNEED] TLB flush miss problem 2017-08-10 15:54:07 -07:00
tlbflush.h
uaccess.h um: switch to RAW_COPY_USER 2017-03-28 18:24:03 -04:00