From patchwork Fri Aug 23 20:06:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13775908 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 575F9C5321D for ; Fri, 23 Aug 2024 20:07:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9D1AD800C2; Fri, 23 Aug 2024 16:07:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9807C800B4; Fri, 23 Aug 2024 16:07:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7AD2A800C2; Fri, 23 Aug 2024 16:07:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 5C2BE800C1 for ; Fri, 23 Aug 2024 16:07:32 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D78D2141E18 for ; Fri, 23 Aug 2024 20:07:31 +0000 (UTC) X-FDA: 82484595102.17.2B208B2 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf02.hostedemail.com (Postfix) with ESMTP id 7248180011 for ; Fri, 23 Aug 2024 20:07:28 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=HV2ihxX+; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=lXllRYz4; spf=pass (imf02.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724443607; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vwvcGfY8z/E7d1LQNSWVyNbTzzeBCeH2vvP6/vUeckw=; b=vYiJjjK2zbAJxSeMfP7Krx3rKU9R5nHJXb8LH5+mpGnCwjGCAQHzEavp/r+rZ5aMzihcbt hHeYpm5AqtelsBajOqksWalJ0+bUfrlWWkVZNiAF3bJ2SvggiaVCrLVCABIDDPbgbl4LMf UTpurKI2W9otIAQ0MFtsfUCdMRXjKuw= ARC-Authentication-Results: i=2; imf02.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=HV2ihxX+; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=lXllRYz4; spf=pass (imf02.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724443607; a=rsa-sha256; cv=pass; b=bn1lOGWUi+cOl26tkCnA0a3ILbPSOtOCgsl0mQ0mmu///8++ISwzm2iRSswayE6hqrudYd /bbGt2+JgsNfhUxrHjmDLC+6xd+xe/vUI+EM2VNJnsW0zbAzIAYEBa9l+ZTCwWs5MmHMs8 lshthSiFk5vG3xZF+R29jc16ZQq5Zo0= 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 47NH0VeS010832; Fri, 23 Aug 2024 20:07:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=vwvcGfY8z/E7d1LQNSWVyNbTzzeBCeH2vvP6/vUeckw=; b= HV2ihxX+uP90/5eHWEEQT/6B1lyeMZWyOC7rBW90k1r1YyGSdRsmlthN74kZSmuA Si05mw9vAeaL5jo9cD8lN5kyq9FF8wZfIdKleiUAPIy8Rl7ZPQgjv1Fhwks1zKz2 SOBWOaeiNYQLV030+IRyW0p0njeW6sn6XaMprdINBGiBP88qPM5BAJidY8Z6ZiHg yDBe0s6S0KN8uLzao+ffYzxuIuRPrflHxcGDVAn0KoyFG7g+eKfIiXmrluY+40K5 x+xcxcp1GrbYEKHSzGAFGgmTji+VdkKOw4CQd2mhUrjH1RxV1t9OOWtPlw/S6qni chD2IHMEuXCnrNUgRRxC3w== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412m4v56xy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:27 +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 47NJdFFc007123; Fri, 23 Aug 2024 20:07:25 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2177.outbound.protection.outlook.com [104.47.58.177]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4170s610wk-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kudwNLhPTYnzIFub58tLNLqPO1YUtLisZCpdBwkyuqmLJ/hHlhW01IcIm5BzztrAv006yjvrDtj8vzSSJ/l/SkdnnAA4ij4a1xUJyosFdYAz/7aAVZYn1q943WSWXruXjHVY5xQIMi/4f6oh7JJwXyw4Dyo0FY/J3qDcX53Lj3jXBKfKUx5atan8Bcde2nsx9HuhlHM3MsJ6ljWs2zesdQHS71e4Adg0TyCOIq0YM8Dka0UI76J/B3LB40AdCfIUghXobfXctjdNEcZqGnGg8WRrbmmx828nkcvtjjPWQTmpT9U2S9AvhhMY5ntRQvnRapMEnCqByLUUlocjdJh/xA== 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=vwvcGfY8z/E7d1LQNSWVyNbTzzeBCeH2vvP6/vUeckw=; b=M/ayX6QXiJXfpLgTG/jD2XZQBhnMJJWvUkwvHZ0LR8DBddzAU9ejMmJOGJ1FQPWhT0d/B7Js/TZ6mo2GgCWhXbgrDhOui0mVxiWcVSCarwXbKETOgrIRPjLxXXhQPUs6emKHV7MsQzMPrfmlypqSorg0a1o2zlriR+eOoRiZKTZ/xbXFdLmzKTcotit9ZnryWy3fV+k/BMIXLM8AHTl/2TBbiiUkrTDz8AN5y+xiki7mfrPDd6a3QVZVn1sKZnYpV+siekxXAUVl4vS8SHx5XckAa1CFSrVRjDAbuPrqNe0xzw4mPL6r7rmZfjHUTu6J2SeNdWKe5W5AUJ7PRO7qxA== 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=vwvcGfY8z/E7d1LQNSWVyNbTzzeBCeH2vvP6/vUeckw=; b=lXllRYz4aW4blOGmmwR+8dSs0olmgdHk/jvvMSITwvd7Hidu5Q63VWloZMzna084EQmOmrXU0nOMjZz4+sBeY01P57bvAKsTKkVGf7w3l5MxK22bNQBGKtGYOhVC2cLpB/+2RctVX3TrjywctYWM6+wUciE8wtAjvV+1r/SjcxI= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by BL3PR10MB6187.namprd10.prod.outlook.com (2603:10b6:208:3be::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.17; Fri, 23 Aug 2024 20:07:11 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%6]) with mapi id 15.20.7897.014; Fri, 23 Aug 2024 20:07:11 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH v2 01/10] tools: improve vma test Makefile Date: Fri, 23 Aug 2024 21:06:56 +0100 Message-ID: <31cdc7695e11b6588574431666d806e5d4e3a909.1724441678.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0189.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a4::14) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|BL3PR10MB6187:EE_ X-MS-Office365-Filtering-Correlation-Id: 22e7f207-62af-48c3-3a73-08dcc3af2c6d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: dr2oPIw5StTNo89m1RiSqBDPedK1zWNu23vbNRCu12Gga0iA1l5vhPBpzx/v02tw8Fh84KFudtUP9NQBY8hvXeW1T/5QnFo2FgZ/E/g0hYi7hyrpSOkInk01g+BJl1z+b4Hia0uZItnaLu0q+aRXJFsvRUpCXXeU3ZD99jfeD5SxYYQ8VNmA/lxmsXDVLqq/800ABf/poUFnvWREWOXWWOdobWa5lmHH+icyVOGM0grXDhG/jRy/cuWX1J9fiiFwooTnkRrsFvea0NHolbUphz3sgP2KfgZM6NnNlYDvmk426MYJxE/aHwSL3EkHmHEvBZwf1iU94QSUA5eKdeirmSswR44pkj8azTBLe8xg6oRP+Amwwg4102sonByHTff5yYQ5NtNI5ICK4DOdcTlxRIdSNMQG93slFXf+6glIyp1wcWS1bEaaMAxjtVEH0rJ7ihWxWBhMEtLZ0KDYb1Ke2EpZY7u+IZn9gkQFsNFRCJiu0Yo7eMjBQZjrkptkVO2AJL2TuE67wvAx8i4IY85OnKiChD84jQlD89zPcWocUUEentgaOaPbs9kFyrkBEPKcijAxNO0WekF7xxEYsogrqQG6aZuACTMAmBffCj11K+dpaMNh0VN4mWoWQwnU65IMccqk2Lx8v33VI9Q8mM0uPssS0lxkURiz+Hg3Gta8bD2ayRvt2unUIh5n9tXAS9vZGsDXa3r7VJyYyDDhC5Ik2f65i7c+AF9YmvBT8YKHFtTwnKNpcAl2bIMCqnG2cl+qHtqRGS94XTqw7QC+qnBOnDUn8LlmxR7+vGn+gVtYHVtC7zrfqSvagErOtRzdIYF91/y1zdY8RgbQw+9qABQIfj9C9Ywwk43JHpunU/5HlwuuiG0MZ+B2alxiPgyJ8KHKHaZZF3sbXpJOvVmj0jM1aDM1++a9sd2N5CU1SXP4KDZveBSYUWv1wybaOSfcG3zJl/ZNrQu5dPe3KT26kNBpH0mQodi0LHZrTmMDeE7cqVBFFi7UreCVHK9vJrUSZxD7pWBixjOiJ9olvAD4lmu+UqzSfDMbmPQw8XSqIqafr293UlbR9YxVcGdVJumpxzpXhtsmOPrSEUZIplU7o12WFbHo2p1dX0G/nJiwuq6R9+t0u3svDLXF7kqKCQflL1JV2c1jRXG6t7BWq8R3lKeld3+rD+fG5cjkpvOyv8KT2aMc2zmwOotDwl12os2HHWQoR+Zqx5KxLFhbCq94KwnRMvMFVjoOguiogTKJYGgXOocyTN5uSEmP5Oh5siCzC8DepX78uUkBzmz5GK5gsCGJWPdcZlv8vcqCilsIEzceKCIvwhKEZ5qUK/UlB45Z9qtIK8/V1dlPCSiEWKc+iLF4pw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ov7WEF3H57y5zWFTMI5WtKFEqhte23fRmt4kJamDGQPaoQrTu0u/I6/zWjqkFzEPS8w6JAusdOEsMSE5xrNWbiGKknjPQvbxpGo1n+/9GUbuq3TpclpbEzT23A+5rwbvtYqha14LI/2SnLXZrOMF3n0FBASG8d0Dzjm1RaNrrrpScPQV7VOrd6HHTII6QGNef1hh7HQZZZp3J7Lb62JXtQl4YOenWInyDcccN4aChl9hCT9iakMZ1SfwY+kkdHMf2SEUhaKjh7lrCNB3fIlWksmLYJUFA3LpXK4umwa+Tp9w1DEzNz/AmYr/yUU5p6xWF5/6pkHayjgft5XH3E2KLdpzCef0lAVnMLy6/AcnDnplVUOHtIf/WkNUun52InUQciv8vnUvPf1Hmav0xQoIrnHhIZ3TaxsMiBv+8+zM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FDlyy7A5bqtwIC9CejPP2iVR2p3aKYI6pdwrd7krGUvHApX6SjW/+0OIMrhz7LA57fpcPj/QrM2Gc+6OfAMgtqiXlnuHgR6lduRyFXD8thQnWgGH2VFFrmeT734Y3A== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: HakRyIuGGrqpmlD3gkJxkKI2pfCFrwWI9DlmZeHJBpyQjptQ0aT3pgXweLBzHIys3hC1fAwHCLtadp0IafdvWmJj/XJOBjGkpnyGUIyplG7dm7KlFsY/6BDtEXe5EJFT2A33qRydrNYnVNKpRCnirGLlvYADLjF4BaUKs3QllgWu/13mvPCXXhPjJChHOAacpR3TDF35ka7n/2I5+pxiI8hIKNTHXwuvcSQs1RAfLu3EOQbxx2gGGtQejKobO/a1OKxmZWaOM0WVCVoXDlgiDl/ZkDQbo8qMe6/c4oMxw8JpAJUc44M71dwH4MJ8W9CFK+Ol3zoL+Lt1kea9kINIYAWSISvtSFtWwKi8a6ao63wXqrnVJR1E/4CNTDRT4rLUcUJh/BHR6lz/v7+1dJaoITuHfhxDbQGAZwx+13FuHoqNMZgWj+E0lgLvQ5eTTJarS7GRgC+8qDlAXF/j60kQqcDpwfy/fN+rIm4rK6kfl83BWQTLdfRpuQugWtJOS6PbVszH+qsfe4GXpNbb0skQckdf8WMNnqQHXm1okLgx0b6geRQd/Ffy8XaDMhKCsGtn594nhp92PHQspqwWkDBEXcNCeB2x93gLxaHbpsoCy+s= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22e7f207-62af-48c3-3a73-08dcc3af2c6d X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 20:07:11.2681 (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: eZAymfB9n7CNO1Tl5oiaDbfySn8/5SiqSIBj2Er8bATVQTdE/yhyeaqmRv4RlS38xuIBckZ5swo3Ail4a5tsgmy5pM6OAKPnOtCQqpDnYvA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR10MB6187 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-23_16,2024-08-23_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408230148 X-Proofpoint-ORIG-GUID: 4ouXl2o-asrgy8B4YFmzmwTo9ihdcyqL X-Proofpoint-GUID: 4ouXl2o-asrgy8B4YFmzmwTo9ihdcyqL X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 7248180011 X-Stat-Signature: 9e8sgsz5689jjwc76xfgoyy8mmxqga9t X-HE-Tag: 1724443648-595752 X-HE-Meta: U2FsdGVkX1+tqmQuK1Qw+0bYUIerVuK7V8eZKtvzI9csVK1srOk/5rz43OIM9mxNBapWepOnfLa32oT37cj4JdDnF/AwwB0y1kQcMoodxqRRcrvhHnfjaoE+h+6ha4Qzj/pUs/D3cUTE/9lu+w6IjgepmRBtKaoyWJQzPnf28xHcPAIpwK8eRmw60tEV9WObGryBje5zJg8ZQ32sq1uXqxfIOElqXqJiLFkmUNPLj0m5xuPOFPNLlBcD1oKLEtrG+jFazXuKLLcrxB8ev9decuG0wZq2vgJEa/xxFWJeFWehZnpwAk0S3vBgddIHhmbzQ/QWREGMHYLQr+jpXVOS7sGS/Z9YoVfFbyx+cqbp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8nbuEwLfqEYB X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Have vma.o depend on its source dependencies explicitly, as previously these were simply being ignored as existing object files were up to date. This now correctly re-triggers the build if mm/ source is changed as well as local source code. Also set clean as a phony rule. Signed-off-by: Lorenzo Stoakes Reviewed-by: Liam R. Howlett --- tools/testing/vma/Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/testing/vma/Makefile b/tools/testing/vma/Makefile index bfc905d222cf..860fd2311dcc 100644 --- a/tools/testing/vma/Makefile +++ b/tools/testing/vma/Makefile @@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-or-later -.PHONY: default +.PHONY: default clean default: vma @@ -9,7 +9,9 @@ include ../shared/shared.mk OFILES = $(SHARED_OFILES) vma.o maple-shim.o TARGETS = vma -vma: $(OFILES) vma_internal.h ../../../mm/vma.c ../../../mm/vma.h +vma.o: vma.c vma_internal.h ../../../mm/vma.c ../../../mm/vma.h + +vma: $(OFILES) $(CC) $(CFLAGS) -o $@ $(OFILES) $(LDLIBS) clean: From patchwork Fri Aug 23 20:06:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13775912 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0C9AC5321D for ; Fri, 23 Aug 2024 20:07:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E8E80800C4; Fri, 23 Aug 2024 16:07:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DD182800C1; Fri, 23 Aug 2024 16:07:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A45A3800C4; Fri, 23 Aug 2024 16:07:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 59278800C5 for ; Fri, 23 Aug 2024 16:07:33 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0CBF1A1AE5 for ; Fri, 23 Aug 2024 20:07:33 +0000 (UTC) X-FDA: 82484595186.10.CBC728C Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf10.hostedemail.com (Postfix) with ESMTP id 854A4C0018 for ; Fri, 23 Aug 2024 20:07:29 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Lj4lnF3R; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=M5PWar0k; spf=pass (imf10.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724443584; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=UPxqbNoDBYP8B7VVZMhyOT3/5hYZyNmGe2+94P6u69A=; b=YGp35sBNgOCuKpY0QyA6iBHOi0WtBLO5jGlcliHk1a+x7suuh475L0qsJH2MORpzVo4d4L 2DPiFM8w5d5j/9dcoPEpn40X094xkSZuKb7LsTtOowGGeyqwrfJpGd1pt/Xoq7fiR5368W 6eVQ2Rft5v6sYT5F5gJZLS7G3HjKbfo= ARC-Authentication-Results: i=2; imf10.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Lj4lnF3R; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=M5PWar0k; spf=pass (imf10.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724443584; a=rsa-sha256; cv=pass; b=EfZTX9Eov2aqsuFe/nP5Fm2C4G8yfRXOcZ8a2eoszocMx/YVo+LgQPQHy1fSbsECbC+KSz T5R9/jAlGQc9PZeaGBxJy+Han4BV05ttnFzCETHoUrTPd5HH6Mq6lncb14hNffZT4n8lo2 BbK/SfCPzOYCG8wiia4qHQej794UqjE= 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 47NH0XEK025165; Fri, 23 Aug 2024 20:07:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=UPxqbNoDBYP8B7VVZMhyOT3/5hYZyNmGe2+94P6u69A=; b= Lj4lnF3RRXO1ErMBCgFPrcU41k60+gC+xSm8/LmetjLHI/8+R3PeHU0avDBKvH3X kUBTenHvLFKLyQen6xbzaRXVYiy3pyTWi+NlIfV9iNedBcJ8pW8My0ab15+m8q50 E9+9hKdBebtYpCq6DRIUYZFeJo7W8N0UH6n3qvht9ptuVaL7wF+Z0TS7+W4mimb5 amEcvHvNqaMkvhS0R6UlX8F747M+3DDZOm5annW91qvj3xlC6+iZqus2NczycKd6 jJSA5M7HbN+KTM6uIzx1vcxPOYk7nFZtY/f0gT8mePE3fnQWrg4VF+YIFr0tXZU2 XaIukzrF2mGRooHIckR64A== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412m45n6bw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:27 +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 47NJdFFd007123; Fri, 23 Aug 2024 20:07:26 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2177.outbound.protection.outlook.com [104.47.58.177]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4170s610wk-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CB5l0TUi6nzVNfNKD4WzpL8wbcS3znKCbNn1cm1bt62IXNMgbAKr0Gy/Icy8Xh7ZrsJFswoMXfacZ31cr2oqJsWNDWEZI/5pZ4dc0iY8Y7oX11chWOE5orM57KIFZWWTi0TOuKzRlpnyMeD1dT8LHXl1fgg3K0KsC9mgULUuOaxzoBXE4Nl+p+A7aUMuZVWZHsdza/UhIcxmGxWccfnklCebAmnZp3K7jqpkjbueVhTnZJevyREWYdV+LP8k926ybfTp6as1w3XDcNJ31qDvIW8I4omz2Qbgoj0786OSBwjP44g4e1pFChTkgG1OaIZhKtw44ZxNrQ6aqlOXHV+qZg== 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=UPxqbNoDBYP8B7VVZMhyOT3/5hYZyNmGe2+94P6u69A=; b=s2vJVSj/OOboQimsHINWFtBh09sPB7uObr2Y+GYLBbnQWHCJn6Q0k/16mH5ovbhj8tJy85ZL5LjsbTVvg5FZ67tu5S0HIL33e0bILIHvSA0kWnWg/m3fMqbXReN2ZnMtndJTlTnEpIdBpxF2IRotE9u3OZgZnbsXa5HWlnnqqJVM1MsTQBsbYMxJAQdZ7QV9rmIXxK7L6DojkLzJeb4NOutOTsBdaJYfyrOhRPRj7bQSrf9Y5GqFnv2heHdhIrE65WrDnwatvptVc97xjhdSOtlZsonFA81SOEHesjlOGCYgd+ypJ6UeLd6Z6Z4iTkuywif4ftAoFxFhr9V5GFfdPA== 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=UPxqbNoDBYP8B7VVZMhyOT3/5hYZyNmGe2+94P6u69A=; b=M5PWar0kDc39sF3/N6YYfMpLiKvwRk6LVrkCTo9Of8oScv0m/j4zG4wmDn1mgjree1ZtWH2GjnbHNLBPtXzEPsWbd07OCg6TI9EiD3VxD4ebXVBiNg5mtYGdo7RsoY/S/CnM84Or6Ew5texIk9O09qPvkvOSMYk8HDwk5LPTD2A= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by BL3PR10MB6187.namprd10.prod.outlook.com (2603:10b6:208:3be::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.17; Fri, 23 Aug 2024 20:07:14 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%6]) with mapi id 15.20.7897.014; Fri, 23 Aug 2024 20:07:14 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH v2 02/10] tools: add VMA merge tests Date: Fri, 23 Aug 2024 21:06:57 +0100 Message-ID: <0ba339d826857ec8d7a37412464d23af84578d38.1724441678.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: X-ClientProxiedBy: LO3P123CA0008.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:ba::13) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|BL3PR10MB6187:EE_ X-MS-Office365-Filtering-Correlation-Id: 74668c1b-eef4-4298-4f79-08dcc3af2e19 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: x1aAZmFJmfXbCSNxE+h6vB2qm/Zh98B8psOoQang1mVjwZHDlTldtqM8tebuXMfVsIeAHAYPtSeQfH0++LraqSHWaWNqvsK9cNQiBm+vdefrDuvqtzxcxTiRLbp2GcT0qLI1hinV5nrMwNcqt81w4j5EdePrnNYQMtujyBDX8f15N4bLrY3AsvRDuCb6ttPG7pECUofT2jHqGd8i0Jttj6qyVLadGKfbq2GN8I2DPh4aLAOEDes8INtyINyfmmAGW0DYFDszVdIPc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rFPN1RxlxbtihjNA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: I2M24vtyT7ZPHBsvPjJDZLXYIpEHAeqqEHg+3g/OtH3r/c1ALxAsc8NN4vxW6dFewNtYwLe1UMN87Oab9Zhycy0gQjFO3Mk+MXzxoVS3W9Fu1tqtRvkDFBfr+xlyOgFTI1gvdrszWuwscqVQfXVYj4iXpNbWMOIu/LqTqjHIfbE3q6TdTAILlugboJ1HLC3Q2uchy4z35n8zeNGvJIoG40W2c0IHKyO4zBCK69Kj1L6pFlBWdf4LXypDAwB4mktX5Wu3bh9Zg11yGzrnb/0Wu6g/MD2k6InYPGFaEzBPsaFTQdVx6GrnoXaVi9kk6JvjpGrKLQi5gtgOEE3kVLAzQ9gmFZvsn4ylPwx7/1XLWhTT4TMFaTUxkFM4avioNzQE1D/0OUQwTICOCtu/zssCpvNXyTZpGhgrF3hY1Ti0ppZkzlTMr54kqnUBgMir50LSi6271QdUCkytJf8EE6rRflRfnYseCfkEu6AuRCTIfXI6GG46EsURpHBBgewRCPMn497VL1i2x3OsmmPEt6v2cOYmIkSze7B2Imjib4b2X+LKX93gPyvF9qEkVp72h4RdolL1HoN84lnAgd/fRAYGxw1wZP6cU4Y29pZ7OCEHheeY1iqjvNuj7QA6GJUlJUfFjoQcB9M2+4uc0/P9KVMK0TW01kCYGq1O+iPHGeS7K96lKMaMTSY/ugokzCdaRFQtqrEY0hOrrh+Tz1NSWKJqjL/rWunmFGJK4XMr+RPHg6A8m44l7axYvCfRpSJGA1PykxtVqbovluL58Wn+P1WnJzaiIQ0G/zxQ5JYGZshFRrln6n8QNPKBArOv+cvtEUKgGYYtFenJK+6w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phg1V8VmBVYk0Lhn4n1XMYJJSSg1IPCZtreOBi6OaM68tGbrNqWIWN1XZkYAP64ZgEJ+aVsiHXmQYFDQlpkrYNR4KyCNoE1iOqSBLgIntFCi/x8ZMPucbU8keg4+Y8McTOCFmBq0FaJ9Fl04gS9mBy0HGFyVptwbpKZLkq607svVrp8wZzHqsRaE02C4iCN9QRJlXvpXBaHQemAvU6gL2QOqm5cxmh+tzaBnw83seKMYKDBK31oCmGJkfiTw2ozue0KgqPCA1lwGp/Yvdm1Q0cmLFfUISKTZIvsvxM02Hza7vwDGmYBYook+5VRXJ2P3KvwPtdWRx/IYQiz6XdeOP43u/wAs/ej0/e5G3av+gkIF3zT3lVVO4yCpl8mWmT3wXniQQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 74668c1b-eef4-4298-4f79-08dcc3af2e19 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 20:07:14.2425 (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: Zf5ChWfGjlh/SjNTMNyV30Gmqs6r7b7uTnBTtN76DHaKJzwAG0gQmSCQCMu5ILdkvfOmOsIF3J+u2ad62Y77uxiNjSH6ph61Rv8xrY/Amik= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR10MB6187 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-23_16,2024-08-23_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408230148 X-Proofpoint-ORIG-GUID: _XzE_fJCueE1U9GG637N4dIcIRxX6VG8 X-Proofpoint-GUID: _XzE_fJCueE1U9GG637N4dIcIRxX6VG8 X-Stat-Signature: 5tqehspwu3zdqs4ee8q7whr7tjbphzdu X-Rspam-User: X-Rspamd-Queue-Id: 854A4C0018 X-Rspamd-Server: rspam02 X-HE-Tag: 1724443649-325927 X-HE-Meta: U2FsdGVkX1/nbXnQtW9LRFzkWqTBMacz6GiGoJXIkauNjyOs4Ic/LAGYvqxmKYRgm366eRObukLHOVgV1KlqNq1RgoMZ5e6savndSY6FQTRjvaCSV2tO0MGw6U7FdxHpJ+VYXgiiS0CWa1Cdv5Mv+PiWoySv6yN4r/jNRFf6dQ7gqmdt8/0Uqfw/wfds7dACB2FRNsaaU/snJVPn/h2/0FG8kti+9YY4OG9bIHUennoKtkdRK/bzF5v1iLkEWQxhSZ0EAoDCt5KNVvM1z2c7Smzu/c91sVLKloXsOEWWM7Ace0nlswAkUMdFME26NDlVBt8nTecabkW3GZz4BqAwfip8r41uzjeYN31RMMYkNQ2eFE4RHax4zXtIv6YMaq7bBkxE2RX0V9NbJe2ONkFhOV85isuOKn3vAwH+oTwQmodECZtQ79M0qg2CSfzWW+RdGlFVqaULmWflEUYKLFLPEl763+kRZtazygT/w6zr/TvZspG2X7Rnlr7WwWeyEbwjoRNZSVGbcBEKdQ9Pp5A1bRn/IJWaLq33IJ0EF0iuM5TmjHico1uWkVnMV3njTtZrPdt3bcJbKjcXerssSJO12GLQB2L+DMk6pAm34stcAjPRA4PVE2Zt74cPYLxpCCCVMKOq3O2d2clXo3/Wkx1glE9IoJ5MlVIcFGPusOobSgxQ+EIH6KkPL3kVKFsOi9IXhjAo4j1AKQnUUHG0VFYQ+SvyS5NjmgW08chnx+WpvGicgmsDZHpnq548frOyLPsggFQFxxLhePd5jTWO+cWpBi13LR1zKQWGBdpwAaQk4r9uTyStNgWDZSN6SH+MLIbMfLU25ar0EEtM6HIJrwq6dcKz9Tx6o4RWj1uw7DgPnk9xsOkKKYnNsK1842PTpq2sqAY0/RsXq8msbhUuCzOHYG9lJ4mbNWtaKVmj3nHGk9CHL77B9PqxUNTV/NzaTEPKij3qUakmr+Wr2D/tdg5 GUYLzwta IxiHWCEtQjdqF2yNnoiZOeZEHV6Xu6jN0giAhkl7W6X3itLXgvM6/4tPGBH+G+CUkynLpX2Uc/yMnmyl1qhASWqJzrWte+TYa9W0NRRFeXKXts8Fv9Mbc8HkV7c1AEVbw1CG0tkijsRNvRyA8dtitjIORVQbWwgP5ahlYsTLxYRr1pOrLrlmB5ODxllUF+phKl5cYzX+N4sHSdlkBWqz52O5j51Of3c9Gk56IWH986bFQAkCrjJtL9OZ//aGqGv2uHtrZ3i9xF3NTlSPsl3Ai0ElSucP83lWnBMD1pZAenMbB75AgjhWzfnxLJ/IEsGmS4d1Llj8Dc2/2KokURh5K24LrcbJkoL5dUFpHAfZ82eMfXFOwgsPTs45yovjLNkYBBeBg09bzSHjS5wagUMVijvfYtAAuut2KMnT7boEwyhcbqTr7QdN5VcGv05LItNxbSEo72SJHtZfV2zD1hveMZcwzV6cafjF937E4 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add a variety of VMA merge unit tests to assert that the behaviour of VMA merge is correct at an abstract level and VMAs are merged or not merged as expected. These are intentionally added _before_ we start refactoring vma_merge() in order that we can continually assert correctness throughout the rest of the series. In order to reduce churn going forward, we backport the vma_merge_struct data type to the test code which we introduce and use in a future commit, and add wrappers around the merge new and existing VMA cases. Signed-off-by: Lorenzo Stoakes Reviewed-by: Liam R. Howlett --- tools/testing/vma/vma.c | 1218 +++++++++++++++++++++++++++++- tools/testing/vma/vma_internal.h | 45 +- 2 files changed, 1253 insertions(+), 10 deletions(-) diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index 48e033c60d87..9b272633ca9e 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -7,13 +7,43 @@ #include "maple-shared.h" #include "vma_internal.h" +/* Include so header guard set. */ +#include "../../../mm/vma.h" + +static bool fail_prealloc; + +/* Then override vma_iter_prealloc() so we can choose to fail it. */ +#define vma_iter_prealloc(vmi, vma) \ + (fail_prealloc ? -ENOMEM : mas_preallocate(&(vmi)->mas, (vma), GFP_KERNEL)) + /* * Directly import the VMA implementation here. Our vma_internal.h wrapper * provides userland-equivalent functionality for everything vma.c uses. */ #include "../../../mm/vma.c" +/* + * Temporarily forward-ported from a future in which vmg's are used for merging. + */ +struct vma_merge_struct { + struct mm_struct *mm; + struct vma_iterator *vmi; + pgoff_t pgoff; + struct vm_area_struct *prev; + struct vm_area_struct *next; /* Modified by vma_merge(). */ + struct vm_area_struct *vma; /* Either a new VMA or the one being modified. */ + unsigned long start; + unsigned long end; + unsigned long flags; + struct file *file; + struct anon_vma *anon_vma; + struct mempolicy *policy; + struct vm_userfaultfd_ctx uffd_ctx; + struct anon_vma_name *anon_name; +}; + const struct vm_operations_struct vma_dummy_vm_ops; +static struct anon_vma dummy_anon_vma; #define ASSERT_TRUE(_expr) \ do { \ @@ -28,6 +58,14 @@ const struct vm_operations_struct vma_dummy_vm_ops; #define ASSERT_EQ(_val1, _val2) ASSERT_TRUE((_val1) == (_val2)) #define ASSERT_NE(_val1, _val2) ASSERT_TRUE((_val1) != (_val2)) +static struct task_struct __current; + +struct task_struct *get_current(void) +{ + return &__current; +} + +/* Helper function to simply allocate a VMA. */ static struct vm_area_struct *alloc_vma(struct mm_struct *mm, unsigned long start, unsigned long end, @@ -47,22 +85,201 @@ static struct vm_area_struct *alloc_vma(struct mm_struct *mm, return ret; } +/* Helper function to allocate a VMA and link it to the tree. */ +static struct vm_area_struct *alloc_and_link_vma(struct mm_struct *mm, + unsigned long start, + unsigned long end, + pgoff_t pgoff, + vm_flags_t flags) +{ + struct vm_area_struct *vma = alloc_vma(mm, start, end, pgoff, flags); + + if (vma == NULL) + return NULL; + + if (vma_link(mm, vma)) { + vm_area_free(vma); + return NULL; + } + + /* + * Reset this counter which we use to track whether writes have + * begun. Linking to the tree will have caused this to be incremented, + * which means we will get a false positive otherwise. + */ + vma->vm_lock_seq = -1; + + return vma; +} + +/* Helper function which provides a wrapper around a merge new VMA operation. */ +static struct vm_area_struct *merge_new(struct vma_merge_struct *vmg) +{ + /* vma_merge() needs a VMA to determine mm, anon_vma, and file. */ + struct vm_area_struct dummy = { + .vm_mm = vmg->mm, + .vm_flags = vmg->flags, + .anon_vma = vmg->anon_vma, + .vm_file = vmg->file, + }; + + /* + * For convenience, get prev and next VMAs. Which the new VMA operation + * requires. + */ + vmg->next = vma_next(vmg->vmi); + vmg->prev = vma_prev(vmg->vmi); + + vma_iter_set(vmg->vmi, vmg->start); + return vma_merge_new_vma(vmg->vmi, vmg->prev, &dummy, vmg->start, + vmg->end, vmg->pgoff); +} + +/* + * Helper function which provides a wrapper around a merge existing VMA + * operation. + */ +static struct vm_area_struct *merge_existing(struct vma_merge_struct *vmg) +{ + /* vma_merge() needs a VMA to determine mm, anon_vma, and file. */ + struct vm_area_struct dummy = { + .vm_mm = vmg->mm, + .vm_flags = vmg->flags, + .anon_vma = vmg->anon_vma, + .vm_file = vmg->file, + }; + + return vma_merge(vmg->vmi, vmg->prev, &dummy, vmg->start, vmg->end, + vmg->flags, vmg->pgoff, vmg->policy, vmg->uffd_ctx, + vmg->anon_name); +} + +/* + * Helper function which provides a wrapper around the expansion of an existing + * VMA. + */ +static int expand_existing(struct vma_merge_struct *vmg) +{ + return vma_expand(vmg->vmi, vmg->vma, vmg->start, vmg->end, vmg->pgoff, + vmg->next); +} + +/* + * Helper function to reset merge state the associated VMA iterator to a + * specified new range. + */ +static void vmg_set_range(struct vma_merge_struct *vmg, unsigned long start, + unsigned long end, pgoff_t pgoff, vm_flags_t flags) +{ + vma_iter_set(vmg->vmi, start); + + vmg->prev = NULL; + vmg->next = NULL; + vmg->vma = NULL; + + vmg->start = start; + vmg->end = end; + vmg->pgoff = pgoff; + vmg->flags = flags; +} + +/* + * Helper function to try to merge a new VMA. + * + * Update vmg and the iterator for it and try to merge, otherwise allocate a new + * VMA, link it to the maple tree and return it. + */ +static struct vm_area_struct *try_merge_new_vma(struct mm_struct *mm, + struct vma_merge_struct *vmg, + unsigned long start, unsigned long end, + pgoff_t pgoff, vm_flags_t flags, + bool *was_merged) +{ + struct vm_area_struct *merged; + + vmg_set_range(vmg, start, end, pgoff, flags); + + merged = merge_new(vmg); + if (merged) { + *was_merged = true; + return merged; + } + + *was_merged = false; + return alloc_and_link_vma(mm, start, end, pgoff, flags); +} + +/* + * Helper function to reset the dummy anon_vma to indicate it has not been + * duplicated. + */ +static void reset_dummy_anon_vma(void) +{ + dummy_anon_vma.was_cloned = false; + dummy_anon_vma.was_unlinked = false; +} + +/* + * Helper function to remove all VMAs and destroy the maple tree associated with + * a virtual address space. Returns a count of VMAs in the tree. + */ +static int cleanup_mm(struct mm_struct *mm, struct vma_iterator *vmi) +{ + struct vm_area_struct *vma; + int count = 0; + + fail_prealloc = false; + reset_dummy_anon_vma(); + + vma_iter_set(vmi, 0); + for_each_vma(*vmi, vma) { + vm_area_free(vma); + count++; + } + + mtree_destroy(&mm->mm_mt); + mm->map_count = 0; + return count; +} + +/* Helper function to determine if VMA has had vma_start_write() performed. */ +static bool vma_write_started(struct vm_area_struct *vma) +{ + int seq = vma->vm_lock_seq; + + /* We reset after each check. */ + vma->vm_lock_seq = -1; + + /* The vma_start_write() stub simply increments this value. */ + return seq > -1; +} + +/* Helper function providing a dummy vm_ops->close() method.*/ +static void dummy_close(struct vm_area_struct *) +{ +} + static bool test_simple_merge(void) { struct vm_area_struct *vma; unsigned long flags = VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE; struct mm_struct mm = {}; struct vm_area_struct *vma_left = alloc_vma(&mm, 0, 0x1000, 0, flags); - struct vm_area_struct *vma_middle = alloc_vma(&mm, 0x1000, 0x2000, 1, flags); struct vm_area_struct *vma_right = alloc_vma(&mm, 0x2000, 0x3000, 2, flags); VMA_ITERATOR(vmi, &mm, 0x1000); + struct vma_merge_struct vmg = { + .mm = &mm, + .vmi = &vmi, + .start = 0x1000, + .end = 0x2000, + .flags = flags, + .pgoff = 1, + }; ASSERT_FALSE(vma_link(&mm, vma_left)); - ASSERT_FALSE(vma_link(&mm, vma_middle)); ASSERT_FALSE(vma_link(&mm, vma_right)); - vma = vma_merge_new_vma(&vmi, vma_left, vma_middle, 0x1000, - 0x2000, 1); + vma = merge_new(&vmg); ASSERT_NE(vma, NULL); ASSERT_EQ(vma->vm_start, 0); @@ -142,10 +359,17 @@ static bool test_simple_expand(void) struct mm_struct mm = {}; struct vm_area_struct *vma = alloc_vma(&mm, 0, 0x1000, 0, flags); VMA_ITERATOR(vmi, &mm, 0); + struct vma_merge_struct vmg = { + .vmi = &vmi, + .vma = vma, + .start = 0, + .end = 0x3000, + .pgoff = 0, + }; ASSERT_FALSE(vma_link(&mm, vma)); - ASSERT_FALSE(vma_expand(&vmi, vma, 0, 0x3000, 0, NULL)); + ASSERT_FALSE(expand_existing(&vmg)); ASSERT_EQ(vma->vm_start, 0); ASSERT_EQ(vma->vm_end, 0x3000); @@ -178,6 +402,980 @@ static bool test_simple_shrink(void) return true; } +static bool test_merge_new(void) +{ + unsigned long flags = VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE; + struct mm_struct mm = {}; + VMA_ITERATOR(vmi, &mm, 0); + struct vma_merge_struct vmg = { + .mm = &mm, + .vmi = &vmi, + }; + struct anon_vma_chain dummy_anon_vma_chain_a = { + .anon_vma = &dummy_anon_vma, + }; + struct anon_vma_chain dummy_anon_vma_chain_b = { + .anon_vma = &dummy_anon_vma, + }; + struct anon_vma_chain dummy_anon_vma_chain_c = { + .anon_vma = &dummy_anon_vma, + }; + struct anon_vma_chain dummy_anon_vma_chain_d = { + .anon_vma = &dummy_anon_vma, + }; + int count; + struct vm_area_struct *vma, *vma_a, *vma_b, *vma_c, *vma_d; + bool merged; + + /* + * 0123456789abc + * AA B CC + */ + vma_a = alloc_and_link_vma(&mm, 0, 0x2000, 0, flags); + ASSERT_NE(vma_a, NULL); + /* We give each VMA a single avc so we can test anon_vma duplication. */ + INIT_LIST_HEAD(&vma_a->anon_vma_chain); + list_add(&dummy_anon_vma_chain_a.same_vma, &vma_a->anon_vma_chain); + + vma_b = alloc_and_link_vma(&mm, 0x3000, 0x4000, 3, flags); + ASSERT_NE(vma_b, NULL); + INIT_LIST_HEAD(&vma_b->anon_vma_chain); + list_add(&dummy_anon_vma_chain_b.same_vma, &vma_b->anon_vma_chain); + + vma_c = alloc_and_link_vma(&mm, 0xb000, 0xc000, 0xb, flags); + ASSERT_NE(vma_c, NULL); + INIT_LIST_HEAD(&vma_c->anon_vma_chain); + list_add(&dummy_anon_vma_chain_c.same_vma, &vma_c->anon_vma_chain); + + /* + * NO merge. + * + * 0123456789abc + * AA B ** CC + */ + vma_d = try_merge_new_vma(&mm, &vmg, 0x7000, 0x9000, 7, flags, &merged); + ASSERT_NE(vma_d, NULL); + INIT_LIST_HEAD(&vma_d->anon_vma_chain); + list_add(&dummy_anon_vma_chain_d.same_vma, &vma_d->anon_vma_chain); + ASSERT_FALSE(merged); + ASSERT_EQ(mm.map_count, 4); + + /* + * Merge BOTH sides. + * + * 0123456789abc + * AA*B DD CC + */ + vma_b->anon_vma = &dummy_anon_vma; + vma = try_merge_new_vma(&mm, &vmg, 0x2000, 0x3000, 2, flags, &merged); + ASSERT_EQ(vma, vma_a); + /* Merge with A, delete B. */ + ASSERT_TRUE(merged); + ASSERT_EQ(vma->vm_start, 0); + ASSERT_EQ(vma->vm_end, 0x4000); + ASSERT_EQ(vma->vm_pgoff, 0); + ASSERT_EQ(vma->anon_vma, &dummy_anon_vma); + ASSERT_TRUE(vma_write_started(vma)); + ASSERT_EQ(mm.map_count, 3); + + /* + * Merge to PREVIOUS VMA. + * + * 0123456789abc + * AAAA* DD CC + */ + vma = try_merge_new_vma(&mm, &vmg, 0x4000, 0x5000, 4, flags, &merged); + ASSERT_EQ(vma, vma_a); + /* Extend A. */ + ASSERT_TRUE(merged); + ASSERT_EQ(vma->vm_start, 0); + ASSERT_EQ(vma->vm_end, 0x5000); + ASSERT_EQ(vma->vm_pgoff, 0); + ASSERT_EQ(vma->anon_vma, &dummy_anon_vma); + ASSERT_TRUE(vma_write_started(vma)); + ASSERT_EQ(mm.map_count, 3); + + /* + * Merge to NEXT VMA. + * + * 0123456789abc + * AAAAA *DD CC + */ + vma_d->anon_vma = &dummy_anon_vma; + vma = try_merge_new_vma(&mm, &vmg, 0x6000, 0x7000, 6, flags, &merged); + ASSERT_EQ(vma, vma_d); + /* Prepend. */ + ASSERT_TRUE(merged); + ASSERT_EQ(vma->vm_start, 0x6000); + ASSERT_EQ(vma->vm_end, 0x9000); + ASSERT_EQ(vma->vm_pgoff, 6); + ASSERT_EQ(vma->anon_vma, &dummy_anon_vma); + ASSERT_TRUE(vma_write_started(vma)); + ASSERT_EQ(mm.map_count, 3); + + /* + * Merge BOTH sides. + * + * 0123456789abc + * AAAAA*DDD CC + */ + vma = try_merge_new_vma(&mm, &vmg, 0x5000, 0x6000, 5, flags, &merged); + ASSERT_EQ(vma, vma_a); + /* Merge with A, delete D. */ + ASSERT_TRUE(merged); + ASSERT_EQ(vma->vm_start, 0); + ASSERT_EQ(vma->vm_end, 0x9000); + ASSERT_EQ(vma->vm_pgoff, 0); + ASSERT_EQ(vma->anon_vma, &dummy_anon_vma); + ASSERT_TRUE(vma_write_started(vma)); + ASSERT_EQ(mm.map_count, 2); + + /* + * Merge to NEXT VMA. + * + * 0123456789abc + * AAAAAAAAA *CC + */ + vma_c->anon_vma = &dummy_anon_vma; + vma = try_merge_new_vma(&mm, &vmg, 0xa000, 0xb000, 0xa, flags, &merged); + ASSERT_EQ(vma, vma_c); + /* Prepend C. */ + ASSERT_TRUE(merged); + ASSERT_EQ(vma->vm_start, 0xa000); + ASSERT_EQ(vma->vm_end, 0xc000); + ASSERT_EQ(vma->vm_pgoff, 0xa); + ASSERT_EQ(vma->anon_vma, &dummy_anon_vma); + ASSERT_TRUE(vma_write_started(vma)); + ASSERT_EQ(mm.map_count, 2); + + /* + * Merge BOTH sides. + * + * 0123456789abc + * AAAAAAAAA*CCC + */ + vma = try_merge_new_vma(&mm, &vmg, 0x9000, 0xa000, 0x9, flags, &merged); + ASSERT_EQ(vma, vma_a); + /* Extend A and delete C. */ + ASSERT_TRUE(merged); + ASSERT_EQ(vma->vm_start, 0); + ASSERT_EQ(vma->vm_end, 0xc000); + ASSERT_EQ(vma->vm_pgoff, 0); + ASSERT_EQ(vma->anon_vma, &dummy_anon_vma); + ASSERT_TRUE(vma_write_started(vma)); + ASSERT_EQ(mm.map_count, 1); + + /* + * Final state. + * + * 0123456789abc + * AAAAAAAAAAAAA + */ + + count = 0; + vma_iter_set(&vmi, 0); + for_each_vma(vmi, vma) { + ASSERT_NE(vma, NULL); + ASSERT_EQ(vma->vm_start, 0); + ASSERT_EQ(vma->vm_end, 0xc000); + ASSERT_EQ(vma->vm_pgoff, 0); + ASSERT_EQ(vma->anon_vma, &dummy_anon_vma); + + vm_area_free(vma); + count++; + } + + /* Should only have one VMA left (though freed) after all is done.*/ + ASSERT_EQ(count, 1); + + mtree_destroy(&mm.mm_mt); + return true; +} + +static bool test_vma_merge_special_flags(void) +{ + unsigned long flags = VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE; + struct mm_struct mm = {}; + VMA_ITERATOR(vmi, &mm, 0); + struct vma_merge_struct vmg = { + .mm = &mm, + .vmi = &vmi, + }; + vm_flags_t special_flags[] = { VM_IO, VM_DONTEXPAND, VM_PFNMAP, VM_MIXEDMAP }; + vm_flags_t all_special_flags = 0; + int i; + struct vm_area_struct *vma_left, *vma; + + /* Make sure there aren't new VM_SPECIAL flags. */ + for (i = 0; i < ARRAY_SIZE(special_flags); i++) { + all_special_flags |= special_flags[i]; + } + ASSERT_EQ(all_special_flags, VM_SPECIAL); + + /* + * 01234 + * AAA + */ + vma_left = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + ASSERT_NE(vma_left, NULL); + + /* 1. Set up new VMA with special flag that would otherwise merge. */ + + /* + * 01234 + * AAA* + * + * This should merge if not for the VM_SPECIAL flag. + */ + vmg_set_range(&vmg, 0x3000, 0x4000, 3, flags); + for (i = 0; i < ARRAY_SIZE(special_flags); i++) { + vm_flags_t special_flag = special_flags[i]; + + vma_left->__vm_flags = flags | special_flag; + vmg.flags = flags | special_flag; + vma = merge_new(&vmg); + ASSERT_EQ(vma, NULL); + } + + /* 2. Modify VMA with special flag that would otherwise merge. */ + + /* + * 01234 + * AAAB + * + * Create a VMA to modify. + */ + vma = alloc_and_link_vma(&mm, 0x3000, 0x4000, 3, flags); + ASSERT_NE(vma, NULL); + vmg.vma = vma; + + for (i = 0; i < ARRAY_SIZE(special_flags); i++) { + vm_flags_t special_flag = special_flags[i]; + + vma_left->__vm_flags = flags | special_flag; + vmg.flags = flags | special_flag; + vma = merge_existing(&vmg); + ASSERT_EQ(vma, NULL); + } + + cleanup_mm(&mm, &vmi); + return true; +} + +static bool test_vma_merge_with_close(void) +{ + unsigned long flags = VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE; + struct mm_struct mm = {}; + VMA_ITERATOR(vmi, &mm, 0); + struct vma_merge_struct vmg = { + .mm = &mm, + .vmi = &vmi, + }; + const struct vm_operations_struct vm_ops = { + .close = dummy_close, + }; + struct vm_area_struct *vma_next = + alloc_and_link_vma(&mm, 0x2000, 0x3000, 2, flags); + struct vm_area_struct *vma; + + /* + * When we merge VMAs we sometimes have to delete others as part of the + * operation. + * + * Considering the two possible adjacent VMAs to which a VMA can be + * merged: + * + * [ prev ][ vma ][ next ] + * + * In no case will we need to delete prev. If the operation is + * mergeable, then prev will be extended with one or both of vma and + * next deleted. + * + * As a result, during initial mergeability checks, only + * can_vma_merge_before() (which implies the VMA being merged with is + * 'next' as shown above) bothers to check to see whether the next VMA + * has a vm_ops->close() callback that will need to be called when + * removed. + * + * If it does, then we cannot merge as the resources that the close() + * operation potentially clears down are tied only to the existing VMA + * range and we have no way of extending those to the nearly merged one. + * + * We must consider two scenarios: + * + * A. + * + * vm_ops->close: - - !NULL + * [ prev ][ vma ][ next ] + * + * Where prev may or may not be present/mergeable. + * + * This is picked up by a specific check in can_vma_merge_before(). + * + * B. + * + * vm_ops->close: - !NULL + * [ prev ][ vma ] + * + * Where prev and vma are present and mergeable. + * + * This is picked up by a specific check in the modified VMA merge. + * + * IMPORTANT NOTE: We make the assumption that the following case: + * + * - !NULL NULL + * [ prev ][ vma ][ next ] + * + * Cannot occur, because vma->vm_ops being the same implies the same + * vma->vm_file, and therefore this would mean that next->vm_ops->close + * would be set too, and thus scenario A would pick this up. + */ + + ASSERT_NE(vma_next, NULL); + + /* + * SCENARIO A + * + * 0123 + * *N + */ + + /* Make the next VMA have a close() callback. */ + vma_next->vm_ops = &vm_ops; + + /* Our proposed VMA has characteristics that would otherwise be merged. */ + vmg_set_range(&vmg, 0x1000, 0x2000, 1, flags); + + /* The next VMA having a close() operator should cause the merge to fail.*/ + ASSERT_EQ(merge_new(&vmg), NULL); + + /* Now create the VMA so we can merge via modified flags */ + vmg_set_range(&vmg, 0x1000, 0x2000, 1, flags); + vma = alloc_and_link_vma(&mm, 0x1000, 0x2000, 1, flags); + vmg.vma = vma; + + /* + * The VMA being modified in a way that would otherwise merge should + * also fail. + */ + ASSERT_EQ(merge_existing(&vmg), NULL); + + /* SCENARIO B + * + * 0123 + * P* + * + * In order for this scenario to trigger, the VMA currently being + * modified must also have a .close(). + */ + + /* Reset VMG state. */ + vmg_set_range(&vmg, 0x1000, 0x2000, 1, flags); + /* + * Make next unmergeable, and don't let the scenario A check pick this + * up, we want to reproduce scenario B only. + */ + vma_next->vm_ops = NULL; + vma_next->__vm_flags &= ~VM_MAYWRITE; + /* Allocate prev. */ + vmg.prev = alloc_and_link_vma(&mm, 0, 0x1000, 0, flags); + /* Assign a vm_ops->close() function to VMA explicitly. */ + vma->vm_ops = &vm_ops; + vmg.vma = vma; + /* Make sure merge does not occur. */ + ASSERT_EQ(merge_existing(&vmg), NULL); + + cleanup_mm(&mm, &vmi); + return true; +} + +static bool test_vma_merge_new_with_close(void) +{ + unsigned long flags = VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE; + struct mm_struct mm = {}; + VMA_ITERATOR(vmi, &mm, 0); + struct vma_merge_struct vmg = { + .mm = &mm, + .vmi = &vmi, + }; + struct vm_area_struct *vma_prev = alloc_and_link_vma(&mm, 0, 0x2000, 0, flags); + struct vm_area_struct *vma_next = alloc_and_link_vma(&mm, 0x5000, 0x7000, 5, flags); + const struct vm_operations_struct vm_ops = { + .close = dummy_close, + }; + struct vm_area_struct *vma; + + /* + * We should allow the partial merge of a proposed new VMA if the + * surrounding VMAs have vm_ops->close() hooks (but are otherwise + * compatible), e.g.: + * + * New VMA + * A v-------v B + * |-----| |-----| + * close close + * + * Since the rule is to not DELETE a VMA with a close operation, this + * should be permitted, only rather than expanding A and deleting B, we + * should simply expand A and leave B intact, e.g.: + * + * New VMA + * A B + * |------------||-----| + * close close + */ + + /* Have prev and next have a vm_ops->close() hook. */ + vma_prev->vm_ops = &vm_ops; + vma_next->vm_ops = &vm_ops; + + vmg_set_range(&vmg, 0x2000, 0x5000, 2, flags); + vma = merge_new(&vmg); + ASSERT_NE(vma, NULL); + ASSERT_EQ(vma->vm_start, 0); + ASSERT_EQ(vma->vm_end, 0x5000); + ASSERT_EQ(vma->vm_pgoff, 0); + ASSERT_EQ(vma->vm_ops, &vm_ops); + ASSERT_TRUE(vma_write_started(vma)); + ASSERT_EQ(mm.map_count, 2); + + cleanup_mm(&mm, &vmi); + return true; +} + +static bool test_merge_existing(void) +{ + unsigned long flags = VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE; + struct mm_struct mm = {}; + VMA_ITERATOR(vmi, &mm, 0); + struct vm_area_struct *vma, *vma_prev, *vma_next; + struct vma_merge_struct vmg = { + .mm = &mm, + .vmi = &vmi, + }; + + /* + * Merge right case - partial span. + * + * <-> + * 0123456789 + * VVVVNNN + * -> + * 0123456789 + * VNNNNNN + */ + vma = alloc_and_link_vma(&mm, 0x2000, 0x6000, 2, flags); + vma_next = alloc_and_link_vma(&mm, 0x6000, 0x9000, 6, flags); + vmg_set_range(&vmg, 0x3000, 0x6000, 3, flags); + vmg.vma = vma; + vmg.prev = vma; + vma->anon_vma = &dummy_anon_vma; + ASSERT_EQ(merge_existing(&vmg), vma_next); + ASSERT_EQ(vma_next->vm_start, 0x3000); + ASSERT_EQ(vma_next->vm_end, 0x9000); + ASSERT_EQ(vma_next->vm_pgoff, 3); + ASSERT_EQ(vma_next->anon_vma, &dummy_anon_vma); + ASSERT_EQ(vma->vm_start, 0x2000); + ASSERT_EQ(vma->vm_end, 0x3000); + ASSERT_EQ(vma->vm_pgoff, 2); + ASSERT_TRUE(vma_write_started(vma)); + ASSERT_TRUE(vma_write_started(vma_next)); + ASSERT_EQ(mm.map_count, 2); + + /* Clear down and reset. */ + ASSERT_EQ(cleanup_mm(&mm, &vmi), 2); + + /* + * Merge right case - full span. + * + * <--> + * 0123456789 + * VVVVNNN + * -> + * 0123456789 + * NNNNNNN + */ + vma = alloc_and_link_vma(&mm, 0x2000, 0x6000, 2, flags); + vma_next = alloc_and_link_vma(&mm, 0x6000, 0x9000, 6, flags); + vmg_set_range(&vmg, 0x2000, 0x6000, 2, flags); + vmg.vma = vma; + vma->anon_vma = &dummy_anon_vma; + ASSERT_EQ(merge_existing(&vmg), vma_next); + ASSERT_EQ(vma_next->vm_start, 0x2000); + ASSERT_EQ(vma_next->vm_end, 0x9000); + ASSERT_EQ(vma_next->vm_pgoff, 2); + ASSERT_EQ(vma_next->anon_vma, &dummy_anon_vma); + ASSERT_TRUE(vma_write_started(vma_next)); + ASSERT_EQ(mm.map_count, 1); + + /* Clear down and reset. We should have deleted vma. */ + ASSERT_EQ(cleanup_mm(&mm, &vmi), 1); + + /* + * Merge left case - partial span. + * + * <-> + * 0123456789 + * PPPVVVV + * -> + * 0123456789 + * PPPPPPV + */ + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma = alloc_and_link_vma(&mm, 0x3000, 0x7000, 3, flags); + vmg_set_range(&vmg, 0x3000, 0x6000, 3, flags); + vmg.prev = vma_prev; + vmg.vma = vma; + vma->anon_vma = &dummy_anon_vma; + + ASSERT_EQ(merge_existing(&vmg), vma_prev); + ASSERT_EQ(vma_prev->vm_start, 0); + ASSERT_EQ(vma_prev->vm_end, 0x6000); + ASSERT_EQ(vma_prev->vm_pgoff, 0); + ASSERT_EQ(vma_prev->anon_vma, &dummy_anon_vma); + ASSERT_EQ(vma->vm_start, 0x6000); + ASSERT_EQ(vma->vm_end, 0x7000); + ASSERT_EQ(vma->vm_pgoff, 6); + ASSERT_TRUE(vma_write_started(vma_prev)); + ASSERT_TRUE(vma_write_started(vma)); + ASSERT_EQ(mm.map_count, 2); + + /* Clear down and reset. */ + ASSERT_EQ(cleanup_mm(&mm, &vmi), 2); + + /* + * Merge left case - full span. + * + * <--> + * 0123456789 + * PPPVVVV + * -> + * 0123456789 + * PPPPPPP + */ + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma = alloc_and_link_vma(&mm, 0x3000, 0x7000, 3, flags); + vmg_set_range(&vmg, 0x3000, 0x7000, 3, flags); + vmg.prev = vma_prev; + vmg.vma = vma; + vma->anon_vma = &dummy_anon_vma; + ASSERT_EQ(merge_existing(&vmg), vma_prev); + ASSERT_EQ(vma_prev->vm_start, 0); + ASSERT_EQ(vma_prev->vm_end, 0x7000); + ASSERT_EQ(vma_prev->vm_pgoff, 0); + ASSERT_EQ(vma_prev->anon_vma, &dummy_anon_vma); + ASSERT_TRUE(vma_write_started(vma_prev)); + ASSERT_EQ(mm.map_count, 1); + + /* Clear down and reset. We should have deleted vma. */ + ASSERT_EQ(cleanup_mm(&mm, &vmi), 1); + + /* + * Merge both case. + * + * <--> + * 0123456789 + * PPPVVVVNNN + * -> + * 0123456789 + * PPPPPPPPPP + */ + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma = alloc_and_link_vma(&mm, 0x3000, 0x7000, 3, flags); + vma_next = alloc_and_link_vma(&mm, 0x7000, 0x9000, 7, flags); + vmg_set_range(&vmg, 0x3000, 0x7000, 3, flags); + vmg.prev = vma_prev; + vmg.vma = vma; + vma->anon_vma = &dummy_anon_vma; + ASSERT_EQ(merge_existing(&vmg), vma_prev); + ASSERT_EQ(vma_prev->vm_start, 0); + ASSERT_EQ(vma_prev->vm_end, 0x9000); + ASSERT_EQ(vma_prev->vm_pgoff, 0); + ASSERT_EQ(vma_prev->anon_vma, &dummy_anon_vma); + ASSERT_TRUE(vma_write_started(vma_prev)); + ASSERT_EQ(mm.map_count, 1); + + /* Clear down and reset. We should have deleted prev and next. */ + ASSERT_EQ(cleanup_mm(&mm, &vmi), 1); + + /* + * Non-merge ranges. the modified VMA merge operation assumes that the + * caller always specifies ranges within the input VMA so we need only + * examine these cases. + * + * - + * - + * - + * <-> + * <> + * <> + * 0123456789a + * PPPVVVVVNNN + */ + + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma = alloc_and_link_vma(&mm, 0x3000, 0x8000, 3, flags); + vma_next = alloc_and_link_vma(&mm, 0x8000, 0xa000, 8, flags); + + vmg_set_range(&vmg, 0x4000, 0x5000, 4, flags); + vmg.prev = vma; + vmg.vma = vma; + ASSERT_EQ(merge_existing(&vmg), NULL); + + vmg_set_range(&vmg, 0x5000, 0x6000, 5, flags); + vmg.prev = vma; + vmg.vma = vma; + ASSERT_EQ(merge_existing(&vmg), NULL); + + vmg_set_range(&vmg, 0x6000, 0x7000, 6, flags); + vmg.prev = vma; + vmg.vma = vma; + ASSERT_EQ(merge_existing(&vmg), NULL); + + vmg_set_range(&vmg, 0x4000, 0x7000, 4, flags); + vmg.prev = vma; + vmg.vma = vma; + ASSERT_EQ(merge_existing(&vmg), NULL); + + vmg_set_range(&vmg, 0x4000, 0x6000, 4, flags); + vmg.prev = vma; + vmg.vma = vma; + ASSERT_EQ(merge_existing(&vmg), NULL); + + vmg_set_range(&vmg, 0x5000, 0x6000, 5, flags); + vmg.prev = vma; + vmg.vma = vma; + ASSERT_EQ(merge_existing(&vmg), NULL); + + ASSERT_EQ(cleanup_mm(&mm, &vmi), 3); + + return true; +} + +static bool test_anon_vma_non_mergeable(void) +{ + unsigned long flags = VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE; + struct mm_struct mm = {}; + VMA_ITERATOR(vmi, &mm, 0); + struct vm_area_struct *vma, *vma_prev, *vma_next; + struct vma_merge_struct vmg = { + .mm = &mm, + .vmi = &vmi, + }; + struct anon_vma_chain dummy_anon_vma_chain1 = { + .anon_vma = &dummy_anon_vma, + }; + struct anon_vma_chain dummy_anon_vma_chain2 = { + .anon_vma = &dummy_anon_vma, + }; + + /* + * In the case of modified VMA merge, merging both left and right VMAs + * but where prev and next have incompatible anon_vma objects, we revert + * to a merge of prev and VMA: + * + * <--> + * 0123456789 + * PPPVVVVNNN + * -> + * 0123456789 + * PPPPPPPNNN + */ + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma = alloc_and_link_vma(&mm, 0x3000, 0x7000, 3, flags); + vma_next = alloc_and_link_vma(&mm, 0x7000, 0x9000, 7, flags); + + /* + * Give both prev and next single anon_vma_chain fields, so they will + * merge with the NULL vmg->anon_vma. + * + * However, when prev is compared to next, the merge should fail. + */ + + INIT_LIST_HEAD(&vma_prev->anon_vma_chain); + list_add(&dummy_anon_vma_chain1.same_vma, &vma_prev->anon_vma_chain); + ASSERT_TRUE(list_is_singular(&vma_prev->anon_vma_chain)); + vma_prev->anon_vma = &dummy_anon_vma; + ASSERT_TRUE(is_mergeable_anon_vma(NULL, vma_prev->anon_vma, vma_prev)); + + INIT_LIST_HEAD(&vma_next->anon_vma_chain); + list_add(&dummy_anon_vma_chain2.same_vma, &vma_next->anon_vma_chain); + ASSERT_TRUE(list_is_singular(&vma_next->anon_vma_chain)); + vma_next->anon_vma = (struct anon_vma *)2; + ASSERT_TRUE(is_mergeable_anon_vma(NULL, vma_next->anon_vma, vma_next)); + + ASSERT_FALSE(is_mergeable_anon_vma(vma_prev->anon_vma, vma_next->anon_vma, NULL)); + + vmg_set_range(&vmg, 0x3000, 0x7000, 3, flags); + vmg.prev = vma_prev; + vmg.vma = vma; + + ASSERT_EQ(merge_existing(&vmg), vma_prev); + ASSERT_EQ(vma_prev->vm_start, 0); + ASSERT_EQ(vma_prev->vm_end, 0x7000); + ASSERT_EQ(vma_prev->vm_pgoff, 0); + ASSERT_TRUE(vma_write_started(vma_prev)); + ASSERT_FALSE(vma_write_started(vma_next)); + + /* Clear down and reset. */ + ASSERT_EQ(cleanup_mm(&mm, &vmi), 2); + + /* + * Now consider the new VMA case. This is equivalent, only adding a new + * VMA in a gap between prev and next. + * + * <--> + * 0123456789 + * PPP****NNN + * -> + * 0123456789 + * PPPPPPPNNN + */ + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma_next = alloc_and_link_vma(&mm, 0x7000, 0x9000, 7, flags); + + INIT_LIST_HEAD(&vma_prev->anon_vma_chain); + list_add(&dummy_anon_vma_chain1.same_vma, &vma_prev->anon_vma_chain); + vma_prev->anon_vma = (struct anon_vma *)1; + + INIT_LIST_HEAD(&vma_next->anon_vma_chain); + list_add(&dummy_anon_vma_chain2.same_vma, &vma_next->anon_vma_chain); + vma_next->anon_vma = (struct anon_vma *)2; + + vmg_set_range(&vmg, 0x3000, 0x7000, 3, flags); + vmg.prev = vma_prev; + + ASSERT_EQ(merge_new(&vmg), vma_prev); + ASSERT_EQ(vma_prev->vm_start, 0); + ASSERT_EQ(vma_prev->vm_end, 0x7000); + ASSERT_EQ(vma_prev->vm_pgoff, 0); + ASSERT_TRUE(vma_write_started(vma_prev)); + ASSERT_FALSE(vma_write_started(vma_next)); + + /* Final cleanup. */ + ASSERT_EQ(cleanup_mm(&mm, &vmi), 2); + + return true; +} + +static bool test_dup_anon_vma(void) +{ + unsigned long flags = VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE; + struct mm_struct mm = {}; + VMA_ITERATOR(vmi, &mm, 0); + struct vma_merge_struct vmg = { + .mm = &mm, + .vmi = &vmi, + }; + struct anon_vma_chain dummy_anon_vma_chain = { + .anon_vma = &dummy_anon_vma, + }; + struct vm_area_struct *vma_prev, *vma_next, *vma; + + reset_dummy_anon_vma(); + + /* + * Expanding a VMA delete the next one duplicates next's anon_vma and + * assigns it to the expanded VMA. + * + * This covers new VMA merging, as these operations amount to a VMA + * expand. + */ + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma_next = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, flags); + vma_next->anon_vma = &dummy_anon_vma; + + vmg_set_range(&vmg, 0, 0x5000, 0, flags); + vmg.vma = vma_prev; + vmg.next = vma_next; + + ASSERT_EQ(expand_existing(&vmg), 0); + + /* Will have been cloned. */ + ASSERT_EQ(vma_prev->anon_vma, &dummy_anon_vma); + ASSERT_TRUE(vma_prev->anon_vma->was_cloned); + + /* Cleanup ready for next run. */ + cleanup_mm(&mm, &vmi); + + /* + * next has anon_vma, we assign to prev. + * + * |<----->| + * |-------*********-------| + * prev vma next + * extend delete delete + */ + + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, flags); + vma_next = alloc_and_link_vma(&mm, 0x5000, 0x8000, 5, flags); + + /* Initialise avc so mergeability check passes. */ + INIT_LIST_HEAD(&vma_next->anon_vma_chain); + list_add(&dummy_anon_vma_chain.same_vma, &vma_next->anon_vma_chain); + + vma_next->anon_vma = &dummy_anon_vma; + vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); + vmg.prev = vma_prev; + vmg.vma = vma; + + ASSERT_EQ(merge_existing(&vmg), vma_prev); + + ASSERT_EQ(vma_prev->vm_start, 0); + ASSERT_EQ(vma_prev->vm_end, 0x8000); + + ASSERT_EQ(vma_prev->anon_vma, &dummy_anon_vma); + ASSERT_TRUE(vma_prev->anon_vma->was_cloned); + + cleanup_mm(&mm, &vmi); + + /* + * vma has anon_vma, we assign to prev. + * + * |<----->| + * |-------*********-------| + * prev vma next + * extend delete delete + */ + + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, flags); + vma_next = alloc_and_link_vma(&mm, 0x5000, 0x8000, 5, flags); + + vma->anon_vma = &dummy_anon_vma; + vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); + vmg.prev = vma_prev; + vmg.vma = vma; + + ASSERT_EQ(merge_existing(&vmg), vma_prev); + + ASSERT_EQ(vma_prev->vm_start, 0); + ASSERT_EQ(vma_prev->vm_end, 0x8000); + + ASSERT_EQ(vma_prev->anon_vma, &dummy_anon_vma); + ASSERT_TRUE(vma_prev->anon_vma->was_cloned); + + cleanup_mm(&mm, &vmi); + + /* + * vma has anon_vma, we assign to prev. + * + * |<----->| + * |-------************* + * prev vma + * extend shrink/delete + */ + + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma = alloc_and_link_vma(&mm, 0x3000, 0x8000, 3, flags); + + vma->anon_vma = &dummy_anon_vma; + vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); + vmg.prev = vma_prev; + vmg.vma = vma; + + ASSERT_EQ(merge_existing(&vmg), vma_prev); + + ASSERT_EQ(vma_prev->vm_start, 0); + ASSERT_EQ(vma_prev->vm_end, 0x5000); + + ASSERT_EQ(vma_prev->anon_vma, &dummy_anon_vma); + ASSERT_TRUE(vma_prev->anon_vma->was_cloned); + + cleanup_mm(&mm, &vmi); + + /* + * vma has anon_vma, we assign to next. + * + * |<----->| + * *************-------| + * vma next + * shrink/delete extend + */ + + vma = alloc_and_link_vma(&mm, 0, 0x5000, 0, flags); + vma_next = alloc_and_link_vma(&mm, 0x5000, 0x8000, 5, flags); + + vma->anon_vma = &dummy_anon_vma; + vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); + vmg.prev = vma; + vmg.vma = vma; + + ASSERT_EQ(merge_existing(&vmg), vma_next); + + ASSERT_EQ(vma_next->vm_start, 0x3000); + ASSERT_EQ(vma_next->vm_end, 0x8000); + + ASSERT_EQ(vma_next->anon_vma, &dummy_anon_vma); + ASSERT_TRUE(vma_next->anon_vma->was_cloned); + + cleanup_mm(&mm, &vmi); + return true; +} + +static bool test_vmi_prealloc_fail(void) +{ + unsigned long flags = VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE; + struct mm_struct mm = {}; + VMA_ITERATOR(vmi, &mm, 0); + struct vma_merge_struct vmg = { + .mm = &mm, + .vmi = &vmi, + }; + struct vm_area_struct *vma_prev, *vma; + + /* + * We are merging vma into prev, with vma possessing an anon_vma, which + * will be duplicated. We cause the vmi preallocation to fail and assert + * the duplicated anon_vma is unlinked. + */ + + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, flags); + vma->anon_vma = &dummy_anon_vma; + + vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); + vmg.prev = vma_prev; + vmg.vma = vma; + + fail_prealloc = true; + + /* This will cause the merge to fail. */ + ASSERT_EQ(merge_existing(&vmg), NULL); + /* We will already have assigned the anon_vma. */ + ASSERT_EQ(vma_prev->anon_vma, &dummy_anon_vma); + /* And it was both cloned and unlinked. */ + ASSERT_TRUE(dummy_anon_vma.was_cloned); + ASSERT_TRUE(dummy_anon_vma.was_unlinked); + + cleanup_mm(&mm, &vmi); /* Resets fail_prealloc too. */ + + /* + * We repeat the same operation for expanding a VMA, which is what new + * VMA merging ultimately uses too. This asserts that unlinking is + * performed in this case too. + */ + + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, flags); + vma->anon_vma = &dummy_anon_vma; + + vmg_set_range(&vmg, 0, 0x5000, 3, flags); + vmg.vma = vma_prev; + vmg.next = vma; + + fail_prealloc = true; + ASSERT_EQ(expand_existing(&vmg), -ENOMEM); + + ASSERT_EQ(vma_prev->anon_vma, &dummy_anon_vma); + ASSERT_TRUE(dummy_anon_vma.was_cloned); + ASSERT_TRUE(dummy_anon_vma.was_unlinked); + + cleanup_mm(&mm, &vmi); + return true; +} + int main(void) { int num_tests = 0, num_fail = 0; @@ -193,11 +1391,21 @@ int main(void) } \ } while (0) + /* Very simple tests to kick the tyres. */ TEST(simple_merge); TEST(simple_modify); TEST(simple_expand); TEST(simple_shrink); + TEST(merge_new); + TEST(vma_merge_special_flags); + TEST(vma_merge_with_close); + TEST(vma_merge_new_with_close); + TEST(merge_existing); + TEST(anon_vma_non_mergeable); + TEST(dup_anon_vma); + TEST(vmi_prealloc_fail); + #undef TEST printf("%d tests run, %d passed, %d failed.\n", diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_internal.h index 093560e5b2ac..a3c262c6eb73 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -81,8 +81,6 @@ #define AS_MM_ALL_LOCKS 2 -#define current NULL - /* We hardcode this for now. */ #define sysctl_max_map_count 0x1000000UL @@ -92,6 +90,12 @@ typedef struct pgprot { pgprotval_t pgprot; } pgprot_t; typedef unsigned long vm_flags_t; typedef __bitwise unsigned int vm_fault_t; +/* + * The shared stubs do not implement this, it amounts to an fprintf(STDERR,...) + * either way :) + */ +#define pr_warn_once pr_err + typedef struct refcount_struct { atomic_t refs; } refcount_t; @@ -100,9 +104,30 @@ struct kref { refcount_t refcount; }; +/* + * Define the task command name length as enum, then it can be visible to + * BPF programs. + */ +enum { + TASK_COMM_LEN = 16, +}; + +struct task_struct { + char comm[TASK_COMM_LEN]; + pid_t pid; + struct mm_struct *mm; +}; + +struct task_struct *get_current(void); +#define current get_current() + struct anon_vma { struct anon_vma *root; struct rb_root_cached rb_root; + + /* Test fields. */ + bool was_cloned; + bool was_unlinked; }; struct anon_vma_chain { @@ -682,13 +707,21 @@ static inline int vma_dup_policy(struct vm_area_struct *, struct vm_area_struct return 0; } -static inline int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *) +static inline int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src) { + /* For testing purposes. We indicate that an anon_vma has been cloned. */ + if (src->anon_vma != NULL) { + dst->anon_vma = src->anon_vma; + dst->anon_vma->was_cloned = true; + } + return 0; } -static inline void vma_start_write(struct vm_area_struct *) +static inline void vma_start_write(struct vm_area_struct *vma) { + /* Used to indicate to tests that a write operation has begun. */ + vma->vm_lock_seq++; } static inline void vma_adjust_trans_huge(struct vm_area_struct *vma, @@ -759,8 +792,10 @@ static inline void vma_assert_write_locked(struct vm_area_struct *) { } -static inline void unlink_anon_vmas(struct vm_area_struct *) +static inline void unlink_anon_vmas(struct vm_area_struct *vma) { + /* For testing purposes, indicate that the anon_vma was unlinked. */ + vma->anon_vma->was_unlinked = true; } static inline void anon_vma_unlock_write(struct anon_vma *) From patchwork Fri Aug 23 20:06:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13775910 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72677C5321E for ; Fri, 23 Aug 2024 20:07:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 51DAD800C3; Fri, 23 Aug 2024 16:07:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4CAB8800C4; Fri, 23 Aug 2024 16:07:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 25613800C3; Fri, 23 Aug 2024 16:07:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 02E44800C1 for ; Fri, 23 Aug 2024 16:07:32 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9D8721A0C2B for ; Fri, 23 Aug 2024 20:07:32 +0000 (UTC) X-FDA: 82484595144.15.388605D Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf18.hostedemail.com (Postfix) with ESMTP id 42DCC1C000F for ; Fri, 23 Aug 2024 20:07:29 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=jrnGDUv7; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=PoNUPfaj; spf=pass (imf18.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724443539; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=G07yRBnF8m4u5HMCec6mYo3CU3xKGFgZoQ+zxPgkK9Y=; b=bhJTS9d9rOWus3eLVgAv7O3149NgHiFK32q1ulQ8DAbc7IeyUygjwiFELJ+nw9NzoRT/Dk /oA3HWW5oq7a+KWjdSgEryT5ZS/qf5j1V6KmvZEKhpykAW77B/yMDaTZQQlpDgpV//1S+Q Os7bP+rfBkkn1J3nSiRRRKP+XC9sWPM= ARC-Authentication-Results: i=2; imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=jrnGDUv7; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=PoNUPfaj; spf=pass (imf18.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724443539; a=rsa-sha256; cv=pass; b=dLzDhI+TXSa5bNnPKosaeVi5fyJG8WVEAtTVmdIeTj0q7b/4jWegMiNohz9bNEfpi0x82g PIaEhMb+i8NQ1qc6eP6Nkb3tFa3+8IM6Un8bIvDonTfyoEo8F+si12FumPxLW3T1tDQRak DE3uYoxOgQhqoYeusLNZeMN/pSE9nPE= Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47NH0ZT3002378; Fri, 23 Aug 2024 20:07:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=G07yRBnF8m4u5HMCec6mYo3CU3xKGFgZoQ+zxPgkK9Y=; b= jrnGDUv7lvxCO/3oERWGgJjWdpJs7pSVOaJ2CsxTgB3FsrLAMnITPa6vDK1d6v23 dffvowAhvw8+y/yxpupEcNsM/Ro2+lKXXUjCYtDytCihOtNAW9AQunKZvKpPqmSp +VvAtrbj3NgbMYWLNdSl9hVODPrrbHvdF8LFYWJJ8INBdLxpWapW3ALBfK1z4Civ bECvn1Nfewf7ZPNN2kPnR0mLdODvtTUBRA9AlVQamAg9PHtbDlFH9qurNsLgx2su omw+/xKkVoUkBIzN81yWFWfjUodx5r0njuQc54Z396l1dCVhbQz4U7E3gBWn/yCk 3xUM8xSa6h/XLnGDljhK6Q== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412m67n1fc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:27 +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 47NJdFFe007123; Fri, 23 Aug 2024 20:07:26 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2177.outbound.protection.outlook.com [104.47.58.177]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4170s610wk-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Q0Zkq+3UN/PeavXRWJAkdy7ihJvhR7/KB+C7ER0NSPpelVC1iHLRbcr3VI27Iq4yJ6D7waJuOFeeNnq/aAupmyyrP7fNIFjn7P0JWrThg2RVSkk+jH2pgPL/o+3yvNieUeTnHj1HoNQs1MWVRAwPuv02wVIMVQZ+x7F64lJ6okwjEG87fDZ4rz0riihDJeDoup3QeUeh1NhgCXFPFJ0DKy7Q08IrosEDBSU5GMNfzcF2LKqcUQ1Q70IRZTIpAo4tD8yXo93k96/mzMo68WwwZKOM/ALMkd/ucBqB16/eU3yoemb6iSWMG9rxbpLunY2bRE5tPs5RdhaALVdbufG0tg== 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=G07yRBnF8m4u5HMCec6mYo3CU3xKGFgZoQ+zxPgkK9Y=; b=iQjkSBnSVaM41JWEPiVqXuCEuiET3Qe7/hFIVcpfIYxR/oLBYVrgVMmsKZhFFrMnr4o2YQQRljo9g51C8S8BsRaMP6lCeL/8EpdQnXTtyyYZlr1B+2y71iMagHrqkEEgVsq7eP/8ckmytbncDVxmUdJg+CUTQLe/FN9he++bDWxE4JOSRV+0fzMeYeJASNeG18WdeRDIpI3pbLa3uHGLiJJloV8E0XwHSrJkMcTTxlqgkDgROxrbRdsDCn1L8MigRexW+43unlMVZaJ1WOY3ZsHxSI6ppp+IYZpdFT7S7aaAZ2K9Uk7Qy7aYRo9MirdOQvz7TA7nfBxC/tMIFPdxMQ== 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=G07yRBnF8m4u5HMCec6mYo3CU3xKGFgZoQ+zxPgkK9Y=; b=PoNUPfajOpunC5UC36nhNqmfxZ9JILemOq0gnL9JDW2euVN5e8sPyXScSLZ03utaD5chLK8p3YH8DpL5YIjv2XuT5eqAWeD/IUd21WoQmIWPvid2rZ2ELHWFxJfl87CcRBQhlOe+As5YXPr1P+aDYqoZ7JCQnuitoTy7DmPs9ak= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by BL3PR10MB6187.namprd10.prod.outlook.com (2603:10b6:208:3be::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.17; Fri, 23 Aug 2024 20:07:17 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%6]) with mapi id 15.20.7897.014; Fri, 23 Aug 2024 20:07:17 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH v2 03/10] mm: introduce vma_merge_struct and abstract vma_merge(),vma_modify() Date: Fri, 23 Aug 2024 21:06:58 +0100 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0035.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:151::22) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|BL3PR10MB6187:EE_ X-MS-Office365-Filtering-Correlation-Id: 590ed16f-5b68-45ec-ef13-08dcc3af2fc7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: 1sT1/jYKE92IQBvea+QopDA8R+s9TWN26exX0wtd/fTqUxH21OAfX6ms8kS3U/K2xgCuqQk0JB+M1gvRh3lHSLURvUgrUry7d0WxbrhpQrMuneb8OunTx+ZG8S5EiPdKhmINrGNW+NwJxKj3E4irCttLb+0WjALbN/NQ6QNMpbquPDA23lqoru3to8a32YiCq4v8Z4C6R7az24Lmee9CyNyV4iK+je1zLEh7u9wGEDHozRHOfqZpAKFat0bVD8QczYRItTSlIWzRwvoeK9xiuCkXxjs/F8zn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k9HQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2B4fnb6HaRBoytIJ4aKxOboAphO6UAGsoIi9j1H02WQ8y1jLaL/vB8lXiUPkqs+FGq1EwDLJaJY9WLIRyE22HsjdNWVswdyIrVZvUWqkPNhayor2JFfdB9bn0QzJB/UuP72tM8t1mnxXGn4SDiHx0pfW1s9nB8NHn6w36PBnpJc+0IjvXEFOsxQdDXC117DG7grA3keQtFvoOAV6cnBRsC2CyDwpZIknbreJwJCfYrX6BDvZPHXvsPnkAGENRumIvXLoT5N/Gfxykj473ymqQrlhO/z+fx9AW9A40OCBV7VXpJNWGfnIw9StzhhfFPfWJu6H7gEmx6atknpMWSzkK+Pgql5Q8UiabhfOdAea+v9bVoCRRZ5Bpu3wIhKgSWgQvcoVUDwiAEtJf9GKGk9ywesikeZDgEcVgLn1zYyIPEn32/bFU0maVmySbkFM+9ZqDhrVhtPKr9NQyauqdN/XaEOqLeN69uV5kjTVsWReJ9x3YcI7v6sTVMY3N1UycMw5NcUxUGbYl44DUFIf8n7/4INV5zAPK83p5xDysoewSF54xSjbt0BfMKCJBpLIMTIKazlRjMFIKeNgafIFPWq305t6YDg1pIIG3bHbZH8t5CCvo3u5n7/6Tzd80gIPscKoJsLjnhAW8MPSGPmhtPeOTtsESghZxoyMLSdEma/bese8cZHOWKduCGQDHSnb2X5DWr511Y2TIlHXdyDpoP6ZzVOhV2pMxw6DH9ExBazjtncskJ7/oviZ3K3/wo6xPUp2J7aTkRfd4sd3bEs6metHbr728PibiSRrMqNxVEUvu/jakNVfdMyLhgrsqYTI961dycdTWLDFnIdCj7Erqx7yM092VkMWgfD6RO7xCy8e4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gjY6PR6YJMa+MoKdm/bia3rgIINurPSr1jSpl1qPloaYfR2fMr/DFXtMDdi3+pDCkv9X1QkdnoxUZWqe6ClqDv0ATC5LNKld3Nd7SjEKjsqLjHyBElxUp5cRYtcrWGOX56RerqI/I9tQYh7wnrlDFgjtYW9mXLlcbxLXI+RdwXGoFfUgaBf83vJSD/fcfl5S3rPmYHEgQ3CMu1bJc42lrBoMZDVbtP7IB+kh6qkzqU4yCyVzpzTlPzyJocC8NkdYzv2V5hSLKtNdw3KIzQqo85LSICquU9V42cNdt8W5jfaaGOo3BFI5gSoaCJ78CGvsw3Wkg6wJUllMSMe5GUeDX4t1gEgDs2/4ZD1Cg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 590ed16f-5b68-45ec-ef13-08dcc3af2fc7 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 20:07:17.0608 (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: q7fAPnbjyVCuQ2g/qKOK5OKNPw8mNflzDGwvQGQ0ii5LBCjNCR8jEDzUJdbpNR1fkT1ESJALkUmSpJNw+HVNkgGgH0GSSqoMMexPIyMbtbA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR10MB6187 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-23_16,2024-08-23_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408230148 X-Proofpoint-ORIG-GUID: DTvZHalHgEm-LcBIPmqYOwpR_F6ytObf X-Proofpoint-GUID: DTvZHalHgEm-LcBIPmqYOwpR_F6ytObf X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 42DCC1C000F X-Stat-Signature: i1zdc1dokqpjp36xb5t4ngsx7xg6psfz X-Rspam-User: X-HE-Tag: 1724443649-309789 X-HE-Meta: U2FsdGVkX1+N88vkNFtcPdt3Uc+3mjcihIiyowndfF+r10EFJMs+9oxqKu7ZRd/An4YO5SShgbZporRId85XgsSLW7THpZco1DfpbKcHCCjfmv83G9HafpgItjv5AeLyH67YJNbH9X9Z/LasaMFyv6Te2FAr5TpercMIYz17F10/Yq4Jz0fh7Y3XBnfoNXv6dA+lf2GFv2rAq645f6i48502lHBtA9V0gvX4h7cHvPnPwFDl3TRIZcxnKvW6GQJ41ngdHPGPguITuBRw6tHVain13cQmJuqtv93wYjxQdpyiiM9r0Xpl5Xp55lAdlZEv4RcSIexLT9u08MPWtmTwZj0241VoCD0YKIDdafjNxziK7gi+M7PpNxsBllwvDK26aH3rTNKT3CEyhdnTgyhvRVZ02SSmfoNc03WBqwM/g97Zlkrcm3me22PQpZ3CZ65tQKREFGjLigKC2Fg1x5qMDtJUjQ62EM5tUpl0qSruDHC5ti7NK9LEmeMnjJ3Q4/nm1/h8T/3BhbPHRK6u0fKO5XC+rHXeGL7BRRouNrKuLpLoWmz91gcFOeg452IEPsM9RSOd6wxFjXCak3a3Rpwcm1f1l3JKWugOCa1c3cHaD90EgHkFZJAAN6y47TvfFKwbWb41xFvp3vArlQLP/8OLo15vGE+RvwctC7Dad7S7E9ku0j/7n6CCcMUUNNcX1qxGcSOslPBod3KW7BYgtQX2mhqKUslMfBWyl8l1gh3HJktOHPhnCHPxvsxPOQ7V2LmjfKHRK5gVpM7EN86RivqWj1EP7nvB97KoMcNqVC1nBOm9w786WR6uSZkBcxbVJBDONQBMlbRfnR8AiqtYqoaLvUbLLFoK7stJBd9yauApJ0weeb0RQyswBxQ6iOU0UWg8w1cSPQnQQ/UF90YpE500JEs6NmDvO6NHNDRynNEY3TAsB3ZI2FwZLF+VZXIL7lkved1qvuRCZFHCxc4TS1X Z/ZbgFUY cUOmbDllZHEKCV/Rhs05fMHGToTHeB38nyw/mGgsQdMZXal6xyS67dvpcO9CydyzaDx0BKmeLFbl2BsJ78gSWfj5RCWOL9saT7MYudbaKdfyhd2QsG9jGoIrkt1awmLlECNJ18sm+QsipXNATq5GkZ9kHOataQKl4q7zPFDKejmypidsklMxKhrHUg1p0s2rVVh5tk8Ju+6tl1yQL8MNysllzZSXmBA9T1KGSQpEvk/ZxLg3i8pc7256CfSkJM6PiMcjDEXsuvRY3r+f/O1q09OFo5OrTAY0X2Y8Pv0G/O0S+bht5i7EQW+gslXR4LZ3hxs/NPuPctMN49HPuM3GM6DcC3X5axqoyJR4WqZSqBvyMOMGZmJSYPso6sbH34uDiLSfmhcRjHnp26aL+CpUBadMvyqSLJ7yeyv/cLYrvTig5J2Hk0uUP836mCMQWGznJpCLKZWnHhjx9eHmGVWSa5BW3rGawy2TH9cpYeqUqCZjIAds2vsJD9TiUgASsX7NHOIm4GIX1NDF7Dqc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Rather than passing around huge numbers of parameters to numerous helper functions, abstract them into a single struct that we thread through the operation, the vma_merge_struct ('vmg'). Adjust vma_merge() and vma_modify() to accept this parameter, as well as predicate functions can_vma_merge_before(), can_vma_merge_after(), and the vma_modify_...() helper functions. Also introduce VMG_STATE() and VMG_VMA_STATE() helper macros to allow for easy vmg declaration. We additionally remove the requirement that vma_merge() is passed a VMA object representing the candidate new VMA. Previously it used this to obtain the mm_struct, file and anon_vma properties of the proposed range (a rather confusing state of affairs), which are now provided by the vmg directly. We also remove the pgoff calculation previously performed vma_modify(), and instead calculate this in VMG_VMA_STATE() via the vma_pgoff_offset() helper. Signed-off-by: Lorenzo Stoakes Reviewed-by: Liam R. Howlett --- mm/mmap.c | 77 ++++++++------- mm/vma.c | 209 ++++++++++++++++++++++++---------------- mm/vma.h | 128 ++++++++++++++---------- tools/testing/vma/vma.c | 43 +-------- 4 files changed, 249 insertions(+), 208 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index e495b0381265..4066c0444495 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1373,9 +1373,11 @@ unsigned long mmap_region(struct file *file, unsigned long addr, unsigned long end = addr + len; unsigned long merge_start = addr, merge_end = end; bool writable_file_mapping = false; - pgoff_t vm_pgoff; int error = -ENOMEM; VMA_ITERATOR(vmi, mm, addr); + VMG_STATE(vmg, mm, &vmi, addr, end, vm_flags, pgoff); + + vmg.file = file; /* Find the first overlapping VMA */ vma = vma_find(&vmi, end); @@ -1388,12 +1390,12 @@ unsigned long mmap_region(struct file *file, unsigned long addr, if (vms_gather_munmap_vmas(&vms, &mas_detach)) return -ENOMEM; - next = vms.next; - prev = vms.prev; + next = vmg.next = vms.next; + prev = vmg.prev = vms.prev; vma = NULL; } else { - next = vma_next(&vmi); - prev = vma_prev(&vmi); + next = vmg.next = vma_next(&vmi); + prev = vmg.prev = vma_prev(&vmi); if (prev) vma_iter_next_range(&vmi); } @@ -1413,6 +1415,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vms.nr_accounted = 0; vm_flags |= VM_ACCOUNT; + vmg.flags = vm_flags; } if (vm_flags & VM_SPECIAL) @@ -1421,28 +1424,31 @@ unsigned long mmap_region(struct file *file, unsigned long addr, /* Attempt to expand an old mapping */ /* Check next */ if (next && next->vm_start == end && !vma_policy(next) && - can_vma_merge_before(next, vm_flags, NULL, file, pgoff+pglen, - NULL_VM_UFFD_CTX, NULL)) { + can_vma_merge_before(&vmg)) { merge_end = next->vm_end; vma = next; - vm_pgoff = next->vm_pgoff - pglen; + vmg.pgoff = next->vm_pgoff - pglen; + /* + * We set this here so if we will merge with the previous VMA in + * the code below, can_vma_merge_after() ensures anon_vma + * compatibility between prev and next. + */ + vmg.anon_vma = vma->anon_vma; + vmg.uffd_ctx = vma->vm_userfaultfd_ctx; } /* Check prev */ if (prev && prev->vm_end == addr && !vma_policy(prev) && - (vma ? can_vma_merge_after(prev, vm_flags, vma->anon_vma, file, - pgoff, vma->vm_userfaultfd_ctx, NULL) : - can_vma_merge_after(prev, vm_flags, NULL, file, pgoff, - NULL_VM_UFFD_CTX, NULL))) { + can_vma_merge_after(&vmg)) { merge_start = prev->vm_start; vma = prev; - vm_pgoff = prev->vm_pgoff; + vmg.pgoff = prev->vm_pgoff; vma_prev(&vmi); /* Equivalent to going to the previous range */ } if (vma) { /* Actually expand, if possible */ - if (!vma_expand(&vmi, vma, merge_start, merge_end, vm_pgoff, next)) { + if (!vma_expand(&vmi, vma, merge_start, merge_end, vmg.pgoff, next)) { khugepaged_enter_vma(vma, vm_flags); goto expanded; } @@ -1772,26 +1778,29 @@ static int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *vma, * Expand the existing vma if possible; Note that singular lists do not * occur after forking, so the expand will only happen on new VMAs. */ - if (vma && vma->vm_end == addr && !vma_policy(vma) && - can_vma_merge_after(vma, flags, NULL, NULL, - addr >> PAGE_SHIFT, NULL_VM_UFFD_CTX, NULL)) { - vma_iter_config(vmi, vma->vm_start, addr + len); - if (vma_iter_prealloc(vmi, vma)) - goto unacct_fail; - - vma_start_write(vma); - - init_vma_prep(&vp, vma); - vma_prepare(&vp); - vma_adjust_trans_huge(vma, vma->vm_start, addr + len, 0); - vma->vm_end = addr + len; - vm_flags_set(vma, VM_SOFTDIRTY); - vma_iter_store(vmi, vma); - - vma_complete(&vp, vmi, mm); - validate_mm(mm); - khugepaged_enter_vma(vma, flags); - goto out; + if (vma && vma->vm_end == addr && !vma_policy(vma)) { + VMG_STATE(vmg, mm, vmi, addr, addr + len, flags, PHYS_PFN(addr)); + + vmg.prev = vma; + if (can_vma_merge_after(&vmg)) { + vma_iter_config(vmi, vma->vm_start, addr + len); + if (vma_iter_prealloc(vmi, vma)) + goto unacct_fail; + + vma_start_write(vma); + + init_vma_prep(&vp, vma); + vma_prepare(&vp); + vma_adjust_trans_huge(vma, vma->vm_start, addr + len, 0); + vma->vm_end = addr + len; + vm_flags_set(vma, VM_SOFTDIRTY); + vma_iter_store(vmi, vma); + + vma_complete(&vp, vmi, mm); + validate_mm(mm); + khugepaged_enter_vma(vma, flags); + goto out; + } } if (vma) diff --git a/mm/vma.c b/mm/vma.c index e5a5e418c7cb..74c627ff0313 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -7,16 +7,18 @@ #include "vma_internal.h" #include "vma.h" -/* - * If the vma has a ->close operation then the driver probably needs to release - * per-vma resources, so we don't attempt to merge those if the caller indicates - * the current vma may be removed as part of the merge. - */ -static inline bool is_mergeable_vma(struct vm_area_struct *vma, - struct file *file, unsigned long vm_flags, - struct vm_userfaultfd_ctx vm_userfaultfd_ctx, - struct anon_vma_name *anon_name, bool may_remove_vma) +static inline bool is_mergeable_vma(struct vma_merge_struct *vmg, bool merge_next) { + struct vm_area_struct *vma = merge_next ? vmg->next : vmg->prev; + /* + * If the vma has a ->close operation then the driver probably needs to + * release per-vma resources, so we don't attempt to merge those if the + * caller indicates the current vma may be removed as part of the merge, + * which is the case if we are attempting to merge the next VMA into + * this one. + */ + bool may_remove_vma = merge_next; + /* * VM_SOFTDIRTY should not prevent from VMA merging, if we * match the flags but dirty bit -- the caller should mark @@ -25,15 +27,15 @@ static inline bool is_mergeable_vma(struct vm_area_struct *vma, * the kernel to generate new VMAs when old one could be * extended instead. */ - if ((vma->vm_flags ^ vm_flags) & ~VM_SOFTDIRTY) + if ((vma->vm_flags ^ vmg->flags) & ~VM_SOFTDIRTY) return false; - if (vma->vm_file != file) + if (vma->vm_file != vmg->file) return false; if (may_remove_vma && vma->vm_ops && vma->vm_ops->close) return false; - if (!is_mergeable_vm_userfaultfd_ctx(vma, vm_userfaultfd_ctx)) + if (!is_mergeable_vm_userfaultfd_ctx(vma, vmg->uffd_ctx)) return false; - if (!anon_vma_name_eq(anon_vma_name(vma), anon_name)) + if (!anon_vma_name_eq(anon_vma_name(vma), vmg->anon_name)) return false; return true; } @@ -94,16 +96,16 @@ static void init_multi_vma_prep(struct vma_prepare *vp, * We assume the vma may be removed as part of the merge. */ bool -can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags, - struct anon_vma *anon_vma, struct file *file, - pgoff_t vm_pgoff, struct vm_userfaultfd_ctx vm_userfaultfd_ctx, - struct anon_vma_name *anon_name) +can_vma_merge_before(struct vma_merge_struct *vmg) { - if (is_mergeable_vma(vma, file, vm_flags, vm_userfaultfd_ctx, anon_name, true) && - is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) { - if (vma->vm_pgoff == vm_pgoff) + pgoff_t pglen = PHYS_PFN(vmg->end - vmg->start); + + if (is_mergeable_vma(vmg, true) && + is_mergeable_anon_vma(vmg->anon_vma, vmg->next->anon_vma, vmg->next)) { + if (vmg->next->vm_pgoff == vmg->pgoff + pglen) return true; } + return false; } @@ -116,18 +118,11 @@ can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags, * * We assume that vma is not removed as part of the merge. */ -bool -can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags, - struct anon_vma *anon_vma, struct file *file, - pgoff_t vm_pgoff, struct vm_userfaultfd_ctx vm_userfaultfd_ctx, - struct anon_vma_name *anon_name) +bool can_vma_merge_after(struct vma_merge_struct *vmg) { - if (is_mergeable_vma(vma, file, vm_flags, vm_userfaultfd_ctx, anon_name, false) && - is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) { - pgoff_t vm_pglen; - - vm_pglen = vma_pages(vma); - if (vma->vm_pgoff + vm_pglen == vm_pgoff) + if (is_mergeable_vma(vmg, false) && + is_mergeable_anon_vma(vmg->anon_vma, vmg->prev->anon_vma, vmg->prev)) { + if (vmg->prev->vm_pgoff + vma_pages(vmg->prev) == vmg->pgoff) return true; } return false; @@ -1022,16 +1017,10 @@ int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, * **** is not represented - it will be merged and the vma containing the * area is returned, or the function will return NULL */ -static struct vm_area_struct -*vma_merge(struct vma_iterator *vmi, struct vm_area_struct *prev, - struct vm_area_struct *src, unsigned long addr, unsigned long end, - unsigned long vm_flags, pgoff_t pgoff, struct mempolicy *policy, - struct vm_userfaultfd_ctx vm_userfaultfd_ctx, - struct anon_vma_name *anon_name) +static struct vm_area_struct *vma_merge(struct vma_merge_struct *vmg) { - struct mm_struct *mm = src->vm_mm; - struct anon_vma *anon_vma = src->anon_vma; - struct file *file = src->vm_file; + struct mm_struct *mm = vmg->mm; + struct vm_area_struct *prev = vmg->prev; struct vm_area_struct *curr, *next, *res; struct vm_area_struct *vma, *adjust, *remove, *remove2; struct vm_area_struct *anon_dup = NULL; @@ -1041,16 +1030,18 @@ static struct vm_area_struct bool merge_prev = false; bool merge_next = false; bool vma_expanded = false; + unsigned long addr = vmg->start; + unsigned long end = vmg->end; unsigned long vma_start = addr; unsigned long vma_end = end; - pgoff_t pglen = (end - addr) >> PAGE_SHIFT; + pgoff_t pglen = PHYS_PFN(end - addr); long adj_start = 0; /* * We later require that vma->vm_flags == vm_flags, * so this tests vma->vm_flags & VM_SPECIAL, too. */ - if (vm_flags & VM_SPECIAL) + if (vmg->flags & VM_SPECIAL) return NULL; /* Does the input range span an existing VMA? (cases 5 - 8) */ @@ -1058,27 +1049,26 @@ static struct vm_area_struct if (!curr || /* cases 1 - 4 */ end == curr->vm_end) /* cases 6 - 8, adjacent VMA */ - next = vma_lookup(mm, end); + next = vmg->next = vma_lookup(mm, end); else - next = NULL; /* case 5 */ + next = vmg->next = NULL; /* case 5 */ if (prev) { vma_start = prev->vm_start; vma_pgoff = prev->vm_pgoff; /* Can we merge the predecessor? */ - if (addr == prev->vm_end && mpol_equal(vma_policy(prev), policy) - && can_vma_merge_after(prev, vm_flags, anon_vma, file, - pgoff, vm_userfaultfd_ctx, anon_name)) { + if (addr == prev->vm_end && mpol_equal(vma_policy(prev), vmg->policy) + && can_vma_merge_after(vmg)) { + merge_prev = true; - vma_prev(vmi); + vma_prev(vmg->vmi); } } /* Can we merge the successor? */ - if (next && mpol_equal(policy, vma_policy(next)) && - can_vma_merge_before(next, vm_flags, anon_vma, file, pgoff+pglen, - vm_userfaultfd_ctx, anon_name)) { + if (next && mpol_equal(vmg->policy, vma_policy(next)) && + can_vma_merge_before(vmg)) { merge_next = true; } @@ -1129,7 +1119,7 @@ static struct vm_area_struct remove = curr; } else { /* case 5 */ adjust = curr; - adj_start = (end - curr->vm_start); + adj_start = end - curr->vm_start; } if (!err) err = dup_anon_vma(prev, curr, &anon_dup); @@ -1169,13 +1159,13 @@ static struct vm_area_struct vma_expanded = true; if (vma_expanded) { - vma_iter_config(vmi, vma_start, vma_end); + vma_iter_config(vmg->vmi, vma_start, vma_end); } else { - vma_iter_config(vmi, adjust->vm_start + adj_start, + vma_iter_config(vmg->vmi, adjust->vm_start + adj_start, adjust->vm_end); } - if (vma_iter_prealloc(vmi, vma)) + if (vma_iter_prealloc(vmg->vmi, vma)) goto prealloc_fail; init_multi_vma_prep(&vp, vma, adjust, remove, remove2); @@ -1187,20 +1177,20 @@ static struct vm_area_struct vma_set_range(vma, vma_start, vma_end, vma_pgoff); if (vma_expanded) - vma_iter_store(vmi, vma); + vma_iter_store(vmg->vmi, vma); if (adj_start) { adjust->vm_start += adj_start; adjust->vm_pgoff += adj_start >> PAGE_SHIFT; if (adj_start < 0) { WARN_ON(vma_expanded); - vma_iter_store(vmi, next); + vma_iter_store(vmg->vmi, next); } } - vma_complete(&vp, vmi, mm); + vma_complete(&vp, vmg->vmi, mm); validate_mm(mm); - khugepaged_enter_vma(res, vm_flags); + khugepaged_enter_vma(res, vmg->flags); return res; prealloc_fail: @@ -1208,8 +1198,8 @@ static struct vm_area_struct unlink_anon_vmas(anon_dup); anon_vma_fail: - vma_iter_set(vmi, addr); - vma_iter_load(vmi); + vma_iter_set(vmg->vmi, addr); + vma_iter_load(vmg->vmi); return NULL; } @@ -1226,32 +1216,27 @@ static struct vm_area_struct * The function returns either the merged VMA, the original VMA if a split was * required instead, or an error if the split failed. */ -struct vm_area_struct *vma_modify(struct vma_iterator *vmi, - struct vm_area_struct *prev, - struct vm_area_struct *vma, - unsigned long start, unsigned long end, - unsigned long vm_flags, - struct mempolicy *policy, - struct vm_userfaultfd_ctx uffd_ctx, - struct anon_vma_name *anon_name) +static struct vm_area_struct *vma_modify(struct vma_merge_struct *vmg) { - pgoff_t pgoff = vma->vm_pgoff + ((start - vma->vm_start) >> PAGE_SHIFT); + struct vm_area_struct *vma = vmg->vma; struct vm_area_struct *merged; - merged = vma_merge(vmi, prev, vma, start, end, vm_flags, - pgoff, policy, uffd_ctx, anon_name); + /* First, try to merge. */ + merged = vma_merge(vmg); if (merged) return merged; - if (vma->vm_start < start) { - int err = split_vma(vmi, vma, start, 1); + /* Split any preceding portion of the VMA. */ + if (vma->vm_start < vmg->start) { + int err = split_vma(vmg->vmi, vma, vmg->start, 1); if (err) return ERR_PTR(err); } - if (vma->vm_end > end) { - int err = split_vma(vmi, vma, end, 0); + /* Split any trailing portion of the VMA. */ + if (vma->vm_end > vmg->end) { + int err = split_vma(vmg->vmi, vma, vmg->end, 0); if (err) return ERR_PTR(err); @@ -1260,6 +1245,65 @@ struct vm_area_struct *vma_modify(struct vma_iterator *vmi, return vma; } +struct vm_area_struct *vma_modify_flags( + struct vma_iterator *vmi, struct vm_area_struct *prev, + struct vm_area_struct *vma, unsigned long start, unsigned long end, + unsigned long new_flags) +{ + VMG_VMA_STATE(vmg, vmi, prev, vma, start, end); + + vmg.flags = new_flags; + + return vma_modify(&vmg); +} + +struct vm_area_struct +*vma_modify_flags_name(struct vma_iterator *vmi, + struct vm_area_struct *prev, + struct vm_area_struct *vma, + unsigned long start, + unsigned long end, + unsigned long new_flags, + struct anon_vma_name *new_name) +{ + VMG_VMA_STATE(vmg, vmi, prev, vma, start, end); + + vmg.flags = new_flags; + vmg.anon_name = new_name; + + return vma_modify(&vmg); +} + +struct vm_area_struct +*vma_modify_policy(struct vma_iterator *vmi, + struct vm_area_struct *prev, + struct vm_area_struct *vma, + unsigned long start, unsigned long end, + struct mempolicy *new_pol) +{ + VMG_VMA_STATE(vmg, vmi, prev, vma, start, end); + + vmg.policy = new_pol; + + return vma_modify(&vmg); +} + +struct vm_area_struct +*vma_modify_flags_uffd(struct vma_iterator *vmi, + struct vm_area_struct *prev, + struct vm_area_struct *vma, + unsigned long start, unsigned long end, + unsigned long new_flags, + struct vm_userfaultfd_ctx new_ctx) +{ + VMG_VMA_STATE(vmg, vmi, prev, vma, start, end); + + vmg.flags = new_flags; + vmg.uffd_ctx = new_ctx; + + return vma_modify(&vmg); +} + /* * Attempt to merge a newly mapped VMA with those adjacent to it. The caller * must ensure that [start, end) does not overlap any existing VMA. @@ -1269,8 +1313,11 @@ struct vm_area_struct struct vm_area_struct *vma, unsigned long start, unsigned long end, pgoff_t pgoff) { - return vma_merge(vmi, prev, vma, start, end, vma->vm_flags, pgoff, - vma_policy(vma), vma->vm_userfaultfd_ctx, anon_vma_name(vma)); + VMG_VMA_STATE(vmg, vmi, prev, vma, start, end); + + vmg.pgoff = pgoff; + + return vma_merge(&vmg); } /* @@ -1281,12 +1328,10 @@ struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, struct vm_area_struct *vma, unsigned long delta) { - pgoff_t pgoff = vma->vm_pgoff + vma_pages(vma); + VMG_VMA_STATE(vmg, vmi, vma, vma, vma->vm_end, vma->vm_end + delta); /* vma is specified as prev, so case 1 or 2 will apply. */ - return vma_merge(vmi, vma, vma, vma->vm_end, vma->vm_end + delta, - vma->vm_flags, pgoff, vma_policy(vma), - vma->vm_userfaultfd_ctx, anon_vma_name(vma)); + return vma_merge(&vmg); } void unlink_file_vma_batch_init(struct unlink_vma_file_batch *vb) diff --git a/mm/vma.h b/mm/vma.h index c774642697a0..9060a1a1edfa 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -52,6 +52,59 @@ struct vma_munmap_struct { unsigned long data_vm; }; +/* Represents a VMA merge operation. */ +struct vma_merge_struct { + struct mm_struct *mm; + struct vma_iterator *vmi; + pgoff_t pgoff; + struct vm_area_struct *prev; + struct vm_area_struct *next; /* Modified by vma_merge(). */ + struct vm_area_struct *vma; /* Either a new VMA or the one being modified. */ + unsigned long start; + unsigned long end; + unsigned long flags; + struct file *file; + struct anon_vma *anon_vma; + struct mempolicy *policy; + struct vm_userfaultfd_ctx uffd_ctx; + struct anon_vma_name *anon_name; +}; + +/* Assumes addr >= vma->vm_start. */ +static inline pgoff_t vma_pgoff_offset(struct vm_area_struct *vma, + unsigned long addr) +{ + return vma->vm_pgoff + PHYS_PFN(addr - vma->vm_start); +} + +#define VMG_STATE(name, mm_, vmi_, start_, end_, flags_, pgoff_) \ + struct vma_merge_struct name = { \ + .mm = mm_, \ + .vmi = vmi_, \ + .start = start_, \ + .end = end_, \ + .flags = flags_, \ + .pgoff = pgoff_, \ + } + +#define VMG_VMA_STATE(name, vmi_, prev_, vma_, start_, end_) \ + struct vma_merge_struct name = { \ + .mm = vma_->vm_mm, \ + .vmi = vmi_, \ + .prev = prev_, \ + .next = NULL, \ + .vma = vma_, \ + .start = start_, \ + .end = end_, \ + .flags = vma_->vm_flags, \ + .pgoff = vma_pgoff_offset(vma_, start_), \ + .file = vma_->vm_file, \ + .anon_vma = vma_->anon_vma, \ + .policy = vma_policy(vma_), \ + .uffd_ctx = vma_->vm_userfaultfd_ctx, \ + .anon_name = anon_vma_name(vma_), \ + } + #ifdef CONFIG_DEBUG_VM_MAPLE_TREE void validate_mm(struct mm_struct *mm); #else @@ -208,80 +261,53 @@ void remove_vma(struct vm_area_struct *vma, bool unreachable, bool closed); void unmap_region(struct ma_state *mas, struct vm_area_struct *vma, struct vm_area_struct *prev, struct vm_area_struct *next); -/* Required by mmap_region(). */ -bool -can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags, - struct anon_vma *anon_vma, struct file *file, - pgoff_t vm_pgoff, struct vm_userfaultfd_ctx vm_userfaultfd_ctx, - struct anon_vma_name *anon_name); - -/* Required by mmap_region() and do_brk_flags(). */ -bool -can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags, - struct anon_vma *anon_vma, struct file *file, - pgoff_t vm_pgoff, struct vm_userfaultfd_ctx vm_userfaultfd_ctx, - struct anon_vma_name *anon_name); - -struct vm_area_struct *vma_modify(struct vma_iterator *vmi, - struct vm_area_struct *prev, - struct vm_area_struct *vma, - unsigned long start, unsigned long end, - unsigned long vm_flags, - struct mempolicy *policy, - struct vm_userfaultfd_ctx uffd_ctx, - struct anon_vma_name *anon_name); +/* + * Can we merge the VMA described by vmg into the following VMA vmg->next? + * + * Required by mmap_region(). + */ +bool can_vma_merge_before(struct vma_merge_struct *vmg); + +/* + * Can we merge the VMA described by vmg into the preceding VMA vmg->prev? + * + * Required by mmap_region() and do_brk_flags(). + */ +bool can_vma_merge_after(struct vma_merge_struct *vmg); /* We are about to modify the VMA's flags. */ -static inline struct vm_area_struct -*vma_modify_flags(struct vma_iterator *vmi, - struct vm_area_struct *prev, - struct vm_area_struct *vma, - unsigned long start, unsigned long end, - unsigned long new_flags) -{ - return vma_modify(vmi, prev, vma, start, end, new_flags, - vma_policy(vma), vma->vm_userfaultfd_ctx, - anon_vma_name(vma)); -} +struct vm_area_struct *vma_modify_flags(struct vma_iterator *vmi, + struct vm_area_struct *prev, + struct vm_area_struct *vma, + unsigned long start, unsigned long end, + unsigned long new_flags); /* We are about to modify the VMA's flags and/or anon_name. */ -static inline struct vm_area_struct +struct vm_area_struct *vma_modify_flags_name(struct vma_iterator *vmi, struct vm_area_struct *prev, struct vm_area_struct *vma, unsigned long start, unsigned long end, unsigned long new_flags, - struct anon_vma_name *new_name) -{ - return vma_modify(vmi, prev, vma, start, end, new_flags, - vma_policy(vma), vma->vm_userfaultfd_ctx, new_name); -} + struct anon_vma_name *new_name); /* We are about to modify the VMA's memory policy. */ -static inline struct vm_area_struct +struct vm_area_struct *vma_modify_policy(struct vma_iterator *vmi, struct vm_area_struct *prev, struct vm_area_struct *vma, unsigned long start, unsigned long end, - struct mempolicy *new_pol) -{ - return vma_modify(vmi, prev, vma, start, end, vma->vm_flags, - new_pol, vma->vm_userfaultfd_ctx, anon_vma_name(vma)); -} + struct mempolicy *new_pol); /* We are about to modify the VMA's flags and/or uffd context. */ -static inline struct vm_area_struct +struct vm_area_struct *vma_modify_flags_uffd(struct vma_iterator *vmi, struct vm_area_struct *prev, struct vm_area_struct *vma, unsigned long start, unsigned long end, unsigned long new_flags, - struct vm_userfaultfd_ctx new_ctx) -{ - return vma_modify(vmi, prev, vma, start, end, new_flags, - vma_policy(vma), new_ctx, anon_vma_name(vma)); -} + struct vm_userfaultfd_ctx new_ctx); struct vm_area_struct *vma_merge_new_vma(struct vma_iterator *vmi, struct vm_area_struct *prev, diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index 9b272633ca9e..b12f72979478 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -22,26 +22,6 @@ static bool fail_prealloc; */ #include "../../../mm/vma.c" -/* - * Temporarily forward-ported from a future in which vmg's are used for merging. - */ -struct vma_merge_struct { - struct mm_struct *mm; - struct vma_iterator *vmi; - pgoff_t pgoff; - struct vm_area_struct *prev; - struct vm_area_struct *next; /* Modified by vma_merge(). */ - struct vm_area_struct *vma; /* Either a new VMA or the one being modified. */ - unsigned long start; - unsigned long end; - unsigned long flags; - struct file *file; - struct anon_vma *anon_vma; - struct mempolicy *policy; - struct vm_userfaultfd_ctx uffd_ctx; - struct anon_vma_name *anon_name; -}; - const struct vm_operations_struct vma_dummy_vm_ops; static struct anon_vma dummy_anon_vma; @@ -115,14 +95,6 @@ static struct vm_area_struct *alloc_and_link_vma(struct mm_struct *mm, /* Helper function which provides a wrapper around a merge new VMA operation. */ static struct vm_area_struct *merge_new(struct vma_merge_struct *vmg) { - /* vma_merge() needs a VMA to determine mm, anon_vma, and file. */ - struct vm_area_struct dummy = { - .vm_mm = vmg->mm, - .vm_flags = vmg->flags, - .anon_vma = vmg->anon_vma, - .vm_file = vmg->file, - }; - /* * For convenience, get prev and next VMAs. Which the new VMA operation * requires. @@ -131,8 +103,7 @@ static struct vm_area_struct *merge_new(struct vma_merge_struct *vmg) vmg->prev = vma_prev(vmg->vmi); vma_iter_set(vmg->vmi, vmg->start); - return vma_merge_new_vma(vmg->vmi, vmg->prev, &dummy, vmg->start, - vmg->end, vmg->pgoff); + return vma_merge(vmg); } /* @@ -141,17 +112,7 @@ static struct vm_area_struct *merge_new(struct vma_merge_struct *vmg) */ static struct vm_area_struct *merge_existing(struct vma_merge_struct *vmg) { - /* vma_merge() needs a VMA to determine mm, anon_vma, and file. */ - struct vm_area_struct dummy = { - .vm_mm = vmg->mm, - .vm_flags = vmg->flags, - .anon_vma = vmg->anon_vma, - .vm_file = vmg->file, - }; - - return vma_merge(vmg->vmi, vmg->prev, &dummy, vmg->start, vmg->end, - vmg->flags, vmg->pgoff, vmg->policy, vmg->uffd_ctx, - vmg->anon_name); + return vma_merge(vmg); } /* From patchwork Fri Aug 23 20:06:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13775911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A152AC5321D for ; Fri, 23 Aug 2024 20:07:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B2F74800C6; Fri, 23 Aug 2024 16:07:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE3C4800C5; Fri, 23 Aug 2024 16:07:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70EB0800C6; Fri, 23 Aug 2024 16:07:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 3AEBB800C1 for ; Fri, 23 Aug 2024 16:07:33 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DA32F1C00A9 for ; Fri, 23 Aug 2024 20:07:32 +0000 (UTC) X-FDA: 82484595144.24.54CC8CC Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf14.hostedemail.com (Postfix) with ESMTP id 7FC6E10000D for ; Fri, 23 Aug 2024 20:07:29 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=IgCzZROw; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=MAqwsMaA; spf=pass (imf14.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724443608; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3xTjVIqKqveTebbEp0Zxm5DICHh70p8Rc7Hp9qiX/R4=; b=02VKcwG4I1VCPOikcpoBfF+x3nrlXUXoU5l5AcElzbn69z0W+pLhvJb9u2BbRgYrurVxtz P4biWwagwougVwAYSuEeNop36S6Mt7N7YwFLnOaRgaARM/Q3pIzlCDM7UXekRX1SfrkoHy YUYJV9v4bDiNYGHsfoTrAXsYh43NnlQ= ARC-Authentication-Results: i=2; imf14.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=IgCzZROw; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=MAqwsMaA; spf=pass (imf14.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724443608; a=rsa-sha256; cv=pass; b=6FNvTABXiAc2Su94sdW/1askixtOeHcmvzqfTrH/Y+FVfB3a3LPIf+AEGhvBkvqU/PnBJP 6D3Y3NmkA5SSVe/uzwAPel1L/sIYhEhk4gAMI0x3jblp9wtL3zPT0uMWGk3N5LSzvpSUn5 6BsNiT8pPnGlt+hsBbBIY9AzJ6ePrvk= Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47NH0VJR002318; Fri, 23 Aug 2024 20:07:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=3xTjVIqKqveTebbEp0Zxm5DICHh70p8Rc7Hp9qiX/R4=; b= IgCzZROwgOBSH3GwRLNnOgtJLAkBXZPLFLRfgE1Blg8fmiQgJ9sjiTXXtT+DSn9x XMRzOY3+kKXnv2ZLOwo/bNs8wp1QHDc2+gaoJBaGZKNgawzzljX0ZG/HL40Qoo1c JwnMdazAVO+DcLRDHghn8yiCA9DkfNFXoOEq0J+z0YK9l3r0H3+toK37K0zLE9Gd JFvenU5TTV45DWqDpLVWA1w+CAFyoFphh7/olRJZF7r0WTj52T+xbglpgQzXD83k Edto4zq07iy0JivyfqCFPSeD2vNCzlF5ffv5j5dzyb/Lx0hEg3whBeWK/HSfkOCn ksX+Suta4+SqdVsDnEyDrw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412m67n1fd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:28 +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 47NJdFFf007123; Fri, 23 Aug 2024 20:07:26 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2177.outbound.protection.outlook.com [104.47.58.177]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4170s610wk-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xCQa2xxtj/AVGnfmBRJGsbOMejKd20TvdC8z3LB0CzV9vYICNqcJG9Nb6sIytsLzmjF9h1qQrDnPzS1OGsMCwzCdPS2U7O1L39vzAssG6OxJ/S2D1bqMQEdzPC2ZUwUhf8arkDKjGtu5kw7pAhGb4jIyS5P3e/KxrQz7jFHTE9V1d09qmT9v4n9QESX24RJ5EHP2W5rKIj14BGBoVWCuKXhZX+y8hJm+d6FdRz23p8mFRtkC0LDnH16FT/Sk3qPWUpQ/zxJZeVpsV4jcyoOpklLCPRd8pbvHGx6UvfsGSkmh/XsAJMOwj+sYI9EgA8VLBTj0MrTvCevC6O/puGmzNQ== 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=3xTjVIqKqveTebbEp0Zxm5DICHh70p8Rc7Hp9qiX/R4=; b=yb5CwtencIvl8qIqlS7Ey2BA0AMxd70IiFY3QG9u09umYejVMNEdLWc/a8Us7QGpAZd0Q1BN65drmHjZbO3jOU9MLrc3vQEZ3o5CvvJ9pI8R3GvWG5k0ZGG9izyp/7FDkRUGq+bymvuJM/XnUvxgeTvR74CsMe1XfVuvYRlvAjlvZQQhHLRjwhjiH1VoaDDTkEcGcgTePdpdWmWlmqvNiapl3yBSEIVR70iDa4rO0Etql/Ff/m7X8v6hECg6tM189IZUGP7XtuzgoGydHgntf0zNw08iiiGAZPmzhdWeritPzyL6yvmEWHOOyrY+hGbUw5lMOGpCNAkD+kGFxzoWnQ== 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=3xTjVIqKqveTebbEp0Zxm5DICHh70p8Rc7Hp9qiX/R4=; b=MAqwsMaAhucagrtkUhA4qwdeC39SLkJGxfqC73vIAu+oKmfqOUN2z5BlmllEXPTVp8jT7S9rEdh60GegQhYoBUvimvqw17XvdLJfKyO+2rQH/qt3q+VVnfxVg9oYEEVEnuY1cMuA6rslD4l0U1hSZjdLUzmjnP/4HXUnZVTUxIo= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by BL3PR10MB6187.namprd10.prod.outlook.com (2603:10b6:208:3be::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.17; Fri, 23 Aug 2024 20:07:19 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%6]) with mapi id 15.20.7897.014; Fri, 23 Aug 2024 20:07:19 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH v2 04/10] mm: remove duplicated open-coded VMA policy check Date: Fri, 23 Aug 2024 21:06:59 +0100 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0145.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::13) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|BL3PR10MB6187:EE_ X-MS-Office365-Filtering-Correlation-Id: d08ec701-ebdb-4c0b-2594-08dcc3af317a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: tdj0SCr2QlMnuR1CExpvBR+dWdCsz05BFU9QfcnjPYULUg5WOv41jrQ9zBObQzLPYBL57ARar1tJy7ofiBWPwj4XLEeaTRyl9/HcEKLoG9rm/cpPc+gGa7lxjhBdkvZxRbqZ8S0k7YXdO1GhKoJvC6f1yLFUQ7p++zA2BizdM9FZDv9wOGlLx6ijR9XI/x2lQnY48NojElU77A1zpaSe5NtbS1g++eQGl+8LcUSyRWkqIx5xrurYj5QgET8XKTBCzflpDAS0AjbO/fsNPcnZKAFVUIisknzbpMxI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rA9V2Caq7Y4AnWWW41891Kw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9D/bvyY/rgRV62UIsQeBRqGm2R0IDMPgeyOR7X7V/gnUSAfPVm8FBdrz2URu3e1Q6DiiPpaENb1KxifnsAHBFvyRG2id1TASihNQ7EzICY6wc9lPyHx7ycT0YMROlHxqICIcdt0WJ43tzGShhygB4UQXiS1xcz2mDR50F7F2ot/U6HaO/tvNMn34pFtkDCBOj+iJIR4XLWWOsF6/2dLLDnOPdeTDhpLgzZ0YMrvJTOqa7U6gOOgE9gBpkyy9oibYFuzfc01HzkZ9L2+SD1BPFCL3QxEQGgMT7rM41zmmOL0Hq26PxyIcl6yBIQ9Bc4Vb4HAhY7mcHDXvRC873nHdiO13BjcmJEyATxJYfL5/nnRnXz1KYgyMrWdTU0uujI7LlOHz0jsti18LZ3YJyHtcSURbLeXMD4SSw+vvFuovNNa2lYm7LSqGvU923048JAAAzkmZp+xkREP6Q127EmsfvOMbkurLMWx6xfRJHJ9QJdyP6heROhfOjmUvovaqtT6L8pJi1Pb8V/w6159GfIiVaNheC/sNfg+wDYdCD7HU+p427yAMawm8UTs41R+c0wImBSBO7PqldeeDru2vC7UwlTuussYId2e7snZm5LlhnEjQPP7y2bBqXItgrZZFLzis3CpdFKEPT2i9eV7v/pJoCrtfrxupCf2O22xC8AiuKxF77U4sKAv/JUFTYDFEpgqfTqYhE4JNG+D4xS3V7/SfwVLOTuo61zKMQAlcjvwGXsEaZHzJ8Tm50KEmagk/3KcbuMVYhktbcpLpUxy8g5LSofN8EiPxCe+1d5OdFcNc2uqur222VkJ+p2j5L3E+OiMXrgNqfjT0Ax4MFpN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aqFhHXd+4Qok27qzDttFlx0nem1RRXSp/AMn8nZuZiGVKd1hyhN+0JA+vJgMDSZNX1fOrN5/m4zAeLrAkZ9F6b2ABXErCY6ntR/1X6+syL2FuI3eAubd2c0F+che/t31r8ItLVWXm3tP8HGUc8fMnl0KTmxnWyo35+tIL8KPTjzd0UbStAJMZ51sjpVNgX8qiNos8Tgde1i64a9k8g+oBpBMeyhTjf+65CxAFsMYlhEnZSKRjFh0VSLh+209Mfw8qt2xGrrc88/C830ngwJrLclF4y5E5LlygkHPhYh7MKLo0SoEpY5DJVutgW9ESc2G6vM3zyKuo6wfZG+HaH4edAw3ZPrrzNj2vDCeTl3Y/wgfGFuFGHqmwDsc2kIgQfeL7RlDgmc+vpWZ/SkdQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: d08ec701-ebdb-4c0b-2594-08dcc3af317a X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 20:07:19.7516 (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: Dy2mVjtMxB88KNrK7fA+AMg5KI56TO9x7bqzuLonqsYR1FAZEsEB0MZ6PODeOn31XtieQMx2DrALcy1AfLgImL9/2dbzJmRcqgca9vkM4q0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR10MB6187 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-23_16,2024-08-23_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 mlxlogscore=983 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408230148 X-Proofpoint-ORIG-GUID: Nj41znAtbQ8N4fq2PKCihWPceeOwYBRA X-Proofpoint-GUID: Nj41znAtbQ8N4fq2PKCihWPceeOwYBRA X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 7FC6E10000D X-Stat-Signature: 6yi5w4nta99wd17ayewnurx6u9mamyim X-HE-Tag: 1724443649-807799 X-HE-Meta: U2FsdGVkX19nMAgre0fPjaO8c+UXAJ6EGKIA6+6dqQrGOPygI1BYSmdVSkpble6DCKzB4X5/BZ8f7tPMhO2OtsAX9hyOP0MIO1fHoV47tyZzxZjGt6eINdS4YQDNSI2fkuoxhL+iJ8Ow6HJr/R1tdSHt5c/yJTRVkddyluaxuTjB0he1e/LA41w+Yc/ZU0wMS2wMwos4erRMpEmgl1iKqpfxkfyrNXo0fzuie7D04OhCPeFopNRph0dj3NatEnip0CRvyiJPuH70FI1Lmbd15F6tHWyjQ6vnXwuuqVbR3f4xSjG1YnPtQg7e4ovf+YxiezLXOLKBsmXcFfVdpFdCauvh2+4Q2xsYLpe8GwFJ90fFwNYu75x2KGqBh+ry+D1yTq9szkB3YVuV9WkUsbh67Oj7nGv9VDA3I6AJsdpaXVlB4pup8xyao+7d0EiTz5Mh3Ws58964quQu9nR+OHyPoGiaf2qBXOnm88hE05cQjd+AuR4S8PXdWIPkek4boDyymDbbh0MOa6G1NyRBYC/CT6LMxO70bk7LGhOgZWbQOiyQZJU9r8DAJEK3pjN5PlZ+jYKmRxzVvKX50xZacvZlXfDKIlMFCr9enuBW833Rhj5S5WM4bsG0PemwauzjIkb1TxN2c3GIlj3Me08EneC+wWAN7okjqiF43YyioXPRMSlFxQn6enJa+gJnFzlOkdhOCh6e6P8mA9N6P2bMMUQXE9GAkzO5UNMRsnP9aWZEnYimZtx4Np9+kXzQ+EGy08HaR8qaOX24PEZzuB3A/7vwRSUEDyQ3urgyKQHhJ1/3atJYmvHoKNS4QOoY1h1sQCVmZEk4bhkUBDpVVvJuuuqyfxiq/J/Eh5KBSpYtnqwDF3W7RjmuywDMIXULI5KhaHY2oCkUttnAgdcbsKQBx4fyma1qd+Anqo7h6vVSRGTLKh8yQk1+v8JednAbV1BScWR2mifVFRqQgcLkDyE4qF5 Ju7WMyW+ 6n4/Rg/xQqiLudsUsoVgBSitQTwHqS7d5Q/SAHVZ/l6ExJ4+2dbTgOwxh8K8hpu2d101b6aSS38UcqFKJwJGcr4HXZxRCzlFBwhJbtHwkBboJABapM4ahRA8sQos00th/hJp+auudENZFRv0uz9sXAi9xSEdHzskuJ0QnquUm+4O3jseBngZiBRVoqVFXgfyjYwadqJqCvGfdzMdat1gpok4YX6GpnhUrSEQWjFt5Wrbo2kqeTc8Zx9yqIT/F0qSiq9WgqKO3YtqdUH2KJxS8p/Js/dkXRmIhDQc4hxtphW46k4+eqW5ezKvG7fHipuzMuEBWjrCdmZ77nDwtUJ2Y5M/l+nYduVhvQS+SWiiPtveMJGBHzKIdb/6hNZt9StHWLjKF1f/rjxe7r2qynvOJ8mr8iqjLbLFV7IJIjEKc+JJUUO71+zkVnIor5OepdefF3Rh9BxPuWJs/9qfqSun9cfV+Hm/ap0RH0D83 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Both can_vma_merge_before() and can_vma_merge_after() are invoked after checking for compatible VMA NUMA policy, we can simply move this to is_mergeable_vma() and abstract this altogether. In mmap_region() we set vmg->policy to NULL, so the policy comparisons checked in can_vma_merge_before() and can_vma_merge_after() are exactly equivalent to !vma_policy(vmg.next) and !vma_policy(vmg.prev). Equally, in do_brk_flags(), vmg->policy is NULL, so the can_vma_merge_after() is checking !vma_policy(vma), as we set vmg.prev to vma. In vma_merge(), we compare prev and next policies with vmg->policy before checking can_vma_merge_after() and can_vma_merge_before() respectively, which this patch causes to be checked in precisely the same way. This therefore maintains precisely the same logic as before, only now abstracted into is_mergeable_vma(). Signed-off-by: Lorenzo Stoakes Acked-by: Vlastimil Babka Reviewed-by: Liam R. Howlett --- mm/mmap.c | 8 +++----- mm/vma.c | 9 ++++----- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 4066c0444495..c72f50feb98a 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1423,8 +1423,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, /* Attempt to expand an old mapping */ /* Check next */ - if (next && next->vm_start == end && !vma_policy(next) && - can_vma_merge_before(&vmg)) { + if (next && next->vm_start == end && can_vma_merge_before(&vmg)) { merge_end = next->vm_end; vma = next; vmg.pgoff = next->vm_pgoff - pglen; @@ -1438,8 +1437,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, } /* Check prev */ - if (prev && prev->vm_end == addr && !vma_policy(prev) && - can_vma_merge_after(&vmg)) { + if (prev && prev->vm_end == addr && can_vma_merge_after(&vmg)) { merge_start = prev->vm_start; vma = prev; vmg.pgoff = prev->vm_pgoff; @@ -1778,7 +1776,7 @@ static int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *vma, * Expand the existing vma if possible; Note that singular lists do not * occur after forking, so the expand will only happen on new VMAs. */ - if (vma && vma->vm_end == addr && !vma_policy(vma)) { + if (vma && vma->vm_end == addr) { VMG_STATE(vmg, mm, vmi, addr, addr + len, flags, PHYS_PFN(addr)); vmg.prev = vma; diff --git a/mm/vma.c b/mm/vma.c index 74c627ff0313..b1ec412fac7f 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -19,6 +19,8 @@ static inline bool is_mergeable_vma(struct vma_merge_struct *vmg, bool merge_nex */ bool may_remove_vma = merge_next; + if (!mpol_equal(vmg->policy, vma_policy(vma))) + return false; /* * VM_SOFTDIRTY should not prevent from VMA merging, if we * match the flags but dirty bit -- the caller should mark @@ -1058,17 +1060,14 @@ static struct vm_area_struct *vma_merge(struct vma_merge_struct *vmg) vma_pgoff = prev->vm_pgoff; /* Can we merge the predecessor? */ - if (addr == prev->vm_end && mpol_equal(vma_policy(prev), vmg->policy) - && can_vma_merge_after(vmg)) { - + if (addr == prev->vm_end && can_vma_merge_after(vmg)) { merge_prev = true; vma_prev(vmg->vmi); } } /* Can we merge the successor? */ - if (next && mpol_equal(vmg->policy, vma_policy(next)) && - can_vma_merge_before(vmg)) { + if (next && can_vma_merge_before(vmg)) { merge_next = true; } From patchwork Fri Aug 23 20:07:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13775913 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D751FC531DC for ; Fri, 23 Aug 2024 20:07:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1BBE4800C5; Fri, 23 Aug 2024 16:07:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 14AE0800C1; Fri, 23 Aug 2024 16:07:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D60E1800C7; Fri, 23 Aug 2024 16:07:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8F3DA800C1 for ; Fri, 23 Aug 2024 16:07:33 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 46D55120D7A for ; Fri, 23 Aug 2024 20:07:33 +0000 (UTC) X-FDA: 82484595186.29.6ABF73F Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf03.hostedemail.com (Postfix) with ESMTP id CDB5F2000C for ; Fri, 23 Aug 2024 20:07:29 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=msiUYvij; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=o2WezEGI; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf03.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724443558; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=N0jU9GfEGn2Y+Rp/ei4IM2Nkf6/N/D+Xhjwf9ZOd8E4=; b=0nWX2Y+DAs0FDSjB3hIJKonDhi+Pg78vmaEeNXgBZWE9jG74PcqGSM3Jg09/GkVF4+PDHX wQak2Kr+d8sh+F19wrgJ72QP2WaSk/d9m6VHIBqsHReARAUw7FShjfy59xnUsa0aihddFd LMj0Ag560TmrKckB8s0Liq9hJLt1Szs= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724443558; a=rsa-sha256; cv=pass; b=ZdUUfB2fbIhryYgk/icf+srb7EDu9Um15n2WvdNQdip93aTcEY3BCorXnGFKRfjmdXtVNi RUm+wzQLnlewnOQAs2Gk4isDRDciX07wiHVoZUQWxYduaKSjSofl0n1xB+Jx5pBF4WLRmu ArxYtrPJHwMY8yPXefsmq3EjzAPgwsQ= ARC-Authentication-Results: i=2; imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=msiUYvij; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=o2WezEGI; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf03.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") 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 47NH0UQB020538; Fri, 23 Aug 2024 20:07:28 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=N0jU9GfEGn2Y+Rp/ei4IM2Nkf6/N/D+Xhjwf9ZOd8E4=; b= msiUYvijmvwxBEbqsY23KDN+YkMw19/zh+r+mmhOSXitG5M2ZBV5JCbn+KEnTWMY E4QVvXxYZiNQwMThXm/t5s1ccFif3toZdhJ1W4AQsEDCrtizGlxaWQ878EWX00+H vHOFnDIPFasW+OTE8E/v3ByMGjC7cKkchM5zIx7qyU/gfkDGnpTU1fHESY1lZyI4 MFSttF9VfjyCtw556UwoPMlXGIzwFPCxAoIrZBXeA0AgIN96AzMWeJSVxpM6Ka7n 2P7a6nkq9xM2zh0RinJ2naPSuC/at8smDUWrmtl38USj9TUFhHUKVWtxQvZiONer RwrR/VvdSRlhTsi4agUJoQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412mdt56b2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:28 +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 47NJdFFg007123; Fri, 23 Aug 2024 20:07:27 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2177.outbound.protection.outlook.com [104.47.58.177]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4170s610wk-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IUfaGgJbuRgvjzWLgHXct3EPZepjBaFud6WSHjBjDgXUXBfVk84uo5zwfSGwNvx7cX7Hl1Y7gR+m8uJtIOVyGUqRihF8qAfaCr6TCwQ53FffadoJDRaw+4pCfjdcd0f4rzGS2TxCnZwKf4MyaKxODcVBshsWsy8dDUKGBiu3fVQPf88sS7+w1tcWMwhk+JS9P1MH1tA4FmlQ+CdQ/A6uow9stRESjd6x3KE4SJmg3Vcz5Uk2bWzYAIY4665AZOsadBQS++Ilt9tQk4d3aIMiIiO68EHlSLpr5oBz06Z9v8Cg3v620JQ3BTj8swgiUa2v6AtURDvJYZjR0yjSueujoA== 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=N0jU9GfEGn2Y+Rp/ei4IM2Nkf6/N/D+Xhjwf9ZOd8E4=; b=m9xYN30+WNW7GeB4JBwAN+OuHvT2FGwe2sxdTpuZbIhEjI2p5RM/2aDKNbNxUkZBR+b73el9TXt0Sfmvwgtu/WWyZkbHEes/FVPkRj/NYWuYvdzLcAt0XDUJf2VbhFyUbo6REwww6NNmNfnx/6R3QoYmdvV7p17Y2sq9pKdPq/Qb5PZOiONLZng0ROZQl4m6K0MtEkx8CiJA0UhVPM0nrvGoBWtEFaB1JHimbjyeG1ECBeFF8T6G9uIQbfv3NCmOijNTJbMcJKNqffwBh8n12r8Domk8+mTRDE45CrE77vyIeu+ixdIFW/svXA3uhz0jiXsX394lg3hd5/SkjtMTmA== 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=N0jU9GfEGn2Y+Rp/ei4IM2Nkf6/N/D+Xhjwf9ZOd8E4=; b=o2WezEGIZhG6NYQOryPd59WXZ8APzpldVR/cxdqwQXWqQHQ+yIypl+cSB7B/be7rqf3VqY3XO6siXtFm9+Otc+HFi001onDmsryRU1y+QGIf4Ctw7wUwIK5GD7uFmurqhhJfYkHwJdXarDCXd2QRiMEfJfRvh4vqUG0v2G1fFNA= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by BL3PR10MB6187.namprd10.prod.outlook.com (2603:10b6:208:3be::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.17; Fri, 23 Aug 2024 20:07:23 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%6]) with mapi id 15.20.7897.014; Fri, 23 Aug 2024 20:07:23 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH v2 05/10] mm: abstract vma_expand() to use vma_merge_struct Date: Fri, 23 Aug 2024 21:07:00 +0100 Message-ID: <0cc0e4d1af6722b3b0d121647089659bd8060087.1724441678.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0288.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:195::23) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|BL3PR10MB6187:EE_ X-MS-Office365-Filtering-Correlation-Id: 1205a18f-9ab9-43f4-7270-08dcc3af3332 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: is8c1VreVyKWLkbi2zdH4H3JVbrUx3DiOA6DaziGkRHsTwRL7D0EXygLeJ+Bu7GitrYHjwgoXQ8adgjiVGrjRCkVGhKYdOT7MtbQvZf88yPOQHzSkPvxtTkLOPFj/xPDVQ46pXI09wJU5HBWPWPUICIRsDNJTrjGWoyUagQX7zei0O4GM6kDWwhkHFwOo+sBlUXHgKx32S5mDQTEw1P1g3rDKUKmpUKAOMY80dWNIJUOX1J77GML1pWOBjfxoExxK11MxkczRG53ZuNmC9NsvK3QSgcF1ZyaqQFu1IjUTmftoRgzu1ECKtLqJP4pJ1yqM/CdQrfsyPWaKuQwJBYEZNqdhowqbjGgzftwOCIZicpRjqnBnHekwlKry8t92s/Q4766gttr5hYOYJm8Yl89Son6RUmVosZTTMcFTdAXoOAWUeP3p/OTwXjczodH/A5hqQKmN6M+1SxyFPGdWM9/EWJZeR5E1Vnx/qpGmrq+xG0eA5gPPPihQbebG3ED66R7ia0k11ebOmTlT2pvqL2LVIMR7g0S+dUNaFUXNn6cH3uVJEHpSoOw6F5Bc7HT8/wNhyuPG+ENrYv59nPLGN8sVuqmb1MHTl/ArabBra3Av4jzs+aGr2msZt8vZJPySeZaad22zreuZftK5J5DUygX2BnPpiqE6i6NrVUQnov8JnbhkIaqifJlqXvBYMzPlWhtiMucXMC4XJuuRP6Cle4eFeSjOy+EI8h6gziCDQcCs5dRiPQ/Ov+/ado6YBD/rw/fJFO4lKZoyrtec9kniN+8xbG6fIl/ObUBXIr5UjioUwpaMYarnTk2ZgSP7+fRbhDOlIyac6swcPVCyZCTiRQ+TLTntgH33fsApFrlMwTmIX444XJkLT/r3MoQxeV+L49Oi5vJDqM85xgmyGmHEyWVNifbTeUNYrTLY7HoLTkWuOSXnVr43rQsQg36AQqfjxf/u8j8j3c8BcZ9dPR8VJYVSxgWNwxvOc55wiTnJWrQVmy9aDAlrC/E2TQPWs0FHQ1EzzpDi2assPR3YBGJP5LjT/d4C7mevK2PiSoCe/gvF5EQLYmpEmuyIx08t3sawIqz3Wwf7dP7Qm0l5TAtOmTY00bliUCIevh+zzLMYldLpyMQppoSULVvc2+7DJEc5hzOsj4WeyYFJVWqWCA4sThZ88EDpEbcSWLwMgZ5u/6wZ0zIMUOHE0frPBmfJL0k0m/jXu8Na+j3n5J5sE/tIQdyDc4nrD1G9AkEx7zSTfD4xRTzhTsW+SdkQiCE1/Aa7dn8fWW1mXE916zp2Qat9heEdHKA9DVj+U/zkukWlxsmd3Mtyw+uJOr++VPD3s7i+l/aBY8ldI/EZyPICwyS1tgR2Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AAhlbtvxUFVpTsVZL8G/77ih/MwQDS0aj1dmkSvDImNcDbBhozlL2iBKtERbQ3XapPCdm+jAR+uKoEOl46BJdgApYj4vMW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gezKNpQrGRm7imPzZsqbFxYOl9o5/UF4B+FwYLLSha4lRqkSEbglOvBBESM7moCzYmeKhvoGBhBVxQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1205a18f-9ab9-43f4-7270-08dcc3af3332 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 20:07:22.7717 (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: xn6coRJbqU7E5gku93I2udU+HyjHtnG2s7e0GFHcC2zTPO39GpxhDXfIUmRDDecQCBcTG0UKi6qT8AvBV1yEmHzD4Pa4P02GeYSw8qSr8gU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR10MB6187 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-23_16,2024-08-23_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408230148 X-Proofpoint-ORIG-GUID: Oy603X3y8QiBTD0ccsaNoNTODcPmRYde X-Proofpoint-GUID: Oy603X3y8QiBTD0ccsaNoNTODcPmRYde X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: CDB5F2000C X-Stat-Signature: p8gswrbndmpzsuwbfuk53dnfacpsdjn3 X-Rspam-User: X-HE-Tag: 1724443649-334145 X-HE-Meta: U2FsdGVkX199PDXgqwJ5O/AX+BK7txS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zkLIbnmjZdCXwH3P8SMLx3cWXZx9vHvzS0ufoSCAkfKU0RbojkV9/iMJ5kwuBAme+HkkZMMTWt8eRXFj7J6lHbWE0XnD4RUjtrbeenCqGhQVOa7h1WK25veHWsZa3fUpVTMCbd6rK8mYmh7z7CP/uMx/SEvzytKwrmcG58O1Fu95InEvPm3A/sONL8bXUGBg1qnzHp0cKOj3VYcO96sH+hMTYTkGwFMffaiqnUNZ54PmZRmqmUTS3mB1QMD6nvHxZhsgWIk9E3GyCyFOypgR+uFCc+sQifHWbGos8lroHRCozP/sf/6VkS7y1smCAld+y3hWHSVjkLdAyyvvDTFUxyauYhZaZaFwTrDL+N13D7m0qjFLIBBlpnUzYRN7s2bvMEnf7wB1WpJs55pYfhdW4rOtivV/zE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The purpose of the vmg is to thread merge state through functions and avoid egregious parameter lists. We expand this to vma_expand(), which is used for a number of merge cases. Accordingly, adjust its callers, mmap_region() and relocate_vma_down(), to use a vmg. An added purpose of this change is the ability in a future commit to perform all new VMA range merging using vma_expand(). Signed-off-by: Lorenzo Stoakes Reviewed-by: Liam R. Howlett --- mm/mmap.c | 16 +++++++++------- mm/vma.c | 39 +++++++++++++++++---------------------- mm/vma.h | 5 +---- tools/testing/vma/vma.c | 3 +-- 4 files changed, 28 insertions(+), 35 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index c72f50feb98a..0d242c9b1f4c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1371,7 +1371,6 @@ unsigned long mmap_region(struct file *file, unsigned long addr, struct ma_state mas_detach; struct maple_tree mt_detach; unsigned long end = addr + len; - unsigned long merge_start = addr, merge_end = end; bool writable_file_mapping = false; int error = -ENOMEM; VMA_ITERATOR(vmi, mm, addr); @@ -1424,8 +1423,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, /* Attempt to expand an old mapping */ /* Check next */ if (next && next->vm_start == end && can_vma_merge_before(&vmg)) { - merge_end = next->vm_end; - vma = next; + vmg.end = next->vm_end; + vma = vmg.vma = next; vmg.pgoff = next->vm_pgoff - pglen; /* * We set this here so if we will merge with the previous VMA in @@ -1438,15 +1437,15 @@ unsigned long mmap_region(struct file *file, unsigned long addr, /* Check prev */ if (prev && prev->vm_end == addr && can_vma_merge_after(&vmg)) { - merge_start = prev->vm_start; - vma = prev; + vmg.start = prev->vm_start; + vma = vmg.vma = prev; vmg.pgoff = prev->vm_pgoff; vma_prev(&vmi); /* Equivalent to going to the previous range */ } if (vma) { /* Actually expand, if possible */ - if (!vma_expand(&vmi, vma, merge_start, merge_end, vmg.pgoff, next)) { + if (!vma_expand(&vmg)) { khugepaged_enter_vma(vma, vm_flags); goto expanded; } @@ -2319,6 +2318,7 @@ int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift) unsigned long new_start = old_start - shift; unsigned long new_end = old_end - shift; VMA_ITERATOR(vmi, mm, new_start); + VMG_STATE(vmg, mm, &vmi, new_start, old_end, 0, vma->vm_pgoff); struct vm_area_struct *next; struct mmu_gather tlb; @@ -2335,7 +2335,8 @@ int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift) /* * cover the whole range: [new_start, old_end) */ - if (vma_expand(&vmi, vma, new_start, old_end, vma->vm_pgoff, NULL)) + vmg.vma = vma; + if (vma_expand(&vmg)) return -ENOMEM; /* @@ -2368,6 +2369,7 @@ int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift) tlb_finish_mmu(&tlb); vma_prev(&vmi); + /* Shrink the vma to just the new range */ return vma_shrink(&vmi, vma, new_start, new_end, vma->vm_pgoff); } diff --git a/mm/vma.c b/mm/vma.c index b1ec412fac7f..4867ae722a9a 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -467,30 +467,25 @@ void validate_mm(struct mm_struct *mm) /* * vma_expand - Expand an existing VMA * - * @vmi: The vma iterator - * @vma: The vma to expand - * @start: The start of the vma - * @end: The exclusive end of the vma - * @pgoff: The page offset of vma - * @next: The current of next vma. + * @vmg: Describes a VMA expansion operation. * - * Expand @vma to @start and @end. Can expand off the start and end. Will - * expand over @next if it's different from @vma and @end == @next->vm_end. - * Checking if the @vma can expand and merge with @next needs to be handled by - * the caller. + * Expand @vma to vmg->start and vmg->end. Can expand off the start and end. + * Will expand over vmg->next if it's different from vmg->vma and vmg->end == + * vmg->next->vm_end. Checking if the vmg->vma can expand and merge with + * vmg->next needs to be handled by the caller. * * Returns: 0 on success */ -int vma_expand(struct vma_iterator *vmi, struct vm_area_struct *vma, - unsigned long start, unsigned long end, pgoff_t pgoff, - struct vm_area_struct *next) +int vma_expand(struct vma_merge_struct *vmg) { struct vm_area_struct *anon_dup = NULL; bool remove_next = false; + struct vm_area_struct *vma = vmg->vma; + struct vm_area_struct *next = vmg->next; struct vma_prepare vp; vma_start_write(vma); - if (next && (vma != next) && (end == next->vm_end)) { + if (next && (vma != next) && (vmg->end == next->vm_end)) { int ret; remove_next = true; @@ -503,21 +498,21 @@ int vma_expand(struct vma_iterator *vmi, struct vm_area_struct *vma, init_multi_vma_prep(&vp, vma, NULL, remove_next ? next : NULL, NULL); /* Not merging but overwriting any part of next is not handled. */ VM_WARN_ON(next && !vp.remove && - next != vma && end > next->vm_start); + next != vma && vmg->end > next->vm_start); /* Only handles expanding */ - VM_WARN_ON(vma->vm_start < start || vma->vm_end > end); + VM_WARN_ON(vma->vm_start < vmg->start || vma->vm_end > vmg->end); /* Note: vma iterator must be pointing to 'start' */ - vma_iter_config(vmi, start, end); - if (vma_iter_prealloc(vmi, vma)) + vma_iter_config(vmg->vmi, vmg->start, vmg->end); + if (vma_iter_prealloc(vmg->vmi, vma)) goto nomem; vma_prepare(&vp); - vma_adjust_trans_huge(vma, start, end, 0); - vma_set_range(vma, start, end, pgoff); - vma_iter_store(vmi, vma); + vma_adjust_trans_huge(vma, vmg->start, vmg->end, 0); + vma_set_range(vma, vmg->start, vmg->end, vmg->pgoff); + vma_iter_store(vmg->vmi, vma); - vma_complete(&vp, vmi, vma->vm_mm); + vma_complete(&vp, vmg->vmi, vma->vm_mm); return 0; nomem: diff --git a/mm/vma.h b/mm/vma.h index 9060a1a1edfa..8f01fbc20fe7 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -128,10 +128,7 @@ void init_vma_prep(struct vma_prepare *vp, void vma_complete(struct vma_prepare *vp, struct vma_iterator *vmi, struct mm_struct *mm); -int vma_expand(struct vma_iterator *vmi, struct vm_area_struct *vma, - unsigned long start, unsigned long end, pgoff_t pgoff, - struct vm_area_struct *next); - +int vma_expand(struct vma_merge_struct *vmg); int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma, unsigned long start, unsigned long end, pgoff_t pgoff); diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index b12f72979478..cce1ba78c57f 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -121,8 +121,7 @@ static struct vm_area_struct *merge_existing(struct vma_merge_struct *vmg) */ static int expand_existing(struct vma_merge_struct *vmg) { - return vma_expand(vmg->vmi, vmg->vma, vmg->start, vmg->end, vmg->pgoff, - vmg->next); + return vma_expand(vmg); } /* From patchwork Fri Aug 23 20:07:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13775925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 003A9C5321D for ; Fri, 23 Aug 2024 20:07:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14EF7800C9; Fri, 23 Aug 2024 16:07:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 08565800C8; Fri, 23 Aug 2024 16:07:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0638800C7; Fri, 23 Aug 2024 16:07:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id AA151800C1 for ; Fri, 23 Aug 2024 16:07:42 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5DC2B41FD8 for ; Fri, 23 Aug 2024 20:07:42 +0000 (UTC) X-FDA: 82484595564.18.428FAAE Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf10.hostedemail.com (Postfix) with ESMTP id 0ED18C0021 for ; Fri, 23 Aug 2024 20:07:38 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="laMt5Hp/"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=ROL22bGY; spf=pass (imf10.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724443549; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=goF2lUyd/6o9YQa0vbk2oC9TN0OOiZB8fM+8ZD/mB7c=; b=mKK4SW55qEkd2uTXIly9Qh3tfI8gZz+7TESEXIv4Pc7qlB0mFL0xy55KG0+3Tdn2+z95Ff VgSx/WNg0IwnYFNfmxbobdgDum2ffbIdoAqPz1YRUg7myAxdSfclAtR7bJIkgqVr1p61Iy Pi8v/cDzmgJcnxv2JRMPZxv/EeYNAk4= ARC-Authentication-Results: i=2; imf10.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="laMt5Hp/"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=ROL22bGY; spf=pass (imf10.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724443549; a=rsa-sha256; cv=pass; b=f0PyoTApEl97XvDEIL2ctfvxi2+SqJpGwharOSDX4e9mPgYYMQscUBs/VvRUk7NX4zUK0K D8CdN0KCeKLAVdNSCFOl5ISS2Ig6VMfCvLQxARjuMfPBfVeGct8lisG/4jI+KVPVHWAjAZ EcBl9OqpDydTuAlLUzhSQ2F0Omzz8+k= Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47NH0VVj023941; Fri, 23 Aug 2024 20:07:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=goF2lUyd/6o9YQa0vbk2oC9TN0OOiZB8fM+8ZD/mB7c=; b= laMt5Hp/E59pch8Xrx4KbaUiIayFOql6QnsPA/BhR0CY/fReoBOn29dj5TLE/Qly nhWjQCHfQ6ZCfNiaicPb9FMJapeOfbqf6zSilMFNNY6eU7HcOvUWu1X5Sx5dNX7a sw2ZHLUOKCPjVSucjW1CzgFpXgflIkqfN35WS1GBfhyG6+MJKj3nx1XRIZ50hc9V VlwpFc950RDJcFPeiGkgrXBclXucm+0hcHr7g788S5DDjUiq7/+C/fl7voL4WSHH AFgJszs+uEaDNKfuyHAEq5IUsyvjpIq6klxxpeqSDFC8ePF6RfXMJWzYiKWNDjjO JDfwgBqGimqViu67P7Ik0A== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412m6gn7jd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:37 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 47NJdCpW007466; Fri, 23 Aug 2024 20:07:36 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2173.outbound.protection.outlook.com [104.47.57.173]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4170s5gxw2-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ajLW04s3SZ+X4mMd+KvB0dzbUtLX2ZtACDy5Js7zi+FLI7kT20Dw48rGEwtQTwz4fadMKen0w0gKWHB6luXdlKU57LeF1i26jMZdi0cUkkVBmSd0wOEx+Vn8qNQ/qe7u+M+Bj4qE1iyazyGctACHaFUWc9zMhkL0DC6jjHZUTtnklQpSxzvsKxGvHYxDVlLagnwKNcK+0Nrb/1ZN/WUfsZ5eLUjpR+xhQr/uDTtn+ZpIGZF1L+jWjWA4bhTQqNi0a9wubhp3UfGRqhdfrY/dunSkNDa99L+0hER9U/VfuFCv4xAJKN2MdKBDVEtT7F4onS63JTP++9TXiceHwsgNXA== 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=goF2lUyd/6o9YQa0vbk2oC9TN0OOiZB8fM+8ZD/mB7c=; b=VZt4XGE9uDOvwvNrOvLa5a1InIb3hKH5jKIvkqJQg2m5zt5Q1hZkIXCfWMQeHV4Nr1N4l083rz1vsmgwA9QBz4QmxT6Ezz+1RJE0vvW743vIWHauy4dZypFTqibElWSlw9lUi8BRlBRLs98UxGHL8UrbL9zj3MIniKJRnJ1tecC5JadUvQBAYVIZFGSLM3Vm0ByJWlPhMPHzu+EeJ51TQCWbeEWKRLHM+10mZxn/iZ3826jmMK4ia3ZgCn6iDrA4z4cl2gKUVGmqIBivlfNJ89qL6ljtjwyht/UOKVQGOWjapCg+PP0UutqDluDQqS6721qFod2tqYKC94nS4jsITw== 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=goF2lUyd/6o9YQa0vbk2oC9TN0OOiZB8fM+8ZD/mB7c=; b=ROL22bGYMOV98hRf3OENg/WsT+Fs+3jCLdKVMKMSF5HdFjupxE2ZMgwG2L6Xa13j8p8pgmroU0EkGxuivZJ8bRrOGBdtw4oVNIL/77GxvG6DX80Exq4q4GAytdkoWMOFOzvvr+Hab8YchLQ/cJ3Zdb4hWv3IDxFPM9yJmS/gp8k= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by BL3PR10MB6187.namprd10.prod.outlook.com (2603:10b6:208:3be::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.17; Fri, 23 Aug 2024 20:07:25 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%6]) with mapi id 15.20.7897.014; Fri, 23 Aug 2024 20:07:25 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH v2 06/10] mm: avoid using vma_merge() for new VMAs Date: Fri, 23 Aug 2024 21:07:01 +0100 Message-ID: <57f55a1473586a88211e04b44c6b128332d4272c.1724441678.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0149.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::17) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|BL3PR10MB6187:EE_ X-MS-Office365-Filtering-Correlation-Id: 1a803a30-0a96-4079-31f9-08dcc3af34d1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: WRTfZFnvGThwfMBkAtCy7hPGRVj9DrlCHRdAPiGB1hSKTGUxvhDAFrb41ZMlcEZAeE1iGLiXgqmtbGfHFGClHI3o+ydbHUtPOERFhZ0D+JMd2VFxT3uk+f4UXnZ8lBjvmV84dkXCHZXVU86ZGtuhGq6RjieZBprm7kcYrkAcalFPiJBT27yYDMSTmflVZj8e6+KdcwzNlpPvRTRcMl0iMhPupBLsiiI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YIc3V8zEWrizEW5igGPv/cbtuVMKR4KWR6g79t6zclrVkOUY4FlhKpE8Tks1QFRq3g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YaZaup5SJQYf3DAqKq0VglKG1wQpvvqli1JsiZpRdY0UDs8JfX0RF4b7KKyj1JQDZLJsTSbBEkxgCFphojQkFsUCuAZdug50pNH597GxMfhPR6rTKBncARyKgkUmHTcYDKfd3i0c/hllOE/vPcNGoBT5FqR+Ydi3/XvgQNRPLvx2Inm2ezeK/1dWrm/35zcQyYsQIqRt21rD2wQ+FR7GvRFGONABlvWY5F4efiIp4LsRZ1j/YwYJKh4K7gEXRpWXPSiNh+GhnjxD/RymQIVYz47NcGDuTsnUXOU+9F9V45YxYtYRpt+DXWbikvnGwk7u5oRN+s1oxD5cAJrGn68iOJXJKlU/Ji8YvVxNYSe+gYRLzwd8FO0Lz/do6wF1zLuiY8emPnfHxn9K8jT/Xeaaj8QBVKbQ3R+K7/ckdYwHB1l00FG/LL3BRJrA1Wvh1MLEYC+sQroR9KiPKoXpBHXz9hI+tteaxurBpSUkrdQSOHiOZ+4tyqYc+wsDcEjkvHd93u8W6FroZ/jVVHheXPYkMoVf34m75FQ4J3FR/iIkLzR9wqElh0KVqVQd872PCYmNkcVByDGnbFXCAumVqPfn9jK4ykTVTO/x3hUs4FpHDFyEASof+4d+gAqG2aIT6k+NnvIgClmfqTixXOQxREqV/IMuTLH9Xd1wo++asMsq50xS2Nbf90U7VI/DcbI22pe+WAqBqJ2VT7RB6Rq7VaTSxKZGtEu3RhK5ZkdtIsds1eUCMHEu3gR6/I7XnAPnfGFE9hnsCCR1uKlj/sGU0ORmychMLEl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JS8tdcX3iRZgaLD55pn37i+73mtAv9eNLPj2gvKnNfJ2WtWQH6Vz1AQ+wifqwxF3NaktWOv/J6hQ+1fyD2+kG/G8HQx3h9abYlwF63OaEMxP5An+tG1Vf2RL8pOLQJI0XrOfS5N+gx0DJvXmXa5zlOanqfFnvEG3i2CbCIOyG/VDOMnV9oek/9HMnAK73bk8b3JkkFp4YYT0pqMDsM3GtFywucv0efDWNA4pro8/CBR5xLjv+HnouJ91dtj8SPObSITZG8GUdLouRWon4x+1ZPw5mZMpX/Axc+ZBfXIdzVcytcqIlzmOy5aErB5ULrz9Tgh1QiXoa1kzENwP6DKZAc+rdIeQ5do4KhYm1lmDtT7pprAmx7tCxM19u1mKlDiOW0AvXDGQjKEUJ0lG9zTTno8VlERpsxkvVkEdCokTsw3Qrv8DrspYlFCY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a803a30-0a96-4079-31f9-08dcc3af34d1 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 20:07:25.4836 (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: fXvgw5Q8P02+Fx5mtBBgnavgl3J16ODcZDpIc/qDCrdNAUje3XeuCH4kZX11VAiGMa/CUpRoSduBb0/E2Fw8OhrEhQakXZwr8tKCQiCIpnM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR10MB6187 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-23_16,2024-08-23_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408230148 X-Proofpoint-ORIG-GUID: V6v47r33P2OX54NTnyo_0sQsDkJMwt63 X-Proofpoint-GUID: V6v47r33P2OX54NTnyo_0sQsDkJMwt63 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 0ED18C0021 X-Stat-Signature: b4eux3y7wfw9z8gtwoiaf8xhp78fipet X-Rspam-User: X-HE-Tag: 1724443658-951150 X-HE-Meta: U2FsdGVkX19/Uo5u2YoFkMxGgV3t9tiwKDIgiyuV00AwuBe01niL4FFaMJQpq5fhsImNjr19ix3P5RUDLmFhV+oecxBnAHcUrGltShfhQ+gdckT6RCRKOn9UInKirwHLn9AiXuZdQr6i2/35IFt6r3h9t7XX0oi1UErf9Gq755yUACBhWIJ0onMjyzh23UUoUAS/NQhXy5ebUBOtQ4Bue+ZMW3d45JHDlIzgeMHwpPhLl977nXMOX5i7XLKHiRsHJVP/yItKxEelIwjvlu8fOt51IMTI63Xo6Kbra1Cfp9584fF6BXFmAojfPyCpIpyKppjgqnVirOnYcmNUPes2bWG0dG5f2q/gvAI++cgwiBgkR0W4J0bOd5gmshDYoelzlQIxUYvTF49+HTMaOU0rSkLIUj2JvR/LkiVwxsQzKBNcgDPPxzMQZzmZOyieXxsdV7KJ5nqn0buVmnGAdA7hJN2aTjN5Rzc857l9bJ9IPs4A7nr+LEYMHDKLtVPlzuzrm77TBZ5ua4pQOU0g2HjL2wz1Vj8RwsmrE+IehgyMywT5Zfqw5M+6QqM1kMrlg6m20pabXjv15bGIt2+H1LpGimEr7phoBiqFjCr2ewsSKNUt2S3gU7aTM2vwzJ2vO4PTD6QDiUftUN6xzVzd5grMmwF8xAnmUo7SkgxZ0QgkiMVosXHrzOVoH3GkK2KeAiJyMSSWBCjMwylEwzfj9O5/8ZTC3eJuoVliXtPP8fcEfOQC+wwvZFg6yzz19GVZQDXiAoI5ZrJhDCIS1n0DwGTDqOBYQ9VdvQZbAuvzmgG8sdNEfRiko8o1fJ4g6h5p0OTEgikHu3c3EveIrpKxafGQd3ywitaWan2qFyEchiDQE6dai4XvByD+3i6Pt3+DGoQK6HlHyQoQB9Sf6OAVzxedOH5Jx5qJSuBT4kLN72BTz6nV1B1jo9h6/WVHIvsfvYsSzvmM+roNCUGseA9Dsk1 CdYdgQbV QFHdOqotD/Vqn74fkXLgJIBUAZ8bXxAojLlRe6tmusvuJ1wEoYukXLkRSXe432p72CA67mK1pRJIWzTw9/KgkmPNVmReRHEmc1efMT0qt3JevLi+WiYdel8YSXKgKkU+kRHVi71XOqWcwNGFxiRtChUtmq1u3fBPtsNuxyFCucuiU0Am+om3Dqj/4Gg9HhlVVOoIqnqH8YG8KB//WN90Gay6Vm8utN3I7J69femT2axuqf+htnFWnFW3Hb7MWQimH0/EO6PFmPgYjzUa/hi7qqH3mCaZ3TxbJXjOX/pwO0rbELwa/xX6PdjrrWKbRy8pU+s4xAigfp169nsWzluxpOiH0VBFzWF7C78AuiApRUVOIJXWAg8iVa5xMP/X8cD2pKC/lPWBHuQzV0dsbz97xfpLKvhPqDmN/uXSMBHu6xR7F1InBlDgzTx8kT7NDWwLiArddvuxgNSfnFsn3E36RUGn+hw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Abstract vma_merge_new_vma() to use vma_merge_struct and rename the resultant function vma_merge_new_range() to be clear what the purpose of this function is - a new VMA is desired in the specified range, and we wish to see if it is possible to 'merge' surrounding VMAs into this range rather than having to allocate a new VMA. Note that this function uses vma_extend() exclusively, so adopts its requirement that the iterator point at or before the gap. We add an assert to this effect. This is as opposed to vma_merge_existing_range(), which will be introduced in a subsequent commit, and provide the same functionality for cases in which we are modifying an existing VMA. In mmap_region() and do_brk_flags() we open code scenarios where we prefer to use vma_expand() rather than invoke a full vma_merge() operation. Abstract this logic and eliminate all of the open-coding, and also use the same logic for all cases where we add new VMAs to, rather than ultimately use vma_merge(), rather use vma_expand(). Doing so removes duplication and simplifies VMA merging in all such cases, laying the ground for us to eliminate the merging of new VMAs in vma_merge() altogether. Also add the ability for the vmg to track state, and able to report errors, allowing for us to differentiate a failed merge from an inability to allocate memory in callers. This makes it far easier to understand what is happening in these cases avoiding confusion, bugs and allowing for future optimisation. Signed-off-by: Lorenzo Stoakes Reported-by: kernel test robot Signed-off-by: Lorenzo Stoakes Signed-off-by: Lorenzo Stoakes Reported-by: Mark Brown Tested-by: Mark Brown --- mm/mmap.c | 93 +++++------------- mm/vma.c | 162 ++++++++++++++++++++++++++----- mm/vma.h | 20 +++- tools/testing/vma/vma.c | 33 ++++++- tools/testing/vma/vma_internal.h | 6 ++ 5 files changed, 216 insertions(+), 98 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 0d242c9b1f4c..80d70ed099cf 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1364,8 +1364,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, { struct mm_struct *mm = current->mm; struct vm_area_struct *vma = NULL; - struct vm_area_struct *next, *prev, *merge; pgoff_t pglen = PHYS_PFN(len); + struct vm_area_struct *merge; unsigned long charged = 0; struct vma_munmap_struct vms; struct ma_state mas_detach; @@ -1389,13 +1389,13 @@ unsigned long mmap_region(struct file *file, unsigned long addr, if (vms_gather_munmap_vmas(&vms, &mas_detach)) return -ENOMEM; - next = vmg.next = vms.next; - prev = vmg.prev = vms.prev; + vmg.next = vms.next; + vmg.prev = vms.prev; vma = NULL; } else { - next = vmg.next = vma_next(&vmi); - prev = vmg.prev = vma_prev(&vmi); - if (prev) + vmg.next = vma_next(&vmi); + vmg.prev = vma_prev(&vmi); + if (vmg.prev) vma_iter_next_range(&vmi); } @@ -1417,45 +1417,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vmg.flags = vm_flags; } - if (vm_flags & VM_SPECIAL) - goto cannot_expand; - - /* Attempt to expand an old mapping */ - /* Check next */ - if (next && next->vm_start == end && can_vma_merge_before(&vmg)) { - vmg.end = next->vm_end; - vma = vmg.vma = next; - vmg.pgoff = next->vm_pgoff - pglen; - /* - * We set this here so if we will merge with the previous VMA in - * the code below, can_vma_merge_after() ensures anon_vma - * compatibility between prev and next. - */ - vmg.anon_vma = vma->anon_vma; - vmg.uffd_ctx = vma->vm_userfaultfd_ctx; - } - - /* Check prev */ - if (prev && prev->vm_end == addr && can_vma_merge_after(&vmg)) { - vmg.start = prev->vm_start; - vma = vmg.vma = prev; - vmg.pgoff = prev->vm_pgoff; - vma_prev(&vmi); /* Equivalent to going to the previous range */ - } - - if (vma) { - /* Actually expand, if possible */ - if (!vma_expand(&vmg)) { - khugepaged_enter_vma(vma, vm_flags); - goto expanded; - } - - /* If the expand fails, then reposition the vma iterator */ - if (unlikely(vma == prev)) - vma_iter_set(&vmi, addr); - } - -cannot_expand: + vma = vma_merge_new_range(&vmg); + if (vma) + goto expanded; /* * Determine the object being mapped and call the appropriate @@ -1503,10 +1467,11 @@ unsigned long mmap_region(struct file *file, unsigned long addr, * If vm_flags changed after call_mmap(), we should try merge * vma again as we may succeed this time. */ - if (unlikely(vm_flags != vma->vm_flags && prev)) { - merge = vma_merge_new_vma(&vmi, prev, vma, - vma->vm_start, vma->vm_end, - vma->vm_pgoff); + if (unlikely(vm_flags != vma->vm_flags && vmg.prev)) { + vmg.flags = vma->vm_flags; + /* If this fails, state is reset ready for a reattempt. */ + merge = vma_merge_new_range(&vmg); + if (merge) { /* * ->mmap() can change vma->vm_file and fput @@ -1521,6 +1486,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, /* Update vm_flags to pick up the change. */ vm_flags = vma->vm_flags; goto unmap_writable; + } else { + vma_iter_config(&vmi, addr, end); } } @@ -1554,7 +1521,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma_link_file(vma); /* - * vma_merge() calls khugepaged_enter_vma() either, the below + * vma_merge_new_range() calls khugepaged_enter_vma() too, the below * call covers the non-merge case. */ khugepaged_enter_vma(vma, vma->vm_flags); @@ -1609,7 +1576,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma_iter_set(&vmi, vma->vm_end); /* Undo any partial mapping done by a device driver. */ - unmap_region(&vmi.mas, vma, prev, next); + unmap_region(&vmi.mas, vma, vmg.prev, vmg.next); } if (writable_file_mapping) mapping_unmap_writable(file->f_mapping); @@ -1755,7 +1722,6 @@ static int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long flags) { struct mm_struct *mm = current->mm; - struct vma_prepare vp; /* * Check against address space limits by the changed size @@ -1779,25 +1745,12 @@ static int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *vma, VMG_STATE(vmg, mm, vmi, addr, addr + len, flags, PHYS_PFN(addr)); vmg.prev = vma; - if (can_vma_merge_after(&vmg)) { - vma_iter_config(vmi, vma->vm_start, addr + len); - if (vma_iter_prealloc(vmi, vma)) - goto unacct_fail; - - vma_start_write(vma); - - init_vma_prep(&vp, vma); - vma_prepare(&vp); - vma_adjust_trans_huge(vma, vma->vm_start, addr + len, 0); - vma->vm_end = addr + len; - vm_flags_set(vma, VM_SOFTDIRTY); - vma_iter_store(vmi, vma); - - vma_complete(&vp, vmi, mm); - validate_mm(mm); - khugepaged_enter_vma(vma, flags); + vma_iter_next_range(vmi); + + if (vma_merge_new_range(&vmg)) goto out; - } + else if (vmg_nomem(&vmg)) + goto unacct_fail; } if (vma) diff --git a/mm/vma.c b/mm/vma.c index 4867ae722a9a..8a5fa15f46a2 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -464,6 +464,116 @@ void validate_mm(struct mm_struct *mm) } #endif /* CONFIG_DEBUG_VM_MAPLE_TREE */ +/* + * vma_merge_new_range - Attempt to merge a new VMA into address space + * + * @vmg: Describes the VMA we are adding, in the range @vmg->start to @vmg->end + * (exclusive), which we try to merge with any adjacent VMAs if possible. + * + * We are about to add a VMA to the address space starting at @vmg->start and + * ending at @vmg->end. There are three different possible scenarios: + * + * 1. There is a VMA with identical properties immediately adjacent to the + * proposed new VMA [@vmg->start, @vmg->end) either before or after it - + * EXPAND that VMA: + * + * Proposed: |-----| or |-----| + * Existing: |----| |----| + * + * 2. There are VMAs with identical properties immediately adjacent to the + * proposed new VMA [@vmg->start, @vmg->end) both before AND after it - + * EXPAND the former and REMOVE the latter: + * + * Proposed: |-----| + * Existing: |----| |----| + * + * 3. There are no VMAs immediately adjacent to the proposed new VMA or those + * VMAs do not have identical attributes - NO MERGE POSSIBLE. + * + * In instances where we can merge, this function returns the expanded VMA which + * will have its range adjusted accordingly and the underlying maple tree also + * adjusted. + * + * Returns: In instances where no merge was possible, NULL. Otherwise, a pointer + * to the VMA we expanded. + * + * This function adjusts @vmg to provide @vmg->next if not already specified, + * and adjusts [@vmg->start, @vmg->end) to span the expanded range. + * + * ASSUMPTIONS: + * - The caller must hold a WRITE lock on the mm_struct->mmap_lock. + * - The caller must have determined that [@vmg->start, @vmg->end) is empty, + other than VMAs that will be unmapped should the operation succeed. + * - The caller must have specified the previous vma in @vmg->prev. + * - The caller must have specified the next vma in @vmg->next. + * - The caller must have positioned the vmi at or before the gap. + */ +struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) +{ + struct vm_area_struct *prev = vmg->prev; + struct vm_area_struct *next = vmg->next; + unsigned long start = vmg->start; + unsigned long end = vmg->end; + pgoff_t pgoff = vmg->pgoff; + pgoff_t pglen = PHYS_PFN(end - start); + bool can_merge_before, can_merge_after; + + mmap_assert_write_locked(vmg->mm); + VM_WARN_ON(vmg->vma); + /* vmi must point at or before the gap. */ + VM_WARN_ON(vma_iter_addr(vmg->vmi) > end); + + vmg->state = VMA_MERGE_NOMERGE; + + /* Special VMAs are unmergeable, also if no prev/next. */ + if ((vmg->flags & VM_SPECIAL) || (!prev && !next)) + return NULL; + + can_merge_before = next && next->vm_start == end && + can_vma_merge_before(vmg); + can_merge_after = prev && prev->vm_end == start && + can_vma_merge_after(vmg); + + /* If we can merge with the next VMA, adjust vmg accordingly. */ + if (can_merge_before && + (!can_merge_after || is_mergeable_anon_vma(prev->anon_vma, + next->anon_vma, NULL))) { + vmg->end = next->vm_end; + vmg->vma = next; + vmg->pgoff = next->vm_pgoff - pglen; + } + + /* If we can merge with the previous VMA, adjust vmg accordingly. */ + if (can_merge_after) { + vmg->start = prev->vm_start; + vmg->vma = prev; + vmg->pgoff = prev->vm_pgoff; + + vma_prev(vmg->vmi); /* Equivalent to going to the previous range */ + } + + /* + * Now try to expand adjacent VMA(s). This takes care of removing the + * following VMA if we have VMAs on both sides. + */ + if (vmg->vma && !vma_expand(vmg)) { + khugepaged_enter_vma(vmg->vma, vmg->flags); + + vmg->state = VMA_MERGE_SUCCESS; + return vmg->vma; + } + + /* If expansion failed, reset state. Allows us to retry merge later. */ + vmg->vma = NULL; + vmg->start = start; + vmg->end = end; + vmg->pgoff = pgoff; + if (vmg->vma == prev) + vma_iter_set(vmg->vmi, start); + + return NULL; +} + /* * vma_expand - Expand an existing VMA * @@ -474,7 +584,11 @@ void validate_mm(struct mm_struct *mm) * vmg->next->vm_end. Checking if the vmg->vma can expand and merge with * vmg->next needs to be handled by the caller. * - * Returns: 0 on success + * Returns: 0 on success. + * + * ASSUMPTIONS: + * - The caller must hold a WRITE lock on vmg->vma->mm->mmap_lock. + * - The caller must have set @vmg->vma and @vmg->next. */ int vma_expand(struct vma_merge_struct *vmg) { @@ -484,6 +598,8 @@ int vma_expand(struct vma_merge_struct *vmg) struct vm_area_struct *next = vmg->next; struct vma_prepare vp; + mmap_assert_write_locked(vmg->mm); + vma_start_write(vma); if (next && (vma != next) && (vmg->end == next->vm_end)) { int ret; @@ -516,6 +632,7 @@ int vma_expand(struct vma_merge_struct *vmg) return 0; nomem: + vmg->state = VMA_MERGE_ERROR_NOMEM; if (anon_dup) unlink_anon_vmas(anon_dup); return -ENOMEM; @@ -1034,6 +1151,8 @@ static struct vm_area_struct *vma_merge(struct vma_merge_struct *vmg) pgoff_t pglen = PHYS_PFN(end - addr); long adj_start = 0; + vmg->state = VMA_MERGE_NOMERGE; + /* * We later require that vma->vm_flags == vm_flags, * so this tests vma->vm_flags & VM_SPECIAL, too. @@ -1185,13 +1304,19 @@ static struct vm_area_struct *vma_merge(struct vma_merge_struct *vmg) vma_complete(&vp, vmg->vmi, mm); validate_mm(mm); khugepaged_enter_vma(res, vmg->flags); + + vmg->state = VMA_MERGE_SUCCESS; return res; prealloc_fail: + vmg->state = VMA_MERGE_ERROR_NOMEM; if (anon_dup) unlink_anon_vmas(anon_dup); anon_vma_fail: + if (err == -ENOMEM) + vmg->state = VMA_MERGE_ERROR_NOMEM; + vma_iter_set(vmg->vmi, addr); vma_iter_load(vmg->vmi); return NULL; @@ -1298,22 +1423,6 @@ struct vm_area_struct return vma_modify(&vmg); } -/* - * Attempt to merge a newly mapped VMA with those adjacent to it. The caller - * must ensure that [start, end) does not overlap any existing VMA. - */ -struct vm_area_struct -*vma_merge_new_vma(struct vma_iterator *vmi, struct vm_area_struct *prev, - struct vm_area_struct *vma, unsigned long start, - unsigned long end, pgoff_t pgoff) -{ - VMG_VMA_STATE(vmg, vmi, prev, vma, start, end); - - vmg.pgoff = pgoff; - - return vma_merge(&vmg); -} - /* * Expand vma by delta bytes, potentially merging with an immediately adjacent * VMA with identical properties. @@ -1324,8 +1433,9 @@ struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, { VMG_VMA_STATE(vmg, vmi, vma, vma, vma->vm_end, vma->vm_end + delta); - /* vma is specified as prev, so case 1 or 2 will apply. */ - return vma_merge(&vmg); + /* We use the VMA to populate VMG fields only. */ + vmg.vma = NULL; + return vma_merge_new_range(&vmg); } void unlink_file_vma_batch_init(struct unlink_vma_file_batch *vb) @@ -1426,9 +1536,10 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, struct vm_area_struct *vma = *vmap; unsigned long vma_start = vma->vm_start; struct mm_struct *mm = vma->vm_mm; - struct vm_area_struct *new_vma, *prev; + struct vm_area_struct *new_vma; bool faulted_in_anon_vma = true; VMA_ITERATOR(vmi, mm, addr); + VMG_VMA_STATE(vmg, &vmi, NULL, vma, addr, addr + len); /* * If anonymous vma has not yet been faulted, update new pgoff @@ -1439,11 +1550,18 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, faulted_in_anon_vma = false; } - new_vma = find_vma_prev(mm, addr, &prev); + new_vma = find_vma_prev(mm, addr, &vmg.prev); if (new_vma && new_vma->vm_start < addr + len) return NULL; /* should never get here */ - new_vma = vma_merge_new_vma(&vmi, prev, vma, addr, addr + len, pgoff); + vmg.vma = NULL; /* New VMA range. */ + vmg.pgoff = pgoff; + vmg.next = vma_next(&vmi); + vma_prev(&vmi); + vma_iter_next_range(&vmi); + + new_vma = vma_merge_new_range(&vmg); + if (new_vma) { /* * Source vma may have been merged into new_vma diff --git a/mm/vma.h b/mm/vma.h index 8f01fbc20fe7..dbcdf1431014 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -52,6 +52,13 @@ struct vma_munmap_struct { unsigned long data_vm; }; +enum vma_merge_state { + VMA_MERGE_START, + VMA_MERGE_ERROR_NOMEM, + VMA_MERGE_NOMERGE, + VMA_MERGE_SUCCESS, +}; + /* Represents a VMA merge operation. */ struct vma_merge_struct { struct mm_struct *mm; @@ -68,8 +75,14 @@ struct vma_merge_struct { struct mempolicy *policy; struct vm_userfaultfd_ctx uffd_ctx; struct anon_vma_name *anon_name; + enum vma_merge_state state; }; +static inline bool vmg_nomem(struct vma_merge_struct *vmg) +{ + return vmg->state == VMA_MERGE_ERROR_NOMEM; +} + /* Assumes addr >= vma->vm_start. */ static inline pgoff_t vma_pgoff_offset(struct vm_area_struct *vma, unsigned long addr) @@ -85,6 +98,7 @@ static inline pgoff_t vma_pgoff_offset(struct vm_area_struct *vma, .end = end_, \ .flags = flags_, \ .pgoff = pgoff_, \ + .state = VMA_MERGE_START, \ } #define VMG_VMA_STATE(name, vmi_, prev_, vma_, start_, end_) \ @@ -103,6 +117,7 @@ static inline pgoff_t vma_pgoff_offset(struct vm_area_struct *vma, .policy = vma_policy(vma_), \ .uffd_ctx = vma_->vm_userfaultfd_ctx, \ .anon_name = anon_vma_name(vma_), \ + .state = VMA_MERGE_START, \ } #ifdef CONFIG_DEBUG_VM_MAPLE_TREE @@ -306,10 +321,7 @@ struct vm_area_struct unsigned long new_flags, struct vm_userfaultfd_ctx new_ctx); -struct vm_area_struct -*vma_merge_new_vma(struct vma_iterator *vmi, struct vm_area_struct *prev, - struct vm_area_struct *vma, unsigned long start, - unsigned long end, pgoff_t pgoff); +struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg); struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, struct vm_area_struct *vma, diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index cce1ba78c57f..3a3a850d951c 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -101,9 +101,9 @@ static struct vm_area_struct *merge_new(struct vma_merge_struct *vmg) */ vmg->next = vma_next(vmg->vmi); vmg->prev = vma_prev(vmg->vmi); + vma_iter_next_range(vmg->vmi); - vma_iter_set(vmg->vmi, vmg->start); - return vma_merge(vmg); + return vma_merge_new_range(vmg); } /* @@ -162,10 +162,14 @@ static struct vm_area_struct *try_merge_new_vma(struct mm_struct *mm, merged = merge_new(vmg); if (merged) { *was_merged = true; + ASSERT_EQ(vmg->state, VMA_MERGE_SUCCESS); return merged; } *was_merged = false; + + ASSERT_EQ(vmg->state, VMA_MERGE_NOMERGE); + return alloc_and_link_vma(mm, start, end, pgoff, flags); } @@ -595,6 +599,7 @@ static bool test_vma_merge_special_flags(void) vmg.flags = flags | special_flag; vma = merge_new(&vmg); ASSERT_EQ(vma, NULL); + ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); } /* 2. Modify VMA with special flag that would otherwise merge. */ @@ -616,6 +621,7 @@ static bool test_vma_merge_special_flags(void) vmg.flags = flags | special_flag; vma = merge_existing(&vmg); ASSERT_EQ(vma, NULL); + ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); } cleanup_mm(&mm, &vmi); @@ -708,6 +714,7 @@ static bool test_vma_merge_with_close(void) /* The next VMA having a close() operator should cause the merge to fail.*/ ASSERT_EQ(merge_new(&vmg), NULL); + ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); /* Now create the VMA so we can merge via modified flags */ vmg_set_range(&vmg, 0x1000, 0x2000, 1, flags); @@ -719,6 +726,7 @@ static bool test_vma_merge_with_close(void) * also fail. */ ASSERT_EQ(merge_existing(&vmg), NULL); + ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); /* SCENARIO B * @@ -744,6 +752,7 @@ static bool test_vma_merge_with_close(void) vmg.vma = vma; /* Make sure merge does not occur. */ ASSERT_EQ(merge_existing(&vmg), NULL); + ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); cleanup_mm(&mm, &vmi); return true; @@ -792,6 +801,7 @@ static bool test_vma_merge_new_with_close(void) vmg_set_range(&vmg, 0x2000, 0x5000, 2, flags); vma = merge_new(&vmg); ASSERT_NE(vma, NULL); + ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); ASSERT_EQ(vma->vm_start, 0); ASSERT_EQ(vma->vm_end, 0x5000); ASSERT_EQ(vma->vm_pgoff, 0); @@ -831,6 +841,7 @@ static bool test_merge_existing(void) vmg.prev = vma; vma->anon_vma = &dummy_anon_vma; ASSERT_EQ(merge_existing(&vmg), vma_next); + ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); ASSERT_EQ(vma_next->vm_start, 0x3000); ASSERT_EQ(vma_next->vm_end, 0x9000); ASSERT_EQ(vma_next->vm_pgoff, 3); @@ -861,6 +872,7 @@ static bool test_merge_existing(void) vmg.vma = vma; vma->anon_vma = &dummy_anon_vma; ASSERT_EQ(merge_existing(&vmg), vma_next); + ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); ASSERT_EQ(vma_next->vm_start, 0x2000); ASSERT_EQ(vma_next->vm_end, 0x9000); ASSERT_EQ(vma_next->vm_pgoff, 2); @@ -889,6 +901,7 @@ static bool test_merge_existing(void) vma->anon_vma = &dummy_anon_vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); + ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); ASSERT_EQ(vma_prev->vm_start, 0); ASSERT_EQ(vma_prev->vm_end, 0x6000); ASSERT_EQ(vma_prev->vm_pgoff, 0); @@ -920,6 +933,7 @@ static bool test_merge_existing(void) vmg.vma = vma; vma->anon_vma = &dummy_anon_vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); + ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); ASSERT_EQ(vma_prev->vm_start, 0); ASSERT_EQ(vma_prev->vm_end, 0x7000); ASSERT_EQ(vma_prev->vm_pgoff, 0); @@ -948,6 +962,7 @@ static bool test_merge_existing(void) vmg.vma = vma; vma->anon_vma = &dummy_anon_vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); + ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); ASSERT_EQ(vma_prev->vm_start, 0); ASSERT_EQ(vma_prev->vm_end, 0x9000); ASSERT_EQ(vma_prev->vm_pgoff, 0); @@ -981,31 +996,37 @@ static bool test_merge_existing(void) vmg.prev = vma; vmg.vma = vma; ASSERT_EQ(merge_existing(&vmg), NULL); + ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); vmg_set_range(&vmg, 0x5000, 0x6000, 5, flags); vmg.prev = vma; vmg.vma = vma; ASSERT_EQ(merge_existing(&vmg), NULL); + ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); vmg_set_range(&vmg, 0x6000, 0x7000, 6, flags); vmg.prev = vma; vmg.vma = vma; ASSERT_EQ(merge_existing(&vmg), NULL); + ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); vmg_set_range(&vmg, 0x4000, 0x7000, 4, flags); vmg.prev = vma; vmg.vma = vma; ASSERT_EQ(merge_existing(&vmg), NULL); + ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); vmg_set_range(&vmg, 0x4000, 0x6000, 4, flags); vmg.prev = vma; vmg.vma = vma; ASSERT_EQ(merge_existing(&vmg), NULL); + ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); vmg_set_range(&vmg, 0x5000, 0x6000, 5, flags); vmg.prev = vma; vmg.vma = vma; ASSERT_EQ(merge_existing(&vmg), NULL); + ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); ASSERT_EQ(cleanup_mm(&mm, &vmi), 3); @@ -1071,6 +1092,7 @@ static bool test_anon_vma_non_mergeable(void) vmg.vma = vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); + ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); ASSERT_EQ(vma_prev->vm_start, 0); ASSERT_EQ(vma_prev->vm_end, 0x7000); ASSERT_EQ(vma_prev->vm_pgoff, 0); @@ -1106,6 +1128,7 @@ static bool test_anon_vma_non_mergeable(void) vmg.prev = vma_prev; ASSERT_EQ(merge_new(&vmg), vma_prev); + ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); ASSERT_EQ(vma_prev->vm_start, 0); ASSERT_EQ(vma_prev->vm_end, 0x7000); ASSERT_EQ(vma_prev->vm_pgoff, 0); @@ -1181,6 +1204,7 @@ static bool test_dup_anon_vma(void) vmg.vma = vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); + ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); ASSERT_EQ(vma_prev->vm_start, 0); ASSERT_EQ(vma_prev->vm_end, 0x8000); @@ -1209,6 +1233,7 @@ static bool test_dup_anon_vma(void) vmg.vma = vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); + ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); ASSERT_EQ(vma_prev->vm_start, 0); ASSERT_EQ(vma_prev->vm_end, 0x8000); @@ -1236,6 +1261,7 @@ static bool test_dup_anon_vma(void) vmg.vma = vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); + ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); ASSERT_EQ(vma_prev->vm_start, 0); ASSERT_EQ(vma_prev->vm_end, 0x5000); @@ -1263,6 +1289,7 @@ static bool test_dup_anon_vma(void) vmg.vma = vma; ASSERT_EQ(merge_existing(&vmg), vma_next); + ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); ASSERT_EQ(vma_next->vm_start, 0x3000); ASSERT_EQ(vma_next->vm_end, 0x8000); @@ -1303,6 +1330,7 @@ static bool test_vmi_prealloc_fail(void) /* This will cause the merge to fail. */ ASSERT_EQ(merge_existing(&vmg), NULL); + ASSERT_EQ(vmg.state, VMA_MERGE_ERROR_NOMEM); /* We will already have assigned the anon_vma. */ ASSERT_EQ(vma_prev->anon_vma, &dummy_anon_vma); /* And it was both cloned and unlinked. */ @@ -1327,6 +1355,7 @@ static bool test_vmi_prealloc_fail(void) fail_prealloc = true; ASSERT_EQ(expand_existing(&vmg), -ENOMEM); + ASSERT_EQ(vmg.state, VMA_MERGE_ERROR_NOMEM); ASSERT_EQ(vma_prev->anon_vma, &dummy_anon_vma); ASSERT_TRUE(dummy_anon_vma.was_cloned); diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_internal.h index a3c262c6eb73..c5b9da034511 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -740,6 +740,12 @@ static inline void vma_iter_free(struct vma_iterator *vmi) mas_destroy(&vmi->mas); } +static inline +struct vm_area_struct *vma_iter_next_range(struct vma_iterator *vmi) +{ + return mas_next_range(&vmi->mas, ULONG_MAX); +} + static inline void vm_acct_memory(long pages) { } From patchwork Fri Aug 23 20:07:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13775926 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96CE8C531DC for ; Fri, 23 Aug 2024 20:07:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 58E53800C7; Fri, 23 Aug 2024 16:07:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 51863800C1; Fri, 23 Aug 2024 16:07:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14679800C7; Fri, 23 Aug 2024 16:07:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id DF093800C1 for ; Fri, 23 Aug 2024 16:07:42 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 90FD3C1E17 for ; Fri, 23 Aug 2024 20:07:42 +0000 (UTC) X-FDA: 82484595564.27.5B162AF Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf07.hostedemail.com (Postfix) with ESMTP id 4F3B840009 for ; Fri, 23 Aug 2024 20:07:39 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="W/pj68mx"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=vjSu6P8J; spf=pass (imf07.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724443594; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1cVRTGlz38lLREn/y2HwxJjhQMGObDwlsW1VGdwo/4c=; b=Y/1cm6HpKAJbyOZmBH85brNdXth5hGXLgpo4df7u+8iHJD95V59s37iy4HvNZm8G1wphpT VZlzWwxIx53brv3J0fsXo/DIBUKS05iBGZY/czPkUkkRb7hGS95A1F+FfNCbLtf0ZPBPRF PpAPzpUIDRJisQQ9G1F+SVjUPLTIPic= ARC-Authentication-Results: i=2; imf07.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="W/pj68mx"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=vjSu6P8J; spf=pass (imf07.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724443594; a=rsa-sha256; cv=pass; b=LdKiJWwrS/VWN+TvHXbyKiPtve3yYChevKHXeJaYWmEQDwezzqj3OMXEMdIlKWlRRg8BNU YYVNcwPSf6XG5fNo5gfzV03pwMtCiJVag861MpW5Rr9RDxsW9LXy3zTRTwhL7mGSkUvBvL D3IhFdZzFpZsM2EeO7cRUnrEZ19ITUQ= Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47NH0TVV009515; Fri, 23 Aug 2024 20:07:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=1cVRTGlz38lLREn/y2HwxJjhQMGObDwlsW1VGdwo/4c=; b= W/pj68mxauJvqxrNP1P8FmTOvMv+ZjgeyjXrkhHuZu/pWgYZV+cCINcNjOfR9ixX OZK8AW0lll4EYnm3qg0Jld3npAaguT1y/g7QWAhwSPSq8JDDycBYIqjMcQIKN3hx ztOu/yABLaIjddHGNHRlutGX+eUVb1yEJDHf0GiKviyT6SzkOd+8JyfXxAMCkUqX KtE803yTSDFG7sOOEsHJmnNSyO5jSk3XDOSmbjNJvGRq4qjCDgdEZA3BEROOqFOo LoPNvAZS4CIIkORz1Q/sJFWthsXh6b2/KGrv4wxFe1AkIA0WXREA/GYpw5UN2jDv DeUynedn/XafjhyOI2/j5w== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412m3dwh86-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:38 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 47NJdCpX007466; Fri, 23 Aug 2024 20:07:37 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2173.outbound.protection.outlook.com [104.47.57.173]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4170s5gxw2-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xiFtiCzSFgG83OUTLGrumg9HW4pQc3MraH2xOrvCwPBT3i+5Y5zjCI7oluGkSkjhAIwMDEI75D+pPyr4KrV7SsOAReXE2wA6FRw71RiDhyAkWZOFKvlafMLNkvMFLsx57YxBr0SiZTkFpIs06NbhewHgp5UbGbyedo2vCqGEYelrQFn7N/oLVBL43Wzc5cI9/ruxUMmcS7A/PDXUOzNvN2wad0cyYp0HZzmADePHGjhlQDZdQwa9g9efp6Ua9m1lhRFIFu/8iGxUjIglsYoLxv0v6EmsUA9j4jxoS6ZpuE/CyF5gtfm3dg64tq8crdDiWKx5MC7Rx0vtPP9oP5/eiA== 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=1cVRTGlz38lLREn/y2HwxJjhQMGObDwlsW1VGdwo/4c=; b=aER4cB120KJAWdr4PIeKCzT9e54s9J1QnNRCTAjwI9o2xvsI0/vkz4AynLr9JyYNvRqt5sfu9Z0aizGcuPrr1hWBVunNSC1FUO+fK9xJWZegopnNKqNatAK883s++chbTVc3Wtznr62y2RFNlbiJ8J40XjeftajSyhfuemq2W/b1zv56MSLQ1XkXQVcwGO7cllrDRX1J3BqidvkkzZe9ue0H8pPNR9FtUl8neqF7BRRF+3J5QPbgjUJDZ1n3fKVRCPhFbRy5OTDFe1znBPC0eISCikbdBcQp+qPN+HgF3qRAZ43I1i0nNa4qDg0xcN9QB+T1A2AsbRcsps6tU+VTmA== 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=1cVRTGlz38lLREn/y2HwxJjhQMGObDwlsW1VGdwo/4c=; b=vjSu6P8JD+qGGLzv3RAoBeaEvY7cW935RzDIdOhHQjNKkjVne9PuZRH3MtCIglY6CTbIZFNx3JxbUayFXUrqcTe2PX/OGMKcaqdKWOf//c7Ji/vAe1eOWTcI0yz6ysmx0yUEY+nyqFGE5K04muLaO5fB5Pt6tSBdgnjtgjBff6Q= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by BL3PR10MB6187.namprd10.prod.outlook.com (2603:10b6:208:3be::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.17; Fri, 23 Aug 2024 20:07:28 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%6]) with mapi id 15.20.7897.014; Fri, 23 Aug 2024 20:07:28 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH v2 07/10] mm: make vma_prepare() and friends static and internal to vma.c Date: Fri, 23 Aug 2024 21:07:02 +0100 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0466.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a2::22) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|BL3PR10MB6187:EE_ X-MS-Office365-Filtering-Correlation-Id: 54a68a9e-97e0-4777-2537-08dcc3af3689 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: Omji4YgGzU6PTVTPsazPKKOl/Ct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8Lw9kFE9RzARxgRKhvqU1tw0shfdeVGIJWZM2zLH35kz/PHSs72mZK1lmr2mD/Y24rC6D+cSjsFPSCP/jOQmTUJs/YRQ3TRotm6Q77GosbMJ7JD0yuwtGhH5289nkaVtwDq1+yYQrHbF+rWhp50n6wr0o1gMCsxzw7lJ6acI8mKEJxe8xA0bIFiVT78Afc9PYPJ1GrBq7Okj5FU9psBvGJKjP1vWanGkxmi6BLtq9Eagu4Js87aHU+Ow+DRar+L81XAHCMNXHw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RkNR5uyHQ8l2rJu1EcdiLXZzEiokR3wzSOi4+0qHwWSnktKO4TcA6P6RLvgY+5BAOC1EcfuznVzDhw58WKAeoj4Dr/g/2qJ+iatYaNnz+XeLnMayAYabxh96kXKxpFEoRSARacXyRau9mcQAnix+06iBuLwFM7d33y1nM4+GRUaRQ22x4yk6P8KCMgtgBjAk3/GtkDCwr9ZuOTXuidbmGsTY9j3ZGgknAeKgBhViRfMG8i6LFv/jFycJbDLZD11VxO31vsN60iuyaSf+BeGkfTEUFqHdlwLpc1+yl0hBECz0rziy65OoaEPR5jSqdw2+t+uoS8vd2/WaCXO1KubsjHw2Zb8SBYLA6KsqWzCEq1sry8r3YkUMyUAvysTS14GTet7vnzpsNk8JdqrIOwDF5rXHGbKeCZhGkRpPDy194k5EPmDnLGxNHk5mOi/Ro2Aa/twytxl2rm2j3jBczgw0ps2o5uTHJVbCjcm6D6gP0GivsWfbh6Y0PsaDAuC3PToXq1GAQuWZm0Th0whwtFBr1QcYwLnrxIEdhkeOEUXKi2hxkqm+rSpX6ucSWhHPKjEUBZ9+rNtrDCuxs6m22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AntiSpam-ExternalHop-MessageData-0: p3oIQaoQta40t5TnN0uxPz16tAqNnWfFPxgpmwXBbWCdRxK6jfrlokC/GCK1ZXcP8D1dKYHeHRlFnG8XIRStAWwAHtEwss5TVF69MLweCsfTbSiTZR1TTGUueQlWw4Mm7kt8VZrUKOkTPTEL0GA8VA26ppiZ+338r2iQQGOj1A4QoqLsgNrrVsZ9SQ4Xz3ltDOSM/81bKSDEcJWVNy/bhd0+NcKj214xermHRH8Q5Oc46a9DBRT6hY4M78U87NlrI2o+YBvnvvVOYPSQFEb9VDgS2uNA1HpTWR7DxYiyphfXMLEgJ1dSQt4YdR8OLqAmyInqUTCPzReRKnuz3cqqL0BHA9My54GD+j2L8G+x+3HtRwp2gGSxi+lYjEoI+Y0xLszy/aaPvl+At0RyEAcsslrdj6e3WN9S+hmKhcCXypPiJs7Qw4OqYt35FWu8lI6T5Uv2YqvLh6yUjiPGLgMBaf0AIQmPO5qriAXYpCikHYJ2OTxIehA8yDg73jFBmyfTDuVMLVRJ7uCA7OJEmISDb6J9hjiJFhb4EStmvWsJiCpKprjeAjCjrXqqRla7JiWNtLu9+sta+3SQIqIRF9ay9GoQskrWkgefZabxYErMOj8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 54a68a9e-97e0-4777-2537-08dcc3af3689 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 20:07:28.3690 (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: bDZTnh8A6PnOO4mK8Ti6z1novpLUXlsKI0L5HPTXFViu62fcGGQMIfnbGJIxJI+tNiRw+hdPaA3zCC8nZYETaTg7PCEZ5w6gcTE6seWxfbw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR10MB6187 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-23_16,2024-08-23_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408230148 X-Proofpoint-ORIG-GUID: ugOaNlQnvPZZIOj264AVEphZos-UXtyD X-Proofpoint-GUID: ugOaNlQnvPZZIOj264AVEphZos-UXtyD X-Stat-Signature: ryp8zagejkkbpaynxbei6ewcsykw7hkj X-Rspam-User: X-Rspamd-Queue-Id: 4F3B840009 X-Rspamd-Server: rspam02 X-HE-Tag: 1724443659-450446 X-HE-Meta: U2FsdGVkX1/4g9PChciqR3EmiqQfKGtTXiSUjYJ79iJuE6IAG8HWuzoxGMRU9sfU+IaJK9sacY/g3zTqx9RXMN3JtyYmeShskfOw1DaYDTbFBaod7dHvqwhXrqfYyF4Tnc09ZZQ1o2v7iyextIDiJ2X+Cdwv12juXi2VfvHWPXh0qcr2U0wPBoirkxqPjIg2VzFY0xhWAg9LfTDrBdLGC1s7IhULqyLiq7HEKhUTDWuGln8V0VbrN07DCbFDJK7bJHfksore+e+jkeFMgB8jOi25+ylB7B0Bw4cAm1hIoFFtV2viGzWGSoUK9aXdQdYPlAJAQusM22MMOWPG2lDPnsTyQtEcsvabmI58wjlU1RIb6pFlHjo0rpfUaV8uYC2pTW04E20mwx38fdGo7E9iG/b176aVV8OiCzQZ6wrWZONss2YABENsn7pij3jigYKwUBevIUGZ67rMRaU/4HF9N5abWWaXVbocdr4R7MqCD1O1KYt0iHQtsY897cIEL922z3a+da/JWmsz64zjdYwAuUU3UOMOu4RucgdVTQT2eiBDN2WE3oNhXC7jKvwPTgKv7OMqtRPcriZrU4N2I5W9QFIKXHLxbgdwGkJfkauwDQ+zmt+2D9jZTEln2+ETEqwiCQjm3c6wBNb0z4VmYMLnb/BH9fdjEb4BN5LdNnMmNmYhaen8UJzumpthSk2jby8gqVMcPpEhTnEvX2Hiv7kxe/HrH5+tD70ffhsapHPpi8XjFGiK4z84XE3uoNB8X3MBYAJUc1mfwnxjuVj+lC0OH2tdzkMbys9jQ8y4rJ+wNLYRajs/s2zTGzyGQtv0WrL37oi8RlVJo2fs+0ES/by+9fraxhRijC4sHHgL8Tzx0yPV6Fm6KzeK3wD3dFlLeP+XXWTO8BWR+F3k95Etz9syANFXZ3T0M6ECPM2wPloLJ/+luBkPGX2l+1OsTT9veFiNcVGgHer3FYHqjQo16wd qUFFfWp9 fJQDMPstW2+hYkrMQQAicMddA7EgP0pTJEtDSNv62xDbKoINFizDYfA25+dpBG08qGNp2ZxdfC+wT6AAK02mgzF9Jj8pcG6mwHMbOiCeLNKCbYkdWA//pKqahwCkLsq0+WsH1empRICJcMneco9TwZALIfr+qsk45YWsxvTL2OyfE/kKkCuUVe0IzP/oY/rpKw3f1dQKKGh8BBHTgLWOgu3QtsFG5MMwmk70pCbS14iPohYHlUO7H+o1EKrgMbYTqyKJdp1fTr/3/VvNCMUA8CH5GPSmixuTQlJojKJIc6qJTx5Co7oG8nlN4wYpdK76T/KjivZkNSEGepKje2LKdCltzJcRijzsdWK2i0I0dU2fL43pdFrIwBd84WbUtKSOco33F6M2buloaaOY/Gs99r6lj6vj9CKlVcGD5A/8DoZ61gYGMYpdip67YEk7q6cD5npo7jgfYBL8F7JP15az2u9R2pQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Now we have abstracted merge behaviour for new VMA ranges, we are able to render vma_prepare(), init_vma_prep(), vma_complete(), can_vma_merge_before() and can_vma_merge_after() static and internal to vma.c. These are internal implementation details of kernel VMA manipulation and merging mechanisms and thus should not be exposed. This also renders the functions userland testable. Signed-off-by: Lorenzo Stoakes --- mm/vma.c | 318 +++++++++++++++++++++++++++---------------------------- mm/vma.h | 25 ----- 2 files changed, 158 insertions(+), 185 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 8a5fa15f46a2..07df0d5fb3d2 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -97,8 +97,7 @@ static void init_multi_vma_prep(struct vma_prepare *vp, * * We assume the vma may be removed as part of the merge. */ -bool -can_vma_merge_before(struct vma_merge_struct *vmg) +static bool can_vma_merge_before(struct vma_merge_struct *vmg) { pgoff_t pglen = PHYS_PFN(vmg->end - vmg->start); @@ -120,7 +119,7 @@ can_vma_merge_before(struct vma_merge_struct *vmg) * * We assume that vma is not removed as part of the merge. */ -bool can_vma_merge_after(struct vma_merge_struct *vmg) +static bool can_vma_merge_after(struct vma_merge_struct *vmg) { if (is_mergeable_vma(vmg, false) && is_mergeable_anon_vma(vmg->anon_vma, vmg->prev->anon_vma, vmg->prev)) { @@ -130,6 +129,162 @@ bool can_vma_merge_after(struct vma_merge_struct *vmg) return false; } +static void __vma_link_file(struct vm_area_struct *vma, + struct address_space *mapping) +{ + if (vma_is_shared_maywrite(vma)) + mapping_allow_writable(mapping); + + flush_dcache_mmap_lock(mapping); + vma_interval_tree_insert(vma, &mapping->i_mmap); + flush_dcache_mmap_unlock(mapping); +} + +/* + * Requires inode->i_mapping->i_mmap_rwsem + */ +static void __remove_shared_vm_struct(struct vm_area_struct *vma, + struct address_space *mapping) +{ + if (vma_is_shared_maywrite(vma)) + mapping_unmap_writable(mapping); + + flush_dcache_mmap_lock(mapping); + vma_interval_tree_remove(vma, &mapping->i_mmap); + flush_dcache_mmap_unlock(mapping); +} + +/* + * vma_prepare() - Helper function for handling locking VMAs prior to altering + * @vp: The initialized vma_prepare struct + */ +static void vma_prepare(struct vma_prepare *vp) +{ + if (vp->file) { + uprobe_munmap(vp->vma, vp->vma->vm_start, vp->vma->vm_end); + + if (vp->adj_next) + uprobe_munmap(vp->adj_next, vp->adj_next->vm_start, + vp->adj_next->vm_end); + + i_mmap_lock_write(vp->mapping); + if (vp->insert && vp->insert->vm_file) { + /* + * Put into interval tree now, so instantiated pages + * are visible to arm/parisc __flush_dcache_page + * throughout; but we cannot insert into address + * space until vma start or end is updated. + */ + __vma_link_file(vp->insert, + vp->insert->vm_file->f_mapping); + } + } + + if (vp->anon_vma) { + anon_vma_lock_write(vp->anon_vma); + anon_vma_interval_tree_pre_update_vma(vp->vma); + if (vp->adj_next) + anon_vma_interval_tree_pre_update_vma(vp->adj_next); + } + + if (vp->file) { + flush_dcache_mmap_lock(vp->mapping); + vma_interval_tree_remove(vp->vma, &vp->mapping->i_mmap); + if (vp->adj_next) + vma_interval_tree_remove(vp->adj_next, + &vp->mapping->i_mmap); + } + +} + +/* + * vma_complete- Helper function for handling the unlocking after altering VMAs, + * or for inserting a VMA. + * + * @vp: The vma_prepare struct + * @vmi: The vma iterator + * @mm: The mm_struct + */ +static void vma_complete(struct vma_prepare *vp, struct vma_iterator *vmi, + struct mm_struct *mm) +{ + if (vp->file) { + if (vp->adj_next) + vma_interval_tree_insert(vp->adj_next, + &vp->mapping->i_mmap); + vma_interval_tree_insert(vp->vma, &vp->mapping->i_mmap); + flush_dcache_mmap_unlock(vp->mapping); + } + + if (vp->remove && vp->file) { + __remove_shared_vm_struct(vp->remove, vp->mapping); + if (vp->remove2) + __remove_shared_vm_struct(vp->remove2, vp->mapping); + } else if (vp->insert) { + /* + * split_vma has split insert from vma, and needs + * us to insert it before dropping the locks + * (it may either follow vma or precede it). + */ + vma_iter_store(vmi, vp->insert); + mm->map_count++; + } + + if (vp->anon_vma) { + anon_vma_interval_tree_post_update_vma(vp->vma); + if (vp->adj_next) + anon_vma_interval_tree_post_update_vma(vp->adj_next); + anon_vma_unlock_write(vp->anon_vma); + } + + if (vp->file) { + i_mmap_unlock_write(vp->mapping); + uprobe_mmap(vp->vma); + + if (vp->adj_next) + uprobe_mmap(vp->adj_next); + } + + if (vp->remove) { +again: + vma_mark_detached(vp->remove, true); + if (vp->file) { + uprobe_munmap(vp->remove, vp->remove->vm_start, + vp->remove->vm_end); + fput(vp->file); + } + if (vp->remove->anon_vma) + anon_vma_merge(vp->vma, vp->remove); + mm->map_count--; + mpol_put(vma_policy(vp->remove)); + if (!vp->remove2) + WARN_ON_ONCE(vp->vma->vm_end < vp->remove->vm_end); + vm_area_free(vp->remove); + + /* + * In mprotect's case 6 (see comments on vma_merge), + * we are removing both mid and next vmas + */ + if (vp->remove2) { + vp->remove = vp->remove2; + vp->remove2 = NULL; + goto again; + } + } + if (vp->insert && vp->file) + uprobe_mmap(vp->insert); +} + +/* + * init_vma_prep() - Initializer wrapper for vma_prepare struct + * @vp: The vma_prepare struct + * @vma: The vma that will be altered once locked + */ +static void init_vma_prep(struct vma_prepare *vp, struct vm_area_struct *vma) +{ + init_multi_vma_prep(vp, vma, NULL, NULL, NULL); +} + /* * Close a vm structure and free it. */ @@ -270,31 +425,6 @@ static int split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, return __split_vma(vmi, vma, addr, new_below); } -/* - * init_vma_prep() - Initializer wrapper for vma_prepare struct - * @vp: The vma_prepare struct - * @vma: The vma that will be altered once locked - */ -void init_vma_prep(struct vma_prepare *vp, - struct vm_area_struct *vma) -{ - init_multi_vma_prep(vp, vma, NULL, NULL, NULL); -} - -/* - * Requires inode->i_mapping->i_mmap_rwsem - */ -static void __remove_shared_vm_struct(struct vm_area_struct *vma, - struct address_space *mapping) -{ - if (vma_is_shared_maywrite(vma)) - mapping_unmap_writable(mapping); - - flush_dcache_mmap_lock(mapping); - vma_interval_tree_remove(vma, &mapping->i_mmap); - flush_dcache_mmap_unlock(mapping); -} - /* * vma has some anon_vma assigned, and is already inserted on that * anon_vma's interval trees. @@ -327,60 +457,6 @@ anon_vma_interval_tree_post_update_vma(struct vm_area_struct *vma) anon_vma_interval_tree_insert(avc, &avc->anon_vma->rb_root); } -static void __vma_link_file(struct vm_area_struct *vma, - struct address_space *mapping) -{ - if (vma_is_shared_maywrite(vma)) - mapping_allow_writable(mapping); - - flush_dcache_mmap_lock(mapping); - vma_interval_tree_insert(vma, &mapping->i_mmap); - flush_dcache_mmap_unlock(mapping); -} - -/* - * vma_prepare() - Helper function for handling locking VMAs prior to altering - * @vp: The initialized vma_prepare struct - */ -void vma_prepare(struct vma_prepare *vp) -{ - if (vp->file) { - uprobe_munmap(vp->vma, vp->vma->vm_start, vp->vma->vm_end); - - if (vp->adj_next) - uprobe_munmap(vp->adj_next, vp->adj_next->vm_start, - vp->adj_next->vm_end); - - i_mmap_lock_write(vp->mapping); - if (vp->insert && vp->insert->vm_file) { - /* - * Put into interval tree now, so instantiated pages - * are visible to arm/parisc __flush_dcache_page - * throughout; but we cannot insert into address - * space until vma start or end is updated. - */ - __vma_link_file(vp->insert, - vp->insert->vm_file->f_mapping); - } - } - - if (vp->anon_vma) { - anon_vma_lock_write(vp->anon_vma); - anon_vma_interval_tree_pre_update_vma(vp->vma); - if (vp->adj_next) - anon_vma_interval_tree_pre_update_vma(vp->adj_next); - } - - if (vp->file) { - flush_dcache_mmap_lock(vp->mapping); - vma_interval_tree_remove(vp->vma, &vp->mapping->i_mmap); - if (vp->adj_next) - vma_interval_tree_remove(vp->adj_next, - &vp->mapping->i_mmap); - } - -} - /* * dup_anon_vma() - Helper function to duplicate anon_vma * @dst: The destination VMA @@ -675,84 +751,6 @@ int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma, return 0; } -/* - * vma_complete- Helper function for handling the unlocking after altering VMAs, - * or for inserting a VMA. - * - * @vp: The vma_prepare struct - * @vmi: The vma iterator - * @mm: The mm_struct - */ -void vma_complete(struct vma_prepare *vp, - struct vma_iterator *vmi, struct mm_struct *mm) -{ - if (vp->file) { - if (vp->adj_next) - vma_interval_tree_insert(vp->adj_next, - &vp->mapping->i_mmap); - vma_interval_tree_insert(vp->vma, &vp->mapping->i_mmap); - flush_dcache_mmap_unlock(vp->mapping); - } - - if (vp->remove && vp->file) { - __remove_shared_vm_struct(vp->remove, vp->mapping); - if (vp->remove2) - __remove_shared_vm_struct(vp->remove2, vp->mapping); - } else if (vp->insert) { - /* - * split_vma has split insert from vma, and needs - * us to insert it before dropping the locks - * (it may either follow vma or precede it). - */ - vma_iter_store(vmi, vp->insert); - mm->map_count++; - } - - if (vp->anon_vma) { - anon_vma_interval_tree_post_update_vma(vp->vma); - if (vp->adj_next) - anon_vma_interval_tree_post_update_vma(vp->adj_next); - anon_vma_unlock_write(vp->anon_vma); - } - - if (vp->file) { - i_mmap_unlock_write(vp->mapping); - uprobe_mmap(vp->vma); - - if (vp->adj_next) - uprobe_mmap(vp->adj_next); - } - - if (vp->remove) { -again: - vma_mark_detached(vp->remove, true); - if (vp->file) { - uprobe_munmap(vp->remove, vp->remove->vm_start, - vp->remove->vm_end); - fput(vp->file); - } - if (vp->remove->anon_vma) - anon_vma_merge(vp->vma, vp->remove); - mm->map_count--; - mpol_put(vma_policy(vp->remove)); - if (!vp->remove2) - WARN_ON_ONCE(vp->vma->vm_end < vp->remove->vm_end); - vm_area_free(vp->remove); - - /* - * In mprotect's case 6 (see comments on vma_merge), - * we are removing both mid and next vmas - */ - if (vp->remove2) { - vp->remove = vp->remove2; - vp->remove2 = NULL; - goto again; - } - } - if (vp->insert && vp->file) - uprobe_mmap(vp->insert); -} - static inline void vms_clear_ptes(struct vma_munmap_struct *vms, struct ma_state *mas_detach, bool mm_wr_locked) { diff --git a/mm/vma.h b/mm/vma.h index dbcdf1431014..edc9034d675c 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -132,17 +132,6 @@ void anon_vma_interval_tree_pre_update_vma(struct vm_area_struct *vma); /* Required for expand_downwards(). */ void anon_vma_interval_tree_post_update_vma(struct vm_area_struct *vma); -/* Required for do_brk_flags(). */ -void vma_prepare(struct vma_prepare *vp); - -/* Required for do_brk_flags(). */ -void init_vma_prep(struct vma_prepare *vp, - struct vm_area_struct *vma); - -/* Required for do_brk_flags(). */ -void vma_complete(struct vma_prepare *vp, - struct vma_iterator *vmi, struct mm_struct *mm); - int vma_expand(struct vma_merge_struct *vmg); int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma, unsigned long start, unsigned long end, pgoff_t pgoff); @@ -273,20 +262,6 @@ void remove_vma(struct vm_area_struct *vma, bool unreachable, bool closed); void unmap_region(struct ma_state *mas, struct vm_area_struct *vma, struct vm_area_struct *prev, struct vm_area_struct *next); -/* - * Can we merge the VMA described by vmg into the following VMA vmg->next? - * - * Required by mmap_region(). - */ -bool can_vma_merge_before(struct vma_merge_struct *vmg); - -/* - * Can we merge the VMA described by vmg into the preceding VMA vmg->prev? - * - * Required by mmap_region() and do_brk_flags(). - */ -bool can_vma_merge_after(struct vma_merge_struct *vmg); - /* We are about to modify the VMA's flags. */ struct vm_area_struct *vma_modify_flags(struct vma_iterator *vmi, struct vm_area_struct *prev, From patchwork Fri Aug 23 20:07:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13775927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB078C5321E for ; Fri, 23 Aug 2024 20:07:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA40E800C1; Fri, 23 Aug 2024 16:07:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D5487800CA; Fri, 23 Aug 2024 16:07:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ABB7C800C1; Fri, 23 Aug 2024 16:07:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8D002800C8 for ; Fri, 23 Aug 2024 16:07:43 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 40EF1160D96 for ; Fri, 23 Aug 2024 20:07:43 +0000 (UTC) X-FDA: 82484595606.27.EC4FEC0 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf27.hostedemail.com (Postfix) with ESMTP id DDCE140009 for ; Fri, 23 Aug 2024 20:07:39 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Qd4sBxLi; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=fxTyG3pn; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf27.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724443599; a=rsa-sha256; cv=pass; b=Gl8ZRlPFBASxvWVw3jVFFBpGSZ5wZABRa2VJWNoKICU3qwUWC/tyf4FVpMyw1ILQ5FdRWH 8fAsugilt1hNeudneQNB0TGSJZ/dBh0SefgkZ7gg8lx4oAIhg6Fy1vdF/5TdOqe1R0zUYQ 06ezTLe93Ezao0S5nIFI7iV4DKUTFwo= ARC-Authentication-Results: i=2; imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Qd4sBxLi; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=fxTyG3pn; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf27.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724443599; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GqWVfQYfbej3Jam2dL9UX9I4S8UA+aoiCAwVhcWe/jw=; b=UpeUQNDtNfzZztZJ+0stV9vggEBinAEwj7/IQPAd/ntuIQQKG4ZHMgjjC29tP1BHpx9rgq iygQiqX0cRkC2SLxptS+SS28RwF7Jaw0S3mqysZoW/H2ovLzA0MlI0jyeEk8I62o9OKYI0 OVxNvQajoowX5Je0dKX0dX+IMCoLx2c= Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47NH0Uvk028392; Fri, 23 Aug 2024 20:07:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=GqWVfQYfbej3Jam2dL9UX9I4S8UA+aoiCAwVhcWe/jw=; b= Qd4sBxLiDu6jPS7Cr1sb1OPHvS+FmxNndyNXkmcl2emL6y9dgPAkYpV5evvGUxos gEbLclA+PhBwD17cVvfCON1oHbuQPZl1gwXgCRQ8YBP4+TTY7RiVMnHkxl/KK9xV ucZ58e1UC0vFtiOuklXiTZzwEZG2kFi85xj0gXhh93N7sq0kU0EQib16XWICXgQk +TXw61MDk+ZcBEHkcWClTTF8o0B7c1+ZjXXuPiVgfoD65Age5ZhScnqqlFnUTYcW 5THWLFDyStwIY4mTnrygdTS+ad3LSyiKD/Au6Yk6bumjWOTtcKkQ0tsOTDD5Ltb1 BlnZB2TCddQ24KCxb7QJVg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412m2dn8yu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:38 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 47NJdCpY007466; Fri, 23 Aug 2024 20:07:37 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2173.outbound.protection.outlook.com [104.47.57.173]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4170s5gxw2-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ronr7znJQYGFIArD/lXEZnWM9hJPdVEGZhT0z2RARfl1LYYdkadhScERF9jww9CBWzA95yExpfL4On0gLNdO51c9y74jIekbFr/1wgT+1rI7F5V87BzwE7J89Sf1v+N4tSmgOiVUsSHNevT2HFd/oIWkx6r0uJncrxRzrsu/Vb6I2vlGmwP3iFkA3LhjORQf0QoaW94sffCgZNoETOVkSPVk8K4eAfLva5H6iBbReIVrC2UxVAE4XA+0+PdT3ukCtCttOzZJsrNhKcHt1aFNs9gvDvFoGii5y3cgdFyei0PKkGDvQmMqlAg8PH3nps0lEpTvh+L4vgBf1tvJzbJ6FA== 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=GqWVfQYfbej3Jam2dL9UX9I4S8UA+aoiCAwVhcWe/jw=; b=DARdRiO6F8yjRdYoeKVefPoCYXI7mFrdVplvMYnqdACeXPyNcQtt5KTaLPfzbrqJkupJ9/lgJt+keBemht5WCQrfmptFM9FsjxCv5BUZXJf8iqab5gAlm3WSCIDRXS1t11P8S19DKSmGuY4YGDuHRrn0gqLXawmsdZmt835asHdyAtnS+qgQQDJUcSlShqNLaSdDkU/4CObrNi5wEV5SY2xXYdOiKdxVzxRH2UdJ7iHLUgb0xYlGF7FrgLqaunnriDncyoGfdokU/+j/3Nqo29Rf+GI/+PXhWbfs8dOmKc4uughXGmN8RvRNVYJL01vLBpIlk5KriTlQXPr/2gq5rw== 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=GqWVfQYfbej3Jam2dL9UX9I4S8UA+aoiCAwVhcWe/jw=; b=fxTyG3pn7i2sxxMQKw1rHk68AcE7zmKHHlV6JxQVIxZWB7Og+eS1a1XSRJbSvxA3Zz0FDumf8joHCokmhtfrkoVRVV+CFb9tZyXoTNO/CfucJSTogC3ADJ6FJRi5BpP4VhZjGw2VTe1qQ6BwyMC710j+q7NdC2sHCDXSpUgjL8c= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by BL3PR10MB6187.namprd10.prod.outlook.com (2603:10b6:208:3be::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.17; Fri, 23 Aug 2024 20:07:31 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%6]) with mapi id 15.20.7897.014; Fri, 23 Aug 2024 20:07:31 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH v2 08/10] mm: introduce commit_merge(), abstracting final commit of merge Date: Fri, 23 Aug 2024 21:07:03 +0100 Message-ID: <1574f1e878da4dc2f23be611f318c4f5eb82ef01.1724441678.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0065.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:153::16) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|BL3PR10MB6187:EE_ X-MS-Office365-Filtering-Correlation-Id: 3c6f6306-11e5-4038-9d6b-08dcc3af3854 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: iT3r6nft2Mi2mqx/3/x0sEfTW3o86z86j1CH27j1pXw4N9WLV2S5xui6GeOJG/uabZGtq/f2xCxNT0IBS+bS7KuM95VAX8ypgFTRhM57yRtoo4im6w02qCFlssqgCTgpwQ0cGUjnITJT7U1GlzaFHP7vDPFY/NTBCQs6tlPsB2BljFqxoFLVF1a8UAKU5Mw6K1OJygHpHy4PbbwfkW0wDVcRKICA4flnJlHlUeet3LIAxxDT8x7tDf1MthJMmHq826OwNSkSIWr16HkviAcWmPZ9xRtpI7kut+I/N1w6Sl+hqMJGAHmfE1EysEt0/QM8ENyd9j5EEtQ7ClRy3QZSQfayhutB+oyaodbUc0M4YY3qrSJlU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M;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VsNKW+BvUHMfb8uP1D8HAhCrUqacBezyI7Jo+mm8UhUIZ+Wzp17MGra+6HKdlzCYp5KfUOQyzS5LUvSt7a7BnVN+kusFT+Mh4KO/Se+7woRfYRjhUozRDa+iqXEC7cFGyczmTSrqg3ThUfHyuh8oVPmSotAcWtxGUd4at0MPYQj1bu4+h8rxuUdW1CVZwnDwH38gdWypNvnKgbWnSyWZ0IGRs+bghrNA7lJHbshV46XjCz8J4jrinwhZldKw4HYiaSipGoKJzD9qm91aJIqKc4jl5tPCusZFSH3m6W7/5iB5tsXL4iEc3E4mAVk5S/RL151hhtWMUguHHD50UbDGuaJtDN/Bc3VEdKNSY56J/noZ7QmfZ358RowNnsK72BiLHafdAwvDIKNRfkt4vyyg5g6f0nsvAZtBVcyAb7OmAQhFPXZ48QULUmsYynSwwHusSVRbj+CZlDlS/OWWcJRCQxCYsnbkkI6mkPX8vGH3Xzbhtanjp9Iu++x1BHAx4694dfTBZjBi6CwViWRN+3vqq1Osbn5YiJpdCtuWvUCxTq0Fyos/1gNv8zcbZ2/jJcWotaBeYpPeBpvWLWNq35UzKPGNOxRjpRO/BrbNgyQBrKgT7MxteztI6XWaF1eqxKdUtDVSTFSc8B57PIVFOU0vRzx6wa3nmSWKfYSeqGtaIIkcN4B9Isn4IYBwrWIhWpgVt5+tNEZcnFjALxLGe60gCGQxnU0JXbT5lE8j6ty7W3q8cFr9JUi6x233hN1JIteRzO04SmS5srmwUJtPLzQm1AifA6DKOTBLqKfFa8ghblaiH8tRE/RtvvKyjR+MJODRRbiHJZ2IE2lRZVNBOaM/iSoJNcf5OOB5BWJu+LyFW0N43auSDErVwiplkF9Gd+EgSQDg9NpsV4F9UEOugPdW79PFnlY7IatIqRl1+XD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Bs1Heoq7Ye0g3pO1DYmsn/Yq7oaxrQMCYG3CZO2jZHUgdJPphBqmwNL+AXDB6wwdxOQWqw5PJ62QaGJC1OTz1YKLC0bOlCy6YvlUFBabNpfv1VUk7jhILYMeCI090cENfO4tTRcubbnfxH7+UA9y7IoeauDFZHLqzyJhvTj8ONGOsKjD8NzYljJPZVUVGYFXroxqDP25lBZ2l6nI8xwcNyPgk2bSC7o3d6Cwpp17KKBhhXE1rIZIa0Sd9eM/FV37oREQehopbHijHi1p/MDlR2F7bFs7TbdT0DJrRzWqfvFxwpVirwZgJM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3c6f6306-11e5-4038-9d6b-08dcc3af3854 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 20:07:31.2415 (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: khkVzmAFles6akgoRVTD+x3itjYYHMDKLmGGpoShtlEwtHT/OcJlOHXuhOPtCsM2uJzJ3dMFtLy80Vic+54QWhTLYQasUChetTQSRVppQBM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR10MB6187 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-23_16,2024-08-23_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408230148 X-Proofpoint-GUID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aM8fCWGiNBKlmG1aTlwLLDKcg2P7LZptONGaSl1ogDVGowbejbtjilFc9Wx2A40r9zc3NGBEX/RRn4CwWUFjYxJo7F/iU4JnFLiDbkvpRZKdK7+ jJNi+FZ8 01k7/gmo6AiKHDvDVkBotkuSRCtyhG2uQ1C4EqHkuBRQxdUN9az7SLmTc1uoo0uWQl9O3r8glQJkLT9mhGE+AmhmytDOoD8tH0EcfB0uMyDrJwqxGPFrqqEGnRayvUQIT3aqrGd2F1rcApNHkzuRqnATZg0xZYKohqHun835p5KsT42aU5OYX4oQ57RKyyTnR43fFZA5oIJb8lAWTNG0i+ff32yAYBpoN9e//iXQx0W3fomeINlhgnbwJz4+P1X3jS2ZxFLghMmkodSBb1MZZy/SKHs4llFmSo9bK2Bj4y/DFIe3J8aheFy91EZ2q60bQOHgYM8LBkXnJcrtd05P5prqYBi8NGR1KFH9CotQcEigeFnnEAA4TPk3lAYr/EEkBAkfSlpEQAwYHTWq6g+TpbldPDAYUnr/ShY5iW8G4M+ZmzyY6YFUF/+qiQyNqCV/jCcwzaWV1DT1M/K6+coOR+NGS2IE2dzI54AypndNvgJp6h6ViGCWz9pG62y4e0WSSfT2y X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Pull the part of vma_expand() which actually commits the merge operation, that is inserts it into the maple tree and sets the VMA's vma->vm_start and vma->vm_end parameters, into its own function. We implement only the parts needed for vma_expand() which now as a result of previous work is also the means by which new VMA ranges are merged. The next commit in the series will implement merging of existing ranges which will extend commit_merge() to accommodate this case and result in all merges using this common code. Signed-off-by: Lorenzo Stoakes --- mm/vma.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 07df0d5fb3d2..8d670059e728 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -540,6 +540,31 @@ void validate_mm(struct mm_struct *mm) } #endif /* CONFIG_DEBUG_VM_MAPLE_TREE */ +/* Actually perform the VMA merge operation. */ +static int commit_merge(struct vma_merge_struct *vmg, + struct vm_area_struct *remove) +{ + struct vma_prepare vp; + + init_multi_vma_prep(&vp, vmg->vma, NULL, remove, NULL); + + /* Note: vma iterator must be pointing to 'start'. */ + vma_iter_config(vmg->vmi, vmg->start, vmg->end); + + if (vma_iter_prealloc(vmg->vmi, vmg->vma)) + return -ENOMEM; + + vma_prepare(&vp); + vma_adjust_trans_huge(vmg->vma, vmg->start, vmg->end, 0); + vma_set_range(vmg->vma, vmg->start, vmg->end, vmg->pgoff); + + vma_iter_store(vmg->vmi, vmg->vma); + + vma_complete(&vp, vmg->vmi, vmg->vma->vm_mm); + + return 0; +} + /* * vma_merge_new_range - Attempt to merge a new VMA into address space * @@ -672,7 +697,6 @@ int vma_expand(struct vma_merge_struct *vmg) bool remove_next = false; struct vm_area_struct *vma = vmg->vma; struct vm_area_struct *next = vmg->next; - struct vma_prepare vp; mmap_assert_write_locked(vmg->mm); @@ -687,24 +711,15 @@ int vma_expand(struct vma_merge_struct *vmg) return ret; } - init_multi_vma_prep(&vp, vma, NULL, remove_next ? next : NULL, NULL); /* Not merging but overwriting any part of next is not handled. */ - VM_WARN_ON(next && !vp.remove && + VM_WARN_ON(next && !remove_next && next != vma && vmg->end > next->vm_start); /* Only handles expanding */ VM_WARN_ON(vma->vm_start < vmg->start || vma->vm_end > vmg->end); - /* Note: vma iterator must be pointing to 'start' */ - vma_iter_config(vmg->vmi, vmg->start, vmg->end); - if (vma_iter_prealloc(vmg->vmi, vma)) + if (commit_merge(vmg, remove_next ? next : NULL)) goto nomem; - vma_prepare(&vp); - vma_adjust_trans_huge(vma, vmg->start, vmg->end, 0); - vma_set_range(vma, vmg->start, vmg->end, vmg->pgoff); - vma_iter_store(vmg->vmi, vma); - - vma_complete(&vp, vmg->vmi, vma->vm_mm); return 0; nomem: From patchwork Fri Aug 23 20:07:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13775928 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C299C5321D for ; Fri, 23 Aug 2024 20:08:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CE51800CA; Fri, 23 Aug 2024 16:07:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 28157800C8; Fri, 23 Aug 2024 16:07:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03236800CB; Fri, 23 Aug 2024 16:07:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BA44D800C8 for ; Fri, 23 Aug 2024 16:07:43 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 72DB6161BDD for ; Fri, 23 Aug 2024 20:07:43 +0000 (UTC) X-FDA: 82484595606.01.3E37E53 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf01.hostedemail.com (Postfix) with ESMTP id 2A69740008 for ; Fri, 23 Aug 2024 20:07:40 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=ahOe5ugA; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=AdV2xgw8; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf01.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724443642; a=rsa-sha256; cv=pass; b=PTCMG4WqO/rWbnLOiSNQ552xDcaALZY7HjMkVtto1byNqLkMA4tXZ+5eudxG9A9NP7WYBY RfbguaJNXJL0QoRsDYTdN4z8fgFlr98rd8EVcwLYoYJ4ON3BhfzxFgUngJ8ymSmSowx/R0 XWus7Xjh10SUpmJ/31SG5HoIWwTv1aE= ARC-Authentication-Results: i=2; imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=ahOe5ugA; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=AdV2xgw8; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf01.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724443642; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=T9/w8+JoCq4C+DFhw2QKtJGEAya5D7dvEbSvitfxAY8=; b=eYeHJOWlVmIEqg7K7xxk29wxJ0SXQa/LuWH7MprqXEY2cNp6dzMpxA8BszQ1avWA2BrJ1x IVrT30BJ5qWh4Os1RzeWuyZml0ipYIEuPHpwDzUqf4UskN6mWdz/tS0KDYm5n/7A2q3Oo9 Y0MoIt1Y3c++OXWq08cHDzHXWPcGA6Y= Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47NH0URU009613; Fri, 23 Aug 2024 20:07:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=T9/w8+JoCq4C+DFhw2QKtJGEAya5D7dvEbSvitfxAY8=; b= ahOe5ugAb4FbWpM6NM6zDAlFDpYPmJGjsXGgrKwTJJuUq15kKpmjibWVnT9M70Ms boD+eY0MXnldwPT4okFdKG6Uvbk+4if2ewbRTf/0nBDb+Q3kxqhE7du9ZQS0hqLB 1CK5vLyJf2zo4ItYxgOnr82u0/X8ctUFc7l7rujGqgPa8QxFLoG0clYDua75Q+rG lqwoB7oVDBOqorsnocVgKcyYCA/0jhNatVCX1zhafIKeXesCs0N7wM1RE7Mn3Lac JFZHTY2B5bDXsx5hyrLa05zvTTD+WFZWdYRsRZ4hp4MtuWT7iZWsf+kymAxHi1cQ MBjhmE6oI2PdH84kY+HUbQ== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412m3dwh87-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:39 +0000 (GMT) Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 47NJdCpZ007466; Fri, 23 Aug 2024 20:07:38 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2173.outbound.protection.outlook.com [104.47.57.173]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4170s5gxw2-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PaFacq0Ze7CvceZ+xPvniYpREum6GK3TAIenA3N8GAPJM4WCltJiYz1RWunbyWO66CupehEkxgYAtVz4i0W4dtMT9ayEr0qRwpISqgrJLt8ttXZRULbN+yu6Hcnhy272esmo4wTd32U+sQmVzqcARwnBncpBsvUYXDZdkQu5aX16G5euF2EmXKjLmnrPeZBfr91zaCtvJgI1d/5P6+aDgZqd4fjOIs3tF93JkJvrGxWiXGyFAI5Hcmh/yNpr4pgYKFsWUfGNTrbMyEhrYhlP2Qp2obC2tFI74AdIrxM2cFPaeI6jnd1fcgOflusNyCD8Hk74EVotQYSrYHFAmOY60w== 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=T9/w8+JoCq4C+DFhw2QKtJGEAya5D7dvEbSvitfxAY8=; b=K+4R5i2Z0122Eg67E8SYsQpeGbQyTIhng0ncBHWlP6ck8eNTQGYh/s5EWdz5ycRALaLgdt+/1+DM9hOnZjv0VeoXDGNjM7yXCJBH+sJFe4Cz/OTCfD6eUbEoG+Lco5bppGrjbp6BVzbGpmHANQkGu7HzlASwsFvkAGXUglnF/YXgOzQOZV9PT8RL8Tmq6m9Cicnj2takAZnFrw4tBwnMwP2ss2Nk3vsXk2JuvZPbwBYxP1eiVHvV83ruMfszsczwpAkCiD9wjM+hG3fIPGyoQzADXs768ORiNXzH6T3C1iZyM/AUGwS2q3gR3AYALFXqxT4WjQC0sxYVq4T8s7pD8g== 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=T9/w8+JoCq4C+DFhw2QKtJGEAya5D7dvEbSvitfxAY8=; b=AdV2xgw897jltzfulXR7qaScUCcwZ9x96sFLbnyqy5uwNmC6GEoSYm9FhAXu2c04na6gZHKW5+xxm7FXQv/EPZe4fFhsCRPDMYg6C3zHmkx0VESPyRfv9p4Ad2tEotyW8w9qhjf2RQm1I0YXoTVQaugTqKcp+Y5YH124CyxYD54= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by BL3PR10MB6187.namprd10.prod.outlook.com (2603:10b6:208:3be::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.17; Fri, 23 Aug 2024 20:07:34 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%6]) with mapi id 15.20.7897.014; Fri, 23 Aug 2024 20:07:34 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH v2 09/10] mm: refactor vma_merge() into modify-only vma_merge_existing_range() Date: Fri, 23 Aug 2024 21:07:04 +0100 Message-ID: <16da4f8c7f1b84093a2588cbafa936e1c98b2575.1724441678.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: X-ClientProxiedBy: LO6P123CA0032.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:2fe::7) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|BL3PR10MB6187:EE_ X-MS-Office365-Filtering-Correlation-Id: 161e3bda-7d83-4e6c-fa7b-08dcc3af39ef X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014; X-Microsoft-Antispam-Message-Info: Y3JXB+HAPDA4CpJZts9aJNaUJ0Sb7EMcmY+q7NBDYLnw6p956F21p3oFV6HpU4FX6lznRlHqLu6Gbi4Hr3cdptOzC/SVADw61UC9p2R18yBX277jFgxrH07qV93CvBz8C66oxh815TnKl22ZPubyrj2qHBIq3wyvtQtakPJ81sT79i6lG1YK82Al8IBw8q58e02FSOoQrHrtSN4L1x/Qaqqa2rbddAbtxm+V+h4U/4L7F0CHgWDTx9R7Xlaz3JL+FRK8GDOb4VV3nsRObFlHSA3tR7aouvOGNxY4MVWrCn/XE3KC1iLqx/RBGtTcVn5tK/YWkvCXx6GUSm9Mg1fsU8MtgV4FWZxRnZJG9h+AAJajwWcXKYHMRFJg7n1jXzLXAqPyiJ9QKZNgTNfUGGD/eiMKbp7k22zYKJpoqFygRDwDskiak2IOmmL7lshFU4glsnL44yEQugzYdbP12zisD2oMiY3/uTdW9ZMcBdlaSiW9Tboz3hqB2KHBYrERqGCIS1bpr44MXM84QP/qSj1pUWEiHJiHGEFHB2CGdsEnAlSF84uBJWzBXtcXbuHKAMEGmpcx0SoaPi4oPXFVLys5XVPd7ptTaf9EUzoOp33y54Vf3Xvs1wJobXAJcUcRKL/6ms58mPXhYqvjIhK8YWmUXzUt6W7SZscUJ3XgvXRu9hnqM7s+Nl2tZk/J7P2AxW/AtfApM7MaDg8vFdlguMbJJpHN1LVD5dY/5Ql3SQO2PHpYq6TdTnTGbFRU1rP7Kf6hC+dc1CdbtG4fAjrsqNCOLsyEZrYFdCgkb41/x4k1/la/OSrMAEc1adQuQl3OYyrxKRqSB+vbUO1UokwTNUSImE0xZqakp/wSk+l3kA8DNszhc5qebkBHFbLxsNkvbXrT5B+kUt/1ys92SShDj6df8sBVZeER0HOaHkv55fKo1uxAtcLW4k3EL5aOMvr9sMuw/7ZSrF+jeRbAr8e3tQ2dCOvXwCRS3bB46pf1AMAr4fK0C3oN/NpCcO0ot3L/xxEyswvJD/V0EfL8TKWx1L+XuiDkDqnPcNFdB1kxNiPkzOkKFPH3uOspbXSV0UkI+eyW8UTPvcZAhGddd7Vj6r1ICOXnPETTEZy9Ucigc0PINPTVbVqAlfMp5/513nzkFvslzGMCnPcY3eHernr8HytPVq5Ff+76JK27wziP1QbnlBEugltA9xR6rOocJqxAt4sQKkO4ct6/G9J7LJjkl+u0xxdyCdKiCYadIDbubqkS94cKPkLiYnovpJKDqkKGMhZgISkGKI6JHGwFiHAOrreUvaiSpuXh63j+cX2z5vUQ7747XMlYiWgywS0sZcP5Jf/3cxaDQB1d4qmBeZgQ187SIw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2fxafu/G0MoDdEqUA2pAvFvOO6C0FePmSJE5QC6EXM9tExD25OCJkfBXW6c99K9t6sgOQPQ4wj7nr+7kJ00H0EOYvsjLScuJ58xZ/qavf1gcyajUYYjUuDiBFzCgHnkVS92P9jBxzQnzzAjW4KE6/ozTouubAXRVeBh+oM8/h1OlcqY78t4zmEg+vd3z1tExCsNfd4JgA0Zf74w51jPnXPIDoqQhBPEVxpPjIoBspa4uoc1S8nspSBle73HeaMMMnAm3wzR/30XPLTJ1usULnnvrR3dMm4xOXTqTTd4np3CZ2JShrP6iq3rjvWNjIyTGn2oA5N6aCz2E5yMGD3jSYAJa6+Uhj6LoA34oVd2kfcjQlfcoCWN5PYueu2OVixWRg9HyLmhXh9aMPId3IfjJQSyEVn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PGQelxFd0GDHZZp/deQFbrnGd3wx14pJOFi7RGF/n4CJXsYT1Dz6ARRosW/q8sNi5fDCJKHRZa6VMcuLeF4tVfU4prdpEut/zOgxt5pk16Fd3lNmfYuLiV55XGZf60OBz5Q== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: nFEBe9mjP1EhL87BH5dH4MoR7hig030ougmtqSYcTcaL1+QBAp8cdQ/Os5wDR7ttIQZ0pMo8K/2VdLGW4XfqSdHzxjg5OnELmwLt13HrXqlCz+DzwbCmgfGYLwCUWIfsHgde0MdG4neECONcKN9KbVBQ+P5ZP3+A39nnHrU3Q/tz0mgGb7kib9i2gSF7y+C/reZTEipgI64ol9SZBORUQTe8VPkps2OTsMrz+rKS8p/6cmhFrk38QiMrMqiIRDwmCkXM2hhEWQC+3LETnSHF7QhsWtwurj58jsSbyBj1SDwLoFc7bsdKDaIvaJzeajj7WHfepu5UIFAuXixU33i3NJBKblPMdjc+qhkSBvjWN6t/iLBXLbIuTDIQncqgg4QNK4ufXQip59ANp8cXorUdriCVOrGmo/9buwOQ3Kt8RSoz4qUfeGz4izT129YUx0J0gMmbdl3XITmUK7F95D1B7CWGytTPMk1qCmQitcZK2DCik5umYjEUsY4dK84OOKXRj+HBqpr4f4kRYSPWpUMKMoNNVVLeIo0qcHAyCiQjf049Wi/dFNd5CuK31/1pgByStsYL61oZtaaJ4sNSjpGKWLGPiBY9E4A7alOG6+Em6mM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 161e3bda-7d83-4e6c-fa7b-08dcc3af39ef X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 20:07:34.0700 (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: VFjYLwbwMfuEwtwZOoDM2CuAbDP1EAUBBMLWNRRd0I+Ys6H2fd59UQI8G3rMT3nOJk8xlKd4QLkieYnGPzbDPZTZafOMWvSG+bXqQl7IaXc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR10MB6187 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-23_16,2024-08-23_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 bulkscore=0 phishscore=0 adultscore=0 suspectscore=0 malwarescore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408230148 X-Proofpoint-ORIG-GUID: 4fa7QSw9MB7lBKP7mTwzLqoQx0Cg9pDY X-Proofpoint-GUID: 4fa7QSw9MB7lBKP7mTwzLqoQx0Cg9pDY X-Rspam-User: X-Rspamd-Queue-Id: 2A69740008 X-Rspamd-Server: rspam01 X-Stat-Signature: 1egd7nimja95sh8e5hgp86mtsop6pe7t X-HE-Tag: 1724443660-995505 X-HE-Meta: U2FsdGVkX19TnrxmpE54RTDG4V05+EB+ZzxJgdW3eaPIeHH19kbsppqGjssSH09GDtc4gyG5F/+VCdF/6qrUpbRGqCWdzray7FLATnHj0uqLFDdN0taqGViwlluk/SfWp9i5c+emZ6kIv2LHVT6Whago71akqm25Nuv9G1NXQnMe7Qzg+B2yTU7sjCw539hdrYnNZTq41E1O6vlAeVnZQgQUCtFY/LRwm7daUUg/9WfP7k9F71HllOl8OBJiFvmp/6LhmVBHevYW2WJzi6f3nnBcBlr6IHB0MG4fT8+LrvmNSqA5Necgc9pp1jlfp7btuBA92ZUocdhHE10HIAA1mf31QxBI6k60UxpTcNn7upM4n2HC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ensWI5qMKd66Wpa/whYTJ1XvDe0trcHXyAhDFzxDP9nFPJbd0rM//DZqdUTW X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The existing vma_merge() function is no longer required to handle what were previously referred to as cases 1-3 (i.e. the merging of a new VMA), as this is now handled by vma_merge_new_vma(). Additionally, simplify the convoluted control flow of the original, maintaining identical logic only expressed more clearly and doing away with a complicated set of cases, rather logically examining each possible outcome - merging of both the previous and subsequent VMA, merging of the previous VMA and merging of the subsequent VMA alone. We now utilise the previously implemented commit_merge() function to share logic with vma_expand() de-duplicating code and providing less surface area for bugs and confusion. In order to do so, we adjust this function to accept parameters specific to merging existing ranges. Signed-off-by: Lorenzo Stoakes --- mm/vma.c | 527 +++++++++++++++++++++------------------- tools/testing/vma/vma.c | 9 +- 2 files changed, 283 insertions(+), 253 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 8d670059e728..31c52598ee50 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -542,29 +542,297 @@ void validate_mm(struct mm_struct *mm) /* Actually perform the VMA merge operation. */ static int commit_merge(struct vma_merge_struct *vmg, - struct vm_area_struct *remove) + struct vm_area_struct *adjust, + struct vm_area_struct *remove, + struct vm_area_struct *remove2, + long adj_start, + bool expanded) { struct vma_prepare vp; - init_multi_vma_prep(&vp, vmg->vma, NULL, remove, NULL); + init_multi_vma_prep(&vp, vmg->vma, adjust, remove, remove2); - /* Note: vma iterator must be pointing to 'start'. */ - vma_iter_config(vmg->vmi, vmg->start, vmg->end); + VM_WARN_ON(vp.anon_vma && adjust && adjust->anon_vma && + vp.anon_vma != adjust->anon_vma); + + if (expanded) { + /* Note: vma iterator must be pointing to 'start'. */ + vma_iter_config(vmg->vmi, vmg->start, vmg->end); + } else { + vma_iter_config(vmg->vmi, adjust->vm_start + adj_start, + adjust->vm_end); + } if (vma_iter_prealloc(vmg->vmi, vmg->vma)) return -ENOMEM; vma_prepare(&vp); - vma_adjust_trans_huge(vmg->vma, vmg->start, vmg->end, 0); + vma_adjust_trans_huge(vmg->vma, vmg->start, vmg->end, adj_start); vma_set_range(vmg->vma, vmg->start, vmg->end, vmg->pgoff); - vma_iter_store(vmg->vmi, vmg->vma); + if (expanded) + vma_iter_store(vmg->vmi, vmg->vma); + + if (adj_start) { + adjust->vm_start += adj_start; + adjust->vm_pgoff += PHYS_PFN(adj_start); + if (adj_start < 0) { + WARN_ON(expanded); + vma_iter_store(vmg->vmi, adjust); + } + } vma_complete(&vp, vmg->vmi, vmg->vma->vm_mm); return 0; } +/* + * vma_merge_existing_range - Attempt to merge VMAs based on a VMA having its + * attributes modified. + * + * @vmg: Describes the modifications being made to a VMA and associated + * metadata. + * + * When the attributes of a range within a VMA change, then it might be possible + * for immediately adjacent VMAs to be merged into that VMA due to having + * identical properties. + * + * This function checks for the existence of any such mergeable VMAs and updates + * the maple tree describing the @vmg->vma->vm_mm address space to account for + * this, as well as any VMAs shrunk/expanded/deleted as a result of this merge. + * + * As part of this operation, if a merge occurs, the @vmg object will have its + * vma, start, end, and pgoff fields modified to execute the merge. Subsequent + * calls to this function should reset these fields. + * + * Returns: The merged VMA if merge succeeds, or NULL otherwise. + * + * ASSUMPTIONS: + * - The caller must assign the VMA to be modifed to @vmg->vma. + * - The caller must have set @vmg->prev to the previous VMA, if there is one. + * - The caller must not set @vmg->next, as we determine this. + * - The caller must hold a WRITE lock on the mm_struct->mmap_lock. + * - vmi must be positioned within [@vmg->vma->vm_start, @vmg->vma->vm_end). + */ +static struct vm_area_struct *vma_merge_existing_range(struct vma_merge_struct *vmg) +{ + struct vm_area_struct *vma = vmg->vma; + struct vm_area_struct *prev = vmg->prev; + struct vm_area_struct *next, *res; + struct vm_area_struct *anon_dup = NULL; + struct vm_area_struct *adjust = NULL; + unsigned long start = vmg->start; + unsigned long end = vmg->end; + bool left_side = vma && start == vma->vm_start; + bool right_side = vma && end == vma->vm_end; + bool merge_both = false; + int err = 0; + long adj_start = 0; + bool merge_will_delete_vma, merge_will_delete_next; + bool merge_left, merge_right; + bool expanded; + + mmap_assert_write_locked(vmg->mm); + VM_WARN_ON(!vma); /* We are modifying a VMA, so caller must specify. */ + VM_WARN_ON(vmg->next); /* We set this. */ + VM_WARN_ON(prev && start <= prev->vm_start); + VM_WARN_ON(start >= end); + /* + * If vma == prev, then we are offset into a VMA. Otherwise, if we are + * not, we must span a portion of the VMA. + */ + VM_WARN_ON(vma && ((vma != prev && vmg->start != vma->vm_start) || + vmg->end > vma->vm_end)); + /* The vmi must be positioned within vmg->vma. */ + VM_WARN_ON(vma && !(vma_iter_addr(vmg->vmi) >= vma->vm_start && + vma_iter_addr(vmg->vmi) < vma->vm_end)); + + vmg->state = VMA_MERGE_NOMERGE; + + /* + * If a special mapping or neither at the furthermost left or right side + * of the VMA, then we have no chance of merging and should abort. + * + * We later require that vma->vm_flags == vm_flags, so this tests + * vma->vm_flags & VM_SPECIAL, too. + */ + if (vmg->flags & VM_SPECIAL || (!left_side && !right_side)) + return NULL; + + if (left_side && prev && prev->vm_end == start && can_vma_merge_after(vmg)) { + merge_left = true; + vma_prev(vmg->vmi); + } else { + merge_left = false; + } + + if (right_side) { + next = vmg->next = vma_lookup(vma->vm_mm, end); + + /* + * We can merge right if there is a subsequent VMA, if it is + * immediately adjacent, and if it is compatible with vma. + */ + merge_right = next && end == next->vm_start && + can_vma_merge_before(vmg); + + /* + * We can only merge both if the anonymous VMA of the previous + * VMA is compatible with the anonymous VMA of the subsequent + * VMA. + * + * Otherwise, we default to merging only the left. + */ + if (merge_left && merge_right) + merge_right = merge_both = + is_mergeable_anon_vma(prev->anon_vma, + next->anon_vma, NULL); + } else { + merge_right = false; + next = NULL; + } + + /* If we have nothing to merge, abort. */ + if (!merge_left && !merge_right) + return NULL; + + /* If we span the entire VMA, a merge implies it will be deleted. */ + merge_will_delete_vma = left_side && right_side; + /* + * If we merge both VMAs, then next is also deleted. This implies + * merge_will_delete_vma also. + */ + merge_will_delete_next = merge_both; + + /* No matter what happens, we will be adjusting vma. */ + vma_start_write(vma); + + if (merge_left) + vma_start_write(prev); + + if (merge_right) + vma_start_write(next); + + if (merge_both) { + /* + * |<----->| + * |-------*********-------| + * prev vma next + * extend delete delete + */ + + vmg->vma = prev; + vmg->start = prev->vm_start; + vmg->end = next->vm_end; + vmg->pgoff = prev->vm_pgoff; + + /* + * We already ensured anon_vma compatibility above, so now it's + * simply a case of, if prev has no anon_vma object, which of + * next or vma contains the anon_vma we must duplicate. + */ + err = dup_anon_vma(prev, next->anon_vma ? next : vma, &anon_dup); + } else if (merge_left) { + /* + * |<----->| OR + * |<--------->| + * |-------************* + * prev vma + * extend shrink/delete + */ + + vmg->vma = prev; + vmg->start = prev->vm_start; + vmg->pgoff = prev->vm_pgoff; + + if (merge_will_delete_vma) { + /* + * can_vma_merge_after() assumed we would not be + * removing vma, so it skipped the check for + * vm_ops->close, but we are removing vma. + */ + if (vma->vm_ops && vma->vm_ops->close) + err = -EINVAL; + } else { + adjust = vma; + adj_start = vmg->end - vma->vm_start; + } + + if (!err) + err = dup_anon_vma(prev, vma, &anon_dup); + } else { /* merge_right */ + /* + * |<----->| OR + * |<--------->| + * *************-------| + * vma next + * shrink/delete extend + */ + + pgoff_t pglen = PHYS_PFN(vmg->end - vmg->start); + + VM_WARN_ON(!merge_right); + /* If we are offset into a VMA, then prev must be vma. */ + VM_WARN_ON(vmg->start > vma->vm_start && prev && vma != prev); + + if (merge_will_delete_vma) { + vmg->vma = next; + vmg->end = next->vm_end; + vmg->pgoff = next->vm_pgoff - pglen; + } else { + /* + * We shrink vma and expand next. + * + * IMPORTANT: This is the ONLY case where the final + * merged VMA is NOT vmg->vma, but rather vmg->next. + */ + + vmg->start = vma->vm_start; + vmg->end = start; + vmg->pgoff = vma->vm_pgoff; + + adjust = next; + adj_start = -(vma->vm_end - start); + } + + err = dup_anon_vma(next, vma, &anon_dup); + } + + if (err) + goto abort; + + /* + * In nearly all cases, we expand vmg->vma. There is one exception - + * merge_right where we partially span the VMA. In this case we shrink + * the end of vmg->vma and adjust the start of vmg->next accordingly. + */ + expanded = !merge_right || merge_will_delete_vma; + + if (commit_merge(vmg, adjust, + merge_will_delete_vma ? vma : NULL, + merge_will_delete_next ? next : NULL, + adj_start, expanded)) { + if (anon_dup) + unlink_anon_vmas(anon_dup); + + vmg->state = VMA_MERGE_ERROR_NOMEM; + return NULL; + } + + res = merge_left ? prev : next; + khugepaged_enter_vma(res, vmg->flags); + + vmg->state = VMA_MERGE_SUCCESS; + return res; + +abort: + vma_iter_set(vmg->vmi, start); + vma_iter_load(vmg->vmi); + vmg->state = VMA_MERGE_ERROR_NOMEM; + return NULL; +} + /* * vma_merge_new_range - Attempt to merge a new VMA into address space * @@ -717,7 +985,7 @@ int vma_expand(struct vma_merge_struct *vmg) /* Only handles expanding */ VM_WARN_ON(vma->vm_start < vmg->start || vma->vm_end > vmg->end); - if (commit_merge(vmg, remove_next ? next : NULL)) + if (commit_merge(vmg, NULL, remove_next ? next : NULL, NULL, 0, true)) goto nomem; return 0; @@ -1092,249 +1360,6 @@ int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, return do_vmi_align_munmap(vmi, vma, mm, start, end, uf, unlock); } -/* - * Given a mapping request (addr,end,vm_flags,file,pgoff,anon_name), - * figure out whether that can be merged with its predecessor or its - * successor. Or both (it neatly fills a hole). - * - * In most cases - when called for mmap, brk or mremap - [addr,end) is - * certain not to be mapped by the time vma_merge is called; but when - * called for mprotect, it is certain to be already mapped (either at - * an offset within prev, or at the start of next), and the flags of - * this area are about to be changed to vm_flags - and the no-change - * case has already been eliminated. - * - * The following mprotect cases have to be considered, where **** is - * the area passed down from mprotect_fixup, never extending beyond one - * vma, PPPP is the previous vma, CCCC is a concurrent vma that starts - * at the same address as **** and is of the same or larger span, and - * NNNN the next vma after ****: - * - * **** **** **** - * PPPPPPNNNNNN PPPPPPNNNNNN PPPPPPCCCCCC - * cannot merge might become might become - * PPNNNNNNNNNN PPPPPPPPPPCC - * mmap, brk or case 4 below case 5 below - * mremap move: - * **** **** - * PPPP NNNN PPPPCCCCNNNN - * might become might become - * PPPPPPPPPPPP 1 or PPPPPPPPPPPP 6 or - * PPPPPPPPNNNN 2 or PPPPPPPPNNNN 7 or - * PPPPNNNNNNNN 3 PPPPNNNNNNNN 8 - * - * It is important for case 8 that the vma CCCC overlapping the - * region **** is never going to extended over NNNN. Instead NNNN must - * be extended in region **** and CCCC must be removed. This way in - * all cases where vma_merge succeeds, the moment vma_merge drops the - * rmap_locks, the properties of the merged vma will be already - * correct for the whole merged range. Some of those properties like - * vm_page_prot/vm_flags may be accessed by rmap_walks and they must - * be correct for the whole merged range immediately after the - * rmap_locks are released. Otherwise if NNNN would be removed and - * CCCC would be extended over the NNNN range, remove_migration_ptes - * or other rmap walkers (if working on addresses beyond the "end" - * parameter) may establish ptes with the wrong permissions of CCCC - * instead of the right permissions of NNNN. - * - * In the code below: - * PPPP is represented by *prev - * CCCC is represented by *curr or not represented at all (NULL) - * NNNN is represented by *next or not represented at all (NULL) - * **** is not represented - it will be merged and the vma containing the - * area is returned, or the function will return NULL - */ -static struct vm_area_struct *vma_merge(struct vma_merge_struct *vmg) -{ - struct mm_struct *mm = vmg->mm; - struct vm_area_struct *prev = vmg->prev; - struct vm_area_struct *curr, *next, *res; - struct vm_area_struct *vma, *adjust, *remove, *remove2; - struct vm_area_struct *anon_dup = NULL; - struct vma_prepare vp; - pgoff_t vma_pgoff; - int err = 0; - bool merge_prev = false; - bool merge_next = false; - bool vma_expanded = false; - unsigned long addr = vmg->start; - unsigned long end = vmg->end; - unsigned long vma_start = addr; - unsigned long vma_end = end; - pgoff_t pglen = PHYS_PFN(end - addr); - long adj_start = 0; - - vmg->state = VMA_MERGE_NOMERGE; - - /* - * We later require that vma->vm_flags == vm_flags, - * so this tests vma->vm_flags & VM_SPECIAL, too. - */ - if (vmg->flags & VM_SPECIAL) - return NULL; - - /* Does the input range span an existing VMA? (cases 5 - 8) */ - curr = find_vma_intersection(mm, prev ? prev->vm_end : 0, end); - - if (!curr || /* cases 1 - 4 */ - end == curr->vm_end) /* cases 6 - 8, adjacent VMA */ - next = vmg->next = vma_lookup(mm, end); - else - next = vmg->next = NULL; /* case 5 */ - - if (prev) { - vma_start = prev->vm_start; - vma_pgoff = prev->vm_pgoff; - - /* Can we merge the predecessor? */ - if (addr == prev->vm_end && can_vma_merge_after(vmg)) { - merge_prev = true; - vma_prev(vmg->vmi); - } - } - - /* Can we merge the successor? */ - if (next && can_vma_merge_before(vmg)) { - merge_next = true; - } - - /* Verify some invariant that must be enforced by the caller. */ - VM_WARN_ON(prev && addr <= prev->vm_start); - VM_WARN_ON(curr && (addr != curr->vm_start || end > curr->vm_end)); - VM_WARN_ON(addr >= end); - - if (!merge_prev && !merge_next) - return NULL; /* Not mergeable. */ - - if (merge_prev) - vma_start_write(prev); - - res = vma = prev; - remove = remove2 = adjust = NULL; - - /* Can we merge both the predecessor and the successor? */ - if (merge_prev && merge_next && - is_mergeable_anon_vma(prev->anon_vma, next->anon_vma, NULL)) { - vma_start_write(next); - remove = next; /* case 1 */ - vma_end = next->vm_end; - err = dup_anon_vma(prev, next, &anon_dup); - if (curr) { /* case 6 */ - vma_start_write(curr); - remove = curr; - remove2 = next; - /* - * Note that the dup_anon_vma below cannot overwrite err - * since the first caller would do nothing unless next - * has an anon_vma. - */ - if (!next->anon_vma) - err = dup_anon_vma(prev, curr, &anon_dup); - } - } else if (merge_prev) { /* case 2 */ - if (curr) { - vma_start_write(curr); - if (end == curr->vm_end) { /* case 7 */ - /* - * can_vma_merge_after() assumed we would not be - * removing prev vma, so it skipped the check - * for vm_ops->close, but we are removing curr - */ - if (curr->vm_ops && curr->vm_ops->close) - err = -EINVAL; - remove = curr; - } else { /* case 5 */ - adjust = curr; - adj_start = end - curr->vm_start; - } - if (!err) - err = dup_anon_vma(prev, curr, &anon_dup); - } - } else { /* merge_next */ - vma_start_write(next); - res = next; - if (prev && addr < prev->vm_end) { /* case 4 */ - vma_start_write(prev); - vma_end = addr; - adjust = next; - adj_start = -(prev->vm_end - addr); - err = dup_anon_vma(next, prev, &anon_dup); - } else { - /* - * Note that cases 3 and 8 are the ONLY ones where prev - * is permitted to be (but is not necessarily) NULL. - */ - vma = next; /* case 3 */ - vma_start = addr; - vma_end = next->vm_end; - vma_pgoff = next->vm_pgoff - pglen; - if (curr) { /* case 8 */ - vma_pgoff = curr->vm_pgoff; - vma_start_write(curr); - remove = curr; - err = dup_anon_vma(next, curr, &anon_dup); - } - } - } - - /* Error in anon_vma clone. */ - if (err) - goto anon_vma_fail; - - if (vma_start < vma->vm_start || vma_end > vma->vm_end) - vma_expanded = true; - - if (vma_expanded) { - vma_iter_config(vmg->vmi, vma_start, vma_end); - } else { - vma_iter_config(vmg->vmi, adjust->vm_start + adj_start, - adjust->vm_end); - } - - if (vma_iter_prealloc(vmg->vmi, vma)) - goto prealloc_fail; - - init_multi_vma_prep(&vp, vma, adjust, remove, remove2); - VM_WARN_ON(vp.anon_vma && adjust && adjust->anon_vma && - vp.anon_vma != adjust->anon_vma); - - vma_prepare(&vp); - vma_adjust_trans_huge(vma, vma_start, vma_end, adj_start); - vma_set_range(vma, vma_start, vma_end, vma_pgoff); - - if (vma_expanded) - vma_iter_store(vmg->vmi, vma); - - if (adj_start) { - adjust->vm_start += adj_start; - adjust->vm_pgoff += adj_start >> PAGE_SHIFT; - if (adj_start < 0) { - WARN_ON(vma_expanded); - vma_iter_store(vmg->vmi, next); - } - } - - vma_complete(&vp, vmg->vmi, mm); - validate_mm(mm); - khugepaged_enter_vma(res, vmg->flags); - - vmg->state = VMA_MERGE_SUCCESS; - return res; - -prealloc_fail: - vmg->state = VMA_MERGE_ERROR_NOMEM; - if (anon_dup) - unlink_anon_vmas(anon_dup); - -anon_vma_fail: - if (err == -ENOMEM) - vmg->state = VMA_MERGE_ERROR_NOMEM; - - vma_iter_set(vmg->vmi, addr); - vma_iter_load(vmg->vmi); - return NULL; -} - /* * We are about to modify one or multiple of a VMA's flags, policy, userfaultfd * context and anonymous VMA name within the range [start, end). @@ -1354,7 +1379,7 @@ static struct vm_area_struct *vma_modify(struct vma_merge_struct *vmg) struct vm_area_struct *merged; /* First, try to merge. */ - merged = vma_merge(vmg); + merged = vma_merge_existing_range(vmg); if (merged) return merged; diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index 3a3a850d951c..d31bb7bd972a 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -112,7 +112,7 @@ static struct vm_area_struct *merge_new(struct vma_merge_struct *vmg) */ static struct vm_area_struct *merge_existing(struct vma_merge_struct *vmg) { - return vma_merge(vmg); + return vma_merge_existing_range(vmg); } /* @@ -752,7 +752,12 @@ static bool test_vma_merge_with_close(void) vmg.vma = vma; /* Make sure merge does not occur. */ ASSERT_EQ(merge_existing(&vmg), NULL); - ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); + /* + * Initially this is misapprehended as an out of memory report, as the + * close() check is handled in the same way as anon_vma duplication + * failures, however a subsequent patch resolves this. + */ + ASSERT_EQ(vmg.state, VMA_MERGE_ERROR_NOMEM); cleanup_mm(&mm, &vmi); return true; From patchwork Fri Aug 23 20:07:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13775929 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 398ACC5472F for ; Fri, 23 Aug 2024 20:08:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BF514800CB; Fri, 23 Aug 2024 16:08:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5683800C8; Fri, 23 Aug 2024 16:08:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 935D9800CB; Fri, 23 Aug 2024 16:08:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 6EE93800C8 for ; Fri, 23 Aug 2024 16:08:05 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 21A8081DB3 for ; Fri, 23 Aug 2024 20:08:05 +0000 (UTC) X-FDA: 82484596530.26.93A0485 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf21.hostedemail.com (Postfix) with ESMTP id B91371C001E for ; Fri, 23 Aug 2024 20:08:01 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=JCYJi7pU; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=bsVY8O5v; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf21.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724443600; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=1/OPj+BBHa5JPP0Om/PikHyhUPZrpTHgM+iJwISRc54=; b=jCCwocY6Ig01uR93piSynBtcUvtyaEUDEA3KstXWmH2h7Ql0wB7sqBOKEmk3VQ07+5lCow HmQlntR9DDNWMZZ7tgyOxOeQtRDobKXkEMm470BGcmBDrzb/xK73tiP2j6XkOck7sNvCgA pQmndJfzBJHALAIZhtrRsbQplQ1CBFc= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1724443600; a=rsa-sha256; cv=pass; b=fZA4Z1huKY0gj9CXOCgoIGB2bxZm27JnUJQnESnjXMZNRiBJRnr1FZKxrzu+BfM/d8b8F+ d9GOO55Arzo6lB7m9IJRinVclsFwwcMStWp1nVzZVvA9msU3o8iRo2qHhbo9Dspz+TqEmJ x/ywe+myagoH6Cr0P+flV6RIwcEype8= ARC-Authentication-Results: i=2; imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=JCYJi7pU; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=bsVY8O5v; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf21.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47NH0Ve8002321; Fri, 23 Aug 2024 20:08:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=1/OPj+BBHa5JPP0Om/PikHyhUPZrpTHgM+iJwISRc54=; b= JCYJi7pUVqkyPojyJ/Mi6swpPK2qsdrrvGPXtolZF8DsuzVpzusG/aCzQhSbwy30 4iiocB7K16IJy71MfDoOOOLJvBhKmrMkrk74xKKGcA+fWl/eEk5N3+iWzIkwddbO FxAvvcKEmWtb0+9FFSUt7dcGDlbYwFfoUjpRWeqReDNLwWZNAcVNj+2JrmeWspeS 72gQH48pTfNursYzcTDM1SSL20zNmJ2I62MVB3MUAb56eCPl73l6kOVLYprFnoo6 22oRP0F4zzBk0pXPtzxHgkdkiBxz1D21tbQpX7HjhVjb04y5oYlP4CAmu2LEGNUw Xoz2+XOBiElcW7ldKXwuuQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 412m67n1gt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:08:00 +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 47NJdDFl007056; Fri, 23 Aug 2024 20:07:59 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2100.outbound.protection.outlook.com [104.47.58.100]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4170s612ca-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 23 Aug 2024 20:07:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xkLUsKlUwEDR866YHKwtC/ShWtRFRkbXRHTBnQqAFV3mK5Ecg2C3q43GvJ+i9w+On9f/mPkGQHWGvyYUm5WNKZmsI5zmTheTA4N6vvYZU9DmhWBWpV6STgiVjM7wOo6uJ8CH1RTXUEortzR+f1d4AHwHPxDt8NSNAY19kialLbDVmAlx9rrwNut00NtJtDzVPskqrJpa/plnKUi0y6yRA7IwvOFJcYUNGHIS883HyUKllem+wkKPpqdtZ9ZZSn5LDmuouISxiqsAHeREEsG7sGfmYAN78f8t441wdCmulbtGAlAkarfQaoDoLn/iJ0VWoGYBILrNg+FLHOK/t0ZGhQ== 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=1/OPj+BBHa5JPP0Om/PikHyhUPZrpTHgM+iJwISRc54=; b=xqaY31G3ilur2ihxX6Hx6Wzy9ooDjolMYMpkyzOYC5L96yg4xsqlcwgh+Fqv3d5z4IZNdBF7/69xTfnhnHYm61UnZpRg5HLOMwjl1+qHjWdDAcXDwRhVdEaLfIoOCrpmfkMOCB93Qfd02AxkI5E6Ru/knoKLp5z8rHEW2u7IYllz8OT4P+Q9MMNuoAD+b8qlo3EV2JXIJwfx0uRhV9w7zB2aTRhsD0cZbrVQ5fVbfwtss2lPn1CVYzA4c6zbLagvvfTs88BYthM9R8yiwY5Dycr8pGhn54p67kbvkgPadUAIjj1W0TYMXvEC2/l8nI0yV19ZP0t0Gb7tYFSpOsuKIw== 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=1/OPj+BBHa5JPP0Om/PikHyhUPZrpTHgM+iJwISRc54=; b=bsVY8O5vS0kx4L0iyc/NTHFIbiVEV8jbfiK6AShGjbqAcl163D8RT2C7RS4AC6bgkftrGHg5EHL4CHs9TIbw1TwePR3P+OsFdkGK/l5sIji1t6d0sXDy+nuj0Z2JjHWMneJrxq5yjY2XnDj8Tytw89lZCu+FXbNEv9Xr5LKE+7s= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by SA6PR10MB8086.namprd10.prod.outlook.com (2603:10b6:806:446::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7897.11; Fri, 23 Aug 2024 20:07:37 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%6]) with mapi id 15.20.7897.014; Fri, 23 Aug 2024 20:07:37 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH v2 10/10] mm: rework vm_ops->close() handling on VMA merge Date: Fri, 23 Aug 2024 21:07:05 +0100 Message-ID: <3fdfcebeef4b2004940bd09eac6648ad9b2f224b.1724441678.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: X-ClientProxiedBy: LO6P123CA0021.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:313::12) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|SA6PR10MB8086:EE_ X-MS-Office365-Filtering-Correlation-Id: 04aff7d7-d862-4837-ab8d-08dcc3af3ba5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014; X-Microsoft-Antispam-Message-Info: dyE35eItbDJSHAyv2YxDVd1bqN/jVvDij45MpoWARnTqbHRoMbHPpnaQ5NpsVYmJFfZsny7Sr5MruJfdCdjvGft7/K3mAC+5wKcNk+HkLn0to0QaOLuz+bZwci3XcfgbKCgvIIE5Sfh68wQS/Qt0sMLBmYsNQdUbaXHaBVRhgqHFNWE3+XeMdvTaM/7CWRNSfPj67i9SNCk8eT+Me6zRkpMCXy4+KJpkkg1ZplLWV7N1bXAhuOTLl/M/f1ni7rCjBeSO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T6WAZAwCG1K4NNrlPbMc9g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cMdMMlaos0Shk+/K11UB8WM2WHL6NlLlZ21oZZ7aMOR8R6Vs0Sj8naSMj9K0RyrX9Ct5L7n4Q6b33T1ZCvc+vCg8jNohW5dTGwRg98MRAU0PpkZqOrUqrJfvpyruLsMLxDVKIVNA/9I1XJqD1EvpnGsijJ/Z0R+knNCXi6yGun2tzF9devV+HFgZP+AReVh3aKJnFrJ94B1pEk11NoK/XK9qD1TmQdqcnqTTYU+PbS+gBwL2mmYr6Zu1nw5mYdOYedptfEbJyc0CPY4CeN20rZui5EKiuGLONwkgaeQjsA2SwYxyRCk7fwT6evg2CT8JFVgyLATH3Po2QvounbyAl10b4AfG60xV6cOmXIhX3XMEznpvRMDgptfZUswYEcXOyv9YUMiXV0Aq49c9PeNw/YcU8TGiKIwXM/CenpSQV+wVm24vyAc1y+Xs99zbLoiujMMPYsHvlny2OsBtNhF7+kaGauhhxXWEUb80ac9OBh8+D1gEKs06iyW56539bz/pSBSnktzb5pa/3kwb99zW2ia+ghORHRckaGeEs505KLOO8bgaG6A+htm7EWOrvm2oVzVELPgUoEjHElQSnmc7CCfLzedseLPDPfMcJ19FJP9Puy/KFv6/W9wFO3lQVfpeHW25tWUmp/A9SCUQnhAZZIPZa1fLmRQo/FMFaeMIfxJG22x95hYRMxy88m+F8nO9+LM1bA8cPj+U/vuqPtYnYNS78uSZnG+FysWbuvL/xqZ+hrYdtt8o8t6wvtteumuKvVIiZx6VEqMXjxCzVgG/ViZub3A9ToHGIj+iGDw1lrnUeZZOb1wvYQPMeVbKUEEwldf/C33s9jn5yZX44j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a23iHVT55MhKSVH0BxAOSErs5zGSBLM22l3gYMSljHFoescm2SDSYeLn1MExVH2P1Ll//LsrjggnmBWcioY8Em9nvAt5QLlNK0o7HPqCa9ktDjux3s5HhgsvG7tkcgFCQmiwVHxdx79loo4j/tJRVNkMNjTPUkBGODQI0BKYVqXZBSsLGRB/PXOHxkC7uPnzHPQdAtO6q4AjI08KepWnwdTAf8ABarlXWPuBSNK2f+AHx9LMvjzdWBRgiHV9TWORQPhUK2/76yHp/N1Z1XXK8GN3hMwbeUWIPuT6/EwM+05E0T50xHu8lkruRb2DXeXrZVs9cM7SKMBEl60EDL9nQ5BoTxTiNMlQWHGe89Pm2zeIS9QZi9aWXhzrzPNm89QE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04aff7d7-d862-4837-ab8d-08dcc3af3ba5 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2024 20:07:36.9320 (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: 4w9Spix2WCqbx431ba+1vYVXZch4u1xhtKBZmmX7E9UnsXSoVf20o2PR/Gs+CMaiGPj0ZYnz7xHku2FH+Mee09RqGbjmKBAIuZdr8kENe5k= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA6PR10MB8086 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-23_16,2024-08-23_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 suspectscore=0 adultscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408230148 X-Proofpoint-ORIG-GUID: jtNl3bkj5kmzX89BNO8R1uDbptNz_-Sq X-Proofpoint-GUID: jtNl3bkj5kmzX89BNO8R1uDbptNz_-Sq X-Rspamd-Queue-Id: B91371C001E X-Stat-Signature: cotd5g7feuyhmtug39wd4hif4ooykfms X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1724443681-578835 X-HE-Meta: U2FsdGVkX1/e6c49vr5+8fhQNdLnyGyzmXjdhh51qHVc/hIesPbAdBwlaROboHLBlDkZi8GHlEAte+4Dc4ntcgM2kaZ59okR6fggxrcMzgQSu+XecIVFuvRFs2UDqNq7xvBylUxUmKYOQ7iZ1+QzPPkOVUleltFYOR04gzpVsDLUQWWJ6m39KkM6e5FvaSoXCTxS1LS4eAycotCRSeIcat5PtcNwgaEWWO8OR8nbK2/IEBnqgQB2LWbLsduExCEWezigEI1ah1qH3eaz0Ehhp+/avwUMvv/JtsMhWvmnebmqmugi+48vJdCD9Ga94Uafn5Vq84rAcpZKQ+tnoCm+S2U4VJ/f6onFRnn3ywzXtLfnjsBfh2vIJJnETWsVRYKpckQJqM9JxiICQRLbTLU/lUex2f7wq7ChEjMB1g02Qb6VpJNLqUiTHVRaN4CLTl60CnGeOKHwN9cmsqKGH0zIbSbzgLDht+tMcD2uync71T2EwrG4qsKEEH9jX1bTgG8lRGUAk0jF9A1Axz5LcBbofhaJQ/mgE1OvQ7CfLAMz/6Zv4aJUth4zhScrAMrqaxzrKSzPNnmiwtZ+OnadxGAo/4SVpDPgK2Gp6bSP7qKB6eQMvwVvNltdER4J6rqr7w9RQIAti9QXOlve3H1bNDalkLp6Di7O17NCQVFgXFosRzwECH8SGVTZoWSCYabKa4aKbaD72wSYaQYd1ad8lAJkR9AxBNd36QmL9iz7ZzBMqDp1MMDHQhve1SMIHYq4ufDHeoHsy1mReZjoQnw7sk6KqskW42K0W+zaGbq0K4CEPEHaGe5IH8bcbZ4J585Hp+MVwQek7XZALEUGtrGo7NNzZGiez7zx6sNT9O4swsAMtMK5low3s93AtgehQ3AfpoFOFwXBjberiZgOF6BcKJ9jlc93hRHgaLqVtEV8ihfPjpmX1doOV3dozeaKkcb1ioWL7zBqGCe5ZlM1zYCs+ZU 2UOWBOPj JT7V+IpmGVaBtxcBUDPvQyq37ZuOfELY9fRsZUCBELO+YwGHtG0z9Q4YAcSSk7mDGZvr67jCT4ReYG7iScoN3a37MFbjDS5M4kK+ZchZQ0EPvh1HfzHJYMHQlGp+L6ezLF/K741AfGcO/oZLwU/weWo/3vaCY4m2ghG/lpTve6ByUITKEWRcSNTTJiXHFTupqau09VmCDcnRJg2Vm/BTXaBaD+fgFRN0cEa5jOUCaD9lPQdIMQ0HGcBuxRLyd4g0b/Y5oOBQ1K0ap5I0J9SAh1BC1U0rgLOjyv4Ut45MUIYCfV83DB7ZmAYP1LbtmetGUIiXV/xTIUbSLu6MawZHpRAS1RWpQn8EVOFm1Uo93dFHK9mArFxzzOn6STFrkisVah6Sw/zTgU2OgD30Ew/o5BNmqMTZs2vOO/t0MVOE1Fk46qf60NdrLkxq62f/nWpQahW6HqXbdn7IixmKEAc5SuEv9QSvtKkLELTRm2xy+eMybCIYWZ8x6IC4eKgKxgxwmG0Rr7zYM131OhM4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In commit 714965ca8252 ("mm/mmap: start distinguishing if vma can be removed in mergeability test") we relaxed the VMA merge rules for VMAs possessing a vm_ops->close() hook, permitting this operation in instances where we wouldn't delete the VMA as part of the merge operation. This was later corrected in commit fc0c8f9089c2 ("mm, mmap: fix vma_merge() case 7 with vma_ops->close") to account for a subtle case that the previous commit had not taken into account. In both instances, we first rely on is_mergeable_vma() to determine whether we might be dealing with a VMA that might be removed, taking advantage of the fact that a 'previous' VMA will never be deleted, only VMAs that follow it. The second patch corrects the instance where a merge of the previous VMA into a subsequent one did not correctly check whether the subsequent VMA had a vm_ops->close() handler. Both changes prevent merge cases that are actually permissible (for instance a merge of a VMA into a following VMA with a vm_ops->close(), but with no previous VMA, which would result in the next VMA being extended, not deleted). In addition, both changes fail to consider the case where a VMA that would otherwise be merged with the previous and next VMA might have vm_ops->close(), on the assumption that for this to be the case, all three would have to have the same vma->vm_file to be mergeable and thus the same vm_ops. And in addition both changes operate at 50,000 feet, trying to guess whether a VMA will be deleted. As we have majorly refactored the VMA merge operation and de-duplicated code to the point where we know precisely where deletions will occur, this patch removes the aforementioned checks altogether and instead explicitly checks whether a VMA will be deleted. In cases where a reduced merge is still possible (where we merge both previous and next VMA but the next VMA has a vm_ops->close hook, meaning we could just merge the previous and current VMA), we do so, otherwise the merge is not permitted. We take advantage of our userland testing to assert that this functions correctly - replacing the previous limited vm_ops->close() tests with tests for every single case where we delete a VMA. We also update all testing for both new and modified VMAs to set vma->vm_ops->close() in every single instance where this would not prevent the merge, to assert that we never do so. Signed-off-by: Lorenzo Stoakes Acked-by: Vlastimil Babka --- mm/vma.c | 60 ++++++++++----- tools/testing/vma/vma.c | 166 +++++++++++++++++++++++++++++++--------- 2 files changed, 167 insertions(+), 59 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 31c52598ee50..dcc641a3f979 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -10,14 +10,6 @@ static inline bool is_mergeable_vma(struct vma_merge_struct *vmg, bool merge_next) { struct vm_area_struct *vma = merge_next ? vmg->next : vmg->prev; - /* - * If the vma has a ->close operation then the driver probably needs to - * release per-vma resources, so we don't attempt to merge those if the - * caller indicates the current vma may be removed as part of the merge, - * which is the case if we are attempting to merge the next VMA into - * this one. - */ - bool may_remove_vma = merge_next; if (!mpol_equal(vmg->policy, vma_policy(vma))) return false; @@ -33,8 +25,6 @@ static inline bool is_mergeable_vma(struct vma_merge_struct *vmg, bool merge_nex return false; if (vma->vm_file != vmg->file) return false; - if (may_remove_vma && vma->vm_ops && vma->vm_ops->close) - return false; if (!is_mergeable_vm_userfaultfd_ctx(vma, vmg->uffd_ctx)) return false; if (!anon_vma_name_eq(anon_vma_name(vma), vmg->anon_name)) @@ -587,6 +577,12 @@ static int commit_merge(struct vma_merge_struct *vmg, return 0; } +/* We can only remove VMAs when merging if they do not have a close hook. */ +static bool can_merge_remove_vma(struct vm_area_struct *vma) +{ + return !vma->vm_ops || !vma->vm_ops->close; +} + /* * vma_merge_existing_range - Attempt to merge VMAs based on a VMA having its * attributes modified. @@ -699,12 +695,30 @@ static struct vm_area_struct *vma_merge_existing_range(struct vma_merge_struct * /* If we span the entire VMA, a merge implies it will be deleted. */ merge_will_delete_vma = left_side && right_side; + + /* + * If we need to remove vma in its entirety but are unable to do so, + * we have no sensible recourse but to abort the merge. + */ + if (merge_will_delete_vma && !can_merge_remove_vma(vma)) + return NULL; + /* * If we merge both VMAs, then next is also deleted. This implies * merge_will_delete_vma also. */ merge_will_delete_next = merge_both; + /* + * If we cannot delete next, then we can reduce the operation to merging + * prev and vma (thereby deleting vma). + */ + if (merge_will_delete_next && !can_merge_remove_vma(next)) { + merge_will_delete_next = false; + merge_right = false; + merge_both = false; + } + /* No matter what happens, we will be adjusting vma. */ vma_start_write(vma); @@ -746,21 +760,12 @@ static struct vm_area_struct *vma_merge_existing_range(struct vma_merge_struct * vmg->start = prev->vm_start; vmg->pgoff = prev->vm_pgoff; - if (merge_will_delete_vma) { - /* - * can_vma_merge_after() assumed we would not be - * removing vma, so it skipped the check for - * vm_ops->close, but we are removing vma. - */ - if (vma->vm_ops && vma->vm_ops->close) - err = -EINVAL; - } else { + if (!merge_will_delete_vma) { adjust = vma; adj_start = vmg->end - vma->vm_start; } - if (!err) - err = dup_anon_vma(prev, vma, &anon_dup); + err = dup_anon_vma(prev, vma, &anon_dup); } else { /* merge_right */ /* * |<----->| OR @@ -885,6 +890,7 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) unsigned long end = vmg->end; pgoff_t pgoff = vmg->pgoff; pgoff_t pglen = PHYS_PFN(end - start); + bool merge_next = false; bool can_merge_before, can_merge_after; mmap_assert_write_locked(vmg->mm); @@ -910,6 +916,8 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) vmg->end = next->vm_end; vmg->vma = next; vmg->pgoff = next->vm_pgoff - pglen; + + merge_next = true; } /* If we can merge with the previous VMA, adjust vmg accordingly. */ @@ -918,6 +926,14 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) vmg->vma = prev; vmg->pgoff = prev->vm_pgoff; + /* + * If this merge would result in removal of the next VMA but we + * are not permitted to do so, reduce the operation to merging + * prev and vma. + */ + if (merge_next && !can_merge_remove_vma(next)) + vmg->end = end; + vma_prev(vmg->vmi); /* Equivalent to going to the previous range */ } @@ -973,6 +989,8 @@ int vma_expand(struct vma_merge_struct *vmg) int ret; remove_next = true; + /* This should already have been checked by this point. */ + VM_WARN_ON(!can_merge_remove_vma(next)); vma_start_write(next); ret = dup_anon_vma(vma, next, &anon_dup); if (ret) diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index d31bb7bd972a..ea4f9109ffc2 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -387,6 +387,9 @@ static bool test_merge_new(void) struct anon_vma_chain dummy_anon_vma_chain_d = { .anon_vma = &dummy_anon_vma, }; + const struct vm_operations_struct vm_ops = { + .close = dummy_close, + }; int count; struct vm_area_struct *vma, *vma_a, *vma_b, *vma_c, *vma_d; bool merged; @@ -430,6 +433,7 @@ static bool test_merge_new(void) * 0123456789abc * AA*B DD CC */ + vma_a->vm_ops = &vm_ops; /* This should have no impact. */ vma_b->anon_vma = &dummy_anon_vma; vma = try_merge_new_vma(&mm, &vmg, 0x2000, 0x3000, 2, flags, &merged); ASSERT_EQ(vma, vma_a); @@ -466,6 +470,7 @@ static bool test_merge_new(void) * AAAAA *DD CC */ vma_d->anon_vma = &dummy_anon_vma; + vma_d->vm_ops = &vm_ops; /* This should have no impact. */ vma = try_merge_new_vma(&mm, &vmg, 0x6000, 0x7000, 6, flags, &merged); ASSERT_EQ(vma, vma_d); /* Prepend. */ @@ -483,6 +488,7 @@ static bool test_merge_new(void) * 0123456789abc * AAAAA*DDD CC */ + vma_d->vm_ops = NULL; /* This would otherwise degrade the merge. */ vma = try_merge_new_vma(&mm, &vmg, 0x5000, 0x6000, 5, flags, &merged); ASSERT_EQ(vma, vma_a); /* Merge with A, delete D. */ @@ -640,13 +646,11 @@ static bool test_vma_merge_with_close(void) const struct vm_operations_struct vm_ops = { .close = dummy_close, }; - struct vm_area_struct *vma_next = - alloc_and_link_vma(&mm, 0x2000, 0x3000, 2, flags); - struct vm_area_struct *vma; + struct vm_area_struct *vma_prev, *vma_next, *vma; /* - * When we merge VMAs we sometimes have to delete others as part of the - * operation. + * When merging VMAs we are not permitted to remove any VMA that has a + * vm_ops->close() hook. * * Considering the two possible adjacent VMAs to which a VMA can be * merged: @@ -697,28 +701,52 @@ static bool test_vma_merge_with_close(void) * would be set too, and thus scenario A would pick this up. */ - ASSERT_NE(vma_next, NULL); - /* - * SCENARIO A + * The only case of a new VMA merge that results in a VMA being deleted + * is one where both the previous and next VMAs are merged - in this + * instance the next VMA is deleted, and the previous VMA is extended. * - * 0123 - * *N + * If we are unable to do so, we reduce the operation to simply + * extending the prev VMA and not merging next. + * + * 0123456789 + * PPP**NNNN + * -> + * 0123456789 + * PPPPPPNNN */ - /* Make the next VMA have a close() callback. */ + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma_next = alloc_and_link_vma(&mm, 0x5000, 0x9000, 5, flags); vma_next->vm_ops = &vm_ops; - /* Our proposed VMA has characteristics that would otherwise be merged. */ - vmg_set_range(&vmg, 0x1000, 0x2000, 1, flags); + vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); + ASSERT_EQ(merge_new(&vmg), vma_prev); + ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); + ASSERT_EQ(vma_prev->vm_start, 0); + ASSERT_EQ(vma_prev->vm_end, 0x5000); + ASSERT_EQ(vma_prev->vm_pgoff, 0); - /* The next VMA having a close() operator should cause the merge to fail.*/ - ASSERT_EQ(merge_new(&vmg), NULL); - ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); + ASSERT_EQ(cleanup_mm(&mm, &vmi), 2); - /* Now create the VMA so we can merge via modified flags */ - vmg_set_range(&vmg, 0x1000, 0x2000, 1, flags); - vma = alloc_and_link_vma(&mm, 0x1000, 0x2000, 1, flags); + /* + * When modifying an existing VMA there are further cases where we + * delete VMAs. + * + * <> + * 0123456789 + * PPPVV + * + * In this instance, if vma has a close hook, the merge simply cannot + * proceed. + */ + + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, flags); + vma->vm_ops = &vm_ops; + + vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); + vmg.prev = vma_prev; vmg.vma = vma; /* @@ -728,38 +756,90 @@ static bool test_vma_merge_with_close(void) ASSERT_EQ(merge_existing(&vmg), NULL); ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); - /* SCENARIO B + ASSERT_EQ(cleanup_mm(&mm, &vmi), 2); + + /* + * This case is mirrored if merging with next. * - * 0123 - * P* + * <> + * 0123456789 + * VVNNNN * - * In order for this scenario to trigger, the VMA currently being - * modified must also have a .close(). + * In this instance, if vma has a close hook, the merge simply cannot + * proceed. */ - /* Reset VMG state. */ - vmg_set_range(&vmg, 0x1000, 0x2000, 1, flags); - /* - * Make next unmergeable, and don't let the scenario A check pick this - * up, we want to reproduce scenario B only. - */ - vma_next->vm_ops = NULL; - vma_next->__vm_flags &= ~VM_MAYWRITE; - /* Allocate prev. */ - vmg.prev = alloc_and_link_vma(&mm, 0, 0x1000, 0, flags); - /* Assign a vm_ops->close() function to VMA explicitly. */ + vma = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, flags); + vma_next = alloc_and_link_vma(&mm, 0x5000, 0x9000, 5, flags); vma->vm_ops = &vm_ops; + + vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.vma = vma; - /* Make sure merge does not occur. */ ASSERT_EQ(merge_existing(&vmg), NULL); /* * Initially this is misapprehended as an out of memory report, as the * close() check is handled in the same way as anon_vma duplication * failures, however a subsequent patch resolves this. */ - ASSERT_EQ(vmg.state, VMA_MERGE_ERROR_NOMEM); + ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); + + ASSERT_EQ(cleanup_mm(&mm, &vmi), 2); + + /* + * Finally, we consider two variants of the case where we modify a VMA + * to merge with both the previous and next VMAs. + * + * The first variant is where vma has a close hook. In this instance, no + * merge can proceed. + * + * <> + * 0123456789 + * PPPVVNNNN + */ + + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, flags); + vma_next = alloc_and_link_vma(&mm, 0x5000, 0x9000, 5, flags); + vma->vm_ops = &vm_ops; + + vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); + vmg.prev = vma_prev; + vmg.vma = vma; + + ASSERT_EQ(merge_existing(&vmg), NULL); + ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); + + ASSERT_EQ(cleanup_mm(&mm, &vmi), 3); + + /* + * The second variant is where next has a close hook. In this instance, + * we reduce the operation to a merge between prev and vma. + * + * <> + * 0123456789 + * PPPVVNNNN + * -> + * 0123456789 + * PPPPPNNNN + */ + + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, flags); + vma_next = alloc_and_link_vma(&mm, 0x5000, 0x9000, 5, flags); + vma_next->vm_ops = &vm_ops; + + vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); + vmg.prev = vma_prev; + vmg.vma = vma; + + ASSERT_EQ(merge_existing(&vmg), vma_prev); + ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); + ASSERT_EQ(vma_prev->vm_start, 0); + ASSERT_EQ(vma_prev->vm_end, 0x5000); + ASSERT_EQ(vma_prev->vm_pgoff, 0); + + ASSERT_EQ(cleanup_mm(&mm, &vmi), 2); - cleanup_mm(&mm, &vmi); return true; } @@ -828,6 +908,9 @@ static bool test_merge_existing(void) .mm = &mm, .vmi = &vmi, }; + const struct vm_operations_struct vm_ops = { + .close = dummy_close, + }; /* * Merge right case - partial span. @@ -840,7 +923,9 @@ static bool test_merge_existing(void) * VNNNNNN */ vma = alloc_and_link_vma(&mm, 0x2000, 0x6000, 2, flags); + vma->vm_ops = &vm_ops; /* This should have no impact. */ vma_next = alloc_and_link_vma(&mm, 0x6000, 0x9000, 6, flags); + vma_next->vm_ops = &vm_ops; /* This should have no impact. */ vmg_set_range(&vmg, 0x3000, 0x6000, 3, flags); vmg.vma = vma; vmg.prev = vma; @@ -873,6 +958,7 @@ static bool test_merge_existing(void) */ vma = alloc_and_link_vma(&mm, 0x2000, 0x6000, 2, flags); vma_next = alloc_and_link_vma(&mm, 0x6000, 0x9000, 6, flags); + vma_next->vm_ops = &vm_ops; /* This should have no impact. */ vmg_set_range(&vmg, 0x2000, 0x6000, 2, flags); vmg.vma = vma; vma->anon_vma = &dummy_anon_vma; @@ -899,7 +985,9 @@ static bool test_merge_existing(void) * PPPPPPV */ vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma_prev->vm_ops = &vm_ops; /* This should have no impact. */ vma = alloc_and_link_vma(&mm, 0x3000, 0x7000, 3, flags); + vma->vm_ops = &vm_ops; /* This should have no impact. */ vmg_set_range(&vmg, 0x3000, 0x6000, 3, flags); vmg.prev = vma_prev; vmg.vma = vma; @@ -932,6 +1020,7 @@ static bool test_merge_existing(void) * PPPPPPP */ vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma_prev->vm_ops = &vm_ops; /* This should have no impact. */ vma = alloc_and_link_vma(&mm, 0x3000, 0x7000, 3, flags); vmg_set_range(&vmg, 0x3000, 0x7000, 3, flags); vmg.prev = vma_prev; @@ -960,6 +1049,7 @@ static bool test_merge_existing(void) * PPPPPPPPPP */ vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma_prev->vm_ops = &vm_ops; /* This should have no impact. */ vma = alloc_and_link_vma(&mm, 0x3000, 0x7000, 3, flags); vma_next = alloc_and_link_vma(&mm, 0x7000, 0x9000, 7, flags); vmg_set_range(&vmg, 0x3000, 0x7000, 3, flags);