Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp35097611rwd; Mon, 10 Jul 2023 02:28:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlHB1NcYXmGdObSnQ2KVv11DrsY0mkaFrChB4QSqj/aeYLt5q2Rg6vyEJGY3pK9puC1zwB61 X-Received: by 2002:a05:620a:2809:b0:767:a9ec:5417 with SMTP id f9-20020a05620a280900b00767a9ec5417mr10657998qkp.69.1688981338636; Mon, 10 Jul 2023 02:28:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688981338; cv=none; d=google.com; s=arc-20160816; b=kGu2HHYVTkTit4NmF/aPPXuAEjh1AwKIZ6XtCNoICMloH3/nszTtkdXm9KloScZBl4 68rGvEcXN/i/FeQJ3ZwQJkKzLMTRVuLXPIqXI93wz2ksbFjAnl6RekAl4xOqof5LH9Kv PmxdiMreHOLWed8G3xu/qU4wN7Z6ruNgLWCqXkzHuW/S6CKjPXtkR3VA9JhJ/Z8o+6ys 0Jw2j5zq+nPdmbX+6aVOxh9ZBerKjIZTbt/v8yMru9u/qSn0awfN2Oiza8N8YdR++NuK Rc+X5zzv8U43BrbYQTzJvOMxeGcQMk2bRJRqN2PSFcrYfwmRJ9XseM1xta8C6v+ahDA8 txDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=5Mbc1vx3AzfxzMQH9xxT7mc7wMXv9RGjwMKx8cQLYH4=; fh=n/uFFHpsFa62ZufDN5OP0hBfmwzblShQmk2j2eA0Bnc=; b=P+la1xnUcRJUIEkXrdyOzdvhwU+S72giRV4Ajr1WFIDsOXi5uPK/ThMFnMc/i1gBfm GRSvV3VhQzLftmIZ0YsjxGGDJqYuxopASfDWP0RwihHElIzJOywxn2rgRhUTgvQBZ7/C nisyRr0FvAgLEeQtepXa0EFutxxxxBvyB3Gw38PG54E7eMZUdibzeAwuUl/kgagcH18P wWXlE3q0LB4ahbd8TBPdUDFqYZh3XxChVmHS9ldbTE0XwjpayWuXSGc5Um+fZsDBigfM csZ/3fUxfI4KZLavNqNDIW8XmNsBQ++MYKalvdrKde/DHaJ5wEb+l0Nk4QyQTZpGeMQd KjXg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o11-20020a056a001bcb00b0066d93ab678asi8592006pfw.16.2023.07.10.02.28.46; Mon, 10 Jul 2023 02:28:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231435AbjGJI7S (ORCPT + 99 others); Mon, 10 Jul 2023 04:59:18 -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 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 > > . >