mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Miaohe Lin <linmiaohe@huawei.com>
To: Mani Tofigh <mt4022@columbia.edu>
Cc: David Hildenbrand <david@kernel.org>,
	Naoya Horiguchi <nao.horiguchi@gmail.com>,
	Kiryl Shutsemau <kas@kernel.org>, Mike Rapoport <rppt@kernel.org>,
	Mike Kravetz <mike.kravetz@oracle.com>,
	Matthew Wilcox <willy@infradead.org>, <linux-mm@kvack.org>,
	<linux-kernel@vger.kernel.org>, <tz2294@columbia.edu>,
	<stable@vger.kernel.org>, Muchun Song <muchun.song@linux.dev>,
	Oscar Salvador <osalvador@suse.de>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH v3] mm/memory-failure: set PG_hwpoison of a non-hugetlb page under hugetlb_lock
Date: Tue, 17 Nov 2026 15:01:23 +0800	[thread overview]
Message-ID: <b0f30561-aabf-2bf5-2204-20907c40ef43@huawei.com> (raw)
In-Reply-To: <a87cbd92-0e07-4f84-9a6f-8db0b1778fcf@columbia.edu>

On 2026/11/12 7:21, Mani Tofigh wrote:
> On 11/9/26 2:23 AM, Miaohe Lin wrote:
>> I have no idea why the error on P itself is ignored, could you explain that?
> 
> 
> My bad, I should have explained that.  By then P is part of a hugetlb
> folio that's still free or being set up, so get_hwpoison_page() can't
> take it and we just end with "Ignored".  Nothing marks the folio, so
> the bad page goes back to the pool and gets handed out later.

I see. Thanks for explaining.

> 
> If the folio is already in use it's even worse... it gets split as a
> THP and hangs.  (That's a different race though, I'll send a separate fix for that soon.)
>> I think we should clear the PageHWPoison flag we just set since the retry path expects
>> we have cleared the PageHWPoison flag in the first round.
> 
> 
> Agreed, as long as the page still isn't hugetlb.  Once it is, HVO may
> have remapped its struct page, so the clear either hits the shared tail
> page (read-only on e.g. 6.6) or gets lost while HVO copies the first
> vmemmap page.

In both cases, will the hwpoison flag be lost? If so, would TestClearPageHWPoison work?

> 
> So how about clearing it under hugetlb_lock only if the page still isn't
> hugetlb, and otherwise skipping the retry like the second round does?

If the page becomes hugetlb, should we skip the retry path? try_memory_failure_hugetlb
can't handle this case?

> 
>> I suspect this won’t solve the problem. The below race might still exist:
>>
>>    Task A (memory_failure)              Task B (nr_hugepages write)
>>    get_huge_page_for_hwpoison()         alloc_fresh_hugetlb_folio()
>>      /* P not hugetlb */                  /* P becomes a tail page */
>>    clear_non_hugetlb_hwpoison
>>    goto retry
>>    get_huge_page_for_hwpoison()
>>      /* P not hugetlb */
>>                      __folio_set_hugetlb
>>                                           hugetlb_vmemmap_optimize_folio()
>>                                             /* P's struct page now in
>>                                                the shared tail page */
>>    TestSetPageHWPoison(P)
> 
> 
> I think that one's covered.  With the patch, the "not hugetlb" check and
> TestSetPageHWPoison() are under the same hugetlb_lock, and
> __folio_set_hugetlb() moves under hugetlb_lock too, before HVO.  So A
> either sees P as hugetlb, or the flag lands in P's OWN struct page
> before HVO gets to it.
> 
> Also, with Muchun's vmemmap_remap_rwsem [1] HVO waits for
> get_huge_page_for_hwpoison() anyway, so if his series goes in first the
> hugetlb.c part can go.

Yes, this should fix the race.

Thanks.
.


      reply	other threads:[~2026-11-17  7:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06 16:09 Mani Tofigh via B4 Relay
2026-11-06 22:39 ` Andrew Morton
2026-11-09 11:29   ` Miaohe Lin
2026-11-09  7:23 ` Miaohe Lin
2026-11-11 23:21   ` Mani Tofigh
2026-11-17  7:01     ` Miaohe Lin [this message]

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=b0f30561-aabf-2bf5-2204-20907c40ef43@huawei.com \
    --to=linmiaohe@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=kas@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=mt4022@columbia.edu \
    --cc=muchun.song@linux.dev \
    --cc=nao.horiguchi@gmail.com \
    --cc=osalvador@suse.de \
    --cc=rppt@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=tz2294@columbia.edu \
    --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

all inboxes | Powered by JetHome®