Linux filesystem development
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Jane Chu <jane.chu@oracle.com>,
	linux-mm@kvack.org, Muchun Song <muchun.song@linux.dev>,
	Oscar Salvador <osalvador@suse.de>,
	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 v9 08/15] hugetlb: Use the has_hwpoisoned flag
Date: Thu, 13 Aug 2026 17:17:59 +0100	[thread overview]
Message-ID: <an3uN4TAAZ2miXhe@casper.infradead.org> (raw)
In-Reply-To: <a51a6236-8881-4479-8f04-39676e0e1f14@kernel.org>

On Thu, Aug 13, 2026 at 10:29:20AM +0200, David Hildenbrand (Arm) wrote:
> On 8/5/26 23:05, Matthew Wilcox (Oracle) wrote:
> > Other large folios use the has_hwpoisoned flag.  Convert hugetlb to match.
> > This will help us use the per-page hwpoison flag in the future.
> 
> Currently, the first thing we do in hugetlb_update_hwpoison() is:
> 
> 	int ret = folio_test_set_hwpoison(folio);
> 
> So a hugetlb folio *always* has folio_test_hwpoison() set.
> 
> So we can locklessly check whether a hugetlb folios has the flag set simply by
> ... checking whether it's a hugetlb folio and has the flag set.

You make it sound so easy ;-)

If we don't hold a reference on the folio, then the folio (whether it's
hugetlb or not) can be split.  And then folio_test_hwpoison() can hit
the assertion that it's now a tail page.

