Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp32763pxj; Thu, 20 May 2021 03:57:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweyyyOfp/5+uUuzMUWcAFHQTiX2vsGG6xztYgD5aIWdzWNb9JYr9lFMZA5smctNoaLBIFV X-Received: by 2002:a17:906:4b19:: with SMTP id y25mr4221561eju.49.1621508262162; Thu, 20 May 2021 03:57:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621508262; cv=none; d=google.com; s=arc-20160816; b=J3j8n4O4nDt/NnqwiTqomC0NeaEDzwtWlofkpHwTWq8ByfLZ8pBH5cugWMSR5QORQ4 ZtZHUz43gH2opH0jnYDxv9WXK88RyKt22yQkgyAck2gXLafCCXwA/RfhXbk1iuMjwLqX mDj3NMveUnJ35TcUYt4h/e/4UMo2WMM+wUr+OUYVEf7zDgTN78/gsL15JvYXxpUQkmW1 wDsVipFlNsvt89Ur78j2DVukTLWIEZyIykjnMUUOPk5aJX820RxViKHln/5MN4c08opO AyzLka7/qaFsEwa4gXZH1Dbke+mlMetlI/Mt5l/FOc6zSftoErj4TlOoPJ+UqNjAIHF1 h8IQ== 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=2+dNOcgGlM4cS2952+xkQUlmfB+BGPjjYsB9NPMk9ng=; b=WJdkNSDNWRFc1tsRmu9Hq7QMdQe0CNdrdU8jZfWnOGloRMeb8nfdsadGQZhcf0+0HT pbzTZaZ0c450MqD4hEBKvxf5TsOBLRS+b3qo+P7r7+rbLZfHpaxLZiO212cQn9nRtdYo kqHSJagk6fOItMAwoja27RbnEkqoN7ct+waflaw1fuWpMtMcBOPSvFi7pOjoBpXUZhSG bV/LZ9N+aSVpi2YvfS4g9HpQXlwgqJ4dMjWcCkth4EA/N87CQnUS4wmDgLu7YWJEcvlZ AMqMVkPGcAXXiH15qnB33Co7vEZkwZzvmZADcRzfKLygKipXYm2Tt4ZdthqWywOZt5Z+ zIQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YKxJfttG; 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=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j26si1851125edq.225.2021.05.20.03.57.11; Thu, 20 May 2021 03:57:42 -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=@linuxfoundation.org header.s=korg header.b=YKxJfttG; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238670AbhETKyM (ORCPT + 99 others); Thu, 20 May 2021 06:54:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:39654 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237720AbhETKil (ORCPT ); Thu, 20 May 2021 06:38:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DA59D61C79; Thu, 20 May 2021 09:54:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504497; bh=MmVAgyYqHDI2wWDlWO1LQ2t08By/1j+dK10i4ZJa9Kg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YKxJfttG6EQEfsDXzfWdvGi71xxjmheCHzS07M7iYLSICEpMRJpQGBSt157QUSaq2 pJoyHsfla1PWD3hD3XkuCCUtXMn3I6aoEQHawYV2qkHOX0hX18UGLLjBjWXTeli4Ip b/mcLIktu2E+2Mz0ViyOI7sLlYTSbdCRvcfYSrtc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Miaohe Lin , Feilong Lin , Mike Kravetz , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 4.14 271/323] mm/hugeltb: handle the error case in hugetlb_fix_reserve_counts() Date: Thu, 20 May 2021 11:22:43 +0200 Message-Id: <20210520092129.517462862@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miaohe Lin [ Upstream commit da56388c4397878a65b74f7fe97760f5aa7d316b ] A rare out of memory error would prevent removal of the reserve map region for a page. hugetlb_fix_reserve_counts() handles this rare case to avoid dangling with incorrect counts. Unfortunately, hugepage_subpool_get_pages and hugetlb_acct_memory could possibly fail too. We should correctly handle these cases. Link: https://lkml.kernel.org/r/20210410072348.20437-5-linmiaohe@huawei.com Fixes: b5cec28d36f5 ("hugetlbfs: truncate_hugepages() takes a range of pages") Signed-off-by: Miaohe Lin Cc: Feilong Lin Cc: Mike Kravetz Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/hugetlb.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 0f6959961f9a..777ad49dbd46 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -589,13 +589,20 @@ void hugetlb_fix_reserve_counts(struct inode *inode) { struct hugepage_subpool *spool = subpool_inode(inode); long rsv_adjust; + bool reserved = false; rsv_adjust = hugepage_subpool_get_pages(spool, 1); - if (rsv_adjust) { + if (rsv_adjust > 0) { struct hstate *h = hstate_inode(inode); - hugetlb_acct_memory(h, 1); + if (!hugetlb_acct_memory(h, 1)) + reserved = true; + } else if (!rsv_adjust) { + reserved = true; } + + if (!reserved) + pr_warn("hugetlb: Huge Page Reserved count may go negative.\n"); } /* -- 2.30.2