Skip to content

Commit

Permalink
mm/hugeltb: handle the error case in hugetlb_fix_reserve_counts()
Browse files Browse the repository at this point in the history
[ Upstream commit da56388 ]

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: b5cec28 ("hugetlbfs: truncate_hugepages() takes a range of pages")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Cc: Feilong Lin <linfeilong@huawei.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
MiaoheLin authored and gregkh committed May 19, 2021
1 parent 22349c1 commit ed98b88
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions mm/hugetlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

/*
Expand Down

0 comments on commit ed98b88

Please sign in to comment.