From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AE27EB64DA for ; Mon, 10 Jul 2023 08:59:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231965AbjGJI7W (ORCPT ); Mon, 10 Jul 2023 04:59:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229493AbjGJI7R (ORCPT ); Mon, 10 Jul 2023 04:59:17 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6015C3 for ; Mon, 10 Jul 2023 01:59:15 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QzyXZ1hN1ztR8c; Mon, 10 Jul 2023 16:56:14 +0800 (CST) Received: from [10.174.151.185] (10.174.151.185) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 10 Jul 2023 16:59:10 +0800 Subject: Re: [PATCH 8/8] mm: memory-failure: fix race window when trying to get hugetlb folio To: Naoya Horiguchi CC: , , , References: <20230708085744.3599311-1-linmiaohe@huawei.com> <20230708085744.3599311-9-linmiaohe@huawei.com> <20230710075812.GH1686200@ik1-406-35019.vs.sakura.ne.jp> <74acb109-76cc-3990-c770-8330e343ef54@huawei.com> <20230710083925.GA1754785@ik1-406-35019.vs.sakura.ne.jp> From: Miaohe Lin Message-ID: <147fb145-1289-4526-862e-0cb63c9711e0@huawei.com> Date: Mon, 10 Jul 2023 16:59:10 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20230710083925.GA1754785@ik1-406-35019.vs.sakura.ne.jp> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.151.185] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/7/10 16:39, Naoya Horiguchi wrote: > On Mon, Jul 10, 2023 at 04:32:27PM +0800, Miaohe Lin wrote: >> On 2023/7/10 15:58, Naoya Horiguchi wrote: >>> On Sat, Jul 08, 2023 at 04:57:44PM +0800, Miaohe Lin wrote: >>>> page_folio() is fetched before calling get_hwpoison_hugetlb_folio() >>>> without hugetlb_lock being held. So hugetlb page could be demoted >>>> before get_hwpoison_hugetlb_folio() holding hugetlb_lock but after >>>> page_folio() is fetched. So get_hwpoison_hugetlb_folio() will hold >>>> unexpected extra refcnt of hugetlb folio while leaving demoted page >>>> un-refcnted. >>> >>> Very nice, thank you for finding the issue. >>> >>>> >>>> Fixes: 25182f05ffed ("mm,hwpoison: fix race with hugetlb page allocation") >>>> Signed-off-by: Miaohe Lin >>>> --- >>>> mm/memory-failure.c | 18 ++++++++++++++---- >>>> 1 file changed, 14 insertions(+), 4 deletions(-) >>>> >>>> diff --git a/mm/memory-failure.c b/mm/memory-failure.c >>>> index 76d88d27cdbe..066bf57f2d22 100644 >>>> --- a/mm/memory-failure.c >>>> +++ b/mm/memory-failure.c >>>> @@ -1388,8 +1388,14 @@ static int __get_hwpoison_page(struct page *page, unsigned long flags) >>>> bool hugetlb = false; >>>> >>>> ret = get_hwpoison_hugetlb_folio(folio, &hugetlb, false); >>>> - if (hugetlb) >>>> - return ret; >>>> + if (hugetlb) { >>>> + if (folio == page_folio(page)) >>>> + return ret; >>> >>> Some short comment about the race against demotion here is helpful. >> >> Does the below comment makes sense to you? >> >> " >> Make sure hugetlb demotion did not happen from under us. >> " > > Yes, this sounds fine. Will do it in v2. Thanks. > > Thanks, > Naoya Horiguchi > > . >