Re: [PATCH v9 08/15] hugetlb: Use the has_hwpoisoned flag
"David Hildenbrand (Arm)" <[email protected]>
| Newsgroups | org.kernel.vger.linux-fsdevel,org.kvack.linux-mm |
|---|---|
| Message-ID | <[email protected]> |
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.
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).
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.
But then, special-casing hugetlb *again* through folio_test_huge_poison(),
that's rather odd, no?
(what on earth is "huge_poison" is this supposed to be "hugetlb_poison" ? Why
"poison" and not "hwpoison"? Really odd)
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.
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?
[...]
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -1978,6 +1978,22 @@ static inline unsigned int folio_unmap_pte_batch(struct folio *folio,
> FPB_RESPECT_WRITE | FPB_RESPECT_SOFT_DIRTY);
> }
>
> +/*
> + * 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.
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.
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.
*/
> + if (folio_test_hugetlb(folio))
> + return folio_test_has_hwpoisoned(folio);
> + return PageHWPoison(page);
> +}
> +
> /*
> * @arg: enum ttu_flags will be passed to this argument
> */
> @@ -1993,7 +2009,6 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma,
> enum ttu_flags flags = (enum ttu_flags)(long)arg;
> unsigned long nr_pages = 1, end_addr;
> unsigned long pfn;
[...]
> dec_mm_counter(mm, mm_counter(folio));
> set_pte_at(mm, address, pvmw.pte, pteval);
> @@ -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.
--
Cheers,
David