From nobody Wed Dec 17 12:33:50 2025 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4808A198E75 for ; Wed, 10 Jul 2024 19:23:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720639433; cv=fail; b=ZXPPua/xy44NFwG3usyLevwvCk/xHk/YiM/oghoiDanxAwaGSqI16YNRCXMcw/gMBUS4ESMH+m01Uv5Xo4ndpwfgaND8vNPuv/tVFj9nbzhWy+CibDptwNCfJPdEiDEIE5cxG2MmlGgn3pXtO/PEBB39ZLS7ZYrJNAb7J8MQvcM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720639433; c=relaxed/simple; bh=LRr5Qp5g578MIQeoqcd3VHi2/VCpxWdNp89F2/ElgMo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=t8CFEbPB8dTZHC3r64Bh2PwxBIyAHuNFPKxmvSpeD0SHgZOAwW6twYVIffR6tPtKKKFbYXUpcXj3gncn7FXddP3PaCjIVR0McglZZph1hwYh4mSjClK0Rb+8c23R12GY3LwbZ5vHvH/j7SbYGSbzLK2Q5IkyF5Hj5XODhakgDfA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=PhNxe6Wr; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=t1uZ4w07; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="PhNxe6Wr"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="t1uZ4w07" Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46AG6eq5017502; Wed, 10 Jul 2024 19:23: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=l1bikM7qDZXJmibT+K9xa3k5hYIYZogr/swJJwrXmuo=; b= PhNxe6WrhJimgdDnXMYCE0iWgRt1v9klUnXJ6sJqAycID54+T9tszT2UOq3SXQpw o5zooxJuye5+gVu4DWYBt6xv2W91v16Veuhu52UVTcKrhlSeE6r4DEhCBiPo+4I/ ztAcREaIkKpwuNMqBmZH65M0ne1m1vFwEyYNkKrlrhSHObOBI09wl7v5gJJfBQyL A6l73xqIFEdSxz/7FS/lL4Y0hgAdXOLXOVcy+vN8AKQp6kTu/iYjNEWdklYO8PCG WSQyCuen7e4mT6eTtDeNI50XGA3vrd16xAD+Z5S9rdkkwFUuM1eg8+/Rs5/+cVUS OpQiFd4mDdYsy6nkoanceA== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 406wybr4d5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jul 2024 19:23:33 +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 46AIihMF033699; Wed, 10 Jul 2024 19:23:32 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2042.outbound.protection.outlook.com [104.47.66.42]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 409vv1948k-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jul 2024 19:23:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DMgvQAPapRX9JonYseuxzWf5u21EWFMbeCSURODDHH0Yr1YPgOX9iOFkmEufqZEvqYrH4NsotnKkE6RoXoQ4fGXE89PDvGpxoHUf6Lnp3GQh7QdtPF4j+/3iecH7XzBIMLlXYC2JNEvXzXHisQETwo2um+XqyaB9JXQIpxFvUoZpsRbCv82nBhG1hysT2J+kIx/wka1Ik5AlSdICGp9zZYJz0XLa0uKl/9pnLaTHqmBVlm/vdVxDBeuQ7Opj6Vzt8jqYBWhhpWPOk15W7pP+qdp8mXGVzQQ08cCeSna4SzFIUo2e71K2p+h1hN6Tjlae30ARFhYqUcI0IQLZ7gYR6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=l1bikM7qDZXJmibT+K9xa3k5hYIYZogr/swJJwrXmuo=; b=IxNvpqP0y252vjoc+DKo6HfYwPHplLN34f0YqjAfNlJcCelmaxlCqzpGF80tub6/OXH9RL7LTvbNGh1XsAS/hNXK3w4/5liVtsALGwZLPKGEN3AXVPVx+3j5Kz74HielRKL+Xs3Tb/bytP7XIjQo4l4rh0oZ1rlUcO5kUtUs/0GLmXjtte378HV3uFDI+b5lk8pIqoy/oeo0ORGHUkM4WcdJCNetmvwUN+XfrjiBe6qLEUQTXyVF9Y+opCI7yx5YrSacBdOqs8G/fJKr3F/P0+VSHaPeSkw+breDzE7w/LkBWkXSnj3Wo0VF1vzLtFtTCmJX4OapyG4Txfutc9pQ5w== 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=l1bikM7qDZXJmibT+K9xa3k5hYIYZogr/swJJwrXmuo=; b=t1uZ4w072K6lQeI0nI1gVC8yl51YhDNFOS+DGUAiVz9iBsksfr9ZD33q6A2yX/879Zw1+rKv0Fnbjev2zvlkCBxDRL+VXDNckhOuNAjrHMUivxGx4lK3DC5a2Ek9eQqhD4eni1SOYp2+56j9kBX8GQr+5B//99/w7aEhFqg5Jus= Received: from DS0PR10MB7933.namprd10.prod.outlook.com (2603:10b6:8:1b8::15) by DS0PR10MB7295.namprd10.prod.outlook.com (2603:10b6:8:f7::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.36; Wed, 10 Jul 2024 19:23:09 +0000 Received: from DS0PR10MB7933.namprd10.prod.outlook.com ([fe80::2561:85b0:ae8f:9490]) by DS0PR10MB7933.namprd10.prod.outlook.com ([fe80::2561:85b0:ae8f:9490%3]) with mapi id 15.20.7741.033; Wed, 10 Jul 2024 19:23:09 +0000 From: "Liam R. Howlett" To: linux-mm@kvack.org, Andrew Morton Cc: Suren Baghdasaryan , Vlastimil Babka , Lorenzo Stoakes , Matthew Wilcox , sidhartha.kumar@oracle.com, "Paul E . McKenney" , Bert Karwatzki , Jiri Olsa , linux-kernel@vger.kernel.org, Kees Cook , "Liam R. Howlett" , Lorenzo Stoakes Subject: [PATCH v4 05/21] mm/mmap: Introduce vma_munmap_struct for use in munmap operations Date: Wed, 10 Jul 2024 15:22:34 -0400 Message-ID: <20240710192250.4114783-6-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240710192250.4114783-1-Liam.Howlett@oracle.com> References: <20240710192250.4114783-1-Liam.Howlett@oracle.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: YTBP288CA0001.CANP288.PROD.OUTLOOK.COM (2603:10b6:b01:14::14) To DS0PR10MB7933.namprd10.prod.outlook.com (2603:10b6:8:1b8::15) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR10MB7933:EE_|DS0PR10MB7295:EE_ X-MS-Office365-Filtering-Correlation-Id: 96bc9b43-5ea3-4725-c629-08dca115bb4b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?II+BAusK9PAuxsHVAN0kVVzJzDe3V3V5romBY2yyH9nrOTuhDRHopjsOn3Ht?= =?us-ascii?Q?Ky4f+49rUeWbDIsn0qHcSEC8bYOglbFiIUCYjTsF0O8g3TcJwmQ2zX02JtY9?= =?us-ascii?Q?Ea12sRPRYt/CnCL52dY1+kBPE0UiraiF8s0PWhX9QhEdlr30vG3Xvwj/HykV?= =?us-ascii?Q?vq1m+v5DHFQMMPJp1EueGadtalrH3NufnMW/1aFjF6kCsVH12Vc4daUhjLN4?= =?us-ascii?Q?0TSSFpgZ1W7Q8xpd1u7sfQO8lGPhjI1OfgMjzj7TtrshLkYqiItYN9uRAijR?= =?us-ascii?Q?rcBOFQ9Wck//CwvLVGPK6K0C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q?atKve7FOpHD2dB6ue7v8+eP+BvmtCZUXLdIAvWNNYusiOKUCfsF2kKv5t+sR?= =?us-ascii?Q?fRWZwmR95CPhpFw2TUmtBHgoS1k6j9A7OQfx95YX4nKUi0VTbz60RqGtpebu?= =?us-ascii?Q?/Aj983tlfAZIXa0wYqYDVSxWI+E/gaF+v5Qe3yxOnlSbpQ=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR10MB7933.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(7416014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?bS6TzQ/LMTLvoAbmH7ZegUf50gV0WK/ePWk/SJ6YKMna9d508/7JcGCc6J1l?= =?us-ascii?Q?jfe/J34/mQCSPXByxGN+0oh3I67H/ZwupJTam3nL0/pyDbL6OkrShOjH4vk1?= =?us-ascii?Q?E+q2U5LbKHEamoqXcu38E1oMiPmV5kfGYAr/dPoaIFoj7TgOCuarDzzMqfZy?= =?us-ascii?Q?3CiBSi3ZGZb/H1JkMHFfr7rpVp0jBW38bmeJh0AkyrNAh/OnOk/CypYx6a4c?= =?us-ascii?Q?GvWQp0L7mdiXL1By8xAS1a2TQ27YwCVdAo3zvGHmXZy4DyZumi26xHm10Z+G?= =?us-ascii?Q?eBRi958kJUV4Uji3nuwcUGnLfsmKtX9+tYx+uf+nG4HnTs9ebNYfc50lQ3BM?= =?us-ascii?Q?tL8kHH+JmHM7DG9W72/i2rrdtgAZopz1+8FcOdTHjlo55sRH+cl8EiyjuZb/?= =?us-ascii?Q?UQhcpJEKeCdPThcLm2426eOnuud8ACgJWx7YVSgntoTrhRVahQvPLAKDJywX?= =?us-ascii?Q?E3GbDssaKZ5Aj6rVvKy2rRGWrQfRE9waWQVBJBvn1Fh9zn9HkRxB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TfJQOfWrm26v39Rhquc4eXLVCFx7kDW?= =?us-ascii?Q?xwG5FOXedrYfB8+ZAQQhY44xjwdyG4v4K3PhDFMwpbeUXkhKHep9VyaOhV6P?= =?us-ascii?Q?c24xwSVLDjVwmIuwweV4BuPlt3Ku4UspPvpOCNbeS2qnlG7E9TxgABKVIWFu?= =?us-ascii?Q?6S6EtD0PG+tw452VWFPBtQiWpNHw8ullBDbQiYyuIMNS8CeC4Xto2+dZBSOK?= =?us-ascii?Q?qQ=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Y4lz4BfC6GTQ6/XUw6FTkyD9XJsrV/DfWqWUFTjfQRVOYGJkcaYE86U/UrsAMTtx9GNp7edhaBzBN4uZU/LqwGRjc/xAdQN6MXCM9Uv1j9H1jkyXlFWg/Wh13KUf7MZtSYuGT7urrPNMCE6+MS27ZTcYns3PWNw+/ttrvi2veD3ptKlXDA8Ldbhx5X+qJslAcvy38wrhBMfrBM7OctgBgLE5x3JxZ4hGJ1N+TrAycoQXXuJjVT/0cJSuAG4IdFioC2zqHJJnTt4mevvBy9quBOnuLVNNbgFZhOEF8rX13qoOO1YdT2fSRj43h49THqojzl4mLo4jlU/xg4mQgbgaEQ0HC0qsDoI+SW/mh+5m7TocQbuze9WWpIf4bJ26AJ4SpvI6qgLQnYtP6er1BfGv3cSNzQTjGKfraSHjP/5Pzy2Jlk7yKPqh3nccnI/H8pGECaFYMqWdyCKodvLjwWcph/ojpzsBdnXuyPwziQGAUa0wpZH2iMTOua9xNUDXFMYeayIclad9UW7zXNhsI63/T8at1ztY6GVHoW1YLjomc90BGAiFHe/6BNKI+3bJcuZBXV6Iv5SpH+IXbaONMQKjBoTLi1+YLSwUO63Y5iYZY8w= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 96bc9b43-5ea3-4725-c629-08dca115bb4b X-MS-Exchange-CrossTenant-AuthSource: DS0PR10MB7933.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jul 2024 19:23:09.0085 (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: 3ftYL95aoAmEhSzOOgCSHo/VsrE6StNAxTNIgbr2vMcm0CLHuVnSlBzCpBZgzJPPJnES4T3meTL/uy9IncMPPA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB7295 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-10_14,2024-07-10_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 mlxscore=0 adultscore=0 suspectscore=0 malwarescore=0 phishscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2406180000 definitions=main-2407100137 X-Proofpoint-GUID: aSbZQNEFBktszQSSddDGRI6RXCAPM04t X-Proofpoint-ORIG-GUID: aSbZQNEFBktszQSSddDGRI6RXCAPM04t Content-Type: text/plain; charset="utf-8" Use a structure to pass along all the necessary information and counters involved in removing vmas from the mm_struct. Update vmi_ function names to vms_ to indicate the first argument type change. Signed-off-by: Liam R. Howlett Reviewed-by: Suren Baghdasaryan Reviewed-by: Lorenzo Stoakes --- mm/internal.h | 16 ++++++ mm/mmap.c | 138 ++++++++++++++++++++++++++------------------------ 2 files changed, 89 insertions(+), 65 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 2ea9a88dcb95..43b3c99c77ba 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1481,6 +1481,22 @@ struct vma_prepare { struct vm_area_struct *remove2; }; =20 +/* + * vma munmap operation + */ +struct vma_munmap_struct { + struct vma_iterator *vmi; + struct mm_struct *mm; + struct vm_area_struct *vma; /* The first vma to munmap */ + struct list_head *uf; /* Userfaultfd list_head */ + unsigned long start; /* Aligned start addr (inclusive) */ + unsigned long end; /* Aligned end addr (exclusive) */ + int vma_count; /* Number of vmas that will be removed */ + unsigned long nr_pages; /* Number of pages being removed */ + unsigned long locked_vm; /* Number of locked pages */ + bool unlock; /* Unlock after the munmap */ +}; + void __meminit __init_single_page(struct page *page, unsigned long pfn, unsigned long zone, int nid); =20 diff --git a/mm/mmap.c b/mm/mmap.c index 0d03fcf2ac0b..1ed0720c38c5 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -500,6 +500,31 @@ static inline void init_vma_prep(struct vma_prepare *v= p, init_multi_vma_prep(vp, vma, NULL, NULL, NULL); } =20 +/* + * init_vma_munmap() - Initializer wrapper for vma_munmap_struct + * @vms: The vma munmap struct + * @vmi: The vma iterator + * @vma: The first vm_area_struct to munmap + * @start: The aligned start address to munmap + * @end: The aligned end address to munmap + * @uf: The userfaultfd list_head + * @unlock: Unlock after the operation. Only unlocked on success + */ +static inline void init_vma_munmap(struct vma_munmap_struct *vms, + struct vma_iterator *vmi, struct vm_area_struct *vma, + unsigned long start, unsigned long end, struct list_head *uf, + bool unlock) +{ + vms->vmi =3D vmi; + vms->vma =3D vma; + vms->mm =3D vma->vm_mm; + vms->start =3D start; + vms->end =3D end; + vms->unlock =3D unlock; + vms->uf =3D uf; + vms->vma_count =3D 0; + vms->nr_pages =3D vms->locked_vm =3D 0; +} =20 /* * vma_prepare() - Helper function for handling locking VMAs prior to alte= ring @@ -2603,81 +2628,63 @@ static inline void abort_munmap_vmas(struct ma_stat= e *mas_detach) } =20 /* - * vmi_complete_munmap_vmas() - Finish the munmap() operation - * @vmi: The vma iterator - * @vma: The first vma to be munmapped - * @mm: The mm struct - * @start: The start address - * @end: The end address - * @unlock: Unlock the mm or not - * @mas_detach: them maple state of the detached vma maple tree - * @locked_vm: The locked_vm count in the detached vmas + * vms_complete_munmap_vmas() - Finish the munmap() operation + * @vms: The vma munmap struct + * @mas_detach: The maple state of the detached vmas * - * This function updates the mm_struct, unmaps the region, frees the resou= rces + * This updates the mm_struct, unmaps the region, frees the resources * used for the munmap() and may downgrade the lock - if requested. Every= thing * needed to be done once the vma maple tree is updated. */ -static void -vmi_complete_munmap_vmas(struct vma_iterator *vmi, struct vm_area_struct *= vma, - struct mm_struct *mm, unsigned long start, - unsigned long end, bool unlock, struct ma_state *mas_detach, - unsigned long locked_vm) + +static void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, + struct ma_state *mas_detach) { struct vm_area_struct *prev, *next; - int count; + struct mm_struct *mm; =20 - count =3D mas_detach->index + 1; - mm->map_count -=3D count; - mm->locked_vm -=3D locked_vm; - if (unlock) + mm =3D vms->mm; + mm->map_count -=3D vms->vma_count; + mm->locked_vm -=3D vms->locked_vm; + if (vms->unlock) mmap_write_downgrade(mm); =20 - prev =3D vma_iter_prev_range(vmi); - next =3D vma_next(vmi); + prev =3D vma_iter_prev_range(vms->vmi); + next =3D vma_next(vms->vmi); if (next) - vma_iter_prev_range(vmi); + vma_iter_prev_range(vms->vmi); =20 /* * We can free page tables without write-locking mmap_lock because VMAs * were isolated before we downgraded mmap_lock. */ mas_set(mas_detach, 1); - unmap_region(mm, mas_detach, vma, prev, next, start, end, count, - !unlock); + unmap_region(mm, mas_detach, vms->vma, prev, next, vms->start, vms->end, + vms->vma_count, !vms->unlock); /* Statistics and freeing VMAs */ mas_set(mas_detach, 0); remove_mt(mm, mas_detach); validate_mm(mm); - if (unlock) + if (vms->unlock) mmap_read_unlock(mm); =20 __mt_destroy(mas_detach->tree); } =20 /* - * vmi_gather_munmap_vmas() - Put all VMAs within a range into a maple tree + * vms_gather_munmap_vmas() - Put all VMAs within a range into a maple tree * for removal at a later date. Handles splitting first and last if neces= sary * and marking the vmas as isolated. * - * @vmi: The vma iterator - * @vma: The starting vm_area_struct - * @mm: The mm_struct - * @start: The aligned start address to munmap. - * @end: The aligned end address to munmap. - * @uf: The userfaultfd list_head + * @vms: The vma munmap struct * @mas_detach: The maple state tracking the detached tree - * @locked_vm: a pointer to store the VM_LOCKED pages count. * * Return: 0 on success */ -static int -vmi_gather_munmap_vmas(struct vma_iterator *vmi, struct vm_area_struct *vm= a, - struct mm_struct *mm, unsigned long start, - unsigned long end, struct list_head *uf, - struct ma_state *mas_detach, unsigned long *locked_vm) +static int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, + struct ma_state *mas_detach) { struct vm_area_struct *next =3D NULL; - int count =3D 0; int error =3D -ENOMEM; =20 /* @@ -2689,17 +2696,18 @@ vmi_gather_munmap_vmas(struct vma_iterator *vmi, st= ruct vm_area_struct *vma, */ =20 /* Does it split the first one? */ - if (start > vma->vm_start) { + if (vms->start > vms->vma->vm_start) { =20 /* * Make sure that map_count on return from munmap() will * not exceed its limit; but let map_count go just above * its limit temporarily, to help free resources as expected. */ - if (end < vma->vm_end && mm->map_count >=3D sysctl_max_map_count) + if (vms->end < vms->vma->vm_end && + vms->mm->map_count >=3D sysctl_max_map_count) goto map_count_exceeded; =20 - error =3D __split_vma(vmi, vma, start, 1); + error =3D __split_vma(vms->vmi, vms->vma, vms->start, 1); if (error) goto start_split_failed; } @@ -2708,25 +2716,25 @@ vmi_gather_munmap_vmas(struct vma_iterator *vmi, st= ruct vm_area_struct *vma, * Detach a range of VMAs from the mm. Using next as a temp variable as * it is always overwritten. */ - next =3D vma; + next =3D vms->vma; do { /* Does it split the end? */ - if (next->vm_end > end) { - error =3D __split_vma(vmi, next, end, 0); + if (next->vm_end > vms->end) { + error =3D __split_vma(vms->vmi, next, vms->end, 0); if (error) goto end_split_failed; } vma_start_write(next); - mas_set(mas_detach, count++); + mas_set(mas_detach, vms->vma_count++); error =3D mas_store_gfp(mas_detach, next, GFP_KERNEL); if (error) goto munmap_gather_failed; =20 vma_mark_detached(next, true); if (next->vm_flags & VM_LOCKED) - *locked_vm +=3D vma_pages(next); + vms->locked_vm +=3D vma_pages(next); =20 - if (unlikely(uf)) { + if (unlikely(vms->uf)) { /* * If userfaultfd_unmap_prep returns an error the vmas * will remain split, but userland will get a @@ -2736,16 +2744,17 @@ vmi_gather_munmap_vmas(struct vma_iterator *vmi, st= ruct vm_area_struct *vma, * split, despite we could. This is unlikely enough * failure that it's not worth optimizing it for. */ - error =3D userfaultfd_unmap_prep(next, start, end, uf); + error =3D userfaultfd_unmap_prep(next, vms->start, + vms->end, vms->uf); =20 if (error) goto userfaultfd_error; } #ifdef CONFIG_DEBUG_VM_MAPLE_TREE - BUG_ON(next->vm_start < start); - BUG_ON(next->vm_start > end); + BUG_ON(next->vm_start < vms->start); + BUG_ON(next->vm_start > vms->end); #endif - } for_each_vma_range(*vmi, next, end); + } for_each_vma_range(*(vms->vmi), next, vms->end); =20 #if defined(CONFIG_DEBUG_VM_MAPLE_TREE) /* Make sure no VMAs are about to be lost. */ @@ -2754,21 +2763,21 @@ vmi_gather_munmap_vmas(struct vma_iterator *vmi, st= ruct vm_area_struct *vma, struct vm_area_struct *vma_mas, *vma_test; int test_count =3D 0; =20 - vma_iter_set(vmi, start); + vma_iter_set(vms->vmi, vms->start); rcu_read_lock(); - vma_test =3D mas_find(&test, count - 1); - for_each_vma_range(*vmi, vma_mas, end) { + vma_test =3D mas_find(&test, vms->vma_count - 1); + for_each_vma_range(*(vms->vmi), vma_mas, vms->end) { BUG_ON(vma_mas !=3D vma_test); test_count++; - vma_test =3D mas_next(&test, count - 1); + vma_test =3D mas_next(&test, vms->vma_count - 1); } rcu_read_unlock(); - BUG_ON(count !=3D test_count); + BUG_ON(vms->vma_count !=3D test_count); } #endif =20 - while (vma_iter_addr(vmi) > start) - vma_iter_prev_range(vmi); + while (vma_iter_addr(vms->vmi) > vms->start) + vma_iter_prev_range(vms->vmi); =20 return 0; =20 @@ -2804,11 +2813,11 @@ do_vmi_align_munmap(struct vma_iterator *vmi, struc= t vm_area_struct *vma, MA_STATE(mas_detach, &mt_detach, 0, 0); mt_init_flags(&mt_detach, vmi->mas.tree->ma_flags & MT_FLAGS_LOCK_MASK); mt_on_stack(mt_detach); + struct vma_munmap_struct vms; int error; - unsigned long locked_vm =3D 0; =20 - error =3D vmi_gather_munmap_vmas(vmi, vma, mm, start, end, uf, - &mas_detach, &locked_vm); + init_vma_munmap(&vms, vmi, vma, start, end, uf, unlock); + error =3D vms_gather_munmap_vmas(&vms, &mas_detach); if (error) goto gather_failed; =20 @@ -2817,8 +2826,7 @@ do_vmi_align_munmap(struct vma_iterator *vmi, struct = vm_area_struct *vma, goto clear_tree_failed; =20 /* Point of no return */ - vmi_complete_munmap_vmas(vmi, vma, mm, start, end, unlock, &mas_detach, - locked_vm); + vms_complete_munmap_vmas(&vms, &mas_detach); return 0; =20 clear_tree_failed: --=20 2.43.0