From patchwork Tue Aug 20 23:57:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 13770676 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 CDD08C5320E for ; Tue, 20 Aug 2024 23:58:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57CB16B00B2; Tue, 20 Aug 2024 19:58:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F4D16B00B4; Tue, 20 Aug 2024 19:58:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AE5B6B00B3; Tue, 20 Aug 2024 19:58:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id EB3086B00B0 for ; Tue, 20 Aug 2024 19:58:33 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A64EC16065B for ; Tue, 20 Aug 2024 23:58:33 +0000 (UTC) X-FDA: 82474290906.20.E4E060C Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf02.hostedemail.com (Postfix) with ESMTP id 5E9D28001B for ; Tue, 20 Aug 2024 23:58:30 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=iKKYPDuV; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=LmA1o+xd; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf02.hostedemail.com: domain of liam.howlett@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=liam.howlett@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724198231; 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:dkim-signature; bh=mYzjgcT0Ns/K/MAg9MEWqBBmmk3U8iiO2h1IDlSxUIc=; b=PwVetmi9WpHpvHcyjygGcvF1my7IZHOEJXQVVKE09o9zYTYGAKTzs670+XyVeLo/IMHq4B NQFHiDSgjbRHdxVHzOblgMtPbOBdmrDMMz84jGhRSL5J2y0hqh8QKE2gFHCcm8JacpHRow wwV3m/DG/DzZ4944vK2eyeEKJd8pZXU= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724198231; a=rsa-sha256; cv=pass; b=ktUadQvqjOONgbrbR0pRSIfln/p1D4w5tlb/G1ccJM7WbzAAAkfMHJYD4OfzebksiQMQK1 dBRMLEz5HzxvRnfhIP7S86pWtKfWvh3YaqvXPdSeCDxwL8U4sAr6uCkd6RfIdWH3xtyHXn WShe1whML8LOtj9oLb1lD7pl6Iv8xiU= ARC-Authentication-Results: i=2; imf02.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=iKKYPDuV; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=LmA1o+xd; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf02.hostedemail.com: domain of liam.howlett@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=liam.howlett@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47KMBa8x017785; Tue, 20 Aug 2024 23:58:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=mYzjgcT0Ns/K/MAg9MEWqBBmmk3U8iiO2h1IDlSxUIc=; b= iKKYPDuVUh/iY5ThywtPK9elkPNQ7oyKpg2ni8+6i0uvR4g8YD6hPg2bfSTO5Cop EeXgNMu3U4/U36AjlEfUkyo8OZDESOa7QgaIrzKaS7mSLOqCP/3ubQL+d6pzpafH yjYH8GCLcOXMN++gFsTQEOJCC0FAuOQ0xT00ej0WJALbRSggr3TxtcysbMXbzycc WxeTr9/q1iS9gbd+zldVW/qfgJiIlfKQTn//j5tTvO8a2fjPe4OMlwHN12flq42b hCF7cvjeKdco0flqQNDuAsjC2klD3FiZXw6lfYCYXn3zFp1qS3HnZa2VcqoualFq i8ASFdJrW71OiR8b7YiNUA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412mdsxagv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Aug 2024 23:58:22 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 47KNY1IL023382; Tue, 20 Aug 2024 23:58:21 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2173.outbound.protection.outlook.com [104.47.58.173]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4154x78g2k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Aug 2024 23:58:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=x9oFZESBAcTYwvBCqdW/klrXpPA46IM5jSm6LdtIFVOGTAGX7FBJFksbbdXTrUBbsJOFhoZjxSAML9S3uHLQ3GECv8QYGE42NDNLJD31bY7lDNvhFRkthZJVtshPtWJuYeRPYqEmbhIZ1OZZc9orNjybEHFtgrKdClQPv+hMrGkfGN9yhFJkjt9JgS+6FGXOKgVTfkbAhFyZbNia978uGvWxDnJtWykWcBwe6OTASxDpMa2vEjwX7ELEZNfMUg2Y4KtNxHoUOSzaPiP1KeNQ1kk1nQSHP8egUeLNTvyVwB3K9tYHeI7QmGueZrC93tUxlcX/VXSPbuP5VVjqIaXI3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mYzjgcT0Ns/K/MAg9MEWqBBmmk3U8iiO2h1IDlSxUIc=; b=AbPLGEi7Sp3ha9QiBJ/SX3vIVhq1pwrS6y1z/dD2ER3/GM1ci9y3zxg6QgID6IDtaA/VfJyYjZY2F3B+HLSrAL4BztfckuK/IX1j+dSxoRE1Vf6BROmrq6AM3CNeMLEXlNdyUSaJ4XKjD3SLMR04x3AmpXW2igJP3TVmRbDvrd/OTzm11ePGVWVfR1sEKbRXvXSjIuVUInh3QBzydAF5Fz5y/sJ3fyRn6lqg+9Cu0h63vhQwrGfH42xr0ZvQsRGRqgcOxUpTXTUW49hqLR/g0hQjkZFoU+xibXP+aAmob9OyWu55a1W2XO4yC+iCB+2CTnWid/lFehqqc/vzMwgBdA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mYzjgcT0Ns/K/MAg9MEWqBBmmk3U8iiO2h1IDlSxUIc=; b=LmA1o+xdRRBQSOapHA91momzxQgrJLUZtN5a0VaSc9OfBrs9MB9XcIX4ldyZKBmvMJaKIic0C9A4kyPbVot3i71/GECykuhyVMOOLyLJno+526hYgUjoLWeBb+dJgt+X9JBSzrpDMRZMH9Z8koJwLAhQNfy6+jUIhZsxCEegdCU= Received: from DS0PR10MB7933.namprd10.prod.outlook.com (2603:10b6:8:1b8::15) by PH0PR10MB7099.namprd10.prod.outlook.com (2603:10b6:510:26d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.13; Tue, 20 Aug 2024 23:58:13 +0000 Received: from DS0PR10MB7933.namprd10.prod.outlook.com ([fe80::2561:85b0:ae8f:9490]) by DS0PR10MB7933.namprd10.prod.outlook.com ([fe80::2561:85b0:ae8f:9490%3]) with mapi id 15.20.7897.010; Tue, 20 Aug 2024 23:58:13 +0000 From: "Liam R. Howlett" To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Suren Baghdasaryan , Lorenzo Stoakes , Matthew Wilcox , Vlastimil Babka , sidhartha.kumar@oracle.com, Bert Karwatzki , Jiri Olsa , Kees Cook , "Paul E . McKenney" , "Liam R. Howlett" Subject: [PATCH v6 14/20] mm/mmap: Avoid zeroing vma tree in mmap_region() Date: Tue, 20 Aug 2024 19:57:23 -0400 Message-ID: <20240820235730.2852400-15-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240820235730.2852400-1-Liam.Howlett@oracle.com> References: <20240820235730.2852400-1-Liam.Howlett@oracle.com> X-ClientProxiedBy: YT4PR01CA0323.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:10a::29) To DS0PR10MB7933.namprd10.prod.outlook.com (2603:10b6:8:1b8::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7933:EE_|PH0PR10MB7099:EE_ X-MS-Office365-Filtering-Correlation-Id: b38d223f-c1c6-4ae6-184a-08dcc173f397 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|7416014|376014; X-Microsoft-Antispam-Message-Info: itD2Fxz7dhWw0R7hN6ixg6zot71s570PBZ8upV329AeIhHSMmRM5uCkB+rLJw6xiIIx0WgxXTA/lFiiBT6sZutnvVigvvPP/veGlHNJ+28vgNJEAGU2vEZgYtV9uP1EQL1KuaWDR2v8qQ3QroIWkFG33xLugzIuNN8sS8QxdC9R0evlF1uvAEC8OlZA6yf4R1LFaIVjzEeXSOd+yxvEIAyO/45/41ohOM7Wbt3hwr9PcfIJz+ilbX7s706SkZ89WreiuqUFY5w+QnQeOdgiio4xKq45QUsbmZxYjFq9OYY209AvKfldf9OUotZMo4HSMLyzs6gkpUz+UwUCOpoEk6Y9KZmCUMepNBrkTX5mNZPfoG1G17fJsnbi9x50Mwe2lMPPU3Px78R3JvnraGJOWHykl1L7ykzEaKdedg03m7KKOyGkuNyR8bLqrpGIwIjjc26oFHZd0Od+1m/0MbQF15HUID58OFhU8OfCQngBVvVcyHu6oHAhU4FPB3HIuRFukEwWFi9GaPz7NlGFCDEUY34AVCNwO1lBK6j2jZoo/GLffiGb/ipGazDN3jRCAZ3afERJQ6Nidj24D8uJyXvRLjicldQvapaUtMaeo0UTyhMJRACeIawWhvo8QmocXzDiqH3qN2bhiwyuOeOcdK5QHbFBgGqgwwr+CsSji8EzVQzI+FNtD7lK3Q0jJgEQJWQSuqW8FDxakUgVNV+PU201P1rHWo1mC1qHTvc5jKf0Xc49L2mdtCYXcgC909MEh5Ma+tgnAr4w8MB8ny04H9n7ItSKY7qJHrhPUwomSDG/Kct6a4w+TbJCrDyDaXupEVAt37bk98HOGQQlyxwBmfLV+WKn+N3ZeH270tvpiIEU5T6ldZnUCsTyBTDabmfg8rwBxnj4FJKSqvP7dcIP8YvwAXdIKs2hJmMvX/i5EU/ib385dftHbpDFo1aH+88+46P5xSmWGU94tarZP7NCO8YgZqzizfnAPkrHrknQSb/hmNcRvWF2Oi8FFqkYSWC2AgGuMglHIYOfoJ4m3Bq3ybVgms3hDFdDxhMPfTz5FJyJl5zAkncoG2ATFj+Y6zstmlzm2GB+M0dHGkEVkUwwoSKgDWDtrscBIMSu0IK0xxlN80rhBkXztDxak2Ly4gc2xs9l2rLDl/1B1NtRBgTNYWFEer9ovjTubkZT6W9DMjLP5MYRxj+MFchNXavOLyjE2+Wy2f421/BzHVQu8nMgdZVg2DUPOarFohjtI4WodXgWY3uOLaCfjEtBGO7v61akJLMXvEaUJeALmm8kK+qniYttH5dIxnVvPavOxoD9Cj6kAR5hbeHR2nJ3eLaAkpC+FuuAvsgdqMzRejlmVhefIozeSsw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR10MB7933.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(7416014)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3PPDcHmKgNVZFyYNzLTKquB+82ZQll0PHa0P1hwvNz61t7WlT7nybh46SJSoKJW/hUU+AWFv6Nn+YZSmg75bs/yEJCkZph2eBZEy4G7StILAoQUyETp7dM+ZaZEe2J3m0mVGeF+EfG7f02n4BkABm7q6nXnkJS5+O6fxjWr9yrFM0zssp4KjIwgVNWGoe/g9KQWmHWhOLO4yZ8kRvn/j1bSK4YPjBM82pM5TCV7wUzMJXfWS9fGxC3tdf2ouYd5sZC16q8LpjgEC4OOZH09KlR36n1iPIIC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ZJpMtHVlfwCaki3b1wZMdv7pj21fQk48ISJNC/UjU1VnDJUBN3q4Jxs9bOm6fhUyCfavvBXse/8Zo4xp7icROA1+LakATBsYRKVwEHYbeHT1kGM4trLPVwTOzcPNorBeB90TujfJCNlODpuct+2xXroC8/D0OOALz4soPUceaSDp5Bs+FuaHeTFj7ZVWZTH9X51Cc7n3zd9TDdoQP/trDGqj6s4KQuTv4PLcK4fb8h3Un8MKNeEBiKYM/4KpaCb3oAaAq+zVtNK4diwgPYzMT8Q== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: TEPx/nrij0zhHYSrJyu3IGt/Jl8JJqvl1H55MYRd5ENcaFGSU8e9b1cKm4pz2TZw/FsC3Rh3OUBZ4JpXk5wUXgoGKZ5kHY8IKMI3qqBCAJx4N+TgSJj+X/DPBS3HTljkT+DottlTwtMaBCuHKUhirKhvVltTr+vNAXBzELJcG3crLGyYOrR28QQzTfUwnIT99oZigEVep9HamekjbKDCJNOg6QTLxLJKFIXx3GVqMLW0BS7y7x+Dp/8kZ3BOi1BmRKlRkFZbXV9QpKYPtbt0JHf337OmkhvEkasbEsttaIT7luiNwCsgpcM/K+rQWK11i9ukeISH2mzKEuYv2IU5wjWo1numy41lZsEM7aNyBrljlJXw3r+8ez1B/EoHNdbb9DqpCBMokc6BFQreydjXTlX6Eex4qFxA2DVidm1XL5GHmqzyf39cLb4ozxWPiMUmzejb6YHLlX6Rs6sVnLEbXx1UKqimzZ/62iQHQxl/omMKeodCf3JjAj/ShxpXwTWdRoqkmsb1xqA396E2/trbbTbBK5j9d0girQZ8pPOgSVW3SOKnRbqLDJc3sELu/bu/YJlMlfjtB3w8Iy2K1ZXTYGFXh7l+YI1QPv0GsELAZhk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b38d223f-c1c6-4ae6-184a-08dcc173f397 X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7933.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Aug 2024 23:58:13.3296 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0bWYXsm/64qDvXDyjwyHso2qS8Sr7AOqu31lRV1Yx0Ynk+ge4rJ6GWo3VL7tDraGanp3RLULN943Nx5ZPSVVFw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB7099 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-20_18,2024-08-19_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 bulkscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408200176 X-Proofpoint-ORIG-GUID: 3nXwtLY0qE24pLf4hlDMjb2XR-FAZO3m X-Proofpoint-GUID: 3nXwtLY0qE24pLf4hlDMjb2XR-FAZO3m X-Stat-Signature: a435krk97tx6oy3497cjgk37469it6ud X-Rspamd-Queue-Id: 5E9D28001B X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1724198310-937234 X-HE-Meta: U2FsdGVkX19QKY+SRFG7c0snLUpwQK1iNK0rtOCc6VXx8ElbMkpJe3voNdv0rTdBR3qp2cNNO6im2e8nSjdKaodo8QFCXShM2fPEuZP56HzcGmRpE1vVthHjGwyoCNSggE8Y2miA8z1ee12noGNZSqPfnCPuniWW7r/85I98A2tuGQgRoPlU64a8XKpRPCeRETXDA5P4kKIVakUAaSb0MgrkdsXgeSXSQ0tdsmLWiSsBiLtZ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mtXNqd/R5eNQV7+aw58+8vn96kl0Fzf2hqcGGcWadsUSKTi9DM6j5jCjbAySL2/ILeauLfhOcVZhUROkt9l9GaqA0b6h7Q+ytsk93Ap8w5naZU5RjMJpLtPF2aivMX46G2RPNgbno96R7x7y+Whc+PcKnD/Fsgd6DjSNeO8kFyEwoDQOM8bHpo892bVGcA7v2NwBeJLde+LRkw== 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: List-Subscribe: List-Unsubscribe: From: "Liam R. Howlett" Instead of zeroing the vma tree and then overwriting the area, let the area be overwritten and then clean up the gathered vmas using vms_complete_munmap_vmas(). To ensure locking is downgraded correctly, the mm is set regardless of MAP_FIXED or not (NULL vma). If a driver is mapping over an existing vma, then clear the ptes before the call_mmap() invocation. This is done using the vms_clean_up_area() helper. If there is a close vm_ops, that must also be called to ensure any cleanup is done before mapping over the area. This also means that calling open has been added to the abort of an unmap operation, for now. Temporarily keep track of the number of pages that will be removed and reduce the charged amount. This also drops the validate_mm() call in the vma_expand() function. It is necessary to drop the validate as it would fail since the mm map_count would be incorrect during a vma expansion, prior to the cleanup from vms_complete_munmap_vmas(). Clean up the error handing of the vms_gather_munmap_vmas() by calling the verification within the function. Signed-off-by: Liam R. Howlett Reviewed-by: Lorenzo Stoakes --- mm/mmap.c | 62 ++++++++++++++++++++++++++----------------------------- mm/vma.c | 54 +++++++++++++++++++++++++++++++++++++----------- mm/vma.h | 22 ++++++++++++++------ 3 files changed, 87 insertions(+), 51 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 71b2bad717b6..6550d9470d3a 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1373,23 +1373,19 @@ unsigned long mmap_region(struct file *file, unsigned long addr, unsigned long merge_start = addr, merge_end = end; bool writable_file_mapping = false; pgoff_t vm_pgoff; - int error; + int error = -ENOMEM; VMA_ITERATOR(vmi, mm, addr); + unsigned long nr_pages, nr_accounted; - /* Check against address space limit. */ - if (!may_expand_vm(mm, vm_flags, len >> PAGE_SHIFT)) { - unsigned long nr_pages; + nr_pages = count_vma_pages_range(mm, addr, end, &nr_accounted); - /* - * MAP_FIXED may remove pages of mappings that intersects with - * requested mapping. Account for the pages it would unmap. - */ - nr_pages = count_vma_pages_range(mm, addr, end); - - if (!may_expand_vm(mm, vm_flags, - (len >> PAGE_SHIFT) - nr_pages)) - return -ENOMEM; - } + /* + * Check against address space limit. + * MAP_FIXED may remove pages of mappings that intersects with requested + * mapping. Account for the pages it would unmap. + */ + if (!may_expand_vm(mm, vm_flags, (len >> PAGE_SHIFT) - nr_pages)) + return -ENOMEM; /* Find the first overlapping VMA */ vma = vma_find(&vmi, end); @@ -1400,14 +1396,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, mas_init(&mas_detach, &mt_detach, /* addr = */ 0); /* Prepare to unmap any existing mapping in the area */ if (vms_gather_munmap_vmas(&vms, &mas_detach)) - goto gather_failed; - - /* Remove any existing mappings from the vma tree */ - if (vma_iter_clear_gfp(&vmi, addr, end, GFP_KERNEL)) - goto clear_tree_failed; + return -ENOMEM; - /* Unmap any existing mapping in the area */ - vms_complete_munmap_vmas(&vms, &mas_detach); next = vms.next; prev = vms.prev; vma = NULL; @@ -1423,8 +1413,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr, */ if (accountable_mapping(file, vm_flags)) { charged = len >> PAGE_SHIFT; + charged -= nr_accounted; if (security_vm_enough_memory_mm(mm, charged)) - return -ENOMEM; + goto abort_munmap; + vms.nr_accounted = 0; vm_flags |= VM_ACCOUNT; } @@ -1473,10 +1465,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, * not unmapped, but the maps are removed from the list. */ vma = vm_area_alloc(mm); - if (!vma) { - error = -ENOMEM; + if (!vma) goto unacct_error; - } vma_iter_config(&vmi, addr, end); vma_set_range(vma, addr, end, pgoff); @@ -1485,6 +1475,11 @@ unsigned long mmap_region(struct file *file, unsigned long addr, if (file) { vma->vm_file = get_file(file); + /* + * call_mmap() may map PTE, so ensure there are no existing PTEs + * call the vm_ops close function if one exists. + */ + vms_clean_up_area(&vms, &mas_detach, true); error = call_mmap(file, vma); if (error) goto unmap_and_free_vma; @@ -1575,6 +1570,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr, expanded: perf_event_mmap(vma); + /* Unmap any existing mapping in the area */ + vms_complete_munmap_vmas(&vms, &mas_detach); + vm_stat_account(mm, vm_flags, len >> PAGE_SHIFT); if (vm_flags & VM_LOCKED) { if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) || @@ -1603,7 +1601,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, return addr; close_and_free_vma: - if (file && vma->vm_ops && vma->vm_ops->close) + if (file && !vms.closed_vm_ops && vma->vm_ops && vma->vm_ops->close) vma->vm_ops->close(vma); if (file || vma->vm_file) { @@ -1622,14 +1620,12 @@ unsigned long mmap_region(struct file *file, unsigned long addr, unacct_error: if (charged) vm_unacct_memory(charged); - validate_mm(mm); - return error; -clear_tree_failed: - abort_munmap_vmas(&mas_detach); -gather_failed: +abort_munmap: + if (vms.nr_pages) + abort_munmap_vmas(&mas_detach, vms.closed_vm_ops); validate_mm(mm); - return -ENOMEM; + return error; } static int __vm_munmap(unsigned long start, size_t len, bool unlock) @@ -1959,7 +1955,7 @@ void exit_mmap(struct mm_struct *mm) do { if (vma->vm_flags & VM_ACCOUNT) nr_accounted += vma_pages(vma); - remove_vma(vma, true); + remove_vma(vma, /* unreachable = */ true, /* closed = */ false); count++; cond_resched(); vma = vma_next(&vmi); diff --git a/mm/vma.c b/mm/vma.c index 7104c2c080bb..5b33f7460ab7 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -136,10 +136,10 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags, /* * Close a vm structure and free it. */ -void remove_vma(struct vm_area_struct *vma, bool unreachable) +void remove_vma(struct vm_area_struct *vma, bool unreachable, bool closed) { might_sleep(); - if (vma->vm_ops && vma->vm_ops->close) + if (!closed && vma->vm_ops && vma->vm_ops->close) vma->vm_ops->close(vma); if (vma->vm_file) fput(vma->vm_file); @@ -521,7 +521,6 @@ int vma_expand(struct vma_iterator *vmi, struct vm_area_struct *vma, vma_iter_store(vmi, vma); vma_complete(&vp, vmi, vma->vm_mm); - validate_mm(vma->vm_mm); return 0; nomem: @@ -645,11 +644,14 @@ void vma_complete(struct vma_prepare *vp, uprobe_mmap(vp->insert); } -static void vms_complete_pte_clear(struct vma_munmap_struct *vms, - struct ma_state *mas_detach, bool mm_wr_locked) +static inline void vms_clear_ptes(struct vma_munmap_struct *vms, + struct ma_state *mas_detach, bool mm_wr_locked) { struct mmu_gather tlb; + if (!vms->clear_ptes) /* Nothing to do */ + return; + /* * We can free page tables without write-locking mmap_lock because VMAs * were isolated before we downgraded mmap_lock. @@ -658,11 +660,31 @@ static void vms_complete_pte_clear(struct vma_munmap_struct *vms, lru_add_drain(); tlb_gather_mmu(&tlb, vms->mm); update_hiwater_rss(vms->mm); - unmap_vmas(&tlb, mas_detach, vms->vma, vms->start, vms->end, vms->vma_count, mm_wr_locked); + unmap_vmas(&tlb, mas_detach, vms->vma, vms->start, vms->end, + vms->vma_count, mm_wr_locked); + mas_set(mas_detach, 1); /* start and end may be different if there is no prev or next vma. */ - free_pgtables(&tlb, mas_detach, vms->vma, vms->unmap_start, vms->unmap_end, mm_wr_locked); + free_pgtables(&tlb, mas_detach, vms->vma, vms->unmap_start, + vms->unmap_end, mm_wr_locked); tlb_finish_mmu(&tlb); + vms->clear_ptes = false; +} + +void vms_clean_up_area(struct vma_munmap_struct *vms, + struct ma_state *mas_detach, bool mm_wr_locked) +{ + struct vm_area_struct *vma; + + if (!vms->nr_pages) + return; + + vms_clear_ptes(vms, mas_detach, mm_wr_locked); + mas_set(mas_detach, 0); + mas_for_each(mas_detach, vma, ULONG_MAX) + if (vma->vm_ops && vma->vm_ops->close) + vma->vm_ops->close(vma); + vms->closed_vm_ops = true; } /* @@ -686,7 +708,10 @@ void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, if (vms->unlock) mmap_write_downgrade(mm); - vms_complete_pte_clear(vms, mas_detach, !vms->unlock); + if (!vms->nr_pages) + return; + + vms_clear_ptes(vms, mas_detach, !vms->unlock); /* Update high watermark before we lower total_vm */ update_hiwater_vm(mm); /* Stat accounting */ @@ -697,7 +722,7 @@ void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, /* Remove and clean up vmas */ mas_set(mas_detach, 0); mas_for_each(mas_detach, vma, ULONG_MAX) - remove_vma(vma, false); + remove_vma(vma, /* = */ false, vms->closed_vm_ops); vm_unacct_memory(vms->nr_accounted); validate_mm(mm); @@ -849,13 +874,14 @@ int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, while (vma_iter_addr(vms->vmi) > vms->start) vma_iter_prev_range(vms->vmi); + vms->clear_ptes = true; return 0; userfaultfd_error: munmap_gather_failed: end_split_failed: modify_vma_failed: - abort_munmap_vmas(mas_detach); + abort_munmap_vmas(mas_detach, /* closed = */ false); start_split_failed: map_count_exceeded: return error; @@ -900,7 +926,7 @@ int do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, return 0; clear_tree_failed: - abort_munmap_vmas(&mas_detach); + abort_munmap_vmas(&mas_detach, /* closed = */ false); gather_failed: validate_mm(mm); return error; @@ -1618,17 +1644,21 @@ bool vma_wants_writenotify(struct vm_area_struct *vma, pgprot_t vm_page_prot) } unsigned long count_vma_pages_range(struct mm_struct *mm, - unsigned long addr, unsigned long end) + unsigned long addr, unsigned long end, + unsigned long *nr_accounted) { VMA_ITERATOR(vmi, mm, addr); struct vm_area_struct *vma; unsigned long nr_pages = 0; + *nr_accounted = 0; for_each_vma_range(vmi, vma, end) { unsigned long vm_start = max(addr, vma->vm_start); unsigned long vm_end = min(end, vma->vm_end); nr_pages += PHYS_PFN(vm_end - vm_start); + if (vma->vm_flags & VM_ACCOUNT) + *nr_accounted += PHYS_PFN(vm_end - vm_start); } return nr_pages; diff --git a/mm/vma.h b/mm/vma.h index 6028fdf79257..756dd42a6ec4 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -48,6 +48,8 @@ struct vma_munmap_struct { unsigned long stack_vm; unsigned long data_vm; bool unlock; /* Unlock after the munmap */ + bool clear_ptes; /* If there are outstanding PTE to be cleared */ + bool closed_vm_ops; /* call_mmap() was encountered, so vmas may be closed */ }; #ifdef CONFIG_DEBUG_VM_MAPLE_TREE @@ -95,14 +97,13 @@ static inline void init_vma_munmap(struct vma_munmap_struct *vms, unsigned long start, unsigned long end, struct list_head *uf, bool unlock) { + vms->mm = current->mm; vms->vmi = vmi; vms->vma = vma; if (vma) { - vms->mm = vma->vm_mm; vms->start = start; vms->end = end; } else { - vms->mm = NULL; vms->start = vms->end = 0; } vms->unlock = unlock; @@ -112,6 +113,8 @@ static inline void init_vma_munmap(struct vma_munmap_struct *vms, vms->exec_vm = vms->stack_vm = vms->data_vm = 0; vms->unmap_start = FIRST_USER_ADDRESS; vms->unmap_end = USER_PGTABLES_CEILING; + vms->clear_ptes = false; + vms->closed_vm_ops = false; } int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, @@ -120,18 +123,24 @@ int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, struct ma_state *mas_detach); +void vms_clean_up_area(struct vma_munmap_struct *vms, + struct ma_state *mas_detach, bool mm_wr_locked); + /* * abort_munmap_vmas - Undo any munmap work and free resources * * Reattach any detached vmas and free up the maple tree used to track the vmas. */ -static inline void abort_munmap_vmas(struct ma_state *mas_detach) +static inline void abort_munmap_vmas(struct ma_state *mas_detach, bool closed) { struct vm_area_struct *vma; mas_set(mas_detach, 0); - mas_for_each(mas_detach, vma, ULONG_MAX) + mas_for_each(mas_detach, vma, ULONG_MAX) { vma_mark_detached(vma, false); + if (closed && vma->vm_ops && vma->vm_ops->open) + vma->vm_ops->open(vma); + } __mt_destroy(mas_detach->tree); } @@ -145,7 +154,7 @@ int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, unsigned long start, size_t len, struct list_head *uf, bool unlock); -void remove_vma(struct vm_area_struct *vma, bool unreachable); +void remove_vma(struct vm_area_struct *vma, bool unreachable, bool closed); void unmap_region(struct ma_state *mas, struct vm_area_struct *vma, struct vm_area_struct *prev, struct vm_area_struct *next); @@ -259,7 +268,8 @@ bool vma_wants_writenotify(struct vm_area_struct *vma, pgprot_t vm_page_prot); int mm_take_all_locks(struct mm_struct *mm); void mm_drop_all_locks(struct mm_struct *mm); unsigned long count_vma_pages_range(struct mm_struct *mm, - unsigned long addr, unsigned long end); + unsigned long addr, unsigned long end, + unsigned long *nr_accounted); static inline bool vma_wants_manual_pte_write_upgrade(struct vm_area_struct *vma) {