From patchwork Wed Aug 30 00:45:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Yznaga X-Patchwork-Id: 13369870 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 B00F3C6FA8F for ; Wed, 30 Aug 2023 00:46:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1040D8E003E; Tue, 29 Aug 2023 20:46:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B4C78E000B; Tue, 29 Aug 2023 20:46:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBDDF8E003E; Tue, 29 Aug 2023 20:46:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DBB6C8E000B for ; Tue, 29 Aug 2023 20:46:06 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 74269140381 for ; Wed, 30 Aug 2023 00:46:06 +0000 (UTC) X-FDA: 81178929132.01.842C0F2 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf10.hostedemail.com (Postfix) with ESMTP id 848E9C0008 for ; Wed, 30 Aug 2023 00:46:04 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b="HF/9BymV"; dmarc=pass (policy=none) header.from=oracle.com; spf=pass (imf10.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693356364; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=PhGhyYE8rmDQgefAGYRE87G5qSJoJ4aDuH/NIUFX7f4=; b=jK5y+nVWYbjowgKp7RIbvIKOkYymo8KbKBrEfb43v8lnc2nZQwNRLZWDBkQgrpEzSKAHBr GwBnmjoVn8YmizSaYwPHzn91xYUJaAEp8EMG29p8qz6P4ijRopEPY8oVW7K9RjLQaZw7YM YfdtWg1pY+VdTrkFh43pY8QCY6p8HIQ= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-03-30 header.b="HF/9BymV"; dmarc=pass (policy=none) header.from=oracle.com; spf=pass (imf10.hostedemail.com: domain of anthony.yznaga@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=anthony.yznaga@oracle.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693356364; a=rsa-sha256; cv=none; b=8WKkGYCL/aU2/HhZUW7IGU6w+2ShnNt3ddjC9hvvtLjAzozizbcWgkAV4vfrcn/MLA9zWW kwtadfnd58eHhFI9HLZxcxMZhshrTiZeJcWnR+4I568oHPlCE3fUKUmPyJX4ShJG+JSs0n Prvim1w+MED1/jcdooXxBRJujIu2Qkw= Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37TNdYmW016406; Wed, 30 Aug 2023 00:45:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=PhGhyYE8rmDQgefAGYRE87G5qSJoJ4aDuH/NIUFX7f4=; b=HF/9BymVSG3hRuoIsfY6qWq8Q1SpEA/ZAuF7LYD3c2/9oIQttJFPIEo9aDGZHIq2pUgy YyQHZGzMVLMJqlL2qoe29l6jm3Kv5VzzODf+MybM7LquzhDUtt9vVdeZdhb36KKVsbU6 EPnOovz081O+CgWqtOpAJFGJwbsgInsSf1ERLvpAOGLQ/kjnwSutX1les9kjCxkivH/n ojbjYhhfkXPCaTqqUMq++LKf3mC0qIurqupc3aBZk5+zAt9x54C7g5/tbYp1Sc9dnSLa ziBW3Ozry9omgwvtnec+th4GQWKFxrrrUsIWD1KTTZ6TX4q+42o9zoF4Sr2t43ZG8zTw WA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3sq9xt6aea-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Aug 2023 00:45:52 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 37TMguDG037459; Wed, 30 Aug 2023 00:45:51 GMT Received: from localhost.us.oracle.com (dhcp-10-65-180-98.vpn.oracle.com [10.65.180.98]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3sr6mnvyk1-1; Wed, 30 Aug 2023 00:45:51 +0000 From: Anthony Yznaga To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, 0x7f454c46@gmail.com, bgeffon@google.com Subject: [PATCH] mm/mremap: fix unaccount of memory on vma_merge() failure Date: Tue, 29 Aug 2023 17:45:49 -0700 Message-Id: <20230830004549.16131-1-anthony.yznaga@oracle.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-29_16,2023-08-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=860 phishscore=0 suspectscore=0 spamscore=0 bulkscore=0 malwarescore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2308300005 X-Proofpoint-ORIG-GUID: -fY7Djomw6iorEFyRNUJoiX52HsYwb2C X-Proofpoint-GUID: -fY7Djomw6iorEFyRNUJoiX52HsYwb2C X-Rspam-User: X-Stat-Signature: wuuyg3dtckatr67nh3hyj3p5ktuxrsno X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 848E9C0008 X-HE-Tag: 1693356364-395973 X-HE-Meta: U2FsdGVkX18iYPzOMZWJ0HVWSBpyXMCNsl1mCw/nXmkdEzDzZUP4n9JJrBKZqY8aonjKRyty9lTkU0PPGsETCLzwgpqxwhEUoE0c0nEDyVVPtu1CO6VHB7/foj7A0PGUoYrJqH+qFEyBf56b6nNvddlyM6Ok1vVRswPLDeXHO71hkjMKEb972uFw4zGZHn2m6Y/DLoat4Ad3E68TZX0d80vBTwZXIZbvaVbE12asBmp6flue8jezfE3XBWpwMa1q+n9RG/8a62UYiEEx2UIRSg0b0LV103FDt7fNmtgxAfyTkyMK5hqYecHpqAih2kxLcpBtnQEv+vP1ARxVoxPBoUba9UO6CjVateXiriZKjW4QH0BxnGNUILt921jETUW4bS4m8bX8G1mNq2ccYZbq9gPr+YF9UF+vV2THcZkH45wHEbhhzXiHt2TNoY/0ZrcDLfTBSon2ObGoAeujdpmMojSZVgqiKOU5oGxwSHIqhBeOOF7itAli70vVAWySEqRmuz23HGy8GkLkV6JSWDkj5f7TpvGymCN/4RJisO1/HBpx6z7Ih0Y6JIu3Rqy/cESBhRDXqDZ1fQtWL7wfSIyC2fc+MVMVbiQQ2qnhZtCD1ZRRt2XibRTYSMdtGbBBJDa0BLlLipJffThBq7zBoDTCIK4SLm9EiQopGpZmn0WVJOudNv9PPE0WegTi5Jbu/IfJvzLJeK0bvYdrNwZ/LwznQSgQZ9sz4+vIdNUG+tun+JpeDFCvpi7ahOWmH88om3PcgD46chjDYa7sHqt9xUerNb4kbvmJDYtyZMy8Jz2J5doESINyKsENalhSymVXUlodInSLPU0sL8dF0NajKt+0RHg3eSJzFMxRVVA+WZQ/a37eCQrZ0RjH/MHA/QcKyDNO5OYzzCPA48B7n7xMlO1rUtMajUVnkYW6E4aMt2RSJKjH/feqXZGWqhkHsnoQUh3BARW8zV0Rp3qG+iDoPmm 7bUCwcN6 ccqtGonvs0oGHV6l7P1qltvhZK+8TR0413Aci1VqLpU6ABnavK2TSE+O/8LJyLPAZ1O2XTN6nbZlpUNM208ekMw4uMKy/G30XK0omO388V2MxYmPYYKrDD5XhXfhHynjfOKk7cay4y0VK86hoU2cAcjHNt2yf0CRUGQdUoKopUiioxrglIKVqJC4VH8zsel7Sm8DyZXcRy8rSmn6vxzzj0hzyvaXAIiwFXQT0T5077Z/EN4uwSPi8hj4B7gYPisiv7Q/4Jm3Salofn1tM2nnAQPXB38VrQaEj8cDeqp/is/UqEoniCeKoZ+oH2Ek52flC8HCXOCHyrX4VNbRKi3LImQx5hw== 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: Fix mremap so that only accounted memory is unaccounted if the mapping is expandable but vma_merge() fails. Fixes: fdbef6149135 ("mm/mremap: don't account pages in vma_to_resize()") Signed-off-by: Anthony Yznaga Acked-by: Brian Geffon --- mm/mremap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/mremap.c b/mm/mremap.c index 056478c106ee..07cdb04d4ab5 100644 --- a/mm/mremap.c +++ b/mm/mremap.c @@ -1037,12 +1037,14 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len, pgoff_t extension_pgoff = vma->vm_pgoff + ((extension_start - vma->vm_start) >> PAGE_SHIFT); VMA_ITERATOR(vmi, mm, extension_start); + long charged = 0; if (vma->vm_flags & VM_ACCOUNT) { if (security_vm_enough_memory_mm(mm, pages)) { ret = -ENOMEM; goto out; } + charged = pages; } /* @@ -1058,7 +1060,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len, vma->vm_file, extension_pgoff, vma_policy(vma), vma->vm_userfaultfd_ctx, anon_vma_name(vma)); if (!vma) { - vm_unacct_memory(pages); + vm_unacct_memory(charged); ret = -ENOMEM; goto out; }