Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp498603pxj; Tue, 18 May 2021 08:04:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpVexqzAKPGynA6/63SYQ4tVMiOSmEiwO8Z9aa2E/4RkTkf/k0Xa6ocvB5UobU5bSlxoNQ X-Received: by 2002:a05:6602:158a:: with SMTP id e10mr4410892iow.137.1621350281976; Tue, 18 May 2021 08:04:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621350281; cv=none; d=google.com; s=arc-20160816; b=CqBibNJl47Qj/fbLpoo5ZXnJXQfZ7HldCw0WEGEnsptWLO79L9womBscSKBdjCNkvo OPjKaJQ96vNLXOfMM3G2T65VY4H8Qfv9QwFD4dFRdPXHqJnDqvhWFF78wt42OAntJrfF 7jRHqAwuJmCOBU4m0QDiHDGokhH7XpkWSR0UdUKNvt2h/XE5QwbmtDOrA0Ivdfh62voU PPmPTp5WfoUgyV38Hdo9vWas76cYQ0gZb4mOWEzyQrD2iXRT/YBMO7QWeTpI/4CFDFjw Hushzf7fiDo6DDaMyDkPkocO76SK9Oyai7O233lV2I8Y43TDmH867fkkWZ5h1ifqVXdk mPDQ== 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=dnfizv6z4Ly/IJbppkTljU7NjeJgU+sFecOsJ0mM8/M=; b=kxRIlJiQNkMglCu7ZHkCw/ASYyDT0z2WMQd7SZ50a7W9dNB9ktHxQ4p1EfP5L02GvO z8LosSsqEIYzLOfcjkV3Rkawv2kztjP0osXiEXxeqJu9czUygdyu6FAqCfF7OGiRaq+x pEI8DCE+rJgzkj09KGfDSne97zf0D5LkvqG0KfZRheQJYO33Nn+QtEQd8qVxQUlpy2qw jqpBrtArVPdhzMZZIGNqHMupzdJcafBeyX9UM9ws9yyyjjOCv6+l6X9K4UcSNx0uvlhC gsQ2XmxCy1lqz+z7VfzKRMPKEUJFLncwuMvt/dUO3b/sw8I8kzrBLsXdN2DUTAAmnq/Q uCUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YOSqNB6i; 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 p17si325487jas.72.2021.05.18.08.04.27; Tue, 18 May 2021 08:04:41 -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=YOSqNB6i; 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 S243116AbhEQPvK (ORCPT + 99 others); Mon, 17 May 2021 11:51:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:39260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243370AbhEQPeG (ORCPT ); Mon, 17 May 2021 11:34:06 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0D41C61CD5; Mon, 17 May 2021 14:39:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262352; bh=zlwl3RE4NCCA1eFtQw8KakoyzJR5WJUgQ+CVONCrWpc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YOSqNB6iAF5Lwhuv8gweiMESDoav7y2ZvWAfEEJJKWz92pK51IzzOYnV+4zf9Ooao N/SJfnbf8PMn6tdNnxJcYDAKVmnI3qBgjb4MbHi6AB1f77R8fZTOwT/nkqJ1OWRthM +Spu+qrZnZLXDhlr67mDA9shQ6hs0W/bmMvXPOJo= 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 5.10 167/289] mm/hugeltb: handle the error case in hugetlb_fix_reserve_counts() Date: Mon, 17 May 2021 16:01:32 +0200 Message-Id: <20210517140310.748965962@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@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 573f1a0183be..900851a4f914 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -745,13 +745,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