linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Jinjiang Tu <tujinjiang@huawei.com>
To: David Hildenbrand <david@redhat.com>, <akpm@linux-foundation.org>,
	<linmiaohe@huawei.com>, <osalvador@suse.de>, <mhocko@kernel.org>,
	<ziy@nvidia.com>
Cc: <linux-mm@kvack.org>, <wangkefeng.wang@huawei.com>
Subject: [PATCH v4] mm/vmscan: fix hwpoisoned large folio handling in shrink_folio_list
Date: Fri, 11 Jul 2025 16:55:45 +0800	[thread overview]
Message-ID: <69fd4e00-1b13-d5f7-1c82-705c7d977ea4@huawei.com> (raw)
In-Reply-To: <990715ed-f660-4b88-b850-57d6aee6ee59@redhat.com>

In shrink_folio_list(), the hwpoisoned folio may be large folio, which
can't be handled by unmap_poisoned_folio(). For THP, try_to_unmap_one()
must be passed with TTU_SPLIT_HUGE_PMD to split huge PMD first and then
retry. Without TTU_SPLIT_HUGE_PMD, we will trigger null-ptr deref of
pvmw.pte. Even we passed TTU_SPLIT_HUGE_PMD, we will trigger a WARN_ON_ONCE
due to the page isn't in swapcache.

Since UCE is rare in real world, and race with reclaimation is more rare,
just skipping the hwpoisoned large folio is enough. memory_failure() will
handle it if the UCE is triggered again.

Fixes: 1b0449544c64 ("mm/vmscan: don't try to reclaim hwpoison folio")
Reported-by: syzbot+3b220254df55d8ca8a61@syzkaller.appspotmail.com
Closes: 
https://lore.kernel.org/all/68412d57.050a0220.2461cf.000e.GAE@google.com/
Acked-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
---
  mm/memory-failure.c | 4 ++++
  mm/vmscan.c         | 8 ++++++++
  2 files changed, 12 insertions(+)

diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index b91a33fb6c69..225dddff091d 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1561,6 +1561,10 @@ static int get_hwpoison_page(struct page *p, 
unsigned long flags)
      return ret;
  }

+/*
+ * The caller must guarantee the folio isn't large folio, except hugetlb.
+ * try_to_unmap() can't handle it.
+ */
  int unmap_poisoned_folio(struct folio *folio, unsigned long pfn, bool 
must_kill)
  {
      enum ttu_flags ttu = TTU_IGNORE_MLOCK | TTU_SYNC | TTU_HWPOISON;
diff --git a/mm/vmscan.c b/mm/vmscan.c
index f8dfd2864bbf..424412680cfc 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1138,6 +1138,14 @@ static unsigned int shrink_folio_list(struct 
list_head *folio_list,
              goto keep;

          if (folio_contain_hwpoisoned_page(folio)) {
+            /*
+             * unmap_poisoned_folio() can't handle large
+             * folio, just skip it. memory_failure() will
+             * handle it if the UCE is triggered again.
+             */
+            if (folio_test_large(folio))
+                goto keep_locked;
+
              unmap_poisoned_folio(folio, folio_pfn(folio), false);
              folio_unlock(folio);
              folio_put(folio);
-- 
2.43.0




  reply	other threads:[~2025-07-11  8:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-11  2:17 [PATCH v3] " Jinjiang Tu
2025-07-11  3:04 ` Zi Yan
2025-07-11  5:37 ` Oscar Salvador
2025-07-11  8:05 ` David Hildenbrand
2025-07-11  8:55   ` Jinjiang Tu [this message]
2025-07-12 23:42     ` [PATCH v4] " Andrew Morton
2025-07-11  8:56   ` [PATCH v3] " Jinjiang Tu

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=69fd4e00-1b13-d5f7-1c82-705c7d977ea4@huawei.com \
    --to=tujinjiang@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=linmiaohe@huawei.com \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=osalvador@suse.de \
    --cc=wangkefeng.wang@huawei.com \
    --cc=ziy@nvidia.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