From: jane.chu@oracle.com
To: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
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>,
"Gregory Price (Meta)" <gourry@gourry.net>
Subject: Re: [PATCH v8 02/15] memory-failure: Prevent hugetlb freeing during unpoisoning
Date: Mon, 3 Aug 2026 23:40:25 -0700 [thread overview]
Message-ID: <2f5fb8e1-67bb-41ec-af8f-b4da60be4583@oracle.com> (raw)
In-Reply-To: <20260731200802.574821-3-willy@infradead.org>
On 7/31/2026 1:07 PM, Matthew Wilcox (Oracle) wrote:
> If we fail to get a reference on the hugetlb folio, then it might be
> freed as we operate on it. Prevent the freeing and the attendant races
> around manipulation of the raw_hwp list by holding the hugetlb_lock,
> which is also held by the hugetlb
>
>
> If we fail to get a reference on the hugetlb folio, then it might be
> freed as we operate on it. Prevent the freeing and the attendant races
> around manipulation of the raw_hwp list by holding the hugetlb_lock,
> which is also held by the hugetlb code when freeing hugetlb folios.
>
> Fixes: ac5fcde0a96a ("mm, hwpoison: make unpoison aware of raw error info in hwpoisoned hugepage")
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Reviewed-by: Gregory Price (Meta) <gourry@gourry.net>
> ---
> include/linux/hugetlb.h | 19 +++++++++++++++++++
> mm/memory-failure.c | 6 +++++-
> 2 files changed, 24 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
> index 2abaf99321e9..50eab2c23299 100644
> --- a/include/linux/hugetlb.h
> +++ b/include/linux/hugetlb.h
> @@ -110,6 +110,17 @@ extern struct resv_map *resv_map_alloc(void);
> void resv_map_release(struct kref *ref);
>
> extern spinlock_t hugetlb_lock;
> +
> +static inline void hugetlb_lock_irq(void)
> +{
> + spin_lock_irq(&hugetlb_lock);
> +}
> +
> +static inline void hugetlb_unlock_irq(void)
> +{
> + spin_unlock_irq(&hugetlb_lock);
> +}
> +
> extern int hugetlb_max_hstate __read_mostly;
> #define for_each_hstate(h) \
> for ((h) = hstates; (h) < &hstates[hugetlb_max_hstate]; (h)++)
> @@ -279,6 +290,14 @@ unsigned int arch_hugetlb_cma_order(void);
>
> #else /* !CONFIG_HUGETLB_PAGE */
>
> +static inline void hugetlb_lock_irq(void)
> +{
> +}
> +
> +static inline void hugetlb_unlock_irq(void)
> +{
> +}
> +
> static inline void hugetlb_dup_vma_private(struct vm_area_struct *vma)
> {
> }
> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> index 944e6e1d4971..1dd0e7b99bb1 100644
> --- a/mm/memory-failure.c
> +++ b/mm/memory-failure.c
> @@ -2725,13 +2725,17 @@ int unpoison_memory(unsigned long pfn)
>
> ghp = get_hwpoison_page(p, MF_UNPOISON);
> if (!ghp) {
> + hugetlb_lock_irq();
> if (folio_test_hugetlb(folio)) {
> huge = true;
> count = folio_free_raw_hwp(folio, false);
> - if (count == 0)
> + if (count == 0) {
> + hugetlb_unlock_irq();
> goto unlock_mutex;
> + }
> }
> ret = folio_test_clear_hwpoison(folio) ? 0 : -EBUSY;
> + hugetlb_unlock_irq();
> } else if (ghp < 0) {
> if (ghp == -EHWPOISON) {
> ret = put_page_back_buddy(p) ? 0 : -EBUSY;
> --
> 2.47.3
>
Patch itself looks good, so Reviewed-by: Jane Chu <jane.chu@oracle.com>
That said, there is a pre-existing issue:
folio_free_raw_hwp() should check HPG_raw_hwp_unreliable, and fail the
act of unpoison just like what __update_and_free_hugetlb_folio() does -
static void __update_and_free_hugetlb_folio(struct hstate *h,
struct folio *folio)
{
bool clear_flag = folio_test_hugetlb_vmemmap_optimized(folio);
if (hstate_is_gigantic_no_runtime(h))
return;
/*
* If we don't know which subpages are hwpoisoned, we can't free
* the hugepage, so it's leaked intentionally.
*/
if (folio_test_hugetlb_raw_hwp_unreliable(folio))
return;
thanks,
-jane
next prev parent reply other threads:[~2026-08-04 6:41 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 20:07 [PATCH v8 00/15] Use generic_file_read_iter() in hugetlbfs Matthew Wilcox (Oracle)
2026-07-31 20:07 ` [PATCH v8 01/15] memory-failure: Fix hardware poison check in unpoison_memory() again Matthew Wilcox (Oracle)
2026-07-31 20:07 ` [PATCH v8 02/15] memory-failure: Prevent hugetlb freeing during unpoisoning Matthew Wilcox (Oracle)
2026-08-04 6:40 ` jane.chu [this message]
2026-08-04 15:35 ` Matthew Wilcox
2026-08-04 21:22 ` jane.chu
2026-07-31 20:07 ` [PATCH v8 03/15] mm: Rename folio_contain_hwpoison_page() to folio_has_hwpoison_page() Matthew Wilcox (Oracle)
2026-07-31 20:07 ` [PATCH v8 04/15] hugetlb: Mark some function arguments as const Matthew Wilcox (Oracle)
2026-08-04 6:41 ` jane.chu
2026-07-31 20:07 ` [PATCH v8 05/15] guest_memfd: Use folio_has_hwpoisoned_page() Matthew Wilcox (Oracle)
2026-08-04 6:42 ` jane.chu
2026-07-31 20:07 ` [PATCH v8 06/15] kpageflags: Use is_page_hwpoison() to set KPF_HWPOISON Matthew Wilcox (Oracle)
2026-08-04 6:44 ` jane.chu
2026-08-04 15:46 ` Matthew Wilcox
2026-08-04 20:21 ` jane.chu
2026-08-04 16:13 ` Gregory Price
2026-07-31 20:07 ` [PATCH v8 07/15] hugetlb: Move poison to pages before clearing hugetlb page type Matthew Wilcox (Oracle)
2026-08-04 6:47 ` jane.chu
2026-07-31 20:07 ` [PATCH v8 08/15] hugetlb: Use the has_hwpoisoned flag Matthew Wilcox (Oracle)
2026-08-04 6:51 ` jane.chu
2026-08-04 16:04 ` Matthew Wilcox
2026-08-04 16:28 ` Gregory Price
2026-08-04 16:42 ` Matthew Wilcox
2026-08-04 18:43 ` Gregory Price
2026-07-31 20:07 ` [PATCH v8 09/15] mm: Remove locking mf_mutex in is_raw_hwpoison_page_in_hugepage() Matthew Wilcox (Oracle)
2026-08-04 6:56 ` jane.chu
2026-08-04 16:36 ` Gregory Price
2026-08-04 16:58 ` Matthew Wilcox
2026-08-04 18:47 ` Gregory Price
2026-08-04 20:32 ` jane.chu
2026-07-31 20:07 ` [PATCH v8 10/15] mm: Check individual hugetlb pages for poison Matthew Wilcox (Oracle)
2026-08-04 6:59 ` jane.chu
2026-08-04 19:15 ` Gregory Price
2026-08-04 21:21 ` Matthew Wilcox
2026-08-04 23:01 ` Gregory Price
2026-07-31 20:07 ` [PATCH v8 11/15] filemap: Add hwpoison handling to filemap_read() Matthew Wilcox (Oracle)
2026-07-31 20:07 ` [PATCH v8 12/15] filemap: Remove checks in mapping_set_folio_order_range() Matthew Wilcox (Oracle)
2026-08-04 7:01 ` jane.chu
2026-08-04 21:23 ` Gregory Price
2026-08-05 3:28 ` Matthew Wilcox
2026-07-31 20:07 ` [PATCH v8 13/15] hugetlb: Set mapping folio order Matthew Wilcox (Oracle)
2026-08-04 7:01 ` jane.chu
2026-07-31 20:07 ` [PATCH v8 14/15] filemap: Add support for authoritative mappings Matthew Wilcox (Oracle)
2026-08-04 7:02 ` jane.chu
2026-07-31 20:08 ` [PATCH v8 15/15] hugetlb: replace hugetlbfs_read_iter() with generic_file_read_iter() Matthew Wilcox (Oracle)
2026-08-04 21:26 ` Gregory Price
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=2f5fb8e1-67bb-41ec-af8f-b4da60be4583@oracle.com \
--to=jane.chu@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=christian@brauner.io \
--cc=david@kernel.org \
--cc=gourry@gourry.net \
--cc=jack@suse.cz \
--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 \
--cc=willy@infradead.org \
/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