From patchwork Wed Jul 17 20:07:02 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: 13735747 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 36BFDC3DA5D for ; Wed, 17 Jul 2024 20:08:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2794D6B00A7; Wed, 17 Jul 2024 16:08:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 250DE6B00A8; Wed, 17 Jul 2024 16:08:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 054406B00A9; Wed, 17 Jul 2024 16:08:00 -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 CE32C6B00A8 for ; Wed, 17 Jul 2024 16:08:00 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7CD72120BFB for ; Wed, 17 Jul 2024 20:08:00 +0000 (UTC) X-FDA: 82350330720.11.B8160EC Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf23.hostedemail.com (Postfix) with ESMTP id 2CBAE14001B for ; Wed, 17 Jul 2024 20:07:56 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=F99lLj2D; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=G5Vz3w8W; spf=pass (imf23.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=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721246824; 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=9BtKiGUugGEEWslw8NJfElcvJlWGE3OYXj7kTlHZwJw=; b=K0c+SPkyI2j7GvtIFVL5R7gqs2h2ocaZDRMR1Z+h/k4CLBpBhWu7tE7nRaRKcVfiNBSf0o gZPfUdKODkLr6I3DMJLfwgChEVTW/b7P8q5dxzAFjVsrXboZLormZp1jjX0FpWm2w9Fsel WhiETz6X3CDLnVpIsVSqma+MTVyw6iQ= ARC-Authentication-Results: i=2; imf23.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=F99lLj2D; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=G5Vz3w8W; spf=pass (imf23.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=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1721246824; a=rsa-sha256; cv=pass; b=q41GwhAJdFxHE8lObtprO0orW7Cbt2quRTyswflegaI7Lc/TQ0cHmxFIVVBw3fwoMOBLlX 9zeax73sOVNrSKvOJJqg99fFS1GIMnucj45/NpymT1aRSXy5CrmzOqHV6QWu07LhFShRZn ARHvIQbp/Ad8lRDTGloh12Dn2uWmnCI= Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46HJsRWw002443; Wed, 17 Jul 2024 20:07:49 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=9BtKiGUugGEEWslw8NJfElcvJlWGE3OYXj7kTlHZwJw=; b= F99lLj2D0pPc2p9qzDcSqqZsqT8Tg1ZS7Y1NYvrs6lejysEY3jEiW+X39fNDgWR2 FN0UcxQmVQ62Kp5So0faA1W6mhPJ352cAdJ4cqO2E742CGDsfk93iE8eU6iZL8EC UWdZUa1Eepn1kjIZGEw19NEHjkrjt7Te70ZBa9d8yZwHL2HcEl2LjggUuzlL7wnf YkXmJ2TACG4jxjyLdTxzbQIrpp6lbmZJlxH/QMFylmd6gHt2JKBX56sosDcLcCQE qoy6AlGuBUNDZTnOQTMdC1vsSuqrE6RQh7gGtcyXZ5EI+xR/UaByLHZ5/zXARymO EohV7nqMiEMrmCcL+Vejpw== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40ekxy84at-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Jul 2024 20:07:49 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 46HJIY6I003738; Wed, 17 Jul 2024 20:07:48 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2174.outbound.protection.outlook.com [104.47.73.174]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 40dweyhkpk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 17 Jul 2024 20:07:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PAKIgtkD+w3hmex/YZer243bNB4CarquBBfU6cyalT9ymOZ9vKsT3CfWuEl60fv8ahVNFCmhzMmgxvZJV+9JEAVElLi04XS3abqWnzf0Kvh/oy1KvRnR8mh5DQ/1seF4nUaEmhxXwSlIqGFxZtTCmWXG9MW+j6cdtYzE/8S879NANQfiSxOdBiUiBqyivh41LIpVg5jKJjHQg4Hg4CO31x9AbwgGwN2IwRrUAk2GyZCI4pvvNGz/2S+2H+bnohEAMWFl+foMXlm3iy2+PI1JhLXzKVgqJO05EbJkpklsSAcZllXh8FIEAc6IiiNOnCcqBlAoY06/41u8tZ79hn0Z0A== 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=9BtKiGUugGEEWslw8NJfElcvJlWGE3OYXj7kTlHZwJw=; b=kRYeWNylGwmLKxUbOT2yTDfZlu8ItHUXaXEvbz6mtJIASYt/6RoYqhdHeIcbU3opCbImtjR7CieIbt9MSLsnTAW67pm5L8tKVuISrRBKSrY6BhzI+w9hd3ouC0ltvuyxY93yDWCxatPXwd0pSgdCPlxShJn8/IDD6A3rRcikQHep1NeuQABoJxRQRCxXXDjPAPy9Km5y5icuNwubU9zpBOzM0kZV7dEsLVN96FmmAQMcjDzNlxqyGM4vGLXI2jI9Xz5LBqbrmrf9RcAH7I7ChXcdlhzcFfLh2eS0px7Bym/+T904ctdvXonlDLs3VxThC+RWhDNDyZrSJjlU4wWPjg== 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=9BtKiGUugGEEWslw8NJfElcvJlWGE3OYXj7kTlHZwJw=; b=G5Vz3w8WbkVxrt4i5HAVfajiveBCZ3W+bG1V1S6snjbbhvwf9gLupvAEK7xCl6eYUoAPhJAYuCmlS/3yiU5WoBjdg/JnBkpkJw6EIxw1GmFIfybEwfwaoMsjfxNlAMIKp3IduWyYVcuIYJ1CCgB0I1QqvZadA3O9am+6UoE3l7Y= Received: from DS0PR10MB7933.namprd10.prod.outlook.com (2603:10b6:8:1b8::15) by DM4PR10MB7507.namprd10.prod.outlook.com (2603:10b6:8:187::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7784.16; Wed, 17 Jul 2024 20:07:43 +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.7784.016; Wed, 17 Jul 2024 20:07:43 +0000 From: "Liam R. Howlett" To: linux-mm@kvack.org, Andrew Morton Cc: Suren Baghdasaryan , Vlastimil Babka , Lorenzo Stoakes , Matthew Wilcox , sidhartha.kumar@oracle.com, "Paul E . McKenney" , Bert Karwatzki , Jiri Olsa , linux-kernel@vger.kernel.org, Kees Cook , Jeff Xu , "Liam R. Howlett" Subject: [PATCH v5 14/21] mm/mmap: Avoid zeroing vma tree in mmap_region() Date: Wed, 17 Jul 2024 16:07:02 -0400 Message-ID: <20240717200709.1552558-15-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240717200709.1552558-1-Liam.Howlett@oracle.com> References: <20240717200709.1552558-1-Liam.Howlett@oracle.com> X-ClientProxiedBy: YT4PR01CA0050.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:111::10) To DS0PR10MB7933.namprd10.prod.outlook.com (2603:10b6:8:1b8::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7933:EE_|DM4PR10MB7507:EE_ X-MS-Office365-Filtering-Correlation-Id: 0a15224a-d056-46fe-394d-08dca69c1e24 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: LHfheq0Y2q19j7hVrCrf7J7M0uIUEyeWWwNv2xa9XKRZVfgBKwT9Y08USxZV6o/7Pw8iO3q2bggkeuKrz10geSJsDTTF4OLsOJsrKR0yEshloyiBvLooSflwY3EqUVEtYFcFVg7rqOVzpHKK5Ld/QKwFmd68H2dcsILl4aDlNYNnx8E8d4iY2Bnu8xPdEnCTd3SOdY62VMOHFbuDjrpxC3EZIKLdYIwUIAwKoZBeUCB/JwkTnAzUAN51SjQZCWnhl50o3b5yGl4C3jY03K4OzAC+DOWeejdr8vyXgzgbO6tgr6lfSSQVxrzB1X6M0gW9wqI5I+O7ru2fH+MVxo/x/EMJ8e3oLx0Lya4XdLmSsJPdlLza02Ov0yrRTYVc2nBvruvywyU9pu1HYgdg2Y0UoI6cqXk38XXynq2BE4e8ceBbiV9jvYAuUwQJrhI1EJBJdFmNgiB1+DjmMwVN6+cRQydCLoDxcWQhlF6pmSc9rmPS8myXLPvu2p4E42dWiFf20+Q5dQw4B/dnwvrBwqkRFL/6GeripH5gr+MSfaF+EE+lDgJa4lo7Q4I4fdfXkzEcKa6BV+JsRx0DIg8Q8CJNPiUy5ZOJZLaO0L8nr8gzYuwxaBN1SiOP4Qltax02LtQS7JatosenvWXDU9tawJJsr6t/cyJ3HaZH4rad6izLJBedTzwibAQosR6PTp5ORGbdLaqRSfrwoj9x7WANrc89WQUXIJj2oPXUVBLTyV5yJB88iXEESaxXfKwuBdGPafsEFPtqDHfinUWZ6uMlM1S1ESivmLJpQ6c97PtJkCEIOUu/A3+n4o/nSU6NBqmJJXH6eiQrEgvPZ0kf4qF1MvAwwGB/BBpSQmRWBr34Md0+jeEN+sZZVRrdRFxpZjF1pNNkBLrGSoDbWmyf/NMwflr1l+7LQ/a53vVNpu2YPMl7ww7k71oetFbHVI2pxEkkXMjHT7HDtTyLeTxCDNrLEp4pRfeqPMdugQ1NQ1mH8sZItxPwJeFlo4tIYSDurWr6zQPk7mAvMAq0sRMzeM/R0N3k78LLZT7njZWP6Y7rEcBqTQYgqjGBThTEfvTMkHKNYLEN9id2ytyretSazrWPcZK4eI7zs0T175aTbj7WEPiGZa5TBMuSFKeMSvfGG4R9fE8aUZwMNTqV6ofKnTqDZffK1OmyxqBcb72YeFJmwT6li0uExSPOoY2DiSXiRPkG1rv1pCetCMlPB3R4cIDr965v5JsvWEwXaz4x8r7/8bP8/kq4fYXj7Q1XTPblHyP2IK5pyLPrClGySZQuaDD2/1IsQ1FMdVwixPMFOBuGg97eauhBpR9j7dlzTbIxw/kdJI031x6XVUElRzjdfUmxOMgsLg== 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)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9Jnmiif3feMX6wIxaPvv38Eq/S8UwFz5x7aVLwW1AH524lZVDqcLgXe9cFMPMYWUXxAfOB0QlfD26B1QKvjS5X8l61zxjgKQaZdlJ8+NLQqC7mDJJpFhiD93qTM5GTCBwXq5RRqJmLH0bv1ODDXak1uphwM7uVJyGU8wMpdKoXBq+iMQ06IF3vwOveGyQ9TCv0/8O7ZDexsWGV0j4KOWb4YJZL/oYYVC6yVFl2dCNcCbXBBqyIdPWvzLrplaJlW8KPLRr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hzOlu2N+mbEvI4KyByUM1hGl1w6GpgMz1QZJHWwBONmitNbXyU2Vh+lhG8nLEF2Bg4CwAw7e2xKWUDuSj/t1opwlMTjk5/J2LmUstXHevyAMGR6vx/r+W3ie3ChMb2gT4Ei3kV00jot5EkPzZhpcoo+okrsj6ilfGSL1fyKBWIC8b0pNRO9NwbKz6lY75pu5zmk69GTGudpHhCaHiLLV2Pj7LAc+/ZYrlMkAo198l2vAxm1xSypYzVKVObq6GYoj19jxhQfYAfpw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: mC1P1SEDK2ZsACtWdFu6WEKwncbMM8f8sViK+dnAqLaQc7+N7n3gm9UkHTWJ08zwvgJY8vrgQK+jKx9sBUDMqV1NuSZGffb+u2ijL9EBIWlDySTiTRUXMlvNXz17HsGlIZfqOEfDbo+4erqbVoOauqUD9YqXBuMdwRuCxxA0EL7A2tJFEznmGy+nnQM8gGgTAyMt3LtuibE69xLeCICIUoTFzxffBl2JdqhPTSxt5a3cb41hA2diLq/3551K80m9MLgPJXNyFX7GWqKYyOo0OcOMEvtmhWWZNrfFxtkAm98KzjNjePFvhA7Qc3POsq6N53SBeK0cO3tCk5sMx28rEEfs0bunS7wkpf7qA+yaguVEkBKQbip49FLBwzPgqauiiZs9FltAoNHsG0LT4PQnStDqpZroBgWr/UE4Wrp0QDkle6e2QGRJt8wwb4nZpM439XX0FYHUYvWWR7wKjarqzaxvVnizjx5P20HjX9nB+btwlunIQgBPc2lntu3E3uQbgJO1wESuoYjqGTnVOlRJkj2mdk0+WJRc9vE+t9MxpoOY+IjoVHTtki1lI0JGirXpXc8/7XWjZtYaDp8O1ctQDbSuYATzVhXzVpcumk+eMo8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0a15224a-d056-46fe-394d-08dca69c1e24 X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7933.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2024 20:07:43.1842 (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: T8pJMxzRvvaujBu9QWKuJdr84/+XZDyRlvL5k37GkaAxdDjbFtEHHKLC0NFRHiVdKpB7ohePI0KsefAj6Mbkxw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB7507 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-07-17_15,2024-07-17_02,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2407170152 X-Proofpoint-ORIG-GUID: 8pxu8IA42-a4_-5pWZhOhMGtHFSc9l3C X-Proofpoint-GUID: 8pxu8IA42-a4_-5pWZhOhMGtHFSc9l3C X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2CBAE14001B X-Stat-Signature: hiektzyyk5h5oxgfeouaoszdc7zb7cc8 X-Rspam-User: X-HE-Tag: 1721246876-712208 X-HE-Meta: U2FsdGVkX18NTJ1692OGcBe2M2KQkJhlp0wW67p5vdLf6ss/7iphU7wIjycy3F4KieBPTpMuP3oyIX6WdY6ljmP0UQZoVXb2cpPZK7rsYJlcq2aoOpVohsIigRKyDuMPYc3RVB4Pnt+vMH+ZyJFvlZapRZttibUGtuBLSmysj3Eb6OSjOsabb1vHRSc19KLcTcjSr3KJ+HpgtqVbZDxUBB9polpKywKpQIxBJJ1paBk0cTiGZTfZAG8fheI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BHHAFa9GuK7o1Hyj6YJHd345/kB9cD41pDYfVABtsFxeVX6gdEFVgemdbGUh8YPiZAMEdmw3NP35FGeZ4h/40DxgVSog4SS6e/hFHwI2HrkvXPv2AIVK4Ns3VIJjy21cezc10bCuW+w9UBysdXQ== 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(). If a driver is mapping over an existing vma, then clear the ptes before the call_mmap() invocation. If the vma has a vm_ops->close(), then call the close() function. This is done using the vms_clear_ptes() and vms_close_vmas() helpers. This has the side effect of needing to call open() on the vmas if the mmap_region() fails later on. Temporarily keep track of the number of pages that will be removed and reduce the charged amount. This commit 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. Note that before this change, a MAP_FIXED could fail and leave a gap in the vma tree. With this change, a MAP_FIXED failure will fail without creating a gap and leave *a* vma in the area (may have been split) and attept to restore them to an operational state (re-attached and vm_ops->open()'ed if they were vm_ops->close()'d). Signed-off-by: Liam R. Howlett --- mm/internal.h | 2 + mm/mmap.c | 119 +++++++++++++++++++++++++++++++------------------- 2 files changed, 76 insertions(+), 45 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index ec8441362c28..5bd60cb9fcbb 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1503,6 +1503,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; /* vma->vm_ops->close() called already */ }; void __meminit __init_single_page(struct page *page, unsigned long pfn, diff --git a/mm/mmap.c b/mm/mmap.c index 20da0d039c95..0b7aa2c46cec 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -170,10 +170,11 @@ void unlink_file_vma_batch_final(struct unlink_vma_file_batch *vb) /* * Close a vm structure and free it. */ -static void remove_vma(struct vm_area_struct *vma, bool unreachable) +static +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); @@ -401,17 +402,21 @@ anon_vma_interval_tree_post_update_vma(struct vm_area_struct *vma) } static 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; @@ -527,6 +532,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; /* No PTEs to clear yet */ + vms->closed = false; } /* @@ -735,7 +742,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: @@ -2597,23 +2603,31 @@ struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, * * 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) { + if (closed && vma->vm_ops && vma->vm_ops->close && + vma->vm_ops->open) + vma->vm_ops->open(vma); + vma_mark_detached(vma, false); + } __mt_destroy(mas_detach->tree); } -static void vms_complete_pte_clear(struct vma_munmap_struct *vms, +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) + return; + /* * We can free page tables without write-locking mmap_lock because VMAs * were isolated before we downgraded mmap_lock. @@ -2629,6 +2643,23 @@ static void vms_complete_pte_clear(struct vma_munmap_struct *vms, free_pgtables(&tlb, mas_detach, vms->vma, vms->unmap_start, vms->unmap_end, mm_wr_locked); tlb_finish_mmu(&tlb); + vms->clear_ptes = false; +} + +static inline void +vms_close_vmas(struct vma_munmap_struct *vms, struct ma_state *mas_detach) +{ + struct vm_area_struct *vma; + + if (!vms->vma_count) + return; + + 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 = true; } /* @@ -2652,7 +2683,7 @@ static 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); + vms_clear_ptes(vms, mas_detach, !vms->unlock); /* Update high watermark before we lower total_vm */ update_hiwater_vm(mm); /* Stat accounting */ @@ -2663,7 +2694,7 @@ static 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, /* unreachable = */ false, vms->closed); vm_unacct_memory(vms->nr_accounted); validate_mm(mm); @@ -2804,14 +2835,18 @@ static int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, while (vma_iter_addr(vms->vmi) > vms->start) vma_iter_prev_range(vms->vmi); + /* There are now PTEs that need to be cleared */ + vms->clear_ptes = true; + return 0; userfaultfd_error: munmap_gather_failed: end_split_failed: - abort_munmap_vmas(mas_detach); + abort_munmap_vmas(mas_detach, /* closed = */ false); start_split_failed: map_count_exceeded: + validate_mm(vms->mm); return error; } @@ -2855,9 +2890,9 @@ do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, return 0; clear_tree_failed: - abort_munmap_vmas(&mas_detach); -gather_failed: + abort_munmap_vmas(&mas_detach, /* closed = */ false); validate_mm(mm); +gather_failed: return error; } @@ -2945,24 +2980,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; - - /* - * 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; - } + nr_pages = count_vma_pages_range(mm, addr, end, &nr_accounted); + /* + * 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; if (unlikely(!can_modify_mm(mm, addr, end))) return -EPERM; @@ -2979,14 +3009,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; @@ -3002,8 +3026,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; } @@ -3052,10 +3078,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); @@ -3064,6 +3088,9 @@ 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 */ + vms_clear_ptes(&vms, &mas_detach, /* mm_wr_locked = */ true); + vms_close_vmas(&vms, &mas_detach); error = call_mmap(file, vma); if (error) goto unmap_and_free_vma; @@ -3154,6 +3181,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr, expanded: perf_event_mmap(vma); + /* Unmap any existing mapping in the area */ + if (vms.nr_pages) + 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) || @@ -3201,14 +3232,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); validate_mm(mm); - return -ENOMEM; + return error; } static int __vm_munmap(unsigned long start, size_t len, bool unlock) @@ -3549,7 +3578,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);