From nobody Wed Apr 8 07:48:55 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FD6FC28D13 for ; Tue, 23 Aug 2022 03:05:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239914AbiHWDFB (ORCPT ); Mon, 22 Aug 2022 23:05:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239809AbiHWDEL (ORCPT ); Mon, 22 Aug 2022 23:04:11 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D43F5D0E5 for ; Mon, 22 Aug 2022 20:02:58 -0700 (PDT) Received: from canpemm500002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MBYq04wSszlWRv; Tue, 23 Aug 2022 10:59:24 +0800 (CST) Received: from huawei.com (10.175.124.27) by canpemm500002.china.huawei.com (7.192.104.244) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 23 Aug 2022 11:02:36 +0800 From: Miaohe Lin To: , , CC: , , , Subject: [PATCH v2 3/6] mm/hugetlb: fix missing call to restore_reserve_on_error() Date: Tue, 23 Aug 2022 11:02:06 +0800 Message-ID: <20220823030209.57434-4-linmiaohe@huawei.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20220823030209.57434-1-linmiaohe@huawei.com> References: <20220823030209.57434-1-linmiaohe@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To canpemm500002.china.huawei.com (7.192.104.244) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When huge_add_to_page_cache() fails, the page is freed directly without calling restore_reserve_on_error() to restore reserve for newly allocated pages not in page cache. Fix this by calling restore_reserve_on_error() when huge_add_to_page_cache fails. Signed-off-by: Miaohe Lin --- mm/hugetlb.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index d46dfe5ba62c..8e62da153c64 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5576,7 +5576,6 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *m= m, if (idx >=3D size) goto out; =20 -retry: new_page =3D false; page =3D find_lock_page(mapping, idx); if (!page) { @@ -5616,9 +5615,15 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *= mm, if (vma->vm_flags & VM_MAYSHARE) { int err =3D huge_add_to_page_cache(page, mapping, idx); if (err) { + /* + * err can't be -EEXIST which implies someone + * else consumed the reservation since hugetlb + * fault mutex is held when add a hugetlb page + * to the page cache. So it's safe to call + * restore_reserve_on_error() here. + */ + restore_reserve_on_error(h, vma, haddr, page); put_page(page); - if (err =3D=3D -EEXIST) - goto retry; goto out; } new_pagecache_page =3D true; --=20 2.23.0