From: Matthew Wilcox <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>,
linux-fsdevel@vger.kernel.org,
Christian Brauner <christian@brauner.io>,
Jiaqi Yan <jiaqiyan@google.com>
Subject: Re: [PATCH v5 06/12] mm: Remove locking mf_mutex in is_raw_hwpoison_page_in_hugepage()
Date: Mon, 27 Jul 2026 16:32:35 +0100 [thread overview]
Message-ID: <amd6E4kg9_0Dtf3y@casper.infradead.org> (raw)
In-Reply-To: <20260725160042.1557264-7-willy@infradead.org>
Sashiko:
> --- Patch [6]: [PATCH v5 06/12] mm: Remove locking mf_mutex in is_raw_hwpoison_page_in_hugepage() ---
> commit 5aafc5635bbbdae616864594ab6ced23fdde474f
> Author: Matthew Wilcox (Oracle) <willy@infradead.org>
>
> mm: Remove locking mf_mutex in is_raw_hwpoison_page_in_hugepage()
>
> This commit replaces mf_mutex with a new spinlock to protect the hwpoison
> list in hugetlb folios, preventing unexpected sleeping in predicate functions.
> It also renames the function to hugetlb_page_hwpoison and simplifies it to
> use a standard singly linked list.
>
> > diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> > index 9d245b4f2b8fe..e2f50b4aba822 100644
> > --- a/mm/memory-failure.c
> > +++ b/mm/memory-failure.c
> [ ... ]
> > +bool hugetlb_page_hwpoison(const struct folio *folio, const struct page *page)
> > {
> [ ... ]
> > /*
> > - * When RawHwpUnreliable is set, kernel lost track of which subpages
> > - * are HWPOISON. So return as if ALL subpages are HWPOISONed.
> > + * When RawHwpUnreliable is set, kernel lost track of which pages
> > + * are HWPOISON. So return as if ALL pages are HWPOISONed.
> > */
> > if (folio_test_hugetlb_raw_hwp_unreliable(folio))
> > return true;
> >
> > - mutex_lock(&mf_mutex);
> > -
> > - raw_hwp_head = raw_hwp_list_head(folio);
> > - llist_for_each_entry(p, raw_hwp_head->first, node) {
> > - if (page == p->page) {
> > - ret = true;
> > + spin_lock_irqsave(&hwp_page_lock, flags);
>
> This isn't a bug introduced by this patch, but is it possible for a race
> to occur if the unreliable flag is checked without holding the lock?
>
> If CPU1 calls hugetlb_page_hwpoison() and checks the unreliable flag
> locklessly, it might read false.
>
> Concurrently, CPU2 executing hugetlb_update_hwpoison() might fail to
> allocate a list entry, acquire hwp_page_lock, set the unreliable flag,
> and clear the hugetlb_hwpoison list:
>
> hugetlb_update_hwpoison()
> ...
> p = kmalloc_obj(*p, GFP_ATOMIC);
> if (p) {
> ...
> } else {
> folio_set_hugetlb_raw_hwp_unreliable(folio);
> __folio_free_raw_hwp(folio, false);
> }
> spin_unlock_irqrestore(&hwp_page_lock, flags);
>
> CPU1 would then acquire hwp_page_lock, scan the now-empty list, and
> incorrectly conclude the page is safe. This could potentially allow
> poisoned memory to be accessed.
>
> Would it be safer to check folio_test_hugetlb_raw_hwp_unreliable() inside
> the hwp_page_lock critical section?
Hm, yes, that's true. I'll fold the fix into this patch:
@@ -1831,14 +1831,17 @@ bool hugetlb_page_hwpoison(const struct folio *folio, const struct page *page)
if (!folio_test_has_hwpoisoned(folio))
return false;
+ spin_lock_irqsave(&hwp_page_lock, flags);
+
/*
* When RawHwpUnreliable is set, kernel lost track of which pages
* are HWPOISON. So return as if ALL pages are HWPOISONed.
*/
- if (folio_test_hugetlb_raw_hwp_unreliable(folio))
+ if (folio_test_hugetlb_raw_hwp_unreliable(folio)) {
+ spin_unlock_irqrestore(&hwp_page_lock, flags);
return true;
+ }
- spin_lock_irqsave(&hwp_page_lock, flags);
for (p = folio->hugetlb_hwpoison; p; p = p->next) {
if (page == p->page)
break;
> > + for (p = folio->hugetlb_hwpoison; p; p = p->next) {
> > + if (page == p->page)
> > break;
> > - }
> > }
> > + spin_unlock_irqrestore(&hwp_page_lock, flags);
> >
> > - mutex_unlock(&mf_mutex);
> > -
> > - return ret;
> > + return p != NULL;
> > }
next prev parent reply other threads:[~2026-07-27 15:32 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-25 16:00 [PATCH v5 00/12] Use generic_file_read_iter() in hugetlbfs Matthew Wilcox (Oracle)
2026-07-25 16:00 ` [PATCH v5 01/12] memory-failure: Fix hardware poison check in unpoison_memory() again Matthew Wilcox (Oracle)
2026-07-27 14:43 ` Matthew Wilcox
2026-07-27 19:40 ` Andrew Morton
2026-07-25 16:00 ` [PATCH v5 02/12] mm: Rename folio_contain_hwpoison_page() to folio_has_hwpoison_page() Matthew Wilcox (Oracle)
2026-07-27 14:51 ` Matthew Wilcox
2026-07-25 16:00 ` [PATCH v5 03/12] hugetlb: Mark some function arguments as const Matthew Wilcox (Oracle)
2026-07-25 16:00 ` [PATCH v5 04/12] guest_memfd: Use folio_has_hwpoisoned_page() Matthew Wilcox (Oracle)
2026-07-25 16:00 ` [PATCH v5 05/12] hugetlb: Use the has_hwpoisoned flag Matthew Wilcox (Oracle)
2026-07-27 15:19 ` Matthew Wilcox
2026-07-25 16:00 ` [PATCH v5 06/12] mm: Remove locking mf_mutex in is_raw_hwpoison_page_in_hugepage() Matthew Wilcox (Oracle)
2026-07-27 15:32 ` Matthew Wilcox [this message]
2026-07-25 16:00 ` [PATCH v5 07/12] mm: Check individual hugetlb pages for poison Matthew Wilcox (Oracle)
2026-07-25 16:00 ` [PATCH v5 08/12] filemap: Add hwpoison handling to filemap_read() Matthew Wilcox (Oracle)
2026-07-25 16:00 ` [PATCH v5 09/12] filemap: Remove checks in mapping_set_folio_order_range() Matthew Wilcox (Oracle)
2026-07-25 16:00 ` [PATCH v5 10/12] hugetlb: Set mapping folio order Matthew Wilcox (Oracle)
2026-07-25 16:00 ` [PATCH v5 11/12] filemap: Add support for authoritative mappings Matthew Wilcox (Oracle)
2026-07-27 15:55 ` Matthew Wilcox
2026-07-25 16:00 ` [PATCH v5 12/12] hugetlb: replace hugetlbfs_read_iter() with generic_file_read_iter() Matthew Wilcox (Oracle)
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=amd6E4kg9_0Dtf3y@casper.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=jiaqiyan@google.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