aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc/mm
diff options
context:
space:
mode:
authorHuang Ying <ying.huang@intel.com>2018-04-05 19:24:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-04-06 00:36:26 -0400
commitcb9f753a3731f7fe16447bea45cb6f8e8bb432fb (patch)
treef9c9d1ec34be344b46c0a26675fbc7b8830933b5 /arch/sparc/mm
parent1c0ff0f1bdeb183608ac9a345996d4d1ebfed632 (diff)
mm: fix races between swapoff and flush dcache
Thanks to commit 4b3ef9daa4fc ("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>
Diffstat (limited to 'arch/sparc/mm')
-rw-r--r--arch/sparc/mm/init_64.c6
-rw-r--r--arch/sparc/mm/tlb.c2
2 files changed, 4 insertions, 4 deletions
diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
index cb9ebac6663f..8aeb1aabe76e 100644
--- a/arch/sparc/mm/init_64.c
+++ b/arch/sparc/mm/init_64.c
@@ -206,9 +206,9 @@ inline void flush_dcache_page_impl(struct page *page)
206#ifdef DCACHE_ALIASING_POSSIBLE 206#ifdef DCACHE_ALIASING_POSSIBLE
207 __flush_dcache_page(page_address(page), 207 __flush_dcache_page(page_address(page),
208 ((tlb_type == spitfire) && 208 ((tlb_type == spitfire) &&
209 page_mapping(page) != NULL)); 209 page_mapping_file(page) != NULL));
210#else 210#else
211 if (page_mapping(page) != NULL && 211 if (page_mapping_file(page) != NULL &&
212 tlb_type == spitfire) 212 tlb_type == spitfire)
213 __flush_icache_page(__pa(page_address(page))); 213 __flush_icache_page(__pa(page_address(page)));
214#endif 214#endif
@@ -490,7 +490,7 @@ void flush_dcache_page(struct page *page)
490 490
491 this_cpu = get_cpu(); 491 this_cpu = get_cpu();
492 492
493 mapping = page_mapping(page); 493 mapping = page_mapping_file(page);
494 if (mapping && !mapping_mapped(mapping)) { 494 if (mapping && !mapping_mapped(mapping)) {
495 int dirty = test_bit(PG_dcache_dirty, &page->flags); 495 int dirty = test_bit(PG_dcache_dirty, &page->flags);
496 if (dirty) { 496 if (dirty) {
diff --git a/arch/sparc/mm/tlb.c b/arch/sparc/mm/tlb.c
index b5cfab711651..3d72d2deb13b 100644
--- a/arch/sparc/mm/tlb.c
+++ b/arch/sparc/mm/tlb.c
@@ -128,7 +128,7 @@ void tlb_batch_add(struct mm_struct *mm, unsigned long vaddr,
128 goto no_cache_flush; 128 goto no_cache_flush;
129 129
130 /* A real file page? */ 130 /* A real file page? */
131 mapping = page_mapping(page); 131 mapping = page_mapping_file(page);
132 if (!mapping) 132 if (!mapping)
133 goto no_cache_flush; 133 goto no_cache_flush;
134 134