[PATCH] mm,hwpoison: Drain pcplists before bailing out for non-bud= zero-refcount page

From: Oscar Salvador
Date: Mon Aug 03 2020 - 09:25:10 EST


A page with 0-refcount and !PageBuddy could perfectly be a pcppage.
Currently, we bail out with an error if we encounter such a page,
meaning that we do not handle pcppages neither from hard-offline
nor from soft-offline path.

Fix this by draining pcplists whenever we find this kind of page
and retry the check again.
It might be that pcplists have been spilled into the buddy allocator
and so we can handle it.

Signed-off-by: Oscar Salvador <osalvador@xxxxxxx>
---
mm/memory-failure.c | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index b2753ce2b85b..02be529445c0 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -949,13 +949,13 @@ static int page_action(struct page_state *ps, struct =
page *p,
}
=20
/**
- * get_hwpoison_page() - Get refcount for memory error handling:
+ * __get_hwpoison_page() - Get refcount for memory error handling:
* @page: raw error page (hit by memory error)
*
* Return: return 0 if failed to grab the refcount, otherwise true (some
* non-zero value.)
*/
-static int get_hwpoison_page(struct page *page)
+static int __get_hwpoison_page(struct page *page)
{
struct page *head =3D compound_head(page);
=20
@@ -985,6 +985,28 @@ static int get_hwpoison_page(struct page *page)
return 0;
}
=20
+static int get_hwpoison_page(struct page *p)
+{
+ int ret;
+ bool drained =3D false;
+
+retry:
+ ret =3D __get_hwpoison_page(p);
+ if (!ret) {
+ if (!is_free_buddy_page(p) && !page_count(p) && !drained) {
+ /*
+ * The page might be in a pcplist, so try to drain
+ * those and see if we are lucky.
+ */
+ drain_all_pages(page_zone(p));
+ drained =3D true;
+ goto retry;
+ }
+ }
+
+ return ret;
+}
+
/*
* Do all that is necessary to remove user space mappings. Unmap
* the pages and send SIGBUS to the processes if the data was dirty.
@@ -1683,10 +1705,6 @@ static int __get_any_page(struct page *p, unsigned l=
ong pfn)
{
int ret;
=20
- /*
- * When the target page is a free hugepage, just remove it
- * from free hugepage list.
- */
if (!get_hwpoison_page(p)) {
if (PageHuge(p)) {
pr_info("%s: %#lx free huge page\n", __func__, pfn);
--=20
2.25.1=