OpenCloudOS-Kernel/arch/arm
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
..
boot Drop unused VPIF endpoints from device-tree. 2017-08-04 13:22:33 +02:00
common arm: implement ->dma_supported instead of ->set_dma_mask 2017-06-28 06:54:49 -07:00
configs This is the big bulk of pin control changes for the v4.13 series: 2017-07-06 11:38:59 -07:00
crypto crypto: arm/crc32 - enable module autoloading based on CPU feature bits 2017-06-01 12:55:42 +08:00
firmware
include mm: fix MADV_[FREE|DONTNEED] TLB flush miss problem 2017-08-10 15:54:07 -07:00
kernel Merge branch 'fixes' of git://git.armlinux.org.uk/~rmk/linux-arm 2017-07-27 10:35:07 -07:00
kvm Merge branch 'kvmarm-master/master' into HEAD 2017-06-15 09:35:15 +01:00
lib
mach-actions ARM: owl: smp: Drop bogus holding pen 2017-07-03 14:31:47 +02:00
mach-alpine
mach-artpec
mach-asm9260
mach-aspeed clocksource/drivers/fttmr010: Merge Moxa into FTTMR010 2017-06-12 10:45:10 +02:00
mach-at91 Fixes for 4.12: 2017-06-18 23:12:36 -07:00
mach-axxia
mach-bcm ARM: SoC platform updates 2017-07-04 14:34:51 -07:00
mach-berlin
mach-clps711x clocksource/drivers: Rename CLKSRC_OF to TIMER_OF 2017-06-14 12:01:03 +02:00
mach-cns3xxx
mach-davinci ARM: davinci: normalize clk API 2017-07-27 13:15:29 +02:00
mach-digicolor
mach-dove ARM/PCI: Convert PCI scan API to pci_scan_root_bus_bridge() 2017-06-28 15:13:55 -05:00
mach-ebsa110
mach-efm32
mach-ep93xx ARM: ep93xx: normalize clk API 2017-07-27 22:57:24 +02:00
mach-exynos
mach-footbridge
mach-gemini
mach-highbank
mach-hisi
mach-imx ARM: imx6ull: Make suspend/resume work like on 6ul 2017-06-07 11:38:40 +08:00
mach-integrator
mach-iop13xx ARM/PCI: Convert PCI scan API to pci_scan_root_bus_bridge() 2017-06-28 15:13:55 -05:00
mach-iop32x
mach-iop33x
mach-ixp4xx ARM: ixp4xx: fix ioport_unmap definition 2017-07-27 22:57:53 +02:00
mach-keystone
mach-ks8695
mach-lpc18xx
mach-lpc32xx ARM/dmaengine: pl08x: pass reasonable memcpy settings 2017-05-24 09:44:32 +05:30
mach-mediatek clocksource/drivers: Rename clocksource_probe to timer_probe 2017-06-14 11:59:16 +02:00
mach-meson arm: meson: select the clock controller for Meson8 2017-06-09 11:15:36 -07:00
mach-mmp ARM: mmp: mark usb_dma_mask as __maybe_unused 2017-07-27 22:57:49 +02:00
mach-moxart clocksource/drivers/fttmr010: Merge Moxa into FTTMR010 2017-06-12 10:45:10 +02:00
mach-mv78xx0 ARM/PCI: Convert PCI scan API to pci_scan_root_bus_bridge() 2017-06-28 15:13:55 -05:00
mach-mvebu ARM: mvebu: use __pa_symbol in the mv98dx3236 platform SMP code 2017-07-18 11:26:30 +02:00
mach-mxs
mach-netx
mach-nomadik
mach-nspire
mach-omap1 ARM: omap1: avoid unused variable warning 2017-07-27 22:57:46 +02:00
mach-omap2 ARM: SoC fixes for 4.13 2017-08-04 15:12:15 -07:00
mach-orion5x ARM/PCI: Convert PCI scan API to pci_scan_root_bus_bridge() 2017-06-28 15:13:55 -05:00
mach-oxnas
mach-picoxcell
mach-prima2 ARM: sirf: mark sirfsoc_init_late as __maybe_unused 2017-07-27 22:57:44 +02:00
mach-pxa ARM: pxa: select both FB and FB_W100 for eseries 2017-07-27 22:57:55 +02:00
mach-qcom
mach-realview
mach-rockchip ARM: SoC platform updates 2017-07-04 14:34:51 -07:00
mach-rpc ARM: rpc: rename RAM_SIZE macro 2017-07-27 22:57:38 +02:00
mach-s3c24xx clocksource/drivers: Rename CLKSRC_OF to TIMER_OF 2017-06-14 12:01:03 +02:00
mach-s3c64xx dmaengine updates for 4.13-rc1 2017-07-08 12:36:50 -07:00
mach-s5pv210
mach-sa1100 ARM: sa1100: normalize clk API 2017-07-27 13:15:50 +02:00
mach-shmobile Third Round of Renesas ARM Based SoC Fixes for v4.13 2017-08-04 12:54:41 +02:00
mach-socfpga
mach-spear dmaengine updates for 4.13-rc1 2017-07-08 12:36:50 -07:00
mach-sti
mach-stm32 ARM: stm32: Introduce MACH_STM32F469 flag 2017-06-18 20:10:27 -07:00
mach-sunxi clocksource/drivers: Rename clocksource_probe to timer_probe 2017-06-14 11:59:16 +02:00
mach-tango
mach-tegra
mach-u300 clocksource/drivers: Rename clocksource_probe to timer_probe 2017-06-14 11:59:16 +02:00
mach-uniphier
mach-ux500 drivers/perf: arm_pmu: Request PMU SPIs with IRQF_PER_CPU 2017-07-27 13:43:22 +01:00
mach-versatile
mach-vexpress
mach-vt8500
mach-w90x900 ARM: w90x900: normalize clk API 2017-07-27 22:57:36 +02:00
mach-zx
mach-zynq clocksource/drivers: Rename clocksource_probe to timer_probe 2017-06-14 11:59:16 +02:00
mm ARM: NOMMU: Wire-up default DMA interface 2017-07-20 16:09:27 +02:00
net
nwfpe
oprofile
plat-iop
plat-omap
plat-orion
plat-pxa
plat-samsung
plat-versatile
probes arm: Prevent hotplug rwsem recursion 2017-05-26 10:10:46 +02:00
tools
vdso
vfp
xen This is the first pull request for the new dma-mapping subsystem 2017-07-06 19:20:54 -07:00
Kconfig ARM: ep93xx: use ARM_PATCH_PHYS_VIRT correctly 2017-07-27 22:57:51 +02:00
Kconfig-nommu
Kconfig.debug SoC for 4.13: 2017-06-18 22:53:20 -07:00
Makefile ARM: Prepare Actions Semi S500 2017-06-21 18:08:41 +02:00