Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp558335pxj; Thu, 20 May 2021 16:11:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzILjq/ys26sZk9OXWd/GS4PIfQuL0VieBHvyNMFA4a8VgjWaXpSm2ZYSlHJ+PKwyTBfGjX X-Received: by 2002:a50:fb0a:: with SMTP id d10mr7367386edq.47.1621552299561; Thu, 20 May 2021 16:11:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621552299; cv=none; d=google.com; s=arc-20160816; b=UJMQVKmJ6Mj1LAXGOhJU2mGEr2maZkpR99ArtGEUExiuE14POlvm4yCmU1Gy/9xEcW wqRFBGJt/pwkRFEAQ9XPHKSqO4HAPsWKw5D2J+4T28IXWSWcvTOAutC7xsWZhgUFC90c +Viz1h2KLPBV26RbsaPFD1wD/bl99QWIDyWVjXJ02V5kl/H04KjNOhWpo/0l+QWQgWqA 2Bc99gv7G1GrdiJ/kQLSTMPaPcRINWparhm+Wz4fLDmrPpT7yPNXklJX+fNU0GEzO2cO jkc7SmOWr5PMcSdVstoOTE4KdX9uzxGaqU7j8sg+BIIFkZyLcCUbj1MljIf9GfLU/xoR WuBg== 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=X/68JERvhVsp90yoBMAFD5SBlJp0Qgevd2vkqoHSnEc=; b=C+p5T1xgQrqMl1jL0bnDUMG1G2hpd4bxHpcGD2YZtni1AsHEzIBcrQxIrXFtG/DcMZ BLKBt7E78GqD6dLtcMKw4uO7RDNWzv0PQkqU3waf8RS7bpAieh8s0fCFpp55XmiplFQo VGXj9K/VKyagzwxo43YewJGIeTQL0CyeABFFLXQ4JcKJ2GLlb7PlkyVa8LZIVV0M3JJN CYy0uBcuXz1wU8XOgtpbfOkFRpQyj+J+QNEnS/NRf/DC4bsGWzvm0aJXtjlX1S9LmDlm wNdzKneqtIz4YiW9tlXsU0wcUR+XZsz1gr5Y+E6ZeohevWO7b6+XfRo3p5CdVqaDbT6j 3Lrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uHaAFacJ; 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 i11si3764990edc.325.2021.05.20.16.11.16; Thu, 20 May 2021 16:11:39 -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=uHaAFacJ; 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 S241189AbhETLXS (ORCPT + 99 others); Thu, 20 May 2021 07:23:18 -0400 Received: from mail.kernel.org ([198.145.29.99]:59128 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239300AbhETLDD (ORCPT ); Thu, 20 May 2021 07:03:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7D51761D2C; Thu, 20 May 2021 10:04:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621505055; bh=8OQj5p3y3B1QGSdoqzyGs4Hfl3t+mA/SsXXk5jSOApg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uHaAFacJZsX8dWIa8RPUEUhC2M9zlUtBD8ZwAfj1x3RKNxgvV1z+w+OrfJfGXC3qZ Kcy1e3/n5j0Ip4+zKIVqPFdawwgE6hYoDcS8+c9Z4DLEFhbA2mk8vsOZ+xBJQW3E/l cfuUspjEEskIZC9RGHHp23ywCVT7dVRhtXrPBlKY= 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.9 202/240] mm/hugeltb: handle the error case in hugetlb_fix_reserve_counts() Date: Thu, 20 May 2021 11:23:14 +0200 Message-Id: <20210520092115.441531656@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092108.587553970@linuxfoundation.org> References: <20210520092108.587553970@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 e2b5e38e7a4b..9049e8613237 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -586,13 +586,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