]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
mm: fix balloon_page_movable() page->flags check
authorRafael Aquini <aquini@redhat.com>
Thu, 29 Nov 2012 03:17:24 +0000 (14:17 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 5 Dec 2012 05:23:09 +0000 (16:23 +1100)
Fix the following crash by fixing and enhancing the way page->flags are
tested to identify a ballooned page.

BUG: unable to handle kernel NULL pointer dereference at 0000000000000194
IP: [<ffffffff8122b354>] isolate_migratepages_range+0x344/0x7b0

The NULL pointer deref was taking place because balloon_page_movable()
page->flags tests were incomplete and we ended up inadvertently poking at
private pages.

Signed-off-by: Rafael Aquini <aquini@redhat.com>
Reported-by: Sasha Levin <levinsasha928@gmail.com>
Cc: Mel Gorman <mel@csn.ul.ie>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Rik van Riel <riel@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Minchan Kim <minchan@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/balloon_compaction.h

index 2e63d949098b0fc087ffff4e79195fbfdc28b747..6d380e3a9f4e9f2a8026565b2fb08c1b9c03845e 100644 (file)
@@ -106,6 +106,23 @@ static inline void balloon_mapping_free(struct address_space *balloon_mapping)
        kfree(balloon_mapping);
 }
 
+/*
+ * __balloon_page_flags - helper to perform balloon @page ->flags tests.
+ *
+ * As balloon pages are got from Buddy, and we do not play with page->flags
+ * at driver level (exception made when we get the page lock for compaction),
+ * therefore we can safely identify a ballooned page by checking if the
+ * NR_PAGEFLAGS rightmost bits from the page->flags are all cleared.
+ * This approach also helps on skipping ballooned pages that are locked for
+ * compaction or release, thus mitigating their racy check at
+ * balloon_page_movable()
+ */
+#define BALLOON_PAGE_FLAGS_MASK       ((1UL << NR_PAGEFLAGS) - 1)
+static inline bool __balloon_page_flags(struct page *page)
+{
+       return page->flags & BALLOON_PAGE_FLAGS_MASK ? false : true;
+}
+
 /*
  * __is_movable_balloon_page - helper to perform @page mapping->flags tests
  */
@@ -135,8 +152,8 @@ static inline bool balloon_page_movable(struct page *page)
         * Before dereferencing and testing mapping->flags, lets make sure
         * this is not a page that uses ->mapping in a different way
         */
-       if (!PageSlab(page) && !PageSwapCache(page) && !PageAnon(page) &&
-           !page_mapped(page))
+       if (__balloon_page_flags(page) && !page_mapped(page) &&
+           page_count(page) == 1)
                return __is_movable_balloon_page(page);
 
        return false;