linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: zhenwei pi <pizhenwei@bytedance.com>
To: akpm@linux-foundation.org, naoya.horiguchi@nec.com
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	zhenwei pi <pizhenwei@bytedance.com>
Subject: [PATCH v2 3/5] mm/memory-failure.c: add hwpoison_filter for soft offline
Date: Mon,  9 May 2022 18:56:39 +0800	[thread overview]
Message-ID: <20220509105641.491313-4-pizhenwei@bytedance.com> (raw)
In-Reply-To: <20220509105641.491313-1-pizhenwei@bytedance.com>

hwpoison_filter is missing in the soft offline path, this leads an
issue: after enabling the corrupt filter, the user process still has
a chance to inject hwpoison fault by
madvise(addr, len, MADV_SOFT_OFFLINE) at PFN which is expected to
reject.

Also do a minor change in comment of memory_failure().

Signed-off-by: zhenwei pi <pizhenwei@bytedance.com>
---
 mm/memory-failure.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index ece05858568f..ed280ef5473d 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1762,7 +1762,7 @@ static DEFINE_MUTEX(mf_mutex);
  * enabled and no spinlocks hold.
  *
  * Return: 0 for successfully handled the memory error,
- *         -EOPNOTSUPP for memory_filter() filtered the error event,
+ *         -EOPNOTSUPP for hwpoison_filter() filtered the error event,
  *         < 0(except -EOPNOTSUPP) on failure.
  */
 int memory_failure(unsigned long pfn, int flags)
@@ -2317,7 +2317,9 @@ static void put_ref_page(struct page *page)
  * @pfn: pfn to soft-offline
  * @flags: flags. Same as memory_failure().
  *
- * Returns 0 on success, otherwise negated errno.
+ * Returns 0 on success
+ *         -EOPNOTSUPP for hwpoison_filter() filtered the error event
+ *         < 0 otherwise negated errno.
  *
  * Soft offline a page, by migration or invalidation,
  * without killing anything. This is for the case when
@@ -2368,6 +2370,16 @@ int soft_offline_page(unsigned long pfn, int flags)
 	ret = get_hwpoison_page(page, flags | MF_SOFT_OFFLINE);
 	put_online_mems();
 
+	if (hwpoison_filter(page)) {
+		if (ret > 0)
+			put_page(page);
+		else
+			put_ref_page(ref_page);
+
+		mutex_unlock(&mf_mutex);
+		return -EOPNOTSUPP;
+	}
+
 	if (ret > 0) {
 		ret = soft_offline_in_use_page(page);
 	} else if (ret == 0) {
-- 
2.20.1



  parent reply	other threads:[~2022-05-09 11:01 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-09 10:56 [PATCH v2 0/5] memory-failure: fix hwpoison_filter zhenwei pi
2022-05-09 10:56 ` [PATCH v2 1/5] mm/memory-failure.c: move clear_hwpoisoned_pages zhenwei pi
2022-05-09 10:56 ` [PATCH v2 2/5] mm/memory-failure.c: simplify num_poisoned_pages_dec zhenwei pi
2022-05-09 10:56 ` zhenwei pi [this message]
2022-05-11  8:18   ` [PATCH v2 3/5] mm/memory-failure.c: add hwpoison_filter for soft offline HORIGUCHI NAOYA(堀口 直也)
2022-05-09 10:56 ` [PATCH v2 4/5] mm/hwpoison: disable hwpoison filter during removing zhenwei pi
2022-05-11  8:18   ` HORIGUCHI NAOYA(堀口 直也)
2022-05-09 10:56 ` [PATCH v2 5/5] mm/memory-failure.c: simplify num_poisoned_pages_inc/dec zhenwei pi
2022-05-11  8:20   ` HORIGUCHI NAOYA(堀口 直也)
2022-05-11  8:18     ` zhenwei pi

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=20220509105641.491313-4-pizhenwei@bytedance.com \
    --to=pizhenwei@bytedance.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=naoya.horiguchi@nec.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).