aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSantosh Shilimkar <santosh.shilimkar@oracle.com>2016-09-19 17:44:15 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-09-19 18:36:17 -0400
commitc8de641b1e9c5489aa6ca57b7836acd68e7563f1 (patch)
tree6cf2e5f733905522629ef39910f79709f9f78422
parent7cbdb4a286a60c5d519cb9223fe2134d26870d39 (diff)
mm: fix the page_swap_info() BUG_ON check
Commit 62c230bc1790 ("mm: add support for a filesystem to activate swap files and use direct_IO for writing swap pages") replaced the swap_aops dirty hook from __set_page_dirty_no_writeback() with swap_set_page_dirty(). For normal cases without these special SWP flags code path falls back to __set_page_dirty_no_writeback() so the behaviour is expected to be the same as before. But swap_set_page_dirty() makes use of the page_swap_info() helper to get the swap_info_struct to check for the flags like SWP_FILE, SWP_BLKDEV etc as desired for those features. This helper has BUG_ON(!PageSwapCache(page)) which is racy and safe only for the set_page_dirty_lock() path. For the set_page_dirty() path which is often needed for cases to be called from irq context, kswapd() can toggle the flag behind the back while the call is getting executed when system is low on memory and heavy swapping is ongoing. This ends up with undesired kernel panic. This patch just moves the check outside the helper to its users appropriately to fix kernel panic for the described path. Couple of users of helpers already take care of SwapCache condition so I skipped them. Link: http://lkml.kernel.org/r/1473460718-31013-1-git-send-email-santosh.shilimkar@oracle.com Signed-off-by: Santosh Shilimkar <santosh.shilimkar@oracle.com> Cc: Mel Gorman <mgorman@suse.de> Cc: Joe Perches <joe@perches.com> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Rik van Riel <riel@redhat.com> Cc: David S. Miller <davem@davemloft.net> Cc: Jens Axboe <axboe@fb.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Hugh Dickins <hughd@google.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: <stable@vger.kernel.org> [4.7.x] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--mm/page_io.c3
-rw-r--r--mm/swapfile.c1
2 files changed, 3 insertions, 1 deletions
diff --git a/mm/page_io.c b/mm/page_io.c
index 16bd82fad38c..eafe5ddc2b54 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -264,6 +264,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
264 int ret; 264 int ret;
265 struct swap_info_struct *sis = page_swap_info(page); 265 struct swap_info_struct *sis = page_swap_info(page);
266 266
267 BUG_ON(!PageSwapCache(page));
267 if (sis->flags & SWP_FILE) { 268 if (sis->flags & SWP_FILE) {
268 struct kiocb kiocb; 269 struct kiocb kiocb;
269 struct file *swap_file = sis->swap_file; 270 struct file *swap_file = sis->swap_file;
@@ -337,6 +338,7 @@ int swap_readpage(struct page *page)
337 int ret = 0; 338 int ret = 0;
338 struct swap_info_struct *sis = page_swap_info(page); 339 struct swap_info_struct *sis = page_swap_info(page);
339 340
341 BUG_ON(!PageSwapCache(page));
340 VM_BUG_ON_PAGE(!PageLocked(page), page); 342 VM_BUG_ON_PAGE(!PageLocked(page), page);
341 VM_BUG_ON_PAGE(PageUptodate(page), page); 343 VM_BUG_ON_PAGE(PageUptodate(page), page);
342 if (frontswap_load(page) == 0) { 344 if (frontswap_load(page) == 0) {
@@ -386,6 +388,7 @@ int swap_set_page_dirty(struct page *page)
386 388
387 if (sis->flags & SWP_FILE) { 389 if (sis->flags & SWP_FILE) {
388 struct address_space *mapping = sis->swap_file->f_mapping; 390 struct address_space *mapping = sis->swap_file->f_mapping;
391 BUG_ON(!PageSwapCache(page));
389 return mapping->a_ops->set_page_dirty(page); 392 return mapping->a_ops->set_page_dirty(page);
390 } else { 393 } else {
391 return __set_page_dirty_no_writeback(page); 394 return __set_page_dirty_no_writeback(page);
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 78cfa292a29a..2657accc6e2b 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2724,7 +2724,6 @@ int swapcache_prepare(swp_entry_t entry)
2724struct swap_info_struct *page_swap_info(struct page *page) 2724struct swap_info_struct *page_swap_info(struct page *page)
2725{ 2725{
2726 swp_entry_t swap = { .val = page_private(page) }; 2726 swp_entry_t swap = { .val = page_private(page) };
2727 BUG_ON(!PageSwapCache(page));
2728 return swap_info[swp_type(swap)]; 2727 return swap_info[swp_type(swap)];
2729} 2728}
2730 2729