From nobody Mon Nov 25 17:31:27 2024 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 926E1203709 for ; Fri, 25 Oct 2024 12:27:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729859230; cv=fail; b=s5c4Tgt7C1du2TIX2A6sdfLR+w6q/bRyvmL+LwnNCUxu/H6vE74owxCk4G4wQXdYMMrdf5kihLvvsz8bmk2bgTkm5MS4oGURDEHcetmMEYfW0iemf/2Ra2JxKCB9mDB8LJSWKZwkW6JEJKLXtSPVD2HMyJrPYfc2lrU/LZWrWWY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729859230; c=relaxed/simple; bh=mWY4Zvj892s8PHycPdXU9p0PJqG6P7RW1GnZFfrZ2+E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=hr6hB2GvKlyutY8j3gexXrt2KHBUYZkvLaEerNRlnP7wLfkJQucD0W5/1h7zsEBAnnq0YBoFgWz/74ctz3+f3tpr8+hdfnFLsVj8gq1qTk+INISCcDIGc/KyXKsMYBlhuW33JRUFojFscDfPYmXKwRhgtJNMj1t+yfMvfi4xmEo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=jk2sLPvx; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=sge1IFQ6; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="jk2sLPvx"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="sge1IFQ6" 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 49P8Babn014732; Fri, 25 Oct 2024 12:26:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=1RKAonmcILha8U/5gzL1MZCRAiyipTUTBI1zBY8/ua8=; b= jk2sLPvxcBTa+qktcW34pQG1spl3NzAuprtVz+URBnaOeklhuwG6UbYsyv62Z8dt TgbsaXJ0/BlQu6TdAzRf2uYoYG7hJ6ylOdjOoSgvFgvt7pwLJRHgEvj2czzK3EtK 1o6seh2pJjEPQ8VX8nhws1E9jezvOM176pgDUGm6kfxNe9w08mCfGpan4BsNuKk/ 3WbQdHH/tIIwhRRzkxlD+ionC7XG1rUSjKkrhu6HV576ZUFjmFcG7+EZ3N5cU9WW XIo4wPkVkJlrI7QZXs02ENgEdQMuloiaj79YsM3OrrQxRDQcFoJUjJJ32bOVKh0m Ep3QkJ7iULMbTADaAx8sqg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c5asmusx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 12:26:56 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49PBxpoZ016557; Fri, 25 Oct 2024 12:26:55 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2177.outbound.protection.outlook.com [104.47.57.177]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42emhdt4s4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 12:26:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cDcSHylas1xZc8YOYyoNeOelaWe00gN6T4J9MPhjnGQuMXcP+YUSOhFQFm6/ALMtgNxeyprYq33za1YouSwLYfBb1K/BnCsBoW4K5x5a9CyPKelBISO0dS5HxAjOYqd0dr+BUXHO7Q8WMV8BJkwWsH+SFN4mLWpa+iIFQcdqpL21PbejvgB0fyvTDnJNkcuXiPTj7uor+m8owccVC0O35YSLZzl8RyLxsjbHGMf/bAmYxVzsANiKTGYC/mJsuDC1MQ/LwfBu2N9XgpnpmhcKfvI3HJCxTArDn2bwxp8ZfNBsbv0AvaJR2WV7f4PuSmqitqTHyuPLnpYKhWADdn8CUA== 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=1RKAonmcILha8U/5gzL1MZCRAiyipTUTBI1zBY8/ua8=; b=cvkKnk1y1ZOvX3pNWS4OKkA0zn91DqnvvrCaZ0aj/I8HbgjGzowiWLQIgLVD+g/7i19M6ArSbdH4wZ8MhtyVXyhzhUQQb3amNw+dRjBJLGH7dO2826R0wYnFyqaT8x+SwvkEi5XdDsA10zO9egyEuHMLEcslQ1bYzcLSS4t328XO8yIOBqIJSAPk5oSfqCLWwwJ0gjUzylbz6EiMRESBFn1UjdhTeiC/zne6K9P0oRPTqCd2ZATIGtTttdT+9GEU2FDte4grgWrCaYfnIMGRyYy6h04Q1DDORJ1G54TWtO3KeBgSjFqip7bd9/UackedXhvMgsyBisCgJQUOlBRPMg== 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=1RKAonmcILha8U/5gzL1MZCRAiyipTUTBI1zBY8/ua8=; b=sge1IFQ6G1xYqSM5KxNLgBwuT0CQLmlVNVsmWWEAEecCU2fwei9zJaAdy7t4vsirwadq2QLGO1mKwNpALkL9+uZVjnHIdMMggsRs62pgtn8N/GkV0Eo0PgQrqPPH5zDczKNt8sex7kzYxqkuhzdhIAy5Cb7soW8nmFoKtAN4IH4= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by CO1PR10MB4484.namprd10.prod.outlook.com (2603:10b6:303:90::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.23; Fri, 25 Oct 2024 12:26:51 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8093.014; Fri, 25 Oct 2024 12:26:51 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu Subject: [PATCH v3 1/5] tools: testing: add additional vma_internal.h stubs Date: Fri, 25 Oct 2024 13:26:23 +0100 Message-ID: <74b27e159e261d2ac1fe66a130edad1d61fdc176.1729858176.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO4P123CA0376.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18e::21) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|CO1PR10MB4484:EE_ X-MS-Office365-Filtering-Correlation-Id: 2febee1c-88b2-4f95-e90f-08dcf4f04d91 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?V0orUsKOU5W0QrCZy3vutQ1kkVa/XsYApv1AyHvkFwYRK4tHUEYhrW+Oj29x?= =?us-ascii?Q?SV364NKfKdCiCHN1r2oPJU4iQ5a0FNQ/BU1OzviyCEpAgH5mwWcVTepju8Oq?= =?us-ascii?Q?3gUoaMNnO2BgqFkbnWodBvMyflBi9CdMAVtROO3k14s6B5vQUrzKM44n9Sv0?= =?us-ascii?Q?kpsiWvzhtS/O+vtAV9yBR1SCW+yL7gOkuB0ebkIFdMv8U2wccFzPZCVvEkyw?= =?us-ascii?Q?0hUqNAREq+5w4FK6gbYUo32vaskwG1iYSwWH+V7cV4n4IKwewzYXoKcNqtR1?= =?us-ascii?Q?OZ/MrgKq68Ooxf5ht30cMMFSi3FhHPjUC23cTJGHMUuB44RmL6XaxLvUpjT2?= =?us-ascii?Q?Zl8W8Tub6deHQiv3LeoI/ldR4vwG5FNeP47hIQbwNhyI6KO/XMi8/gnFV/vU?= =?us-ascii?Q?Fca1YclerZzKA2Gf0Cst908hvNsEqSTdegg8bNVoGvf0rLCaTJRIukDCRskM?= =?us-ascii?Q?wC6uiDWmQUkuKcFnOM/w9HZH6ZC3ZQxoNjs+6EVXgdMd4TedZxrYFwE7ZAgm?= =?us-ascii?Q?cOHGFVpt/TUgFOI+H/w03Sb3fJ26l4IdWOXUc9Q3xhgPROcJf6aNtmA96quR?= =?us-ascii?Q?tU6D7mc9XdbUkLVl+b9ZSXY6C23TXrW7gOeDaGVEMpqPLlk5ZavSmm3CHNh4?= =?us-ascii?Q?HPw9kVxKo0uGeNrhIFf0S4vUZRSQXqQpjfigbZ83Q/a5uxCjYdCgJwRR36Gb?= =?us-ascii?Q?S1VfE7zd76/v3LBgHabv0bCmTNm6qwAfdRhJkNuQT5VnCiML2G/cU0SZzPGB?= =?us-ascii?Q?c5/x3N5NFwLV+t96AA88FWsM3OD5z9T0jAmhboOP4m5Yr5KOfO2taAHlkNvH?= =?us-ascii?Q?QJNRI5ABkKRyZNMR56gFkkQCUdoWLwsjBAhIvXfp90zp/WPP5lIHZ7YJ2RbS?= =?us-ascii?Q?cV8ll5Q+XYhh25en9Rm2zfyirbtWi69VYofEzymO5HmrySS0lqiIbsXyE2Gc?= =?us-ascii?Q?agw8r6ajpqkWQ8nD56836eaFoVpt6qY3Nfs9yq/cVEOqW4NftNUO+6MpQezN?= =?us-ascii?Q?WbBwaT3YJq6ZJGZGNzvpxMhRO2WjbF4sl+YiBVagtPZtHmtQHsqfObjsi04V?= =?us-ascii?Q?NHhbIaugqML6zSrDINJN7385G43Se5GjE0EHFVTWRKPoziQQhrbbedp1mRHC?= =?us-ascii?Q?OZf8xT4I12ggH1SLkmTfPTuMjlhO2j/t+bIxm36qUosTf6OOEFopFlvV2TUQ?= =?us-ascii?Q?4JEgb6u6sOhCT98jdgwwhbrrRPI41ecWTEojx09En8MphvE/iI+elaawid8L?= =?us-ascii?Q?uIBFVB/dYyGquEmQv9bszKrW+O/su2pEOr2jAo8ss1oyfjrAf5vO5it+wcn7?= =?us-ascii?Q?u3g=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?x8p45yt9FKPcpbMPnRRprJrxXPIRdPsym8NQe00dySAY79JQgQ50XZRf3f5N?= =?us-ascii?Q?IZ3NakYJDldIpcz35egynBNPsO8xEmgZ+0tsFN++lLrDiZ2Hc5qYPigCChSf?= =?us-ascii?Q?As231gnS64Zyusomt7DQH7SiMqfDgX8URuOpG0VVNlVN5TT+kG9m38okpiI/?= =?us-ascii?Q?BKH5TUnuE076Te7z381TtLewUVVIk6jlQw3EAe0pnm/er7Ckb3PP178zJygf?= =?us-ascii?Q?15LD1nwj5HrzkRvQ+SihDGvKoGd3VDWitgxFMasi7lbQV2iqDP25LZwMNwNU?= =?us-ascii?Q?h9jlkYykiIeD/s3zokzLtrDkvACOD3BAkPqKO0CFXFJWSpZdro7ejce1z8OX?= =?us-ascii?Q?MGHG5jENwNcFWJr2Heu3UWAeqPXs0PgHl0Y1d95E5qYuoDOpUwhKm3JPVPgm?= =?us-ascii?Q?dKxMbt5YiMuiNAFBuJmCj+A0vxoIGztGrFIWNgqvlChpI0+z8GqDUMjL1dSW?= =?us-ascii?Q?mIqYiLQuN6/f/qn75Td3d2T/VrrMFcH6VSpNJ5qJ0i1oqXfK9fuujLrfsm/C?= =?us-ascii?Q?fQxymWjMoPm8AphRmJr9bOV3k/Ki0UF/pUbg1Hs4OYbY17THXqdE2xUwKin5?= =?us-ascii?Q?fnXc6OTqF5mmaLsyCtihZsrtCcNs9KMmCBxFgDHRF3AHbMhuh0ZDkbxxTJT/?= =?us-ascii?Q?b3oz0UPvsMeV+ToVZx9T5T0wXl521EScOD7kxt4j1yMy2ZEo1+68CIebDYK2?= =?us-ascii?Q?00fjNsaLNg+PQyKdb2OEC8SovjeKVEFWa0ZO4sHsuYckVUGjyqrNE2UjDaNm?= =?us-ascii?Q?bBcAkkiCQJU6ZpnmqBy+dwe1dLV3CnSJTLgJ296SCwYrA2hmBIpv6Ayrep/p?= =?us-ascii?Q?MCpoWEwIrxfXfzKzVYcH01wgkU6Ey9k8bA9fBwDDN5Sveuh9qu3O/1hdNgLD?= =?us-ascii?Q?HKmRYBo7US0Vhdby9kUWp+NIwBTgjef4QFjMaJNN62aoUvYbm+jjq/2TLyhW?= =?us-ascii?Q?3roephfGjiJis+XA4yd5DUfHlnYhZn7nEMzojupLks1vpdKOZ7uqia2f8Goz?= =?us-ascii?Q?0dmHVsK4E/iONlcAta42LTC48hRAY+S132ufdhjy4j0f0Wx62kBQ+jwxdXIO?= =?us-ascii?Q?g+uVuSZS7U+Oeirn9CO/+bUXWIaKXaxrwEUXeHbqxEDu/CxQkdXMOTJE9eNn?= =?us-ascii?Q?Gx3rXKEfK9K0749JHbtDJ0Ad85rGK1MraRqxINemu9TDbRE0wmA97zE9qihg?= =?us-ascii?Q?QsDkxjw0jFzS7YzQSOf+dRYpJ7BjfUQFXT4SmFWwlbFg5xDLWyLpzBf0Dae1?= =?us-ascii?Q?s6ulGYAMd4w4QV+TgaF3L8KHbyDgDnu4775eHzUg7INotBZ70TEV/3GALojb?= =?us-ascii?Q?bL3Bw4B3IQoMpwU0enxMGN3h/IZCXodWo3iA5iLERLt79vjhKBlmUpiTKxgd?= =?us-ascii?Q?2MzaBqBgQ3BKzHHJvvffA2u2C+4OxjEJOn6UZqi/aJM4pXCX1gqLY7eAQ1fD?= =?us-ascii?Q?yaOzalr8Hgn/d3fmC82rpzK7qt8lFYTYhEIZ/wjHceiSJzXItxqBidouOERM?= =?us-ascii?Q?mfHDmpaAxFEWK3vIja/pxv4LhdbAMoPscjzWkZ3UzpNmqBbiEBc2SthSsGeH?= =?us-ascii?Q?FxCZBFG6OnbT6Cmo7rxHN/r+/kri2bSjRTZHGouiA3upRpKICIkNj4EQTD6X?= =?us-ascii?Q?KFufmTlhZ4ZtSsgFK0BmKxwvLHI649S0TnU2ixq0wFcDOld8L/b0zIJh3O65?= =?us-ascii?Q?ydZHwQ=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Qineu5xaRWetUH6gU2Yn86RLod33WfYM17wl9VC5yOpaVxrVrT47vA7irwgQAYygVuia4XK+X6JvUfXaNEOjAhZxYPQkcUTeaxfwejgXfqFFMHaj4KSHPvGjRJDXsfXRNTPoDaVevbDjq1x9vkuX3EH3MV3aQq3BYuTSYq1AXPzvcrurRgLc4Kn+Tqs4IS4r9okiS3JE738LS/JHpMg9sYWNzosZGRbZRRXOkRhV931kCR/JAWPuHRVyWLura2Ikc2BXrBv90R3SNUguv3Fv4XuvD1T0JaM/2u1+uvMIYKsjF8ntpWTmlhLif7idWzr1N54nGsvtOVSo3Z8HdZVYlCzxP1CXGnkK4kMK6Iy8PikwUQp7vz7PRxebNFoymSdC9O7etQcrIiBbDkwmHZwGtpq/QFED3LtHiiCYI2whb6ur+oLuBtysnJSSXyVwtOnbKRcb+01fjBkL85WT6YuRVHw858EQSeQ4q+ZF2a6ufz7DBdRlr66jlP1iV8G3CHkSpzghPfClw44SyQqEZnsaRA/zQblccWPTLbSwmbSt2rYRekL5XfDnMSQk5hyuvy3N43IA/rhsA7CQjH3vRJOGNcsy7nqWLMBac21x11bqPRw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2febee1c-88b2-4f95-e90f-08dcf4f04d91 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2024 12:26:51.2913 (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: t1NX/qyhrqjVy5I/kPLm03VvmjUAE7xCgM6HIN9qnGwGLus1YZawizZH0yhZH2KpfUhBOG+yaGvtD3qQbfOM7R+Ft/5fE+jlhOSIfJhE+z0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4484 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-25_12,2024-10-25_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 phishscore=0 suspectscore=0 bulkscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410250095 X-Proofpoint-GUID: M3vftKXBPRqZs4T8LzkxgK52g6k_AsMD X-Proofpoint-ORIG-GUID: M3vftKXBPRqZs4T8LzkxgK52g6k_AsMD Content-Type: text/plain; charset="utf-8" Add some additional vma_internal.h stubs in preparation for __mmap_region() being moved to mm/vma.c. Without these the move would result in the tests no longer compiling. Signed-off-by: Lorenzo Stoakes --- tools/testing/vma/vma_internal.h | 115 ++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_inter= nal.h index c5b9da034511..e76ff579e1fd 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -44,7 +44,9 @@ #define VM_LOCKED 0x00002000 #define VM_IO 0x00004000 #define VM_DONTEXPAND 0x00040000 +#define VM_LOCKONFAULT 0x00080000 #define VM_ACCOUNT 0x00100000 +#define VM_NORESERVE 0x00200000 #define VM_MIXEDMAP 0x10000000 #define VM_STACK VM_GROWSDOWN #define VM_SHADOW_STACK VM_NONE @@ -53,6 +55,14 @@ #define VM_ACCESS_FLAGS (VM_READ | VM_WRITE | VM_EXEC) #define VM_SPECIAL (VM_IO | VM_DONTEXPAND | VM_PFNMAP | VM_MIXEDMAP) =20 +/* This mask represents all the VMA flag bits used by mlock */ +#define VM_LOCKED_MASK (VM_LOCKED | VM_LOCKONFAULT) + +#ifdef CONFIG_64BIT +/* VM is sealed, in vm_flags */ +#define VM_SEALED _BITUL(63) +#endif + #define FIRST_USER_ADDRESS 0UL #define USER_PGTABLES_CEILING 0UL =20 @@ -698,8 +708,9 @@ static inline void tlb_finish_mmu(struct mmu_gather *) { } =20 -static inline void get_file(struct file *) +static inline struct file *get_file(struct file *f) { + return f; } =20 static inline int vma_dup_policy(struct vm_area_struct *, struct vm_area_s= truct *) @@ -920,4 +931,106 @@ static inline bool signal_pending(void *) return false; } =20 +static inline bool is_file_hugepages(struct file *) +{ + return false; +} + +static inline int security_vm_enough_memory_mm(struct mm_struct *, long) +{ + return true; +} + +static inline bool may_expand_vm(struct mm_struct *, vm_flags_t, unsigned = long) +{ + return true; +} + +static inline void vm_flags_init(struct vm_area_struct *vma, + vm_flags_t flags) +{ + vma->__vm_flags =3D flags; +} + +static inline void vm_flags_set(struct vm_area_struct *vma, + vm_flags_t flags) +{ + vma_start_write(vma); + vma->__vm_flags |=3D flags; +} + +static inline void vm_flags_clear(struct vm_area_struct *vma, + vm_flags_t flags) +{ + vma_start_write(vma); + vma->__vm_flags &=3D ~flags; +} + +static inline int call_mmap(struct file *, struct vm_area_struct *) +{ + return 0; +} + +static inline int shmem_zero_setup(struct vm_area_struct *) +{ + return 0; +} + +static inline void vma_set_anonymous(struct vm_area_struct *vma) +{ + vma->vm_ops =3D NULL; +} + +static inline void ksm_add_vma(struct vm_area_struct *) +{ +} + +static inline void perf_event_mmap(struct vm_area_struct *) +{ +} + +static inline bool vma_is_dax(struct vm_area_struct *) +{ + return false; +} + +static inline struct vm_area_struct *get_gate_vma(struct mm_struct *) +{ + return NULL; +} + +bool vma_wants_writenotify(struct vm_area_struct *vma, pgprot_t vm_page_pr= ot); + +/* Update vma->vm_page_prot to reflect vma->vm_flags. */ +static inline void vma_set_page_prot(struct vm_area_struct *vma) +{ + unsigned long vm_flags =3D vma->vm_flags; + pgprot_t vm_page_prot; + + /* testing: we inline vm_pgprot_modify() to avoid clash with vma.h. */ + vm_page_prot =3D pgprot_modify(vma->vm_page_prot, vm_get_page_prot(vm_fla= gs)); + + if (vma_wants_writenotify(vma, vm_page_prot)) { + vm_flags &=3D ~VM_SHARED; + /* testing: we inline vm_pgprot_modify() to avoid clash with vma.h. */ + vm_page_prot =3D pgprot_modify(vm_page_prot, vm_get_page_prot(vm_flags)); + } + /* remove_protection_ptes reads vma->vm_page_prot without mmap_lock */ + WRITE_ONCE(vma->vm_page_prot, vm_page_prot); +} + +static inline bool arch_validate_flags(unsigned long) +{ + return true; +} + +static inline void vma_close(struct vm_area_struct *) +{ +} + +static inline int mmap_file(struct file *, struct vm_area_struct *) +{ + return 0; +} + #endif /* __MM_VMA_INTERNAL_H */ --=20 2.47.0 From nobody Mon Nov 25 17:31:27 2024 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C004D20402E for ; Fri, 25 Oct 2024 12:27:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729859239; cv=fail; b=fdzlyFPSDKkd9JYel303TfO0G9HbbJmC8kU9pGimk4zfGg9q5WvHIXQbXQGwwUd15StN5+uyVTkWSknoC678LR2wv7eIDcPGuNcfVHzCWsxJe7TSDvtO2fbkLp3a7cru6Kbu7SJGqjD8Bx2MwEnpjVJoTlesZg8ncWVWiLir88o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729859239; c=relaxed/simple; bh=vPqHs9Nf7qupIKP9+48cqzwgaroNUSpwzFhytzfc/Us=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=cdSMl3AsX8hww1yCqEFbjTMurb+0bpIJe3EwdR0x2579ov3Nq6FaNAxEWLdyRbFaQlXML5A8E7jGAZxder+3q6QuMc9jWGDEKiztnI7xL1Iqiub5Af3SSPNdUa3WZzOHZUKg9cc1h1KAA+BELtwNLlws9k/Jl3mRNPu5v5RN+u0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=iDdFFshc; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=J15mkOls; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="iDdFFshc"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="J15mkOls" 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 49P8BYFe014704; Fri, 25 Oct 2024 12:27:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=v2dv89kI7lw9WI2akap4rWRfGxfF/RsmR8cPxtvRT3Q=; b= iDdFFshcUMstesfit8GHcTErF7yUhtHFOmNpvYe6rjm2YOf8VSHRgDCCuBBTMwKI B3ZBDqiFsWu1C+M+oq3DBWg/dhjQpY0aQmNelmHtkebPACtVi9QYPzIh4dwjizQs 8bngK17ImM1STZBTZmiavgr9ZYPdNIRZ/yNrTDKWm0RK4YmT31c9DgerkFY3Mu+x yVpapRG5WC/o8ccFtdEaS79Il5TuksOS+q8KnkKfKrsymGN+YbtjkSwJIdVo+6rW AClm2vdyBudEoB/0vQJI80GdR7KNEyw55jUNOgGC8YDsg7zgoAnVHKn516/67993 tssUbJLCEdLxqIsfoXW03w== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c5asmut7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 12:27:03 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49PBxpRi016475; Fri, 25 Oct 2024 12:27:02 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2171.outbound.protection.outlook.com [104.47.58.171]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42emhdt4th-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 12:27:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mNkyJstE0exslBTkAXPcTcZ6znOL2Q1GSq+NQNqXvnAMCEETSk2aCYMlGLeQOL0RYQJajdik7fyLVzZff4ufd/w97V+AIZp0K9dBu1uH3i7beRawz4C3T1i+md1lPH84d/ZrcQ3DtsHqKEp9YwQfTTau1LXdBgrXzlFGeGxTIrFb4EdteaKL50fiFa3rxJwzGXUupZN2fMPLX0krsGZi69Cny2vuJJKHtRmrucxCTt3nK8RlRi9V4LGa/1hIUiShXskyYVdAo4yPbUT89fCmLZMkCiBMdSec3m+Co/TJaW7zZyInHQ35gT89gVsYxi2xBjHmCbEyP72rbLT0vxePxA== 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=v2dv89kI7lw9WI2akap4rWRfGxfF/RsmR8cPxtvRT3Q=; b=aal6jA9c8GqEaMfmpC0/vYyDclEsW/3p/LCwxs85/4LToaCq7Gdd7VR47PzIT9keZeEV7T+PfTYvKpZ7rjFpehAwhv8Ih2iooYX1ZEYrHL/Bxlqkf2M53lunr3Ff2/9t9h3GLv1WkSUgyVJmVDlXRiR8Isy1RaqOykzstSph5vyP5PGUH8xkejeLAb+DBQgaG3UTpIMXiAufiWZQm51BInSROokThF9811ypoPJTCz/zI5+gRVEosBF+LE0UavmF2GMByOSxwNXk4oGsJjJPJ9uqFyUJVxISgF0sETyf7BFTfrHDhP+0E34Gc7HOcJ0cS1x2lnvDpuzxd7KlDU+DVA== 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=v2dv89kI7lw9WI2akap4rWRfGxfF/RsmR8cPxtvRT3Q=; b=J15mkOlsjimKSakQyXM6u2Dsu+icU/hy2duH+ZbDzSGltN2L2LqoGz0yHKJJPv2NC1TnNm3nJDCE1yfVGca7rmPYqsOaCbLht0/h1BzqczhGVBYJffH2ZafCFjpXx6bE+8aeP9CtxhWftZMEMBzomGi+5ekthboUYWzxSEUXMMI= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by CO1PR10MB4484.namprd10.prod.outlook.com (2603:10b6:303:90::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.23; Fri, 25 Oct 2024 12:26:54 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8093.014; Fri, 25 Oct 2024 12:26:54 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu Subject: [PATCH v3 2/5] mm: isolate mmap internal logic to mm/vma.c Date: Fri, 25 Oct 2024 13:26:24 +0100 Message-ID: <93fc2c3aa37dd30590b7e4ee067dfd832007bf7e.1729858176.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO4P123CA0448.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a9::21) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|CO1PR10MB4484:EE_ X-MS-Office365-Filtering-Correlation-Id: ac415e02-f052-4556-7aed-08dcf4f04f69 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?i3aMan+sFFNzvmXV/nHe8+sMiCCEk2WpRC5jI1Z463XLQZY90stVIHJuS64u?= =?us-ascii?Q?OHKl+V1P4dB+VgY6vyyOm3aDwwxxBIMZ7AfM/ALX8EkPxmOMf5n5sZ7tUddU?= =?us-ascii?Q?wPheFR0c9Jd0PQhW0I+sl1UmGAalAO64xVnFccOyH/CADnhJq8YVcZzhsyec?= =?us-ascii?Q?9YHojPXaEb3RM6nzQCfvWFn1wYb9fRxaAoOr5VH66Gtbop5sJBycBeTsKQR7?= =?us-ascii?Q?I113we2bdRJ9JYozlBg0h0GVicSY0zQmg8JFm5AiEMroghJ2nT7cbl7tS3vK?= =?us-ascii?Q?HpDOTfoi8wNy5jRtZnYtOfZqp0Dc0mlSxiF+tRa+xaE/sjMxP8jOJmB5xORJ?= =?us-ascii?Q?zu1EeVu52cG/XzUhx8LaOT20sVHcO6uc2+PZbE5ebY0plrZ5SqtivI8d2g5M?= =?us-ascii?Q?2mi7uMKsp1oOkpwtkc8mPeUXh05JjdKi7rpx1zRPjs5ZLUh339Ag9OERFJD0?= =?us-ascii?Q?OZ4bOHqr4MMi+FD+JvBYQJBDyCj0Oet7IrkvD5qD9CKnNKzMqWXfqFrunPX1?= =?us-ascii?Q?SlAyJOcIrLfxrSLYerUObQcZDMSFDuu9i/z+f3iaX1jpgV1/F1j4q8WhtrZi?= =?us-ascii?Q?+1CPkeyZxGS6PgD/Mr1v+/BpB8Ki2L7I9Zpu8Re7qKKEJ19OEuaEfULIlJXb?= =?us-ascii?Q?rXdy7UctEbgCCluPlJLPKiYhhD0VtgdG3gNw5/3GDVRSx94aRxWJgMa+udqX?= =?us-ascii?Q?GRr/pp3u5ddSjP+fs8H3ZVngfGGXHGDyjoasb15J6KdLZjFocu17/PV4uS/h?= =?us-ascii?Q?ulFkY9hF2CBS5Rb8G4qwhUfakAZjsJnryycfsbMUPsSAUnvJe6OE4kW0U6/J?= =?us-ascii?Q?6RCqY3KCXIYtlxuXln+TWcVHpIRpcpqfmUbQGhs31nkPZoSrStRm7YgHCP/k?= =?us-ascii?Q?zrPviJj1QJcUPt5yXX5UUi2dqJg8PKYPR7XyxK1em/BR49EI2z9bbojLB3xt?= =?us-ascii?Q?mRXzna1GLyYpWQJvHosVsGyMaWKXCnZ9zIorgjaBldBx8IoF9YU9g2r1T/GI?= =?us-ascii?Q?4pLbUk9sugxRaTbc+RerIks0VDjjXYSQRN3dNY/UTFfNNc3a9LRhwfTJtcaz?= =?us-ascii?Q?otld/DiFRr1yH23jBCC4z4CFim8SZe/M6hLBB8DKxFc7/ORlt7Dz1UJ2vgSr?= =?us-ascii?Q?Edw0KQuQ1bYLDUzzWMcw9gsZ+DOknhnYHAnBqPub2+qlL+RQTkWfncQAKcai?= =?us-ascii?Q?gqo6rSI4B0d6JX1fZrEryYIYy75e6aMGdfKXi/RmVXoCBMH6eSlxNBHBOQ57?= =?us-ascii?Q?Hj626YF1iAU+1B9N6zIxoPg3sKgG0QpPq3i0ZuYizw7Lsyx8lQsLnOmw3Brm?= =?us-ascii?Q?vdZW5HYQzy21xV8Q9VXEUlv7?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?RnLo10JZ/TyF63gvlKijympeTRx26Au35ui8JxqFWtKmDjru6/D9d4FHq2HO?= =?us-ascii?Q?ck66kcl6Qjoirg7nLosihc5t3l4eKkO1OriMjyrr8+f1jvGHdePPO3GFOM7K?= =?us-ascii?Q?+L/X7ox17LodLAlC/XKksj2mSUZVN2q6a8KqFgzHpYLJ7E4HG/QruZo/370a?= =?us-ascii?Q?q+PRJbzLwwI14e/UF5ju4cESkd3h0E+N+8OwQX3KoF64JdBq9bz71GjZw0Ls?= =?us-ascii?Q?JiWcG7Ae9pSEJnIjdDvuTWCA/0zhppU5lz5d+uL8fkzT2CpZWPVIijhlwVWv?= =?us-ascii?Q?9ndIFnDIhVlFf8L0HYErZm7MLAqzk/9996noMp5h936oY+dRhqHqbW6/IGtf?= =?us-ascii?Q?vo601ynxFyqqebPC/7coSaTd/NnG6MxBo/ywZqrbRdB0blUtpTOw8HClg1wf?= =?us-ascii?Q?/THIoAG1ijA0te2HQRuCXP6KZaH5ku42zq0CMxjZGaVD2WUuLoYUj3lg1K7b?= =?us-ascii?Q?oAyMXErTQyHU+T+STyGE9S7yDZC8EfpSlUETUDY5XXtId9yRyr4SwCR9Zs2a?= =?us-ascii?Q?LGWxR771YfYzbepKJxnNxp+1jDKWx2jPZlLaLFNrJcFaIkUjkgbu4G9lr1KL?= =?us-ascii?Q?QK8QhCL/RCWmp7h2NJQRq29tYBLrSsc6jegoJXWgdP7xQskCUjOMVWa/Knd/?= =?us-ascii?Q?RdpGtlJetSmmXAHv2MIy5MdVD4psDud5iFwdGsjAfl2Ztr6oQbob0oDGz7T3?= =?us-ascii?Q?OvDMASKG+bK4x896QwYachKEx2BBVsLj6ZdMnvmW79VQvXjkHMByoqCe6w0W?= =?us-ascii?Q?yfbgl6Qr5TgQQIvMlBzjZPoWySj7RqaCnRQTdmyjbhp/VrXNVZpuzb5FJ+UB?= =?us-ascii?Q?Cdf60iyanieu8YMWRUjxvXUCGlLjjdjs1EZkmZHwy718ualEIS+7e0/mS9LB?= =?us-ascii?Q?r4539E5nQ0UL4ADc/tbPhPGJyacnsBvEuSWY0O+YQueIXbZCynD980QSwBAW?= =?us-ascii?Q?1fEdDNV4Lksm2r3Pxnfn0Tr7zBykNxIFONAAGrb4zn+VsFSYOoTwTSGF/kLn?= =?us-ascii?Q?VWb5dzNJ6af54SesTSx17NfBqdi3oLzidBJAazyt9g5SJSqY+gOXMDH+xBDu?= =?us-ascii?Q?Y8uDknSlniQIJVEC/01DbkJlTU0hc8VkaZEguXvcyAXIeWmVPWJl7WDZsT22?= =?us-ascii?Q?F2QIWqSlxnYWAwkSOqBg6ZLq8VT4PKvc98Pfbs/An/ap3nHqx3KL+uuWtaAC?= =?us-ascii?Q?BVtacMSbV18jhmQ5kvkwXcQmMyg92diQXxlqH0uumC4PWbG36Tje+KAGdNqp?= =?us-ascii?Q?TXoeskckSgHa6eZ64cKro7MSOd8qxKPBiAYKirQE+LBbFGOrm9+pUv8Gv8ky?= =?us-ascii?Q?dJxq9BkBjXEppvE+gZfzIicrFEGiR26sLZs7BpN2xzz/3/H9QonMKzAzIa8P?= =?us-ascii?Q?d+bJ9aF1JXw52P1ZruizblYnH15kByO9JpRG978LozpbUoGhpnfTYaMwprXV?= =?us-ascii?Q?Nf/zhNk8UldHFPXbVErmzr/Y2gX5dQ15BT3piVVaMf5xBD1QdgkZzI+aEM9u?= =?us-ascii?Q?xaWIZf/xqDBYdBZLcPgjXj3K/JCMmtR8dQ3m8vB79mNjVF46Adbmxqy+c6KX?= =?us-ascii?Q?urCW08RYbbAMMO+Bc8ejpI6FuJpLhV8DaVoMeYQ7AXPlb5ExGZt0o8xDI5XI?= =?us-ascii?Q?NZPwzLE9AC01DmaawWcU2ExoaNMwoA1aV/0osMBOgDFpvP3MY6IrRP+QRd7P?= =?us-ascii?Q?0NQkNA=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: kwvxFeBzFuN+R8p/1W1GzTFEJojlxqOpkJYzzVVq3TvkfTHVWW37aXEDGAaZTICuG2y6geEUlFOZe3hXpr5C3cLKpbd396g4CzKD5Mknq4Vqc7zPKkhYYsnVdICeosZTbZuX7WrelYU8+xgnwff9C93zhQaiZO45H0/7yN1AhyBEviCmxQiutISE81kU+n/xFKZnqSNMNpBMyOsjY89JKvjOdlw5iLCidQN5/KFGkoOy4zOvFJ0Xpmv65trMKWtfFGnOuzXwbXCNm8Oj5QHpo2vkLivAvm0FWd1tEA6/pqjJw4KPJn6uIr/oAia+vJga06UINKz8GlQs6ZaW4S/ljaPoT7C2KWPIeA0YV9JNW5YTuhSW7rvityG0FXcOXWZOGgKMX7MDZ+HuZyY8CDAPhR8wXrtScRLyrg1v/YT7gfSiemMChERfsP6ig9kP5sWnSsB61bJLv5Ss5lKfporgPAftoHlTQIpHlOpl+wpIwdAnefrSRdGX8QmWgS2csZ25CfeLqqisjuvy3/sp1g/5RzASB9NuCHCHVCeaUZzir4XHIpIfdsZwrz+D5JiCobOiM9B6Zad444Sb15QCJdnc+Nl3gAmKJQUJIsROi1lrITo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac415e02-f052-4556-7aed-08dcf4f04f69 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2024 12:26:54.4095 (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: XZb6AR6beI8sEUi0jr6vDhWgWwQgFzMkemcYS1dft3EGtm5CydJFCW9Fl4CHugRyCVUla5oUL60cFgdfq7j1ChqDt6lm90C0Z+UkVu29xiI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4484 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-25_12,2024-10-25_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 phishscore=0 suspectscore=0 bulkscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410250095 X-Proofpoint-GUID: Rvno4F1x0mJy_mdNFTjy4FNT3LgaVXOE X-Proofpoint-ORIG-GUID: Rvno4F1x0mJy_mdNFTjy4FNT3LgaVXOE Content-Type: text/plain; charset="utf-8" In previous commits we effected improvements to the mmap() logic in mmap_region() and its newly introduced internal implementation function __mmap_region(). However as these changes are intended to be backported, we kept the delta as small as is possible and made as few changes as possible to the newly introduced mm/vma.* files. Take the opportunity to move this logic to mm/vma.c which not only isolates it, but also makes it available for later userland testing which can help us catch such logic errors far earlier. Reviewed-by: Vlastimil Babka Signed-off-by: Lorenzo Stoakes --- mm/mmap.c | 234 --------------------------------- mm/vma.c | 323 +++++++++++++++++++++++++++++++++++++++++++++- mm/vma.h | 97 +------------- mm/vma_internal.h | 5 + 4 files changed, 329 insertions(+), 330 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index e686d57ed9f7..0affd1a0687f 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -577,22 +577,6 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_arg_struct __use= r *, arg) } #endif /* __ARCH_WANT_SYS_OLD_MMAP */ =20 -/* - * We account for memory if it's a private writeable mapping, - * not hugepages and VM_NORESERVE wasn't set. - */ -static inline bool accountable_mapping(struct file *file, vm_flags_t vm_fl= ags) -{ - /* - * hugetlb has its own accounting separate from the core VM - * VM_HUGETLB may not be set yet so we cannot check for that flag. - */ - if (file && is_file_hugepages(file)) - return false; - - return (vm_flags & (VM_NORESERVE | VM_SHARED | VM_WRITE)) =3D=3D VM_WRITE; -} - /** * unmapped_area() - Find an area between the low_limit and the high_limit= with * the correct alignment and offset, all from @info. Note: current->mm is = used @@ -1361,224 +1345,6 @@ int do_munmap(struct mm_struct *mm, unsigned long s= tart, size_t len, return do_vmi_munmap(&vmi, mm, start, len, uf, false); } =20 -static unsigned long __mmap_region(struct file *file, unsigned long addr, - unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, - struct list_head *uf) -{ - struct mm_struct *mm =3D current->mm; - struct vm_area_struct *vma =3D NULL; - pgoff_t pglen =3D PHYS_PFN(len); - unsigned long charged =3D 0; - struct vma_munmap_struct vms; - struct ma_state mas_detach; - struct maple_tree mt_detach; - unsigned long end =3D addr + len; - int error; - VMA_ITERATOR(vmi, mm, addr); - VMG_STATE(vmg, mm, &vmi, addr, end, vm_flags, pgoff); - - vmg.file =3D file; - /* Find the first overlapping VMA */ - vma =3D vma_find(&vmi, end); - init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock =3D */ false); - if (vma) { - mt_init_flags(&mt_detach, vmi.mas.tree->ma_flags & MT_FLAGS_LOCK_MASK); - mt_on_stack(mt_detach); - mas_init(&mas_detach, &mt_detach, /* addr =3D */ 0); - /* Prepare to unmap any existing mapping in the area */ - error =3D vms_gather_munmap_vmas(&vms, &mas_detach); - if (error) - goto gather_failed; - - vmg.next =3D vms.next; - vmg.prev =3D vms.prev; - vma =3D NULL; - } else { - vmg.next =3D vma_iter_next_rewind(&vmi, &vmg.prev); - } - - /* Check against address space limit. */ - if (!may_expand_vm(mm, vm_flags, pglen - vms.nr_pages)) { - error =3D -ENOMEM; - goto abort_munmap; - } - - /* - * Private writable mapping: check memory availability - */ - if (accountable_mapping(file, vm_flags)) { - charged =3D pglen; - charged -=3D vms.nr_accounted; - if (charged) { - error =3D security_vm_enough_memory_mm(mm, charged); - if (error) - goto abort_munmap; - } - - vms.nr_accounted =3D 0; - vm_flags |=3D VM_ACCOUNT; - vmg.flags =3D vm_flags; - } - - /* - * clear PTEs while the vma is still in the tree so that rmap - * cannot race with the freeing later in the truncate scenario. - * This is also needed for mmap_file(), which is why vm_ops - * close function is called. - */ - vms_clean_up_area(&vms, &mas_detach); - vma =3D vma_merge_new_range(&vmg); - if (vma) - goto expanded; - /* - * Determine the object being mapped and call the appropriate - * specific mapper. the address has already been validated, but - * not unmapped, but the maps are removed from the list. - */ - vma =3D vm_area_alloc(mm); - if (!vma) { - error =3D -ENOMEM; - goto unacct_error; - } - - vma_iter_config(&vmi, addr, end); - vma_set_range(vma, addr, end, pgoff); - vm_flags_init(vma, vm_flags); - vma->vm_page_prot =3D vm_get_page_prot(vm_flags); - - if (vma_iter_prealloc(&vmi, vma)) { - error =3D -ENOMEM; - goto free_vma; - } - - if (file) { - vma->vm_file =3D get_file(file); - error =3D mmap_file(file, vma); - if (error) - goto unmap_and_free_file_vma; - - /* Drivers cannot alter the address of the VMA. */ - WARN_ON_ONCE(addr !=3D vma->vm_start); - /* - * Drivers should not permit writability when previously it was - * disallowed. - */ - VM_WARN_ON_ONCE(vm_flags !=3D vma->vm_flags && - !(vm_flags & VM_MAYWRITE) && - (vma->vm_flags & VM_MAYWRITE)); - - vma_iter_config(&vmi, addr, end); - /* - * If vm_flags changed after mmap_file(), we should try merge - * vma again as we may succeed this time. - */ - if (unlikely(vm_flags !=3D vma->vm_flags && vmg.prev)) { - struct vm_area_struct *merge; - - vmg.flags =3D vma->vm_flags; - /* If this fails, state is reset ready for a reattempt. */ - merge =3D vma_merge_new_range(&vmg); - - if (merge) { - /* - * ->mmap() can change vma->vm_file and fput - * the original file. So fput the vma->vm_file - * here or we would add an extra fput for file - * and cause general protection fault - * ultimately. - */ - fput(vma->vm_file); - vm_area_free(vma); - vma =3D merge; - /* Update vm_flags to pick up the change. */ - vm_flags =3D vma->vm_flags; - goto file_expanded; - } - vma_iter_config(&vmi, addr, end); - } - - vm_flags =3D vma->vm_flags; - } else if (vm_flags & VM_SHARED) { - error =3D shmem_zero_setup(vma); - if (error) - goto free_iter_vma; - } else { - vma_set_anonymous(vma); - } - -#ifdef CONFIG_SPARC64 - /* TODO: Fix SPARC ADI! */ - WARN_ON_ONCE(!arch_validate_flags(vm_flags)); -#endif - - /* Lock the VMA since it is modified after insertion into VMA tree */ - vma_start_write(vma); - vma_iter_store(&vmi, vma); - mm->map_count++; - vma_link_file(vma); - - /* - * vma_merge_new_range() calls khugepaged_enter_vma() too, the below - * call covers the non-merge case. - */ - khugepaged_enter_vma(vma, vma->vm_flags); - -file_expanded: - file =3D vma->vm_file; - ksm_add_vma(vma); -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, pglen); - if (vm_flags & VM_LOCKED) { - if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) || - is_vm_hugetlb_page(vma) || - vma =3D=3D get_gate_vma(current->mm)) - vm_flags_clear(vma, VM_LOCKED_MASK); - else - mm->locked_vm +=3D pglen; - } - - if (file) - uprobe_mmap(vma); - - /* - * New (or expanded) vma always get soft dirty status. - * Otherwise user-space soft-dirty page tracker won't - * be able to distinguish situation when vma area unmapped, - * then new mapped in-place (which must be aimed as - * a completely new data area). - */ - vm_flags_set(vma, VM_SOFTDIRTY); - - vma_set_page_prot(vma); - - return addr; - -unmap_and_free_file_vma: - fput(vma->vm_file); - vma->vm_file =3D NULL; - - vma_iter_set(&vmi, vma->vm_end); - /* Undo any partial mapping done by a device driver. */ - unmap_region(&vmi.mas, vma, vmg.prev, vmg.next); -free_iter_vma: - vma_iter_free(&vmi); -free_vma: - vm_area_free(vma); -unacct_error: - if (charged) - vm_unacct_memory(charged); - -abort_munmap: - vms_abort_munmap_vmas(&vms, &mas_detach); -gather_failed: - return error; -} - unsigned long mmap_region(struct file *file, unsigned long addr, unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, struct list_head *uf) diff --git a/mm/vma.c b/mm/vma.c index bb7cfa2dc282..0a2965be582d 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -1103,7 +1103,7 @@ static inline void vms_clear_ptes(struct vma_munmap_s= truct *vms, vms->clear_ptes =3D false; } =20 -void vms_clean_up_area(struct vma_munmap_struct *vms, +static void vms_clean_up_area(struct vma_munmap_struct *vms, struct ma_state *mas_detach) { struct vm_area_struct *vma; @@ -1126,7 +1126,7 @@ void vms_clean_up_area(struct vma_munmap_struct *vms, * used for the munmap() and may downgrade the lock - if requested. Every= thing * needed to be done once the vma maple tree is updated. */ -void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, +static void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, struct ma_state *mas_detach) { struct vm_area_struct *vma; @@ -1167,6 +1167,23 @@ void vms_complete_munmap_vmas(struct vma_munmap_stru= ct *vms, __mt_destroy(mas_detach->tree); } =20 +/* + * reattach_vmas() - Undo any munmap work and free resources + * @mas_detach: The maple state with the detached maple tree + * + * Reattach any detached vmas and free up the maple tree used to track the= vmas. + */ +static void reattach_vmas(struct ma_state *mas_detach) +{ + struct vm_area_struct *vma; + + mas_set(mas_detach, 0); + mas_for_each(mas_detach, vma, ULONG_MAX) + vma_mark_detached(vma, false); + + __mt_destroy(mas_detach->tree); +} + /* * vms_gather_munmap_vmas() - Put all VMAs within a range into a maple tree * for removal at a later date. Handles splitting first and last if neces= sary @@ -1177,7 +1194,7 @@ void vms_complete_munmap_vmas(struct vma_munmap_struc= t *vms, * * Return: 0 on success, error otherwise */ -int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, +static int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, struct ma_state *mas_detach) { struct vm_area_struct *next =3D NULL; @@ -1315,6 +1332,39 @@ int vms_gather_munmap_vmas(struct vma_munmap_struct = *vms, return error; } =20 +/* + * init_vma_munmap() - Initializer wrapper for vma_munmap_struct + * @vms: The vma munmap struct + * @vmi: The vma iterator + * @vma: The first vm_area_struct to munmap + * @start: The aligned start address to munmap + * @end: The aligned end address to munmap + * @uf: The userfaultfd list_head + * @unlock: Unlock after the operation. Only unlocked on success + */ +static void init_vma_munmap(struct vma_munmap_struct *vms, + struct vma_iterator *vmi, struct vm_area_struct *vma, + unsigned long start, unsigned long end, struct list_head *uf, + bool unlock) +{ + vms->vmi =3D vmi; + vms->vma =3D vma; + if (vma) { + vms->start =3D start; + vms->end =3D end; + } else { + vms->start =3D vms->end =3D 0; + } + vms->unlock =3D unlock; + vms->uf =3D uf; + vms->vma_count =3D 0; + vms->nr_pages =3D vms->locked_vm =3D vms->nr_accounted =3D 0; + vms->exec_vm =3D vms->stack_vm =3D vms->data_vm =3D 0; + vms->unmap_start =3D FIRST_USER_ADDRESS; + vms->unmap_end =3D USER_PGTABLES_CEILING; + vms->clear_ptes =3D false; +} + /* * do_vmi_align_munmap() - munmap the aligned region from @start to @end. * @vmi: The vma iterator @@ -2069,3 +2119,270 @@ void mm_drop_all_locks(struct mm_struct *mm) =20 mutex_unlock(&mm_all_locks_mutex); } + +/* + * We account for memory if it's a private writeable mapping, + * not hugepages and VM_NORESERVE wasn't set. + */ +static bool accountable_mapping(struct file *file, vm_flags_t vm_flags) +{ + /* + * hugetlb has its own accounting separate from the core VM + * VM_HUGETLB may not be set yet so we cannot check for that flag. + */ + if (file && is_file_hugepages(file)) + return false; + + return (vm_flags & (VM_NORESERVE | VM_SHARED | VM_WRITE)) =3D=3D VM_WRITE; +} + +/* + * vms_abort_munmap_vmas() - Undo as much as possible from an aborted munm= ap() + * operation. + * @vms: The vma unmap structure + * @mas_detach: The maple state with the detached maple tree + * + * Reattach any detached vmas, free up the maple tree used to track the vm= as. + * If that's not possible because the ptes are cleared (and vm_ops->closed= () may + * have been called), then a NULL is written over the vmas and the vmas are + * removed (munmap() completed). + */ +static void vms_abort_munmap_vmas(struct vma_munmap_struct *vms, + struct ma_state *mas_detach) +{ + struct ma_state *mas =3D &vms->vmi->mas; + + if (!vms->nr_pages) + return; + + if (vms->clear_ptes) + return reattach_vmas(mas_detach); + + /* + * Aborting cannot just call the vm_ops open() because they are often + * not symmetrical and state data has been lost. Resort to the old + * failure method of leaving a gap where the MAP_FIXED mapping failed. + */ + mas_set_range(mas, vms->start, vms->end - 1); + mas_store_gfp(mas, NULL, GFP_KERNEL|__GFP_NOFAIL); + /* Clean up the insertion of the unfortunate gap */ + vms_complete_munmap_vmas(vms, mas_detach); +} + +unsigned long __mmap_region(struct file *file, unsigned long addr, + unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, + struct list_head *uf) +{ + struct mm_struct *mm =3D current->mm; + struct vm_area_struct *vma =3D NULL; + pgoff_t pglen =3D PHYS_PFN(len); + unsigned long charged =3D 0; + struct vma_munmap_struct vms; + struct ma_state mas_detach; + struct maple_tree mt_detach; + unsigned long end =3D addr + len; + int error; + VMA_ITERATOR(vmi, mm, addr); + VMG_STATE(vmg, mm, &vmi, addr, end, vm_flags, pgoff); + + vmg.file =3D file; + /* Find the first overlapping VMA */ + vma =3D vma_find(&vmi, end); + init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock =3D */ false); + if (vma) { + mt_init_flags(&mt_detach, vmi.mas.tree->ma_flags & MT_FLAGS_LOCK_MASK); + mt_on_stack(mt_detach); + mas_init(&mas_detach, &mt_detach, /* addr =3D */ 0); + /* Prepare to unmap any existing mapping in the area */ + error =3D vms_gather_munmap_vmas(&vms, &mas_detach); + if (error) + goto gather_failed; + + vmg.next =3D vms.next; + vmg.prev =3D vms.prev; + vma =3D NULL; + } else { + vmg.next =3D vma_iter_next_rewind(&vmi, &vmg.prev); + } + + /* Check against address space limit. */ + if (!may_expand_vm(mm, vm_flags, pglen - vms.nr_pages)) { + error =3D -ENOMEM; + goto abort_munmap; + } + + /* + * Private writable mapping: check memory availability + */ + if (accountable_mapping(file, vm_flags)) { + charged =3D pglen; + charged -=3D vms.nr_accounted; + if (charged) { + error =3D security_vm_enough_memory_mm(mm, charged); + if (error) + goto abort_munmap; + } + + vms.nr_accounted =3D 0; + vm_flags |=3D VM_ACCOUNT; + vmg.flags =3D vm_flags; + } + + /* + * clear PTEs while the vma is still in the tree so that rmap + * cannot race with the freeing later in the truncate scenario. + * This is also needed for mmap_file(), which is why vm_ops + * close function is called. + */ + vms_clean_up_area(&vms, &mas_detach); + vma =3D vma_merge_new_range(&vmg); + if (vma) + goto expanded; + /* + * Determine the object being mapped and call the appropriate + * specific mapper. the address has already been validated, but + * not unmapped, but the maps are removed from the list. + */ + vma =3D vm_area_alloc(mm); + if (!vma) { + error =3D -ENOMEM; + goto unacct_error; + } + + vma_iter_config(&vmi, addr, end); + vma_set_range(vma, addr, end, pgoff); + vm_flags_init(vma, vm_flags); + vma->vm_page_prot =3D vm_get_page_prot(vm_flags); + + if (vma_iter_prealloc(&vmi, vma)) { + error =3D -ENOMEM; + goto free_vma; + } + + if (file) { + vma->vm_file =3D get_file(file); + error =3D mmap_file(file, vma); + if (error) + goto unmap_and_free_file_vma; + + /* Drivers cannot alter the address of the VMA. */ + WARN_ON_ONCE(addr !=3D vma->vm_start); + /* + * Drivers should not permit writability when previously it was + * disallowed. + */ + VM_WARN_ON_ONCE(vm_flags !=3D vma->vm_flags && + !(vm_flags & VM_MAYWRITE) && + (vma->vm_flags & VM_MAYWRITE)); + + vma_iter_config(&vmi, addr, end); + /* + * If vm_flags changed after mmap_file(), we should try merge + * vma again as we may succeed this time. + */ + if (unlikely(vm_flags !=3D vma->vm_flags && vmg.prev)) { + struct vm_area_struct *merge; + + vmg.flags =3D vma->vm_flags; + /* If this fails, state is reset ready for a reattempt. */ + merge =3D vma_merge_new_range(&vmg); + + if (merge) { + /* + * ->mmap() can change vma->vm_file and fput + * the original file. So fput the vma->vm_file + * here or we would add an extra fput for file + * and cause general protection fault + * ultimately. + */ + fput(vma->vm_file); + vm_area_free(vma); + vma =3D merge; + /* Update vm_flags to pick up the change. */ + vm_flags =3D vma->vm_flags; + goto file_expanded; + } + vma_iter_config(&vmi, addr, end); + } + + vm_flags =3D vma->vm_flags; + } else if (vm_flags & VM_SHARED) { + error =3D shmem_zero_setup(vma); + if (error) + goto free_iter_vma; + } else { + vma_set_anonymous(vma); + } + +#ifdef CONFIG_SPARC64 + /* TODO: Fix SPARC ADI! */ + WARN_ON_ONCE(!arch_validate_flags(vm_flags)); +#endif + + /* Lock the VMA since it is modified after insertion into VMA tree */ + vma_start_write(vma); + vma_iter_store(&vmi, vma); + mm->map_count++; + vma_link_file(vma); + + /* + * vma_merge_new_range() calls khugepaged_enter_vma() too, the below + * call covers the non-merge case. + */ + khugepaged_enter_vma(vma, vma->vm_flags); + +file_expanded: + file =3D vma->vm_file; + ksm_add_vma(vma); +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, pglen); + if (vm_flags & VM_LOCKED) { + if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) || + is_vm_hugetlb_page(vma) || + vma =3D=3D get_gate_vma(current->mm)) + vm_flags_clear(vma, VM_LOCKED_MASK); + else + mm->locked_vm +=3D pglen; + } + + if (file) + uprobe_mmap(vma); + + /* + * New (or expanded) vma always get soft dirty status. + * Otherwise user-space soft-dirty page tracker won't + * be able to distinguish situation when vma area unmapped, + * then new mapped in-place (which must be aimed as + * a completely new data area). + */ + vm_flags_set(vma, VM_SOFTDIRTY); + + vma_set_page_prot(vma); + + return addr; + +unmap_and_free_file_vma: + fput(vma->vm_file); + vma->vm_file =3D NULL; + + vma_iter_set(&vmi, vma->vm_end); + /* Undo any partial mapping done by a device driver. */ + unmap_region(&vmi.mas, vma, vmg.prev, vmg.next); +free_iter_vma: + vma_iter_free(&vmi); +free_vma: + vm_area_free(vma); +unacct_error: + if (charged) + vm_unacct_memory(charged); + +abort_munmap: + vms_abort_munmap_vmas(&vms, &mas_detach); +gather_failed: + return error; +} diff --git a/mm/vma.h b/mm/vma.h index d58068c0ff2e..388d34748674 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -165,99 +165,6 @@ static inline int vma_iter_store_gfp(struct vma_iterat= or *vmi, return 0; } =20 -#ifdef CONFIG_MMU -/* - * init_vma_munmap() - Initializer wrapper for vma_munmap_struct - * @vms: The vma munmap struct - * @vmi: The vma iterator - * @vma: The first vm_area_struct to munmap - * @start: The aligned start address to munmap - * @end: The aligned end address to munmap - * @uf: The userfaultfd list_head - * @unlock: Unlock after the operation. Only unlocked on success - */ -static inline void init_vma_munmap(struct vma_munmap_struct *vms, - struct vma_iterator *vmi, struct vm_area_struct *vma, - unsigned long start, unsigned long end, struct list_head *uf, - bool unlock) -{ - vms->vmi =3D vmi; - vms->vma =3D vma; - if (vma) { - vms->start =3D start; - vms->end =3D end; - } else { - vms->start =3D vms->end =3D 0; - } - vms->unlock =3D unlock; - vms->uf =3D uf; - vms->vma_count =3D 0; - vms->nr_pages =3D vms->locked_vm =3D vms->nr_accounted =3D 0; - vms->exec_vm =3D vms->stack_vm =3D vms->data_vm =3D 0; - vms->unmap_start =3D FIRST_USER_ADDRESS; - vms->unmap_end =3D USER_PGTABLES_CEILING; - vms->clear_ptes =3D false; -} -#endif - -int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, - struct ma_state *mas_detach); - -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); - -/* - * reattach_vmas() - Undo any munmap work and free resources - * @mas_detach: The maple state with the detached maple tree - * - * Reattach any detached vmas and free up the maple tree used to track the= vmas. - */ -static inline void reattach_vmas(struct ma_state *mas_detach) -{ - struct vm_area_struct *vma; - - mas_set(mas_detach, 0); - mas_for_each(mas_detach, vma, ULONG_MAX) - vma_mark_detached(vma, false); - - __mt_destroy(mas_detach->tree); -} - -/* - * vms_abort_munmap_vmas() - Undo as much as possible from an aborted munm= ap() - * operation. - * @vms: The vma unmap structure - * @mas_detach: The maple state with the detached maple tree - * - * Reattach any detached vmas, free up the maple tree used to track the vm= as. - * If that's not possible because the ptes are cleared (and vm_ops->closed= () may - * have been called), then a NULL is written over the vmas and the vmas are - * removed (munmap() completed). - */ -static inline void vms_abort_munmap_vmas(struct vma_munmap_struct *vms, - struct ma_state *mas_detach) -{ - struct ma_state *mas =3D &vms->vmi->mas; - if (!vms->nr_pages) - return; - - if (vms->clear_ptes) - return reattach_vmas(mas_detach); - - /* - * Aborting cannot just call the vm_ops open() because they are often - * not symmetrical and state data has been lost. Resort to the old - * failure method of leaving a gap where the MAP_FIXED mapping failed. - */ - mas_set_range(mas, vms->start, vms->end - 1); - mas_store_gfp(mas, NULL, GFP_KERNEL|__GFP_NOFAIL); - /* Clean up the insertion of the unfortunate gap */ - vms_complete_munmap_vmas(vms, mas_detach); -} - int do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, struct mm_struct *mm, unsigned long start, @@ -336,6 +243,10 @@ 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); =20 +unsigned long __mmap_region(struct file *file, unsigned long addr, + unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, + struct list_head *uf); + static inline bool vma_wants_manual_pte_write_upgrade(struct vm_area_struc= t *vma) { /* diff --git a/mm/vma_internal.h b/mm/vma_internal.h index b930ab12a587..fc5f172a36bd 100644 --- a/mm/vma_internal.h +++ b/mm/vma_internal.h @@ -17,8 +17,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -32,11 +34,14 @@ #include #include #include +#include #include #include #include #include #include +#include +#include #include #include #include --=20 2.47.0 From nobody Mon Nov 25 17:31:27 2024 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 644A3204033 for ; Fri, 25 Oct 2024 12:27:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729859240; cv=fail; b=DH84xhYYjpTT4YpXiVaRtUqnQYot/r2kBBI/3JCzGHVbExVbxdw7Bz48KY0CHgGMHKzhmLwBCaDxs0goI3F4GEs5lNM+apUhrGH1818akh27N25m21YZjH14VCLF8fcUbNJYV89fbUZ+Ao/d+JhPV+CsRqUxu0JYGJIxpwA+1og= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729859240; c=relaxed/simple; bh=qKR44KByMohzwwmmH5JP4+FmtjoTCjH0fwarecyq5bM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=LPNG4NdkXAAk29jhlTiOAhw7bqRUPeGNyBXuiQbmATHLVvS2EBuJG8Myoo4w9YlIo97j8aEBRV4gKLXf9L9+PGkP83AIiMfvV6tqd3NPkmX8foQRZ6XME1Ptjwmw6N8n0pioxxwex153gkvAojrGJOQc4qT59xtDk81vhdHFri8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=m6k4klEh; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=ynLSN769; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="m6k4klEh"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="ynLSN769" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49P8BZn4005842; Fri, 25 Oct 2024 12:27:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=tW/u9DgrsB/MKCUWnxSg/nTn3ydO0p05DZVgDkldlBM=; b= m6k4klEhZMTAqv1rfH8Kjx7SFwysJqy/4V3O1njAw/SiEUWNEV3GoMgw+Q2YG/sL qMptBZ2AVcsVCfA1pikazNQO33ZhvDy0thO0uT5RznlpIe4T9XIxuwPMlvR5zQy5 puCGTKolg6hx8gQLGb/lR0k8L3BGkyszCx1bxJKFKlcsBfbKGkVxJJDwp5mgMr7j ipPfMu6XQ8Rr7l5ik8ywzA8If34Y7hqXZ4ASfviTVBP2bBDr1kwHmdHzjMrV9SM3 SC38VGjrStWZBOjD2Q2psUGJE9+RRvu/7CShWxrcBXrSlNp0Fyq/QxeFD/gsa/08 aYucDczmkZ86uwiqEYDrrQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c53uvttx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 12:27:04 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49PBxpRl016475; Fri, 25 Oct 2024 12:27:02 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2171.outbound.protection.outlook.com [104.47.58.171]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42emhdt4th-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 12:27:02 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rsdrgkE9ZFZFPuiQsGU/nQ2iWNimlBe7hzpNeoEEswJARGk2dX8xLVXfC0EIIFrHW3tmG4jqF4+tLE3eExWOz05ZxhW2ccg5/YLVCR+W70Yr813loNtiv5X8yJGTugGgRjtQQDUVzAXqw5OV3jwpXeuXKTAcdRrTbRCjcmAzr5+oI0kNlaeUsowEm9rZf0+LO9neaKG32kISfs2NJH7yQCVu9E9PlKNlCQ8BPMHaAYoofbxTH9ilDJvh6L+CrUAjbe1ttdgTQuhO2/ca4fhGzn7vAwPZwVPbVwLZuZ81AWmwKX11kSKd0EoAZemphltv5HihdAiONy56UYItDjf9aw== 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=tW/u9DgrsB/MKCUWnxSg/nTn3ydO0p05DZVgDkldlBM=; b=RQGXV4fvH0pl/3KB4gdAlSSw31GJKnEDsjVIlZE2i98MXhNgrTfOyyiapnjF+uq9r81wdbDDKs0WSFu3gnpd56mWyToBcuPi0t7AogDuxXDVIS5DPGMuIhDTzlT66gvFrG/Z8Q+cD6JOtsp3Kp14Dbx2s1ksP/Dn0tAE+J+ynqvSkJlZoJU6vQ3sA14XLyq1oFZys7OJkFu2T6dsuljh8LbPjAEgl2N6H1vP6KbXBFaE04hXfHRcZkA0bwXItgVHp47Wnysw3N1E8hpx41ocoIVZGjfqgGaymeRAEnRqEb5/GovW00XZoQJKISRWVpy9C24gzsn5CUwWPGgEtewF7g== 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=tW/u9DgrsB/MKCUWnxSg/nTn3ydO0p05DZVgDkldlBM=; b=ynLSN769BOlRDcAWIQlrfLrhY6gZ/el/zfM5rrw45bZEuPkWYJ1sfmbgXxFDMfgQQlhvh8AnT1lE/CdLuiUKV+kuuVKSyVhb4egKxkfonWdUmdTX81CkgEzrIAd5ozaNRPFWBsX5OPZpHEU/E5e+XRLTNpZaKmmD0NTyRo5z4vs= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by CO1PR10MB4484.namprd10.prod.outlook.com (2603:10b6:303:90::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.23; Fri, 25 Oct 2024 12:26:57 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8093.014; Fri, 25 Oct 2024 12:26:57 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu Subject: [PATCH v3 3/5] mm: refactor __mmap_region() Date: Fri, 25 Oct 2024 13:26:25 +0100 Message-ID: <25bd2edc3275450f448cbfe0756ce2a7cd06810f.1729858176.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO4P265CA0164.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:312::13) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|CO1PR10MB4484:EE_ X-MS-Office365-Filtering-Correlation-Id: 914a8a93-d272-42ce-1a5a-08dcf4f0515b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?osZhqhfKNS8pMS3EbYV+v+gfXfQocnPHpeAIxQyXyC8P9N14h74d8mUd90GU?= =?us-ascii?Q?Aq3EFnCSeVhZ9ZPAuehGo5oa7ww1BTQwuJb+shYxwCp4KDU1/RoEMB8EhWFS?= =?us-ascii?Q?saV0XS3QDjaFetrcT5bKc+cZ4jxUCJ/syYONDQ1NytNQDDJiZzKRTswR36aR?= =?us-ascii?Q?VMnS5MA0/p9qhGDSlqP4fpxrjo4/HGLn9E5OIz2R5gSmKKrc9BdV4ada8pHf?= =?us-ascii?Q?bJD/bS9y5TTqpwc8zDJLPS9TrxnXpM418zxkYGDEdnB3dfV2X9MpDrJC8o6R?= =?us-ascii?Q?0FH3DpBvaj91gjU2eijRIwoHs2d0tj/30LgVdGuq1/zzGiaFUXuJF63KhqF7?= =?us-ascii?Q?Qjsr5xMRMRFCXK8Ep94m2mnWUPQiCrWfH8zV1sp8BuDRkBcoUChX+CnpOpV1?= =?us-ascii?Q?ttXneVi3jeVOre7muQjSyBMvdH3meu2qD+dqnyhOGe2HfOfxk+Z4LnxheyAi?= =?us-ascii?Q?AJw12VHusArRXJ1FA+uVEondqITRk2JQPfS/sJcsIbkjJDly3HWej/iD9eT9?= =?us-ascii?Q?LuXnI0XS4doaPQQaAtcwUXPFfs0P3maMEaZNiWG1haKHX8Hs4N+6qt6DNAu8?= =?us-ascii?Q?FW9N29hEkdVZ9ixLH4XVY3y1Y5mCZipSXyC/r5IAmZr15ESoK0Z5TuMJjHEH?= =?us-ascii?Q?KrxlnMmc9S3SA6DNw+goKh3JcIlB8q/0dMgUD51ywnXvbSj6Aew7dyEm81fw?= =?us-ascii?Q?Esui7TUfXctg5rqTZs0gqdfFTIgXqBQOxP9Nr3Mt9h1xlgfCvGRtmvY76tAZ?= =?us-ascii?Q?v6ZAclFwtomZ5sQCnynH6GneTfrgAcUlNXytHL2ugj162mBcT0YOrzrc3Ke4?= =?us-ascii?Q?ZfHMrLRBXVPx+rsIA+91qIhXSbWL5sjIQsuoz2hOmoaJsSCp08fP3uqDeI0E?= =?us-ascii?Q?q1qM8XNURICPxXimHPOAbsulphidJirLS9V3MXz2cu6EP04ATAJgOeSiONV3?= =?us-ascii?Q?Y8UdJE6zO5fAeKDusWVYH8ZTeDBirupZA3PG0WAB1QqF+BHwTbD+Br4OHKx7?= =?us-ascii?Q?HMW6PE1hJFu4Ogs4Bm9isX5jVyR5rEs2KHCogb1pNsF0FNffV5BryUrvXjXP?= =?us-ascii?Q?cp7VNtgjPXVXHgsOdDb4kjZO/SD5KGQJoWXiLYtXsk7MWKYSeVgYMVORnBjl?= =?us-ascii?Q?+vAGdgzGsrBTWtTml/7uDqbE5Q91DK/snvY24A0lpUqz8MRXMD4xZu1nyMPQ?= =?us-ascii?Q?o7Xg+DFbaT/94N1gAK/zD3p8flrSZCQmKfdpKkwxUSZ7OHYfT2V8TOEZaTaM?= =?us-ascii?Q?cY5wjuQiSgqKhJmfsEJ6Fq0sKEH7YeBHOn2/KuW7O+IMts4R0gn17fmagqiX?= =?us-ascii?Q?+8nmUJB7nyGF6hmxYBVIcVeP?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?r6HNeyun50+FwmOiBnQmv6cpgDVyOHRsFTDfvwwXJPoJ28dGMfVKWolJRdA1?= =?us-ascii?Q?qHhGRripqHSV9wEhsCTlBsLUEHOKEav59AWtm38BQJidvDyUNEWkhP7CeoQu?= =?us-ascii?Q?HIyGRC7diVZV/dYWhzbKDHdvWsTzNhn81d44nvNZE4Odadb9lH5wa/g0H4Ko?= =?us-ascii?Q?oKiWbSfz3Fwvtpxh0prEUKH+RwCNpnM5yplW1MUEZ77MYIa1rmabLXm5iuZM?= =?us-ascii?Q?I+PRph1n0VXc03hl+PVVafWMsZi/VIeO4NpEriaEWhBghpyxS4upjh7+MF0u?= =?us-ascii?Q?K4ENT/PLQxukvCDQNa4tQSmKlQALnS2Q5PCTN59XyXyKF4Mm1fC+t/Soobgz?= =?us-ascii?Q?X5AwC+QP+kxwWpBu7/bp08lnx7Uy2kVndJH0kk6vjiVjes7lybQTjuZyBnxb?= =?us-ascii?Q?O53RuFhsoASL4wlqJBarVQJIz5DDJEbC8tjAgR44Zvvi3lfZd9M9JiBK48+i?= =?us-ascii?Q?BIDiEys+Mdsyimkz7t2PSJ4DjXsa4cNMpla20Lbe38C8+YH2ble7Qc1Y7OOi?= =?us-ascii?Q?yjy+lfNAWDqiHD1evQXL7yZCCGX/pPWcRGI05XPL4SIk2Thqs83sdKRMSHCa?= =?us-ascii?Q?RbUNwHORjbdjXEw6k1fF7o5rHDrWw/LlZBnjgS6BaP5C/iaz6CZNTLdii1lq?= =?us-ascii?Q?i/N++6ePkd8sgkyscoO2kMse1ceGnXnVm9vsqGI5aDyTiHhR040yNSKhr5oC?= =?us-ascii?Q?q/4jEafWQhgTt13mfWlRMVYPPyIBEZTOvMDJ0YZafM09HJ5CnO9uzinhucQ3?= =?us-ascii?Q?VDf5tdeYacCB/8rgqdVS9z5/UFmAcHabRwyZpoKVb7CXqKt8oBo+IzC1hTel?= =?us-ascii?Q?Dq9Fm5xYm521PzBYSipgNE7gWr57VYmHakrbQl4eNBn6jekeMJmTANLW2SgF?= =?us-ascii?Q?+p7RHoWhvsem/Uq4iey8fuH9d9bEO5lQwCAj+u4aenpdJpfyyCBIrBvmUtu2?= =?us-ascii?Q?uIlacxWSwRZJOvDXXDyyvwKhDXCmIPgIH2ajIVfZmhrsEsW95hK510uUrmxk?= =?us-ascii?Q?+5P0e1rpdDkpk8Z/jDGAVWT/ZY1f0ecuZP19JUwtx1l9mqjJMb49oBc+Bf3l?= =?us-ascii?Q?IJk9Oh3frXYKQvP0OlM+fwDvaOF3Y0sS9Xm5fGoXCT9N0Nx9/t30KvXu1VUe?= =?us-ascii?Q?1HO0uDVYsFmejLZa9JblBvUbz10Df66JFpfhZg5aUZuH7wHZyDy3bJ72jhcM?= =?us-ascii?Q?MqEtZ4P0nwX3i2XaP27N/1rJUYq0WGaTr7u5wBo8iDur/2nD15byX0xKe8O8?= =?us-ascii?Q?+bKtjqRMqnOD22K1GPvTrZn/2gRkBxjyRoqoaGbdovIIYwBcPOmUBY9TgIE0?= =?us-ascii?Q?cnPA5wpBQlv732FDkJUHdkSBeRCC7gx49CFAJ6/nQoLdnwbA4KtA/UvVOQfB?= =?us-ascii?Q?lqnFvPu61UwaPYu0IX6NnAkk7Ul5Tu4awfyaGnV11pODfN2mlPDheB6u5Dk+?= =?us-ascii?Q?D3XeOASsUm9r3ZIXtwUsNo2UyYjYtcaTWerODfP8SIcW9TpHPQ7xCTqxX1RU?= =?us-ascii?Q?s4/ftPtmM6OGuvwX5d75+rSYlsHvutGmXLSGoDNQeUCR6v+kHQRzeON7Q1x9?= =?us-ascii?Q?XPXBaDba3Hg16HPy5yDFdJU23k+l5kiYwN/wAYKqq2bXGMPoND/XhIEfeIMm?= =?us-ascii?Q?Bl5NEr76y5uteH8pLtnv/sCfCqlb+lSHhRZvH29p7R3dvKdfXhRDCQqwi0vb?= =?us-ascii?Q?4/g+eA=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: etryJ5fLoaS1vvp81pFYFoLxRtvmdAc6uyK+iDPQyZUfRNH5xy16pTrqP+/aY5LMEtd8WSfpoejumL4fUbxPUbkOpw5hslWuBmjmAQo5UN/41H6lx+GmbRk4wyus4MUp/+K5aRuYa491bXADo5HPYSHUerOQnaO0qzi9vwDnNxfpuAVP4bHOEZYuYmmQxgJcCp26h/JutBjFC0nlS56UxNquTa4RlwZnz9KhNXImN9m3yEVFdusFVvB1amCj6JBg3lk5FBnP+El1AuIzJbHRR0EXruXs9D7GMlprcrBs6YlPWTQm1tXm0ZsX2vWZTZPtx3PnicVGb+FP+3aW/6PbSY7gbfquQFXPFpWJv3mdpSwGA6Pt816szI3vx0EuWNJ/6E5S87/glb6tLxaNwkPntaTtpSdIf5XgtdWdN5DWgH5VvxEoQd9RGfEeygEHYbVlVJCXKK/hJo2627HsvlYBH/FrITm/mWbdBg3Ctnvv6nTzD8XWMEl4//4gQtPRl3IqJZNBqoVq0VdG0fqvmMZpexI9icIFUvp90iuKxzkLWhrJ7k4be2Bj7SXtJRsT6pf5ivLIRVsFnLN/8E+US0J3Js2ESnjJmgB7G8w8UWJaD98= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 914a8a93-d272-42ce-1a5a-08dcf4f0515b X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2024 12:26:57.5594 (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: UoAwdC64miYexY8atyLM0kplhvI55RkL8ISG5ZOSJt8ztVlB4DmA2q+41bZVZoSlbxbXFKLaiiRhXdvRJXR43xC311p1zExijZ/dwP/q89w= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4484 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-25_12,2024-10-25_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 phishscore=0 suspectscore=0 bulkscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410250095 X-Proofpoint-GUID: 8HOIUugaD2zHS8gRfFuKMNjyXbOJt0Cz X-Proofpoint-ORIG-GUID: 8HOIUugaD2zHS8gRfFuKMNjyXbOJt0Cz Content-Type: text/plain; charset="utf-8" We have seen bugs and resource leaks arise from the complexity of the __mmap_region() function. This, and the generally deeply fragile error handling logic and complexity which makes understanding the function difficult make it highly desirable to refactor it into something readable. Achieve this by separating the function into smaller logical parts which are easier to understand and follow, and which importantly very significantly simplify the error handling. Note that we now call vms_abort_munmap_vmas() in more error paths than we used to, however in cases where no abort need occur, vms->nr_pages will be equal to zero and we simply exit this function without doing more than we would have done previously. Importantly, the invocation of the driver mmap hook via mmap_file() now has very simple and obvious handling (this was previously the most problematic part of the mmap() operation). Use a generalised stack-based 'mmap state' to thread through values and also retrieve state as needed. Also avoid ever relying on vma merge (vmg) state after a merge is attempted, instead maintain meaningful state in the mmap state and establish vmg state as and when required. This avoids any subtle bugs arising from merge logic mutating this state and mmap_region() logic later relying upon it. Reviewed-by: Vlastimil Babka Signed-off-by: Lorenzo Stoakes --- mm/vma.c | 410 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 270 insertions(+), 140 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 0a2965be582d..b91c947babd6 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -7,6 +7,56 @@ #include "vma_internal.h" #include "vma.h" =20 +struct mmap_state { + struct mm_struct *mm; + struct vma_iterator *vmi; + + unsigned long addr; + unsigned long end; + pgoff_t pgoff; + unsigned long pglen; + unsigned long flags; + struct file *file; + + unsigned long charged; + + struct vm_area_struct *prev; + struct vm_area_struct *next; + + /* Unmapping state. */ + struct vma_munmap_struct vms; + struct ma_state mas_detach; + struct maple_tree mt_detach; +}; + +#define MMAP_STATE(name, mm_, vmi_, addr_, len_, pgoff_, flags_, file_) \ + struct mmap_state name =3D { \ + .mm =3D mm_, \ + .vmi =3D vmi_, \ + .addr =3D addr_, \ + .end =3D (addr_) + len, \ + .pgoff =3D pgoff_, \ + .pglen =3D PHYS_PFN(len_), \ + .flags =3D flags_, \ + .file =3D file_, \ + } + +#define VMG_MMAP_STATE(name, map_, vma_) \ + struct vma_merge_struct name =3D { \ + .mm =3D (map_)->mm, \ + .vmi =3D (map_)->vmi, \ + .start =3D (map_)->addr, \ + .end =3D (map_)->end, \ + .flags =3D (map_)->flags, \ + .pgoff =3D (map_)->pgoff, \ + .file =3D (map_)->file, \ + .prev =3D (map_)->prev, \ + .vma =3D vma_, \ + .next =3D (vma_) ? NULL : (map_)->next, \ + .state =3D VMA_MERGE_START, \ + .merge_flags =3D VMG_FLAG_DEFAULT, \ + } + static inline bool is_mergeable_vma(struct vma_merge_struct *vmg, bool mer= ge_next) { struct vm_area_struct *vma =3D merge_next ? vmg->next : vmg->prev; @@ -2169,188 +2219,249 @@ static void vms_abort_munmap_vmas(struct vma_munm= ap_struct *vms, vms_complete_munmap_vmas(vms, mas_detach); } =20 -unsigned long __mmap_region(struct file *file, unsigned long addr, - unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, - struct list_head *uf) +/* + * __mmap_prepare() - Prepare to gather any overlapping VMAs that need to = be + * unmapped once the map operation is completed, check limits, account map= ping + * and clean up any pre-existing VMAs. + * + * @map: Mapping state. + * @uf: Userfaultfd context list. + * + * Returns: 0 on success, error code otherwise. + */ +static int __mmap_prepare(struct mmap_state *map, struct list_head *uf) { - struct mm_struct *mm =3D current->mm; - struct vm_area_struct *vma =3D NULL; - pgoff_t pglen =3D PHYS_PFN(len); - unsigned long charged =3D 0; - struct vma_munmap_struct vms; - struct ma_state mas_detach; - struct maple_tree mt_detach; - unsigned long end =3D addr + len; int error; - VMA_ITERATOR(vmi, mm, addr); - VMG_STATE(vmg, mm, &vmi, addr, end, vm_flags, pgoff); - - vmg.file =3D file; - /* Find the first overlapping VMA */ - vma =3D vma_find(&vmi, end); - init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock =3D */ false); - if (vma) { - mt_init_flags(&mt_detach, vmi.mas.tree->ma_flags & MT_FLAGS_LOCK_MASK); - mt_on_stack(mt_detach); - mas_init(&mas_detach, &mt_detach, /* addr =3D */ 0); + struct vma_iterator *vmi =3D map->vmi; + struct vma_munmap_struct *vms =3D &map->vms; + + /* Find the first overlapping VMA and initialise unmap state. */ + vms->vma =3D vma_find(vmi, map->end); + init_vma_munmap(vms, vmi, vms->vma, map->addr, map->end, uf, + /* unlock =3D */ false); + + /* OK, we have overlapping VMAs - prepare to unmap them. */ + if (vms->vma) { + mt_init_flags(&map->mt_detach, + vmi->mas.tree->ma_flags & MT_FLAGS_LOCK_MASK); + mt_on_stack(map->mt_detach); + mas_init(&map->mas_detach, &map->mt_detach, /* addr =3D */ 0); /* Prepare to unmap any existing mapping in the area */ - error =3D vms_gather_munmap_vmas(&vms, &mas_detach); - if (error) - goto gather_failed; + error =3D vms_gather_munmap_vmas(vms, &map->mas_detach); + if (error) { + /* On error VMAs will already have been reattached. */ + vms->nr_pages =3D 0; + return error; + } =20 - vmg.next =3D vms.next; - vmg.prev =3D vms.prev; - vma =3D NULL; + map->next =3D vms->next; + map->prev =3D vms->prev; } else { - vmg.next =3D vma_iter_next_rewind(&vmi, &vmg.prev); + map->next =3D vma_iter_next_rewind(vmi, &map->prev); } =20 /* Check against address space limit. */ - if (!may_expand_vm(mm, vm_flags, pglen - vms.nr_pages)) { - error =3D -ENOMEM; - goto abort_munmap; - } + if (!may_expand_vm(map->mm, map->flags, map->pglen - vms->nr_pages)) + return -ENOMEM; =20 - /* - * Private writable mapping: check memory availability - */ - if (accountable_mapping(file, vm_flags)) { - charged =3D pglen; - charged -=3D vms.nr_accounted; - if (charged) { - error =3D security_vm_enough_memory_mm(mm, charged); + /* Private writable mapping: check memory availability. */ + if (accountable_mapping(map->file, map->flags)) { + map->charged =3D map->pglen; + map->charged -=3D vms->nr_accounted; + if (map->charged) { + error =3D security_vm_enough_memory_mm(map->mm, map->charged); if (error) - goto abort_munmap; + return error; } =20 - vms.nr_accounted =3D 0; - vm_flags |=3D VM_ACCOUNT; - vmg.flags =3D vm_flags; + vms->nr_accounted =3D 0; + map->flags |=3D VM_ACCOUNT; } =20 /* - * clear PTEs while the vma is still in the tree so that rmap + * Clear PTEs while the vma is still in the tree so that rmap * cannot race with the freeing later in the truncate scenario. * This is also needed for mmap_file(), which is why vm_ops * close function is called. */ - vms_clean_up_area(&vms, &mas_detach); - vma =3D vma_merge_new_range(&vmg); - if (vma) - goto expanded; + vms_clean_up_area(vms, &map->mas_detach); + + return 0; +} + +static int __mmap_new_file_vma(struct mmap_state *map, + struct vm_area_struct **vmap, bool *mergedp) +{ + struct vma_iterator *vmi =3D map->vmi; + struct vm_area_struct *vma =3D *vmap; + int error; + + vma->vm_file =3D get_file(map->file); + error =3D mmap_file(vma->vm_file, vma); + if (error) { + fput(vma->vm_file); + vma->vm_file =3D NULL; + + vma_iter_set(vmi, vma->vm_end); + /* Undo any partial mapping done by a device driver. */ + unmap_region(&vmi->mas, vma, map->prev, map->next); + + return error; + } + + /* Drivers cannot alter the address of the VMA. */ + WARN_ON_ONCE(map->addr !=3D vma->vm_start); + /* + * Drivers should not permit writability when previously it was + * disallowed. + */ + VM_WARN_ON_ONCE(map->flags !=3D vma->vm_flags && + !(map->flags & VM_MAYWRITE) && + (vma->vm_flags & VM_MAYWRITE)); + + /* mmap_file() might have changed VMA flags. */ + map->flags =3D vma->vm_flags; + + vma_iter_config(vmi, map->addr, map->end); + /* + * If flags changed after mmap_file(), we should try merge + * vma again as we may succeed this time. + */ + if (unlikely(map->flags !=3D vma->vm_flags && map->prev)) { + struct vm_area_struct *merge; + VMG_MMAP_STATE(vmg, map, /* vma =3D */ NULL); + + merge =3D vma_merge_new_range(&vmg); + if (merge) { + /* + * ->mmap() can change vma->vm_file and fput + * the original file. So fput the vma->vm_file + * here or we would add an extra fput for file + * and cause general protection fault + * ultimately. + */ + fput(vma->vm_file); + vm_area_free(vma); + vma =3D merge; + *mergedp =3D true; + } else { + vma_iter_config(vmi, map->addr, map->end); + } + } + + *vmap =3D vma; + return 0; +} + +/* + * __mmap_new_vma() - Allocate a new VMA for the region, as merging was not + * possible. + * + * An exception to this is if the mapping is file-backed, and the underlyi= ng + * driver changes the VMA flags, permitting a subsequent merge of the VMA,= in + * which case the returned VMA is one that was merged on a second attempt. + * + * @map: Mapping state. + * @vmap: Output pointer for the new VMA. + * + * Returns: Zero on success, or an error. + */ +static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **= vmap) +{ + struct vma_iterator *vmi =3D map->vmi; + int error =3D 0; + bool merged =3D false; + struct vm_area_struct *vma; + /* * Determine the object being mapped and call the appropriate * specific mapper. the address has already been validated, but * not unmapped, but the maps are removed from the list. */ - vma =3D vm_area_alloc(mm); - if (!vma) { - error =3D -ENOMEM; - goto unacct_error; - } + vma =3D vm_area_alloc(map->mm); + if (!vma) + return -ENOMEM; =20 - vma_iter_config(&vmi, addr, end); - vma_set_range(vma, addr, end, pgoff); - vm_flags_init(vma, vm_flags); - vma->vm_page_prot =3D vm_get_page_prot(vm_flags); + vma_iter_config(vmi, map->addr, map->end); + vma_set_range(vma, map->addr, map->end, map->pgoff); + vm_flags_init(vma, map->flags); + vma->vm_page_prot =3D vm_get_page_prot(map->flags); =20 - if (vma_iter_prealloc(&vmi, vma)) { + if (vma_iter_prealloc(vmi, vma)) { error =3D -ENOMEM; goto free_vma; } =20 - if (file) { - vma->vm_file =3D get_file(file); - error =3D mmap_file(file, vma); - if (error) - goto unmap_and_free_file_vma; - - /* Drivers cannot alter the address of the VMA. */ - WARN_ON_ONCE(addr !=3D vma->vm_start); - /* - * Drivers should not permit writability when previously it was - * disallowed. - */ - VM_WARN_ON_ONCE(vm_flags !=3D vma->vm_flags && - !(vm_flags & VM_MAYWRITE) && - (vma->vm_flags & VM_MAYWRITE)); - - vma_iter_config(&vmi, addr, end); - /* - * If vm_flags changed after mmap_file(), we should try merge - * vma again as we may succeed this time. - */ - if (unlikely(vm_flags !=3D vma->vm_flags && vmg.prev)) { - struct vm_area_struct *merge; - - vmg.flags =3D vma->vm_flags; - /* If this fails, state is reset ready for a reattempt. */ - merge =3D vma_merge_new_range(&vmg); - - if (merge) { - /* - * ->mmap() can change vma->vm_file and fput - * the original file. So fput the vma->vm_file - * here or we would add an extra fput for file - * and cause general protection fault - * ultimately. - */ - fput(vma->vm_file); - vm_area_free(vma); - vma =3D merge; - /* Update vm_flags to pick up the change. */ - vm_flags =3D vma->vm_flags; - goto file_expanded; - } - vma_iter_config(&vmi, addr, end); - } - - vm_flags =3D vma->vm_flags; - } else if (vm_flags & VM_SHARED) { + if (map->file) + error =3D __mmap_new_file_vma(map, &vma, &merged); + else if (map->flags & VM_SHARED) error =3D shmem_zero_setup(vma); - if (error) - goto free_iter_vma; - } else { + else vma_set_anonymous(vma); - } + + if (error) + goto free_iter_vma; + + if (merged) + goto file_expanded; =20 #ifdef CONFIG_SPARC64 /* TODO: Fix SPARC ADI! */ - WARN_ON_ONCE(!arch_validate_flags(vm_flags)); + WARN_ON_ONCE(!arch_validate_flags(map->flags)); #endif =20 /* Lock the VMA since it is modified after insertion into VMA tree */ vma_start_write(vma); - vma_iter_store(&vmi, vma); - mm->map_count++; + vma_iter_store(vmi, vma); + map->mm->map_count++; vma_link_file(vma); =20 /* * vma_merge_new_range() calls khugepaged_enter_vma() too, the below * call covers the non-merge case. */ - khugepaged_enter_vma(vma, vma->vm_flags); + khugepaged_enter_vma(vma, map->flags); =20 file_expanded: - file =3D vma->vm_file; ksm_add_vma(vma); -expanded: + *vmap =3D vma; + return 0; + +free_iter_vma: + vma_iter_free(vmi); +free_vma: + vm_area_free(vma); + return error; +} + +/* + * __mmap_complete() - Unmap any VMAs we overlap, account memory mapping + * statistics, handle locking and finalise the VMA. + * + * @map: Mapping state. + * @vma: Merged or newly allocated VMA for the mmap()'d region. + */ +static void __mmap_complete(struct mmap_state *map, struct vm_area_struct = *vma) +{ + struct mm_struct *mm =3D map->mm; + unsigned long vm_flags =3D vma->vm_flags; + perf_event_mmap(vma); =20 - /* Unmap any existing mapping in the area */ - vms_complete_munmap_vmas(&vms, &mas_detach); + /* Unmap any existing mapping in the area. */ + vms_complete_munmap_vmas(&map->vms, &map->mas_detach); =20 - vm_stat_account(mm, vm_flags, pglen); + vm_stat_account(mm, vma->vm_flags, map->pglen); if (vm_flags & VM_LOCKED) { if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) || is_vm_hugetlb_page(vma) || - vma =3D=3D get_gate_vma(current->mm)) + vma =3D=3D get_gate_vma(mm)) vm_flags_clear(vma, VM_LOCKED_MASK); else - mm->locked_vm +=3D pglen; + mm->locked_vm +=3D map->pglen; } =20 - if (file) + if (vma->vm_file) uprobe_mmap(vma); =20 /* @@ -2363,26 +2474,45 @@ unsigned long __mmap_region(struct file *file, unsi= gned long addr, vm_flags_set(vma, VM_SOFTDIRTY); =20 vma_set_page_prot(vma); +} =20 - return addr; +unsigned long __mmap_region(struct file *file, unsigned long addr, + unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, + struct list_head *uf) +{ + struct mm_struct *mm =3D current->mm; + struct vm_area_struct *vma =3D NULL; + int error; + VMA_ITERATOR(vmi, mm, addr); + MMAP_STATE(map, mm, &vmi, addr, len, pgoff, vm_flags, file); =20 -unmap_and_free_file_vma: - fput(vma->vm_file); - vma->vm_file =3D NULL; + error =3D __mmap_prepare(&map, uf); + if (error) + goto abort_munmap; =20 - vma_iter_set(&vmi, vma->vm_end); - /* Undo any partial mapping done by a device driver. */ - unmap_region(&vmi.mas, vma, vmg.prev, vmg.next); -free_iter_vma: - vma_iter_free(&vmi); -free_vma: - vm_area_free(vma); -unacct_error: - if (charged) - vm_unacct_memory(charged); + /* Attempt to merge with adjacent VMAs... */ + if (map.prev || map.next) { + VMG_MMAP_STATE(vmg, &map, /* vma =3D */ NULL); + + vma =3D vma_merge_new_range(&vmg); + } =20 + /* ...but if we can't, allocate a new VMA. */ + if (!vma) { + error =3D __mmap_new_vma(&map, &vma); + if (error) + goto unacct_error; + } + + __mmap_complete(&map, vma); + + return addr; + + /* Accounting was done by __mmap_prepare(). */ +unacct_error: + if (map.charged) + vm_unacct_memory(map.charged); abort_munmap: - vms_abort_munmap_vmas(&vms, &mas_detach); -gather_failed: + vms_abort_munmap_vmas(&map.vms, &map.mas_detach); return error; } --=20 2.47.0 From nobody Mon Nov 25 17:31:27 2024 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D05B7203709 for ; Fri, 25 Oct 2024 12:27:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729859238; cv=fail; b=frsJAxzTHUbUxDpjj6gKMhLagf/PiT6Z86lrjAhUti/xd/5EXbyFlnpaPgWaHTz1vh0uELLYM6ZaGW/mF+YmXey4agpNvH4x8phXRpL3nFgGngWQqcxAq/wKAorFTYgVW6KdCnBb67f0XHucLeAManJyDNIgQNjyw2Tzo5iP7fg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729859238; c=relaxed/simple; bh=tPN38tBgdOY8UIWFhut+ECcIjhdA1NTIVjcz7qJP7/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=UfkdOn6vVvM3f+VZtfKjIN11Xmo0pR4Vq/9og/LsKSzRzWCnz1f3ZX/a3Pmt0SK6b+ixfInMbeFmlSYWKF/qiV/uOiqPSoMtI74mw8xtnfzVzHDQDZlhQ6nFgT7oMJv2KMmEivJkEounRsoVssuLFNa3BpiELUMWaS6/EvK2vOA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=DbEvce0i; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=LjAvkv1k; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="DbEvce0i"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="LjAvkv1k" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49P8BZ8O005839; Fri, 25 Oct 2024 12:27:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=Fh+NuR7QCmcKWxRi86ErJ9aexreyrERuoTi9h/YGAIM=; b= DbEvce0iBzEHNApq2ebk5pLRwE3WaPP2XCGHlX92+5pvdS+u/DPK86y3TqT5rImr RSgkJ1khh9JD+f4IKa+8wCI6SOf0dlE9v/Ntt5NISF6IJIf0qV0dKvv9giUJCuvw 5eOR0ynTm/1u5AAqNl9weR6yF33Mj0W7DhTZnCiB9x4TCarbuEz6D9sQMxQ5U0bo Vdtz7n1CtHby+ccE9JYD1m5CJPNpevdOH+4m8UI8jyVvHhygbVr67wZXQJsouvvy jL7fWyjOGWF/rmZ7UuSOIdzBEM0l3XgfPTDCJ5pSvv+GBPoHNDvI6hgh83F1JJ+R 6WWRJqeVxUs4mGwochTRXw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c53uvtty-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 12:27:04 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49PBxpRm016475; Fri, 25 Oct 2024 12:27:03 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2171.outbound.protection.outlook.com [104.47.58.171]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42emhdt4th-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 12:27:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wJ8eefl3dxv+QsJWWMWUAyCX07U927502Jms4JRblLUdCpDt9HRjqFbKybnGIAKOnUjysaO1L+7ultaR+6kB528+ei+Lzl/bjMzvOxM+J6loxl5IdOQ5JCaAJXjYODwyEffGgJh/xCohd4oc5uSr3xPJqts5mr2hAC+oUupKP5tsN5jkR0D6Qi743qetASwQidJMubMlFIMdyqhzfIi7+8JMMFJ2dNr45OKcAHaWa3BG9ZKjJlfAbD2DA6A/mQzE0SHhNkyYFa4+7lv90k1kRw2OjnjzbTKEAGZNd0L716lVu9cT0hKeDAYy7aJTvaRDemlPb5KbBfZhaQyE6/1mXg== 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=Fh+NuR7QCmcKWxRi86ErJ9aexreyrERuoTi9h/YGAIM=; b=POC/br9G1MSryKkGLnAzEPTQGkTi9UuA7EAYvoBED02LxXPXIZrY2JFRjbldSMJ6KG56myMTSbYp/WC9KvmXeWrFAjFduqPkradKPDTCsGo9GSanFcWigbPDNv/9kAKlFamFVLbvbSCPHAhn23KQA6bvqafRzBiEmXoYLMgw2dDt9tNJx8ENAw305NV/LHjgFCIWeyZmamIQkL7f+c0dK4DsAFBHFJMywSsxin2LSkEYQ8i+4x+V2fSFHqEqkCk0JFPsxBleoH+jjCv89cmQ3/g1z3rQ8CvX5qNR4g6izfnximLPcxTAcAP+tS+gacGz9G13aVf7d3iwlToAjn+/JA== 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=Fh+NuR7QCmcKWxRi86ErJ9aexreyrERuoTi9h/YGAIM=; b=LjAvkv1kRsrkEn3lKQaukdhuy1M60SIV9Wk0FmjvsCKaI3Np0ZErYujTa6T+s94832OvnMCTod69xLW7hAeYud1z3Yt3vH1MqOz9dVZphbBXLgc+hr+S+1TGxKWZ0hyXPTbDd+vrz4liO6VvBoi0TdEIxCxXcfrmZK7LRkf2D98= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by CO1PR10MB4484.namprd10.prod.outlook.com (2603:10b6:303:90::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.23; Fri, 25 Oct 2024 12:27:01 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8093.014; Fri, 25 Oct 2024 12:27:01 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu Subject: [PATCH v3 4/5] mm: remove unnecessary reset state logic on merge new VMA Date: Fri, 25 Oct 2024 13:26:26 +0100 Message-ID: <5d9a59eee6498ae017cc87d89aa723de7179f75d.1729858176.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO4P123CA0384.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18f::11) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|CO1PR10MB4484:EE_ X-MS-Office365-Filtering-Correlation-Id: 6a062c4c-1fbc-4710-1f55-08dcf4f05360 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?2djdjVV85awVdBOnSsubmgLlKUOqMrCtcJyqsnThveLdzfMFQDqEIq+Y2JH+?= =?us-ascii?Q?x7JgyzkuajQCnCW1nQv7OdTZI1hEaf5d3MCU51sTyKl5I1bIMwn8qQLBr3ir?= =?us-ascii?Q?KNwB12sLJr7zoxO3qTf9J2UP8JKHqQlji3znOiUV8eUmIdDGcCsSFhKEmcBZ?= =?us-ascii?Q?rAfPfkKzHaUWnVSYgsn4i21CRCSKgXliqsGEhHkBOvV6v5as3RXfR7L0KANB?= =?us-ascii?Q?+I6OxHd/sEkWWIUohBeRPbCbXXzNdF01d+VVyvQqUQhwIFKGsoYsdqcYwnij?= =?us-ascii?Q?mYOYNK9nlK0C5plVx+vzNjVXI+zCEjG0I0if2alxyp1+qUPjk4GyuzMlZpx9?= =?us-ascii?Q?8uLyugqtaeWyKKOF0hofUDqdVLvpD+k+lAZ5fcgyPYn2YR8bcBQxArn7Jfs2?= =?us-ascii?Q?+JsYveEXC6JI0A6n4sbcBClEcES1ChaupcLl3Ppo/Dxeh49EQittgOs5eCo2?= =?us-ascii?Q?3NRmLvLwDPJuTBhL2OjLwwawXWqmk2NQFRE2dcNloEXOLeWRgRg0Ns2OxXxr?= =?us-ascii?Q?O1R4tEPBcoqD837D0QXKIFjFNZzH2SO3wdAT5lPXOQUEytlHKjEzxaVRXrk2?= =?us-ascii?Q?6DsCnaE9WnqR/Ru5V33WzCTmTx4FBIxhXHICa1CAUMVXfQxrKof+eTspSr9v?= =?us-ascii?Q?dh84KZ6zbk7xRtN2WitcLoLVRG3kB+h08skomHl9qhUwNBClL6WRzcFda+rU?= =?us-ascii?Q?DcvYjEDGaQ0U8idJd4d3bbCGqMPXAjMqRfRB2Pqa7iJ+p74BArrmO4oms5ob?= =?us-ascii?Q?eRH3KkdoPAbgCVfdT+Q4GnoemLZUP9lcmH1evsesUh3seQOIuAJseiWnLHAX?= =?us-ascii?Q?OeNLWeHfCo/p6S7OIWcm3vEIDHYDt0WDyHkG4S66sDeo7RLzwCejG7/lwQJH?= =?us-ascii?Q?K/eKyULbMbBp6ehJ9gkiiu5q/cW6dnhzrpdflPuS+PqqhDiKrEmx6BhF8tpI?= =?us-ascii?Q?ta9/+H6rDuU4MtJVQNn/G4/DUxwZsl85Y8/q5Hf73SachqXe/b7SHyl+NPMQ?= =?us-ascii?Q?nKLZuQWwFCiiI/LS+MXZJN/7scpwGasPlef9SoJM1PbRvVgOcTJJ/MWRiJKL?= =?us-ascii?Q?QzdHjiXHttK6TT5cz7U2kQQzeoY2xihJZcs8OIK1ZwCrNTKf1+hXdjgsIhcB?= =?us-ascii?Q?WFCQsE1uNCupahuZZPR74J69SSdWeuc0s23Vsx3HotKnvyCK57U+8I/BkpEG?= =?us-ascii?Q?DH3xUGApYbjz4JoTgWHREB4WPhC2YSJwaH9C0Wgb7rvbMfKlw8duX/vUa7yG?= =?us-ascii?Q?NGy7x5yLckcPrwGbk/ND4NU275lggqy6fa0wotsMJfkot8Ufk3CR0T/TrMTj?= =?us-ascii?Q?Zm2cA+6aw5I9+alrU783XZR5?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?SspEO2vJ+EnSxTZVbjQOSyNEjfU2Tl0PyFzepbsA2ljkk4vO3hE7uL3aMza8?= =?us-ascii?Q?ZRFyUpE/q3aauM8OVBLo2Y8YfR/lUG0KJolWY7+R+039kWKuxeXib+fqJUY6?= =?us-ascii?Q?5h62hxuAlml+OsbpH9gvge5Y0jHByPwiTm+vry1dyRGkt7s2CdFP2UuWs1cU?= =?us-ascii?Q?4y7KX+yPJQXefayZ7HLtI44erwFyzE51fjE6ADH9R4z5jLD1v4mB2fYczsJF?= =?us-ascii?Q?YXhxdqWT0epmuaG90AVjKke13nQUNAiq35XYHO5hcmdV9rYBCHAv5obGUWTk?= =?us-ascii?Q?Y370yCsghBdRTV34p5ACbqL7dJZ4e75wqyQWbcmUapCJx3dmUVvH7QK8+zzm?= =?us-ascii?Q?8BowgBYMPcdCt4fUWYTvOZJ5RP2Ebzt9JwzHZ9IcW93pfPJlJ2LSsikxju16?= =?us-ascii?Q?SSaHDZN62gmcjk5Ycy2m5+TVK2Cq4Bqri0W4DNxYN0Dqqz94STvxRbCY8+xc?= =?us-ascii?Q?YrrYxX5gZw7riNrNHQgeeQT+he01Ozl5ES9k1XFZ1dwzMmw/z1SFGBWN2VMw?= =?us-ascii?Q?0UIW5ybxhEOpopDvtNKOp/Rq8xXPdESjX1KY/fOhmysDz8dSbJ0f9VznmfMF?= =?us-ascii?Q?jARBtd3iduDU8n+MGAFB2EiqljNbMj4RIG7jhP2MPDpWS+RrOeGyk3rrfJju?= =?us-ascii?Q?Q3MuGV59TKoUkvgGoGcmOtO230SUKkfxuZB36ydGGpTnseB19MsAIatB9FsV?= =?us-ascii?Q?EAimWh9lbTMeW+FBhxED5EeqlhW4Fq14g17oc8WsahlMq4aRMNOCHpuBXyWD?= =?us-ascii?Q?8X8+UmnuJp6p4OJ2sC5CNAE1fx1+tqXoAx95FV7zWFgOwGc4R7vsef/gCzH6?= =?us-ascii?Q?82cmPAIHkHGPnzFnuFwPevs3YVqMHv0Nhml3af5uNC+uD4D5Gz00Tgixppmi?= =?us-ascii?Q?eI6Y1jrxreky6LZfDSlMFI19wdjL7hV/BbW0GPbhwV+Xn121lRucqXljxJg3?= =?us-ascii?Q?+Izv4ubaxLWhlsLC/+ghsBedGYtidwzJK2lqa527E9+ab1sJNgDtqFI7Si9t?= =?us-ascii?Q?W9ldLypl6246Ji98qlae1fdCFEC/VyelIeyMzG+rt3vJIHU4+oV4FHMAOSgK?= =?us-ascii?Q?LSKk9CC5jDMgTMaTRf9gSaL/uPtfmmJiwTtIrBWItz5kWbnsdzXH5nDJroW/?= =?us-ascii?Q?PI+3t6bgjcG/lIhrMrtNDmMDp0LbdcMeGbd1ZEWONUWD1Bi0LCFUu88fFnHj?= =?us-ascii?Q?gFOC2Mqs49pl3q1VcOOLMRD2AIKPoOmlq6YnB6yS8XK65atGjPkxrC/1nArO?= =?us-ascii?Q?PZaPMTib2eLL6NEAxJ7u3eJEBbK6pTCIvNp7mSjCC1LFNUtpVa/dScsX9d3V?= =?us-ascii?Q?EcbJOX84sF0STM+K8H9CWt5gHVVF/kBk9M21LOc6ens56TIrmZ8YxxQaF3Z3?= =?us-ascii?Q?v3mwdh46kCbaw7+lYTXcbgllhS9q3Hx4esvDGa2oqG0yDJvDXwANEbEoRPtG?= =?us-ascii?Q?Nsgwx96RSI+jhrMiXo2V6KZFliyc+KY7wFOa7t6lbd/1TPB8vahM1dnSq59u?= =?us-ascii?Q?KehvUIAJuFnURWaCpcQoEiC0xgD+EhKFLpoGVQZmi1hDdFDngDbuQzq695G0?= =?us-ascii?Q?+tp622uldAotiAab7eZKu0KlMdG/4gmExoOMPdPCTyothkeaUylBUj9P0cvq?= =?us-ascii?Q?Z3jDnwwMgmOSdC+ENYHJnQL6JK0m2pRfw2crFIv6w5sArEKuuf38YzELiHaB?= =?us-ascii?Q?xQ1WbA=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: E1zoyNcnWpKbpu1zUXuMhQEvW8QXMM+7QoLynOLya7ylMwWYGEX0M5dSv4R0Lird0Nd0wfjciyOU9M3cRnq5AGGWslJYM5/eJzQAA8RMjyKACV6hjk461ckcDZ8cXMGelhEbA21bXWWThLvWaNiEoSIJuX9EpBUpfI74XwkukCARArgzg9OVdNkB95xpnAgjRFz4G4Ox6G5MUDZxVkTs0gBd+o2YdA8YrXhVhkUgT0/hBS2tEFpuiC04715oHRKOmTJj1Fg4qyV6zdXa6WaYFlppbSrZBZA2kX0woozUwCwIy5eo3t4Hhy/X52CABf3nWigV05xOf3WbU3QMcJVwyxOP3up2yXc77FedbzmQQGn8ONVKGoiptgcwk+Qb0USfKao45gWCeSBrPRWUvuo74gqoisv0Y21UG8HTRumC2/98Uz3D64XUTc1Quyeh04FKL0C8yQNq3xJWgwf3FVM4PZ+HgY0rJ4nkKDJRVaqxn9uC6H9LYNI0wj+XrAhTYrSbQ0c34VykxOSymR7/d85r3Ma0SMmfLEvcYKmtNprfqBQmV0hpLN5JLo2Frqr8HeUPYjO8JD4KEeV9sCwO4oxjBjOb9+sQxc2oibYERH1cQXE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6a062c4c-1fbc-4710-1f55-08dcf4f05360 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2024 12:27:01.0607 (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: rSzS7/VX+MtWwK3rb60IBMc/2AjT6d83SRH7K4vO3p2ithcjFDWXIsH+jsYl9k5azdm+01uxfWbqOLdK81bFvtA+nAwiF/EldDJBMq6VM40= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4484 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-25_12,2024-10-25_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 phishscore=0 suspectscore=0 bulkscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410250095 X-Proofpoint-GUID: fTZuV6PyLCISfuKZjl2HvDXEV7SoME3v X-Proofpoint-ORIG-GUID: fTZuV6PyLCISfuKZjl2HvDXEV7SoME3v Content-Type: text/plain; charset="utf-8" The only place where this was used was in mmap_region(), which we have now adjusted to not require this to be performed (we reset ourselves in effect). It also created a dangerous assumption that VMG state could be safely reused after a merge, at which point it may have been mutated in unexpected ways, leading to subtle bugs. Note that it was discovered by Wei Yang that there was also an error in this code - we are comparing vmg->vma with prev after setting it to NULL. This however had no impact, as we previously reset VMA iterator state before attempting merge again, but it was useless effort. In any case, this patch removes all of the logic so also eliminates this wasted effort. Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- mm/vma.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index b91c947babd6..7c690be67910 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -963,7 +963,6 @@ struct vm_area_struct *vma_merge_new_range(struct vma_m= erge_struct *vmg) struct vm_area_struct *next =3D vmg->next; unsigned long start =3D vmg->start; unsigned long end =3D vmg->end; - pgoff_t pgoff =3D vmg->pgoff; pgoff_t pglen =3D PHYS_PFN(end - start); bool can_merge_left, can_merge_right; bool just_expand =3D vmg->merge_flags & VMG_FLAG_JUST_EXPAND; @@ -1020,16 +1019,6 @@ struct vm_area_struct *vma_merge_new_range(struct vm= a_merge_struct *vmg) return vmg->vma; } =20 - /* If expansion failed, reset state. Allows us to retry merge later. */ - if (!just_expand) { - vmg->vma =3D NULL; - vmg->start =3D start; - vmg->end =3D end; - vmg->pgoff =3D pgoff; - if (vmg->vma =3D=3D prev) - vma_iter_set(vmg->vmi, start); - } - return NULL; } =20 --=20 2.47.0 From nobody Mon Nov 25 17:31:27 2024 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7C98B203703 for ; Fri, 25 Oct 2024 12:27:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729859241; cv=fail; b=BogAuqW1iNC/T5OphJ5vHexzq7aXqRH0nTQVEy+V6IRxFGvjV7nBg/Y57fWcqKPH0AOiShSxoV4ioUnZOTb5kUDcAzy3wtbUx7Th90T9u4D5j2hAVugbAEGuoprYiLttkOfl4B1XaJ4g++AE462BDw1spYocVwFdoezUl+QmT2U= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729859241; c=relaxed/simple; bh=LBSjk6vfUIq9PpwrB3e6JjAcOL+38PGFK0yxTmawgTk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=c+OiuJ+Tfp/7zLPHR1F/R2SLcNoRGth77OZAL/sKdT/PxlxD9wIUVo4Wa1t300Ngqgjg11CnpOWTRPljwzdPQzL+rtw0Y7c7U04cL/BOjxI3IkAcbY9gFfkvCqR553cuAzxjT2nk2L4C29f3HmxszEsk8iGAo7g4E23uTsurEHY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=NU6k//XM; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=d+nTQH8n; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="NU6k//XM"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="d+nTQH8n" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49P8BZgo026805; Fri, 25 Oct 2024 12:27:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=rzah8PtqmSFAEkrgx3+NN4GKeumy7rZse5pxRqGcMM4=; b= NU6k//XMb+TkwpLqE9l4ORvz7oc7dhH3bAjyRGPv3vkABROj6uuEc5FOm+bCVL+Q BjAL0ZtqqSmMAvC/RaX+jrbasy4W43/4saqpAInPOtDIg+5c3lM+S565yHkUG/Dq aNi0Iu6ahUQvYC8m9QuaUxFJzYXJ5Jflid494/zQIpfFuPAdnnmHS+wUsepmNHu4 jqEYRyy/S1R2vL4G3rs1wsAJcadseIDKYsWc5pr3gcB9k8kGvILPvKr7EnhydHKf SqMmAuviir44DaeAvqmjMEEj6x02mdfHQGM2oHdsrh6JmrtmJci/mOYQ2riAVPPm DiqeTNOeRJrX6+wrtpqCPA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c55v4u6e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 12:27:07 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49PC7U62015833; Fri, 25 Oct 2024 12:27:07 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2169.outbound.protection.outlook.com [104.47.58.169]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42emhc7tsq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Oct 2024 12:27:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vuN4Kvecfo0MJjCubI5yCv+oQUhA0uNs8rSng/QWq2n9dxlvU9Y6vOhTlN9ysAUmh1a0ep35JIZU1PxlQeneb8wBLzsvk3TH0LrXdsmTXU6UsB/O9/eSXKJs9kpkxunP7ZOnYgUjiPGgLDrLiBK23QCN6GbwQ8K8ZW94xO9Zwqjmb3xMOpxAqRa6ILpS5fSL4GfSoJqPDURZWvLV7V81+J5dcabitzuoUe8SLPye0KzIb/fuBTHtFS4pxkRMfsQ4LmF+cFWv3XTMvZM78Q7uTw1apCC1rKd2M/gqGTqdMZXqTIYHQOvE+n4acEQ49cKTdsLMtTdTcJda5grbIk6uBg== 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=rzah8PtqmSFAEkrgx3+NN4GKeumy7rZse5pxRqGcMM4=; b=D6oKmgNf/UXzpL/dXz+9f7KWHoxZYgb2JutVdRM6s/N20GNqwRZlNbSL9ns4TYsWRRxG+WIjXXhIOCsst4/dBl97adfdXL8eVidv+tV36kQPuC2Gh5nDdHA8JXFIikklgHDpYTu8K7BzmL2JOljvMbn0gLQTH0HQnbdk+gwNKdmydwjikV5uv+/flMDY0M7FfPIo4UTWljvAK+Y36tDexMzz2sg1oEi+T/jSAyZ/gMXUDTdN5nppmjLdwlqNF84mzEmWX2JZpEs+665TA2lKMRVBlz31aFpzPt0Z2/6f7LKE+VVfpK7MrDTIxpEITlMF/6FU9eULXUhsjaI96TCi4A== 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=rzah8PtqmSFAEkrgx3+NN4GKeumy7rZse5pxRqGcMM4=; b=d+nTQH8n3jY/vlBTBqStNRSTTmeuMf1NZfjX/CTB+Jf/SJNr4ZxQW1d7xV+xNsabH0t7wGa1lA0o8J1NQ2j0EMAXv7b6w3YH1Yhjle96Xhx80Js4gDOLE1SXHDFBf+2V+fZZFlrMjdMgVnqyorh4iuQuag7N6fjOBS7A+moWOqg= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by CO1PR10MB4484.namprd10.prod.outlook.com (2603:10b6:303:90::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.23; Fri, 25 Oct 2024 12:27:04 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8093.014; Fri, 25 Oct 2024 12:27:04 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu Subject: [PATCH v3 5/5] mm: defer second attempt at merge on mmap() Date: Fri, 25 Oct 2024 13:26:27 +0100 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO4P265CA0175.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:312::14) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|CO1PR10MB4484:EE_ X-MS-Office365-Filtering-Correlation-Id: 8dfb44ee-6443-4906-9909-08dcf4f05532 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|10070799003|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?qYJuqreerQF9eUS63UnHKlkXtcJOCi7u7FFhi0Fretog8trb9ejn+9RZi3rc?= =?us-ascii?Q?s3ebrojTEX698SSIuxzXJ4bMC7XzvyLr02xg77mEVYjmGohgyrNAijFovBEx?= =?us-ascii?Q?YdiXVTWg3cDi11OVVj96q40Ib/uagCgwaUjmL5V/ajFJDBC8oT26XL/rf/+K?= =?us-ascii?Q?dLpA3ekKjyONPSk2IZsEw445LoS3iMyEdnm+Og/mX/h2p4E5DAnQpLLKMl+R?= =?us-ascii?Q?GtFrPsug5nY5Tqr4tkKKFDKt7ifUtn/jkIx+Z4dFY7Ndn+KHfK1cE+wrakhz?= =?us-ascii?Q?ERIXAOfq1e70Kx/PIbbZFeFZoxJhNw9M2s3k7WAHY52bpsvI9rkoR7d3MXkK?= =?us-ascii?Q?uFZoIGax+weg6c/eEDT+f7s/bxxI1Y1FArAmNXMw7RhC0d4zNr2tu/Ore7qZ?= =?us-ascii?Q?BB7Vw1kd6hUjbULMwqdil8POo+R6fgNITU+aOcNM35LutC6uk5gzkZ5T1Ne7?= =?us-ascii?Q?SiZc2/oL9zVL0469Hj6LnhCBR3Zys2lVH3sj0ysdWFcGUgLQ3MW4Et9ZTkIS?= =?us-ascii?Q?6v5Fa0prkwqTeq2CovyA7a7mDrY5IZpcgj3nWDzNroE67bPxm9d0Gk9OD+Jf?= =?us-ascii?Q?twg5OwIV40OK4y26TgGTTJogo2UWwS6vwypwyiNomZOy6iAHKnTvKEnEiwK0?= =?us-ascii?Q?tvMzei63HmwbtSg4w3TMgkBQRwU5GMa+rHOo1OqQogCPrx2TtScbWKsfczZR?= =?us-ascii?Q?Cl0+3ijgc98Hc6os0XKEAcLNG4phXB4MrrQJLhtXsFDKMH4vorFG1/+LCvZb?= =?us-ascii?Q?xjGhGXucILYb3Y+DAbYXOzV2sYur69B6c4BqA5pcByyq8dpgDXHhhfkPWJSJ?= =?us-ascii?Q?1I1YE4PM3Bg/GQQrgapfV6KK2DAI9FXftN3sbhWTpou1w7NVptndhwj1KotW?= =?us-ascii?Q?83bblAMBFsohOY1Y5kpKHjtgb06MRBgPmLs2QQhUkjqnar2oJaXdgQscbHA5?= =?us-ascii?Q?Ub7hLAMgeqT+kGQAluGT0eV+ckFKZJt0A3TDaKtV9JpXapspcXzKFcxTSLvK?= =?us-ascii?Q?PEHnM5zFJkIw2/R9VpR6evCli/lhRrmOWPgkF8rt+Ltmd+IPRGD0ocE51UNf?= =?us-ascii?Q?IeQ0hR1rUGg5+OFJj8uq92Wc6VxWD0A/QzwgxU0X61PO/c4pbGMqhA2TDjWM?= =?us-ascii?Q?e2IUf+qZYAsdKKsDoBTR76air6Mt5MlbdYzpSS6j71tfGfit1JlrC6vvuE8R?= =?us-ascii?Q?fVwgQJVg6fEcoMV89VvqLdjRxdQbV9lYZdt/O43uqq6HUf4I78W7XoDPAMyA?= =?us-ascii?Q?tHmhnETFMwaOqhX03Ok5seOhQJL2QxwybAoE/JMH9lJ4Hv8iJjHSf6F//Sq2?= =?us-ascii?Q?Je0=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(10070799003)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?+3uyN8lVUn8n+fz75PQhfHl7jSyB3C5kZoHB+3RdtHTZ/J7yLROjn8AJ9Qik?= =?us-ascii?Q?f4J4KVVHeABFXE8bYEuPPC0XpI8jW9IrQXaeeYV2/I8MFRnzpYUCWa3n3et+?= =?us-ascii?Q?C3Lzk6OIHzMhLjBwz/KS9ZhBqC/wqzUjQsKEQ4BlsATMz3aDE0FvGg4UQn2a?= =?us-ascii?Q?ZVLPoxKKI1PnWXGw66DGvYycwBcTIkzot76AvrHZ4cxq9AVZMVD82/tadtfD?= =?us-ascii?Q?qFxcGH9VeSzOq8G3/GeUz7kyEAJkvNRICq00vjnG82XMpkM3ArGVvw8OgeD0?= =?us-ascii?Q?d2RU9peIBNPA0RESnXoKWXkbVZhl5YBfYOGIP8OaBa7rX9u/5x0dwmL/C27C?= =?us-ascii?Q?pW/6JGxe5P3PWP5oiNRmXUn0snNCArAc58PmTyK4IeKZQH7zyXKP2IpmgONZ?= =?us-ascii?Q?z8m+DRpVRB7zpw5PsVSRydR0O1pFTY2GOENHLdtV4SyGlOCmU7HI5ypgossw?= =?us-ascii?Q?xAA+sjBE1RdN1/v2kUmGqV+Gci4X7GKRFoC5JHe/6FvKBr60aBOQ3Q4B79+8?= =?us-ascii?Q?Sq7xIzoalKgUFrHFkR6qf1QmP/uLXRIty+oFN6eap1u70otqmV9dMxsolXCf?= =?us-ascii?Q?jSgHaSluY73EFkxqs6jZ3QMKg7XPVuFl11zVtCqkRxrCKddLcsw9viQ3XqeM?= =?us-ascii?Q?oiG6q7ukym8Kr3pXxP+pl3YP5+Wc/2nYSgW+IwuprsdU/E/SniQwneK/Rl6k?= =?us-ascii?Q?xkGEvoSdBUYZbC4hm/KjaKUJ02dQgmM+pmKv3emjF2LPIIOwBuMPS3YZ9WyM?= =?us-ascii?Q?t1NUVZiBDjgbRjAkhDrouMgFWsxKLTsdMp9PoUyAICuUp3E9Hzko4yTmRLzp?= =?us-ascii?Q?6Z6U9yXixG5xs6ujP0KypKpbRiJc7yK1oDgQybj+2k/9pAY6bhYDHShTpIo0?= =?us-ascii?Q?qD2Rq8tY9PKy7KWyN0D+tMHFnrNkRewEQRJO5DAOyrhlAEDOYBFuc1rRcSi7?= =?us-ascii?Q?pTUxc639M8X1/tPS/d6YKOvQTNjSgHuBgRV/g8Tl30rzEHvhWVZn3kvITpA2?= =?us-ascii?Q?cFH5XAwMBH3dZMaHaNbSwW+393qPNrz3KKRYtKFKN+7gUdI8prlM3n6tqpRA?= =?us-ascii?Q?5GzVDYopR1fI4JtFeXynOj4Z5XTris0FkRfDpf4xX6hZkEdT6h+B5PU8cDgk?= =?us-ascii?Q?xoTtZpeQmV5iwVB3oRq6LE9LiHGL+4ZCv7TYh+jyOCHHtzV6b5B/QI9ufn0W?= =?us-ascii?Q?Rb//TdhXtr3wdCmTBNI5WpQ9ylf58RNc4hXmNCT9PLfJm4b/OZSesi37vIu0?= =?us-ascii?Q?v2QZpy2X0squutTqoW2du/odpLyloU33vo2SWMWioh3cXtdHjIv/zXInr5ta?= =?us-ascii?Q?pB8W7UCSaOAcVJD+WEkcyC0X8Ei8oLpEMHT7VCepXFDyvG+FwrOPiPpFJKzs?= =?us-ascii?Q?7YWjLvTaFKprgWcngCJMqeCQE03h7o5EdSSyUXRjiMNiAF7WvuBFTA/fiS05?= =?us-ascii?Q?Buo5T4PgSR3NJZqIpEs+JjmBZ6JPEzHVtsQHpAS/fZm7kd77hLp6GCjCZ3Q9?= =?us-ascii?Q?pAPffGgTqpOLoudDFJ7W3DLmA9CZzOX/rCbPaFDnXqaEAN5p1h0q6MtxuyaR?= =?us-ascii?Q?aaKQGy1Emepk6QIYLzPqVFtGW0Mf3/gOgDOpkuZ2VU77ahxEAfcQuL1JGT58?= =?us-ascii?Q?Sz9EwkuRbNIQQWHCsa4yfB/t4WL1gPO1T89tf7aFFks7n5O9NqttqpRXwcDE?= =?us-ascii?Q?ZfQCfQ=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: lJiofi6nJtiajkXLDa0h3aGGlb+B5ShIJtcwI4UZes4KDXME9RLlwv5IXgVuXWH1FPFMx1KNs/bIO7E5zpsYajEbImvnJegmDGlImaIxvQArkv91EY6i3n5cTm1BSwOH3uFiewVMBT6XLm1YeU20cPnYFzkIUR1lPYp/Q4eNomAJMPQJQBvD10v3AuWsS1xGhkB8VIBZg2TDw7qnirOLqyC3qkiwfFh0r3rMAVTiJK2Hd2pE4/EbMFCCn6Cwou9KFlch5F7Dvq4cZb4hHzVO5Y0yB/XA7Q7bIbeg15riugzsCAskFB3muLYi/o7Y3jUi1eEb2PRD/7HBE4QjBE4WX4hGinuqnF1zzbwE74rBMRFIeFe5qhmJmWS34lh2gbbyE9jGXrzLFdp1ojo3QHQSm4rR31VmcItl9SGujJ975KiiY2HXj6h3Fa1CiievieAvyguKnojhNF5LPzZj4EG6MCc450Jk6LhAJ2WGQiLnE78vV4U7QSNqGkIarsPP91S7G3k5Eji9b4TsVWVCo420RwTIl9iLU+SEzcqUbS3vjJEIDAUtpaYD9T7KzMpttIytad7TIokqo11yqu2CygB6Z+vStonB2mgqgJQ3a+2DFoY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8dfb44ee-6443-4906-9909-08dcf4f05532 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Oct 2024 12:27:04.0639 (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: Qnhg7qMjYjckbdbujNUcTYaZxDF9TdxeEieuYAb6NZNm74nj0sdSFbeUk0EUoSxrEu5+uEkGPUiCk0SkCoWUO8nMk+djPbYfJ3VDThCVrXo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO1PR10MB4484 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-25_12,2024-10-25_02,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 adultscore=0 suspectscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410250095 X-Proofpoint-GUID: 4846HGWgGTtz7mQcL5vJE8pt_jl0mp-L X-Proofpoint-ORIG-GUID: 4846HGWgGTtz7mQcL5vJE8pt_jl0mp-L Content-Type: text/plain; charset="utf-8" Rather than trying to merge again when ostensibly allocating a new VMA, instead defer until the VMA is added and attempt to merge the existing range. This way we have no complicated unwinding logic midway through the process of mapping the VMA. In addition this removes limitations on the VMA not being able to be the first in the virtual memory address space which was previously implicitly required. In theory, for this very same reason, we should unconditionally attempt merge here, however this is likely to have a performance impact so it is better to avoid this given the unlikely outcome of a merge. Reviewed-by: Vlastimil Babka Signed-off-by: Lorenzo Stoakes --- mm/vma.c | 55 ++++++++++++++----------------------------------------- 1 file changed, 14 insertions(+), 41 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 7c690be67910..7194f9449c60 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -19,6 +19,7 @@ struct mmap_state { struct file *file; unsigned long charged; + bool retry_merge; struct vm_area_struct *prev; struct vm_area_struct *next; @@ -2278,8 +2279,9 @@ static int __mmap_prepare(struct mmap_state *map, str= uct list_head *uf) return 0; } + static int __mmap_new_file_vma(struct mmap_state *map, - struct vm_area_struct **vmap, bool *mergedp) + struct vm_area_struct **vmap) { struct vma_iterator *vmi =3D map->vmi; struct vm_area_struct *vma =3D *vmap; @@ -2308,37 +2310,10 @@ static int __mmap_new_file_vma(struct mmap_state *m= ap, !(map->flags & VM_MAYWRITE) && (vma->vm_flags & VM_MAYWRITE)); - /* mmap_file() might have changed VMA flags. */ + /* If the flags change (and are mergeable), let's retry later. */ + map->retry_merge =3D vma->vm_flags !=3D map->flags && !(vma->vm_flags & V= M_SPECIAL); map->flags =3D vma->vm_flags; - vma_iter_config(vmi, map->addr, map->end); - /* - * If flags changed after mmap_file(), we should try merge - * vma again as we may succeed this time. - */ - if (unlikely(map->flags !=3D vma->vm_flags && map->prev)) { - struct vm_area_struct *merge; - VMG_MMAP_STATE(vmg, map, /* vma =3D */ NULL); - - merge =3D vma_merge_new_range(&vmg); - if (merge) { - /* - * ->mmap() can change vma->vm_file and fput - * the original file. So fput the vma->vm_file - * here or we would add an extra fput for file - * and cause general protection fault - * ultimately. - */ - fput(vma->vm_file); - vm_area_free(vma); - vma =3D merge; - *mergedp =3D true; - } else { - vma_iter_config(vmi, map->addr, map->end); - } - } - - *vmap =3D vma; return 0; } @@ -2346,10 +2321,6 @@ static int __mmap_new_file_vma(struct mmap_state *ma= p, * __mmap_new_vma() - Allocate a new VMA for the region, as merging was not * possible. * - * An exception to this is if the mapping is file-backed, and the underlyi= ng - * driver changes the VMA flags, permitting a subsequent merge of the VMA,= in - * which case the returned VMA is one that was merged on a second attempt. - * * @map: Mapping state. * @vmap: Output pointer for the new VMA. * @@ -2359,7 +2330,6 @@ static int __mmap_new_vma(struct mmap_state *map, str= uct vm_area_struct **vmap) { struct vma_iterator *vmi =3D map->vmi; int error =3D 0; - bool merged =3D false; struct vm_area_struct *vma; /* @@ -2382,7 +2352,7 @@ static int __mmap_new_vma(struct mmap_state *map, str= uct vm_area_struct **vmap) } if (map->file) - error =3D __mmap_new_file_vma(map, &vma, &merged); + error =3D __mmap_new_file_vma(map, &vma); else if (map->flags & VM_SHARED) error =3D shmem_zero_setup(vma); else @@ -2391,9 +2361,6 @@ static int __mmap_new_vma(struct mmap_state *map, str= uct vm_area_struct **vmap) if (error) goto free_iter_vma; - if (merged) - goto file_expanded; - #ifdef CONFIG_SPARC64 /* TODO: Fix SPARC ADI! */ WARN_ON_ONCE(!arch_validate_flags(map->flags)); @@ -2410,8 +2377,6 @@ static int __mmap_new_vma(struct mmap_state *map, str= uct vm_area_struct **vmap) * call covers the non-merge case. */ khugepaged_enter_vma(vma, map->flags); - -file_expanded: ksm_add_vma(vma); *vmap =3D vma; return 0; @@ -2493,6 +2458,14 @@ unsigned long __mmap_region(struct file *file, unsig= ned long addr, goto unacct_error; } + /* If flags changed, we might be able to merge, so try again. */ + if (map.retry_merge) { + VMG_MMAP_STATE(vmg, &map, vma); + + vma_iter_config(map.vmi, map.addr, map.end); + vma_merge_existing_range(&vmg); + } + __mmap_complete(&map, vma); return addr; -- 2.47.0