Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4267788pxj; Wed, 12 May 2021 01:34:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3MnribF5bxJKTouYvN3KWl2Eu+/CC7G4JlcKaUD9xYHnnHT1D+p1laQwTPB/oPtUE0qxz X-Received: by 2002:a17:906:eca9:: with SMTP id qh9mr35906047ejb.258.1620808498761; Wed, 12 May 2021 01:34:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620808498; cv=none; d=google.com; s=arc-20160816; b=lCXW3U/PNllFx/k7iaEw8vpaFPaPiBmRShggFxKmzZwmn9emituU7LSOlzwG6lBlii m1hutJVTqxOe8N3j738LwxF3sQaG575TyZShv5lWQPHi8VEi7wfLsUarGtdRM8rl9+9n WVzGXFLW5kzMl/t8xcLh1bI5cgbBqHqR+o/aI/z7JIIXoA8eNYjODlvAvitHzs3/uLsG mftbCA2dDjFhlYTj4xWM51QEzS4lrxE49qRmc4WAG0j/jQil5Iw8xtpZE0cM/PcZpnBH N2Ka4zVlUwkhXva9gRiN3jbGWyy7nf9wQRZS7iRg2/WQ/8WYf0Wp4U4cWjMiS1TM8bdY g1og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=jqNKoPANwvWYMP7sF6FVmsGqS2qTNG2Z60vXQHE8Pt8=; b=bNjrZ6LhLvidPw2ugsi0n44KgMLPwvezDLJwY8X6SEeEUz4ps6eQYTxVFPRpD1qlex b9cg5n7ed/8zmDTD4m/PBwvP2Qys9fpNVC2aQQJOqyMcRUux9gHwU/52QxWHElyUEsdu CyFqT9av+vdUMbshdyu9b460OUoVLzzTqqekhcs/dCMe1zjzXQMWBiMaItck+y8ueLGF XKM3LR3PK4TewAIAC2sapepp6/DMJj4cClzubHC1DUsHTC8J0rriJjXuJS8uQ1JotbEJ SVfoTd5jF7I+AbQLlG3O2iMSxIHlVOWBOKtUcGqyJE3O01yj9awQ2ATOwYrp0KIyx5GU dV6g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i14si23267623eje.519.2021.05.12.01.34.34; Wed, 12 May 2021 01:34:58 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230424AbhELIei (ORCPT + 99 others); Wed, 12 May 2021 04:34:38 -0400 Received: from mx2.suse.de ([195.135.220.15]:59100 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230211AbhELIeh (ORCPT ); Wed, 12 May 2021 04:34:37 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DD62FAFA9; Wed, 12 May 2021 08:33:28 +0000 (UTC) Date: Wed, 12 May 2021 10:33:24 +0200 From: Oscar Salvador To: Naoya Horiguchi 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 v3 1/2] mm,hwpoison: fix race with compound page allocation Message-ID: <20210512083319.GA14726@linux> References: <20210511151016.2310627-1-nao.horiguchi@gmail.com> <20210511151016.2310627-2-nao.horiguchi@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210511151016.2310627-2-nao.horiguchi@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 12, 2021 at 12:10:15AM +0900, Naoya Horiguchi wrote: > @@ -1095,30 +1095,43 @@ static int __get_hwpoison_page(struct page *page) > { > struct page *head = compound_head(page); > > - if (!PageHuge(head) && PageTransHuge(head)) { > - /* > - * Non anonymous thp exists only in allocation/free time. We > - * can't handle such a case correctly, so let's give it up. > - * This should be better than triggering BUG_ON when kernel > - * tries to touch the "partially handled" page. > - */ > - if (!PageAnon(head)) { > - pr_err("Memory failure: %#lx: non anonymous thp\n", > - page_to_pfn(page)); > - return 0; > + if (PageCompound(page)) { > + if (PageSlab(page)) { > + return get_page_unless_zero(page); > + } else if (PageHuge(head)) { > + int ret = 0; > + > + spin_lock(&hugetlb_lock); > + if (!PageHuge(head)) > + ret = -EBUSY; > + else if (HPageFreed(head) || HPageMigratable(head)) > + ret = get_page_unless_zero(head); > + spin_unlock(&hugetlb_lock); > + return ret; Uhm, I am having a hard time with that -EBUSY. At this stage, we expect __get_hwpoison_page() to either return true or false, depending on whether it could grab a page's refcount or not. Returning -EBUSY here seems wrong (plus it is inconsistent with the comment above the function). It might be useful for the latter patch, I do not know as I yet have to check that one, but if anything, let us stay consistent here in this one. So, if hugetlb vanished under us, let us return "we could not grab the refcount". Does it make sense? -- Oscar Salvador SUSE L3