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: 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>, Matthew Wilcox <willy@infradead.org>
Subject: [PATCH 3/4] filemap: add hwpoison handling to filemap_read()
Date: Tue, 7 Jul 2026 19:17:10 +0100 [thread overview]
Message-ID: <20260707181713.208282-4-willy@infradead.org> (raw)
In-Reply-To: <20260707181713.208282-1-willy@infradead.org>
From: Jane Chu <jane.chu@oracle.com>
Add hwpoison handling to filemap_read() such that .read_iter() could
make best effort copying data out of clean pages without risking
MCE in case page cache contains HWpoison.
[1] https://lore.kernel.org/linux-mm/aeZwAz6PcdlqSnJ2@casper.infradead.org/
Suggested-by: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Jane Chu <jane.chu@oracle.com>
Signed-off-by: Matthew Wilcox <willy@infradead.org>
---
mm/filemap.c | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/mm/filemap.c b/mm/filemap.c
index 5af62e6abca5..2b65367574be 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2483,6 +2483,8 @@ static void filemap_get_read_batch(struct address_space *mapping,
if (!folio_batch_add(fbatch, folio))
break;
+ if (folio_contain_hwpoisoned_page(folio))
+ break;
if (!folio_test_uptodate(folio))
break;
if (folio_test_readahead(folio))
@@ -2749,6 +2751,27 @@ static inline bool pos_same_folio(loff_t pos1, loff_t pos2, struct folio *folio)
return (pos1 >> shift == pos2 >> shift);
}
+static size_t adjust_range_hwpoison(const struct folio *folio, size_t offset,
+ size_t bytes)
+{
+ const struct page *page = folio_page(folio, offset / PAGE_SIZE);
+ size_t safe_bytes;
+
+ if (is_page_hwpoison(page))
+ return 0;
+
+ /* Safe to read the remaining bytes in this page. */
+ safe_bytes = PAGE_SIZE - (offset % PAGE_SIZE);
+ page++;
+
+ /* Check each remaining page as long as we are not done yet. */
+ for (; safe_bytes < bytes; safe_bytes += PAGE_SIZE, page++)
+ if (is_page_hwpoison(page))
+ break;
+
+ return min(safe_bytes, bytes);
+}
+
static void filemap_end_dropbehind_read(struct folio *folio)
{
if (!folio_test_dropbehind(folio))
@@ -2862,6 +2885,14 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_iter *iter,
if (writably_mapped)
flush_dcache_folio(folio);
+ if (folio_contain_hwpoisoned_page(folio)) {
+ bytes = adjust_range_hwpoison(folio, offset, bytes);
+ if (bytes == 0) {
+ error = -EIO;
+ break;
+ }
+ }
+
copied = copy_folio_to_iter(folio, offset, bytes, iter);
already_read += copied;
--
2.47.3
next prev parent reply other threads:[~2026-07-07 18:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 18:17 [PATCH 0/4] Use generic_file_read_iter() in hugetlbfs Matthew Wilcox (Oracle)
2026-07-07 18:17 ` [PATCH 1/4] hugetlbfs: Set mapping folio order Matthew Wilcox (Oracle)
2026-07-07 18:17 ` [PATCH 2/4] mm: Handle hugetlb correctly in is_page_hwpoison() Matthew Wilcox (Oracle)
2026-07-07 18:17 ` Matthew Wilcox (Oracle) [this message]
2026-07-07 18:17 ` [PATCH 4/4] hugetlbfs: replace hugetlbfs_read_iter() with generic_file_read_iter() Matthew Wilcox (Oracle)
2026-07-08 23:31 ` [PATCH 0/4] Use generic_file_read_iter() in hugetlbfs jane.chu
2026-07-09 3:07 ` Matthew Wilcox
2026-07-09 5:56 ` jane.chu
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=20260707181713.208282-4-willy@infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=jack@suse.cz \
--cc=jane.chu@oracle.com \
--cc=linmiaohe@huawei.com \
--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