From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: Andrew Morton <akpm@linux-foundation.org>,
Jane Chu <jane.chu@oracle.com>,
linux-mm@kvack.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
Muchun Song <muchun.song@linux.dev>,
Oscar Salvador <osalvador@suse.de>,
David Hildenbrand <david@kernel.org>,
Miaohe Lin <linmiaohe@huawei.com>,
Naoya Horiguchi <nao.horiguchi@gmail.com>,
Jan Kara <jack@suse.cz>,
linux-fsdevel@vger.kernel.org,
Christian Brauner <christian@brauner.io>
Subject: [PATCH v2 07/10] mm: Handle hugetlb correctly in is_page_hwpoison()
Date: Thu, 9 Jul 2026 19:47:35 +0100 [thread overview]
Message-ID: <20260709184740.1286561-8-willy@infradead.org> (raw)
In-Reply-To: <20260709184740.1286561-1-willy@infradead.org>
Checking to see whether a page inside a hugetlb folio is hardware
poisoned is more complicated than I realised. The correct logic was
in is_raw_hwpoison_page_in_hugepage(). Make is_page_hwpoison() the
official entry point for "is this page hwpoison", no matter what kind
of folio it belongs to. Rename is_raw_hwpoison_page_in_hugepage() to
hugetlb_page_hwpoison(), and remove the attempt to handle non-hugetlb
folios from it.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/hugetlbfs/inode.c | 4 ++--
include/linux/hugetlb.h | 5 -----
include/linux/page-flags.h | 24 +++++++++++++++++++-----
mm/memory-failure.c | 9 ++++-----
4 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index 1760df6f2709..725bb945a440 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -198,7 +198,7 @@ static size_t adjust_range_hwpoison(struct folio *folio, size_t offset,
struct page *page = folio_page(folio, offset / PAGE_SIZE);
size_t safe_bytes;
- if (is_raw_hwpoison_page_in_hugepage(page))
+ if (hugetlb_page_hwpoison(folio, page))
return 0;
/* Safe to read the remaining bytes in this page. */
safe_bytes = PAGE_SIZE - (offset % PAGE_SIZE);
@@ -206,7 +206,7 @@ static size_t adjust_range_hwpoison(struct folio *folio, size_t offset,
/* Check each remaining page as long as we are not done yet. */
for (; safe_bytes < bytes; safe_bytes += PAGE_SIZE, page++)
- if (is_raw_hwpoison_page_in_hugepage(page))
+ if (hugetlb_page_hwpoison(folio, page))
break;
return min(safe_bytes, bytes);
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 18661a7cdb37..1878642e75ec 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -1069,11 +1069,6 @@ void hugetlb_register_node(struct node *node);
void hugetlb_unregister_node(struct node *node);
#endif
-/*
- * Check if a given raw @page in a hugepage is HWPOISON.
- */
-bool is_raw_hwpoison_page_in_hugepage(struct page *page);
-
static inline unsigned long huge_page_mask_align(struct file *file)
{
return PAGE_MASK & ~huge_page_mask(hstate_file(file));
diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index 4185a03a45cf..8e57c12a7301 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -1068,6 +1068,9 @@ static inline bool PageHuge(const struct page *page)
return folio_test_hugetlb(page_folio(page));
}
+#ifdef CONFIG_MEMORY_FAILURE
+bool hugetlb_page_hwpoison(const struct folio *folio, const struct page *page);
+
/*
* Check if a page is currently marked HWPoisoned. Note that this check is
* best effort only and inherently racy: there is no way to synchronize with
@@ -1075,13 +1078,24 @@ static inline bool PageHuge(const struct page *page)
*/
static inline bool is_page_hwpoison(const struct page *page)
{
- const struct folio *folio;
+ const struct folio *folio = page_folio(page);
+
+ if (folio_test_hugetlb(folio))
+ return hugetlb_page_hwpoison(folio, page);
+ return PageHWPoison(page);
+}
+#else
+static inline bool hugetlb_page_hwpoison(const struct folio *folio,
+ const struct page *page)
+{
+ return false;
+}
- if (PageHWPoison(page))
- return true;
- folio = page_folio(page);
- return folio_test_hugetlb(folio) && PageHWPoison(&folio->page);
+static inline bool is_page_hwpoison(const struct page *page)
+{
+ return false;
}
+#endif
static inline bool folio_has_hwpoisoned_page(const struct folio *folio)
{
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index 353288cce1b2..58ab8166b7ec 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1817,18 +1817,17 @@ struct raw_hwp_page {
struct page *page;
};
-bool is_raw_hwpoison_page_in_hugepage(struct page *page)
+/*
+ * Check if a given @page in a hugetlb folio is HWPOISON.
+ */
+bool hugetlb_page_hwpoison(const struct folio *folio, const struct page *page)
{
struct raw_hwp_page *p;
- struct folio *folio = page_folio(page);
bool ret = false;
if (!folio_test_hwpoison(folio))
return false;
- if (!folio_test_hugetlb(folio))
- return PageHWPoison(page);
-
/*
* When RawHwpUnreliable is set, kernel lost track of which subpages
* are HWPOISON. So return as if ALL subpages are HWPOISONed.
--
2.47.3
next prev parent reply other threads:[~2026-07-09 18:48 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 18:47 [PATCH v2 00/10] Use generic_file_read_iter() in hugetlbfs Matthew Wilcox (Oracle)
2026-07-09 18:47 ` [PATCH v2 01/10] mm: Rename folio_contain_hwpoison_page() to folio_has_hwpoison_page() Matthew Wilcox (Oracle)
2026-07-10 14:27 ` Usama Arif
2026-07-09 18:47 ` [PATCH v2 02/10] hugetlb: Mark some function arguments as const Matthew Wilcox (Oracle)
2026-07-10 14:28 ` Usama Arif
2026-07-09 18:47 ` [PATCH v2 03/10] filemap: Remove checks in mapping_set_folio_order_range() Matthew Wilcox (Oracle)
2026-07-10 14:42 ` Usama Arif
2026-07-09 18:47 ` [PATCH v2 04/10] hugetlb: Set mapping folio order Matthew Wilcox (Oracle)
2026-07-10 14:49 ` Usama Arif
2026-07-09 18:47 ` [PATCH v2 05/10] memory-failure: Remove raw_hwp_list_head() Matthew Wilcox (Oracle)
2026-07-10 14:55 ` Usama Arif
2026-07-09 18:47 ` [PATCH v2 06/10] memory-failure: Prevent UAF in raw_hwp_page list Matthew Wilcox (Oracle)
2026-07-10 15:02 ` Usama Arif
2026-07-10 17:16 ` Matthew Wilcox
2026-07-09 18:47 ` Matthew Wilcox (Oracle) [this message]
2026-07-09 18:47 ` [PATCH v2 08/10] filemap: Add hwpoison handling to filemap_read() Matthew Wilcox (Oracle)
2026-07-09 18:47 ` [PATCH v2 09/10] filemap: Add support for authoritative mappings Matthew Wilcox (Oracle)
2026-07-09 18:47 ` [PATCH v2 10/10] hugetlb: replace hugetlbfs_read_iter() with generic_file_read_iter() Matthew Wilcox (Oracle)
2026-07-09 19:19 ` [PATCH v2 00/10] Use generic_file_read_iter() in hugetlbfs Matthew Wilcox
2026-07-10 14:25 ` Usama Arif
2026-07-10 23:04 ` [syzbot ci] " syzbot ci
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=20260709184740.1286561-8-willy@infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=christian@brauner.io \
--cc=david@kernel.org \
--cc=jack@suse.cz \
--cc=jane.chu@oracle.com \
--cc=linmiaohe@huawei.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=muchun.song@linux.dev \
--cc=nao.horiguchi@gmail.com \
--cc=osalvador@suse.de \
/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