kernel_optimize_test/arch/parisc/kernel
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
..
.gitignore
asm-offsets.c
audit.c
binfmt_elf32.c
cache.c mm: fix races between swapoff and flush dcache 2018-04-05 21:36:26 -07:00
compat_audit.c
drivers.c parisc: Fix out of array access in match_pci_device() 2018-03-27 18:52:22 +02:00
entry.S parisc: Fix alignment of pa_tlb_lock in assembly on 32-bit SMP kernel 2018-01-02 22:21:54 +01:00
firmware.c
ftrace.c
hardware.c parisc: Move various functions and strings to init section 2018-03-27 18:52:21 +02:00
head.S parisc: Check if secondary CPUs want own PDC calls 2018-03-02 10:04:46 +01:00
hpmc.S parisc: Fix HPMC handler by increasing size to multiple of 16 bytes 2018-03-27 18:52:22 +02:00
inventory.c
irq.c
Makefile
module.c parisc64: Add .opd based function descriptor dereference 2018-01-09 10:45:38 +01:00
pa7300lc.c
pacache.S parisc: Fix ordering of cache and TLB flushes 2018-03-02 10:03:28 +01:00
parisc_ksyms.c
pci-dma.c microblaze: remove dma_nommu_dma_supported 2018-01-10 16:41:16 +01:00
pci.c
pdc_chassis.c
pdc_cons.c treewide: Switch DEFINE_TIMER callbacks to struct timer_list * 2017-11-21 15:57:05 -08:00
pdt.c mm/memory_failure: Remove unused trapno from memory_failure 2018-01-23 12:17:42 -06:00
perf_asm.S
perf_images.h
perf.c
process.c parisc: machine_power_off() should call pm_power_off() 2018-03-27 18:52:22 +02:00
processor.c
ptrace.c
real2.S
setup.c
signal.c
signal32.c signal: Unify and correct copy_siginfo_to_user32 2018-01-15 19:56:20 -06:00
signal32.h signal: Unify and correct copy_siginfo_to_user32 2018-01-15 19:56:20 -06:00
smp.c parisc: Check if secondary CPUs want own PDC calls 2018-03-02 10:04:46 +01:00
stacktrace.c
sys_parisc.c mm: add ksys_readahead() helper; remove in-kernel calls to sys_readahead() 2018-04-02 20:16:12 +02:00
sys_parisc32.c
syscall_table.S
syscall.S
time.c parisc: Reduce irq overhead when run in qemu 2018-03-02 10:05:07 +01:00
topology.c
traps.c signal/parisc: Document a conflict with SI_USER with SIGFPE 2018-01-12 14:21:03 -06:00
unaligned.c
unwind.c parisc: remove duplicate includes 2017-12-17 21:06:25 +01:00
vmlinux.lds.S parisc64: Add .opd based function descriptor dereference 2018-01-09 10:45:38 +01:00