linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Oscar Salvador <osalvador@suse.de>
To: akpm@linux-foundation.org
Cc: aris@ruivo.org, naoya.horiguchi@nec.com, mhocko@kernel.org,
	tony.luck@intel.com, cai@lca.pw, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Subject: [PATCH v7 13/14] mm,hwpoison: double-check page count in __get_any_page()
Date: Tue, 22 Sep 2020 15:56:49 +0200	[thread overview]
Message-ID: <20200922135650.1634-14-osalvador@suse.de> (raw)
In-Reply-To: <20200922135650.1634-1-osalvador@suse.de>

From: Naoya Horiguchi <naoya.horiguchi@nec.com>

Soft offlining could fail with EIO due to the race condition with hugepage
migration.  This issuse became visible due to the change by previous patch
that makes soft offline handler take page refcount by its own.  We have no
way to directly pin zero refcount page, and the page considered as a zero
refcount page could be allocated just after the first check.

This patch adds the second check to find the race and gives us chance to
handle it more reliably.

Signed-off-by: Naoya Horiguchi <naoya.horiguchi@nec.com>
Reported-by: Qian Cai <cai@lca.pw>
---
 mm/memory-failure.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 963fd9af23ab..46b1821d2817 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1707,6 +1707,9 @@ static int __get_any_page(struct page *p, unsigned long pfn, int flags)
 		} else if (is_free_buddy_page(p)) {
 			pr_info("%s: %#lx free buddy page\n", __func__, pfn);
 			ret = 0;
+		} else if (page_count(p)) {
+			/* raced with allocation */
+			ret = -EBUSY;
 		} else {
 			pr_info("%s: %#lx: unknown zero refcount page type %lx\n",
 				__func__, pfn, p->flags);
@@ -1723,6 +1726,9 @@ static int get_any_page(struct page *page, unsigned long pfn, int flags)
 {
 	int ret = __get_any_page(page, pfn, flags);
 
+	if (ret == -EBUSY)
+		ret = __get_any_page(page, pfn, flags);
+
 	if (ret == 1 && !PageHuge(page) &&
 	    !PageLRU(page) && !__PageMovable(page)) {
 		/*
-- 
2.26.2



  parent reply	other threads:[~2020-09-22 13:57 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-22 13:56 [PATCH v7 00/14] HWPOISON: soft offline rework Oscar Salvador
2020-09-22 13:56 ` [PATCH v7 01/14] mm,hwpoison: cleanup unused PageHuge() check Oscar Salvador
2020-09-22 13:56 ` [PATCH v7 02/14] mm, hwpoison: remove recalculating hpage Oscar Salvador
2020-09-22 13:56 ` [PATCH v7 03/14] mm,hwpoison-inject: don't pin for hwpoison_filter Oscar Salvador
2020-09-22 13:56 ` [PATCH v7 04/14] mm,hwpoison: unexport get_hwpoison_page and make it static Oscar Salvador
2020-09-23  7:24   ` HORIGUCHI NAOYA(堀口 直也)
2020-09-22 13:56 ` [PATCH v7 05/14] mm,hwpoison: refactor madvise_inject_error Oscar Salvador
2020-09-23  7:24   ` HORIGUCHI NAOYA(堀口 直也)
2020-09-22 13:56 ` [PATCH v7 06/14] mm,hwpoison: kill put_hwpoison_page Oscar Salvador
2020-09-23  7:24   ` HORIGUCHI NAOYA(堀口 直也)
2020-09-22 13:56 ` [PATCH v7 07/14] mm,hwpoison: unify THP handling for hard and soft offline Oscar Salvador
2020-09-23  7:26   ` HORIGUCHI NAOYA(堀口 直也)
2020-09-22 13:56 ` [PATCH v7 08/14] mm,hwpoison: rework soft offline for free pages Oscar Salvador
2020-09-23  7:27   ` HORIGUCHI NAOYA(堀口 直也)
2020-09-22 13:56 ` [PATCH v7 09/14] mm,hwpoison: rework soft offline for in-use pages Oscar Salvador
2020-09-23  7:30   ` HORIGUCHI NAOYA(堀口 直也)
2020-09-22 13:56 ` [PATCH v7 10/14] mm,hwpoison: refactor soft_offline_huge_page and __soft_offline_page Oscar Salvador
2020-09-23  7:35   ` HORIGUCHI NAOYA(堀口 直也)
2020-09-22 13:56 ` [PATCH v7 11/14] mm,hwpoison: return 0 if the page is already poisoned in soft-offline Oscar Salvador
2020-09-23  7:39   ` HORIGUCHI NAOYA(堀口 直也)
2020-09-22 13:56 ` [PATCH v7 12/14] mm,hwpoison: introduce MF_MSG_UNSPLIT_THP Oscar Salvador
2020-09-22 13:56 ` Oscar Salvador [this message]
2020-09-22 13:56 ` [PATCH v7 14/14] mm,hwpoison: Try to narrow window race for free pages Oscar Salvador
2020-09-23  7:40   ` HORIGUCHI NAOYA(堀口 直也)
2020-09-22 17:03 ` [PATCH v7 00/14] HWPOISON: soft offline rework Andrew Morton
2020-09-22 17:56   ` osalvador
2020-09-23 13:29 ` Aristeu Rozanski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200922135650.1634-14-osalvador@suse.de \
    --to=osalvador@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=aris@ruivo.org \
    --cc=cai@lca.pw \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=naoya.horiguchi@nec.com \
    --cc=tony.luck@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).