Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp35028251rwd; Mon, 10 Jul 2023 01:14:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlG5Cy+y2BmKEvCoEF1hR6q+R6B+yVtbJwRjkoq1qdLtkFvcRL4LcZyxcuSb38Kta2kATzTU X-Received: by 2002:a05:6512:ea0:b0:4f8:752f:df48 with SMTP id bi32-20020a0565120ea000b004f8752fdf48mr11255337lfb.29.1688976876091; Mon, 10 Jul 2023 01:14:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688976876; cv=none; d=google.com; s=arc-20160816; b=DJLS6GUOj1PP9V0BEjkb7qdDzT/XWDPujkjkaFw6KcUbDRm7CuCucwJB0RV5eYI2Rs NBOGYkPFum5KHoqMu7L2vXh1z9hU7z9MzBwkSAJtjMKUi97WRUPQrY0vKz4LWil/alJn aBDQPmZ2w5wJ/v2qkNAFlFBLqyBg+h6cu7SOm9mNvC4vELe/YqG4/XJCsMddLk2eF7DI CI7ymHgvagK0eA85le1Y+se45vffZTydjPWBsSASNsexNyCMzLMLa0zgaWvXrod8ca+V 4590xM96ISjU7tRhZiymuU4/1DdGBg/HHCkXWXYCzy7ydvjtk7o6QMT9xXUO0PUCUz7z zqcQ== 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=HVMEOtNfmrAJbNlYNLeJkpBJ86lBc5FefQaiwluDrmo=; fh=E8MlcBC5QbYiVw3MLrzWaHvSDHIAwXZ/pWjBhR+9qm4=; b=c5LijW7TYMsGIda/Uj3e1hJawB7b8hoLmlVOLQUIoIQmjNpBLS64oqMSDKLnkkXRNy VVWk3joRSfUrnlQRpghJdvNV/HnDeK4b5NwtNhGI+4LicBna34C+J3xtG/a0ozU9tfeL 8+Ngj9OIHr6XV8SdYNOh//Pt6LSO3XmCCPI17Vc/G0LEQdVgk8sSMab82yWdoUftpBYW jN+PKIBxOxPHT2ndlfyig8Vvu9dIKekJrcXlk043Q49phTVzViM6a3B47h0lBE0rSVUP IQa9OZ9cAjQFsmrZmp+d9ivgC86HofnYLnmSD+PvLlhSfSQTKawBexWfcMuFDQ8T6Bmt 7mPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=H6ST3Ijv; 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 jx16-20020a170906ca5000b0098e044f3701si7716067ejb.201.2023.07.10.01.14.11; Mon, 10 Jul 2023 01:14:36 -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=H6ST3Ijv; 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 S232473AbjGJH6d (ORCPT + 99 others); Mon, 10 Jul 2023 03:58:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232326AbjGJH60 (ORCPT ); Mon, 10 Jul 2023 03:58:26 -0400 Received: from out-43.mta0.migadu.com (out-43.mta0.migadu.com [IPv6:2001:41d0:1004:224b::2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A634195 for ; Mon, 10 Jul 2023 00:58:20 -0700 (PDT) Date: Mon, 10 Jul 2023 16:58:12 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1688975897; 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=HVMEOtNfmrAJbNlYNLeJkpBJ86lBc5FefQaiwluDrmo=; b=H6ST3Ijv+TfXMWOtilgr8Ll8L0J/2ivFMLsOaSbXrc3O0IE8/Q4oBPLl/LeOy8gJB6j2lg rKzmVYnsjHynEBV836ohplSW+R3c8Tmt+9eYtN1BBcnzTbyFup7auNcjGPlXY7isKL09RU aHc1tzI1Nj1xSdtqCTLFNyTv0WgXhQE= 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: <20230710075812.GH1686200@ik1-406-35019.vs.sakura.ne.jp> References: <20230708085744.3599311-1-linmiaohe@huawei.com> <20230708085744.3599311-9-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230708085744.3599311-9-linmiaohe@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 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. Anyway, the patch looks good to me. Acked-by: Naoya Horiguchi > + if (ret > 0) { > + folio_put(folio); > + folio = page_folio(page); > + } > + } > > /* > * This check prevents from calling folio_try_get() for any > @@ -1478,8 +1484,12 @@ static int __get_unpoison_page(struct page *page) > bool hugetlb = false; > > ret = get_hwpoison_hugetlb_folio(folio, &hugetlb, true); > - if (hugetlb) > - return ret; > + if (hugetlb) { > + if (folio == page_folio(page)) > + return ret; > + if (ret > 0) > + folio_put(folio); > + } > > /* > * PageHWPoisonTakenOff pages are not only marked as PG_hwpoison, > -- > 2.33.0 > > >