Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp3520443pxb; Tue, 19 Apr 2022 04:35:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzGE11SLdJwFjndBQXlqBNlgWYewUhs1J6WGGp3pwB/ytTJjnd8OzVSoQ539eZHD3JyX+9U X-Received: by 2002:a17:90a:70cf:b0:1cb:a31e:a2c1 with SMTP id a15-20020a17090a70cf00b001cba31ea2c1mr23782620pjm.94.1650368149926; Tue, 19 Apr 2022 04:35:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650368149; cv=none; d=google.com; s=arc-20160816; b=ccMfGfo/xGL8d2c2KNa3u70nyF796MFHaIVaqfQ5AF9ldVeb9qO4BxP9VgA5KiSwX5 tqL1hJu5XoIL3iwJHTHtQhkwPYQetzAqCrP2TRMgEF8gtuWKTZAkbeen08ILQiij3Pp+ 0HfjgbKuTm8szQqANsaIDFPf+ysGedfEVBhoqnLi1eGMrZh/GE9goG1sJBTjIC94L0iM UuM1xOKVt1hFPHRoDh2+wQxRFers7I4WPiLKg7MMadqLcoabmHSQbPd8vSaMUNnf70s+ O6PAE3ZkacJs64Eu8fcncWLWyo36qvEdjBu2SUQEp9Dq/JTVhkEbDv9YJALjIGW8Ilu+ 5Xfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3GmnwD1tS/jjgdUnZvNVNxq2ePYhyueKbMdTu/pu7Gw=; b=srfh3y/ESqwjD7K652fEdL+LlA1i4sGNIZ9ExTCcCk77JWyuXcmubsMaY3LS76S48G GPTBdVjfhpKPOEMTIfVD7e2Bu/x4VJL4Y5uwf48aUHQwuAiCWwVbsI06U/vFz8nQMlVm J5ns9jOe98TH8dWr64vC29jveo2E42GG4EK3VhDcXXXywolb1q+gzQz2QiSOtwX4thRo W5sBwiUAmg9Nr2qiQaoZGhxGDnU/5hsLSPZvwK/4YjIGYPGHv39t6BQo6FDlmH7Y9wNW XQSt7n4FGQaAjofdC5iKqX/ouh3oHyQdKjDB/H4r8lhi/5h3c6g5s+q1JGnvvnYljxGH 3ddQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YomlO909; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nv16-20020a17090b1b5000b001cb7cda1a79si2380198pjb.148.2022.04.19.04.35.35; Tue, 19 Apr 2022 04:35:49 -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=@linuxfoundation.org header.s=korg header.b=YomlO909; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231859AbiDRMmB (ORCPT + 99 others); Mon, 18 Apr 2022 08:42:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239780AbiDRMd2 (ORCPT ); Mon, 18 Apr 2022 08:33:28 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43AE41B791; Mon, 18 Apr 2022 05:26:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id F3A02B80EC4; Mon, 18 Apr 2022 12:26:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CCC8C385AC; Mon, 18 Apr 2022 12:26:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650284761; bh=k6ThlEZYjczdMB9/EZpDeNWEqo0mO1axpTlVDPr7w40=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YomlO909fTkxBsXEGFURv73+xDGVTFoBI/zenJMOuveQPiDVKXKV3tLM7Qa4fnwWL +K7YNFpD4utCMeIDFrFyyAyVqCS4j+hyswu1hNsV1SLekUCP+7qNQebid68S/FZwdP pr0y5Vc4GTQD2aqDgI2bOwR4tp+g3ssyz+Tm3r3w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mike Kravetz , Naoya Horiguchi , Andrew Morton , Linus Torvalds Subject: [PATCH 5.17 179/219] hugetlb: do not demote poisoned hugetlb pages Date: Mon, 18 Apr 2022 14:12:28 +0200 Message-Id: <20220418121211.887283123@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121203.462784814@linuxfoundation.org> References: <20220418121203.462784814@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 From: Mike Kravetz commit 5a317412ef884763fdf7aa17f9f3636959d11d8f upstream. 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. Link: https://lkml.kernel.org/r/20220307215707.50916-1-mike.kravetz@oracle.com Fixes: 8531fc6f52f5 ("hugetlb: add hugetlb demote page support") Signed-off-by: Mike Kravetz Reviewed-by: Naoya Horiguchi Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/hugetlb.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3469,7 +3469,6 @@ static int demote_pool_huge_page(struct { int nr_nodes, node; struct page *page; - int rc = 0; lockdep_assert_held(&hugetlb_lock); @@ -3480,15 +3479,19 @@ static int demote_pool_huge_page(struct } 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); } } - 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) \