> Then you write:
> 
> "This closes a gap where a page in a previously-poisoned hugetlb folio
> could be observed to not have the hwpoison bit set."
> 
> When does the race you describe become relevant? When freeing the hugetlb folio
> or when demoting it? in both cases, we should be holding the hugetlb lock that
> nasty hwpoison code could sync with (if it doesn't already do that).

Before this patch series, we don't always hold the hugetlb lock when
splitting a hugetlb folio that contains hwpoison.  And we don't want
to have to grab the hugetlb lock if we can avoid it -- unprivileged
userspace can hammer these paths hard, and I don't want to see this
lock be contended.

> I can understand that we want something that covers both scenarios: an
> indication whether any large folio has any hwpoisoned page. Such a unification
> would be good.

Right, and after this patch, we now have that.  Any unknowing part of
the kernel can test folio_has_hwpoisoned_page() (assuming it has a
refcount on the folio).

> But then, special-casing hugetlb *again* through folio_test_huge_poison(),
> that's rather odd, no?

Oh, I'm not happy about it.  But we need an atomic way to determine if
a page belongs to a hugetlb folio with hwpoison detected.  Short of a
complete rearchitecture of how we handle hwpoison, this is the best I've
come up with.

> (what on earth is "huge_poison" is this supposed to be "hugetlb_poison" ? Why
> "poison" and not "hwpoison"? Really odd)

We're inconsistent in our naming on both of these things.  It doesn't
help that somebody decided to reuse the term "poison" to mean
"uninitialised struct page".

> I'd expect that we actually get rid of folio_test_hwpoison entirely and
> exclusively work on per-page state and has_hwpoison. But IIUC, now it's some
> mixture of folio checks, page checks, folio_has, mixed with some hugetlb oddity.

If we could get rid of HVO, we could do it entirely on struct page.
Or, as above, entirely rearchitecture hwpoison handling to not be based
around pages or folios any more.

> I am not quite clear whether the change you propose here is actually required
> for the remainder of this series?
> 
> 	[PATCH v9 00/15] Use generic_file_read_iter() in hugetlbfs
> 
> IOW, do we really need all this hugetlb hwpoison handling just to accomplish
> that, or could some of that (bigger hwpoison rework) be done separately?

Blame Sashiko!  I'm going to ignore it in future, but it's really good
at nerd-sniping "hey all of this is already broken and you could fix it
as part of this series".

> 
> > +/*
> > + * Since we cannot split a hugetlb folio, we want to insert a poison
> > + * entry into the page table for the whole folio even if only one page
> > + * is poisoned.  Otherwise, we've split down to the PTE level and we only
> > + * want to poison the precise page
> > + */
> > +static bool ttu_create_hwpoison(const struct folio *folio,
> > +		const struct page *page, enum ttu_flags flags)
> > +{
> > +	if (!(flags & TTU_HWPOISON))
> > +		return false;
> 
> Why not keep the flag in the caller? Really looks weird given that we have two
> users and one of them doesn't even need the check and must fake it.

try_to_unmap_one() is already 200 lines and contains some tricky code flow.
I'm trying to at least make the problem not-worse.  I think we should
pull out even more code into helpers, but not in this patch series.

> I also don't quite enjoy the function name, and it's likely the reason why we
> need 4 lines of doc for a simple internal helper that checks whether the thing
> (page table entry) we are unmapping/migarting is hwpoisoned. This function is
> not involved at all in any kind of splitting.

I think I was trying to pull out even more code into this function,
which was when I named it, and then I found it tricky to do so.  And
I didn't go back and change the function name.

> Some of that code is getting reworked by Dev to better separate out all the
> hugetlb oddities. At least for the try_to_unmap() path that helper will not be
> required. Staring at the abomination we call try_to_migrate_one(), I assume
> we'll do something similar.
> 
> I'd just call this "ttu_page_is_hwpoisoned()", and add a short
> 
> /*
>  * hugetlb folios are always entirely mapped, so any
>  * hwpoisoned page is problematic.
>  */

I can rename it, no problem.  I think the more verbose description is
justified though; we need to explain why we care about any page in
the folio for hugetlb, but only about the precise page for non-hugetlb.

> > @@ -2423,7 +2436,6 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma,
> >  	struct mmu_notifier_range range;
> >  	enum ttu_flags flags = (enum ttu_flags)(long)arg;
> >  	unsigned long pfn;
> > -	unsigned long hsz = 0;
> 
> While these size changes are reasonable, they make this patch harder to review
> and are not even described in the patch desription.

I suppose.  Do you want me to take them out?

  reply	other threads:[~2026-08-13 16:18 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05 21:05 [PATCH v9 00/15] Use generic_file_read_iter() in hugetlbfs Matthew Wilcox (Oracle)
2026-08-05 21:05 ` [PATCH v9 01/15] memory-failure: Fix hardware poison check in unpoison_memory() again Matthew Wilcox (Oracle)
2026-08-05 21:05 ` [PATCH v9 02/15] memory-failure: Prevent hugetlb freeing during unpoisoning Matthew Wilcox (Oracle)
2026-08-05 21:05 ` [PATCH v9 03/15] mm: Rename folio_contain_hwpoison_page() to folio_has_hwpoison_page() Matthew Wilcox (Oracle)
2026-08-13  7:20   ` David Hildenbrand (Arm)
2026-08-05 21:05 ` [PATCH v9 04/15] hugetlb: Mark some function arguments as const Matthew Wilcox (Oracle)
2026-08-05 21:05 ` [PATCH v9 05/15] guest_memfd: Use folio_has_hwpoisoned_page() Matthew Wilcox (Oracle)
2026-08-13  7:20   ` David Hildenbrand (Arm)
2026-08-13 11:50     ` Matthew Wilcox
2026-08-05 21:05 ` [PATCH v9 06/15] kpageflags: Use is_page_hwpoison() to set KPF_HWPOISON Matthew Wilcox (Oracle)
2026-08-13  7:25   ` David Hildenbrand (Arm)
2026-08-13  9:01     ` David Hildenbrand (Arm)
2026-08-05 21:05 ` [PATCH v9 07/15] hugetlb: Move poison to pages before clearing hugetlb page type Matthew Wilcox (Oracle)
2026-08-05 21:05 ` [PATCH v9 08/15] hugetlb: Use the has_hwpoisoned flag Matthew Wilcox (Oracle)
2026-08-13  8:29   ` David Hildenbrand (Arm)
2026-08-13 16:17     ` Matthew Wilcox [this message]
2026-08-13 11:12   ` Pedro Falcato
2026-08-05 21:05 ` [PATCH v9 09/15] mm: Remove locking mf_mutex in is_raw_hwpoison_page_in_hugepage() Matthew Wilcox (Oracle)
2026-08-05 21:05 ` [PATCH v9 10/15] mm: Check individual hugetlb pages for poison Matthew Wilcox (Oracle)
2026-08-05 21:05 ` [PATCH v9 11/15] filemap: Add hwpoison handling to filemap_read() Matthew Wilcox (Oracle)
2026-08-13 10:55   ` Pedro Falcato
2026-08-13 16:33     ` Matthew Wilcox
2026-08-05 21:05 ` [PATCH v9 12/15] filemap: Remove checks in mapping_set_folio_order_range() Matthew Wilcox (Oracle)
2026-08-13 11:05   ` Pedro Falcato
2026-08-05 21:05 ` [PATCH v9 13/15] hugetlb: Set mapping folio order Matthew Wilcox (Oracle)
2026-08-13 11:06   ` Pedro Falcato
2026-08-05 21:05 ` [PATCH v9 14/15] filemap: Add support for authoritative mappings Matthew Wilcox (Oracle)
2026-08-13 11:10   ` Pedro Falcato
2026-08-05 21:05 ` [PATCH v9 15/15] hugetlb: replace hugetlbfs_read_iter() with generic_file_read_iter() Matthew Wilcox (Oracle)
2026-08-13 11:10   ` Pedro Falcato
2026-08-06 19:47 ` [PATCH v9 00/15] Use generic_file_read_iter() in hugetlbfs jane.chu
2026-08-13  8:37 ` Lorenzo Stoakes (ARM)

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=an3uN4TAAZ2miXhe@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=christian@brauner.io \
    --cc=david@kernel.org \
    --cc=gourry@gourry.net \
    --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