Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3114875pxj; Mon, 17 May 2021 18:09:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWs+BdnNZBZmL/HkGOJasydOizZwZW3Om60iUcx+XcqBBc/uuPS3CVs162MhLQRBzlwk0d X-Received: by 2002:a17:906:a245:: with SMTP id bi5mr3219404ejb.316.1621300157724; Mon, 17 May 2021 18:09:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621300157; cv=none; d=google.com; s=arc-20160816; b=T7zN8NCSNQBAsJF6bHhasr8ttw2bym6S18TEIBQkwxyzJm6QWObh9Hy8QKKHIv6jnA ekZieGd4+pAFiFyt1JKNJUY0dyfejV38p4yRl/I8Ap0BIRUb2XnRo5N4QIUku0WHImSl yXVpMjb1/0f3R+DlJc/ZNzKMBl4+p7MM+74Kr3Pvb1H6plbV1/OCGr4UkSFjnfmbw+D+ S7r9ybm0/M2NGxICOkpxAZIeRRqtClSVoydIt350JRAH4PRaaoNDi5nEchM9AgpxFVP4 lJSaAoY/HreaRiR5F53qqzcDRcT5ZpSiyr75d7+2D6ghNH2wqOTESIfiFjsjbA+Q8IOh Z8iw== 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=QvXW5l0u+Fu5ZuqZGDLrFYcEUAGt16fFeFxTqkxlY0Y=; b=dRqC/PKDiT+ggIe+oCQznzb5YzYW4OH5bVtKQNqBr+qUEIrGT13MfTWxQfAKDs1Lhg d+qI3w/gk3f5Rtx4IAcY95d9fBq6cPU/1Ys9r0m5bqXQduz3nxsPULwbZT7juKv/+r83 mbW1VBs6BIliG5CKuQUB1bnCKo2JWYe31LK/800nHJBAaPP7UxM2rZ698twvnw3QGDAS lZMUB9na5nZ81M7bOFD3ojdpkLNFHT60yf+SlDkBBX1Qp41k7s6HxVmbUYNM6kI/vo6N d+N0Q1f5kATvJ9pnzpPRRc4A3Zswg+Ly6Uqcg8CriJaXFqlPNd1+rlogzXx+CJ9g3S2Q 9Jwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GUuOECKw; 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 gn42si9931574ejc.93.2021.05.17.18.08.55; Mon, 17 May 2021 18:09:17 -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=GUuOECKw; 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 S238827AbhEQOa6 (ORCPT + 99 others); Mon, 17 May 2021 10:30:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:53812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239313AbhEQO0T (ORCPT ); Mon, 17 May 2021 10:26:19 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 15D5D61370; Mon, 17 May 2021 14:13:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621260819; bh=mXSug0opPzVPqY03uBx2QOIAMKoolaKxgQOtlakyozw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GUuOECKwsNjq+Ky1Hzzl7wS4/NuglRrhxnbmTlOCIT1Wqul3Gqr0lNlaPtFJ1BR2B +t0gjBdFGKjPZacUQsJgAm5qrgYnYSLtT4DgAudvPOzXzr+f2vmiCMmCHMmPe4TWPX Q8YpBN3or4cgktmTam5CKX8Y/mXXWWIp1sEhS/YY= 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.12 218/363] mm/hugeltb: handle the error case in hugetlb_fix_reserve_counts() Date: Mon, 17 May 2021 16:01:24 +0200 Message-Id: <20210517140309.959339564@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140302.508966430@linuxfoundation.org> References: <20210517140302.508966430@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 a86a58ef132d..cb253c8e55cc 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -743,13 +743,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