Commit d1474a96 authored by Oscar Salvador's avatar Oscar Salvador Committed by Zheng Zengkai
Browse files

mm,hwpoison: drain pcplists before bailing out for non-buddy zero-refcount page

mainline inclusion
from mainline-v5.11-rc1
commit 17e395b6
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5E2IG
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=17e395b60f5b3dea204fcae60c7b38e84a00d87a

--------------------------------

Patch series "HWpoison: further fixes and cleanups", v5.

This patchset includes some more fixes and a cleanup.

Patch#2 and patch#3 are both fixes for taking a HWpoison page off a buddy
freelist, since having them there has proved to be bad (see [1] and
pathch#2's commit log).  Patch#3 does the same for hugetlb pages.

[1] https://lkml.org/lkml/2020/9/22/565

This patch (of 4):

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.

Link: https://lkml.kernel.org/r/20201013144447.6706-1-osalvador@suse.de
Link: https://lkml.kernel.org/r/20201013144447.6706-2-osalvador@suse.de


Signed-off-by: default avatarOscar Salvador <osalvador@suse.de>
Acked-by: default avatarNaoya Horiguchi <naoya.horiguchi@nec.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: default avatarMa Wupeng <mawupeng1@huawei.com>
Reviewed-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 7bb64d50
Loading
Loading
Loading
Loading
+22 −2
Original line number Diff line number Diff line
@@ -947,13 +947,13 @@ static int page_action(struct page_state *ps, struct page *p,
}

/**
 * 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 = compound_head(page);

@@ -983,6 +983,26 @@ static int get_hwpoison_page(struct page *page)
	return 0;
}

static int get_hwpoison_page(struct page *p)
{
	int ret;
	bool drained = false;

retry:
	ret = __get_hwpoison_page(p);
	if (!ret && !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 = 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.