From patchwork Mon Aug 5 12:13:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13753564 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 A6409C52D6D for ; Mon, 5 Aug 2024 12:14:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36E346B0093; Mon, 5 Aug 2024 08:14:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D0D16B0096; Mon, 5 Aug 2024 08:14:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D1FB6B0095; Mon, 5 Aug 2024 08:14:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E5EE86B0092 for ; Mon, 5 Aug 2024 08:14:26 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9FE77402BC for ; Mon, 5 Aug 2024 12:14:26 +0000 (UTC) X-FDA: 82418084532.29.1A9C727 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf18.hostedemail.com (Postfix) with ESMTP id 55C6D1C0025 for ; Mon, 5 Aug 2024 12:14:23 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=hFG5uhTE; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=yZmGKP39; 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; arc=pass ("microsoft.com:s=arcselector10001:i=1"); 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=1722860056; 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=xPVfZMBmeBkMSApfG27V76GTAsKO8+FIQyoz1mo9i34=; b=qRKCEjgyUxE2QB8973rrKlU6LWxHr3Ihmmp2ivd9fY9ZEbJX3F8W2I7TaO3Put2y5A48tH NKsT1dbWvEfRlT53r0rEl140Ab9j1/zgp8qPZ/7VRr8oUnwaJJTMkQ4oGWiPfBexkgB/KR BVgKTgkbihQIiwfFKCkY0MGFp69q06I= ARC-Authentication-Results: i=2; imf18.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=hFG5uhTE; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=yZmGKP39; 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; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1722860056; a=rsa-sha256; cv=pass; b=IccM2weciyjWoqPFiC2H79HagntynivA1GNfupz9VSLh63i+6+rHWoXcPMKzbyWhWHTBDb oljQ3O94a+gCAhRrUP8WvW6wAFW9/Zx9TJ0h8Q+IXfCgM2L05pTG1w03YHbtejha+A7v1U hrNKcq7PnoPHjseNeEFemkSfQQ78CxU= 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 4758fY7H026858; Mon, 5 Aug 2024 12:14:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=xPVfZMBmeBkMSApfG27V76GTAsKO8+FIQyoz1mo9i34=; b= hFG5uhTEmSuYUQj53nSsPXlbIcX2Gagk9RIZcqSLCq4mkh0wse0RoNOQdMIy8SUb JEXv7rJksmN6k0PEZwyZtegG2Q5K2FF5XVkVQk/JYNFnZiP/NrJvHJHeW5jfVOl5 PDUzZwIvudnilsL+2r7TUUJK5cxnsV8SnKi7vLzt3hKnf1aWiRDl0mV01sEwHkem E61zBZJlTG0p0aS9TGHil2zBXo16lKqfLKs0Uzx1ojCmaTHiJhdEdDqmyk7BR8Gs GaHuDB17nD3PUE90jn/GwjyNfCplJn5gpkwWMHyuSBULtEVxPuQoCbNm/xMB5eqb wO50ij69ClikHGoxJv09Xw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40sb51ag8k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:22 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 475BblAT019380; Mon, 5 Aug 2024 12:14:20 GMT Received: from nam02-dm3-obe.outbound.protection.outlook.com (mail-dm3nam02lp2041.outbound.protection.outlook.com [104.47.56.41]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 40sb07636y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:20 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IDICeIVefwlHhxkp5mUn/Vzbp2Km8tGIcfHg78gcUhN03zgScE0NJowUFMQEstBXbTGO4HRA+GZKJRVXNvKh5M5v1PBT0pf3pOxYJfiUDClJ0V59BotioP8wABx/id/ajWkI0ac0bkXNgf1QMguaFzB8E9Dg58XaSF0OIn74C5sI9edmA083dOr5J8ELrFkByX3LlNARhvo9nN3r/KH1qRVd6MdpX8xSeppk8NdDFBlNXkSh42xkmRc8xMz5pvX/Mlproc5Ddgi+zOXii/b3ygTxYpaXLmRIRXAKqkDrP3R5C5SDZcBHOJJSwLHZPaI5vY4eTnAUauevsRi6C+CohA== 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=xPVfZMBmeBkMSApfG27V76GTAsKO8+FIQyoz1mo9i34=; b=uJR4efBEi3bbbfZPrp7n9SltOeNh6R4nnJma7S/FXtzA3K555RdyOp9PZ0EukqOgNsBQhX4iNTTg7pNioVASPxrHa9Mq3RqveTzOcZWl3G2n0OR68o2mQEORndtsOP0ZQcR6MFsXysw3KtEdB7cCg0/m/4JQJtpA1Il6t7v8nCv6sE05hnPAjZ8Mp7qxTRshe7ZuNwx1DhNHorIsqvyDJMb5x8YZtNGqe4+fjX7QpX2bJV4Mxd8dGWxdHPoEK8PSJCZAuQawwpSQa0QE+6Q732vX9Pj0AXXjIyppoluD9Me/mjb04fPgXQqTs6yIUd49f32qgyUgHdneDphStmy95A== 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=xPVfZMBmeBkMSApfG27V76GTAsKO8+FIQyoz1mo9i34=; b=yZmGKP39hzKcCbyfPE7/3xRaNATskUuNudM1KnxFhwp0Ub/YYqHdNzEn10QBZAYWwVg+A6jQYk+xCJvd7WGPRXjy8l8w7Db1qISUp6vJ5LeH6cwDQFZFkDCx0dNMTskXnOrRliKQRJQdkmMJHMjx87xGepdkmUKGb2WqnSr9Sfk= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by PH7PR10MB6334.namprd10.prod.outlook.com (2603:10b6:510:1b1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.21; Mon, 5 Aug 2024 12:14:18 +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.7828.023; Mon, 5 Aug 2024 12:14:18 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH 01/10] tools: improve vma test Makefile Date: Mon, 5 Aug 2024 13:13:48 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: LNXP265CA0035.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5c::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_|PH7PR10MB6334:EE_ X-MS-Office365-Filtering-Correlation-Id: 3d26be53-55a8-4abd-c00a-08dcb5482163 X-MS-Exchange-SenderADCheck: 1 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JXDyy1sI0ELzZ9SvfEgJfbrvQz1oTFiqFJHe4e1C9f7Po+1shoxot4v3QO3dFPGY/4414b2qJgn1rqYbiNy82ura86xJo8uJaF9XUdG2dW2oLINIoGf61Ig/5IQbfsHv9CA5wzYKRsggQCm97GPCnKrIznQwcvZBX1avqqp1GLzRSo3s2EkxDBOpItQzQJyWba9C2NCDPPu/a3RMOu9ufGdDD18XuJz2qydCkKy9SFQoLN/4oSwlydFu5QkmCR1MxQ4U+A/KJlSwsi0EixF1Sb1gYzB3yiMOUv0U7g5Oda0SxgY4nFamtCnAoXcDSMhawXVkYy1xn4XjoFMDLMbsHiqtDnz89p7if8sc2ZR8VNi7y+Er/A2nBxAg== 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)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DotA/wRx8dNyiriAmdztSwex+hffdlBWJOFsDoUtfmnY4cT53t3GJDB9MDj3Cbji7ZgnJPFVWmcZ7FXM8tMcRecXWu+WOlfV7r+btKRVGHyxAdbRm91dzwwdDdpTQLRsQMfMex+1Fx3VfnYVcUdyOs99Z5LBsAoQQIdlMtx6IxoFXFIK8vqaBeHy7VozJzXXERlDOk3ebbnrTUO7s3fMQTWVPTgy/fjD2FNTecD27WbacOlcd2ROIEPvJVzXW5m+XVjyKYiR9N7mmnFerPW7KsL3SYE4f0ENRpktwxrXL7d2YTAHpH0BVegUNQuMSDBuEtMG9xWUfURMjeL+QCoOzqkvpUCXQP30Rb/PHy5DLMdnwUPGEWaACKC0Sp5jWWjvsdf5SVNDVzRbGlK5HgR267TahNW389yc4GgvfSRbK7kCRobBuG+ZJRhxCN8W+jQvTRH2Og4Oycn3fK7Fo5jIbkvJQeGWHjbURnV9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xsGQOgfxXdeM9IInuMuBgZAU8/+DKvYcGj4HXUj6J+Qwtulq6dWb9DPwbQf3AbS1GcljfQgO602Q4IqY+FjWAqYFm7r8BTcY+UuND38+EWwvE5bEcemQSZymUFUpEJLo8E0Q2ZlXO5+W+pZUS8jVmQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: DySqunF0K1f9MGc6uMKju+/0CEdJn33oRb0qQuAI9SHbSvsO2eOllUE1JL70hrc05+zYYtlQX9bGJHxzXwtw4RlVPF/yXHihADLFK/9n55gSRTyEB8Ol/AtZvD+lEhuibX8qiOtb3EdzyjsZXkmVmRUONIy2pQHQiQ1xNT+smclQf832aWrNbGsIQ4pEpRbc6HkvLPjg3HfGp0oiwOkCmzR/kP/6m5f0z2cVtaIHw5Pm47SAlQ7gAtBX3gq1SA7vfQpoKBdfkuY6cJP7KkMl7xClaFiGoAXDn79xDmR2TVzYeMYjzLeblClWaSaHryA2jRZdadCdk/nvMvyxDkFqld04UIfYSKzIrXIR+MXbXSK/swf+dvBB1Lfp1O7liPUabjyjxf/nuLf229UrtByBOloLFk6rgTfG9Jb2DNdKqq7uHu96ZN7YN4rqQNCd2lYj1P9z8cdvThlpzfIJM5HAre7m431iomNJ1XUrAjftIDZsv+9VEZoo1UX/PSeFUCvfabfiJs856nELsc7c0LouncEJWKUW28kvdDC9A+WG0iOPUsDsgkADTEdqp5yJXN04G8SGFWFzws4ZMA/0AfP8amLZLm/s0JtnjaJN2Fit4Uw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3d26be53-55a8-4abd-c00a-08dcb5482163 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 12:14:18.3118 (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: jorO/eS+ufFJDJCcHGbT9HboOgkpbTt54UrlNbAeNBlotRsdgEA2Z8s3AtDXFW4CybXNASOetFHlPu2jvGUXbNFpC7lgh9sod4vxdoz9jOU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6334 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-05_01,2024-08-02_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 mlxlogscore=999 phishscore=0 bulkscore=0 mlxscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408050088 X-Proofpoint-ORIG-GUID: hgh56i-89_yD09LipcpdsTQ4svZokiqZ X-Proofpoint-GUID: hgh56i-89_yD09LipcpdsTQ4svZokiqZ X-Rspam-User: X-Stat-Signature: o5gamc6bkwbnr3ytb8tfx44wcc8co69w X-Rspamd-Queue-Id: 55C6D1C0025 X-Rspamd-Server: rspam11 X-HE-Tag: 1722860063-92208 X-HE-Meta: U2FsdGVkX19tXR5QAW62Dm2e9QiZxihBuOkvhcrEYq686nC6JHnxQB0uwMk05o7Ufd38+GtfPvKQ384LYylPg5HkN7efzbyRfhSqpYbPTKodjROkpGZ5iOb+ZkL7d7tqiCAQzQuinJzrTBzBBpIzXQrprAN8atFSgQAymX9ke8b0PA0/K7Vri7rNCVLvDDpnsDvbKBfptgYfHguJ1BHe9pVMMLFvxsWKCqa5xLbf9GpuuLD3QbJ9PVdmPeQLGl43osw8iyQBxv3liXNqSzopXOA7cEaBZCEAPfGlEaeMP0b0irj/thmA0h7qHXTfCRnY28HhsTOvOs/8iMaHQMGYK+Tu9wuSkz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mDxZWemXPSmTvVOnyW0udw== 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: 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 --- 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 Mon Aug 5 12:13:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13753565 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 E4A99C3DA7F for ; Mon, 5 Aug 2024 12:14:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 716E56B0095; Mon, 5 Aug 2024 08:14:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C6256B0096; Mon, 5 Aug 2024 08:14:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 42EE56B0098; Mon, 5 Aug 2024 08:14:31 -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 19FB86B0095 for ; Mon, 5 Aug 2024 08:14:31 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BD5BAA8856 for ; Mon, 5 Aug 2024 12:14:30 +0000 (UTC) X-FDA: 82418084700.09.345E8FC Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf14.hostedemail.com (Postfix) with ESMTP id 6280110001D for ; Mon, 5 Aug 2024 12:14:27 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=VSD+pXdz; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=BrhTUnVq; 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; arc=pass ("microsoft.com:s=arcselector10001:i=1"); 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=1722860060; 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=71E9b5edNWehB4FWBwOo1wI3c6T1Io1IcU1kzN9o+1M=; b=Rm8vtJC6gCDRu8bLtjWAhVPMTl+jCkfJx5cxwfYRrER1cm7MJUn6WltGJ7jhW5kK/8r6r+ tg5rKfhIHTmYx+jtpEhaZmFlXHmsx135TKxokAD/wW+e+/M5xwAdgUJB5NqRgbO8312HjD TTcqtJKWffKyJw0VztBL0oV9FjvyrWs= ARC-Authentication-Results: i=2; imf14.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=VSD+pXdz; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=BrhTUnVq; 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; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1722860060; a=rsa-sha256; cv=pass; b=10awR52tCw6nPnxWMlLm6hQAzfAqiYfZ61V8Vn46c9vHSmIeM9WH16Qsc1Q6A9lNz1a3Ak jWRJ8nzhrFwb9A2O3JL4o4bM7d0R6ccqD/8liPG1l4GuCP9c3WtpQqodOREBDz39Ywj30v z+08ByMn1Y8TQoYTLgwNVYMci8SZS5I= 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 4758fYm4026878; Mon, 5 Aug 2024 12:14:26 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=71E9b5edNWehB4FWBwOo1wI3c6T1Io1IcU1kzN9o+1M=; b= VSD+pXdz3WGvtzSqfd1wSgWTBLnR1Ox2qdN6EglmfI5NJPuIUkDQQUGXcY1lhTsf F8vcfiM6B3bwjyub+/DrHO5oF1NTvV15jFBPP8sShc8ea4lB1mZYvH3DENbylZ11 EjtncaKy+VnZ1K2vQ7sNGaW93//kBYltG8jhwHrGHlFGggZgUO5eUCATjqK9di/+ 3bINn4vy6hRKB4Y2sQz102Bg3b1JgVDoCNQ2BYJV9AEvLAmt/c1dDbiBoptqvGbg q+GNqT5fv++U42lc8FskocJYy7VSKSsNbB3YW7Uzk2oCKFI70YPHwi0OcVGATMaY e05f/OnKjcUB5IGdvDA83A== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40sb51ag8s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:25 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 475BThY8018392; Mon, 5 Aug 2024 12:14:24 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2169.outbound.protection.outlook.com [104.47.57.169]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 40sb076p0y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Zr7zbUalMXaXxDWCR8qsSKLkqoQqipuNx4H++hR0Rkigv2DFeOiJBnq7zK6GLhaoSmWeD90PCcqXcrVA8Bqq4ta+0F8rsoNaANConqaLDg/N5/QVoVDY1jPU9UbsQqK+tNMTdULqy6t/zJ+3/LFxs1rQYbuNWTnWUjrl0nfHy5NR/3oB/HCRk/S7Gzd3o7ZbxAxvNlEJVX5fPHcqxk/dnlnsExTKm5OvPdPdygwijSZuFLql3psR5ELyYsT+iDlWDiRffVV7CwVRaia7m0lXBGiu9oyYCLWlsK08aM9PVGTy9UqObpih/vknsaQQqBDLmhrkdmDfdpMdN6WWsxSJdQ== 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=71E9b5edNWehB4FWBwOo1wI3c6T1Io1IcU1kzN9o+1M=; b=PSzTVwMFC/ZsRNPE7MrRIP5cGv0bUUPxRn85Lq662WKZpVZ6v9rhDBElqyHKED+Regg8kH98g2ysqFSn2DSqJwcGOKjlKaUesCU6npiZ0DTdZqd1qmL4UEs9v9A5MLlYt33eypp6pqCItaeQ1rD0Nu6sKKIhLOVtntVflsc+CwkOR3TOlTX8G/gxvUn9h6MPq1Sjxv67XVsLyqgDgNUc5CKJdq1SbaCkZ91nPijWjxu6C5TPQJkXbApBNRTkq9JkFZ0rhXHnROjAw/JiPmUN2yx+P/fzqTW2ndZNH+4RBL+XHr+oV8iROZnlUy84b8cAbPFaHmkIRTigvec+qWIfow== 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=71E9b5edNWehB4FWBwOo1wI3c6T1Io1IcU1kzN9o+1M=; b=BrhTUnVqhsJGkOI4D+qIWcbaOS1JW1zbRLxYNDEYpZHo6FuF1fM/WhNM8cb/aZUI6weqkWEIFZMcQxL4ur8cj1CZ2MEaH9UzBlZ5QT2uIHWqov60dB+TuUp+B0FOgMN00L1Xio3U3/vzqww9rWKj6jKWuhwcMNuBBgXfTSpigm0= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by PH7PR10MB6334.namprd10.prod.outlook.com (2603:10b6:510:1b1::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.21; Mon, 5 Aug 2024 12:14:21 +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.7828.023; Mon, 5 Aug 2024 12:14:21 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH 02/10] mm: introduce vma_merge_struct and abstract merge parameters Date: Mon, 5 Aug 2024 13:13:49 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: LO4P265CA0269.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:37a::9) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|PH7PR10MB6334:EE_ X-MS-Office365-Filtering-Correlation-Id: b28d68a4-e08a-4dbd-54f7-08dcb548233a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: s/c7LxiklbaUwb1cd3OJxrXRTEwvM9MeT6g7d80qVlaFq3Ze2XS7lSswHNh8k4OmOY88zQQVBng20M0xSoOvSWXM29VqkPj8aMOQ5WehuOBLn/KHkq9HY6vsMMfks4rSvzw2Rs0Jlj0zyhU5LXwhF77Q37LfJaZxuIu+Xf4ZH5LnvIUnKxcoQsWz4i7/iL2fvGQWIQfA4x3vlBcIbyqTrEvuqlkwxF9+msXRxByoOLJrDMddL9r2sEt2m1poB76ptNi5XoXWAszWc50NnOVU7rXEiXa/4Rw+dQ1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2TQ== 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)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VdoOPPZAvqJPjeQvGKjU/kZIhJpXWGoE+PmXkPSd2cC8Oc4BR+zfluQJoQzgGblZoNh2fR9GX/079rco+lUKFfEch6VCy2ptnLggEn9F/33pMFvssM1AiRWjkgjtdjfUBB9ujWL8MJf0/olwaxpHtHcOtY9Tx4dKu1rGooSyCncwjc8nA9dfSFa90pjSvxzbh1ix6mszDVpSrxrfSIjInjMAFTfs8WFkr9cHiDBrTGdO5KdoOV/xAOOPxXEaqV3tNH5OlN9MFMIL0habS5AaQwY6dvX2vlPZDnxc7Q3tDAKWPNZkP8ALVfpBBr8avBbS2CpYNirxE9h0ItqBMyyjHzoI3ASFvjQuw5kMAzlOmPAgZQx8UljuWFdjBpaZr9l9RhhWas/wZ/aa+Suev6BRZ5dcpIUy8a0zklELPy5yd6fLXmh8dpu+iR5cU4AUjS17ZzMsEcvdqMnYtyLp3pW0VuPLwGj1CH2BuyPCNihfGSgmnTP2/fJW36fgqL3ohfFUqfIXPSswP8mkhAX6KmxFntgdhKXmT1mntzwILaB9CQao4gN9nVHN3fneu4c9FfItR3ZZWkxaj+d/WE4Uvnt4i/ZQeoCe8aXpFhRLqvj19OwDY/ADwQsAVY+ddh1Ebc7Bsz9hR7jQuVs7yIz15gXt5jCxBz2Focius6K4IoXNRCEs+/oHcdg1epWf3BUAuX55V0dQuWz1sZCJkOR2I7EfxN4T3OEwKayHDyMUWHYfidESiVREv5hYMYKbo1ufO7vwCJ40EmKM3BXDcjH4lrgwKX4PqRWOhwML/gj008o+IxuVcqCMVjIDarHpZCAJ1M8WDjIW7g5en1zC1NQbQFChtLCy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q4M3qLJyag08E8vHalGgl/9Qisy50ROOttsdfjhYrbHKqWmnh+vTkzJ2knmoCZpTzBzTPxGGXQGcvmNzO7sm3smkkAEiksP3Ym6kfzN4oypQ7Thg8CQ5MVL74WH2ckgFdBqKq3euXC7FWe204X6OXNfJLo2R+zG2Q0faRR9ob3sov5mlDGgVtY9+rT4avVrSpxSrTMNSud96A/v9yMUENQiNL/5amsjMV2UNpe5JKY58rDGORs7SMIAz/AcKukmwTLZrK0ZV6MO24zsNVauURIrvsC5ObJ4iPkBItkq55H7wbKeSvTSBJ39cRhRFseLORZpTO4u70uRo/wg2p1a/m1jAnfY5jgfCEy5VKoDRqQwydncQjcZrAl8l/wPj2blRWbW0YvuO5flb1HLHHhWaRp9GyusIbHt/IWhEN4xYx1dSNzK0xD7yIq6ylM= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b28d68a4-e08a-4dbd-54f7-08dcb548233a X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 12:14:21.5495 (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: egEw34IgoPI+tPzL06bP39A975SqH+JUcnV5ct/5ot/qg2bEJSR89fpUAEX7KKCuZ0oM+eKdSim1SIcbkfQ2Ts2Fcm3ngwX+YcpBfNnjsio= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR10MB6334 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-05_01,2024-08-02_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 adultscore=0 mlxscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408050088 X-Proofpoint-ORIG-GUID: RqmQr-MSIXTZFaY511IoP4Wh8HgbH461 X-Proofpoint-GUID: RqmQr-MSIXTZFaY511IoP4Wh8HgbH461 X-Rspam-User: X-Stat-Signature: 6z4zrs5419d99rfz19aeeqey9ihqzsne X-Rspamd-Queue-Id: 6280110001D X-Rspamd-Server: rspam11 X-HE-Tag: 1722860067-603723 X-HE-Meta: U2FsdGVkX19tsOZ6niG+4Y79psO4hC4LRk02FHFmFuyJuPLrs9szm72OL8rypF3z0efvQkJSCDaEaxNsMWdKW1fSXALFITaZrbY5faKWhKqq/d+fE+lAGvKy+jaJNwVGZ18Kp47lYHwM8cONLFcWfRYvKUoYdNWGxYZToR1cPKHEDnlI8/TvOGZSCH0UP3xF/l4aKVy/YxeaJq/Dv2wwPoOj7L9DceIUzjdZ5HC9hb6MYCcv7xyT3BGdllLiC6BiepiI1TArwgxXAlv6WQ21l1Xuklj3gfSNNrf2yXZwn2J2Cq99K4nUFD6tHskBcWdssluTmYiFKiHUTnovywd5J67Uz3SLTucyP+DvxGAEBH9hZh6u2UhgktfCKN8yc749g84WPtGrOZ5nsXKA3qPpyw4cJUDwnVVWkFZyNBB7Tg1p45bKUN9vA+3Cea5FuGPIA4ThJ0S+dD8GOS4CNJrfCdODV+FXj8AFXiJsV0WiRciWAUNz94e0UcNM1lpHOZIHkO7zLjkJ3yMYz5zBrhpq5SMArflWMQM5O6tgLbRXzF/SLZIez10M4UrPrmfZeuNJ3ekgESwYMShaewgSOkIra1soi2WsgNxB4rb99YjAqqHtJQmYhRIHjMsPtwbDcvISh7gpUSOLs6t0Xyu0ymz5a1aEYQK7+TbZOzLrgIOkMN4lM+mOrZW9ZiJQWDtsTLqBLSNlYNcIFBXFrf0chMikNK0YOVfZzySszSB5AChoFfLSoUHBhLFICoXNiWogRV0l36p0fepz0OygmXb1IKBEIkuI2vkfsRnNF5ojzcpw+HoS1Yp3UeZiPWUvPVSUpxnvMjtsQjgJ+CzLRGlojszyPHNgHFcGdyEJaGTcsA58JoSnYDy+wXzNq6B9sJ8C4HrSwLAX/Ee3SxBsbmAAJf1FCa11YWoJX9qrSSTfHf724+oVQ4LlLwB5fqh1szLWkHpbujv2i+Qx/pTb3xRbmfl ppdCOxQq OklJ3JEYpO9qjseAC26H4zuFfh1SwMLeZvVhIwaWoNF2JicOOK9pulKTNlO1AChFskccSwnpW4ZKRIhdoo3WwfdWwnNglpfPpr9muhh6jh3pdBAOHfXysHQqNNTwYsLjoRWnUg4N09XiiwSfHoN4DWsyGatxja+il+52U6xesXPKW4kCdawMqEJVharrUPTtaF1o+Z7LAX3TFoWvMsnrlTtdxHNijfdD1G6Qc31atM5zxznp6Nxvx+1jMghy/71L/uj9owufOJk/2phjWGYDHsej1UqXt8RrGUL8XKgJMrPsEIF1cO+nApBxk467SpLeEgE4e9tzasFjjjtotJTzVZryVcmfUra+m3GcMi5uPUIFhlLDKH2stPbqvzE6QXsfQ1JxSnosKXvHDW41dFf4cjs+bAo3kTabi/gpS0oyCPKf3XwYs4WB2uvxkUoXwBI+p+yCx615opZ3Bq5efFVaLKFoZwQ== 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. Signed-off-by: Lorenzo Stoakes Acked-by: Vlastimil Babka --- mm/mmap.c | 76 ++++++++------ mm/vma.c | 297 ++++++++++++++++++++++++++++++++++++++---------------- mm/vma.h | 92 ++++++++--------- 3 files changed, 294 insertions(+), 171 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 4a9c2329b09a..f931000c561f 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1369,9 +1369,16 @@ 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; VMA_ITERATOR(vmi, mm, addr); + struct vma_merge_struct vmg = { + .vmi = &vmi, + .start = addr, + .end = end, + .flags = vm_flags, + .pgoff = pgoff, + .file = file, + }; /* Check against address space limit. */ if (!may_expand_vm(mm, vm_flags, len >> PAGE_SHIFT)) { @@ -1405,8 +1412,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vm_flags |= VM_ACCOUNT; } - next = vma_next(&vmi); - prev = vma_prev(&vmi); + next = vmg.next = vma_next(&vmi); + prev = vmg.prev = vma_prev(&vmi); if (vm_flags & VM_SPECIAL) { if (prev) vma_iter_next_range(&vmi); @@ -1416,29 +1423,30 @@ 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; + } + + if (vma) { + 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; } else if (prev) { vma_iter_next_range(&vmi); } /* Actually expand, if possible */ if (vma && - !vma_expand(&vmi, vma, merge_start, merge_end, vm_pgoff, next)) { + !vma_expand(&vmi, vma, merge_start, merge_end, vmg.pgoff, next)) { khugepaged_enter_vma(vma, vm_flags); goto expanded; } @@ -1790,25 +1798,31 @@ 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); - khugepaged_enter_vma(vma, flags); - goto out; + if (vma && vma->vm_end == addr && !vma_policy(vma)) { + struct vma_merge_struct vmg = { + .prev = vma, + .flags = flags, + .pgoff = addr >> PAGE_SHIFT, + }; + + 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); + khugepaged_enter_vma(vma, flags); + goto out; + } } if (vma) diff --git a/mm/vma.c b/mm/vma.c index bf0546fe6eab..20c4ce7712c0 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; @@ -180,7 +175,7 @@ void unmap_region(struct mm_struct *mm, struct ma_state *mas, * VMA Iterator will point to the end VMA. */ static int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, - unsigned long addr, int new_below) + unsigned long addr, bool new_below) { struct vma_prepare vp; struct vm_area_struct *new; @@ -261,13 +256,14 @@ static int __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, * Split a vma into two pieces at address 'addr', a new vma is allocated * either for the first part or the tail. */ -static int split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, - unsigned long addr, int new_below) +static int split_vma(struct vma_merge_struct *vmg, bool new_below) { - if (vma->vm_mm->map_count >= sysctl_max_map_count) + if (vmg->vma->vm_mm->map_count >= sysctl_max_map_count) return -ENOMEM; - return __split_vma(vmi, vma, addr, new_below); + return __split_vma(vmg->vmi, vmg->vma, + new_below ? vmg->start : vmg->end, + new_below); } /* @@ -712,7 +708,7 @@ do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, if (end < vma->vm_end && mm->map_count >= sysctl_max_map_count) goto map_count_exceeded; - error = __split_vma(vmi, vma, start, 1); + error = __split_vma(vmi, vma, start, true); if (error) goto start_split_failed; } @@ -725,7 +721,7 @@ do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, do { /* Does it split the end? */ if (next->vm_end > end) { - error = __split_vma(vmi, next, end, 0); + error = __split_vma(vmi, next, end, false); if (error) goto end_split_failed; } @@ -934,16 +930,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 = container_of(vmg->vmi->mas.tree, struct mm_struct, mm_mt); + 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; @@ -953,16 +943,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) */ @@ -970,27 +962,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; } @@ -1041,7 +1032,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); @@ -1081,13 +1072,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); @@ -1099,19 +1090,19 @@ 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); - khugepaged_enter_vma(res, vm_flags); + vma_complete(&vp, vmg->vmi, mm); + khugepaged_enter_vma(res, vmg->flags); return res; prealloc_fail: @@ -1119,8 +1110,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; } @@ -1137,38 +1128,141 @@ 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, true); 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, false); if (err) return ERR_PTR(err); } - return vma; + return vmg->vma; +} + +/* Assumes addr >= vma->vm_start. */ +static pgoff_t vma_pgoff_offset(struct vm_area_struct *vma, unsigned long addr) +{ + return vma->vm_pgoff + PHYS_PFN(addr - vma->vm_start); +} + +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) +{ + struct vma_merge_struct vmg = { + .vmi = vmi, + .prev = prev, + .vma = vma, + .start = start, + .end = end, + .flags = new_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), + }; + + 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) +{ + struct vma_merge_struct vmg = { + .vmi = vmi, + .prev = prev, + .vma = vma, + .start = start, + .end = end, + .flags = new_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 = 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) +{ + struct vma_merge_struct vmg = { + .vmi = vmi, + .prev = prev, + .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 = new_pol, + .uffd_ctx = vma->vm_userfaultfd_ctx, + .anon_name = anon_vma_name(vma), + }; + + 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) +{ + struct vma_merge_struct vmg = { + .vmi = vmi, + .prev = prev, + .vma = vma, + .start = start, + .end = end, + .flags = new_flags, + .file = vma->vm_file, + .anon_vma = vma->anon_vma, + .pgoff = vma_pgoff_offset(vma, start), + .policy = vma_policy(vma), + .uffd_ctx = new_ctx, + .anon_name = anon_vma_name(vma), + }; + + return vma_modify(&vmg); } /* @@ -1180,8 +1274,22 @@ 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)); + struct vma_merge_struct vmg = { + .vmi = vmi, + .prev = prev, + .vma = vma, + .start = start, + .end = end, + .flags = vma->vm_flags, + .file = vma->vm_file, + .anon_vma = vma->anon_vma, + .pgoff = pgoff, + .policy = vma_policy(vma), + .uffd_ctx = vma->vm_userfaultfd_ctx, + .anon_name = anon_vma_name(vma), + }; + + return vma_merge(&vmg); } /* @@ -1193,11 +1301,22 @@ struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, unsigned long delta) { pgoff_t pgoff = vma->vm_pgoff + vma_pages(vma); + struct vma_merge_struct vmg = { + .vmi = vmi, + .prev = vma, + .vma = vma, + .start = vma->vm_end, + .end = vma->vm_end + delta, + .flags = vma->vm_flags, + .file = vma->vm_file, + .pgoff = pgoff, + .policy = vma_policy(vma), + .uffd_ctx = vma->vm_userfaultfd_ctx, + .anon_name = anon_vma_name(vma), + }; /* 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 6efdf1768a0a..c31684cc1da6 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -26,6 +26,23 @@ struct unlink_vma_file_batch { struct vm_area_struct *vmas[8]; }; +/* Represents a VMA merge operation. */ +struct vma_merge_struct { + struct vma_iterator *vmi; + 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; + pgoff_t pgoff; + struct file *file; + struct anon_vma *anon_vma; + struct mempolicy *policy; + struct vm_userfaultfd_ctx uffd_ctx; + struct anon_vma_name *anon_name; +}; + #ifdef CONFIG_DEBUG_VM_MAPLE_TREE void validate_mm(struct mm_struct *mm); #else @@ -72,80 +89,53 @@ void unmap_region(struct mm_struct *mm, struct ma_state *mas, struct vm_area_struct *next, unsigned long start, unsigned long end, unsigned long tree_end, bool mm_wr_locked); -/* 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, From patchwork Mon Aug 5 12:13:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13753566 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 1BDA0C3DA4A for ; Mon, 5 Aug 2024 12:14:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A6BC6B0098; Mon, 5 Aug 2024 08:14:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 608A36B0099; Mon, 5 Aug 2024 08:14:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 31CE06B009B; Mon, 5 Aug 2024 08:14: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 0B1886B0098 for ; Mon, 5 Aug 2024 08:14:33 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 82D9D1A1C20 for ; Mon, 5 Aug 2024 12:14:32 +0000 (UTC) X-FDA: 82418084784.12.A6E3776 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf09.hostedemail.com (Postfix) with ESMTP id 474BC14000A for ; Mon, 5 Aug 2024 12:14:29 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=FrAZKxia; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=dcCPAUQO; spf=pass (imf09.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=1722860038; a=rsa-sha256; cv=pass; b=s+uj4CjdWofgqOO1CXwsF6gOSBIdmJ/Xm3t8Yrdy8DDt4JXZPdNb5K7VOqH4zCtVNndkRJ s/RPjewIaEzlhrZz7zqh5yoE8M+UrReC4marvNcV8ifX16qhysUO5DX2Sj6zZny7LUNNFW f/X2bnhOcX59PlzJb21t5+dPKQ6c2qA= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=FrAZKxia; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=dcCPAUQO; spf=pass (imf09.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=1722860038; 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=cETyroPp4Qzekm0Pgwh0kaDe1z2NOaT3zirK2ZeRr90=; b=CPIpnQ7K6fcqmy5PaVLOhmzBMqiOsJeNdtH7fbAC/UP3Zgh/jYTiHLuKl92k6dFWoXCJiC HB8L9TL3Mg/0iE+vL5EJ06l8UBT5mbUcdM5mIBq+U0Pn/DLHEKASW3xnj4qQV8a22yTwiA jYwbr+y39qY0ZlAU9ZLxpR9gpIomn9A= Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4758fZ5E017605; Mon, 5 Aug 2024 12:14: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=cETyroPp4Qzekm0Pgwh0kaDe1z2NOaT3zirK2ZeRr90=; b= FrAZKxiaIAtJ9NI8cdIbp/OMfrllylygsWqz6Cyqm4jLe4wjhaxURLM4J7ppFyIs VGoOiwhUsEmnsUp1RVEgrEJICbX+BeW2ygI0+AncHZhAgBFwrsYx/refv9um/FgS aNzBH67YPQmxpJ4hPNTbbIYyqX/r7HFeyvJttnkPDydy9v3eq5/ZH2q5T8V3fnjg SjXIwyLhCCSW4HojORf65Mu/CD6tjhUWhmelFRV+vGnrY5D00rY5dCxhXD9a5dV3 F3pct9Jr63icUsB7iN5e7pGqTfGFjZYgk/Ogv2ctsOBS4CM8NxBTdDUhe/wPPBt4 m0v/NOoVvTz+nWpQjzzPJQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40saye2gwy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:28 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 475BqNaH027379; Mon, 5 Aug 2024 12:14:27 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2169.outbound.protection.outlook.com [104.47.59.169]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 40sb0dempv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=goYJuHniNDYIh8p/sMuHtEGJf3QifWVZsans0WKyaYFwKS9gN/NWzmrRr49xDbFMHk1M8EH6J1hoNCuAe+jjkSW+bLdoKBQVxGMxQefTrea/RrS5w4RYxod4Ru1cfyGtbHQ5UX4ykvRMI0xwatCE4rNogNypAvcac2LTgE831C35ShRhFY9AabHqjQ2qpBoKgDLv1LtqQIprYBxFGArH1JBukvlLLcK7Hsfuv8DhGQ7pzgw8ySNrzbslL4M4P+gFGKI25TI0pZPIjZAe+58GiFEjvqg+0U2xBlYdwAPXFzKV1640uhZJYDmXRYuQ4izAZJi14+uN23oUekADyqT/Mw== 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=cETyroPp4Qzekm0Pgwh0kaDe1z2NOaT3zirK2ZeRr90=; b=E1XoCIcSkZDEI3BgIM6SOKRrOumZKibMu8hFCk5pacJ3mxGpfCGlA0KjPmWfZh3/aF7NAI2bXHqbPCDzTOs8N3IxKRkOtiOZBMpD6PznwYAwjQCDPRYTbX1pU0p+g7VsUr3TGlndAV4VgsUiE2EEAgP3unGd8ihUo1XagHnvp381B34Z8w/fzqBSzrqRchFKJIsbMgq46tnueJuFlU084hS2W3F7ZnsWPp2puxHCiYp4mhTFpHcjXEJQZyIRJv0hyxDa+2VCq8IvZ/X4XDyRJgIjIeOO/4sgl+/c8KlxdoVyw5JY2SPwWrQbtEDziT5ilotlh9wtvNXboLicyaJEtQ== 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=cETyroPp4Qzekm0Pgwh0kaDe1z2NOaT3zirK2ZeRr90=; b=dcCPAUQOmDA7HkJg7WTdnBxbSD/IFJqaf9KqVvjZHmBPqLEUDO36EFThHlDcn2ooDCAJxhJfxbOJW1WxN9Vyv5OBkiV3Ma/Zrs5AXFMAWA93eXlfnKj1jYyoKzAz1nXuJ44hz6V0H/YlMvi9L5LaH/XrGkR+yb+yPL4IqYw5RUU= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by SJ2PR10MB7760.namprd10.prod.outlook.com (2603:10b6:a03:574::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 12:14: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.7828.023; Mon, 5 Aug 2024 12:14: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 03/10] mm: abstract duplicated policy comparison Date: Mon, 5 Aug 2024 13:13:50 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: LO4P265CA0254.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:37c::18) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|SJ2PR10MB7760:EE_ X-MS-Office365-Filtering-Correlation-Id: 4a236f40-a6e3-4169-c9f5-08dcb5482596 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antisp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0rKmSdpJZiS38iuZpGoqLf2Jbh7XArOPphuYPdyUOAJqywsERyXxaZU5jFb2v5xbd6wTOFB6cOL0h0zVWhQ+1IY53zre8gmSoQ6eKTB0ZVsyJptaqXbVW0oexxmA2FAz6H81jaGTPTot87NPv4ZtobsJCR/1lCXY4KdRrPyFzbDIQU3Rq4ZzBvdeDFbO6ojBlbWRldU2AL9kyrRcK+PDbHwDhk6FNJ/UrqGzIt5vJn/NkBSlE1WKukmLW65Vm6L6PCNG6IClhb7Mwjare9KUVPqUCmCZnvniXsRrdB+23KepphFgXLbm5fwFfo5U+MBCbQPdSzXEDh+p2CbBOIYkzVAO6Asw== 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)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IEwjWTT8nZGdXEIlLgHGEKaD/JKXpRKJkaXwt+DEp/p4DyTvPq0qPqIh5Ssf/pDaPTAJzsHjJUuhV1pueh7Qiq/Wn0fyOvnqLX09PDgysici4fsB+L/BrOXtG/kAv2+Ya9lve1Qi0IEO7m8EOIdXiyfi4IporbxPI8gaOepmWM7tHUs5oJwgh6fMwIWEfLzC2aiqq/Uha6mm5WgBcDrwqOgkqxXDxRtyADloJvQ6WY5SczO4qWdkv8coe23jqX5lXOVgZRMvJW7jzpsxNJP9uzhj9qLFM39eRRS0fzySNN4EFWlx69TLCkIat9ljPWniYqAapZ+TT5adwtXL0SkaNVHaT0tJvQwqYMyeWhVElqdTIySP2zXu5cZBoA6kDAjRLYfame20uQZO1PNSjNqEh/ocMsYKXphZgI8HmVIT9e/h9d/S8CxQowoDknty2cRRieujdMg1JGgV5OxN5Cu440qJiiu4Qi20z+7Uwnssc6eyH0aV/ayPHFCiJJ1kRN3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u1U5yZz+O5IwKSl9Trw1WbQVl9mVkUCHBLZhxVzI8MfifojTUet7PFv1iTHaBLK5XZV4Xft9fGqRQg9vg6bye+x32M4nPygvhvqLe8PmsmuurjZ0jxiT5A== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: lCgpegdqqA7toEmUmXCZQV35o5bm0VL9EL0HOQs+xc3zxIjwrz8R1rP68X4K1B5Cgo2wyCFnTK0EQ0OB3CNeQ9OCbGxtEOI5MRCPFEQjkthPmv8Q9SkVm+NK0wouXRKZLVx/BjUU7o1dnvo3T+LnBPziESTs95COlyQUUUiBmMFQClIpKGSz44moDimhk5FtffWanbuSw0a6ktEhEBXSPcxoYZN3d4ZMW8NTKm4Yt4EMtvp3SNJ5xxBsoRvzA2yEZiRBMO1wGJ9xklhkCecbmwOpvdtv3lM9e7VnfUfoDu5kcJYY9dCkDASKIZMo/gYQhbHweVoyfwyWa9bFNyqYhJoxdkLIb7tGxvWJxysuyjIQCoc1/JHK4Al8ZQBf9jNfxsH9cKPhyKvmgdS/1TkeEn1SfH+du/k3E2pi3vefsWFRxBHsDRlfJHoJTEoe8306aNx7fAV7HkpgaO4gGv0+NZU6sbSu9GA6CGU88FavxZnS9dZFSwa16vD8loHbbGDQaZYRoozMbfnIR+ZCZ5I9M94sxIiXcR7EFi8UGQBCOTtg8x0ypjJpuSmFdLpV8kL5BlnbOynnE47K3KAri6pXmt66sD3g/j5McN993kAAecw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4a236f40-a6e3-4169-c9f5-08dcb5482596 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 12:14:25.3560 (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: v3ZAV96fQ4QKmHOU35lUtYydPyaHVqSf5wyrVDFn7r81fJdiiByq29P4YtLDeW40u4mgYIF4PPfK4OsZELJJAt3zVt5w+VZGXp2BERCmNF4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7760 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-05_01,2024-08-02_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408050088 X-Proofpoint-ORIG-GUID: hceqNbCgZ5VLM9oATMMBfUwVM60Jhyxp X-Proofpoint-GUID: hceqNbCgZ5VLM9oATMMBfUwVM60Jhyxp X-Stat-Signature: xom6j8jd4mcerdwjjqdfc99iyowf8sdm X-Rspamd-Queue-Id: 474BC14000A X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1722860069-173536 X-HE-Meta: U2FsdGVkX181eKdz3SibgQkUOJURsveRbLTY+SSBwZoBvJWTvKtnBZ9355no7v7K/rqXvjF6eFynsz1u8wmya6unVHew0wg2gctjgyBt+iL7vL7uD0O9EWhg25NcrjPkAyhyy4MLbJTB9tbAdJPXRRBZC4eIHf6Ov6hcBKUD43SMPOM5FVrcuzPiToKNXG6QDzUvE6iXfkB6D0pvwpXlwoHVQkV4ENHpnhr0+eFJLdxI9j8Ww2MzhXCu9uqydylGjd+RjUhxuHVjPTee9Oa/GsoZAbaZZGxO7Jhg5hB7/dcE7sBOW1QIoK2pxtctcuEvS7Y9D8OgL8u2KSsExnB3NRH8rnTOVdY4eRbGygq9xvUrNr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HIHUDVIjbg+lrXs010 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. Signed-off-by: Lorenzo Stoakes --- 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 f931000c561f..721ced6e37b0 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1422,8 +1422,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; @@ -1435,8 +1434,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; @@ -1798,7 +1796,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) { struct vma_merge_struct vmg = { .prev = vma, .flags = flags, diff --git a/mm/vma.c b/mm/vma.c index 20c4ce7712c0..b452b472a085 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 @@ -971,17 +973,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 Mon Aug 5 12:13:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13753567 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 05999C3DA4A for ; Mon, 5 Aug 2024 12:14:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 78C356B009C; Mon, 5 Aug 2024 08:14:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 716356B009E; Mon, 5 Aug 2024 08:14:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4F1CE6B00A0; Mon, 5 Aug 2024 08:14:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 2667F6B009C for ; Mon, 5 Aug 2024 08:14:37 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C1F0B81C8A for ; Mon, 5 Aug 2024 12:14:36 +0000 (UTC) X-FDA: 82418084952.25.CC2A43C Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf03.hostedemail.com (Postfix) with ESMTP id 663AC20019 for ; Mon, 5 Aug 2024 12:14:33 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=hM5K3w92; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=ivbhsCd9; arc=pass ("microsoft.com:s=arcselector10001:i=1"); 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-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1722860023; a=rsa-sha256; cv=pass; b=iBwH1atfRB9du9iArHB5yt3XbiNzDORrwWl4XQyj5oRfXkGuUlcTfZFvIlx80gVDpEW7zI AfFgDc2B2Y9IOOqXHIv+uciv8CEBX/uFihS/klo81qKLkdsN01Tc2X5kF+uud4clH5Cyzu 49uxzyzScEa4oflZg/peG2CdC1HW22o= ARC-Authentication-Results: i=2; imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=hM5K3w92; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=ivbhsCd9; arc=pass ("microsoft.com:s=arcselector10001:i=1"); 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-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722860023; 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=GT4IfTGhfHAPrFMGRxjZsbTc+MQcsBmHmJoRmmTA0Mc=; b=fi/86f29ehhRPa7M1WroIYdpv99W+Z9R/LmkPxu248XEz1xOBXcDdMBSJB7LcSlxiTX3PV lZcrtoWduB5IbrB2A57qvQgi8X3AuDNe8i+R/Vx+9ejR9p8+dYvP3dA2YhrMYKU7iGF889 yaYPcN1P+3YM84ZGvJkVjY/fEY3D6s4= 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 4758fbW5027485; Mon, 5 Aug 2024 12:14:32 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=GT4IfTGhfHAPrFMGRxjZsbTc+MQcsBmHmJoRmmTA0Mc=; b= hM5K3w924mqgoJUq0jio9/rFu/W5uDVBr2Dyw33YJiXAs3+/IVKqmULps1v3FJMN ZDWay+teUu5PuCXBB4K6fI63j4I1Hz8YLNkDgmsxBISz/PMwxSlsiGqboTh3PoEp ixG7gjJvpTu31Ae5n/XRfXTIW8upNjDIYa50Y7oMAjUj/ZqZsgtnkcIOu61OH2UG Au6Wj4RfWCFYaJf1cMFaVe4Nc3FmxmlGzGXHflq2fr39SYwFRb7egBPxo9YvoZc4 NtD3B+WrYdV/BqmC1VomZWJVWd9uw6Yyjf0I96opIyssHpL0iXlUX+z3PpwzOSCN xeEs1v74EKK7LE0NASYnaw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40sbfajgk3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:31 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 475BUP21004733; Mon, 5 Aug 2024 12:14:30 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 40sb0d6qa8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=c/RRwY20z8eHvj6EKP+HdKodyjXsDNW0FKKqLK+FFhZOgEM7cKSfL9TWbDpQJLuZSf48eI4jdGhZLnVUJrxDJsRsUL2OKi4AE6JhTb+rpOa/gbHyggzxi/08s4k7EcBCdujQR4XAy0FIVao5DzqMQ3ct7+qg4aSyzBn27382aJcoGEe6KwVV5Yj/C/JSYvPKhgMWh8TYCNVeERzfmafC16g85pX8UB0DuPpdYFpvEwm8Tq35m+sa6I6akjHSJz+n58NBW2NoeDjEPjKxm+XhfKlurodUdG+0Dg6idd0/xNQpiLjQbp8wl9nqut+ejWmsWp/6wmYDXBBJQc+T24ymqQ== 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=GT4IfTGhfHAPrFMGRxjZsbTc+MQcsBmHmJoRmmTA0Mc=; b=AsQde710EfgT9nOZg+PZgzIcc2lgpPqHEnW6TTApb//5/mzHhs4axwuCWJpgK+h5B+j3DahTQrQcjpKz7jrk1oZzAmRNP4s4mRfqw8OrnfiBnY6qKNT+Ke7a+N6aNVQL8DUxO9WtNE0LGN4VYUHt12oKJyqbiGVkjttl/7OKW8URaJ29QlHy6HkypD5SGWfxICbTbG8KXbkeXAZzQm8Ul95sIV8J5Acp4Xjzj2idZRpbgrb0RvvGxoyL6dAH2tKoXd+SDNiFZ5DtiHxzcXosxG+y1s+CXeHGnOhEi8mVd6VhYs3Hftkq34uJXT1QHr90pOg2ne6A2/vcnjr7kfUPKg== 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=GT4IfTGhfHAPrFMGRxjZsbTc+MQcsBmHmJoRmmTA0Mc=; b=ivbhsCd9gKMXkmbixFiqI9TX9m2TJGT+eNALmSLQra72GOj9amB3nztLX3RrsG+S3OMPtSHg8s3D30L50WLesieuTRmnZtLkh5VT4PhJanN1Resu74GrbPgQ8dH/V/cRMfYxZP/pntlSzdpdBSqCNZJQ4+y/ARFxb2DbkBt57os= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by SJ2PR10MB7760.namprd10.prod.outlook.com (2603:10b6:a03:574::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 12:14: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.7828.023; Mon, 5 Aug 2024 12:14: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 04/10] mm: abstract parameters for vma_expand/shrink() Date: Mon, 5 Aug 2024 13:13:51 +0100 Message-ID: <95292b1d1215f49bd895f1aa38f54a8274c350af.1722849859.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: LO4P265CA0269.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:37a::9) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|SJ2PR10MB7760:EE_ X-MS-Office365-Filtering-Correlation-Id: e600106b-1c9f-4dda-4806-08dcb5482727 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: ggSu+uZvIz/znKvzeU52drZZ23U4QkWL0Xo6vgP5EnvCiXe4N5kkbPvc9L4PCocDiTny+guur9tkpdeEv92uaxKCD3BERXbH0HkGuAYo+0yjBA018OGbomLmTXUZEEUn0JoxofIRAUdTc1ugJygADQx5JzUiTTannGrL3J01Wz3zvR1SvEfmZijQWRSjMSWe/Je90EMCpJBN1/7JYmxEnenu975wiHQWM7DtJat/BkU+/FRFffIY0wXoGhgkiOZFiIJjDqHWMXW5G4GHrn49YKsHgbvKsHMpEE5Xzus2xtIYMsXHzFgcdo8CSnVHrhAg+1dy6UseeYRS3NHLR/2qizHwLGX+iNkQDh5f76jeA0BBo9wGLZ8ac4wCwiGO6RYh4FvfSUOw+ctcKRvk3CnwTh4WvqDRBgWLnaBaY1T7lSb31EvCdf/VCwmbqtdHkkKSY7J0H+HN8qKd6gZDHqGDkGfEYf6RmKGUx1xCFksUs3+zL3iRabNo3iswEJPu8eVaBrJQ14rm6gxQZu83h/txmnQs5rGs/wgsnasMgMSkE5kRMOcSAWT6fxxoV8CXEMXduHdEGorvEfvME7jRVvnGEGBeQJuT91xKBIhBdiH/lU4c9cbr8IjXo/3D7gAu9maPv5vTSD/uoWXR1gdL95dvQq6Zz/mraydO/BA+ZS53rDsbHLCeoB5ZCzqUit3Tf++KbcTpTk/EZVwa5saVvHKRar81Y+1nPw5DyLPhjLUVFyoEY0Sy4lrvlEIgpFm5g9jhp5lmVzNjCFwqsPQNOa0Ms4n0EqZzFVs+i0SRvVa+tH6v+G494PR9UGvurWIUV61ioYD045sixcrtZ22TNZ9RPMQRctG8gJjlibeYfYD4pu/FNJ5pB5EU1f7GgpQOJAoov2/Xyw4OssdPHJ+Dqhar+/zhrJQ0EOVrN+RXWrUn9l3XwD2mT9O3kK3nB1aFm+9u67GJv+GjdjmTjiNNlI3vmXN3gjFq51LjUHD/eGU4ESHksU8+fdIFQ7kJcVqlcDldLsBxjPhgsmUHl6ZrJtZNAmkcO1ofpJD578FM9VV02v5PVauln3oeL+WWwUo781eHQfkph14Wosac2N0+5wrqpoPseX76EU3GATm2l6NOE8DH8tz5qK6SFmUjl6C70giw7XbEX3agW8Dbv/xbxwXTtfjn6Q/jRdzPo01LHx+A9TNYSai6Gk+fw7qzBCFzR+fHUUroqSFLnV6LP64JXBhjQuqtW2E/DEk8TcOMZS/e5dUN4vD6OKJuEdVH0r2e3x4vHEboOgGz58GtDXj+8AUoTCpnVOW4oVeRZXBTA7SbpTbKC2iRO0LOFEsY5SA+9ccSDGgCr9EvlWktig0ezZoQag== 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)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bBrrqULExFAkGiUjXkYi2zciYlgY3NbEiBwCR+FcmnwDvgpx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VF8JNC25eLj7F0qaOubvxPr9bsdXWSCuPzHVCsmgETgUNxVCyT96KUPsGYRoB6YlPcIqYgFffroo4zE14283VuagxvYpbvHTtiwoXIB0tskSkJvlo3tznx4c0w50tnT720h2M+RJAlacvU6pMONvGV/S5SiXXNei79J3ZxofWI+tRFlNmMwqoGczcmMxRMUanplc+MvnQBR626VOsC7vPASNxodzsW06mbwGz3ZZ+pxxxuNh9qGfp8n5KOpb35Y47GTxq4gnihoNjkypLnLgnnk54C2HISZtPu7w5HH/9eG8H1csAutWzKRakdvl5km6kQta8Qy4PVh2F00lRsqvL9yJiNV7o3aoCbEIOQSgeUgDWmh9uL+W51skqohdbbTE+Qi2+34Nq4/O4wQgBDxfUr0tm4krYaGsgN87KMKQClZMSNY05vbThAstna8XmikGohb9WmEIKicSdQnekQ9+CjbfKGGD3pr8t10Edg8U6KeZ0A/DYbhNIIHdQXJmE/Mtsr8n7/RsAM6wSaRjksEL1ikTVmzQtJ1xWDI2PR9q9fAPA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: rb5ndVeligxB73pqq6hqk/aXB8sQ3BzqbmqtAU9Vqv+FRa00o4pdNlDtoqTF+WIXy5ecFgwR7rXauCyESF4CC1H0tf9QBH4+/b5e5d7LaIcmJfq4eZwZ/iBJ518276Fq5mFUYOV3AcQr348Y54SI2lRNT5sRoZg9burjieOUNFMhDlitZe3a0qTd2PeQvyr0aLe4nGf9Sy8WBLJl/edlQidP16sMT76XWmpLhDOD/p8TXF63TzDBFeooSXMbicwnsClM9wMv+ISVxvByp40re7zaLN20d0CV6/e0AKj0O2fFIrKJzxAnuOsoM0+ndrZQ5FF2AJVc/LCSW1jQH/ajTdJqO3e4H0Rl41ERtZYe8qOFyf+myQ9Yw9CPQuwW7Towej8xjke1kSVZ0JJ+H+OIO2Guv+7h/Un9sOxDQJGWsivtCH1bluao2OKjlDGKt99wKiKLKSrYe2VknP/hmXJMdl9cu0d4P8pSIkSJpTdYH95LmN4uLhVk3tNigKheKjPJCLrPUDDU2DLQNG38iKBWoyQbhKzHk5evJ5h+veSWVtGfQ8uf6nikDWbZSd5ePjL4pE4pNY/5+dFno81sD8iWqvmOXZPdXgRHw8QZ/IohUb0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e600106b-1c9f-4dda-4806-08dcb5482727 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 12:14:27.9723 (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: u+fxybTYTCi/9p4M09GOuvPzzGFQhvIvg+0bcqgnHIFob47BDu3OFuF6laUg1SzsAm4JF2gk1+6h3H36crA9PXVGxFGzJqGi8Cs0fmUaVaQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7760 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-05_01,2024-08-02_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 bulkscore=0 adultscore=0 mlxscore=0 phishscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408050088 X-Proofpoint-GUID: zzvnbEPIIlnELCAbUISlKy_fOUcyDNwT X-Proofpoint-ORIG-GUID: zzvnbEPIIlnELCAbUISlKy_fOUcyDNwT X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 663AC20019 X-Stat-Signature: g59yotskg7mh4oi78zi1jjzp91ci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PepMNdK2Cj/CvUiqiSLj5+bX9W0ljtalFHBXq4Ns5hgt9Eh5WOhW91meLEr3tqqD3x8QSPnGJ6I5yTTRQPc/kf6Hc7gvyWGt84iqVCHr3+VoCpmI/nQ4Ei2FrudisT7s8LnaFJ+blDibGoLjXJYZpopXmzY+Gafb2reCYELx+nZGns6gJ/iIocHN8rQbLcexXAaXej4F7c8if/tSbnZiwxuZDswOemd5ADEy87lDLlMgaIoErNXtYLBIRIXObA+nhkiWtVA6oR8UtzYaZWtIensCSC1bEvY9+J8z+a+ZyV7K/am2LZOy8NTWf1SQ8V2P53e82p5tS4J/dYiPbttGqnyw6gdSbiJj/FP3vYdxr8nENtNcTCC28eDdltH9mMmoFwSY7i0Uff24GQ29M4CHxsmIWf0S5tC2LCr8KsrCG9/JpTwIvp8JN4Ns30YXS4RO+Onj49pFsOd6kaVSl3WdfmzKw= 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: Equally use struct vma_merge_struct to abstract parameters for VMA expansion and shrinking. This leads the way to further refactoring and de-duplication by standardising the interface. Signed-off-by: Lorenzo Stoakes --- mm/mmap.c | 30 +++++++++++-------- mm/vma.c | 66 ++++++++++++++++++----------------------- mm/vma.h | 8 ++--- tools/testing/vma/vma.c | 18 +++++++++-- 4 files changed, 65 insertions(+), 57 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index 721ced6e37b0..04145347c245 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1367,7 +1367,6 @@ unsigned long mmap_region(struct file *file, unsigned long addr, pgoff_t pglen = len >> PAGE_SHIFT; unsigned long charged = 0; unsigned long end = addr + len; - unsigned long merge_start = addr, merge_end = end; bool writable_file_mapping = false; int error; VMA_ITERATOR(vmi, mm, addr); @@ -1423,28 +1422,26 @@ 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; + /* We can adjust this as can_vma_merge_after() doesn't touch */ + vmg.end = next->vm_end; + vma = vmg.vma = next; vmg.pgoff = next->vm_pgoff - pglen; - } - if (vma) { + /* We may merge our NULL anon_vma with non-NULL in 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)) { - merge_start = prev->vm_start; - vma = prev; + vmg.start = prev->vm_start; + vma = vmg.vma = prev; vmg.pgoff = prev->vm_pgoff; } else if (prev) { vma_iter_next_range(&vmi); } /* Actually expand, if possible */ - if (vma && - !vma_expand(&vmi, vma, merge_start, merge_end, vmg.pgoff, next)) { + if (vma && !vma_expand(&vmg)) { khugepaged_enter_vma(vma, vm_flags); goto expanded; } @@ -2359,6 +2356,13 @@ int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift) VMA_ITERATOR(vmi, mm, new_start); struct vm_area_struct *next; struct mmu_gather tlb; + struct vma_merge_struct vmg = { + .vmi = &vmi, + .vma = vma, + .start = new_start, + .end = old_end, + .pgoff = vma->vm_pgoff, + }; BUG_ON(new_start > new_end); @@ -2373,7 +2377,7 @@ 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)) + if (vma_expand(&vmg)) return -ENOMEM; /* @@ -2406,6 +2410,8 @@ int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift) tlb_finish_mmu(&tlb); vma_prev(&vmi); + vmg.end = new_end; + /* Shrink the vma to just the new range */ - return vma_shrink(&vmi, vma, new_start, new_end, vma->vm_pgoff); + return vma_shrink(&vmg); } diff --git a/mm/vma.c b/mm/vma.c index b452b472a085..3d6ce04f1b9c 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -489,30 +489,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; @@ -525,21 +520,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: @@ -550,37 +545,34 @@ int vma_expand(struct vma_iterator *vmi, struct vm_area_struct *vma, /* * vma_shrink() - Reduce an existing VMAs memory area - * @vmi: The vma iterator - * @vma: The VMA to modify - * @start: The new start - * @end: The new end + * @vmg: Describes a VMA shrink operation. * * Returns: 0 on success, -ENOMEM otherwise */ -int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma, - unsigned long start, unsigned long end, pgoff_t pgoff) +int vma_shrink(struct vma_merge_struct *vmg) { + struct vm_area_struct *vma = vmg->vma; struct vma_prepare vp; - WARN_ON((vma->vm_start != start) && (vma->vm_end != end)); + WARN_ON((vma->vm_start != vmg->start) && (vma->vm_end != vmg->end)); - if (vma->vm_start < start) - vma_iter_config(vmi, vma->vm_start, start); + if (vma->vm_start < vmg->start) + vma_iter_config(vmg->vmi, vma->vm_start, vmg->start); else - vma_iter_config(vmi, end, vma->vm_end); + vma_iter_config(vmg->vmi, vmg->end, vma->vm_end); - if (vma_iter_prealloc(vmi, NULL)) + if (vma_iter_prealloc(vmg->vmi, NULL)) return -ENOMEM; vma_start_write(vma); init_vma_prep(&vp, vma); vma_prepare(&vp); - vma_adjust_trans_huge(vma, start, end, 0); + vma_adjust_trans_huge(vma, vmg->start, vmg->end, 0); - vma_iter_clear(vmi); - vma_set_range(vma, start, end, pgoff); - vma_complete(&vp, vmi, vma->vm_mm); + vma_iter_clear(vmg->vmi); + vma_set_range(vma, vmg->start, vmg->end, vmg->pgoff); + vma_complete(&vp, vmg->vmi, vma->vm_mm); return 0; } diff --git a/mm/vma.h b/mm/vma.h index c31684cc1da6..c464d25da120 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -66,12 +66,8 @@ 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_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma, - unsigned long start, unsigned long end, pgoff_t pgoff); +int vma_expand(struct vma_merge_struct *vmg); +int vma_shrink(struct vma_merge_struct *vmg); int do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index 48e033c60d87..d216e51206c1 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -142,10 +142,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(vma_expand(&vmg)); ASSERT_EQ(vma->vm_start, 0); ASSERT_EQ(vma->vm_end, 0x3000); @@ -163,10 +170,17 @@ static bool test_simple_shrink(void) struct mm_struct mm = {}; struct vm_area_struct *vma = alloc_vma(&mm, 0, 0x3000, 0, flags); VMA_ITERATOR(vmi, &mm, 0); + struct vma_merge_struct vmg = { + .vmi = &vmi, + .vma = vma, + .start = 0, + .end = 0x1000, + .pgoff = 0, + }; ASSERT_FALSE(vma_link(&mm, vma)); - ASSERT_FALSE(vma_shrink(&vmi, vma, 0, 0x1000, 0)); + ASSERT_FALSE(vma_shrink(&vmg)); ASSERT_EQ(vma->vm_start, 0); ASSERT_EQ(vma->vm_end, 0x1000); From patchwork Mon Aug 5 12:13:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13753568 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 AE38FC3DA7F for ; Mon, 5 Aug 2024 12:14:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 82C786B00A3; Mon, 5 Aug 2024 08:14:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 762356B00A4; Mon, 5 Aug 2024 08:14:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5417D6B00A5; Mon, 5 Aug 2024 08:14:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2F3E26B00A3 for ; Mon, 5 Aug 2024 08:14:39 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BE560A8A45 for ; Mon, 5 Aug 2024 12:14:38 +0000 (UTC) X-FDA: 82418085036.26.66CB922 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf20.hostedemail.com (Postfix) with ESMTP id 5E7B21C0006 for ; Mon, 5 Aug 2024 12:14:35 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=i5j1v96r; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=BLPxSQOG; spf=pass (imf20.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"); 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=1722860068; 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=iWgOVVMp2+tW0FhzdmTzuZixiBNib8oI0PxjDIzzFQg=; b=NmaMKyISxAlGh6JyiDIAhCXO6Z2XVc0av5uRRQTQ1ccl4iMK8uwQmbWoBQ4mOIdns4vHSK FTxLUPg/rKtgwbRPVLObhpBJHuR6NE+S0PM98WWo+3l5yFCLUP6BsvdDPzAIfj9TStuK3u j5B8/3j4T49Nv9NX+wUL9HP30IVPrN4= ARC-Authentication-Results: i=2; imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=i5j1v96r; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=BLPxSQOG; spf=pass (imf20.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"); dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1722860068; a=rsa-sha256; cv=pass; b=qQk+bF7HNv29LfKjj8qRbQ9gE6y+TqYzRbynMPSp6dpk4SkA+MaYK6reqVutZynp75jNq0 nUefk66WooDNeKO5DhCD7i3XzZhwA5B1xaWiVM9dmzOEnpn6/ZiNbLZPA4NkTFdk8FJHW1 YcGhDDckgw3hsiNNNWKCoSxMK9ybVy0= 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 4758fW0E028157; Mon, 5 Aug 2024 12:14:34 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=iWgOVVMp2+tW0FhzdmTzuZixiBNib8oI0PxjDIzzFQg=; b= i5j1v96rGeohR2uDyEOe90dcKWhZ2BVCoMWZ/VndBgLiYHInjR1nrInwkeO/LyH+ X4Zos/6i3sGkPidX6dLPBl9QvTKazAgOZiEJ1pB33fQ4OwQTsttlJ5XS48JXsy5E LnF1ODYimcjjUDk2Y4ZmkUtidh0AOIdRoyxJBOzpx1LwKxaFg1eHnBHc1lDw1s3X emWWtW7jB3c+cbz26QErxhR8+QJIOsCayUq4T2a7GxExq3ErVFkvBW6o/M7+5zIB dXu/8j71FjTGl14Lsev1IWvHQB204ybeLZ6DTg1s90FPvYzZLP6cB26aPYUI5n2F LUwIktVUu6JjNQfTU0VxmA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40sd3uje5h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:34 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 475Ao2iG005668; Mon, 5 Aug 2024 12:14:32 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2177.outbound.protection.outlook.com [104.47.55.177]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 40sb0d6qbt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=kQNIQhaKiGZ6s7ew0xZW3opvikekQOtH0p0Syovy72qX6a/3+e0qerB+psrSYOpNrOqTpX9lqNnM1EbWB3KiKtE1Xh6ASwfi66tMTWkWar5j50DG/8xmDgz3NkwPFoyq9G/ScF8Z3caZHPZFCFN08lZoLlUePOeLKF7mUaJQl1XTvwcWacduiaSmk5EHwou90SmzDKuJEYxzI0kJ9es8LVEjzjP5vmIqWK9V1/xvfSgb12Bx22AENceTxJbv3VLOc/Md6gIsmTLjwRJL9Pbp5Pc2ricuK548MkECF7zAF05QBJ/LAPw++rp4HK+7gbEWhIjNK/Fm48tWHmAUNBI+qQ== 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=iWgOVVMp2+tW0FhzdmTzuZixiBNib8oI0PxjDIzzFQg=; b=dwU1za82vKDbaS3p0u4F4IlpMPko5ZKG9C6GV7uoe83wVQUUWDXHnOqOf00qAD5HaaX8TE7bozRq6sAg2qTQDduQ6rJfIrbWIf2hsjeqN/jlEMMLj5P3GQr8FuBFkI1izxx+cmHGpmOXaCsqtYIagZ454NRzAkTyvApNou8g+VE3ADbF730x2UutnCvHvqXTDgMQVocCKZvW22oXe70sWxxUSFfm/GAQCrfxRHwTH703GRaI4qN5bb1tPGCjL+ncXWFswCI2UT+LpkrflPi93XyvaoNUEdZrI7f4Agu3+Ike6UKQdDA1fcUTgKsc7xyg3NREOGEgngcC45m77m2Y0Q== 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=iWgOVVMp2+tW0FhzdmTzuZixiBNib8oI0PxjDIzzFQg=; b=BLPxSQOGw/PIP62QiORqppEuR+BaAhrXmGQmAGl4fn33C8SDsOCENK/rzKZ1aU60Z2hLbrIdpTxRSOgp93pQHibGSR6nrWO0y14gd/K3ZdylEVngQdX7pEnhrSnl6z5rl33kp9YThXVBTaJ9WH9Jee7uNU7HeKukg+oJi6BekIQ= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by SJ2PR10MB7760.namprd10.prod.outlook.com (2603:10b6:a03:574::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 12:14:30 +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.7828.023; Mon, 5 Aug 2024 12:14:30 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH 05/10] mm: abstract vma_merge_new_vma() to use vma_merge_struct Date: Mon, 5 Aug 2024 13:13:52 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0137.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:193::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_|SJ2PR10MB7760:EE_ X-MS-Office365-Filtering-Correlation-Id: 9e1dba1d-c138-4570-c50a-08dcb54828ca X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 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YI0yWCi/DGIKxHS7972y3WBJkx2XEQb+XNvmz79W2vhgWg8W0JsD7im16f4i690lCdjmr/VfB184XeDhXngmgedvUS6rgN6TvFzMgQXn+rW3XIj9zzqESWbznOxV0unVWCbX/RNcv/MYD12Vq01ZFYVgsB1WVzlFfgKaAxET8r2b7eUZGasJselqtxfV+4na9FbbMueZCMquHPPBgNDRNm6bPZ8dIt1t8JYTXV1tj4Y/OXBD2BzBWNrycTYDcLspzbtZxINXmSyFWgILfFRyBS0aS3Mj3tD0Oc4QbEC38yUS7VErpQqVZz/O7+jLZRBUPNWOE3AUAoQmjEfOk0Op9gG7gesd95W41ZrUXyu9Pg== 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)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Tt2Os9h9RbwXZk2oqyglKlUZkEgsSxjDksRyonFbYBSTXucUKIwfX18Tg2YSWTKJka5NuSfGurajFkLCUVS4o+MIbcwFCIdz46aJL5niiH/Ap8qQ763NXIL4GKwIH9eqEUzZ+5DEVtTJY0hTVcu7vtVDiU3ixtp04C2EWW76dYz6q4g8mzABxr8Kq4zkt+iHVuFDKw0t+VD7MlqjOLlURDnzlLUamaaQ4H2SAAVTnn6QvwPHzfrZI1N40Nhp9pgJ7EJayCJ9yeO7rUHfXry87BONd8GQfINmgTIqj9Em15CHoov4zt5zC0dawxXQ1sLmCgUgNfB2TgJ3OLhb17dzRVf5WH0a+UrAbKJzdCbYK7mttCorJPL75afDNtDd6j1b6onVYG/P8FGPj8P4JfJn15ELIH+Jx2Y9fgcpA3q0M2yl8RE8OLM8KUf9eFvOrGHZVLrJjGGtczUWHs/T9hKoCTG7fKo0xDHu694ZkxtPt300eQSZkA8To/0hF7v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4JMgMsi8t3YJa0ISs+DyNNuH38nuKBp303NUllpgbuAPrmoOeShhZ+a984UjfHW6TJxWvdHi8gIsRrMhq4rdDDpvtpOMBfAudmfQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: NXm/a4pLN0XeyAMdK6L+YSsVdNX+0cvWTu0QrfmJ8bEE+QuC3n9WdFsRefyl/+OpIzw51nEl5P5QGWfvlrOnaTr+Hv9DthC8GrnBe0cKHuglANzfylQckXIQ8MlOp+IYaMVU+TkNnfHzOIf2wkAjh9tAJFJIK5If1QnDsgM+WsSYnUDkjL7cBHqpuDGBxR6+PZdLFAZ2NkggaRoGnGF5V4BWQFhJOy49CN2r+qsHFAhTcOiY6cq0Zh4dHFKlUZcyRtAxRdhGg0vfYnO2tSEH/sLBxLKqfmLnG90a29lbOKRdpoN+S4GmxzrhKWg6TLzRutx9b6yAaeuXWHD9I41dXPrLuAMLir52sJJwhvCYZbmIwSupKZCoZu9+ORqPvG+V7po+MR07OKm3/oV9DQAVJjb8lZEIvJ7JmEHXBM59j+04K7D4iKd3ncXTg2vgqShSQfeZaHb7eGQpWGicZF9CtbgzAmBN8ND/MK0N8dt6PbiXXBW0CDwnOmgATbTYocwd775JWqp68JIJqSPx6Z7/p4vZJq1SjuyFS05oF9pdX3VksjwBlFmeH5vhGn09SRF9MOxTEkt1ns75doC3HI4yn6a7um+p704ZM4+lJZLyy78= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9e1dba1d-c138-4570-c50a-08dcb54828ca X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 12:14:30.7228 (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: udmpVCuv+PVPkUqIyqUVRIfT8eQ1VbjvhpOy5T0UcVAnzywuuevc/9EGYW4yw/3Tm1dDCStNF+tVYNeEnDpRhyodOcY+16/wKubNw4hQEc0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7760 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-05_01,2024-08-02_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 bulkscore=0 adultscore=0 mlxscore=0 phishscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408050088 X-Proofpoint-ORIG-GUID: MOlCFEfnMt_JFrjzqmQIGRRNQRWk8jCH X-Proofpoint-GUID: MOlCFEfnMt_JFrjzqmQIGRRNQRWk8jCH X-Rspam-User: X-Stat-Signature: jgymogjq3ryezf7rnjof6y5sfzasntnb X-Rspamd-Queue-Id: 5E7B21C0006 X-Rspamd-Server: rspam11 X-HE-Tag: 1722860075-594903 X-HE-Meta: U2FsdGVkX19AT4tORQNcA7m5nZPzvWLKDYZNjsV2gxWEBTjwYR0rLCrx/IdJNGycrRveIFB2fYMRrYh72a0t1JCUzEKNZ5aOB2RYhaHzt4Pzb3OXv57Luc3Bgs3kOQC2rhQAa52Flm8NLBJPLFGXZcaaFy8I+N8nSU5T0G4TvcviuDs3P4OwhxXw+dkCw/UyDDUAqKwUzRcQLbjbkI0Lp9GbR45Spr8lM1LMupag5jCS2jvvR8t7wpaFKV1OFnkm1OngmaBAYUExWMsUn/m5dSCnVmjOYwSHafwH0yo3pKxNu6F9EKGWrNJzENByN90KeGGwppwqebiRx9iIVt5wsajEz9doizI1DBi6Y2il/newNPLan3EuRtYtok1wbUKxW/w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F9syML2UZMWiFMZQ2kcskLyuahc0BRveB92O63kiHmMNvnUxrp3riGPZA= 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 this function to so we can write tests which use the newly abstracted interface and maintain a stable interface for tests before/after refactoring. We introduce a temporary wrapper vma_merge_new_vma_wrapper() to minimise the code changes, in a subsequent commit we will entirely refactor this function. We also introduce a temporary implementation of vma_merge_modified() for the same reason - maintaining a common interface to the tests, this will be removed when vma_merge_modified() is correctly implemented in a subsequent commit. Signed-off-by: Lorenzo Stoakes --- mm/mmap.c | 6 +++--- mm/vma.c | 33 ++++++++++++--------------------- mm/vma.h | 33 ++++++++++++++++++++++++++++++--- tools/testing/vma/vma.c | 12 ++++++++---- 4 files changed, 53 insertions(+), 31 deletions(-) -- 2.45.2 diff --git a/mm/mmap.c b/mm/mmap.c index 04145347c245..f6593a81f73d 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1494,9 +1494,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr, * 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); + merge = vma_merge_new_vma_wrapper(&vmi, prev, vma, + vma->vm_start, vma->vm_end, + vma->vm_pgoff); if (merge) { /* * ->mmap() can change vma->vm_file and fput diff --git a/mm/vma.c b/mm/vma.c index 3d6ce04f1b9c..55615392e8d2 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -1106,6 +1106,11 @@ static struct vm_area_struct *vma_merge(struct vma_merge_struct *vmg) return NULL; } +struct vm_area_struct *vma_merge_modified(struct vma_merge_struct *vmg) +{ + return vma_merge(vmg); +} + /* * 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). @@ -1260,27 +1265,14 @@ struct vm_area_struct * 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) +struct vm_area_struct *vma_merge_new_vma(struct vma_merge_struct *vmg) { - struct vma_merge_struct vmg = { - .vmi = vmi, - .prev = prev, - .vma = vma, - .start = start, - .end = end, - .flags = vma->vm_flags, - .file = vma->vm_file, - .anon_vma = vma->anon_vma, - .pgoff = pgoff, - .policy = vma_policy(vma), - .uffd_ctx = vma->vm_userfaultfd_ctx, - .anon_name = anon_vma_name(vma), - }; + if (!vmg->prev) { + vmg->prev = vma_prev(vmg->vmi); + vma_iter_set(vmg->vmi, vmg->start); + } - return vma_merge(&vmg); + return vma_merge(vmg); } /* @@ -1295,7 +1287,6 @@ struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, struct vma_merge_struct vmg = { .vmi = vmi, .prev = vma, - .vma = vma, .start = vma->vm_end, .end = vma->vm_end + delta, .flags = vma->vm_flags, @@ -1425,7 +1416,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, 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); + new_vma = vma_merge_new_vma_wrapper(&vmi, prev, vma, addr, addr + len, pgoff); if (new_vma) { /* * Source vma may have been merged into new_vma diff --git a/mm/vma.h b/mm/vma.h index c464d25da120..50459f9e4c7f 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -134,9 +134,36 @@ struct vm_area_struct 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); +*vma_merge_new_vma(struct vma_merge_struct *vmg); + +/* Temporary convenience wrapper. */ +static inline struct vm_area_struct +*vma_merge_new_vma_wrapper(struct vma_iterator *vmi, struct vm_area_struct *prev, + struct vm_area_struct *vma, unsigned long start, + unsigned long end, pgoff_t pgoff) +{ + struct vma_merge_struct vmg = { + .vmi = vmi, + .prev = prev, + .start = start, + .end = end, + .flags = vma->vm_flags, + .file = vma->vm_file, + .anon_vma = vma->anon_vma, + .pgoff = pgoff, + .policy = vma_policy(vma), + .uffd_ctx = vma->vm_userfaultfd_ctx, + .anon_name = anon_vma_name(vma), + }; + + return vma_merge_new_vma(&vmg); +} + +/* + * Temporary wrapper around vma_merge() so we can have a common interface for + * tests. + */ +struct vm_area_struct *vma_merge_modified(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 d216e51206c1..4416cfa93056 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -53,16 +53,20 @@ static bool test_simple_merge(void) 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 = { + .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 = vma_merge_new_vma(&vmg); ASSERT_NE(vma, NULL); ASSERT_EQ(vma->vm_start, 0); From patchwork Mon Aug 5 12:13:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13753569 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 8FA0BC3DA7F for ; Mon, 5 Aug 2024 12:14:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 281C96B008A; Mon, 5 Aug 2024 08:14:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2325B6B00A6; Mon, 5 Aug 2024 08:14:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F2B5A6B00A9; Mon, 5 Aug 2024 08:14:58 -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 CBB1D6B00A6 for ; Mon, 5 Aug 2024 08:14:58 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8A157121E77 for ; Mon, 5 Aug 2024 12:14:58 +0000 (UTC) X-FDA: 82418085876.07.DA79A48 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf01.hostedemail.com (Postfix) with ESMTP id 368CA40017 for ; Mon, 5 Aug 2024 12:14:54 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=LuMDfAhJ; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=OkuDZ1iU; arc=pass ("microsoft.com:s=arcselector10001:i=1"); 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; 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=1722860033; 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=/dW6PiGqZ6Gp8J7+QDKe42m1XjWc4o3dGnj+I9OHB4Y=; b=32W7DfnXZyVtlOS1wA2ExMKMW2Tb/CRMwpFZQkbmsVbeD46RLRQ46LTPtyK9QOVm40W774 0KCpH1eRAz1bv2PyxRyraaqA7rNnVSschW1dKkVbxmEvUijU++rhMykdXA0KoN0+Zr6hw2 Ov0j9g2+fA+KekP+WfGFekPGCcweU7s= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1722860033; a=rsa-sha256; cv=pass; b=hgd1Zwqec16vydXdlWeR2J/ky0ih5maEjrQVLg8bSIShOaKD/nrIk+feq+PWh75Rvr1Wjl ZRZV2xk1CxyPLN2eQ5Vf9iriCxa7kOhdL37CZne8qQZRIjriSEMeg0+g63g52yRfLawB7F M7hp9Nm6Cy8yGIcDONRdvmd0h35vTdI= ARC-Authentication-Results: i=2; imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=LuMDfAhJ; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=OkuDZ1iU; arc=pass ("microsoft.com:s=arcselector10001:i=1"); 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; dmarc=pass (policy=reject) header.from=oracle.com 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 4758fWr4012618; Mon, 5 Aug 2024 12:14:54 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=/dW6PiGqZ6Gp8J7+QDKe42m1XjWc4o3dGnj+I9OHB4Y=; b= LuMDfAhJ9JhzA6QnG2JKos6komzNNptrfK9/UNLiro/6fqvW2Y+aOoExCZa9Js8Z LUKxpzM2CCyTUYOkEdsCfqMnnxyh/0wjLFrL9nFkwYe36prMUE+FvAZWQs+0N4aA 73bCG2ToaNBiz/3HrrJHshPtZXtc1ru6u0X93m6JTx1DQ9iyo8sxSqSGm1sdz0aA 3CuhOfH1js7Owy6UF8BwwDaPewtnZIurJbKBuQAomNLzsuXZ26wHs4i3nSVggisF /GCDnl2IkkYIUD1YSoQa7Yvrm5LaIK2MVA8H3GC/hVO+sA1kYdESH4+6gSoVIcsV jOLsp2HxHE4ws7iSHct7eA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40sc5tafuh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:38 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 475BThYH018392; Mon, 5 Aug 2024 12:14:37 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2168.outbound.protection.outlook.com [104.47.56.168]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 40sb076pa9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=juGEi2BlXP9PbzwiWVO7wEn62PKhDmZqCkWGrtMe2FG70A/p38VnBdoET+RJY02ZzU+nvalQqwXdkR9wbh8M4RAV/mxCivT+Tu0mho5Gyvy/e/P/e1J9o8ly5GjxrYAR26JG004vA/ubVLSylJVxw4+R7XMStpaCHzMC7r3FZnjWkP3vfGRhSEWEfeccc+P5viSeuSS/Zmp1EtB3MAOnldAJRV+sdVUXw9TJnU+zeXhvPCePYHnYt4R8SI8iOChNDML2s3CV/X3zsYMIwj1tqMClwc/NbbS49enXurmnGWASzLaN5lEWtK7YpxCntt/mbtZzK5pyNERtuchiA9JQgA== 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=/dW6PiGqZ6Gp8J7+QDKe42m1XjWc4o3dGnj+I9OHB4Y=; b=qiWlGIupY8gc2PHV7F+D75mtnB4ljAS3ZZXMfISMNuMNQ7EVm0tURow0rj5xWc7TztV85dQ5tMQR41FHkcTFVCFsFsVzfrO2LKYJlAMaZ74UZMqkqbQT876F1QNZ+9ozSOe486fxnWY4MYQldF+YBipUqsl9PEhHKKpV22oQ26G1P2ZPCZgFdgPpRTY+g/mXBWMzov2oYt/1crHod1kXVubBKPQGI0kNWSRVDkMbs7Z8lmYZbOJtCJ5uOQkfBfHN1X16NvEXVbbaLAaJvTK05pT2dfnhTyt5sV0Mowtt17+jMpB533ZHLRqgA4ih/WIXWY1zZR/qXaXOLlkudT1AoA== 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=/dW6PiGqZ6Gp8J7+QDKe42m1XjWc4o3dGnj+I9OHB4Y=; b=OkuDZ1iUFOi1cuFMhrW7iPLldCIm1wmgER8Xe/Jf9/11y4JWDmtWzcNF6w509sdgeveM1M4mwbGXQc/JF9F300GYSdGC6bGvlGeLeKxGGo4D1OtO+VSfYSJsEXpkaPrQoeFpR4b7oDgangEryTUN+GWL9fqaIjAiXP2AUJS8ynQ= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by SJ2PR10MB7760.namprd10.prod.outlook.com (2603:10b6:a03:574::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 12:14: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.7828.023; Mon, 5 Aug 2024 12:14: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 06/10] tools: add VMA merge tests Date: Mon, 5 Aug 2024 13:13:53 +0100 Message-ID: <4c61f53edde8c362d1ac91dd48fc57003d13cf0b.1722849859.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0178.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a::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_|SJ2PR10MB7760:EE_ X-MS-Office365-Filtering-Correlation-Id: f11109ed-342d-42ef-e79b-08dcb5482a86 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: W0+4iKsOjIjVYt7EURNyIO3C57UrgejDRx1Zj2tXUfrnxIUXMrXGCRrwy+7+HyDruvxBMXCYKMugaVsR9RIZz0fuH2A13cM4T0/7sKPkTCWp1TenxR8iSM8qXbDZrhM4aSCJhKgTS7MOp/8OSD6ur3Mjh3ygeE7njqjIsGBkylGr/qJvduJVvHMkRTeRPRXj04t9HiPcP6Ckm1DHCaYxZ6GghCjuh28OnpGgQXo83su55ZGAubWdSeMv4d6FGUjhkDA1An5k4VwYnbHE03i7clmQdSqn+wrDJHS7M9vklcKtnvE8sZ0AgnZ0in9PCgMLU3F9OoH5WU9ZVMhuuOrczTe8ubK5SzwvVEMqIWOb4jzfNOacBvvNzXxjVj8o59OJBC6yza7Zi6FH186HOo2SYucmxlGu1qnOdu+y7HXEyoptgplNfUrgtJUyUJo6SMvTeHrO7VNyepOFjn4zUJUahSXBhHsCVVj16vQajNso53dmEZCw34PgF6zizws1ADWes8tjzaa01DpmAeA4cG2qvW2U5y1fEu3HPks5K8+faEShTvNDrdZREhvgnYDgaCuGG5BbgIZdgNXKpsyTV7cQcKKzyiLgwAW3XQ5qswvG7GAm5mIyrkmpVe5/5+lQlCYa2/xt3LQqfjogIarZZecwlIRFzIvZ+BEZauHnwCTPC+WBu39ZfNA9cPrh4Yi5TArdwvgz5Lxn49Rvj9U0DR31jjt1ufpN7CTAMM/4+tZ9ovtEU2/nJ/6i0SrfgezZY7PUJUOhdOjR9oLLZzi7ao1DKtAMPaiv8VTCfMM5ydqfEm1h/sGTbLEY7Uxe6ws+vWC/I0h3dX0T805pC27PjhnPaggGTHw6UyWdTfpyUjek/jnAv8n9aBpNQ6RjSKmdwlsNIFVRLJh89So8MTEpSw+7mw6n/489Rt8N+yTRkIZyBGhjym8iDVY0rMwHvRWqohJJ2zzNho5YBZP/Yq7k0DMv/o2TqcowiRnWmjrF4TDwBPKS8fdCEJtrllRbCQX0i90zmrEz43dv38a9Vybt5Sx8kRUwhRHYZ1PyTnu49DOAQWTc7FZ+nZtGwp12/6xozHl0GdcMDGJ2hPzk3xPwCVNT/PvJ87RLpsdcpdWV4QpHFbOp5hfc84Kimt4ElTSesZYSJQOv0fnxuF5orBXwYtZqHIJ4jpB+OEF2dLJYTk1WIQ9xvfkvpQA7RPt/vVgE6Fhr6aY35nngb55Z0+whcHRTMsujiGLC8eieNyHbGq7S9oRUTzmCTay/o1kRijHIVgBedslicjYgbKEoqCGDd5g0ks3pz2mrEbifQrtN6mmiaHFMd1Z0YvG/Sy5V8C6CHk6SOH9mQR6WLzsvnetYjo/H3w== 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)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7mcou/I7fpMe/8lR64pnt/M/+kqkvaDpnwxtVfvGQhN28bwdbdTFZj2eOTt5FLGk/Du8qUws+5F0AE5QUTsVUMT/IQdQdSYPselBhdCsb8MMCSGo9C5OFwHF0q2cElin8qcjluknIpb17SuG6rqDG9kwnn9oDVJUDQCHmx7chXcDV68HrEApB36lVv64Fz0rz4YWmc0StftNOpGLEshGV+Z+iORpePXEzBEmSmhrjhwN8Z2uKs246UzN/DD5d4GOCbvxQrmAGHG/VY5CGKNMDK06dyZ77rxjQe56yKMqVMJPGRlwMPR/jeYjkiPhmOjYgGYHZlQtDUJinndEBT9gWX1X0176uzDYqhInAXLZWJ6RjIa1fDuLVPdhHMoR4ZKYBzyYsgolFs3WA7ikjNHddGVwn0Ji2GjNElgyEurLkQjhjt0SBMciznW0mPcGxbRe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BofpJJKGsxcUrjyzDxWtNFm0gRQ4BfQtmP7qm9WA8E145cvUH/uzrdOgcdEskrkkDEbMSSxvlOPFGmEMcX9q8MjvrP2U89WD3nhfdaVTeZz3rNpASIusFE55xP0ftfjRUWeWrznn3JCWaAgfBMkKeFCgqyxKQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: qszHpnfMblV2jeFBzcwG25E1VXTOLrWryaJuFRm806GfaMgGdjMjh8PRzO9KO9tuqa+phA87tavRDwr1XqcfqdX0abARklbB2JDas1DFw/3IYV0MLmO4rjEBAKEXswGAPxhSzZP5GJe9oE5WyJ/5zFg8QpFdNzJdH07mq+JIw6K1MUoXT+e/cpxPQDFk4EmlAkbs+8HohZLk7bNC996UHduy1tGTlJ/6CryR/Db0yMW0RCAFkDg4GVAJ46OqirfZVOChV9snAXCE+AIht3RdKBCMDGZPxN0Xg4YgOK5o9f9a8+rwPYMUegoeYOzs1G8YoHlbgsRzZQscDH1PDK2EaM0IUFaTZ4D46VQ9F+guqUJXm/+E6VKDQngIfCZcOCzFQXKDu4lLgyQSbmqx02m+54ghkmnSTL+gvfMU/zQRPoJy0oo8x77FZTD4BMybSJzov+dItsRYx5tzxhgs6Ef5+MjebtUQ+v1ET9fcg15JCyq71Qo7RYmkL8sYQSPI/4LNcm7aUuOHolcZ0P2rhWNnYShb/c68B9CoBM6+JRnUyPKV8bPKudvNcwmKjFxUE7DH8f6gUTkSm0PSEP2Zg5q612NktHWbgjfzheWHqPmS/Jw= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f11109ed-342d-42ef-e79b-08dcb5482a86 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 12:14:34.2656 (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: lS80txRdFrzMax+0Z7NRVooWlWRur37M+XL6JhKfOW9gx/TCsAG7NRe1wsNZ2eBQtWNqo0Yz0XOTViaeYf18QfqCccZYZDyGLOf0yienoSY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7760 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-05_01,2024-08-02_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 adultscore=0 mlxscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408050088 X-Proofpoint-ORIG-GUID: TexW1xy0RgNSdvv473OjaKNnUcs34RRw X-Proofpoint-GUID: TexW1xy0RgNSdvv473OjaKNnUcs34RRw X-Stat-Signature: h6ntq16ha4pwpu6c4rocshyq1o4fhcfr X-Rspamd-Queue-Id: 368CA40017 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722860094-102724 X-HE-Meta: U2FsdGVkX1/8GFshSMuPa/IGyKKStqsN4yenNzuP0e+nuoDwBTBEe3GxKkibWfvBuRyZ+mSfUa1rVL7VeLdc+MC9LSZKr/y63fhI7vrNgJBi2/AXbOD3hZlw824tQBPsWeXrZyUuXX/L+B/YOyOnZqweef09l4OZcWLc6IJ18H2znZWZ5b6P5k61Zv5rJkr6DHx6RX2fjSwt2D9vOt5ECB4FOTkZMTkfccGmhjs8hY8/9r/0SG4Tivahw7OJxxPzgG4X3sCMw0kQ0zzu1nG1Ot8N+b/nES2fAI4Kla2vdAr9Ct4tyCwxcq4pVt4oxOJcr2Fb6TKPU1ADlnp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XAhyZh+n+WhGBi4Ep2d+BAH/EjQO4r4UyAd0LNj+ayVEXML2fYGoERg== 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 added intentionally in advance of heavily refactoring the VMA merge functionality in order that we can compare the test results before and after the refactoring to ensure that it functions correctly. Signed-off-by: Lorenzo Stoakes --- tools/testing/vma/vma.c | 814 +++++++++++++++++++++++++++++++ tools/testing/vma/vma_internal.h | 4 +- 2 files changed, 817 insertions(+), 1 deletion(-) -- 2.45.2 diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index 4416cfa93056..e465dc22e2d0 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -14,6 +14,7 @@ #include "../../../mm/vma.c" const struct vm_operations_struct vma_dummy_vm_ops; +static struct anon_vma dummy_anon_vma; #define ASSERT_TRUE(_expr) \ do { \ @@ -28,6 +29,7 @@ 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)) +/* 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,6 +49,115 @@ 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 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 = vma_merge_new_vma(vmg); + if (merged) { + *was_merged = true; + return merged; + } + + *was_merged = false; + return alloc_and_link_vma(mm, start, end, pgoff, flags); +} + +/* + * 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; + + 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; @@ -196,6 +307,702 @@ static bool test_simple_shrink(void) return true; } +static bool test_vma_merge_new_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 = { + .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 = { + .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 = vma_merge_new_vma(&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 = vma_merge_modified(&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 = { + .vmi = &vmi, + }; + struct vm_operations_struct vm_ops = {}; + 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 vma_merge_modified(). + * + * 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. */ + vm_ops.close = dummy_close; + vma_next->vm_ops = (const struct vm_operations_struct *)&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(vma_merge_new_vma(&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(vma_merge_modified(&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 = (const struct vm_operations_struct *)&vm_ops; + vmg.vma = vma; + /* Make sure merge does not occur. */ + ASSERT_EQ(vma_merge_modified(&vmg), NULL); + + cleanup_mm(&mm, &vmi); + return true; +} + +static bool test_vma_merge_modified(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 = { + .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(vma_merge_modified(&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(vma_merge_modified(&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(vma_merge_modified(&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(vma_merge_modified(&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(vma_merge_modified(&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. vma_merge_modified() 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(vma_merge_modified(&vmg), NULL); + + vmg_set_range(&vmg, 0x5000, 0x6000, 5, flags); + vmg.prev = vma; + vmg.vma = vma; + ASSERT_EQ(vma_merge_modified(&vmg), NULL); + + vmg_set_range(&vmg, 0x6000, 0x7000, 6, flags); + vmg.prev = vma; + vmg.vma = vma; + ASSERT_EQ(vma_merge_modified(&vmg), NULL); + + vmg_set_range(&vmg, 0x4000, 0x7000, 4, flags); + vmg.prev = vma; + vmg.vma = vma; + ASSERT_EQ(vma_merge_modified(&vmg), NULL); + + vmg_set_range(&vmg, 0x4000, 0x6000, 4, flags); + vmg.prev = vma; + vmg.vma = vma; + ASSERT_EQ(vma_merge_modified(&vmg), NULL); + + vmg_set_range(&vmg, 0x5000, 0x6000, 5, flags); + vmg.prev = vma; + vmg.vma = vma; + ASSERT_EQ(vma_merge_modified(&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 = { + .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 vma_merge_modified() 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(vma_merge_modified(&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(vma_merge_new_vma(&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; +} + int main(void) { int num_tests = 0, num_fail = 0; @@ -211,11 +1018,18 @@ 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(vma_merge_new_vma); + TEST(vma_merge_special_flags); + TEST(vma_merge_with_close); + TEST(vma_merge_modified); + TEST(anon_vma_non_mergeable); + #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..40797a819d3d 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -687,8 +687,10 @@ static inline int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct 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, From patchwork Mon Aug 5 12:13:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13753570 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 D0A87C3DA4A for ; Mon, 5 Aug 2024 12:15:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA9C96B00A6; Mon, 5 Aug 2024 08:14:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B59AA6B00A7; Mon, 5 Aug 2024 08:14:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 937B96B00A8; Mon, 5 Aug 2024 08:14:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 6E58F6B00A6 for ; Mon, 5 Aug 2024 08:14:59 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2F855141E2D for ; Mon, 5 Aug 2024 12:14:59 +0000 (UTC) X-FDA: 82418085918.09.0FFECE2 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf24.hostedemail.com (Postfix) with ESMTP id CF0BD180002 for ; Mon, 5 Aug 2024 12:14:55 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=TpA7L04u; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=P2ia5gUl; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf24.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-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722860034; 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=feC8z8uC5xsEhMKYHwYFy7Lqw68zN8Vg415PZaV3Wtc=; b=I/AYs85po5PQMK05CZpzKrmJRw6POV6kfGaoUKjdBjlkB0HsyOG9kRazYLl7rJAlZdyQ5R lV8biCfZmVGc2m99rlAMFsgYegaFA65XkASdkdxSf7LldztCmC0De/FTUHRjOPRO185zfz OSR+c+9+4H4Fw7kC0+q0cwv4G99ZW8w= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1722860034; a=rsa-sha256; cv=pass; b=RLOMYiQwbzAxeg7X28dFS/SR3tTye4wnEgXLlyK7C6Gkk0qBj9JNLnsH0EH1ZkjihGonfl 6xY3+pmKXQoUZj+32fIcO0Qe4QknpJFTR+EfnNW1TpBOQhOESRe558p+6a1a8BWi9nIjH6 yYjmzYHYLdJA/60epzJO9GRywjWBqwY= ARC-Authentication-Results: i=2; imf24.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=TpA7L04u; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=P2ia5gUl; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf24.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 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 4758fWVV012608; Mon, 5 Aug 2024 12:14:55 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=feC8z8uC5xsEhMKYHwYFy7Lqw68zN8Vg415PZaV3Wtc=; b= TpA7L04uDrqL08js6Hb80yLUyo5Xa7gDX6n+97kcirfRGPFeqYIUdZzIiL+fT94V 75AlfgRaPBYgrkhl9yQr70DcNjY6D9jdHhrxqny6345zpDZzI33QZHNXQ20hA6Gp jwqLbs8pplkggMbEQWGSmBklhiBcD2I+mwDRG/JYB1g5HzBFIwcz/0hstgEmkUxi PnPM5v1JxNCT95ZzvT+HX8cSyK2xmVT5oFnwhGzIxYx1NCPSvZUFM252vXG7BII7 jlNVGFrR/MfsherCP4LLgTRoEWGpvRighZFFHBVZnYuPft9gxkgxtvbMZLRydvIr KaKCJjkRAFSInV58Fbdabw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40sc5tafun-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:54 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 475C0TYm016979; Mon, 5 Aug 2024 12:14:41 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2168.outbound.protection.outlook.com [104.47.56.168]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 40sb08eu9c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vI3lTj671hqMtxkf0Bc973MQHOdBdAvYvQmfoAc3pkqeXcFt4zrewV2bvq1KhhonUTd7Rwn7N1uFHOCn6COyhekrFbQ5DpuCpYmIr9KPXQHN0E4YfSZ4igvVd8/X7ksxYs5nfANUr9/8MhVQ0dBOkZD572bGyeCYPViuacOAKC5siNLGUtTASM/MA7hOSa7IgcjMZ+Zv/C1NgGU3XxsohBHX4a+GsawaEK20iX4nb5fIK5gKkWpBv30xBR4ToddWAbh/U76HtY7ka9egsEbnFAodHOzWFSfeTh2u3nz8bvfpdcOaSW3NRhwyBpyIudGXGM3D8j9QqHnsmfZ+/TH3Pg== 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=feC8z8uC5xsEhMKYHwYFy7Lqw68zN8Vg415PZaV3Wtc=; b=AKMhGvGhUMKK5d9cpPoC9vyKob23ydHMZ6t2/v/VxPZTTgr3nJgOTwboq4b7awv0GGbxXqdm7BjS3NDbrv04Vs/QWrmkvqq0ArpogvJmmE7A4ichQzXVdwXE8fSb9oZe8MSCMOOynRdf35pT/xfqbtza3w/SBPLm4xCUpIllkzWVSiF6V/bSzZ/IhIlOBloWJdGyOS2eOABeD/mLu1ilE+TZXl+u0oP6xz75JKMV4+qhw3gPuopO6Cn7/EWcwgRNqSlE43Dn1PiS9G2EQ+eqEYTFyBwWEiTQuucEZspbvQMXV6ZjNz0KL4Z4pV6jwiqYGuRm97er1dLC/CdDpk20bA== 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=feC8z8uC5xsEhMKYHwYFy7Lqw68zN8Vg415PZaV3Wtc=; b=P2ia5gUl+gcJa/MS2cRdCyIeUp8VhF0GGnvzkMLMpSbGU8SLMbO28UMnBDNk57Tdf0AdpC5vjntMSCJiAnfO8vyqAvk/C2IYGL614SNH6YVHeIP9ozjUZfYNgyRIma6xHX4iDMVoh8VAC+420S4/ADTGQGINf37z/Y/Xqa5Ymw0= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by SJ2PR10MB7760.namprd10.prod.outlook.com (2603:10b6:a03:574::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 12:14:38 +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.7828.023; Mon, 5 Aug 2024 12:14:38 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH 07/10] mm: avoid using vma_merge() for new VMAs Date: Mon, 5 Aug 2024 13:13:54 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0011.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:62::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_|SJ2PR10MB7760:EE_ X-MS-Office365-Filtering-Correlation-Id: 1b0fad8e-7582-424d-4eda-08dcb5482d75 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: X6X4Fg/qYR2z+hBynTdzU64ZWMI0yYyeMb1o3w5j9Lv2Dw1U0szjYCITam2vLDRJm6aFCNs3uxRW8QyGR0i/sCuZmwG8c35aDthEozc6VzTZDnkIr0PG8uf+FmjxFfQHuIjsrPR4cSc9Y4doIFim58RJVObi7hm6lT453/hITxgPGlvrKox2UmDEGkQ6YVkEfwVjS4kebHph8WqBo+0EA/mRRIUDLe7ZyGjWyQEvv8C/PzfBekdV+d9S9vAI/rPZ+yKo+F0WsU3GH0NBci6xBU9ia9XO5q7+bbVOQi+o+QNsdSQaOjJlcw6g9c5hA0eZ95357fkU2jiaROlNMfyaXrWptp6o/Z5MvdLbo/JYJBFeNSJCQ0J6zMe3ls12iee6BywYLUSZZX6U4VuyDe6hyszf1wjB4FDukkMAD22T9oiUlsaA8b93rRBOOTubrI40bFtgij0qrJ4zfi6nc6yS1Bx0YFfsJSiVg7Ipy9KA9tzoMej8GwbcEgrTI9TGcs7RaT+t/GqljjfbzTeL/AnmRppu21fKTdzB5iTi7lgbEokWYcriyoql1DbDRYEp/xIOyik/36Il6fwI1S2nn8oFzLV1Hn8NnFQQTa9BdG/XGBZa0n3zkj40gQ7Y5T1IVTl9Cy+pMllhIUK+BRRllRVnP5YF+fIwln9WTwr4vz3g+OG2lV/wsyWN/TAnDyxs1HVMrrCX3trwabORKaZA2TXLAucyob/FNHP8uM8ELmOaJfBcTWqyCZIcwx1zWMtibkBpSGfNJZWg/VQcoxDUeJMvoAbGwRFiDagU90kGcNir8RHPT1AaUO3lIjaHOOZkIHywCBIkBUw6eaazTE6QJrEUvc/tBMME5nbeX4MyLQlHfEeKntpJRHhh1mnzCd1hb04uG55cqPeT6ntWljlSJbkcP3zBY7TxComvxrHaB06m4rbHiDrhyUaYZwdY2VnVGNEMxERvFAKiBICKUSEDVc12gcAlynBsLT2/3WLwzu/v0lse69YcmZ8L8b3g0FnrmI1/qB421V5lpSiLUSmMsWnaG1K0MibnaxUrmNr/YNIUp2RmxDi4Uu1bYWQpe4b28xg0AoDJ5es9mQwQtAK0iFZ3CVHsIMob4dUrHo01+92YBg1VeYu+tz4GTc4UqVSQKwFVQg0bVYXhvyni+dUbCPxEf6FqLkI8AvnnqP/HJRB43HG7c0rrlMsXoO4NwtkxY6bz656BA70hTqikXbq4X09p/gPpE/hCcXeWjt2aLRal4CEyxPXeGy9LBhjyXQHb42TGa5esvE6WOUiV0l8SX+nVI9GXPjMOgVxpXNMfhNlQiQTpYnGTthiMMKegj+nyJVMlTXEsC3YNgmB3K8hyWxznEQ== 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)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rNwyRij/G+lybaoQcPOUjJZS8IuuFJBLejti8PQ0pTByTfM7APDLYk8nvPHdjSOxmNK9hP3koML3pm4cZarkt9eDU4/vB4ZVEGCfoSARvcZKnblF8mQbcaiqgteEyQ9cqP7sm33gnKuE8OKPvVhNff0POFp1gT9qTs2LVdmgXy54+f2K/Lb4vXjM45l2sdJjRytDG6vEdGgXrzqT6ynDx6Wg9Q8uqkPwYQI/ElLiO4zMtPihjl8/K/LuOoqJdb5Fec5+W8J1bZriLMHrYC7u2vXtJbFqdaxdtktNHjRtHZ09Yf784eR3sXW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cVO4gTaRs0K5DkHG4Ra6uawQPR7Th0B+J58NRbi0KZ27mOOZN4zv1+uPQLKyIFROE9/O8AVuaIbE/ZLZCDv5yXHRXKbTpJG/p0KaQC6IQmhe+eWyrIFne4Sq2nW/OfPIOyb5c68fuBwJlt+BK5zT/mLELzHod/BRpkav7siGRn/kpLOfH21iYKNWIQFFQLhBN9+6Xxz7KD+mdDIDuzen6pZp0cu8PMqT7Tg0kz026nmpcdDVkik0PXTYJP82weiyByZ3QuqyrFLMsbfmS1N6Tx+t4DlQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: J/S9W88fobQZShFq7uW6FhuQTN4s5eZlNXAQlM+xLfs+Lyutgr2pGv/ZPFok6+RBUCMTAqQR9O7EPHaAuMwcH8OJatLI96kWYmUmNYGatVy3Ac2y6q8Rw1dVn/XBUdu3qLra7tmHldovTsDy3GXw2NpSokebRPXsm4yKUtgIlh9cpoGLKBFkrYUyE+o2OEznJ2HGtzzpxFdhfQifFEbVZVqSI5LYRa2pnfQ4nHGUwA+k5lYAYyzX+KvlOVooaBNiKTtqY3v4Y9EdnS8MjPNfl1qBVP1CKuZS45mYlv4qt8WY9g5GAmDYNvLehuNbjqYGeHhKpnlRAjOpSYUVXuDc7JAVOV8vd4UHRBCkNR9/TaFMOuGi3kJHKqaII6faT+UMSuV8vgoCyce6gpTbUZFBjjWCaiDL+8QmwlWJ0XvBBATDOV8mBnvJTsm8L3tfza9HBzrRinLOrneK7nr4h5t0hjW7B5flmMdrx57k9aLYG6XCgDLQigUIkZSKPhu7NYYnapvAZ3vvAy22zEMqfH/K6Z6ku/HGAZMWLXMouXRh3J1EnRgCvATjHFYC9JVwCVk5cR8hdBJ3B2xMWV8R18twwkBN2gpfq9fyHcIVLIVNvDk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b0fad8e-7582-424d-4eda-08dcb5482d75 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 12:14:38.7685 (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: H1BjCsDASO0fg12oSLQ2QDpqMMwjylLANA+OywGCwZnLcQEeguCIYU2SAilW6ZjAawKUgcCDmH4ggwGdyjAHVdcBEFdEVmfWAl33K4Ttwyo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7760 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-05_01,2024-08-02_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=0 adultscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408050088 X-Proofpoint-ORIG-GUID: H6T1aqxQyXBKgzCW0UgupLC8pPswydHx X-Proofpoint-GUID: H6T1aqxQyXBKgzCW0UgupLC8pPswydHx X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: CF0BD180002 X-Stat-Signature: zgda7g68myp4rxnaii6ribeptj4j9t5a X-HE-Tag: 1722860095-735044 X-HE-Meta: U2FsdGVkX19U4UmNjtkIjJGYC0bkxrlYs0F4oSB/85Kz/vguUdzhNFHaxhc9qt2TcTWcvUaZse9JfaTxHCV5iE5xGGdtE19pE17/DgPTeghWx6JYfgFVWr456Wmccn19zsvJQFT+u8BaLK5pnCScI++0/Znk6P0A1BBtLepArBgiROFTToduz+K+XJr3in/Tq/WNH4brOQX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y9AFPhIBNJxIc7eFYBmDQ0jjhY0zoHxx1kMdiss+jw/+Bth5GXvcLDKav8yCdtabiWhXz/eQqnJPRKDU4PBs+THgwW0zWqFuqEwYXu3MDRadncIh3YLWZ2qPp7icx5srQZ635ad2ww/N2jq4pPNtCAjz1eHjcHJc+letSi5p0SLKR6lzsdFB4oSQhJ0YkysqRP4WhaEaxsGvpbLwBWH7r/nrDyjcYgOdgULMnHlRik+wNRYtEpE= 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 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(). We implement this by replacing vma_merge_new_vma() with this newly abstracted logic. 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. This makes it far easier to understand what is happening in these cases avoiding confusion, bugs and allowing for future optimisation. As a result of this change we are also able to make vma_prepare(), init_vma_prep(), vma_complete(), can_vma_merge_before() and can_vma_merge_after() static and internal to vma.c. Signed-off-by: Lorenzo Stoakes --- mm/mmap.c | 79 ++--- mm/vma.c | 482 +++++++++++++++++++------------ mm/vma.h | 51 +--- tools/testing/vma/vma_internal.h | 6 + 4 files changed, 324 insertions(+), 294 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index f6593a81f73d..c03f50f46396 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1363,8 +1363,7 @@ 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 = len >> PAGE_SHIFT; + struct vm_area_struct *merge; unsigned long charged = 0; unsigned long end = addr + len; bool writable_file_mapping = false; @@ -1411,44 +1410,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vm_flags |= VM_ACCOUNT; } - next = vmg.next = vma_next(&vmi); - prev = vmg.prev = vma_prev(&vmi); - if (vm_flags & VM_SPECIAL) { - if (prev) - vma_iter_next_range(&vmi); - goto cannot_expand; - } - - /* Attempt to expand an old mapping */ - /* Check next */ - if (next && next->vm_start == end && can_vma_merge_before(&vmg)) { - /* We can adjust this as can_vma_merge_after() doesn't touch */ - vmg.end = next->vm_end; - vma = vmg.vma = next; - vmg.pgoff = next->vm_pgoff - pglen; - - /* We may merge our NULL anon_vma with non-NULL in next. */ - vmg.anon_vma = vma->anon_vma; - } - - /* 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; - } else if (prev) { - vma_iter_next_range(&vmi); - } - - /* Actually expand, if possible */ - if (vma && !vma_expand(&vmg)) { - khugepaged_enter_vma(vma, vm_flags); + vma = vma_merge_new_vma(&vmg); + if (vma) goto expanded; - } - - if (vma == prev) - vma_iter_set(&vmi, addr); -cannot_expand: /* * Determine the object being mapped and call the appropriate @@ -1493,10 +1457,9 @@ 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_wrapper(&vmi, prev, vma, - vma->vm_start, vma->vm_end, - vma->vm_pgoff); + if (unlikely(vm_flags != vma->vm_flags && vmg.prev)) { + merge = vma_merge_new_vma(&vmg); + if (merge) { /* * ->mmap() can change vma->vm_file and fput @@ -1596,7 +1559,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(mm, &vmi.mas, vma, prev, next, vma->vm_start, + unmap_region(mm, &vmi.mas, vma, vmg.prev, vmg.next, vma->vm_start, vma->vm_end, vma->vm_end, true); } if (writable_file_mapping) @@ -1773,7 +1736,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 @@ -1795,29 +1757,22 @@ static int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *vma, */ if (vma && vma->vm_end == addr) { struct vma_merge_struct vmg = { + .vmi = vmi, .prev = vma, + .next = NULL, + .start = addr, + .end = addr + len, .flags = flags, .pgoff = addr >> PAGE_SHIFT, + .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), }; - 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); - khugepaged_enter_vma(vma, flags); + if (vma_merge_new_vma(&vmg)) goto out; - } } if (vma) diff --git a/mm/vma.c b/mm/vma.c index 55615392e8d2..a404cf718f9e 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,164 @@ 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); + validate_mm(mm); +} + +/* + * 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. */ @@ -292,31 +449,6 @@ static inline void remove_mt(struct mm_struct *mm, struct ma_state *mas) vm_unacct_memory(nr_accounted); } -/* - * 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. @@ -349,60 +481,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 @@ -486,6 +564,120 @@ void validate_mm(struct mm_struct *mm) } #endif /* CONFIG_DEBUG_VM_MAPLE_TREE */ +/* + * vma_merge_new_vma - 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 also adjusts @vmg to provide @vmg->prev and @vmg->next if + * neither 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. + */ +struct vm_area_struct *vma_merge_new_vma(struct vma_merge_struct *vmg) +{ + bool is_special = vmg->flags & VM_SPECIAL; + 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); + + VM_WARN_ON(vmg->vma); + + if (!prev && !next) { + /* + * Since the caller must have determined that the requested + * range is empty, vmg->vmi will be left pointing at the VMA + * immediately prior. + */ + next = vmg->next = vma_next(vmg->vmi); + prev = vmg->prev = vma_prev(vmg->vmi); + + /* Avoid maple tree re-walk. */ + if (is_special && prev) + vma_iter_next_range(vmg->vmi); + } + + /* If special mapping or no adjacent VMAs, nothing to merge. */ + if (is_special || (!prev && !next)) + return NULL; + + /* If we can merge with the following VMA, adjust vmg accordingly. */ + if (next && next->vm_start == end && can_vma_merge_before(vmg)) { + /* + * We can adjust this here as can_vma_merge_after() doesn't + * touch vmg->end. + */ + vmg->end = next->vm_end; + vmg->vma = next; + vmg->pgoff = next->vm_pgoff - pglen; + + vmg->anon_vma = next->anon_vma; + } + + /* If we can merge with the previous VMA, adjust vmg accordingly. */ + if (prev && prev->vm_end == start && can_vma_merge_after(vmg)) { + vmg->start = prev->vm_start; + vmg->vma = prev; + vmg->pgoff = prev->vm_pgoff; + } else if (prev) { + vma_iter_next_range(vmg->vmi); + } + + /* + * 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); + return vmg->vma; + } + + /* If expansion failed, reset state. Allows us to retry merge later. */ + vmg->vma = NULL; + vmg->anon_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 * @@ -496,7 +688,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->prev and @vmg->next. */ int vma_expand(struct vma_merge_struct *vmg) { @@ -576,85 +772,6 @@ int vma_shrink(struct vma_merge_struct *vmg) 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); - validate_mm(mm); -} - /* * do_vmi_align_munmap() - munmap the aligned region from @start to @end. * @vmi: The vma iterator @@ -1261,20 +1378,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_merge_struct *vmg) -{ - if (!vmg->prev) { - vmg->prev = vma_prev(vmg->vmi); - vma_iter_set(vmg->vmi, vmg->start); - } - - return vma_merge(vmg); -} - /* * Expand vma by delta bytes, potentially merging with an immediately adjacent * VMA with identical properties. @@ -1297,8 +1400,7 @@ struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, .anon_name = anon_vma_name(vma), }; - /* vma is specified as prev, so case 1 or 2 will apply. */ - return vma_merge(&vmg); + return vma_merge_new_vma(&vmg); } void unlink_file_vma_batch_init(struct unlink_vma_file_batch *vb) @@ -1399,24 +1501,40 @@ 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); + struct vma_merge_struct vmg = { + .vmi = &vmi, + .start = addr, + .end = addr + len, + .flags = vma->vm_flags, + .pgoff = pgoff, + .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), + }; /* * If anonymous vma has not yet been faulted, update new pgoff * to match new location, to increase its chance of merging. */ if (unlikely(vma_is_anonymous(vma) && !vma->anon_vma)) { - pgoff = addr >> PAGE_SHIFT; + pgoff = vmg.pgoff = addr >> PAGE_SHIFT; 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_wrapper(&vmi, prev, vma, addr, addr + len, pgoff); + vmg.next = vma_next(&vmi); + vma_prev(&vmi); + + new_vma = vma_merge_new_vma(&vmg); + if (new_vma) { /* * Source vma may have been merged into new_vma diff --git a/mm/vma.h b/mm/vma.h index 50459f9e4c7f..bbb173053f34 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -55,17 +55,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_merge_struct *vmg); @@ -85,20 +74,6 @@ void unmap_region(struct mm_struct *mm, struct ma_state *mas, struct vm_area_struct *next, unsigned long start, unsigned long end, unsigned long tree_end, bool mm_wr_locked); -/* - * 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, @@ -133,31 +108,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_merge_struct *vmg); - -/* Temporary convenience wrapper. */ -static inline struct vm_area_struct -*vma_merge_new_vma_wrapper(struct vma_iterator *vmi, struct vm_area_struct *prev, - struct vm_area_struct *vma, unsigned long start, - unsigned long end, pgoff_t pgoff) -{ - struct vma_merge_struct vmg = { - .vmi = vmi, - .prev = prev, - .start = start, - .end = end, - .flags = vma->vm_flags, - .file = vma->vm_file, - .anon_vma = vma->anon_vma, - .pgoff = pgoff, - .policy = vma_policy(vma), - .uffd_ctx = vma->vm_userfaultfd_ctx, - .anon_name = anon_vma_name(vma), - }; - - return vma_merge_new_vma(&vmg); -} +struct vm_area_struct *vma_merge_new_vma(struct vma_merge_struct *vmg); /* * Temporary wrapper around vma_merge() so we can have a common interface for diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_internal.h index 40797a819d3d..a39a734282d0 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -709,6 +709,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 Mon Aug 5 12:13:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13753572 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 E0C34C52D6D for ; Mon, 5 Aug 2024 12:15:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CBB86B00AD; Mon, 5 Aug 2024 08:15:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 650766B00AE; Mon, 5 Aug 2024 08:15:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 454686B00AF; Mon, 5 Aug 2024 08:15:07 -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 277326B00AD for ; Mon, 5 Aug 2024 08:15:07 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E0ADA1C590E for ; Mon, 5 Aug 2024 12:15:06 +0000 (UTC) X-FDA: 82418086212.16.A06D0E8 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf25.hostedemail.com (Postfix) with ESMTP id 734CBA0014 for ; Mon, 5 Aug 2024 12:15:03 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=OlAx4ukm; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=xTAbzBLf; spf=pass (imf25.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"); 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=1722860096; 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=6Ple6hXc4jx7PabhHpYlqjMxMkcz+BvYXU8D+mrSt2s=; b=b0O6LEXptJUXEUVE5z3JXJgeRSXq0QDfzUKZipA32vgsgaLNK7LSLRLUsXI39m+6Xoi2A1 k0dab1LNAmgFByzNCkqUNvFnzrQ2FzaM2/rxAtE3+fBHBM0E2czWmD/r2W4SXlrBkDyayg i36yni5JjGigTChdlO2z251R77djnjw= ARC-Authentication-Results: i=2; imf25.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=OlAx4ukm; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=xTAbzBLf; spf=pass (imf25.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"); dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1722860096; a=rsa-sha256; cv=pass; b=rp3OKa0wAjwQ22XHdT7DGLoFTXrk/BDbhz7PUwajjiLaHlMqW8ix6I9Xk5lsqKxfaWvKn2 WivUmmMGQLMze66CqR7ZLl+Z10iL5gONs+Mt2RII2+oRM70+BZQOmW44dQNlhFTtb2X8Ti oxrYIFUS+KfsIXdd5h6fcII1T1zQ9VQ= 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 4758fW4X028177; Mon, 5 Aug 2024 12:15:02 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=6Ple6hXc4jx7PabhHpYlqjMxMkcz+BvYXU8D+mrSt2s=; b= OlAx4ukmfEs+gSLRQBZnH0D+pTvqWbi7OZ8NSvgBQ1gdNWIl1bpSffN9GBcu2jQo Rs8UN1DRV/j+t9JQGEeNUlcF3PzTm92sh2uofPABLdtWzgXfkZHATIKpUC3pRczW TUFsDaKD6NxCY9/7vEid5E5EZQViT4fhF1vV476JYtlrlU5/AZHWlTAd/xucfaO0 /1MGIICsVCUPP1bi5sGfMa3Nid9a9CQg49SoRkcjvWhduf4pXJ6SMNi/xvJP1KVI DKOCYZMWJRWuE9qm+wuqWgBjtyJuKko0LWJ/F9gNmGE0ixAZ2MCIud97k6Dyg3M1 5TTzxgdo4+7+YlyhiZVJLA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40sd3uje5u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:15:02 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 475C1vkJ027390; Mon, 5 Aug 2024 12:14:45 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 40sb0den36-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=g4ffaJ9mLd6EQrnGB+dfpsS2orI5yIRRkZlEyQ2e+cQDMScAf1wjvLYhNTQbfSIL5j5pmgS6gpjkars+LqSkSEVU3UVnokiEg+5XMXqtupqHzmKQFyoOYcibYbYiszn3BBXsz3PH6zqwhAXVkD/+aO0hz3Drj/yFHeXvC0vmbgqcd9aIjRyiAIzfPoD4KlXZbf4uJ+KBiTXkwDY4IU9FSsFA1s1IJOXMeSb+XVVYIxvccA/+Qk/XbLhZXLWCHX+453bHTlreU2ZqFjZb2lb3lP8tqEBxTDdkLPLZuoqZc1iROIDzxqfw0OBHzrcpwqi4U/oGD0Wi4Hdc6NtmSGwWpQ== 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=6Ple6hXc4jx7PabhHpYlqjMxMkcz+BvYXU8D+mrSt2s=; b=rjL55n1Il4+CmyanNd366rDE5XA4akAtrMzf9nH2jUnFi2DUwFAO4wW1a52qmwgCt1FfJ4FNcTdoV1uUTBZZFjd8/btJBQQ6bSP+hJwx6n6U4O5Q+wsY14uCux0lHyIpdiaxK7WGi3qeqCX6F/H1m37zgCl5sxvlRxBpjU/dSC0Y2/uc5gUeaYPhRcyex45N4c073dKPeZZ5RgZ8UXW5XMQcIxXTi1r95A0/oEyWjfsRni+MrYMh69bR/nj15tsTSLdSGcyhZOuuoew/ABZaYp22KyAeBji5JD7FkViwTD5MTN0Yr+5gluFybSS8erEerjj7NMsMf+smFPQNRxGWMw== 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=6Ple6hXc4jx7PabhHpYlqjMxMkcz+BvYXU8D+mrSt2s=; b=xTAbzBLffCrPdrWZ2wxHFIhRvZw5Pno9o+JZxu4s/Xt4xdg5zAYKl1/1vcQfc4jtuRK+SbHPvJHCTa2sGkw47OFxYAxR1GS5h4k+E0QSMcNCmPIqvUizWVJ0VyJif9bs78PLrYBqCUSEyXqm/JWT/GF6MIUlyCg8hfXsM1NopWo= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by SJ2PR10MB7760.namprd10.prod.outlook.com (2603:10b6:a03:574::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 12:14:42 +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.7828.023; Mon, 5 Aug 2024 12:14:42 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH 08/10] mm: introduce commit_merge(), abstracting merge operation Date: Mon, 5 Aug 2024 13:13:55 +0100 Message-ID: <3b04eb13b499df3ebf50ae3cde9a7ed5e76237fd.1722849860.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0415.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18b::6) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|SJ2PR10MB7760:EE_ X-MS-Office365-Filtering-Correlation-Id: c221a2d9-754d-4ceb-81f9-08dcb5483006 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: E0mpvROksV7KBRvAq+cC3+7nmP55gq2ucU4u4PgIqZQjkCMJshYot8y63lk0nGdYFVo+Q0NsIoqNNEEuEMosHu6pN7lU1oqeiaGw7BcsJrsBg5C100TWXlIyhMVkhod4YofQCrG7BKVYwj08+KQeJ6QtNsk17F4ybv2bJKcqHf1Ad8mb4H2hoPkoPiW2l5aTdTLutNddeK0mpoTtnBOxwLXk/nJboGdMboZm4WGoY4qDId7cM8X1Umr4wIi8J08dsV2oL+OlLeYPpJ8IeLghCkNK5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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)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FTj99fPZ8VfH5fMcLMiuG8CVNHWCPcddi2rLLiMuSVQKQpewNkhSECYfdBYvxmErc68YcYda736mSc8xJipaFeSYNHxBf5rTY1FQgsRerqV4g+sA+nb/eAhHX9fl1H2qzJWpJB4Fkr86d85nJpdeyAIvpVifME0EFN/F/yiwlfu/tSaYNx38PtDDeiw+qO5A703jnBJ7Rn/5PDJjpTBkkQ66I/w51etDDQguzPRbHCNC/jKmmDgenKLvgrMq3ibZxR7O5oFY7zEUJmKm5ox/lhIna1brPPGLLMtvpYfIWOSQpsqdoMLMa10BiyXKmL3TbhpjW774J0IgdJTUuYEuzTHRgUTcAN1seZrKRujFrRc5w57VSe8VmR3PdIlUMF/6Bm7eUH6PYjRaMKN5II6nYGSo+ObTkgzRS8c4VmUJOWW72T91NqOtkJ8DTsdsGVogNlZtKKKIIdUu/M00hc3Y0oupATuEg9bLIRjYREc4DAbe67zjRfqwYsgEYqEWLeogrfqoxHzeg/BVw2kayoIwpOF3YC6r8I9VV4jaqp0Pk30QiKj4C2yvq1wIcy8U0z7RzRASNUTUp3USmfGNPzZIzhm1ESmaVWCB9rW2eeJ5mBmvyI+8Hv8f3Pm1KvRK8i3c1QAMafCDCuj8ALYfm9z8+xGHSTzeR7eSJyOKvOv6B5yFcRRp7zxtyDnFDJbuCYqpG6wtweVOZ9xiIKmb0vAwVCV9RIzTJfdCWNlbMzk0xe9xcN6nqlbByW3KDyO0qVfgLC1MZ8AvNGoE4XJaEq/aQPao2RhH2uw83vi+ghhELjkAzmMTXTGBxIZeRw7C7P6fMghywddB85hRPU8+KN67bMGYw0YdE7Vq3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G7zaYAL4TQde0HnHeHCwHlOjbdT6U8EJW0UBXluAqOZWXxbDbues3sayqgNg4RDGETMT475CNtW05QAOZm9IXQIRU72+l/AGtu3pNvrl7uh4qn45avpZvhdnZTX8gcd3J7uPTqVjFBqgI2r0br0jUjC4CrVEPur5Mc4cqa1C9wCrChLJQwzCEsAZn2jogbNJskT3fXeBegAd+eLHfowOXI36v9lglZDs04ZsHuYMKCrG+xGA3q8U5tTn0ZiOdqhUyNvpQLV0pWtYLLbGhgBJlH8PPMkyzw/jvDMfLTMsmhAWnnYkatRSH6jcgWo+vb2ygab8b+pJMd4zrB+oD7OAoJ3eHkaJUjKhvnQeqU+5HlG372otDX4ivqBxe4brLXGmODv2425h0D9oyvcnF6ZeoxYfzEsdak921JIpwLW+nKNLAtK6pE= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c221a2d9-754d-4ceb-81f9-08dcb5483006 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 12:14:42.8476 (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: cB9dycVgP8DTlhygumERxy7NKsPBmUHa8m3edpESh/KEzQBGbGHeCHsneyuseX+ZglWYtkatXQRKDyQDGj3zNB9SXJH/jh17+3hbSUisXhY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7760 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-05_01,2024-08-02_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 adultscore=0 phishscore=0 bulkscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408050088 X-Proofpoint-ORIG-GUID: xbUoRhxTiWarJC2wMwT7u_TxEG3X9wtv X-Proofpoint-GUID: xbUoRhxTiWarJC2wMwT7u_TxEG3X9wtv X-Rspam-User: X-Stat-Signature: cpacw5mg9tye8ehudapxbpz7pwzg3fc9 X-Rspamd-Queue-Id: 734CBA0014 X-Rspamd-Server: rspam11 X-HE-Tag: 1722860103-833872 X-HE-Meta: U2FsdGVkX19Iq5xorpETnpHHmlQYgiY65DquQIsFBnGm5uvlsub13ntPNiLQrkP4svQyWzc2dHko8XrM4mGoeGqVjRY0wyjq74EP7rvjA/sTXJvZ5HRHQWqZOr9kh+TxGOOSm+lgYem4yzYkBdaL7y/8EWT/jETsYDg3CPj7RMTSvE8HxRBxsVIejGOBoh7vE5INCdvewVkL2T0vKoer63AmZ20dOqfIzybh6tguov6AYtBEIzwwTKbTODYWWcRpO1gwypVtdVuKGGx3Gaao/MT0ikm4BsT665Hj8xEi/t/YUmiXQLxhoXmE73Ou6TzmlguqyxvNBWgR8fnCmJP56a/fmaSOjx1T2ja0kLtO4GqalFXH2l1jfmjZkS4AAj0Y5bdsdMRwqSGFm9twDx7M5nLvYMasvuwg1YW1xWinO6MgZJXDy7DgiKJ1oD1tm3ZGo12Gx8ET6/JvJjiTya5+miJn7UtDZboLeseus50bw2/4smJ0GGzsJRKZNkZVf3+xctnCMcyNIXGdQnPoMOx/Ox6YjYl3YlKcENXTpBYWWPwcHLWWJx5nsGBkyqDPzrolbyU4BzTzGmN7C7ojImeWAAEp0LnQObR3IU4KnTc9sO5qLWNzMN0rL33NZhtJfm/btoEV8Ub5p5RIun8TGbVf0btYpnnx/0SQjc/tXQJmk7W6KE/vIPsmJRXAIvVyFY17KascoliOigG+ym9/t/0eRQMHBgiFGg4y8GE9ol8cqQd6yOv/IfRultfPt3Ny/6rwMKPpydMX/82884WPieCa4JhJZpP0bP7/BoPqzzLGgijAz8Ks/U4zL7Dg9cZFBpggfbEjLy44Oe+TGRpsPae0GIB0d6otNZPzwDwRdhLWATJibwXWtkCjaiNlzvuMZc4GmHfnFW271tVAhyjRDkwKNMIQOhx/jJyrkGJ7yOvOAHGC65c6aXWCp+hbHSzm4fQmxq9SdTVcR8ovpRztMxy TngjMKDK B9hXK606GOIomV6rGvVJU2r188XYB6tYfSnHZJcX8vujdvziua1eKiX9U6Mqj2GM+tkKXsBV7G0zK+BNTQKuvX6p0KJOLObwXibLBCkxse9w6v20D+GeWbWAksZ6ipmOt+oHkOGoI8n8pObRLXDePwzSaF2WMfpjLbmXtSR44wQbKNgF7GyzoF0UQ5ybsTBMctF6HE9tftNjlgza3ayVVAHytj2ymBWtvUZWXxkdB3GJ/fcyNqe41O2KigDRJumoA4EKCNs06Q0Iu00FAMLEzM5e51XJYRvUQNupqRGG9gN5kbfJEsPNBH2CDJ5CNuETNahTZR1KqGrbR1IndNGhD6x/3F29Z2CVnl5dNJSiXcAbiQ3cvfpa2qWeggL6VFc/jtL12GoyNdwzaTzGxzp80fpLdZ5szxOKx6rSHZ5+sOJuETApDNPtMJ73qhMfRuiT9LMfjzLG3UI545k+v7VGgK9oN7RWIIXXFCSO0+pbSN31ghcOjqwXI5FdiVc89UzeISnCpSyKc3puQUEo= 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 this operation into its own function and have vma_expand() call commit_merge() instead. This lays the groundwork for a subsequent patch which replaces vma_merge() with a simpler function which can share the same code. Signed-off-by: Lorenzo Stoakes Acked-by: Vlastimil Babka --- mm/vma.c | 57 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index a404cf718f9e..b7e3c64d5d68 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -564,6 +564,49 @@ 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 *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, adjust, remove, remove2); + + if (expanded) { + 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, adj_start); + vma_set_range(vmg->vma, vmg->start, vmg->end, vmg->pgoff); + + 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_new_vma - Attempt to merge a new VMA into address space * @@ -700,7 +743,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; vma_start_write(vma); if (next && (vma != next) && (vmg->end == next->vm_end)) { @@ -713,24 +755,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, NULL, remove_next ? next : NULL, NULL, 0, true)) 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 Mon Aug 5 12:13: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: 13753573 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 C8760C3DA7F for ; Mon, 5 Aug 2024 12:15:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 58FD36B00AF; Mon, 5 Aug 2024 08:15:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 540266B00B0; Mon, 5 Aug 2024 08:15:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 31D3C6B00B1; Mon, 5 Aug 2024 08:15:12 -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 0BF716B00AF for ; Mon, 5 Aug 2024 08:15:12 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BB96A1C5945 for ; Mon, 5 Aug 2024 12:15:11 +0000 (UTC) X-FDA: 82418086422.14.ADD0FDA Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf06.hostedemail.com (Postfix) with ESMTP id 58301180018 for ; Mon, 5 Aug 2024 12:15:08 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="PtIBKqZ/"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=MFfCRyud; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf06.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-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1722860101; a=rsa-sha256; cv=pass; b=zGKnfulc4qG3Hw+DcdqckAiRzDQNUttM0PuEiMDgUSf1/1aIkV0c4CoZDRaIR2hTAxfeGq 9GW+j1ys70a7u/zqYcc4DW/SejYkmMXSHzMR8D1Adkp+f0kpFzFPvyi8VqT6iBYodfn+ev nMILQZzMEJ5PZBPrRUxQpm4AsdQDmAw= ARC-Authentication-Results: i=2; imf06.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="PtIBKqZ/"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=MFfCRyud; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf06.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=1722860101; 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=bYQk9Vtsd4JlmFKs6P23Vuo5xBwRpp8167VysTqmo+s=; b=AS9AEHpg49FOT+S2aCHsI8NvOnbUA7tLUrlgOLQ3E4Iqbh9hov27r9Ez6zdgMXxL0YeuP7 R+hjy3daYFZTHfsl7HdqLeNnJ8u4KRPfv+Th1f0yDrMgIXFN8OApKAXcMSOeOKssvchJrA u7UjKGepYIiTfbf5CFJ7lodFmIQvlZA= 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 4758fYEb026939; Mon, 5 Aug 2024 12:15:07 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=bYQk9Vtsd4JlmFKs6P23Vuo5xBwRpp8167VysTqmo+s=; b= PtIBKqZ/xS1xi8J85gOg91FPgFHwE/k6MVHCN9Y16lnxS+Qxe6y6/S6fo2uE6oN1 DhzZyNBXQm9fRMTbRaS47CV3NSFSOdWiectshvEptG6CgLZ/NuMWAzngnnU1OHlG Jt3QBUHhm6XW5qLa/9GT/f9uqOLc9uEqjqreoJRBLBHsMZt7wXrgPFIcBkeFdbsj MhUyd7/59uXrUpE+gPcqhbypqx7EkXe8iIRnVrL2HxAk/BLjlbPzOiLl4URUkWw3 Zy3yUvipJMvLTNYWBxGeBSZWtQcFPPjgV+7gUkufj9oggohyWXIduntmneJY1Q5G hItElSr9wXEyuQRDzovy8w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40sb51ag9j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:15:04 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 475BoM08017725; Mon, 5 Aug 2024 12:14:49 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 40sb076pj8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wjZPLTquSkJXo8N84EyMqkfD+2yYasWkNHTGFzAG3jz5f2NmNHkdhrstvkFf6Y/2Fu2i4DFQixyXZYyN5Yunm5I/id/XYj5DBUI2MmQhDlrshcxKbcDNaMaowt7qfZDhErKZAgEASNhX2QOkYMfqDP6p/v22PH+YV3mBs5JGaDih0P8OwPQoVuFbL9ZKQmjKZKHcoNNjWLEVJWi9ksZhF7qK9QPrPslxL2HnQXfkv1z4pa+/y6CW32xrwwH1b8NMo0IBPUCNhpq6yGf4llP+rBPrwXqzYcg6WXV3RngxFMj3mtxVL46Oj+lqLncZuyASQ+2GUztDhJqIM8AbIIYdfA== 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=bYQk9Vtsd4JlmFKs6P23Vuo5xBwRpp8167VysTqmo+s=; b=DjFEjl57f4kRCaY1osoP1vdFgg7VBZAac2vVY8cH5SLC6nQarZiQOtDG8Xcbzy/kVoVgVU1/8X6Q1ctSPuXgA2p/krh7saT94antneTaB1lFa1lxxOp+jEQlmaDIytT9aOUqPGt04uK1ISBwzhK373qeBy7JpWNteTiW8YuitDVqVgM4fSHFRQobylFaSH365fFVTDp7sJh94ulYI6urovpABSqZsGewylTojQjr3GEiVI+q/5K/XTXPCTKRxtxLU1M96/jxG+qlyc9rza5rqdomHp5mjWtckxBf5hk3dv9xhHz37b5SFB09yDO9iKufveJ3StJWwYKYnP9S4WsCNA== 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=bYQk9Vtsd4JlmFKs6P23Vuo5xBwRpp8167VysTqmo+s=; b=MFfCRyud9V+/tC0On26dOmK2+lHLbXDky8dvuHb4txYB7m8KQw9Q7QYgSrFviiyfCZ6vDfyIM5n7U/ALey64i2ncsUh2vG8G95UTLw/cRQF7pLaRXZt4TBsoE3Iq2pzSgt4BvTFK3Tk8S04s/OO6G1MSeXn/HGNaf5h+u3TA77E= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by SJ2PR10MB7760.namprd10.prod.outlook.com (2603:10b6:a03:574::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 12:14:46 +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.7828.023; Mon, 5 Aug 2024 12:14:46 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH 09/10] mm: refactor vma_merge() into modify-only vma_merge_modified() Date: Mon, 5 Aug 2024 13:13:56 +0100 Message-ID: <5ffdf3241d10bfe96371947a27f596bf21761af8.1722849860.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0600.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:295::20) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|SJ2PR10MB7760:EE_ X-MS-Office365-Filtering-Correlation-Id: 73df79f8-7fb8-4e56-0bbe-08dcb5483229 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: pjWnMBstPse+L/mJadyGx52HKDAaY6vPjZAdwtSz1G8nT0fioNmonhddsU5L/HMYmcm2SztBte4s4H1AEQnAdPJWv0Q2LyWt/HRPhu71gOlfLRoug9Fgz8nzJa4Vi5NKupP45SxTeQtoDzEfXXM4dkq6CF4qcCRhuS9dse1jhJsRc4bwzQVz3INCE0Gkj5PnmNgYMhudFmeRTEaOsUaRjlbZEv0URkZEX1yZ9L1RIaX+BWz4rL3scqCnzEH+a4DRGpHCMigkT6hGAKgg3ut0Mao5ygZjaxDJltEsF2WmjeVSrq/bI5U4ecPvsKIGXB97gcAff6Zsa2WqB84FZCwdOgwRdOgjLGBTcpzqQ3v93xwJFw+WyVjHBNslWxHx7Pt4/Wg7rOHLqqbFr40XzpSSueND0Vw8176H7fIzlsh1vsUD9syfq9GR24B5x2WLBiehHqpE2rPN7iddOVB0ulVyIH5IjFk//eEvNewvG+OWVV1tEt5ktxmULrHR+9gGkMaxgkTl5H6MPXQPcjJkFsclAxXbu+mQp64W49iJbGQZ6CdN9uu6Ty6oq/xxYBGzGuTenH6tstaRwvGTI673NRWZrBaaL0+drJ/5WvC4x7mtJsg4ASyu87MgEZ/HINIauImKC4Am6nsTZmxgMWzcLjWjEDTG+hu4Q1Z01rjCXYX+Lm+RfAdlchbyJlvx14B+sIrHRmsWStVc+cGDvlOkAjaMSDtFpLz/pqRzyeC8zqZ9fotIvNALE+eoJ2bT9gDir7Uabc6X/ebaJ7lCITFdKQ/R/YDL7vEp1djSBdez76Ku+30FMkAYs9TasTkAFX52ogVCUd+t/lKTi9OL/2584/mK5bI1x0B8PvkInVHHN1Ta8HmnOymV/pbEmAr/s5HFenyofuSO5eNy2L2DOzMNEOTNJg13jwPu8q0btu6dw9R5SxJKmyatXo7VWkcAVU9rEcXcTMdRo0B6isauWBBBsUAR52IjkxVU872A8L1jZYilI1yeOackeJSUO/S5wNVu6wOpyx8UATuFU9dEs4Y1JwOiu99hqssYkPjMNZO/5uvj275K2tT1YT9nrpmMt3+Kt9pAs1Hm79M81TZkeWI57lNK85QHTcRFyrap+kuUd6woNss3JrkkbCrM+BWFN8v7Ojb19g6Ej7G7m30u7lm6lf5HnHKQM61PSksZK4u1tSAeENHUXNFX7iVuqHKwmCGSvJe6UCmww968J/z+VtMR9ltIr0Cgp3YNVDN/ttgjMvGver/wOsxO/MWL8EW6URtfi3jbfF7LHMw1gyAH0lp6sXcD7F5lS5mJDChD2guz06W6IkgYqMG8o8lHnlrYdzKzUiXf3McH7jcvHz5kWsF+2CI62A== 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)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lZNISII5nIqo8KGcACaRhlFrbqi5noYj+wy7dhOAy4kpglV6EjShvSvSGMU3oKaE4O+t6jvYilsqIJGKX9DL9Jhv0/nUTRyFW+Upw0DvBOdJESTYTw8tue67Ilo1PKszTD1zeZfGW5Kir9IcMNyi453i+OEMcwehLFkX/AyOWof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jHv2UZaAFYi+9+U/NbyV/NTLlIeYLXZ+2l9PJZCMq65HskzwwPdQwdAcw3Tsr60J78ichtI0C+ihb/WIDpUddLP7ZNn28+YLV+4kzYOyjVmK1HZ93v8dZedhVXYx7JE6aA/S8Vu5YNNAOVc4aTz8txVW23ck4Jus6kWG3vxZ8xFAZPTcEdd84cY9VJiPLFsU5iw56s1w47ftqycii3YY4HmRiw8ih/vSYnPa0WRWpJ3VDbhdyTbTP48BQFWYlZTdbBKhAz5sToM4HEN36yd2GviG8hlhqDtTAR64VaFmgMiTu3oikEy7EMpJ9tlGYslOCD8ZD1Dpltgr0ze120FIONhXy2TKL7JlD/QCz1JqF+ujCMvcSo6zc1bPW/MdwGDcmQ1JImiyAIGctZynFPPjwioNpYg7iELI/Q3JZeEphTs4VFpUc9CQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: NI0Lu9fqlqJY6lacojjYKuUzG+jxwQIOcA4fVvEBjH0T3NHgGd6P9RCJtF0aKeG9NLIP18KdEjrZczYAw9fUEueTiRN1JyIDjMhUVzR/43YneaB87VkzL0mDK3iDLHjx596XI3L5++moe3B7nfCysYm/10GnrFgsWv9EU4adom5U9F3fprUXZqXdFbJUEIPW1TJ04hcelFQMhu/WD9H9vsBgf24Nc/eQW/gnJkj/C6FS1sGCy/VHEpm80uYorhA/221C6+vOJeLXmdm6RMOr23VhKBLSAlCWKcyCc6ISDSAtY5s0zpXTnvXcuZKSOQQkhds79cSmOKsZ1e+Xp4zLDnMdgY6aSFW1eWM47M7b/Jc0bjLws0+yG/46g3we0hccnixPKo3IwrGHsARg8TGZ7Co/p9IVKmnXmpOqI92EjpjmICA9FKe63UHlUlBMqFYTZN8ERyWmj78vSu1va1A/TGPqs0r2NPsWybUHp44CiU2yoObV7RJyNtCHhYE+DIkTLFcbacufcss1qGmRriT1miwZ1vYZ/YCLIvH1nOU03EexDC3Rlj22xtWccR6iPmZeks+Yr37ms0QCH2uXCfCeUeS2B28BWykgwzD5FDYSqvg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 73df79f8-7fb8-4e56-0bbe-08dcb5483229 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 12:14:46.5925 (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: 8ZE/L7am17eCbbvvJ5FfuUCBlMHo7aXFSsDS+FLxTFrTl6U2EBFpz3nTgCsqhoYpUdtK5dyu3k1UG3j5wmfTTVF91V3uoR8Tz9gINmpERWg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7760 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-05_01,2024-08-02_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 spamscore=0 adultscore=0 mlxscore=0 phishscore=0 bulkscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408050088 X-Proofpoint-ORIG-GUID: Aafz0hpcomZzDra5sFRwca5gTmBRfl30 X-Proofpoint-GUID: Aafz0hpcomZzDra5sFRwca5gTmBRfl30 X-Rspam-User: X-Rspamd-Queue-Id: 58301180018 X-Rspamd-Server: rspam01 X-Stat-Signature: u3dgyk6j5kbwjg1eoyjii5fys1wzi3e6 X-HE-Tag: 1722860108-254000 X-HE-Meta: U2FsdGVkX1/IykvbLOdigkeKfB/qeCbBTPIl15HFxVY7nbzs3PI02zTD+eiYc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i/V6sKHcMNmh74KR2ZXcXlvcSrQ8OMJyvn+hyw8sNK1OH1P9Pae2xTXL9KtXgWlM5IWIa2GFz7EGf6Up3ghT5qPVucdfqZCQYHa/1aAE3iFf1l3Nq9ToGLVpo7IGFwsYmVDGXxEdVmQ1i7JkyA6PXU+yrMhYA5ahH73wumRqhVfV9y5VXLn5L5Qush/jczAkN9RcoLlHRgtCI6NTPtuQ2yrYDtYBmXzAjCX5La16iUa3b/FgDZzmQWFWr5D6arvMLSnsfL09DUzObPnYYbI5lNnycDHUi4NfzxbX0oue1i5G4Ry/SsTGoBAOASg5vHlmX2k7Q9fuR+x5hR1bPPc+IZ7+qkITUwIsZKFwpCA0 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, we 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() deduplicating code and providing less surface area for bugs and confusion. Signed-off-by: Lorenzo Stoakes --- mm/vma.c | 474 +++++++++++++++++++++++++++---------------------------- mm/vma.h | 6 - 2 files changed, 232 insertions(+), 248 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index b7e3c64d5d68..c55ae035f5d6 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -569,8 +569,7 @@ static int commit_merge(struct vma_merge_struct *vmg, struct vm_area_struct *adjust, struct vm_area_struct *remove, struct vm_area_struct *remove2, - long adj_start, - bool expanded) + long adj_start, bool expanded) { struct vma_prepare vp; @@ -607,6 +606,236 @@ static int commit_merge(struct vma_merge_struct *vmg, return 0; } +/* + * vma_merge_modified - 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 does not need to set vmg->next, as we determine this. + * - The caller must hold a WRITE lock on the mm_struct->mmap_lock. + */ +static struct vm_area_struct *vma_merge_modified(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_will_delete_vma, merge_will_delete_next; + bool merge_left, merge_right; + bool merge_both = false; + int err = 0; + long adj_start = 0; + + 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)); + + /* + * 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. */ + 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 + */ + + unsigned long end = vmg->end; + + 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 = 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; + + if (commit_merge(vmg, adjust, + merge_will_delete_vma ? vma : NULL, + merge_will_delete_next ? next : NULL, + adj_start, + /* + * 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. + */ + !merge_right || merge_will_delete_vma)) + return NULL; + + res = merge_left ? prev : next; + khugepaged_enter_vma(res, vmg->flags); + + return res; + +abort: + vma_iter_set(vmg->vmi, start); + vma_iter_load(vmg->vmi); + return NULL; +} + /* * vma_merge_new_vma - Attempt to merge a new VMA into address space * @@ -1022,245 +1251,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 = container_of(vmg->vmi->mas.tree, struct mm_struct, mm_mt); - 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; - - /* - * 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); - khugepaged_enter_vma(res, vmg->flags); - return res; - -prealloc_fail: - if (anon_dup) - unlink_anon_vmas(anon_dup); - -anon_vma_fail: - vma_iter_set(vmg->vmi, addr); - vma_iter_load(vmg->vmi); - return NULL; -} - -struct vm_area_struct *vma_merge_modified(struct vma_merge_struct *vmg) -{ - return vma_merge(vmg); -} - /* * 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). @@ -1280,7 +1270,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_modified(vmg); if (merged) return merged; diff --git a/mm/vma.h b/mm/vma.h index bbb173053f34..bf29ff569a3d 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -110,12 +110,6 @@ struct vm_area_struct struct vm_area_struct *vma_merge_new_vma(struct vma_merge_struct *vmg); -/* - * Temporary wrapper around vma_merge() so we can have a common interface for - * tests. - */ -struct vm_area_struct *vma_merge_modified(struct vma_merge_struct *vmg); - struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, struct vm_area_struct *vma, unsigned long delta); From patchwork Mon Aug 5 12:13: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: 13753571 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 5CE24C3DA7F for ; Mon, 5 Aug 2024 12:15:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA6196B0096; Mon, 5 Aug 2024 08:15:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D56FD6B00AA; Mon, 5 Aug 2024 08:15:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B83E66B00AB; Mon, 5 Aug 2024 08:15:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 931C06B0096 for ; Mon, 5 Aug 2024 08:15:04 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4DB3A161BC0 for ; Mon, 5 Aug 2024 12:15:04 +0000 (UTC) X-FDA: 82418086128.14.F264BEB Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf21.hostedemail.com (Postfix) with ESMTP id E791E1C0013 for ; Mon, 5 Aug 2024 12:15:00 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=X70FSOps; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=KKpOThSs; 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; arc=pass ("microsoft.com:s=arcselector10001:i=1"); 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=1722860093; 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=kkI6NNI0jXsxFrPLz75VTLqEXdGgi02HQ4yO6eKoi5M=; b=n4T9rCl3wKv9FPOvqDitwpblo2iPlC74wtw1LxJFxwPiPHLRG6ioWpUJXl1YX9DBGDQVQd IrcNkhVu1oA3jGrNmn4+XsEgNzEzTLuqe1wrZAlbNf6dfkWx3UUaBGmsgVCxphrYMyNM37 UVQK74XYglSE0uX8PBwvpCT/5elkmco= ARC-Authentication-Results: i=2; imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=X70FSOps; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=KKpOThSs; 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; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1722860093; a=rsa-sha256; cv=pass; b=SlqEVFpaQj+uvmzcG57xv2vlJefjB33LxhREuIScjG+5yifWT6OVIIARzZmXtLt+xKkUQe ar+WGF/sF/WLJMms8I7gdfPWljVIQY1eti5+FO4ALNztofZDhFSe+gk/ud2yukkHb1tyM7 +MepzUoT5jO5gkOL57a0FCJ6VyI3WIc= 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 4758fbAB027532; Mon, 5 Aug 2024 12:14: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=kkI6NNI0jXsxFrPLz75VTLqEXdGgi02HQ4yO6eKoi5M=; b= X70FSOpsna+kzk15V5WOOIAGsGM0A5Vj2XRKn32xYVr9ARFyVJftPAG4amZauQv6 coSKeFOX2hVB55XzG1viy7/oyVzZPWo3tqOq/Yzbs/wBsd91WyKLD3FQ3/OOSi7F d5fEYEgXcuYcJkH4/tO61NZbCB8DQjHkn7ZKeuz//MHtTKvyOoGrYaMCLB3SNZq9 iZPi418O3ClwXHZEtO2xx4W1nWusCa5ptd8IEIHS36TpMRjaIlw6EQRE1XYhcTdL gY7PiucOYSXEBuXmuT/n9lzlkjL4xT3egrOKTIsuf2VABF5w3NSxy8EhDshS3yoY VkE3MSuH3z/jzfSrIYkgKg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40sbfajgkr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:59 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 475B4jDr004673; Mon, 5 Aug 2024 12:14:52 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2049.outbound.protection.outlook.com [104.47.66.49]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 40sb0d6qsu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IKxYY564DvbI+nq6bJuKUwZMlYv4WSWIfwcSu8yC36jorLcMa/0iO5wM5OAR5G7GWkXlvA8Pz1i+l5woQJ+0Ckb/1I2xZGDtpZ9j3qRrFTCekg7lKFf3mZ0Lh2UaOtlBAt22JhNIMjmhMQ9SL2pKU5NYNoMY54hL9Bz70LdNy5IrOSLt9H+lgOmFcCh/sYLdCAhlneRlL+SvvP7rhWUo7NnMaCOa3hlMn++Vp2U1qkAUvs5aJEa5N2N/mmNGLtk2Lt8af7Sm7ONxlQL8Nsy1ziJcwcy6Z9HFCW3rBaHAGGJYX0mU4UFP92+MfjfZNcUkK5Mp7TDdBWf32wRCKBiwqg== 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=kkI6NNI0jXsxFrPLz75VTLqEXdGgi02HQ4yO6eKoi5M=; b=bOMR4UgxJrzpwjf45D2Vl9dhjMS1BFKcy7ck/+1VLfQkw1ivGKq1f0oH3dnReU3bqeWfAcXhL2dyxIEnknDbbnFutGOwRqS367D159qm1tpIU53+40W9GB4dnkcDyg3WkxvEX6hBFKPZ7QDqcfH83/acPZJ2tFUU3V8sEDE68XmqRBDci9ApGLb++FeSjVm5A4fqX8Thksa6UOxO9ERWgPWNNe7GvS26RE7zB1QUxhzZ1IsVl7p00iq6Agmzlodq7NX/uEGx1sjcWToDs518zzo2+5TqTk3H1xEnZ+Zs7Vf+ilL80JejjzEFa/yJ4z/wuYOOJPM3SKr3R+7msv5giw== 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=kkI6NNI0jXsxFrPLz75VTLqEXdGgi02HQ4yO6eKoi5M=; b=KKpOThSs4MKe2l/NGjJlANsc1BAyUHFaKyLCu2GW9ybgjF6D/Ddkb5pS/MILIBSdCxB5dd4qChhO82dY8XO1QWKI6J2JGSG9FQLGoP2r7CqCydl+YjxKSWArr5NdlA/IhDcRvLpXtkcp9TzBLASBAm2HnlURAhT/V0/ag3SsXxU= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by SJ2PR10MB7760.namprd10.prod.outlook.com (2603:10b6:a03:574::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 12:14:49 +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.7828.023; Mon, 5 Aug 2024 12:14:49 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH 10/10] mm: rework vm_ops->close() handling on VMA merge Date: Mon, 5 Aug 2024 13:13:57 +0100 Message-ID: <0afd85543d46fd743c0c71b6f6520f9580174b4f.1722849860.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0198.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a4::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_|SJ2PR10MB7760:EE_ X-MS-Office365-Filtering-Correlation-Id: 040b5a69-ebf7-434c-0f83-08dcb54833fe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: uKTxr0Xld4oWzfjFaeIqK0Vj9+O4GFYsM0GFUZdLMPSqJ2dtwJRHD4Th10gOPrl976vh4iWzNeyN82hlWBv4XsEExKd03phTD1FsF2XNN83+/iqVa8+7zo3Bl/+mT7nh2elzhRQ6Som4sWR+lnDBMnpYqiqWk0C7KTttHVcEMNyO9Lst5ap+2MbE/JqFADvpXHS/FTkIse1jrRW+EZTBXOKGHedJ6iJhSPBG32CeDwd/J+FMedM55hV2kQcSDzbjX13ZpVp3PBMi+S6prpP05XmDTu+JcOYZu0rFu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-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)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Yre3cDxn5PdVrv2LxusvIyo/bdQNFQeKUw6ETx1hQFQlS4cHtin7o3nkek8Jwv1ndlZI5Rn8AAuqzfDGPmNabdi0wSUO7abhZOTCNC+1eiYYMqz9GyU1P6mBnOej9Q4/S5AfAsrDUygM+X2Pw0GWtpRKAOfFidW/BjrYiCS33o4G+qgP0erW2vJddKtJmbimf58sCbMFE0Y6pYmQ6Q3VMk82SMdPjvwTqIs9oUN/r9os0eLajPg6CDg/m/AuD3CicZCYLtWto+65/Uk5VtxwGpRqLJmA0x2xZtM+wSwv7yt7kfSRENghk9IwjPbFXslh3Gue7ZHPWYuBadNSZ6SYiwNXkyowcdEjcSx/X5rREXl60Ed87aPlstBVmiKwAIagVboh19D1lCEwp9CAQDhuPC4/PsrRYgq7ofx74PAny8L1snhH+K/J/G2bINIHnfibyXHnuqF8foS3h02oV6bYuKEPtAzseMuV4uvJHtQ3wxJzoXAK+iEjlnDZKnxHbw97hy6K1I9oT4TaoEWl6yw7t+CXoUX9f1m+HapJ/HExpFu5t8yzWK40uUSOEZAw3Tiexa6lEhrdxLrC7WhyhcJa2T12VPW3uj4aSmGBRbT4vCFAL4j4nd29gKmPsYKMtViejfwgOYd9qeVrqctCspuTKLEMCJ4QiaWSr5x+O0MOo3iMD85qZzrXZOtN7f1cI1DWCEwUv5jANhO97yy1SG2vRzB/wCeONdW06i2k1t2ojUtE7rbp4ya4WFpU/8iRYOynFPaZTxBbNA5od3c2KE1MIHRKBzl+Tc7xeS9m+yi2IyRqp5kirXDwbuDUQgEvRWcx4dFpKP/LtXrUwLGZLhs6bE5m9Fs/eVEDzVExz0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tuk7z89iTM7FL+exG+pQJv1xh5x2tpUG2Gs7RiJ00jubht7QdYviQ07UsA/9Ho02O3eQYuspWJ+7ChbR40Kyjvbvjy3JPiPtgIsU4hKWbPzP+Btg+QAwHULH3bcVl45dezG9JO9hIPGNvQV7OL2KFlUKxrVuAKSkRdcqmXRijoKFNwtkyVB4CfbbDf8GmEaPbj8/dDmbBuCT8A4rpjraCL/WCk6rEuC+YXZ7pQ6DBtC+ylW+i40ArqBVdwav0OIwHfLoQ5KlthkpGiPcl6mlZLKoDTgpN58+mLCa4t/fOk9ZBlEVWKKM3ydTdompji4TFm9YkbHv2G0DPyOZCv41mlZQBTz7AJiQKYvS6AcbENtRjwzL0rWhMUTfjS7OKKKhSxmGEfDLKgadC4uGJp+swikxAKAOKBBL1PZLzQAu25XTTSwC6cGc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 040b5a69-ebf7-434c-0f83-08dcb54833fe X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 12:14:49.6607 (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: oJ+hiqfGmy9qcwqxDRWBhRAXH7h9XSal/vVM8VbwBV0RXE5T63DatWwX09jUykdptdfm2NXWcr00p/pEcX+31aKj+S0QEwdFV/mBIPlVHIk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7760 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-05_01,2024-08-02_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 bulkscore=0 adultscore=0 mlxscore=0 phishscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408050088 X-Proofpoint-GUID: rKOA1v5dUVHNKpVm3j_pxlc64ZMx3pVq X-Proofpoint-ORIG-GUID: rKOA1v5dUVHNKpVm3j_pxlc64ZMx3pVq X-Rspam-User: X-Stat-Signature: fjtjaug7qqtmg4fyg19xxywdshgk8hkc X-Rspamd-Queue-Id: E791E1C0013 X-Rspamd-Server: rspam11 X-HE-Tag: 1722860100-703210 X-HE-Meta: U2FsdGVkX1/n3JfqzZs7UBj9Bt2mJkbJmhFbiqqpLa9oz7qORv+hcWdcyi83yH8/w7M4DPEeuGODYFAdyvr+P0LuwPTpRyVV/HbJcusvOZuWMhdy9KvB4SnYdufxq+FGgnoqLosAE93UW8vKH/cpawSgEAwupp7nNKDydtNS39xMD3/sS1Q10DeImYKS+f0ZB+xXtrAZ3fpvgsUKN/bPUXgd70l9HjX+QUvPbszi5czXnh10l+SVfqT+1E8pOnWjOC47lnXxSimgHFHbZAxvkxEnIX96uRq5a9uqjOufawySVZpP1DQ1R+MwoQ9yzOVeqp4h1+4XCu+Rl2K9syGhMFWqTxVB2if4ph+pUmphObkbysObQZxhpnpi8653+BCraS2zw/snDnKe532KvOk4wti0ius2VaRASaK6f2NcDzbDMG7LdhAoFMICjyt5CIGegT2f6ATfp9EBRfMS95Dh+IzP0pzXqw5O/lzI673WNCBaFtPwWHFjVxJ9rOMr+eANseMKEVCt+YErBTcm5lyIgpcKHyJUbaOaMX6a5WMnZdQW5CJQyFW3w2E542YLSOgx0tM2xE5XMnPOO9M+s7BgNMYMgAq/NdhV2rdcEpQPq+FmNP883/NRoSMSajZtttTOZ0Ug31JJBuizwVTJ8usYMPrSEFbyk5hFWliKc5IYZwlXC6GIbT/REVZU3HvfzokOCytCrVC91wJJ5E/UluyH31FY0lUHUSP/XNrf+HCBNE7dG7MbyxfsyYHkbSDyLpDSWFpgueoGatyJF662FZEDyjCzsbxsY2Bt2JU6zAmwYsEr34sweASsUP8bhGFoMgjbiMNyAIce3HVQ3jkRqDXh7/zHRCO431OHXtgSxwLsgg11wf3CK4H22QouUavF25hePMe06hKXkfvK0bkabgB2YeQptM5FsKwxZBH3zG1mEruz0Cr6h+dORMEmSpSTgicDPJuVQJ3c4pOcEYdVEpv 4Skodr7p hlcD7OPhgNI9u02VZpBCuB5OWwKFAm0U21lekgbq/zloZkuNafxNs8Emd0PqTeRSp9hG5v75sUhWeGsERWOyP1LLZHLn+SRcU0XoB7acbk7dgssZFFRth7fGV+FBuzXUWWZzZkWgyNEjIPMwUkOaFK2SR+wPStj9xfYkCq/yBOK5yKT559XNABfDNA/15UpyeccXS9K0KhgLnPdek95biSmzO9GrAr2jON8J3IAEnDx8tJh+EpYbVQxAMzl5Z5w9MVAu+BIjG7sq+tV3ZoLDeFLhc4D08rzM1ABQs7AN61vLsM4PK3ShbkD0iu1UJ5BiDjIMeiN+O7IoRGSIOXLhcHMOF1H3nW2BCF0lMtZH/PlFAS1KYSo6YivIBOQT4Qfxh18EqOSZGxY2YnGlTsKofOSlzJWHmAgwncmFt7xRET2l8QTOnZjp57/L4Bm63ZhUf0ot9zkB3tZDE2UCyIq0U2P9Y+9vNC7ffeENfkt76pnmAG+lJiDJQFeUvgJEK/n04nCzaG6eouJOEfFg= 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 | 69 ++++++++----- tools/testing/vma/vma.c | 213 ++++++++++++++++++++++++---------------- 2 files changed, 173 insertions(+), 109 deletions(-) -- 2.45.2 diff --git a/mm/vma.c b/mm/vma.c index c55ae035f5d6..9c779fc65ba8 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)) @@ -606,6 +596,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_modified - Attempt to merge VMAs based on a VMA having its * attributes modified. @@ -710,9 +706,30 @@ static struct vm_area_struct *vma_merge_modified(struct vma_merge_struct *vmg) /* 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. */ + + /* + * 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); @@ -756,21 +773,12 @@ static struct vm_area_struct *vma_merge_modified(struct vma_merge_struct *vmg) 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 = 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 @@ -886,6 +894,8 @@ struct vm_area_struct *vma_merge_new_vma(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; + struct anon_vma *anon_vma = vmg->anon_vma; VM_WARN_ON(vmg->vma); @@ -916,8 +926,9 @@ struct vm_area_struct *vma_merge_new_vma(struct vma_merge_struct *vmg) vmg->end = next->vm_end; vmg->vma = next; vmg->pgoff = next->vm_pgoff - pglen; - vmg->anon_vma = next->anon_vma; + + merge_next = true; } /* If we can merge with the previous VMA, adjust vmg accordingly. */ @@ -925,6 +936,16 @@ struct vm_area_struct *vma_merge_new_vma(struct vma_merge_struct *vmg) vmg->start = prev->vm_start; 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; + vmg->anon_vma = anon_vma; + } } else if (prev) { vma_iter_next_range(vmg->vmi); } @@ -978,6 +999,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 e465dc22e2d0..0c0a6ffcfc98 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -327,6 +327,9 @@ static bool test_vma_merge_new_vma(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; @@ -370,6 +373,7 @@ static bool test_vma_merge_new_vma(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); @@ -406,6 +410,7 @@ static bool test_vma_merge_new_vma(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. */ @@ -423,6 +428,7 @@ static bool test_vma_merge_new_vma(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. */ @@ -573,120 +579,145 @@ static bool test_vma_merge_with_close(void) struct vma_merge_struct vmg = { .vmi = &vmi, }; - struct vm_operations_struct vm_ops = {}; - struct vm_area_struct *vma_next = - alloc_and_link_vma(&mm, 0x2000, 0x3000, 2, flags); - struct vm_area_struct *vma; + const struct vm_operations_struct vm_ops = { + .close = dummy_close, + }; + struct vm_area_struct *vma_prev, *vma_next, *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. + * When merging VMAs we are not permitted to remove any VMA that has a + * vm_ops->close() hook. * - * 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 vma_merge_modified(). - * - * IMPORTANT NOTE: We make the assumption that the following case: + * This is because executing this hook may clear state that is pertinent + * to the VMA range as a whole. + */ + + /* + * 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. * - * - !NULL NULL - * [ prev ][ vma ][ next ] + * If we are unable to do so, we reduce the operation to simply + * extending the prev VMA and not merging 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. + * 0123456789 + * PPP**NNNN + * -> + * 0123456789 + * PPPPPPNNN */ - ASSERT_NE(vma_next, NULL); + 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; + + vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); + ASSERT_EQ(vma_merge_new_vma(&vmg), vma_prev); + 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); /* - * SCENARIO A + * When modifying an existing VMA there are further cases where we + * delete VMAs. + * + * <> + * 0123456789 + * PPPVV * - * 0123 - * *N + * In this instance, if vma has a close hook, the merge simply cannot + * proceed. */ - /* Make the next VMA have a close() callback. */ - vm_ops.close = dummy_close; - vma_next->vm_ops = (const struct vm_operations_struct *)&vm_ops; + 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; - /* 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); + vmg.prev = vma_prev; + vmg.vma = vma; - /* The next VMA having a close() operator should cause the merge to fail.*/ - ASSERT_EQ(vma_merge_new_vma(&vmg), NULL); + ASSERT_EQ(vma_merge_modified(&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; + ASSERT_EQ(cleanup_mm(&mm, &vmi), 2); /* - * The VMA being modified in a way that would otherwise merge should - * also fail. + * This case is mirrored if merging with next. + * + * <> + * 0123456789 + * VVNNNN + * + * In this instance, if vma has a close hook, the merge simply cannot + * proceed. */ + + 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; + ASSERT_EQ(vma_merge_modified(&vmg), NULL); - /* SCENARIO B + 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. * - * 0123 - * P* + * The first variant is where vma has a close hook. In this instance, no + * merge can proceed. * - * In order for this scenario to trigger, the VMA currently being - * modified must also have a .close(). + * <> + * 0123456789 + * PPPVVNNNN */ - /* Reset VMG state. */ - vmg_set_range(&vmg, 0x1000, 0x2000, 1, flags); + 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(vma_merge_modified(&vmg), NULL); + + ASSERT_EQ(cleanup_mm(&mm, &vmi), 3); + /* - * Make next unmergeable, and don't let the scenario A check pick this - * up, we want to reproduce scenario B only. + * 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_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 = (const struct vm_operations_struct *)&vm_ops; + + 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; - /* Make sure merge does not occur. */ - ASSERT_EQ(vma_merge_modified(&vmg), NULL); - cleanup_mm(&mm, &vmi); + ASSERT_EQ(vma_merge_modified(&vmg), vma_prev); + 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); + return true; } @@ -699,6 +730,9 @@ static bool test_vma_merge_modified(void) struct vma_merge_struct vmg = { .vmi = &vmi, }; + const struct vm_operations_struct vm_ops = { + .close = dummy_close, + }; /* * Merge right case - partial span. @@ -711,7 +745,9 @@ static bool test_vma_merge_modified(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; @@ -743,6 +779,7 @@ static bool test_vma_merge_modified(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; @@ -768,7 +805,9 @@ static bool test_vma_merge_modified(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; @@ -800,6 +839,7 @@ static bool test_vma_merge_modified(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; @@ -827,6 +867,7 @@ static bool test_vma_merge_modified(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);