From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D543EC433EF for ; Tue, 8 Mar 2022 13:43:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19F1C8D0002; Tue, 8 Mar 2022 08:43:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 14D048D0001; Tue, 8 Mar 2022 08:43:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03B7E8D0002; Tue, 8 Mar 2022 08:43:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0228.hostedemail.com [216.40.44.228]) by kanga.kvack.org (Postfix) with ESMTP id E6E0C8D0001 for ; Tue, 8 Mar 2022 08:43:53 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A4AB2AA17B for ; Tue, 8 Mar 2022 13:43:53 +0000 (UTC) X-FDA: 79221337146.18.290DB81 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf22.hostedemail.com (Postfix) with ESMTP id B0B9BC0013 for ; Tue, 8 Mar 2022 13:43:52 +0000 (UTC) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4KCc1t73BrzBrPS; Tue, 8 Mar 2022 21:41:54 +0800 (CST) Received: from [10.174.177.76] (10.174.177.76) 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.2308.21; Tue, 8 Mar 2022 21:43:49 +0800 Subject: Re: [PATCH] hugetlb: do not demote poisoned hugetlb pages To: Mike Kravetz , , CC: HORIGUCHI NAOYA , Oscar Salvador , Michal Hocko , Andrew Morton , References: <20220307215707.50916-1-mike.kravetz@oracle.com> From: Miaohe Lin Message-ID: <6ba788b3-901e-d740-2575-bc652461187b@huawei.com> Date: Tue, 8 Mar 2022 21:43:48 +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: <20220307215707.50916-1-mike.kravetz@oracle.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.76] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B0B9BC0013 X-Stat-Signature: kb3i5ty1pg61rrpa6nb5bw7io8psecmr Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspam-User: X-HE-Tag: 1646747032-883112 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2022/3/8 5:57, Mike Kravetz wrote: > It is possible for poisoned hugetlb pages to reside on the free lists. > The huge page allocation routines which dequeue entries from the free > lists make a point of avoiding poisoned pages. There is no such check > and avoidance in the demote code path. > > If a hugetlb page on the is on a free list, poison will only be set in > the head page rather then the page with the actual error. If such a > page is demoted, then the poison flag may follow the wrong page. A page > without error could have poison set, and a page with poison could not > have the flag set. > > Check for poison before attempting to demote a hugetlb page. Also, > return -EBUSY to the caller if only poisoned pages are on the free list. > > Fixes: 8531fc6f52f5 ("hugetlb: add hugetlb demote page support") > Signed-off-by: Mike Kravetz > Cc: > --- > mm/hugetlb.c | 17 ++++++++++------- > 1 file changed, 10 insertions(+), 7 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index b34f50156f7e..f8ca7cca3c1a 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -3475,7 +3475,6 @@ static int demote_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed) > { > int nr_nodes, node; > struct page *page; > - int rc = 0; > > lockdep_assert_held(&hugetlb_lock); > > @@ -3486,15 +3485,19 @@ static int demote_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed) > } > > for_each_node_mask_to_free(h, nr_nodes, node, nodes_allowed) { > - if (!list_empty(&h->hugepage_freelists[node])) { > - page = list_entry(h->hugepage_freelists[node].next, > - struct page, lru); > - rc = demote_free_huge_page(h, page); > - break; > + list_for_each_entry(page, &h->hugepage_freelists[node], lru) { > + if (PageHWPoison(page)) > + continue; > + > + return demote_free_huge_page(h, page); It seems this patch is not ideal. Memory failure can hit the hugetlb page anytime without holding the hugetlb_lock. So the page might become HWPoison just after the check. But this patch should have handled the common case. Many thanks for your work. :) > } > } > > - return rc; > + /* > + * Only way to get here is if all pages on free lists are poisoned. > + * Return -EBUSY so that caller will not retry. > + */ > + return -EBUSY; > } > > #define HSTATE_ATTR_RO(_name) \ >