Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp35058544rwd; Mon, 10 Jul 2023 01:49:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlGOGqEJqRXXz7Uv8hrHYtU24coTNkD6+uhoEV4coHRXhLo9vj13VkPhXODSrF0/+5jNM9P/ X-Received: by 2002:a17:906:20e:b0:992:8a4a:6811 with SMTP id 14-20020a170906020e00b009928a4a6811mr13830665ejd.15.1688978964873; Mon, 10 Jul 2023 01:49:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688978964; cv=none; d=google.com; s=arc-20160816; b=KjE+03W/+M4EF67e8OPH1oOuxokAa62IU3b1xaATLVvKBuyE9KNTWryDJohQWPEsOj 5ux+wVlwL6XuBxt/47ol3e99oH/9SVo4ItDv4o6MNPCgUxDm0B29kTI0g1rHVcnkLk4N r46GANzPbQtM2ldvv3WD7K5t3eYZgvOrGfytVmgLx7KrFd+O4bR5kiXjgXg/GciO2wY/ qTbEVtEwanX9NlSEeD4NmQq5cOK+09XXHFAYfCjob+qwLbHDgb+2Nsvc8DKJw9PeBNsm Ak/LY5znnvWUdTsFgcDEZeQvmc4cydTHkm93jajtjiGnBeN2Sq/j3EGXs0CX3C7VmEXK IgAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=f3AhQNodXj38q0A4RJMgjfTCHYaDaMVujsrqc1ZOwT4=; fh=E8MlcBC5QbYiVw3MLrzWaHvSDHIAwXZ/pWjBhR+9qm4=; b=iJvQXWIhoV2ChapmfOQM/UxzN7GLWCWUXVZTIyduxYP9PJ0kHZsJEMizXQXkOgBSXq fzc+bdDQ8JRfNLlRknveBcF3yleF7nHRRJKzd+EcSmf1fpspGrvpJvWaLVYxPv/JqC+y WFJQu7Lk16DiTifnwWivSz31AGvUZPiwvd0XbGCIJR2CCrTldJS1mb7jdNLAe2Iv2mgg z8sucbx9+/64lRIUnG+JCb3eeG4iiMNQJ40aHp/hTWqB+VMPsfgkainbiHXhFi6SbVLO 7p+6iSrUCI0QY1511+cHdFi/c3vDZhK0dAu3nVhTktoHxiIdVaz2gCyb+ekpFNfWB7Sz 3WjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=Ivy1al2D; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id se22-20020a170906ce5600b0099351214a94si5643956ejb.648.2023.07.10.01.49.00; Mon, 10 Jul 2023 01:49:24 -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; dkim=pass header.i=@linux.dev header.s=key1 header.b=Ivy1al2D; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233053AbjGJIkc (ORCPT + 99 others); Mon, 10 Jul 2023 04:40:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231834AbjGJIj5 (ORCPT ); Mon, 10 Jul 2023 04:39:57 -0400 Received: from out-52.mta1.migadu.com (out-52.mta1.migadu.com [95.215.58.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69D91183 for ; Mon, 10 Jul 2023 01:39:33 -0700 (PDT) Date: Mon, 10 Jul 2023 17:39:25 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1688978370; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=f3AhQNodXj38q0A4RJMgjfTCHYaDaMVujsrqc1ZOwT4=; b=Ivy1al2D4UEgWZb/o3Qwc8na2ZmkWAjPPgynJKnr1n14TTFft8HSXdG5HwtEARWFytVMeV vj1GhVkawKDFxLDfNOkqtEnk/h9Al6altFXc/6idFD4ZxUcaM2urhxtHK+SLYgPT+l9wwv RG9hXNY8ink+ZItRSNAgXsr617cRE+w= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Naoya Horiguchi To: Miaohe Lin Cc: akpm@linux-foundation.org, naoya.horiguchi@nec.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 8/8] mm: memory-failure: fix race window when trying to get hugetlb folio Message-ID: <20230710083925.GA1754785@ik1-406-35019.vs.sakura.ne.jp> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <74acb109-76cc-3990-c770-8330e343ef54@huawei.com> X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 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. Thanks, Naoya Horiguchi