]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: fix the page_swap_info BUG_ON check
authorSantosh Shilimkar <santosh.shilimkar@oracle.com>
Mon, 12 Sep 2016 16:27:19 +0000 (09:27 -0700)
committerChuck Anderson <chuck.anderson@oracle.com>
Mon, 19 Sep 2016 21:25:21 +0000 (14:25 -0700)
'commit 62c230bc1790 ("mm: add support for a filesystem to activate swap
files and use direct_IO for writing swap pages")' replaced swap_aops
dirty hook from __set_page_dirty_no_writeback() to swap_set_page_dirty().
As such for normal cases without these special SWP flags
code path falls back to __set_page_dirty_no_writeback()
so behaviour is expected to be same as before.

But swap_set_page_dirty() makes use of helper page_swap_info() to
get sis(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
set_page_dirty_lock() path. For set_page_dirty() path which is
often needed for cases to be called from irq context, kswapd()
can togele 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. 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.

Thanks to Wengang for extensive debug using vm cores
and Avinash for his thoughts about the issue.

Orabug: 24661696

Reviewed-by: Avinash Repaka <avinash.repaka@oracle.com>
Reviewed-by: Wengang Wang <wen.gang.wang@oracle.com>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/page_io.c
mm/swapfile.c

index 6424869e275e2aa2d09debfa791ea08302ac68be..37b53ffc3765fa231c5515e3518f4c7bf1a89d01 100644 (file)
@@ -260,6 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
        int ret, rw = WRITE;
        struct swap_info_struct *sis = page_swap_info(page);
 
+       BUG_ON(!PageSwapCache(page));
        if (sis->flags & SWP_FILE) {
                struct kiocb kiocb;
                struct file *swap_file = sis->swap_file;
@@ -331,6 +332,7 @@ int swap_readpage(struct page *page)
        int ret = 0;
        struct swap_info_struct *sis = page_swap_info(page);
 
+       BUG_ON(!PageSwapCache(page));
        VM_BUG_ON_PAGE(!PageLocked(page), page);
        VM_BUG_ON_PAGE(PageUptodate(page), page);
        if (frontswap_load(page) == 0) {
@@ -374,6 +376,7 @@ int swap_set_page_dirty(struct page *page)
 
        if (sis->flags & SWP_FILE) {
                struct address_space *mapping = sis->swap_file->f_mapping;
+               BUG_ON(!PageSwapCache(page));
                return mapping->a_ops->set_page_dirty(page);
        } else {
                return __set_page_dirty_no_writeback(page);
index a7e72103f23bfbf81aad771343dac77c4f4d1958..796d2544e7a931564ca1a78d4e4d8028ac327e92 100644 (file)
@@ -2701,7 +2701,6 @@ int swapcache_prepare(swp_entry_t entry)
 struct swap_info_struct *page_swap_info(struct page *page)
 {
        swp_entry_t swap = { .val = page_private(page) };
-       BUG_ON(!PageSwapCache(page));
        return swap_info[swp_type(swap)];
 }