Re: [PATCH v7 01/13] memory-failure: Fix hardware poison check in unpoison_memory() again
Miaohe Lin <[email protected]>
| Newsgroups | org.kernel.vger.linux-fsdevel,org.kernel.vger.stable,org.kvack.linux-mm |
|---|---|
| Message-ID | <[email protected]> |
On 2026/7/29 9:43, Matthew Wilcox wrote:
> On Tue, Jul 28, 2026 at 08:39:29PM -0400, Gregory Price wrote:
>> On Tue, Jul 28, 2026 at 09:43:53PM +0100, Matthew Wilcox (Oracle) wrote:
>>> The earlier patch (6c54312f9689) that attempted to fix unpoison_memory()
>>> was incorrect for hugetlb folios. Before a6fddef49eef, we checked
>>> the head page for poison (which was correct for hugetlb and incorrect
>>> for THP). We are currently incapable of unpoisoning pages (other than
>>> the first page) in a hugetlb folio.
>>>
>>> Use is_page_hwpoison() which handles hugetlb pages sufficiently well for
>>> this purpose. This is racy as we don't have a reference on the folio at
>>> this point, but fixing that properly requires deeper surgery and this
>>> is a CAP_SYS_ADMIN path only so this will do for the moment and can be
>>> easily backported. It's no worse than the situation before a6fddef49eef.
>>>
>>> The other bug in a6fddef49eef is that we currently clear the HWPoison
>>> flag on the precise page, which is wrong for hugetlb. Fix that too.
>>>
>>> Fixes: a6fddef49eef ("mm/memory-failure: convert unpoison_memory() to folios")
>>> Cc: [email protected]
>>> Cc: Miaohe Lin <[email protected]>
>>> Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
>>
>> Just trying to wrap my head around the state before/after, assuming
>> the following is correct then LGTM:
>>
>> prior:
>> pfn_to_online_page(pfn) -> p = precise page
>> PageHWPoison(page) -> checks precise page. Poison for hugetlb
>> is only set only on the head, so bug.
>> after:
>> is_page_hwpoison(page) -> checks precise page AND head (if hugetlb)
>> p = folio->page -> now TestClearPageHWPoison() explicitly
>> clears the head page poison if hugetlb
>
> Exactly. That was how it worked before a6fddef49eef; it used to do
> p = compound_head(p) (which wasn't great _either_ but had different
> problems ...)
>
> The careful reader will observe that injecting two memory failures
> into the same hugetlb causes ... problems. That's true before and after
Could you elaborate on what problems this might cause? IIUC, second memory
failure on the same hugetlb folio will make try_memory_failure_hugetlb() return
-EHWPOISON without holding another refcnt. Raw error pages will be added to
raw_hwp_page list. Then in unpoison_memory(), raw_hwp_page list will be cleaned
and extra refcnt held by memory_failure will be released and PageHWPoison will be
cleared. So it looks work to me. Or am I miss something?
Reviewed-by: Miaohe Lin <[email protected]>
Thanks.
.