From patchwork Fri Aug 30 18:10:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13785433 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 906B3CA0EFD for ; Fri, 30 Aug 2024 18:11:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 264ED8D0006; Fri, 30 Aug 2024 14:11:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1EC808D0001; Fri, 30 Aug 2024 14:11:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBE5A8D0006; Fri, 30 Aug 2024 14:11:06 -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 B555A8D0001 for ; Fri, 30 Aug 2024 14:11:06 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5F4A9A0370 for ; Fri, 30 Aug 2024 18:11:06 +0000 (UTC) X-FDA: 82509703332.28.CF9189A Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf03.hostedemail.com (Postfix) with ESMTP id D736D20011 for ; Fri, 30 Aug 2024 18:11:02 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=TKkvRVV9; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Qu2zPO2y; arc=pass ("microsoft.com:s=arcselector10001:i=1"); 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; 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=1725041372; 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=fazFJsHyHkXUn6atixEtgs51xdHzmo2Rb8GkbkVPQ5E=; b=Y15+9OWQdrfGM0AyfM4LY4Ku5E5QeU++zYlgVayqgNBI21lK7YT+D5p7iMRWJ6ahfXNncX jve2ohcIU4p3rw6A9yUMadIyNyDoZGu1rQC6DNNFsTGYeQeNzILIALzCJXx9q3lK8uwkpW aUIpOr++DMed3iGrXDw21UuSYhsylNM= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1725041372; a=rsa-sha256; cv=pass; b=EQOTjFKBBkhUI/SB95l1FA16pYR+mwIv1qv6Z3n/5Enw/uvEMLqYbJgBKH5Yafk7dHmpgH yhVy+zPraIQVeAJE/dnIcgbJnYIO9M5vjYvlsp7qylHshnw4jIkIoEnpXFQCL0QnAQmprU lLsaMv6VGVyN5TImEoQwgC/s5hQujwU= ARC-Authentication-Results: i=2; imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=TKkvRVV9; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Qu2zPO2y; arc=pass ("microsoft.com:s=arcselector10001:i=1"); 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; dmarc=pass (policy=reject) header.from=oracle.com 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 47UI0UxJ009289; Fri, 30 Aug 2024 18:10:59 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=fazFJsHyHkXUn6atixEtgs51xdHzmo2Rb8GkbkVPQ5E=; b= TKkvRVV9PjPGqK7hXalDrNgf94vcmp4KxjzlMxgsOqreJjQN0MnO4xurqKXVPhJd N7GpnKOvSjWYoIouJINLp50WGyHxcwoEO5F38kAHj+/11O3CIisuN/9PAutrsYHD TLIJc+9+++kG3cUeyJ6pM/6YbZqqnfz1gpiVmubnaSQoP0sr5GuPcvZ2THA/vSkT 5goGXT9iwcXcTfeoT1EFEdvqp5l+yfXYG/y80WgcOjlVrxL04aNXwGClmCpOTbtF KJtFnI8J/Vod8eo6Jh8bxj0rmtq3IOpHGE/kx1AhjgOghmsAbGr1sdHWYrbiNVtJ j95d5FBvex0lK7UYhzi+ug== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41bfgj8gwx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 30 Aug 2024 18:10:58 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 47UH7202016697; Fri, 30 Aug 2024 18:10:58 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2173.outbound.protection.outlook.com [104.47.56.173]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 418a5wruc2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 30 Aug 2024 18:10:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=I2ejLURu5U7+TM/G3jLbOGXyf02VT2lWmmdSp88N2VKhao4cXFcQ2I4Iy2U2g+Ne/H80P6z8RALhMvj986rP6pwVePeQES+123ttTY1IAfylrqN3+33ExVUYoPP4HRJ29rRMinKQUguR3NQJa0ACqHmqE6+Gz676XsECJvDWXvAu6bQg3XxaocqgQhE5aR90B64gddm7EKoBJaRcBBsFmDXVti555ivqvaGT3T7+IX9oNznI9YG3fEBdUS9nYcuINyOlWZPi1rlHmf9VpWZmBLjGsrHGksl8xnhBaHJNo4sU5EyODtoQ6bU+fO3s6Vl+bp7Zr4EP7ZUXiCix4Hwgcw== 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=fazFJsHyHkXUn6atixEtgs51xdHzmo2Rb8GkbkVPQ5E=; b=yaR672JmD9RvGWDlRrHk56PvELFYkPquJRfc9ad3II9lJwK4KmzwxzeIWFQsERQiA6KyLIMj/XKOL5NDjv9sIBJ/p/ANQ8qGcopkrd72q3emsx6k3rWSjO9cbvUkiZf8hNgWaHlllZl5mOAUWVBGuvnOFgYZL6P2asjMeBKzDbftxAno+9d1un59TlUwfA63EYGLeu6ac3RJNIPVJw6UivwG5C7lfu6iCkRhC+iCFU0bs9ZIMt0Yib7C5VsEjXfXE5Ungv7uJI4MKGIesGfkkltmDdWObDp00d+anli2PcmIQ7kx6GuRUTHZth4tzMV0+7lgTTmNdZsPm/Lhezn3zQ== 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=fazFJsHyHkXUn6atixEtgs51xdHzmo2Rb8GkbkVPQ5E=; b=Qu2zPO2y0qW+r8iIGN06cbjtGwigNzTfPCZOhO+nX7Yik13h3zLC8tKFC6J+6XGDwFRPUgHkbDzBYe+zSJXk2KOcxf6UA2LDhV19js6hSANNRvsUs5ZRRsneqam13CVfRt6xyQDbcKn5ieMLnyMRCJxrkXeZtEQjiB/6PTv0j94= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by IA0PR10MB7276.namprd10.prod.outlook.com (2603:10b6:208:3dc::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7918.19; Fri, 30 Aug 2024 18:10:54 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%5]) with mapi id 15.20.7918.019; Fri, 30 Aug 2024 18:10:54 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Mark Brown Subject: [PATCH v3 09/10] mm: refactor vma_merge() into modify-only vma_merge_existing_range() Date: Fri, 30 Aug 2024 19:10:21 +0100 Message-ID: <2cf6016b7bfcc4965fc3cde10827560c42e4f12c.1725040657.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: X-ClientProxiedBy: LO6P265CA0016.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2ff::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_|IA0PR10MB7276:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ae8b363-e916-4b4d-9134-08dcc91f1685 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: A7ZpZIz9PLgWQK6aAf11ecMNyXLg/8+AnfqIcNQslXJ3VrsrNaU0opXn2tQvfjILH4g1anEPb/NAcGHudCrAmWv/e300VdRPRDxUDzPdFApMii5V88AkDU40PVhY+TBtgMZFqzwWdaZi1jtzBPgfChmOSyzKX0NNdh8KrEUt3jvWvQbB1UwLFl94Uv9cPR7ihNvHz7MfDLRpgsKcTgLqNfkkA4YFm6/Gen7OhDj2+gN+F9xR4qfBaKeVf+EJvTSFrtkL2gUIhwDVaKMRf1pZLLjsInIQn5H9QEYhzxWZXJBDhkhDc8DIQNzk9wIuMZoWJWAeKTY/wH6gw6B1X93JUqGfnagG27BuAOuJjP9L2o+pn70ZhmIixHIAU7nwL/+12VkyynFVwXOIub3Kx8p7atSvjDNzP2cOQv0UI9Nxzm1qxSbEXuf57glQsLWI5qK6b4o4bvvUWYzOJLW1Ag4tdHS/+6It6QWOBQjYlEws9rlE3dA2KC8VkYnhYVzRhehlOfk5kq7mL1dPa/U9yVfx3tuUhXQrzoQZjuNCd4aAMwERs8a4tmNhofmoCb+v3CgmyoOrzkAzVq4KkgBlYK4Ls9Yda0wU56ayEDxusOD10rnc9c2fHxAWRS0aUydvwNnDW6DQjYCxzsD6A9qBB24Enzdx6ZHF1WHpnDke9Ddx7ln2lvYQrOfuk+eIInRkTKFaNN6oRXYhgj7teQjA3JgdBuuS/so5y3cuSDY92ehqSilIk2IhH0Om2qD+TuE5d6QT+yqRmO6uWMb3qtkDlHcbSJ7vGhTlO8INyU4MVC58zyXFho/2xXMRsEAE5VdZolseuizzywn7Cx+GLDxpBnOJyq81kC6INA0LfZk52/e2QDBxqUjvvUMO3LRMrqAJ06omLGx6CUQaDwYaJTNzqB/dWLINF3uB3cnYC/GaoKYfDfaqFMO4tIrCX9Msg0U7j57GF6BYkMraqobENXF42K9fjGH59D9hK9t33UMQWahsO3rmXxXvaMgbwLjjp3tVUta+cUTq816fhis7I1i6vIG2tSyy7DGKMVbPjAVA9edh6xdmhLrDuWEv0Hdu33fOdsocg2QLwzSF6apNnuFRzj05Z+mRYCXqvNc5+Akd6H61knHnFL4F8fdGXMo0G4INLukFYjmZgzD4zy0UzN5mRSFqK6tqF1uDJrfUtG9WnhUEZEOHEWjOirCfqUCiKpMPNO7QbTMCtT35ww8Bu8B493WWhmsl2qnkra5i964IBCywZA3zii6aa7sVnO8do+QonUncZYFsb3f2AbVQuud05L9pR3ngapkWtDL0V698wI6pHO7qOZ33IOkWDgLhPeqPyF5b+Ia78ubzQsprNkrlOSdw6Q== 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: jM5YkDiux3eiBcHDPxEEXNzKG6+JttBGgWwebKMMDZ9yLcB3m/qgZCLxeII4Osj8WAscf8qFanGbSZSzNBcayvHJ3d7d9M5+OPRBjTN0a1Wqf8uVPsO/hlzilfFkTLKjYEo91Zd/ZhhAStNqaULMBK5dgj50O39swkb/XZ2re6dVG+UamnPyNeSw6rMhZg3CJeeriuQV8avSL6FqEQKQK4ks0kZCG8mNJmkp6QYXCtWpd5XavsVoV+MqJYOX/t3r61Zp6pSZKEM4EZYUxujDP/V74+LWXn8jZARIf//l5ST9BoNfWlNIB/8VbsJftir+okaDE6vs7SN++DYDTOfiEot7vJ0N0cwiqthA9+KWwQYQRGGqzKvBLp9WScvw6U6MCliU5FbXMrS8+zYWMu5ATb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Hud9i8QnVN9hDVw4AmqnsHSck2UsgKNVDFQiRYeM7DA4YcQst6l3WgwDJy6h1bxdItLSbK+qxAL2AgBVfLbdv5h8mI1WlD1RrFCN6SnCT6mwc2Y5VCqEvVqcDLrSMpcv2+NK5wkc4z0+bhnvGA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: mzVXgZd9T98gGIoSSn+G0RXyOGe0ZlaFu9KASeprhm97P0j9B8XVpU4LtwCQ9yxhhYsh4g63ajlHqbPj62kRkyky0Mimem0EEXxzpU88Hy/a+2W7FTGfLuXmDVtTlVZSzo7HSbkM7rvto/Qb1Sot9U2HBAuVRRwAMd9ZJA0bKiKWend05WrWzvmjV8JWFftT4In6CSyOyGgfyWchiAS8fG11+geDKXTswSDSDCACaPUmu53o9m5xRsTxbyf9akBTBPAR3atUXr2qqQeopE+UCTGTXDVsyHWmkeDnBQE4nXXsmoXzMTO7lHjvMlGahIgzlih7LzQOgIdQu1zOYo1joeJS7oSHc9VJEMtQELE5xeKxc0M94WeV0NMK0o7A85eAiWp1lRHL7FAC0X3pAKfdV07BRSVJhfU9HVBOPjJWU+qVBpwzGtnmLXLyAJ7S71H6C5xDZw2MYCTAf/fc2CBLIfEwewUzYeXNDlthZA+e+IZqVzuUPZD/RLkWK4J0/5aS1/mlUklsnoUajIoWx4bmAZLr/AcRBXI1uij58IL5JOnn5WB4TQUpthWn8Fnj3uWKTItRJrZCfacD3S0+VL2GpN828hz9zbYRZXM5K96g920= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3ae8b363-e916-4b4d-9134-08dcc91f1685 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2024 18:10:54.1060 (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: y2Wb7S+qNSSbcUYNU1tzMID2U4tJeq1TTbB7p7Vyz/hXtkB+H8vqJ2SMeLnxe5hAzMGrJmaULfKdNj9idF/WZCUR0JzalVcL9Wpq+s1Frk4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB7276 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-30_10,2024-08-30_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 malwarescore=0 suspectscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408300138 X-Proofpoint-ORIG-GUID: gXbHQI5WwrIcY9G3Rmoid2i5UQz-Glb- X-Proofpoint-GUID: gXbHQI5WwrIcY9G3Rmoid2i5UQz-Glb- X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D736D20011 X-Stat-Signature: tamesnkjktxcc1smfipci541suh14bym X-HE-Tag: 1725041462-860745 X-HE-Meta: U2FsdGVkX18pEkB5BDmJ4QyS/8ccwoIAswlZS8eqF4fZNvNh0so8o/b5IQsjo5NMNq/r/a6xkbRzeaQ27wTfvJqnd7dzmzglJFSVSv/B0EOvEHpmGWuas0UEN1u9oKuJY5GuS2JHTOplpC/EbM19Zq0VJgjysv3zXYylIt2Mgfi2K+Ty4G0x6R9H4mhyiUIhs0DCYNyzcPN59gCssCD4EWshpnFbELxbuVOtIeIoktBE+bHRuV3rCoNnn3macnGccIkfCD2Ue1WVTPhd3A4a0jxSAUnwltLKMymHDb3ophX5TN0B9M8AyrmIgb7/BlWUWr1K9Dr2TiQUKmLuxTNsvCjg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Xk8XOLR2j/chqcGzdk7sAVbWC37wl9XWlv4jdXHnMEOAaZ4EhfqzYPeWiKuzFV1vMB6wASO13vZVbjBlMn76AksWXIILgVWtT+l7bNeClvYVGHVg1DsggcBn/66oMJuusctzdX56clSANv/mKA== 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 | 508 ++++++++++++++++++++-------------------- tools/testing/vma/vma.c | 9 +- 2 files changed, 264 insertions(+), 253 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 566cad2338dd..393bef832604 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -587,29 +587,278 @@ 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; + int err = 0; + long adj_start = 0; + bool merge_will_delete_vma, merge_will_delete_next; + bool merge_left, merge_right, merge_both; + 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 if the range being modified is neither at the + * furthermost left or right side of the VMA, then we have no chance of + * merging and should abort. + */ + if (vmg->flags & VM_SPECIAL || (!left_side && !right_side)) + return NULL; + + if (left_side) + merge_left = can_vma_merge_left(vmg); + else + merge_left = false; + + if (right_side) { + next = vmg->next = vma_iter_next_range(vmg->vmi); + vma_iter_prev_range(vmg->vmi); + + merge_right = can_vma_merge_right(vmg, merge_left); + } else { + merge_right = false; + next = NULL; + } + + if (merge_left) /* If merging prev, position iterator there. */ + vma_prev(vmg->vmi); + else if (!merge_right) /* If we have nothing to merge, abort. */ + return NULL; + + merge_both = merge_left && merge_right; + /* 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 * @@ -757,7 +1006,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; @@ -1127,249 +1376,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). @@ -1389,7 +1395,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 b7cdafec09af..25a95d9901ea 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;