From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0568C32789 for ; Tue, 23 Aug 2022 03:02:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 518CF8D0005; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A0CA8D0006; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D8AD8D0005; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 160A98D0001 for ; Mon, 22 Aug 2022 23:02:41 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E56078135F for ; Tue, 23 Aug 2022 03:02:40 +0000 (UTC) X-FDA: 79829359680.23.4313702 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf27.hostedemail.com (Postfix) with ESMTP id 4ADCE4000F for ; Tue, 23 Aug 2022 03:02:40 +0000 (UTC) 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: 8bit Content-Type: text/plain 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661223760; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kqkn5SxGMf5GwNIiPFaKP+kjkG9eONWj7GoENs/VlYc=; b=Nmen5lG6WuGKVQqow+6rYldyYh1LSFQ8mtumQPn9W8UkcgovoejCYKnNIwWV3kIdE5eXOk ZOoDEmwNOjrQ9RBiSEIqus6goyPEUtiu7HVe6kxDkrYDjTd20rskykwknBGgVOOqKnhW/j ee9xp9qy6v7RuIfKxcpVK1kKrg0sKg8= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661223760; a=rsa-sha256; cv=none; b=012Ukdp6OheawWZknvO/y/SYRiUP312jUCz8xSr/WZn8jAqF4meZ34+TMS5kdJ/VnPNbED JBoqehyQr1E9D/Bxv1szd26bpKsCyv448//09l3D63QecwFiSGs9L8SiXVyMP/5ArEMWUe H40RmjA7L+bb7sHPpzZBg81GMCAD5/M= X-Rspamd-Queue-Id: 4ADCE4000F X-Rspam-User: Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf27.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspamd-Server: rspam03 X-Stat-Signature: 4aeayixcwakd33zxmhr5ufwui855smqq X-HE-Tag: 1661223760-113217 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 *mm, if (idx >= size) goto out; -retry: new_page = false; page = 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 = 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 == -EEXIST) - goto retry; goto out; } new_pagecache_page = true; -- 2.23.0