From: Miaohe Lin <linmiaohe@huawei.com>
To: Mike Kravetz <mike.kravetz@oracle.com>,
Naoya Horiguchi <naoya.horiguchi@linux.dev>, <linux-mm@kvack.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Yang Shi <shy828301@gmail.com>,
Dan Carpenter <dan.carpenter@oracle.com>,
Naoya Horiguchi <naoya.horiguchi@nec.com>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v8 1/3] mm/hwpoison: fix race between hugetlb free/demotion and memory_failure_hugetlb()
Date: Fri, 15 Apr 2022 09:55:14 +0800 [thread overview]
Message-ID: <20e677e5-01aa-f8c0-0ce1-bf33da58b7ec@huawei.com> (raw)
In-Reply-To: <5b665bcd-57f8-85ae-b0c4-c055875dbfff@oracle.com>
On 2022/4/15 1:56, Mike Kravetz wrote:
> On 4/8/22 06:53, Naoya Horiguchi wrote:
>> From: Naoya Horiguchi <naoya.horiguchi@nec.com>
>>
>> There is a race condition between memory_failure_hugetlb() and hugetlb
>> free/demotion, which causes setting PageHWPoison flag on the wrong page.
>> The one simple result is that wrong processes can be killed, but another
>> (more serious) one is that the actual error is left unhandled, so no one
>> prevents later access to it, and that might lead to more serious results
>> like consuming corrupted data.
>>
>> Think about the below race window:
>>
>> CPU 1 CPU 2
>> memory_failure_hugetlb
>> struct page *head = compound_head(p);
>> hugetlb page might be freed to
>> buddy, or even changed to another
>> compound page.
>>
>> get_hwpoison_page -- page is not what we want now...
>>
>> The current code first does prechecks roughly and then reconfirms
>> after taking refcount, but it's found that it makes code overly
>> complicated, so move the prechecks in a single hugetlb_lock range.
>>
>> A newly introduced function, try_memory_failure_hugetlb(), always
>> takes hugetlb_lock (even for non-hugetlb pages). That can be
>> improved, but memory_failure() is rare in principle, so should
>> not be a big problem.
...
>
> The above code works as designed, but may be a bit confusing. If HPageFreed()
> we KNOW ref count is zero, so no need to even call get_page_unless_zero() as
> it will always return false in this case. It might be more clear if written
> as separate else if statements such as:
>
> } else if (HPageFreed(head)) {
> ret = 0;
> } else if (HPageMigratable(head)) {
> ret = get_page_unless_zero(head);
> if (ret)
> count_increased = true;
>
This code here is consistent with the logic in get_hwpoison_huge_page. If change is required,
they might need to be changed together.
BTW: They look a bit confusing for me at first but I get used to it later. ;)
Thanks!
> Not insisting this be changed. Just easier to understand IMO.
>
> Again, thanks for your work on this!
>
> Reviewed-by: Mike Kravetz <mike.kravetz@oracle.com>
>
next prev parent reply other threads:[~2022-04-15 1:55 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-08 13:53 [PATCH v8 0/3] " Naoya Horiguchi
2022-04-08 13:53 ` [PATCH v8 1/3] " Naoya Horiguchi
2022-04-09 2:33 ` Miaohe Lin
2022-04-14 17:56 ` Mike Kravetz
2022-04-15 1:55 ` Miaohe Lin [this message]
2022-04-15 2:12 ` HORIGUCHI NAOYA(堀口 直也)
2022-04-15 4:18 ` [PATCH 4/3] mm, hugetlb, hwpoison: separate branch for free and in-use hugepage Naoya Horiguchi
2022-04-15 15:11 ` Mike Kravetz
2022-04-16 1:06 ` Miaohe Lin
2022-04-08 13:53 ` [PATCH v8 2/3] mm/hwpoison: put page in already hwpoisoned case with MF_COUNT_INCREASED Naoya Horiguchi
2022-04-09 2:04 ` Miaohe Lin
2022-04-14 19:41 ` Mike Kravetz
2022-04-08 13:53 ` [PATCH v8 3/3] Revert "mm/memory-failure.c: fix race with changing page compound again" Naoya Horiguchi
2022-04-09 2:07 ` Miaohe Lin
2022-04-14 17:59 ` Mike Kravetz
2022-04-08 23:47 ` [PATCH v8 0/3] mm/hwpoison: fix race between hugetlb free/demotion and memory_failure_hugetlb() Andrew Morton
2022-04-09 2:31 ` Naoya Horiguchi
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=20e677e5-01aa-f8c0-0ce1-bf33da58b7ec@huawei.com \
--to=linmiaohe@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=dan.carpenter@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mike.kravetz@oracle.com \
--cc=naoya.horiguchi@linux.dev \
--cc=naoya.horiguchi@nec.com \
--cc=shy828301@gmail.com \
/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