Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2557559pxj; Mon, 17 May 2021 04:36:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydIf9bwW05+SK3h7iaUghQaL/aLmEvuU6JUY8UPWj3wohvGA3Dfc0J06CD2MTeqaqvPep6 X-Received: by 2002:a02:a30e:: with SMTP id q14mr56074769jai.4.1621251413362; Mon, 17 May 2021 04:36:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621251413; cv=none; d=google.com; s=arc-20160816; b=w30cSTsZPA22jHEwerbc03rIPwamvE7sLwGLiGfpt5cVcYmY9cHqjtJKo1NwvarFKA X8hIzc9cXwmN1VWaVAM8wMbIIjnauSl4OUu1ik7WZxMqzPahGG44hdT/dcUhnzx/ukkx QlH732QtYpY60bKl1tQpcxUPZXCi6yaUxohUrOG+110HQMNhtqCaIz81RmrpGymwljU6 pjCyPl7+kCX98mah1tl+bCGfx42U73LCPmBvm1xGwvzwtGJt5xxwUlPIQK608dsk1lJR 6V271mxTujz8c9Jr5giOsWksxLH53gHAzNiXRAlkSfPJdYLFKWxs1JuN4+35iblkfEWx YTIA== 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:date:dkim-signature; bh=SemXkCbow4yBXflzyDjNxahJ+Elgl4A0uyCJv5Cq9YU=; b=iudGkh8UcoeD2Pu2W+IHEPZiKA7f5pYrigbv+9KLnVfxeXOU+BYLJ1Xn90xutJOTbL hDcctOC7zKnoeKSHnHPlAImYAd2gJh0ZkL2ZOQa16kFB6aOYsazSJN3N5qqkxyaPuwKN Tnqk95nDFq/wAuUsr8PVWCjWd9lXZDLLaEvCsJaSUS4fjh7dvW4Lgu8Nj+ZYtqEwiJND 4GnuRFuBfPXUPFuE7PrSz/o8sHU89niQCCD8s1vN7AOz789dTXZtwBqBC6Jpckc+/mXs x7Y4FGbkqmPvPYGbMYul+Q5FR5A3PQ5/oIAllZ07zrMPu9jiFg0pN9WZ7Bgf/J3Z/umd KNng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DGAyxqLg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w14si16256076iom.23.2021.05.17.04.36.40; Mon, 17 May 2021 04:36:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DGAyxqLg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236782AbhEQLf0 (ORCPT + 99 others); Mon, 17 May 2021 07:35:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236741AbhEQLfZ (ORCPT ); Mon, 17 May 2021 07:35:25 -0400 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51143C061573 for ; Mon, 17 May 2021 04:34:09 -0700 (PDT) Received: by mail-pg1-x52b.google.com with SMTP id k15so4423526pgb.10 for ; Mon, 17 May 2021 04:34:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=SemXkCbow4yBXflzyDjNxahJ+Elgl4A0uyCJv5Cq9YU=; b=DGAyxqLgz3OO1MWLx8qiw1QtWW+DLDx7vUUkjOIhutGsiOt+YlE5BHfM5e21woX6cG h4BaS5ayqZ7xjC7FGxpccTNVf2+Gplw1SUXZGd1h3g+E5zezVy68TW05Hf44BDzfoYFv 3jKBAGy69n78QmAxPzyHMt027++pHWHbuoIxhwI7IFSfMRoBUx7whlOpMb63xsq+bqDV HkpE2lrrYiwnXeAqmNnQtSqaOa3XJLFcraZ6lJ8/p+zZ8bOsHPNEY8/ZTkjh4s1Wg75K gEVP49iODFG12j5B5KoBARKByHZLg5mwxrTci1dS1Ppq4AhZ2RgAl+i8eehY/OAHLO98 liHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=SemXkCbow4yBXflzyDjNxahJ+Elgl4A0uyCJv5Cq9YU=; b=BUfMLJtt7YiVaYlK4/i6fKvU7k+YfIEjl41TOmxLADhPz6vlVtSghCUCJo9d7Mz9V5 4Mi5gvu24JDtmtcqbuv62XSZfKomF6+Ns3aRyIL1y4yCzQUo6MfQxrE8d4bTeKnW9tsD nmrihyw7vHYt4ih2MXrw46vetIJ4hIOFaFuRmV1NDMqLCYj1aBqZFt6smrXr13B0UGo2 d0o0I7zN/Hsi4KQOo4gBZO50rGHWCdbq1mPjqDmpuksEcR4I6qLfFy3nVYvhCzX2hmsa Fqqa97JgP/JKjzN7UZBm1xozbh2KqNjBZiqWERW4bMFsOMEthAlL6PoowWGLeFFgwErN 8HNg== X-Gm-Message-State: AOAM533YUtT5vuBALdt0ZwqIvNrgDUYIFCXUZvyDPyjWRGLXEGGjD7UC L+jY+j0tBA1E4Y6ctuKTUw== X-Received: by 2002:a63:6c9:: with SMTP id 192mr4922117pgg.39.1621251248820; Mon, 17 May 2021 04:34:08 -0700 (PDT) Received: from u2004 (h175-177-040-153.catv02.itscom.jp. [175.177.40.153]) by smtp.gmail.com with ESMTPSA id i7sm1351944pgv.93.2021.05.17.04.34.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 04:34:08 -0700 (PDT) Date: Mon, 17 May 2021 20:34:05 +0900 From: Naoya Horiguchi To: Oscar Salvador Cc: Muchun Song , linux-mm@kvack.org, Andrew Morton , Mike Kravetz , Michal Hocko , Tony Luck , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 1/2] mm,hwpoison: fix race with compound page allocation Message-ID: <20210517113405.GA2512538@u2004> References: <20210517045401.2506032-1-nao.horiguchi@gmail.com> <20210517045401.2506032-2-nao.horiguchi@gmail.com> <20210517101239.GA21612@linux> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210517101239.GA21612@linux> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 17, 2021 at 12:12:50PM +0200, Oscar Salvador wrote: > On Mon, May 17, 2021 at 01:54:00PM +0900, Naoya Horiguchi wrote: > > From: Naoya Horiguchi > > > > When hugetlb page fault (under overcommitting situation) and > > memory_failure() race, VM_BUG_ON_PAGE() is triggered by the following race: > > > > CPU0: CPU1: > > > > gather_surplus_pages() > > page = alloc_surplus_huge_page() > > memory_failure_hugetlb() > > get_hwpoison_page(page) > > __get_hwpoison_page(page) > > get_page_unless_zero(page) > > zero = put_page_testzero(page) > > VM_BUG_ON_PAGE(!zero, page) > > enqueue_huge_page(h, page) > > put_page(page) > > > > __get_hwpoison_page() only checks page refcount before taking additional > ^^ the? ^^ an > > one for memory error handling, which is wrong because there's a time > > window where compound pages have non-zero refcount during initialization. > > > > So makes __get_hwpoison_page() check page status a bit more for a few > ^^ make > > types of compound pages. PageSlab() check is added because otherwise > > "non anonymous thp" path is wrongly chosen. > > This is no longer true with this patch, is it? What happened here? Sorry, we need remove this. I dropped the changes for PageSlab because I'm still not sure about what to do (I'd like to do it in a separate work). > > > static int __get_hwpoison_page(struct page *page) > > { > > struct page *head = compound_head(page); > > + int ret = 0; > > + > > +#ifdef CONFIG_HUGETLB_PAGE > > + spin_lock(&hugetlb_lock); > > + if (PageHuge(head) && (HPageFreed(head) || HPageMigratable(head))) > > + ret = get_page_unless_zero(head); > > + spin_unlock(&hugetlb_lock); > > + if (ret > 0) > > + return ret; > > +#endif > > I am kind of fine with this, but I wonder whether it makes sense to hide this > details into helper (with an empty stub for non-hugetlb pages)? OK, I will do this. > > > if (!PageHuge(head) && PageTransHuge(head)) { > This !PageHuge could go? I'll update this, too. Thanks, Naoya Horiguchi