From: Muchun Song <songmuchun@bytedance.com>
To: Miaohe Lin <linmiaohe@huawei.com>
Cc: Linux-MM <linux-mm@kvack.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Mike Kravetz <mike.kravetz@oracle.com>,
Naoya Horiguchi <naoya.horiguchi@linux.dev>
Subject: Re: [bug report] mm, hwpoison: memory_failure races with alloc_fresh_huge_page/free_huge_page
Date: Tue, 2 Aug 2022 12:07:00 +0800 [thread overview]
Message-ID: <Yuii5FnAXe/q7fx/@FVFYT0MHHV2J> (raw)
In-Reply-To: <3c542543-0965-ef60-4627-1a4116077a5b@huawei.com>
On Tue, Aug 02, 2022 at 10:00:50AM +0800, Miaohe Lin wrote:
> Hi all:
> When I investigate the mm/memory-failure.c code again, I found there's a possible race window
> between memory_failure and alloc_fresh_huge_page/free_huge_page. Thank about the below scene:
>
> CPU 1 CPU 2
> alloc_fresh_huge_page -- page refcnt > 0 memory_failure
> prep_new_huge_page get_huge_page_for_hwpoison
> !PageHeadHuge -- so 2(not a hugepage) is returned
> hugetlb_vmemmap_optimize -- subpages is read-only
> set_compound_page_dtor -- PageHuge is true now, but too late!!!
> TestSetPageHWPoison(p)
> -- We might write to read-only subpages here!!!
>
> Another similar scene:
>
> CPU 1 CPU 2
> free_huge_page -- page refcnt == 0 and not PageHuge memory_failure
> get_huge_page_for_hwpoison
> !PageHeadHuge -- so 2(not a hugepage) is returned
> TestSetPageHWPoison(p)
> -- We might write to read-only subpages here!!!
> hugetlb_vmemmap_restore -- subpages can be written to now, but too late!!!
>
I agree this race is possible, I have proposed this race in thread [1].
But I didn't think more how to solve it.
[1] https://lore.kernel.org/linux-mm/20220623235153.2623702-1-naoya.horiguchi@linux.dev/T/#ma094a7cea7df8fd9a77a91551bf39077d89e23bd
> I think the above scenes are possible. But I can't found a stable solution to fix it. Any suggestions?
> Or is it not worth to fix it as it's too rare? Or am I miss something?
>
Luckily, the system will panic at once, which encountering this race. However,
we don't see any bug report. If we have an easy way to fix it, I think it is worth.
Just a quick reply, no suggestion/solutions from me.
Thanks.
> Any response would be appreciated!
>
> Thanks!
>
next prev parent reply other threads:[~2022-08-02 4:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-02 2:00 [bug report] mm, hwpoison: memory_failure races with alloc_fresh_huge_page/free_huge_page Miaohe Lin
2022-08-02 4:07 ` Muchun Song [this message]
2022-08-02 6:27 ` Miaohe Lin
2022-08-04 7:40 ` Naoya Horiguchi
2022-08-04 7:44 ` Naoya Horiguchi
2022-08-05 2:33 ` Miaohe Lin
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=Yuii5FnAXe/q7fx/@FVFYT0MHHV2J \
--to=songmuchun@bytedance.com \
--cc=akpm@linux-foundation.org \
--cc=linmiaohe@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=naoya.horiguchi@linux.dev \
/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;
as well as URLs for NNTP newsgroup(s).