aboutsummaryrefslogtreecommitdiffstats
path: root/mm/page_alloc.c
diff options
context:
space:
mode:
authorNaoya Horiguchi <n-horiguchi@ah.jp.nec.com>2018-08-23 20:00:42 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-23 21:48:43 -0400
commitd4ae9916ea2947341180d2b538f48875ff393a86 (patch)
treee478e5e6e84de25fade8f2995c9ee49cacd5a488 /mm/page_alloc.c
parent6bc9b56433b76e40d11099338d27fbc5cd2935ca (diff)
mm: soft-offline: close the race against page allocation
A process can be killed with SIGBUS(BUS_MCEERR_AR) when it tries to allocate a page that was just freed on the way of soft-offline. This is undesirable because soft-offline (which is about corrected error) is less aggressive than hard-offline (which is about uncorrected error), and we can make soft-offline fail and keep using the page for good reason like "system is busy." Two main changes of this patch are: - setting migrate type of the target page to MIGRATE_ISOLATE. As done in free_unref_page_commit(), this makes kernel bypass pcplist when freeing the page. So we can assume that the page is in freelist just after put_page() returns, - setting PG_hwpoison on free page under zone->lock which protects freelists, so this allows us to avoid setting PG_hwpoison on a page that is decided to be allocated soon. [akpm@linux-foundation.org: tweak set_hwpoison_free_buddy_page() comment] Link: http://lkml.kernel.org/r/1531452366-11661-3-git-send-email-n-horiguchi@ah.jp.nec.com Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Reported-by: Xishi Qiu <xishi.qiuxishi@alibaba-inc.com> Tested-by: Mike Kravetz <mike.kravetz@oracle.com> Cc: Michal Hocko <mhocko@kernel.org> Cc: <zy.zhengyi@alibaba-inc.com> Cc: Mike Kravetz <mike.kravetz@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/page_alloc.c')
-rw-r--r--mm/page_alloc.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index c677c1506d73..e75865d58ba7 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -8096,3 +8096,33 @@ bool is_free_buddy_page(struct page *page)
8096 8096
8097 return order < MAX_ORDER; 8097 return order < MAX_ORDER;
8098} 8098}
8099
8100#ifdef CONFIG_MEMORY_FAILURE
8101/*
8102 * Set PG_hwpoison flag if a given page is confirmed to be a free page. This
8103 * test is performed under the zone lock to prevent a race against page
8104 * allocation.
8105 */
8106bool set_hwpoison_free_buddy_page(struct page *page)
8107{
8108 struct zone *zone = page_zone(page);
8109 unsigned long pfn = page_to_pfn(page);
8110 unsigned long flags;
8111 unsigned int order;
8112 bool hwpoisoned = false;
8113
8114 spin_lock_irqsave(&zone->lock, flags);
8115 for (order = 0; order < MAX_ORDER; order++) {
8116 struct page *page_head = page - (pfn & ((1 << order) - 1));
8117
8118 if (PageBuddy(page_head) && page_order(page_head) >= order) {
8119 if (!TestSetPageHWPoison(page))
8120 hwpoisoned = true;
8121 break;
8122 }
8123 }
8124 spin_unlock_irqrestore(&zone->lock, flags);
8125
8126 return hwpoisoned;
8127}
8128#endif