Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp372870pxj; Thu, 20 May 2021 11:16:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwT8LfXEJwEj9iDgWUjhy9Ve7dLFOJ9CSVrKTDFqOJAD95fEK/kpCgcBsnhr35bCQFcPVH X-Received: by 2002:a92:3f08:: with SMTP id m8mr6621246ila.154.1621534581941; Thu, 20 May 2021 11:16:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621534581; cv=none; d=google.com; s=arc-20160816; b=hUnLCRRm3VDQimR80J4C8NshHZ8Es3yufauBIuM4cwWTHcOG4z1zaL0YIdXOSoZWmD llovyokAsFQNQW0goPCtv7epwEjY9zknEXfD7w5xgHx0C28cUXb8eEA+qccG0SyoN9EX rSzpgZKv+T44AE4lIJo2GQxI2Lj4HPb7BYh2pHot5SNnSLnQla1li0A2NVhrzwCGfhIu CvgYxyOubQVeBu08JBe+3pdEDEGcw0rZKaO55B28GdLH8AFjt5EWnEl1fdiF5tkYWR4N PyJFdPmBn+Iq8Bd7E6rPsDVrSq/Nhfb4tgSDKrHgEz95NX8JXBxM1A0Ocg/rkDSeODig FoBg== 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=t6tiSJpF4qiU8fc01kM3dNqMxjeU9bgHyCwHM4WygwI=; b=a2wotSmrWwogQwnB5kxW5ozYEm07IlxDdGxQLIM1oTPdyYm64W1L8ldvKpgfRdbUgO 8boP90dFXtQXppslUjeDL64Dzja975UakegiNsokPF75qQ4OpUGOln4djhMofEbdQYzx JIhgKxXD7sBejiQvpyDPN1Xn5oTAXYhUnsLHJlKXpy8yAZbx/QPOsRL5Zo3bWItnvfLG tNETkN1G1igtMNO3ailDqkE4yBOLSjc5EKxb/15uOAocbNNO8/WHFFXeC6kK4Hcu1sIr 7xYHYEtvReSfz5sCVhUJcYaFIItrFhmxJFM60fz/Wo/T4sD/e1OKCEIP7eJHnLoZpkd2 5pBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=roCKixLs; 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 s16si2560602jas.113.2021.05.20.11.16.08; Thu, 20 May 2021 11:16:21 -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=roCKixLs; 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 S236396AbhETKPH (ORCPT + 99 others); Thu, 20 May 2021 06:15:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:43020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235196AbhETKIN (ORCPT ); Thu, 20 May 2021 06:08:13 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2C0EA61944; Thu, 20 May 2021 09:42:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503729; bh=w7ZMjHhsbJZU5ZRd/VHxgDcvLkD2OUDmO97ZLYgpo0A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=roCKixLslPlqnaOo6o/j6XwJesR7CICN3mYoxyrJfWI9tL/j6eURCihpMhTTT4AlI P5/E6gLvB7GaRXqZRYFF45FvGVyFVaQa3SOVto4DQQ9O9Wvk6yhp0hOIl6UL58ie3Z ELP7P5bF0qTYShzCiHxyQpbxD0K9RdGXXtVTYZTY= 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.19 353/425] mm/hugeltb: handle the error case in hugetlb_fix_reserve_counts() Date: Thu, 20 May 2021 11:22:02 +0200 Message-Id: <20210520092143.011492718@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@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 f37a821dc5ce..1dfaec50ff93 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -588,13 +588,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