linux-stable/arch/arm
Huang Ying cb9f753a37 mm: fix races between swapoff and flush dcache
Thanks to commit 4b3ef9daa4 ("mm/swap: split swap cache into 64MB
trunks"), after swapoff the address_space associated with the swap
device will be freed.  So page_mapping() users which may touch the
address_space need some kind of mechanism to prevent the address_space
from being freed during accessing.

The dcache flushing functions (flush_dcache_page(), etc) in architecture
specific code may access the address_space of swap device for anonymous
pages in swap cache via page_mapping() function.  But in some cases
there are no mechanisms to prevent the swap device from being swapoff,
for example,

  CPU1					CPU2
  __get_user_pages()			swapoff()
    flush_dcache_page()
      mapping = page_mapping()
        ...				  exit_swap_address_space()
        ...				    kvfree(spaces)
        mapping_mapped(mapping)

The address space may be accessed after being freed.

But from cachetlb.txt and Russell King, flush_dcache_page() only care
about file cache pages, for anonymous pages, flush_anon_page() should be
used.  The implementation of flush_dcache_page() in all architectures
follows this too.  They will check whether page_mapping() is NULL and
whether mapping_mapped() is true to determine whether to flush the
dcache immediately.  And they will use interval tree (mapping->i_mmap)
to find all user space mappings.  While mapping_mapped() and
mapping->i_mmap isn't used by anonymous pages in swap cache at all.

So, to fix the race between swapoff and flush dcache, __page_mapping()
is add to return the address_space for file cache pages and NULL
otherwise.  All page_mapping() invoking in flush dcache functions are
replaced with page_mapping_file().

[akpm@linux-foundation.org: simplify page_mapping_file(), per Mike]
Link: http://lkml.kernel.org/r/20180305083634.15174-1-ying.huang@intel.com
Signed-off-by: "Huang, Ying" <ying.huang@intel.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Mel Gorman <mgorman@techsingularity.net>
Cc: Dave Hansen <dave.hansen@intel.com>
Cc: Chen Liqin <liqin.linux@gmail.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
Cc: Guan Xuetao <gxt@mprc.pku.edu.cn>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Chris Zankel <chris@zankel.net>
Cc: Vineet Gupta <vgupta@synopsys.com>
Cc: Ley Foon Tan <lftan@altera.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-04-05 21:36:26 -07:00
..
boot zboot: fix stack protector in compressed boot phase 2018-04-05 21:36:21 -07:00
common Merge branches 'fixes', 'misc', 'sa1111' and 'sa1100-for-next' into for-next 2018-01-21 15:38:10 +00:00
configs ARM: omap2: set CONFIG_LIRC=y in defconfig 2018-02-26 21:38:58 +01:00
crypto crypto: arm,arm64 - Fix random regeneration of S_shipped 2018-03-23 23:43:19 +08:00
firmware
include Merge branch 'irq-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2018-04-04 15:19:26 -07:00
kernel Merge branch 'syscalls-next' of git://git.kernel.org/pub/scm/linux/kernel/git/brodo/linux 2018-04-02 21:22:12 -07:00
kvm ARM: kvm: fix building with gcc-8 2018-02-15 20:58:36 +01:00
lib Merge branches 'fixes', 'misc', 'sa1111' and 'sa1100-for-next' into for-next 2018-01-21 15:38:10 +00:00
mach-actions
mach-alpine
mach-artpec
mach-asm9260
mach-aspeed
mach-at91
mach-axxia
mach-bcm
mach-berlin
mach-clps711x ARM: clps711x: mark clps711x_compat as const 2018-02-22 17:42:42 +01:00
mach-cns3xxx
mach-davinci A patch fixing GPIO look-up for MMC/SD card detect and write-protect 2018-03-12 15:30:43 +01:00
mach-digicolor
mach-dove
mach-ebsa110
mach-efm32
mach-ep93xx
mach-exynos ARM: EXYNOS: Add SPDX license identifiers 2018-01-03 18:36:22 +01:00
mach-footbridge
mach-gemini
mach-highbank
mach-hisi
mach-imx perf: Fix sibling iteration 2018-03-16 20:44:12 +01:00
mach-integrator
mach-iop13xx
mach-iop32x
mach-iop33x
mach-ixp4xx
mach-keystone
mach-ks8695
mach-lpc18xx
mach-lpc32xx
mach-mediatek
mach-meson
mach-mmp
mach-moxart
mach-mv78xx0
mach-mvebu ARM: mvebu: Fix broken PL310_ERRATA_753970 selects 2018-02-13 16:39:51 +01:00
mach-mxs
mach-netx
mach-nomadik
mach-nspire
mach-omap1 ARM: OMAP1: clock: Fix debugfs_create_*() usage 2018-02-14 08:35:14 -08:00
mach-omap2 ARM: OMAP2+: Fix sar_base inititalization for HS omaps 2018-02-14 08:35:14 -08:00
mach-orion5x ARM: orion5x: Revert commit 4904dbda41. 2018-02-26 13:41:47 -05:00
mach-oxnas
mach-picoxcell
mach-prima2
mach-pxa spi: spi-gpio: Rewrite to use GPIO descriptors 2018-02-14 16:02:41 +00:00
mach-qcom
mach-realview
mach-rockchip
mach-rpc
mach-s3c24xx spi: spi-gpio: Rewrite to use GPIO descriptors 2018-02-14 16:02:41 +00:00
mach-s3c64xx spi: spi-gpio: Rewrite to use GPIO descriptors 2018-02-14 16:02:41 +00:00
mach-s5pv210 ARM: S5PV210: Add SPDX license identifiers 2018-01-03 18:43:04 +01:00
mach-sa1100 ARM: sa1100/neponset: add GPIO drivers for control and modem registers 2018-01-01 00:50:05 +00:00
mach-shmobile
mach-socfpga
mach-spear
mach-sti
mach-stm32
mach-sunxi
mach-tango
mach-tegra
mach-u300
mach-uniphier
mach-ux500 ARM: ux500: Fix PMU IRQ regression 2018-03-07 16:42:38 +01:00
mach-versatile
mach-vexpress
mach-vt8500 arm: vt8500: kconfig: Remove blank help text 2018-02-02 23:53:10 +09:00
mach-w90x900
mach-zx
mach-zynq
mm mm: fix races between swapoff and flush dcache 2018-04-05 21:36:26 -07:00
net bpf, arm: remove obsolete exception handling from div/mod 2018-01-26 16:42:07 -08:00
nwfpe
oprofile
plat-iop
plat-omap ARM: OMAP: Fix SRAM W+X mapping 2018-03-21 08:16:29 -07:00
plat-orion ARM: orion: fix orion_ge00_switch_board_info initialization 2018-02-22 17:48:39 +01:00
plat-pxa
plat-samsung ARM: SAMSUNG: Add SPDX license identifiers 2018-01-03 18:43:13 +01:00
plat-versatile
probes
tools
vdso
vfp ARM: 8746/1: vfp: Go back to clearing vfp_current_hw_state[] 2018-03-24 14:27:48 +00:00
xen
Kconfig Currently, hardened usercopy performs dynamic bounds checking on slab 2018-02-03 16:25:42 -08:00
Kconfig-nommu
Kconfig.debug ARM: 8747/1: make CONFIG_DEBUG_WX depend on MMU 2018-03-24 14:27:48 +00:00
Makefile