From patchwork Mon Jan 27 15:50:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13951575 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 547F9C02188 for ; Mon, 27 Jan 2025 15:51:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E5121280170; Mon, 27 Jan 2025 10:51:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DD9BD28016F; Mon, 27 Jan 2025 10:51:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB6AB280170; Mon, 27 Jan 2025 10:51:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 31BF528016F for ; Mon, 27 Jan 2025 10:51:16 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 55487A024D for ; Mon, 27 Jan 2025 15:51:15 +0000 (UTC) X-FDA: 83053670910.09.1251251 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf27.hostedemail.com (Postfix) with ESMTP id 97DF440004 for ; Mon, 27 Jan 2025 15:51:11 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="lUacoQ/Q"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=ka29cd3x; spf=pass (imf27.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737993071; 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=rcU8Rnf2jqj92Zfr3OOHzxw3letj6lo5Yzku/ikp7mY=; b=dUfq5VbsrPiBa4tbTziN++zAwRcLV6WH3FHAhs2O+y4+jlqCUGuqxdbksN77448zXYiyE8 sjriwBxBZMsFerG30x0fH0ore/h/EopzjFEAl7U0Gn+RsxaxMTlEWrkSQ3Ju/JKTe8nXcL 670RWaTRhPOhYsNPZFwLeRzqyO1Lsic= ARC-Authentication-Results: i=2; imf27.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="lUacoQ/Q"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=ka29cd3x; spf=pass (imf27.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1737993071; a=rsa-sha256; cv=pass; b=F2Fz2E2lOXif2KJT8NsSdNBrvVyMRoI2PkYoqDCxSJ5KJ9j4d2ss3H866SixF5jXlvf7fh tLKz/bsP5FjBoLjTkHoLVfm6YjxkGxU4UAlwtFQmGmEKpEgzGzcSfguzmoYdadTmHAcrEZ RFrF2dpExhc1NNDbekDymEdoENGGj/Y= Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50RB7O3L010970; Mon, 27 Jan 2025 15:51:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=rcU8Rnf2jqj92Zfr3OOHzxw3letj6lo5Yzku/ikp7mY=; b= lUacoQ/QYZl5NQdCdX86zjg2k4f0/Zl8HhGoOGgf2vQNAYQf/T7SqoTGOfhVOcFP 6Kogl/i4wgSzBRlrHfmMsKmRYcPjqlXS7S92wqUd0GeMFrtqHMAgl/DYBiOGo4er YGx4t/HOaTiO8YoCBaLzQRgfF39hPZfWmXnrNKn+9Lz+xHbsVsbaPJOgfStGkSjj Q1a7h0aMQDskBpecsjRcEscnT+b24hXjI7Nyk6gAxNp3AM4xzVjxIAznIlDNK562 fWV6Qv4IpaPDJTJ1TJG/rcVq/bj5tIMRk46/AFxhYCWDGhq8EP6kFnoWpewZmznF ra+3HROTeRlfnecDgC9SPw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44e900rhk7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Jan 2025 15:51:08 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50RFSOpD005390; Mon, 27 Jan 2025 15:51:07 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 44cpd75syr-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Jan 2025 15:51:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=PsltoaaK3eCl/wMlEri3Jz1o/QGoo+MlT7WrUR+DL5ajaDnElne2txZnvBmUQIQTlCPKoTL+xX+ko1AJY9KV3oXdkRyXVKkwpI9pHbB0/wGfdCagyDyADcg2l1/9FcEHXs4saqy5RZbalyc3N4HgnnCK0VH+ojxWal6lFBne58kDrYoSXKUQmWeZKAr8AUk/2PdItgR3QEifRR8Rve3k5fKMcjIe6fBozPIwSsNLncoChulf5Y5vGZCDLio1x2Y0/yDZtJL/KudGCt2TJ8PzFNsqaWpSgLdmUltWJERg61ajj0uJ+eKibq73RqWGVP2Q/4Sv1ea8pmcQwzmNU8x0Xg== 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=rcU8Rnf2jqj92Zfr3OOHzxw3letj6lo5Yzku/ikp7mY=; b=tIicx7wtXOx4As5/0tkrjpvpuXLLbznuuTAUbRwtaNJfch2RoiPeFZutcYran1Qc6hOdXLa7GhAd3Hxp+ualQyJHAtkoY815sJIpfEVEK0w1EX/W8zvLUggcUh5a/8HWspEbk6eo6MrcigEc5IeXEczE2+eDOBbWih1QIV1jMGa1cnHMzgINNFMqu5mxVH1oK+2Pl9m0rigduyvWBDK+WVNzNtcDMpAdYlaOZW5V1WXHQQbKLC+cc0lLZIBlccAoYXIWbnc0xh93mb8GzBOcfGMKgAapLo0q+mgJBSTXh5Ql6fZUCNHoROWUnp8YjmfWyoXhN99C3Ia6IYfyxUfVoA== 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=rcU8Rnf2jqj92Zfr3OOHzxw3letj6lo5Yzku/ikp7mY=; b=ka29cd3xXwJNu7zmgkucQhCFqavGiGUsYE+mzNUkyfq7Lp3wczmQgGH15GnfLDEiQ7peqPLTDUNCmGjDkWkNGExhAQFUHLAtEzrlFAX3PR5hlNC+5rJEs1Z0S9m21z9DmYr3NmZ9O6LoCaMMLvH8zG4Vywlefls1oGirMft95E4= Received: from MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) by SA3PR10MB6949.namprd10.prod.outlook.com (2603:10b6:806:319::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.18; Mon, 27 Jan 2025 15:51:01 +0000 Received: from MN2PR10MB3374.namprd10.prod.outlook.com ([fe80::eab5:3c8c:1b35:4348]) by MN2PR10MB3374.namprd10.prod.outlook.com ([fe80::eab5:3c8c:1b35:4348%3]) with mapi id 15.20.8377.021; Mon, 27 Jan 2025 15:51:01 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] mm: simplify vma merge structure and expand comments Date: Mon, 27 Jan 2025 15:50:40 +0000 Message-ID: X-Mailer: git-send-email 2.48.0 In-Reply-To: References: X-ClientProxiedBy: LO6P123CA0049.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:310::9) To MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3374:EE_|SA3PR10MB6949:EE_ X-MS-Office365-Filtering-Correlation-Id: ad65cb67-893d-4ffa-4941-08dd3eea662a X-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pOMAJCw6lMXMR2IwPxLczQARqpf9HVNtsX4n5hL+CdFy++P+KV35N9hmGG2aRNeuKG++Q+Rc/iN8xoe7rsbqvKoRSqZ6iKx7Him7Ok7V6iDhjbAiKjYU+kVEfpE9YJlaaS+xtzFuIkmUrhI2r2/ENjW18F4idcM8XY4Yd2TIFUp8gvFwgOqQ5e6XiqR0t+JePsi1I5JLOEXA6hJ4cV8CBGVzK1EQTZs5PkkIyNXu7Yovr7ihhIevet6XW6MJz0eYCrsMZl4MmOPg66uSC0rCgxEhIIKwtSjK7eW5rTBDh1UcUXhchZIkYwDcyD+khLkYModxuoKEA5Sft3wUndEy1Md5YmrlSItMFxEDQ1IjucRarozBxD53R8eDnL+Y1eO2m0mXIZWSieCdnMgIPXoTl0gFenQt5ReTgDw8jmXidSpe8ccnzWHKCLdxTcnPqNTaXYm X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB3374.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: Wbv9831x5M0DgyBS7cR4bVcc4yS0YNR4MjgW44xK/mmmZzzzfWPRMxTeyykl0vTJI3ajK/NNFUeTqLI6KTEIaMk/RusG1mK9YJPfazOhmPOcaYML+3NllcbUhWFDT1RvBcM9c0AFmPOaRJNIslk+ZkkB9cA8kv1vEO69/w22ZWn0suqQxw5g5qkdkIm0DI5XROQqH077MlzIeE2nAoaMOipoO/KKYljVvBfCWohpcfQn0TuyBhbhLvYAFo7oKgx0NamcdAoOQq1rAEiMNZ/kxGpFukyKQe78PQmzeadhjIyJIH6y9nDCD0kVz1YfbrZ8PE78u0PVSZPA2W6BEFzIaFqM3dfFiVv0vGi4wdFmSjnJT18oTusNk4vpcJqUBqFB/3wX7CiX9IBuQemJEdKgt60izHG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LDFG+hXBHTHdjZHtVABgpq9BXeFOUkkoG83C5BTmT0C9JlBJqKBqLrMck/YeSCIqkiXZX2kGDMEi77eDYj2LAsuvtkueL+ZsYeZIyul0zI6v+FCw5Zg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: eBP6zwbMYzLCih8aAJR4AD1BfgMhfy8hUhuzZGFpDq76Ci8w0sJqrAB8YrGamVOZUMQGvOivwixukxpiqjNq0jHL+s+zyQ9EyxVgvy2eq38MIC3fwjB+inEFPKT3s3aIHnW+eb30WtOdKRTkm/M+PcKNuc2YpDZmhzeIHkYYLh+ANIL61l96lS9hhCVEzqen7oH5QGU6+DKhAvdpJZ5gEGBsOdq0E2l5UTU78BK8DqUa9Loc591cIZdno+VDU+hyCXK59FC0WFeWXB7cF93atDF0XBGkJjOJJkRbMAWmnTEKBLmCVFRyy0fTMmr/I0C5lg8ZM0LalBAP5/Uluy2MmKCV8PkS6QC654XEqJli/FOnglRHhE2yIimSZzZpekVjU4Kw8z1yQV4svfjH5G3OHdS/Ymz/iG1CghSns+p0gCQCXHa5/KUZJx4rfQ84safeIFMdaoYVxHlOegyWDoPZd+z5qxotXRZ81sto/UKNyC8YUkWkhsj6GyktUvAYh4cp68+H7aUPt8wDxVU4suRTzgar5Z1xD+4V5QPBoPLtB8iJ98MPj9mzAlrvEfiP+ItDNwRNkjmsK6DoDALise/Ap/UF0Sx0nXJeSdvkyXTqBnA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ad65cb67-893d-4ffa-4941-08dd3eea662a X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3374.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2025 15:51:01.5987 (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: Kd1xzdcY4qgxLbMrqUJisHbeGPCIUDxBczOWR3TiuBFLidspadVmMXC2zgznRYawsB17t75slnMdQls1F7dDa7wyp5KGgep8XMygv5UXLWE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR10MB6949 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-27_07,2025-01-27_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501270126 X-Proofpoint-GUID: u3RW-_C_NAYWdBbfsR1azTW9MUDKpNcu X-Proofpoint-ORIG-GUID: u3RW-_C_NAYWdBbfsR1azTW9MUDKpNcu X-Rspamd-Queue-Id: 97DF440004 X-Stat-Signature: fmzwk6qxzahojr44934sqdqn9pk46msa X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1737993071-260201 X-HE-Meta: U2FsdGVkX1/m4tF2azdj2G+n+1npsj0PcRR2CsKrGNecPiPA6kseli5lONCCM7VeyckszRh5pOH9pG22BN4uV2WWYaYUlSdxK2HNKQuSRFtGQfoOJ+vKzScfShQ+HQSr4AMkKhwYjpXu5Q3fmigK/6NqRGwLBo2IRB8O/AOm0o/LLIYsFZQzLAMVG0I6cIfv08aLiE0+Msm+Ak5o5w9fPRUQxjPDgR+xmzipRAqi+gckrP5wA6huPnlLt4bO5NV/U0Jcp/A2+ahXlCWkHPVtL++Aob4/MTAAZe2hKHSZqWJISyXGncDHC95wsBKYn8VMwrnckI4Yr8DTn7yY6eoQOYfTKo7qM1uFLPlQtv1TcI8Qc6fTKD17TMr4sYIs+H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606uSEO/d6pozi6GeM4rruA1cdQhdtzuxb9W4Hmg/iddvIHkSJIm7UsNlDa/YwxwO3YX/aUOF2gp1gyg33BP/p5aouvwubEEwFeJXnalExB33juZHR 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 merge code, while much improved, still has a number of points of confusion. As part of a broader series cleaning this up to make this more maintainable, we start by addressing some confusion around vma_merge_struct fields. So far, the caller either provides no vmg->vma (a new VMA) or supplies the existing VMA which is being altered, setting vmg->start,end,pgoff to the proposed VMA dimensions. vmg->vma is then updated, as are vmg->start,end,pgoff as the merge process proceeds and the appropriate merge strategy is determined. This is rather confusing, as vmg->vma starts off as the 'middle' VMA between vmg->prev,next, but becomes the 'target' VMA, except in one specific edge case (merge next, shrink middle). Int his patch we introduce vmg->middle to describe the VMA that is between vmg->prev and vmg->next, and does NOT change during the merge operation. We replace vmg->vma with vmg->target, and use this only during the merge operation itself. Aside from the merge right, shrink middle case, this becomes the VMA that forms the basis of the VMA that is returned. This edge case can be addressed in a future commit. We also add a number of comments to explain what is going on. Finally, we adjust the ASCII diagrams showing each merge case in vma_merge_existing_range() to be clearer - the arrow range previously showed the vmg->start, end spanned area, but it is clearer to change this to show the final merged VMA. This patch has no change in functional behaviour. Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- mm/debug.c | 18 ++--- mm/mmap.c | 2 +- mm/vma.c | 166 +++++++++++++++++++++------------------- mm/vma.h | 42 ++++++++-- tools/testing/vma/vma.c | 52 ++++++------- 5 files changed, 159 insertions(+), 121 deletions(-) diff --git a/mm/debug.c b/mm/debug.c index 8d2acf432385..c9e07651677b 100644 --- a/mm/debug.c +++ b/mm/debug.c @@ -261,7 +261,7 @@ void dump_vmg(const struct vma_merge_struct *vmg, const char *reason) pr_warn("vmg %px state: mm %px pgoff %lx\n" "vmi %px [%lx,%lx)\n" - "prev %px next %px vma %px\n" + "prev %px middle %px next %px target %px\n" "start %lx end %lx flags %lx\n" "file %px anon_vma %px policy %px\n" "uffd_ctx %px\n" @@ -270,7 +270,7 @@ void dump_vmg(const struct vma_merge_struct *vmg, const char *reason) vmg, vmg->mm, vmg->pgoff, vmg->vmi, vmg->vmi ? vma_iter_addr(vmg->vmi) : 0, vmg->vmi ? vma_iter_end(vmg->vmi) : 0, - vmg->prev, vmg->next, vmg->vma, + vmg->prev, vmg->middle, vmg->next, vmg->target, vmg->start, vmg->end, vmg->flags, vmg->file, vmg->anon_vma, vmg->policy, #ifdef CONFIG_USERFAULTFD @@ -288,13 +288,6 @@ void dump_vmg(const struct vma_merge_struct *vmg, const char *reason) pr_warn("vmg %px mm: (NULL)\n", vmg); } - if (vmg->vma) { - pr_warn("vmg %px vma:\n", vmg); - dump_vma(vmg->vma); - } else { - pr_warn("vmg %px vma: (NULL)\n", vmg); - } - if (vmg->prev) { pr_warn("vmg %px prev:\n", vmg); dump_vma(vmg->prev); @@ -302,6 +295,13 @@ void dump_vmg(const struct vma_merge_struct *vmg, const char *reason) pr_warn("vmg %px prev: (NULL)\n", vmg); } + if (vmg->middle) { + pr_warn("vmg %px middle:\n", vmg); + dump_vma(vmg->middle); + } else { + pr_warn("vmg %px middle: (NULL)\n", vmg); + } + if (vmg->next) { pr_warn("vmg %px next:\n", vmg); dump_vma(vmg->next); diff --git a/mm/mmap.c b/mm/mmap.c index cda01071c7b1..6401a1d73f4a 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1707,7 +1707,7 @@ int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift) /* * cover the whole range: [new_start, old_end) */ - vmg.vma = vma; + vmg.middle = vma; if (vma_expand(&vmg)) return -ENOMEM; diff --git a/mm/vma.c b/mm/vma.c index af1d549b179c..68a301a76297 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -52,7 +52,7 @@ struct mmap_state { .pgoff = (map_)->pgoff, \ .file = (map_)->file, \ .prev = (map_)->prev, \ - .vma = vma_, \ + .middle = vma_, \ .next = (vma_) ? NULL : (map_)->next, \ .state = VMA_MERGE_START, \ .merge_flags = VMG_FLAG_DEFAULT, \ @@ -639,7 +639,7 @@ static int commit_merge(struct vma_merge_struct *vmg, { struct vma_prepare vp; - init_multi_vma_prep(&vp, vmg->vma, adjust, remove, remove2); + init_multi_vma_prep(&vp, vmg->target, adjust, remove, remove2); VM_WARN_ON(vp.anon_vma && adjust && adjust->anon_vma && vp.anon_vma != adjust->anon_vma); @@ -652,15 +652,15 @@ static int commit_merge(struct vma_merge_struct *vmg, adjust->vm_end); } - if (vma_iter_prealloc(vmg->vmi, vmg->vma)) + if (vma_iter_prealloc(vmg->vmi, vmg->target)) 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); + vma_adjust_trans_huge(vmg->target, vmg->start, vmg->end, adj_start); + vma_set_range(vmg->target, vmg->start, vmg->end, vmg->pgoff); if (expanded) - vma_iter_store(vmg->vmi, vmg->vma); + vma_iter_store(vmg->vmi, vmg->target); if (adj_start) { adjust->vm_start += adj_start; @@ -671,7 +671,7 @@ static int commit_merge(struct vma_merge_struct *vmg, } } - vma_complete(&vp, vmg->vmi, vmg->vma->vm_mm); + vma_complete(&vp, vmg->vmi, vmg->target->vm_mm); return 0; } @@ -694,8 +694,9 @@ static bool can_merge_remove_vma(struct vm_area_struct *vma) * 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. + * the maple tree describing the @vmg->middle->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 @@ -704,45 +705,47 @@ static bool can_merge_remove_vma(struct vm_area_struct *vma) * 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 assign the VMA to be modifed to @vmg->middle. * - The caller must have set @vmg->prev to the previous VMA, if there is one. * - The caller must not set @vmg->next, as we determine this. * - The caller must hold a WRITE lock on the mm_struct->mmap_lock. - * - vmi must be positioned within [@vmg->vma->vm_start, @vmg->vma->vm_end). + * - vmi must be positioned within [@vmg->middle->vm_start, @vmg->middle->vm_end). */ static __must_check struct vm_area_struct *vma_merge_existing_range( struct vma_merge_struct *vmg) { - struct vm_area_struct *vma = vmg->vma; + struct vm_area_struct *middle = vmg->middle; 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 left_side = middle && start == middle->vm_start; + bool right_side = middle && end == middle->vm_end; int err = 0; long adj_start = 0; - bool merge_will_delete_vma, merge_will_delete_next; + bool merge_will_delete_middle, merge_will_delete_next; bool merge_left, merge_right, merge_both; bool expanded; mmap_assert_write_locked(vmg->mm); - VM_WARN_ON_VMG(!vma, vmg); /* We are modifying a VMA, so caller must specify. */ + VM_WARN_ON_VMG(!middle, vmg); /* We are modifying a VMA, so caller must specify. */ VM_WARN_ON_VMG(vmg->next, vmg); /* We set this. */ VM_WARN_ON_VMG(prev && start <= prev->vm_start, vmg); VM_WARN_ON_VMG(start >= end, vmg); /* - * If vma == prev, then we are offset into a VMA. Otherwise, if we are + * If middle == prev, then we are offset into a VMA. Otherwise, if we are * not, we must span a portion of the VMA. */ - VM_WARN_ON_VMG(vma && ((vma != prev && vmg->start != vma->vm_start) || - vmg->end > vma->vm_end), vmg); - /* The vmi must be positioned within vmg->vma. */ - VM_WARN_ON_VMG(vma && !(vma_iter_addr(vmg->vmi) >= vma->vm_start && - vma_iter_addr(vmg->vmi) < vma->vm_end), vmg); + VM_WARN_ON_VMG(middle && + ((middle != prev && vmg->start != middle->vm_start) || + vmg->end > middle->vm_end), vmg); + /* The vmi must be positioned within vmg->middle. */ + VM_WARN_ON_VMG(middle && + !(vma_iter_addr(vmg->vmi) >= middle->vm_start && + vma_iter_addr(vmg->vmi) < middle->vm_end), vmg); vmg->state = VMA_MERGE_NOMERGE; @@ -776,13 +779,13 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( merge_both = merge_left && merge_right; /* If we span the entire VMA, a merge implies it will be deleted. */ - merge_will_delete_vma = left_side && right_side; + merge_will_delete_middle = left_side && right_side; /* - * If we need to remove vma in its entirety but are unable to do so, + * If we need to remove middle 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)) + if (merge_will_delete_middle && !can_merge_remove_vma(middle)) return NULL; /* @@ -793,7 +796,7 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( /* * If we cannot delete next, then we can reduce the operation to merging - * prev and vma (thereby deleting vma). + * prev and middle (thereby deleting middle). */ if (merge_will_delete_next && !can_merge_remove_vma(next)) { merge_will_delete_next = false; @@ -801,8 +804,8 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( merge_both = false; } - /* No matter what happens, we will be adjusting vma. */ - vma_start_write(vma); + /* No matter what happens, we will be adjusting middle. */ + vma_start_write(middle); if (merge_left) vma_start_write(prev); @@ -812,13 +815,13 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( if (merge_both) { /* - * |<----->| - * |-------*********-------| - * prev vma next - * extend delete delete + * |<-------------------->| + * |-------********-------| + * prev middle next + * extend delete delete */ - vmg->vma = prev; + vmg->target = prev; vmg->start = prev->vm_start; vmg->end = next->vm_end; vmg->pgoff = prev->vm_pgoff; @@ -826,78 +829,79 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( /* * 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. + * next or middle contains the anon_vma we must duplicate. */ - err = dup_anon_vma(prev, next->anon_vma ? next : vma, &anon_dup); + err = dup_anon_vma(prev, next->anon_vma ? next : middle, + &anon_dup); } else if (merge_left) { /* - * |<----->| OR - * |<--------->| + * |<------------>| OR + * |<----------------->| * |-------************* - * prev vma + * prev middle * extend shrink/delete */ - vmg->vma = prev; + vmg->target = prev; vmg->start = prev->vm_start; vmg->pgoff = prev->vm_pgoff; - if (!merge_will_delete_vma) { - adjust = vma; - adj_start = vmg->end - vma->vm_start; + if (!merge_will_delete_middle) { + adjust = middle; + adj_start = vmg->end - middle->vm_start; } - err = dup_anon_vma(prev, vma, &anon_dup); + err = dup_anon_vma(prev, middle, &anon_dup); } else { /* merge_right */ /* - * |<----->| OR - * |<--------->| + * |<------------->| OR + * |<----------------->| * *************-------| - * vma next + * middle next * shrink/delete extend */ pgoff_t pglen = PHYS_PFN(vmg->end - vmg->start); VM_WARN_ON_VMG(!merge_right, vmg); - /* If we are offset into a VMA, then prev must be vma. */ - VM_WARN_ON_VMG(vmg->start > vma->vm_start && prev && vma != prev, vmg); + /* If we are offset into a VMA, then prev must be middle. */ + VM_WARN_ON_VMG(vmg->start > middle->vm_start && prev && middle != prev, vmg); - if (merge_will_delete_vma) { - vmg->vma = next; + if (merge_will_delete_middle) { + vmg->target = next; vmg->end = next->vm_end; vmg->pgoff = next->vm_pgoff - pglen; } else { /* - * We shrink vma and expand next. + * We shrink middle and expand next. * * IMPORTANT: This is the ONLY case where the final - * merged VMA is NOT vmg->vma, but rather vmg->next. + * merged VMA is NOT vmg->target, but rather vmg->next. */ - - vmg->start = vma->vm_start; + vmg->target = middle; + vmg->start = middle->vm_start; vmg->end = start; - vmg->pgoff = vma->vm_pgoff; + vmg->pgoff = middle->vm_pgoff; adjust = next; - adj_start = -(vma->vm_end - start); + adj_start = -(middle->vm_end - start); } - err = dup_anon_vma(next, vma, &anon_dup); + err = dup_anon_vma(next, middle, &anon_dup); } if (err) goto abort; /* - * In nearly all cases, we expand vmg->vma. There is one exception - + * In nearly all cases, we expand vmg->middle. 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. + * the end of vmg->middle and adjust the start of vmg->next accordingly. */ - expanded = !merge_right || merge_will_delete_vma; + expanded = !merge_right || merge_will_delete_middle; if (commit_merge(vmg, adjust, - merge_will_delete_vma ? vma : NULL, + merge_will_delete_middle ? middle : NULL, merge_will_delete_next ? next : NULL, adj_start, expanded)) { if (anon_dup) @@ -973,7 +977,7 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) bool just_expand = vmg->merge_flags & VMG_FLAG_JUST_EXPAND; mmap_assert_write_locked(vmg->mm); - VM_WARN_ON_VMG(vmg->vma, vmg); + VM_WARN_ON_VMG(vmg->middle, vmg); /* vmi must point at or before the gap. */ VM_WARN_ON_VMG(vma_iter_addr(vmg->vmi) > end, vmg); @@ -989,13 +993,13 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) /* If we can merge with the next VMA, adjust vmg accordingly. */ if (can_merge_right) { vmg->end = next->vm_end; - vmg->vma = next; + vmg->middle = next; } /* If we can merge with the previous VMA, adjust vmg accordingly. */ if (can_merge_left) { vmg->start = prev->vm_start; - vmg->vma = prev; + vmg->middle = prev; vmg->pgoff = prev->vm_pgoff; /* @@ -1017,10 +1021,10 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) * 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); + if (vmg->middle && !vma_expand(vmg)) { + khugepaged_enter_vma(vmg->middle, vmg->flags); vmg->state = VMA_MERGE_SUCCESS; - return vmg->vma; + return vmg->middle; } return NULL; @@ -1032,44 +1036,46 @@ struct vm_area_struct *vma_merge_new_range(struct vma_merge_struct *vmg) * @vmg: Describes a VMA expansion operation. * * 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 + * Will expand over vmg->next if it's different from vmg->middle and vmg->end == + * vmg->next->vm_end. Checking if the vmg->middle can expand and merge with * vmg->next needs to be handled by the caller. * * Returns: 0 on success. * * ASSUMPTIONS: - * - The caller must hold a WRITE lock on vmg->vma->mm->mmap_lock. - * - The caller must have set @vmg->vma and @vmg->next. + * - The caller must hold a WRITE lock on vmg->middle->mm->mmap_lock. + * - The caller must have set @vmg->middle and @vmg->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 *middle = vmg->middle; struct vm_area_struct *next = vmg->next; mmap_assert_write_locked(vmg->mm); - vma_start_write(vma); - if (next && (vma != next) && (vmg->end == next->vm_end)) { + vma_start_write(middle); + if (next && (middle != next) && (vmg->end == next->vm_end)) { int ret; remove_next = true; /* This should already have been checked by this point. */ VM_WARN_ON_VMG(!can_merge_remove_vma(next), vmg); vma_start_write(next); - ret = dup_anon_vma(vma, next, &anon_dup); + ret = dup_anon_vma(middle, next, &anon_dup); if (ret) return ret; } /* Not merging but overwriting any part of next is not handled. */ VM_WARN_ON_VMG(next && !remove_next && - next != vma && vmg->end > next->vm_start, vmg); + next != middle && vmg->end > next->vm_start, vmg); /* Only handles expanding */ - VM_WARN_ON_VMG(vma->vm_start < vmg->start || vma->vm_end > vmg->end, vmg); + VM_WARN_ON_VMG(middle->vm_start < vmg->start || + middle->vm_end > vmg->end, vmg); + vmg->target = middle; if (commit_merge(vmg, NULL, remove_next ? next : NULL, NULL, 0, true)) goto nomem; @@ -1508,7 +1514,7 @@ int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, */ static struct vm_area_struct *vma_modify(struct vma_merge_struct *vmg) { - struct vm_area_struct *vma = vmg->vma; + struct vm_area_struct *vma = vmg->middle; struct vm_area_struct *merged; /* First, try to merge. */ @@ -1605,7 +1611,7 @@ struct vm_area_struct *vma_merge_extend(struct vma_iterator *vmi, VMG_VMA_STATE(vmg, vmi, vma, vma, vma->vm_end, vma->vm_end + delta); vmg.next = vma_iter_next_rewind(vmi, NULL); - vmg.vma = NULL; /* We use the VMA to populate VMG fields only. */ + vmg.middle = NULL; /* We use the VMA to populate VMG fields only. */ return vma_merge_new_range(&vmg); } @@ -1726,7 +1732,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 */ - vmg.vma = NULL; /* New VMA range. */ + vmg.middle = NULL; /* New VMA range. */ vmg.pgoff = pgoff; vmg.next = vma_iter_next_rewind(&vmi, NULL); new_vma = vma_merge_new_range(&vmg); diff --git a/mm/vma.h b/mm/vma.h index a2e8710b8c47..5b5dd07e478c 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -69,16 +69,48 @@ enum vma_merge_flags { VMG_FLAG_JUST_EXPAND = 1 << 0, }; -/* Represents a VMA merge operation. */ +/* + * Describes a VMA merge operation and is threaded throughout it. + * + * Any of the fields may be mutated by the merge operation, so no guarantees are + * made to the contents of this structure after a merge operation has completed. + */ struct vma_merge_struct { struct mm_struct *mm; struct vma_iterator *vmi; - pgoff_t pgoff; + /* + * Adjacent VMAs, any of which may be NULL if not present: + * + * |------|--------|------| + * | prev | middle | next | + * |------|--------|------| + * + * middle may not yet exist in the case of a proposed new VMA being + * merged, or it may be an existing VMA. + * + * next may be assigned by the caller. + */ 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. */ + struct vm_area_struct *middle; + struct vm_area_struct *next; + /* + * This is the VMA we ultimately target to become the merged VMA, except + * for the one exception of merge right, shrink next (for details of + * this scenario see vma_merge_existing_range()). + */ + struct vm_area_struct *target; + /* + * Initially, the start, end, pgoff fields are provided by the caller + * and describe the proposed new VMA range, whether modifying an + * existing VMA (which will be 'middle'), or adding a new one. + * + * During the merge process these fields are updated to describe the new + * range _including those VMAs which will be merged_. + */ unsigned long start; unsigned long end; + pgoff_t pgoff; + unsigned long flags; struct file *file; struct anon_vma *anon_vma; @@ -118,8 +150,8 @@ static inline pgoff_t vma_pgoff_offset(struct vm_area_struct *vma, .mm = vma_->vm_mm, \ .vmi = vmi_, \ .prev = prev_, \ + .middle = vma_, \ .next = NULL, \ - .vma = vma_, \ .start = start_, \ .end = end_, \ .flags = vma_->vm_flags, \ diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index 04ab45e27fb8..3c0572120e94 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -147,8 +147,8 @@ static void vmg_set_range(struct vma_merge_struct *vmg, unsigned long start, vma_iter_set(vmg->vmi, start); vmg->prev = NULL; + vmg->middle = NULL; vmg->next = NULL; - vmg->vma = NULL; vmg->start = start; vmg->end = end; @@ -338,7 +338,7 @@ static bool test_simple_expand(void) VMA_ITERATOR(vmi, &mm, 0); struct vma_merge_struct vmg = { .vmi = &vmi, - .vma = vma, + .middle = vma, .start = 0, .end = 0x3000, .pgoff = 0, @@ -631,7 +631,7 @@ static bool test_vma_merge_special_flags(void) */ vma = alloc_and_link_vma(&mm, 0x3000, 0x4000, 3, flags); ASSERT_NE(vma, NULL); - vmg.vma = vma; + vmg.middle = vma; for (i = 0; i < ARRAY_SIZE(special_flags); i++) { vm_flags_t special_flag = special_flags[i]; @@ -760,7 +760,7 @@ static bool test_vma_merge_with_close(void) vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; /* * The VMA being modified in a way that would otherwise merge should @@ -787,7 +787,7 @@ static bool test_vma_merge_with_close(void) vma->vm_ops = &vm_ops; vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), NULL); /* * Initially this is misapprehended as an out of memory report, as the @@ -817,7 +817,7 @@ static bool test_vma_merge_with_close(void) vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), NULL); ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); @@ -843,7 +843,7 @@ static bool test_vma_merge_with_close(void) vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -940,7 +940,7 @@ static bool test_merge_existing(void) 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.middle = vma; vmg.prev = vma; vma->anon_vma = &dummy_anon_vma; ASSERT_EQ(merge_existing(&vmg), vma_next); @@ -973,7 +973,7 @@ static bool test_merge_existing(void) 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; + vmg.middle = vma; vma->anon_vma = &dummy_anon_vma; ASSERT_EQ(merge_existing(&vmg), vma_next); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -1003,7 +1003,7 @@ static bool test_merge_existing(void) 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; + vmg.middle = vma; vma->anon_vma = &dummy_anon_vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); @@ -1037,7 +1037,7 @@ static bool test_merge_existing(void) 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; + vmg.middle = vma; vma->anon_vma = &dummy_anon_vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -1067,7 +1067,7 @@ static bool test_merge_existing(void) 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; + vmg.middle = vma; vma->anon_vma = &dummy_anon_vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -1102,37 +1102,37 @@ static bool test_merge_existing(void) vmg_set_range(&vmg, 0x4000, 0x5000, 4, flags); vmg.prev = vma; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), NULL); ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); vmg_set_range(&vmg, 0x5000, 0x6000, 5, flags); vmg.prev = vma; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), NULL); ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); vmg_set_range(&vmg, 0x6000, 0x7000, 6, flags); vmg.prev = vma; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), NULL); ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); vmg_set_range(&vmg, 0x4000, 0x7000, 4, flags); vmg.prev = vma; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), NULL); ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); vmg_set_range(&vmg, 0x4000, 0x6000, 4, flags); vmg.prev = vma; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), NULL); ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); vmg_set_range(&vmg, 0x5000, 0x6000, 5, flags); vmg.prev = vma; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), NULL); ASSERT_EQ(vmg.state, VMA_MERGE_NOMERGE); @@ -1197,7 +1197,7 @@ static bool test_anon_vma_non_mergeable(void) vmg_set_range(&vmg, 0x3000, 0x7000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -1277,7 +1277,7 @@ static bool test_dup_anon_vma(void) vma_next->anon_vma = &dummy_anon_vma; vmg_set_range(&vmg, 0, 0x5000, 0, flags); - vmg.vma = vma_prev; + vmg.middle = vma_prev; vmg.next = vma_next; ASSERT_EQ(expand_existing(&vmg), 0); @@ -1309,7 +1309,7 @@ static bool test_dup_anon_vma(void) vma_next->anon_vma = &dummy_anon_vma; vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -1338,7 +1338,7 @@ static bool test_dup_anon_vma(void) vma->anon_vma = &dummy_anon_vma; vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -1366,7 +1366,7 @@ static bool test_dup_anon_vma(void) vma->anon_vma = &dummy_anon_vma; vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), vma_prev); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -1394,7 +1394,7 @@ static bool test_dup_anon_vma(void) vma->anon_vma = &dummy_anon_vma; vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.prev = vma; - vmg.vma = vma; + vmg.middle = vma; ASSERT_EQ(merge_existing(&vmg), vma_next); ASSERT_EQ(vmg.state, VMA_MERGE_SUCCESS); @@ -1432,7 +1432,7 @@ static bool test_vmi_prealloc_fail(void) vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); vmg.prev = vma_prev; - vmg.vma = vma; + vmg.middle = vma; fail_prealloc = true; @@ -1458,7 +1458,7 @@ static bool test_vmi_prealloc_fail(void) vma->anon_vma = &dummy_anon_vma; vmg_set_range(&vmg, 0, 0x5000, 3, flags); - vmg.vma = vma_prev; + vmg.middle = vma_prev; vmg.next = vma; fail_prealloc = true; From patchwork Mon Jan 27 15:50:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13951576 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 3502AC02188 for ; Mon, 27 Jan 2025 15:51:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B9731280172; Mon, 27 Jan 2025 10:51:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ACCC3280171; Mon, 27 Jan 2025 10:51:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A935280172; Mon, 27 Jan 2025 10:51:22 -0500 (EST) 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 63359280171 for ; Mon, 27 Jan 2025 10:51:22 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1F9D014030D for ; Mon, 27 Jan 2025 15:51:22 +0000 (UTC) X-FDA: 83053671204.18.2F4E1FB Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf28.hostedemail.com (Postfix) with ESMTP id 44446C0020 for ; Mon, 27 Jan 2025 15:51:11 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=EtljPBpJ; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="yx4dmS/Y"; spf=pass (imf28.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737993072; 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=1Mpx68EWduciawJBGblFrr1WVvICto8g1LTm3oOxpWY=; b=blBR1At3KVnH0P/clt9iEKnJlGHEVy6k4Q9z76TeqkK63hoi0FTTdf7smR906zF/vFN4Zu AyM5crCAYto5MxzwYFNymELGI0OVGDw/DisTSooVl24Kgti7PQFuWtfZArDA4wGiw3h3MQ 1TyKwxSAgn0DzQm00XW2q+NNOsKn1QM= ARC-Authentication-Results: i=2; imf28.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=EtljPBpJ; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="yx4dmS/Y"; spf=pass (imf28.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1737993072; a=rsa-sha256; cv=pass; b=OZxLcP5Jm4IScb12tpmq1Dn+5Bx9NB692YYhBwUvuuM4xFHiHbkJyYda8I2YqoR/qETB/P UWqTp78+g2RzlPNO3jD5XXOYonuCJrosp99JRNhsrcAKk3j2Mqp8dCtjJ3HJcuILAR0rr9 Htu8+Q8DQmGbm5Etemze1tEHf6EtCLQ= 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 50RF7DYx009169; Mon, 27 Jan 2025 15:51:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=1Mpx68EWduciawJBGblFrr1WVvICto8g1LTm3oOxpWY=; b= EtljPBpJIgyLT2ZLRdNFxcj1A3tzCKJTjNL9yGgkswzILwRs3H7sqBYYYOgYhHZ+ jo7mWhHwJizpO5u1IBvWZBRcrnGjRUH6YEfCmZkI5Owv44HWO00ULD0+D150bIsu 1RsgOICyeHHveVJbULkSK+vBKfT3Ngnu0PBQIYuMpZT1g/xul6KRT1pefRAJyYWZ 5lCgkDLmpEPLN4LGdsOb8qoIZwe6SJJ2w2zIHpFr2M1sqV4a0A2UvT7Gd9IpwiBV /dCCgpmTKkied1jzy95JK8gFUcpOFiK/6CfHAnxE3+DuTBxURbvNgy4BsBR+SN4y kooBcHbxPFi7b947hLiu+A== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44ecgf83qh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Jan 2025 15:51:09 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50RFSOpF005390; Mon, 27 Jan 2025 15:51:07 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 44cpd75syr-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Jan 2025 15:51:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bCE3RNG1Nd5N0n/DpMCdnMpWgdMh9dwwfWaRlnuMUXv9BMmWhVglKZkTpOzKaOi+IWvWj6B3i0zMVFVMnNGxyuAG+f6eeK3EQ3NwhutjRLxUvwvG1fOZkM8n+EO/TQdO3ig3sssFGP/Z8e+rhbfe8ecQNyyd4My5vYFkT1qMLD8VXNLzaenJJkP4MqFSsgopVvEdEIRTvAoBImedCoEbNGnzEmj19wxy6jPnwK5SXXhFFOr1AtN0UewYD+Fysn3Th9S2I6UsvjeoWqFLerwh3P9I21fIfhz7xExpv9ysxwq3CVLOPrkbzUnVzm0dFAenkq1z6EuNASy2TO/oAD998g== 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=1Mpx68EWduciawJBGblFrr1WVvICto8g1LTm3oOxpWY=; b=SdQWAyHB7oMQrYy4zfdV8vzx7f3KWJtV8IZ+oo23cYkR2cLay351MNKAoSR+HZWq+WKKvP8hOZ1AV/dNAaBnUl60e67a/5BoMfuorhUxXwaLw4taoq2rEbu1YNlIx1KJq1PI1cLnQ+ys31IJZ7wlDadBObvcdysgA2BVrc4/CtgbkHj+k0vb8sf7tNq37jkVp6xeWDqEUHezfqoJ1zzd8kfbEoCiuODg2ySbWkdqK33mR7IxyBnvI+n0V/zRgy++cvlBMe7jYXjLsthzYKhVtQ4/+J7IWvYsZajUPopk6KcK4O8buyoGU3cUmmIQhDOlCNxq4cO/0TuHaDgZWrgeAg== 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=1Mpx68EWduciawJBGblFrr1WVvICto8g1LTm3oOxpWY=; b=yx4dmS/YKKPxlYDmXmJFhkC1I+757QSONbzcqZtiK4t0AYGMERuqFbp12/64t/yfMMnYn1+f7aG+1F/fOLeyLpbICyDvHCqFXlKmdiHIRZbyJexP/fWbjbGFDXguZNEi879UJylDvEwOQBNxiwP/8STm/4E9lt+yQEX1T4QHemM= Received: from MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) by SA3PR10MB6949.namprd10.prod.outlook.com (2603:10b6:806:319::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.18; Mon, 27 Jan 2025 15:51:05 +0000 Received: from MN2PR10MB3374.namprd10.prod.outlook.com ([fe80::eab5:3c8c:1b35:4348]) by MN2PR10MB3374.namprd10.prod.outlook.com ([fe80::eab5:3c8c:1b35:4348%3]) with mapi id 15.20.8377.021; Mon, 27 Jan 2025 15:51:05 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] mm: further refactor commit_merge() Date: Mon, 27 Jan 2025 15:50:41 +0000 Message-ID: <0bbb2efbdc2ac2af2f6d73679cbb0811544d0647.1737929364.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0426.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a0::30) To MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3374:EE_|SA3PR10MB6949:EE_ X-MS-Office365-Filtering-Correlation-Id: 94d045d5-3b3e-4444-11bc-08dd3eea68be 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: tmLS0eagWC/8n4hLGwUxsxnK5EMLZk/HA+AVXwQPUpdh41PeYKTGPGMGMzPQPO6SOqsMcTCehA3eLSv3puQGk+HV1yU/3e8u5eMSWxHNTAEVEy0DWM29426Jzwu1mcXEjFivKkeF0iONTckJ+g4oZrxN4cbOc+f7GnTETh49xb70UPX32o9uWnm6Pii5NiKheq3Akex1XBCHoRT5k/nMOe4BUeZ9ahDTF0NzVfaPlJ1qmELjl6cwxgoLgp8NdZwffgTO/z9bo85IO6cBdd/jSgLPOqO32OL/T0Te8tNhXA637X9wwXVdACt19X8l0lEWoFlmyPGZcr0UyjWO4x5oSBkzB2BeyR5/Ctx/AdZdNjGvos3n6hhOGPLyX3qptvC1hLgYFTPthQUNc9x5TfDg8By4e+MCTd0wTc51jTB93O+4cOgYwpZoqygZgPhxIYxHYzb5g7ilckAtzHZJYNRUT/7jvWXaBWIt9z8bq0aZJ+nx0kw2Lj9QyRKkIaa7YOBjN/im4bwQxSOCF4jVBzJ+47oBy2/OqEuxtaCh1JPGffq/VfUVg/4sD7c1VRfosGp0xcXR6cdoh2yVOzpHTLGaespzYCSW/xa8fHa1fXszyVsu8h9ut+i2utn0JUfCwPyoZYWSPAbASbtzZn4huaElUS29QNtpt5/NrXoXPf/fSJ9/gJat9JV8n+H1fW35ax8+srKJr7LmLw5ujn3BkHJ2qT9hnl+m+zyozxtzKpuIU2/DeJlnf4n0LBKAKW2I4eBahIbG3I7OPaCGR8vF7simk8l8Ph/dWfJ6q/Rvyo68nl1Vi+g8aw23Cwo77uowfsDKRmh30d2ms/YDB1zKbdKJnGErgcsIZ4AL6W9VCBHlJbiqOQiCgdxkCtBySVPawhH4BFabjiilWP3rMB/9+u0bPGq4Qklt2a6gLn34bjTuNZHcLXQYzCZyqMktNuGUeBo9qlsDCynaWrW4Hy+Bix3dBxoSPsjs4GHSEQIaGkl6yhNL1d0nk0VTz1RQb924fUk3kbvObJ281ONXXrdCaqyzCzE1Z5VODav0AIfbtu8HOnfYe1mOJlLY9+yHcGHvX/hssXAFIrJD+3vqya4KrWHWJIHRBHQvhAYuRoDoCI+hdnZC0tC1XND+OWY3EwcaGFIXUrrijr6lZ2fGiZ+c10ssN+UDwq6hTXFvoBjHja5BV0yPUasq6ZEJC4P3kObUl6+genjfeckGxOouffmFRfAU6Q+nNC/u2i5dGJ+FLkxqUB3XngXOir82p0I6PzOxpb5r+iW1z2Jz0ZjQ64Vy0abt/uLFil3mneftErRVGcflsNEZ0d5/OPShq1YSp2HoHBAbbsRNKiTnfO3nTI07QTQJnR+XVcW8vvuoJX0AoO7YpXiXc16PAiBE57ekNKW5rGiY X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB3374.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: Y2GRUHsaMmiSmCn9DUIrx5PYKtyMW3Su6wkigFoJZQ23OXyvYXh+bkKdOnyzvuPYu34Y6YGFlEo7jWjWf7RGa7nyo2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kcGOGjGynmtoQwhc48lR03POh10Sov/wvvyVfRgB+YBao3QaqLA2LZ3kz8yvyPdYxPn7KnuUc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 94d045d5-3b3e-4444-11bc-08dd3eea68be X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3374.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2025 15:51:05.8284 (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: 7bB5fU0aLhB/y3RLSTc/r355B4Bj7YmzNBFTzo4RkqH3yxOT2q7j8LeyoMOzj6QYm2B4A4oUxw57jPQD21UR+4oQsnqysdkP4SpU5nvvTQo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR10MB6949 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-27_07,2025-01-27_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501270126 X-Proofpoint-GUID: miA__8bdjv4EOrO_16t3WpT8iDY42JOv X-Proofpoint-ORIG-GUID: miA__8bdjv4EOrO_16t3WpT8iDY42JOv X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 44446C0020 X-Stat-Signature: t4ostgcnzrwq5eo34qxtyafzpqx8awsw X-HE-Tag: 1737993071-943979 X-HE-Meta: U2FsdGVkX18BwaPLzBQs+jv2B+tTo2z/jvYeMB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n7fHYk0TIyT1Y4ukB4ErZTzMV15HPan9UhBWyKCRGE0WN+0VIm/GZ9sNxq+uU9jJNDZfQ/f8HT4UcxORml0I+isH5llhYNZTfKyV7EGGyTzmAx8wnPrck/owcpZvP5RnGn7QN3fXB+VXS1sP/Rew6hi4KzdQaPTkZC/cdb/SJAJRTTPFrx4pBoHZlyA6UbCZ4eLuxJc+rA2DzVoxNoPCgAp8IY5vUTTQdLT7PvizWxxIpqBrTfc2qrOK8DGKOhiHNDHOAByG4vN0T/PEtxytNKjmVXmODpmMnBlOM+ZhV2s4QSQ47VXnFKixwBEqCbs1lcsvdxfjuIGz8GoLaWdqF/KgxzbkEiANSfau+s70N1UkmJRy9+SENr7bicRHVcbT/Ln9EvhBWGucQKtzvYz2kA668KmqKRgMN8qAU3/WNJse8A7HIa4OSTarn0iKBfRijMInTd7Xosb4gE1KH8K/FIqKMlIuRFsNpIc= 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 current VMA merge mechanism contains a number of confusing mechanisms around removal of VMAs on merge and the shrinking of the VMA adjacent to vma->target in the case of merges which result in a partial merge with that adjacent VMA. Since we now have a STABLE set of VMAs - prev, middle, next - we are now able to have the caller of commit_merge() explicitly tell us which VMAs need deleting, using newly introduced internal VMA merge flags. Doing so allows us to embed this state within the VMG and remove the confusing remove, remove2 parameters from commit_merge(). We additionally are able to eliminate the highly confusing and misleading 'expanded' parameter - a parameter that in reality refers to whether or not the return VMA is the target one or the one immediately adjacent. We can infer which is the case from whether or not the adj_start parameter is negative. This also allows us to simplify further logic around iterator configuration and VMA iterator stores. Doing so means we can also eliminate the adjust parameter, as we are able to infer which VMA ought to be adjusted from adj_start - a positive value implies we adjust the start of 'middle', a negative one implies we adjust the start of 'next'. We are then able to have commit_merge() explicitly return the target VMA, or NULL on inability to pre-allocate memory. Errors were previously filtered so behaviour does not change. This patch has no change in functional behaviour. Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- mm/vma.c | 83 +++++++++++++++++++++++------------------ mm/vma.h | 10 +++++ tools/testing/vma/vma.c | 3 ++ 3 files changed, 60 insertions(+), 36 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 68a301a76297..955c5ebd5739 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -120,8 +120,8 @@ static void init_multi_vma_prep(struct vma_prepare *vp, memset(vp, 0, sizeof(struct vma_prepare)); vp->vma = vma; vp->anon_vma = vma->anon_vma; - vp->remove = remove; - vp->remove2 = remove2; + vp->remove = remove ? remove : remove2; + vp->remove2 = remove ? remove2 : NULL; vp->adj_next = next; if (!vp->anon_vma && next) vp->anon_vma = next->anon_vma; @@ -129,7 +129,6 @@ static void init_multi_vma_prep(struct vma_prepare *vp, vp->file = vma->vm_file; if (vp->file) vp->mapping = vma->vm_file->f_mapping; - } /* @@ -629,22 +628,40 @@ 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) +/* + * Actually perform the VMA merge operation. + * + * On success, returns the merged VMA. Otherwise returns NULL. + */ +static struct vm_area_struct *commit_merge(struct vma_merge_struct *vmg, + long adj_start) { struct vma_prepare vp; + struct vm_area_struct *remove = NULL; + struct vm_area_struct *remove2 = NULL; + struct vm_area_struct *adjust = NULL; + /* + * In all cases but that of merge right, shrink next, we write + * vmg->target to the maple tree and return this as the merged VMA. + */ + bool merge_target = adj_start >= 0; + + if (vmg->merge_flags & __VMG_FLAG_REMOVE_MIDDLE) + remove = vmg->middle; + if (vmg->merge_flags & __VMG_FLAG_REMOVE_NEXT) + remove2 = vmg->next; + + if (adj_start > 0) + adjust = vmg->middle; + else if (adj_start < 0) + adjust = vmg->next; init_multi_vma_prep(&vp, vmg->target, adjust, remove, remove2); VM_WARN_ON(vp.anon_vma && adjust && adjust->anon_vma && vp.anon_vma != adjust->anon_vma); - if (expanded) { + if (merge_target) { /* Note: vma iterator must be pointing to 'start'. */ vma_iter_config(vmg->vmi, vmg->start, vmg->end); } else { @@ -653,27 +670,26 @@ static int commit_merge(struct vma_merge_struct *vmg, } if (vma_iter_prealloc(vmg->vmi, vmg->target)) - return -ENOMEM; + return NULL; vma_prepare(&vp); vma_adjust_trans_huge(vmg->target, vmg->start, vmg->end, adj_start); vma_set_range(vmg->target, vmg->start, vmg->end, vmg->pgoff); - if (expanded) + if (merge_target) vma_iter_store(vmg->vmi, vmg->target); if (adj_start) { adjust->vm_start += adj_start; adjust->vm_pgoff += PHYS_PFN(adj_start); - if (adj_start < 0) { - WARN_ON(expanded); + + if (!merge_target) vma_iter_store(vmg->vmi, adjust); - } } vma_complete(&vp, vmg->vmi, vmg->target->vm_mm); - return 0; + return merge_target ? vmg->target : vmg->next; } /* We can only remove VMAs when merging if they do not have a close hook. */ @@ -718,7 +734,6 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( 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 = middle && start == middle->vm_start; @@ -727,7 +742,6 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( long adj_start = 0; bool merge_will_delete_middle, merge_will_delete_next; bool merge_left, merge_right, merge_both; - bool expanded; mmap_assert_write_locked(vmg->mm); VM_WARN_ON_VMG(!middle, vmg); /* We are modifying a VMA, so caller must specify. */ @@ -846,10 +860,11 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( vmg->start = prev->vm_start; vmg->pgoff = prev->vm_pgoff; - if (!merge_will_delete_middle) { - adjust = middle; + /* + * We both expand prev and shrink middle. + */ + if (!merge_will_delete_middle) adj_start = vmg->end - middle->vm_start; - } err = dup_anon_vma(prev, middle, &anon_dup); } else { /* merge_right */ @@ -883,7 +898,6 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( vmg->end = start; vmg->pgoff = middle->vm_pgoff; - adjust = next; adj_start = -(middle->vm_end - start); } @@ -893,17 +907,13 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( if (err) goto abort; - /* - * In nearly all cases, we expand vmg->middle. There is one exception - - * merge_right where we partially span the VMA. In this case we shrink - * the end of vmg->middle and adjust the start of vmg->next accordingly. - */ - expanded = !merge_right || merge_will_delete_middle; + if (merge_will_delete_middle) + vmg->merge_flags |= __VMG_FLAG_REMOVE_MIDDLE; + if (merge_will_delete_next) + vmg->merge_flags |= __VMG_FLAG_REMOVE_NEXT; - if (commit_merge(vmg, adjust, - merge_will_delete_middle ? middle : NULL, - merge_will_delete_next ? next : NULL, - adj_start, expanded)) { + res = commit_merge(vmg, adj_start); + if (!res) { if (anon_dup) unlink_anon_vmas(anon_dup); @@ -911,9 +921,7 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( return NULL; } - res = merge_left ? prev : next; khugepaged_enter_vma(res, vmg->flags); - vmg->state = VMA_MERGE_SUCCESS; return res; @@ -1076,7 +1084,10 @@ int vma_expand(struct vma_merge_struct *vmg) middle->vm_end > vmg->end, vmg); vmg->target = middle; - if (commit_merge(vmg, NULL, remove_next ? next : NULL, NULL, 0, true)) + if (remove_next) + vmg->merge_flags |= __VMG_FLAG_REMOVE_NEXT; + + if (!commit_merge(vmg, 0)) goto nomem; return 0; diff --git a/mm/vma.h b/mm/vma.h index 5b5dd07e478c..ffbfefb9a83d 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -67,6 +67,16 @@ enum vma_merge_flags { * at the gap. */ VMG_FLAG_JUST_EXPAND = 1 << 0, + /* + * Internal flag used during the merge operation to indicate we will + * remove vmg->middle. + */ + __VMG_FLAG_REMOVE_MIDDLE = 1 << 1, + /* + * Internal flag used during the merge operationr to indicate we will + * remove vmg->next. + */ + __VMG_FLAG_REMOVE_NEXT = 1 << 2, }; /* diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index 3c0572120e94..8cce67237d86 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -154,6 +154,9 @@ static void vmg_set_range(struct vma_merge_struct *vmg, unsigned long start, vmg->end = end; vmg->pgoff = pgoff; vmg->flags = flags; + + vmg->merge_flags = VMG_FLAG_DEFAULT; + vmg->target = NULL; } /* From patchwork Mon Jan 27 15:50:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13951578 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 1F451C0218A for ; Mon, 27 Jan 2025 15:51:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5A2B280173; Mon, 27 Jan 2025 10:51:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E15A28016F; Mon, 27 Jan 2025 10:51:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 77299280173; Mon, 27 Jan 2025 10:51:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4B36128016F for ; Mon, 27 Jan 2025 10:51:27 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EC376802F7 for ; Mon, 27 Jan 2025 15:51:26 +0000 (UTC) X-FDA: 83053671372.02.1823D9B Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf19.hostedemail.com (Postfix) with ESMTP id 3AE2F1A0007 for ; Mon, 27 Jan 2025 15:51:16 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=V5or2bAp; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="eRa/+cf2"; spf=pass (imf19.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737993077; 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=llckhhPabjSnXQX0pplDVCDofcRfJpYOy2ZcvLXG7Ik=; b=quHOS/hPzg+1H+4sTpVsF2kCc8GpV/LxuGU1Vb8unsAZgfPP07jEME088/pNSlEN8LyW1h cpPoux0Q+hYQ0b8G4QF8Lbgu4ppppRvWFW6tDJuSZjx7xCeWnu3D+qhUz+bmt3IEL9KvpZ Fz9rEWghpcLDzsZQxySXAbMgwARwzN0= ARC-Authentication-Results: i=2; imf19.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=V5or2bAp; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="eRa/+cf2"; spf=pass (imf19.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1737993077; a=rsa-sha256; cv=pass; b=ZYOzlLrucliOwwbnhGElinKs5FNVCLB4myZRpHsWeQjzJ+MhTJeRnJdUOY7XTCU3SQfOJA djDlLTKJIAkQ0V0zXAbxNfkjqOsy0tl+46M/W2+tUNRtkOwuK9whgnt3K8UkQrIV8OSPRi RLZTxijJqSxlvEC1HfIzvkN9oPOby7Q= 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 50RFHK5S009502; Mon, 27 Jan 2025 15:51:13 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=llckhhPabjSnXQX0pplDVCDofcRfJpYOy2ZcvLXG7Ik=; b= V5or2bApcWIzJGvqg8dLefqW7mkDiSyVGztrtH+r4zqTGn9N2PEwxnQIkKx+3YWX Q0zLevHYx9scozsLLibaiGZPO/xsID6aavi+VmOwSTUhrTikG0M5wS1Zhiy/EcCd 2CMZKOVQ+uRzkFXsZ/lCLzjAsimkG6ZddbubrqN7PWo1v0eFnExuRFE12Oiiif4Y 5Yp7g3ngISOHnOGI0IiJ227ye5e4MYl2WiDAMi5UaB6VJO4QcljM53JOZRxope+A rXpf99RfvnUjDFDKKmKgJMdggRuU8Gjv4wQyRAtjfvF1xabkbS4mOkWFdndeaBXk jIxhhCnaW/2wakpB0Lr/Fg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44ecn502mw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Jan 2025 15:51:13 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50RF40N8005314; Mon, 27 Jan 2025 15:51:12 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2044.outbound.protection.outlook.com [104.47.55.44]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 44cpd75t64-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Jan 2025 15:51:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aESO9ZxnMCiQPieAn+V4Onm2B+jlID2w36TcYv6uYeuPEejwGg4GfR8l71QQs6UvuDtc0jtPVsEUsd/DbYnyFpdfhkilfYINGEab22zdw5qc/gaAgbvCuAOvTeBO3Is7MDfcxpEoUWjdgn8sQAuT7vJaETpeog4o7BqNTxB5XaiJz/DeBSsH31JJJd4bDPlPCgybas8Tnd2ehvlfq6zFPDDyaH4XroGb3ldvz0lGpzxLkclWjiho+tpVJWRyuGf3EZqXtqPz8E9VZYaE72e6Gaedy+33C9tuWaqwmG0kgc4dCnxtDolBa5J34cdekH80L6W57wZccWbrwHatpCxlQw== 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=llckhhPabjSnXQX0pplDVCDofcRfJpYOy2ZcvLXG7Ik=; b=HOJ28pIWndJZY9lguhcOG+lXf1bkBdEY/E+D9OWb/ar2r0jWdYEvBpbB7oYzNHIeKj+wp+AxIt+guHBu99679yNS79IQvCzqVISXVi+LtrFBjpQBtF6ocyl/M/2e6VZ9y8xM+Me592R104UgoQiFkz2XPNQgk1jDicpDQOavULQRgJTTwoE0xvQ6L9SFVQ9EJzj3KviU78AOKhPi/kyAb/d/4Z5Py9VzkmXACRoQnABlMYIIEJhmwpCup2m0IwPtUS/6mTQHjcsB99ONMZ2bpZEr5Y6WC5rBJV1snwCZ6Sppwls2C+R/5VGvgxbKtiJOYhyK5ta+7LWl/esZDnF75A== 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=llckhhPabjSnXQX0pplDVCDofcRfJpYOy2ZcvLXG7Ik=; b=eRa/+cf27wdsdFVwdA9paQYGNSofiQH8MX7q03A/aNPU7SmhqiH2+0nHNZw6cWcgxN/d34K5pQrWd1QmIvNkNfGGjJ6ChfD4/0zvRLAqjZ1KWUpSx3lsQ/DAa4a6vOv2AGWX6NNSDADjW7H62r1BAG41Uujd+mV+AOp4ympCRBQ= Received: from MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) by PH8PR10MB6339.namprd10.prod.outlook.com (2603:10b6:510:1ce::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.19; Mon, 27 Jan 2025 15:51:09 +0000 Received: from MN2PR10MB3374.namprd10.prod.outlook.com ([fe80::eab5:3c8c:1b35:4348]) by MN2PR10MB3374.namprd10.prod.outlook.com ([fe80::eab5:3c8c:1b35:4348%3]) with mapi id 15.20.8377.021; Mon, 27 Jan 2025 15:51:09 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/5] mm: eliminate adj_start parameter from commit_merge() Date: Mon, 27 Jan 2025 15:50:42 +0000 Message-ID: <335ff27920d96c2a45b9724725cd3be2caf987b1.1737929364.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0013.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:150::18) To MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3374:EE_|PH8PR10MB6339:EE_ X-MS-Office365-Filtering-Correlation-Id: baeaa560-0d5c-44e4-9d41-08dd3eea6ad0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: VVdmKMtZkt1wfSNJQvD55OJhwyzN/VrfJbaib50pTxmMHNWySuHA3DYknMlRXEOHhW536CcxshvFOdL+HC8oFH5wdyxMX0+Zd4nYjmrR67TAxdJLWHwb53cKyAJIOIhoKX7LgN3dOheZyLoj/kc47YHNS+w7pO90TIPjp3iUucLO3B3tZk5HQ2zXiwDmHN/ynq1dfjrJhooPY+pDYdLBxtJ/gbF1jjjAqaW+IkHA+kKmvXjjep6zKQtp1hz6DD5Sp9ExBN/qedtHrBOB6Z1Dkg98kM6xg8Pk3WcQZkYftqqnEX15h0NzCPLtOhgkt22pUq7HqE/nC4ed69dr1OZS48Q9VYerHIIfr2PWaSxA7FdDTOuWQBxCgX/wamtDvNCIqor04lqmc0OquwS5pSsf1KdpBYk1GfNsvn19Iltk2KIqA5dFfR5h9YS9PAS+CukNiyUcmZYiqD7oqXlDtK7cv5rMJmIAwaK/+5/0t/AShHVpXQ/rMjLI57w6oE6cgHtAnxFhRAtKd/7sVZxooVO55k5Rf0XuVe1TuYyTOlPtXvXWu9Vzt2WFis704bPc4C/qWC5FbFmEII8xa6c4aBzqbfgRu2C5YqZEp3WswicvA0NS1ziLaSkL4PiC3dIA7FXj7k6jdCRNs6wnUVivvQ2EeiS/ITif/exADhwofisT+odlWfZ8jo0x1Gzs9kTLDleeBR5R8NNaBdDjeieILM1TrgpM3Hx34PjixrgsgIDYmUecb/8DXGozj32R+8IarZzewSJN4hjSrcMMTUSYPmfyBNgZDEJ0331xLO0XvpucKxGIpwQnnqOGzF+wVZfHaZhMZTes4MP0owxI4jzFWYDi2wdI0FSEZ7zRw8H+pnqXrW0mswJ0fF/smvxCmxpz3fBYYytrY2FnsvDUwsc04SHgmPGajP0yolB8+c/u6ilCqx9w2RDicqB102yOjxqm4huXPJwHwGTyYTvkVAsTWZN3prVhYpZl3asOnZZ8KkMbcte91Wf4Eoqe/6nM+Ved5PdyH1VaSndT/kM0aUWutlvRt7a5ELb0cpsnirFi0T14geQ0KAEm0DvsvSdsK61gPHDH3IKlXCQXUylrD4IBoecpFB3IjtuKQEN0FrQDsnyV/rLyiYzjFnXVQFe7Eh8KuwNm7GCs9/CxuMmDA3amtlZCpFV+t7BWqRahagtnlB0yRQ9W9uO3zqqTTAVpSAj13iWkpSTMLqepzVLtAHCQgf4dvszuftRS/okJzTo1Yltoa481lVoy2kE2GLgfk6BRLSEDHGW3VW3FN0m16mBjaJmeHlnbuxFlAaqfoylxsh90j704P4unXZYbTd0zh/HUm3vCBpSwJK7PobT2d7JOP3j4WKqaICXRH/NhhJax9umPjdTyYoB36fxVjAlVuoZGb/BM X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB3374.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: anH3BaX95n+YunZyOJLTS13rK9RN4iwiAlarRsthWjLTnhKfCeUUKcDrXyoyqcse7/swVHyr1JRSTln/wlXbo77nPyNKqEZ5sqEVR+edl8qYCEGgbvpS7r5B0WhRKV9EZrXeB72AFBa+rOg2Jo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QTWBRp7BL4m3zPL1lkT7zgzxg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: baeaa560-0d5c-44e4-9d41-08dd3eea6ad0 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3374.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2025 15:51:09.2992 (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: 5/gv3Eui7FGlaFoZuUuFBYwBBOLNvCYYYQ9sLZz+HfNaq1aBxH6Oh9voHtSJgGXBBwBiE0enNm2Jx4lq0xDc2LbRhGrQ3Pc6KKZ+X5p7+Ew= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR10MB6339 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-27_07,2025-01-27_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 mlxscore=0 adultscore=0 malwarescore=0 spamscore=0 bulkscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501270126 X-Proofpoint-ORIG-GUID: sFFNWuC20WDiGL3ev0qE1q22MbGcreLF X-Proofpoint-GUID: sFFNWuC20WDiGL3ev0qE1q22MbGcreLF X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 3AE2F1A0007 X-Stat-Signature: nd56xrexa1rbrof7y9kip7s1963zjnw3 X-HE-Tag: 1737993076-256613 X-HE-Meta: U2FsdGVkX1++qebDFHRMhDI5iKW0O9bOg88zdJytdrIrMrD8Fa4o0eE+aBafrmPHJBV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Im288spFkTiCh83yXiMMTmSGsBlpmoY48R+QwA0s6A1C4aplw9RXurg3uGX1X9LvunnsfJKGsC368MlkJpOPtrtVX759m33cwIP59BKllMPMwngAT5x3IvR1+p4KPk9IaNiuvlJobv7rcucrBIa1ThSUZ4f5pH2GduuEzwI3VuqXIuBU1k4sHkSn8IB+L3cdk0Y9+vyy5LzCYOKyKGZ7kz6cn7RwtpbHpYl4KEdS+wknXWn4dodmLZlpu4/sCCFRSY8F2YPPuwKIbLacf3ahJ6w7Xyc4bNQppf9xkPA58SLgX5QEveaNcVb7o+QVbhqPdhXls54nkCGkTBBZQZP8+cIWWjkqNsPpYPQV3c3ZHscQlPpL6hO6OsPQYvzKHeFgldS1nSxbFp7Slz09iSi+ED9Hbzm9IrMlqW5FXJyHq/97iRO+5ajwC/RA9jqNyndJGJEyUvDtgGQ= 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: Introduce internal __VMG_FLAG_ADJUST_MIDDLE_START and __VMG_FLAG_ADJUST_NEXT_START merge flags, enabling us to indicate to commit_merge() that we are performing a merge which either spans only part of vmg->middle, or part of vmg->next respectively. In the former instance, we change the start of vmg->middle to match the attributes of vmg->prev, without spanning all of vmg->middle. This implies that vmg->prev->vm_end and vmg->middle->vm_start are both increased to form the new merged VMA (vmg->prev) and the new subsequent VMA (vmg->middle). In the latter case, we change the end of vmg->middle to match the attributes of vmg->next, without spanning all of vmg->next. This implies that vmg->middle->vm_end and vmg->next->vm_start are both decreased to form the new merged VMA (vmg->next) and the new prior VMA (vmg->middle). Since we now have a stable set of prev, middle, next VMAs threaded through vmg and with these flags set know what is happening, we can perform the calculation in commit_merge() instead. This allows us to drop the confusing adj_start parameter and instead pass semantic information to commit_merge(). In the latter case the -(middle->vm_end - start) calculation becomes -(middle->vm-end - vmg->end), however this is correct as vmg->end is set to the start parameter. This is because in this case (rather confusingly), we manipulate vmg->middle, but ultimately return vmg->next, whose range will be correctly specified. At this point vmg->start, end is the new range for the prior VMA rather than the merged one. This patch has no change in functional behaviour. Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- mm/vma.c | 53 ++++++++++++++++++++++++++++++++--------------------- mm/vma.h | 14 ++++++++++++-- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 955c5ebd5739..e78d65de734b 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -633,29 +633,45 @@ void validate_mm(struct mm_struct *mm) * * On success, returns the merged VMA. Otherwise returns NULL. */ -static struct vm_area_struct *commit_merge(struct vma_merge_struct *vmg, - long adj_start) +static struct vm_area_struct *commit_merge(struct vma_merge_struct *vmg) { - struct vma_prepare vp; struct vm_area_struct *remove = NULL; struct vm_area_struct *remove2 = NULL; + unsigned long flags = vmg->merge_flags; + struct vma_prepare vp; struct vm_area_struct *adjust = NULL; + long adj_start; + bool merge_target; + /* - * In all cases but that of merge right, shrink next, we write - * vmg->target to the maple tree and return this as the merged VMA. + * If modifying an existing VMA and we don't remove vmg->middle, then we + * shrink the adjacent VMA. */ - bool merge_target = adj_start >= 0; + if (flags & __VMG_FLAG_ADJUST_MIDDLE_START) { + adjust = vmg->middle; + /* The POSITIVE value by which we offset vmg->middle->vm_start. */ + adj_start = vmg->end - vmg->middle->vm_start; + merge_target = true; + } else if (flags & __VMG_FLAG_ADJUST_NEXT_START) { + adjust = vmg->next; + /* The NEGATIVE value by which we offset vmg->next->vm_start. */ + adj_start = -(vmg->middle->vm_end - vmg->end); + /* + * In all cases but this - merge right, shrink next - we write + * vmg->target to the maple tree and return this as the merged VMA. + */ + merge_target = false; + } else { + adjust = NULL; + adj_start = 0; + merge_target = true; + } - if (vmg->merge_flags & __VMG_FLAG_REMOVE_MIDDLE) + if (flags & __VMG_FLAG_REMOVE_MIDDLE) remove = vmg->middle; if (vmg->merge_flags & __VMG_FLAG_REMOVE_NEXT) remove2 = vmg->next; - if (adj_start > 0) - adjust = vmg->middle; - else if (adj_start < 0) - adjust = vmg->next; - init_multi_vma_prep(&vp, vmg->target, adjust, remove, remove2); VM_WARN_ON(vp.anon_vma && adjust && adjust->anon_vma && @@ -739,7 +755,6 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( bool left_side = middle && start == middle->vm_start; bool right_side = middle && end == middle->vm_end; int err = 0; - long adj_start = 0; bool merge_will_delete_middle, merge_will_delete_next; bool merge_left, merge_right, merge_both; @@ -860,11 +875,8 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( vmg->start = prev->vm_start; vmg->pgoff = prev->vm_pgoff; - /* - * We both expand prev and shrink middle. - */ if (!merge_will_delete_middle) - adj_start = vmg->end - middle->vm_start; + vmg->merge_flags |= __VMG_FLAG_ADJUST_MIDDLE_START; err = dup_anon_vma(prev, middle, &anon_dup); } else { /* merge_right */ @@ -893,12 +905,11 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( * IMPORTANT: This is the ONLY case where the final * merged VMA is NOT vmg->target, but rather vmg->next. */ + vmg->merge_flags |= __VMG_FLAG_ADJUST_NEXT_START; vmg->target = middle; vmg->start = middle->vm_start; vmg->end = start; vmg->pgoff = middle->vm_pgoff; - - adj_start = -(middle->vm_end - start); } err = dup_anon_vma(next, middle, &anon_dup); @@ -912,7 +923,7 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( if (merge_will_delete_next) vmg->merge_flags |= __VMG_FLAG_REMOVE_NEXT; - res = commit_merge(vmg, adj_start); + res = commit_merge(vmg); if (!res) { if (anon_dup) unlink_anon_vmas(anon_dup); @@ -1087,7 +1098,7 @@ int vma_expand(struct vma_merge_struct *vmg) if (remove_next) vmg->merge_flags |= __VMG_FLAG_REMOVE_NEXT; - if (!commit_merge(vmg, 0)) + if (!commit_merge(vmg)) goto nomem; return 0; diff --git a/mm/vma.h b/mm/vma.h index ffbfefb9a83d..ddf567359880 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -67,16 +67,26 @@ enum vma_merge_flags { * at the gap. */ VMG_FLAG_JUST_EXPAND = 1 << 0, + /* + * Internal flag indicating the merge increases vmg->middle->vm_start + * (and thereby, vmg->prev->vm_end). + */ + __VMG_FLAG_ADJUST_MIDDLE_START = 1 << 1, + /* + * Internal flag indicating the merge decreases vmg->next->vm_start + * (and thereby, vmg->middle->vm_end). + */ + __VMG_FLAG_ADJUST_NEXT_START = 1 << 2, /* * Internal flag used during the merge operation to indicate we will * remove vmg->middle. */ - __VMG_FLAG_REMOVE_MIDDLE = 1 << 1, + __VMG_FLAG_REMOVE_MIDDLE = 1 << 3, /* * Internal flag used during the merge operationr to indicate we will * remove vmg->next. */ - __VMG_FLAG_REMOVE_NEXT = 1 << 2, + __VMG_FLAG_REMOVE_NEXT = 1 << 4, }; /* From patchwork Mon Jan 27 15:50:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13951577 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 0DE9CC0218C for ; Mon, 27 Jan 2025 15:51:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13190280171; Mon, 27 Jan 2025 10:51:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0BB2E28016F; Mon, 27 Jan 2025 10:51:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1A62280173; Mon, 27 Jan 2025 10:51:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3E94828016F for ; Mon, 27 Jan 2025 10:51:22 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7C94B802F4 for ; Mon, 27 Jan 2025 15:51:21 +0000 (UTC) X-FDA: 83053671162.03.B0B8149 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf11.hostedemail.com (Postfix) with ESMTP id 2CCB840009 for ; Mon, 27 Jan 2025 15:51:18 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=mI4FqxgK; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=GpEd4AR3; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf11.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1737993078; a=rsa-sha256; cv=pass; b=yjr27DS9JbL8WIRZ6l21X1u/K6cIa+Un9HPm7BV/DiGKC7Jh686Sy78/zPuglTtIcITqQx kY3VwvwglvEO3hmkkcVpzVhZJCw+PKwBZHqFvm7zPK+oLRJfIPew5CLh+kJOWgiXWW+toa iihM+Ywck32M/ED1ldElLE9D1aVw0o0= ARC-Authentication-Results: i=2; imf11.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=mI4FqxgK; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=GpEd4AR3; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf11.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1737993078; 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=yYt6stsxYImVpnilc4jHtHIA4DfFcWVogY7BkE17NV4=; b=DA7/b5D/2nVgXMbGas2jWAEuXv/0cHGslBk1lG4/paD4ZOXYk68EzOV6L6Myx9crbO0Az8 OFyCH4tHOm6FGESf9MP7E7hDRqpk4x0cIs+W1H/RthcwJdJ7CXP669vl1UZCFXxzbajBeB rb4jAlXgeMHUFFsUJ0gs5fayzYlf2d8= 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 50RFVhVg028428; Mon, 27 Jan 2025 15:51:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=yYt6stsxYImVpnilc4jHtHIA4DfFcWVogY7BkE17NV4=; b= mI4FqxgK8Hsd2uLXcvK1Bn2K5tmAmBmGTTgoqBaB38ZWnFY+6sCbnkygPzkzYv0G /bjcRNnOETiUm3pkQug0wtLV7O5LkYZouN0iDSR/zKt0qjj3zpgFvoRUMJKv/Ry+ 6/ImzzvxFcPUJYrCQDuwsiabqGxSyQigK/ZSZvVk9GQFppo8Y9GtP9ePlTc2SVxU OnIUoPw0SqcYlge/596Ef0GklcZl6z7ojkIbtai/JjTFWgycB1XbMJOB/iWM3Y8e 7Z4bcR6HwQyXXcHSKLZ9RBSlEU5K/xDfoB6cyFbKjDShT+C3SuMBsOCSIefJFCQc tm9HSIVsKIk3/LPCRgi7yQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44ecv581ku-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Jan 2025 15:51:16 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50REwTt2035833; Mon, 27 Jan 2025 15:51:15 GMT Received: from nam02-bn1-obe.outbound.protection.outlook.com (mail-bn1nam02lp2040.outbound.protection.outlook.com [104.47.51.40]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 44cpdd4vuq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Jan 2025 15:51:15 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=nwOeG5lpoPaN+h0wcsD5wRN7eY99SW9EJVWfkiJxytsNEy82ogvpkNYn5W8V38R+Nx8pee+qgnHsyhqU7dgtzpID2snRZ9GBWMs1skY1tBD2wrDRJ34X3fT++Iggs3rtH9fPlM7QW3x1XOItOjvoxqgHtNelmxCFIviv1HB9zsgCW6FGE1VBEX/afywS8FYjoJpb+K0SX+uknIPd2v09dNwBZxt3sfffuIFT02Dq6fCxNQxRbhICMv/9HrBtAkOX8G05C474nvuM8YjEMfBf2qCQkujpQV3yhEwU2xCHKepdDaohyNX0zY2K5p/swdpbD0E62IPAvbPpCjA/LGbA/g== 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=yYt6stsxYImVpnilc4jHtHIA4DfFcWVogY7BkE17NV4=; b=bSPu5FLk5KEZGruOFsYjhY1qIWX1xwA7S/J54UE6jU/Zmz60O68QmQS6bPPYCLwywCZYd0H5qJVjkArg9YaWB06W95oziUZhdjxSRY3CKB1Ert0T+JfABCY/jVzvlZ874VZkQi5VSgbm4yUTT4lDEeK83jRm1aVC4eQFP3lbtb41jp/epX5Ie83OlfQwvyYsQy0ZDTVowU0zhSpFoB2jpuHtSoJAWJcDrX8PslWmcWK/8dBFYH7ZmolKPHFZGjOOUCMnvAlQa1gbT1kQU1VHa1Tn+XYlPlDn3KKO01G8Cx63KiCLKvQeEr+hI934+myXPONILoQghpwlUKocX9sRaw== 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=yYt6stsxYImVpnilc4jHtHIA4DfFcWVogY7BkE17NV4=; b=GpEd4AR38CrNFs6/q3zGc223idN8cwrlEfBbOJJLd8CU/Hu8mOzNMfMGlSfLGDM4pYLuf3WtyhPNiHdAhDxkct9S2BDh6ndy4fAOy8cPBeA8lJ2iZGpgNF32ivn4SSJomVaqTNwODGO1RFEUiVYjbvNZLC7EA7pwMd4UNT/3cNU= Received: from MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) by PH8PR10MB6339.namprd10.prod.outlook.com (2603:10b6:510:1ce::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.19; Mon, 27 Jan 2025 15:51:12 +0000 Received: from MN2PR10MB3374.namprd10.prod.outlook.com ([fe80::eab5:3c8c:1b35:4348]) by MN2PR10MB3374.namprd10.prod.outlook.com ([fe80::eab5:3c8c:1b35:4348%3]) with mapi id 15.20.8377.021; Mon, 27 Jan 2025 15:51:12 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/5] mm: make vmg->target consistent and further simplify commit_merge() Date: Mon, 27 Jan 2025 15:50:43 +0000 Message-ID: <829048d075d18dd34572f330d17af66b8cff8441.1737929364.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: References: X-ClientProxiedBy: LO4P265CA0191.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:311::19) To MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3374:EE_|PH8PR10MB6339:EE_ X-MS-Office365-Filtering-Correlation-Id: ba52fbe6-036b-46d4-f849-08dd3eea6ccc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: wBs+8UhJaPIdRHU8PXpirdLxcrXBapCmrhu1f8yCfliuheFIDsvvqnb76ZLNUxO5uaWHnWGyS4/LnC5vdY0XN05zFrXpMM3/00DXr5T4YXegKl7Vd+7q7a0eGlzdPpZ2KDefOoe3elbYMuy08GZatMww53amZjs4gbo9I7w4LxioBLVCgcYD82uYKcGydvWq67p2ZjHlDGaFMDlbbuIhk6aKJN5iMg3xWaS9o7MseRfhYf0EVja1C3JT+3vLRphk3XAvTNbwR9ZQ4lHnBB6NvkK6J1IbjtN1RUNkrRndewfD1Ddb8qep4imJglF8I8XcVWAEkaoYAJ0+IKkaYq0KehM9skjqSTl4n10Ouv0hYoBwN5MNd+4Lu8hFLBiPbPBxLj7QllzVnZSUPmlmAqubAWtYztWLBILfZtp76/e4xdpiLgPEAeRT0VO7BRGXFyhKd0gxN2ff2kxP/dJ5iEmG4LdSZ/osqLtDyVALfspXPSIRU1CACAoc1P3V3+zgUt5jpiUZPlt4tsPDsYqaxj9USQoMfSwhvYkfUF0P79cvm+mpKnOs06RD0Z9gvJvcQJMkrN/VhLwUnhOj0Erp5TeFnceQfR4yPKC/BopN4DoSY7rMoISVOf0sAFqm1GNoLaW7lxRNdecew7/cI/kH/KzNjcRvg78T+4gMZrixz2KTh3FVtvEJSkPAcdmgaW/br3i5KW3aa7w/QLSiZplKMibjmohwVObcJCNTuPpVFuOOrYhWFuKCyW4h8mPyryR1F4ToO/eZ218GtTWE20wly/ZqMj77AE3rA4w/c1CRmhUo7L/cNUKUcBbdHcBiDs9GqQ40Qb8VkMb5v384b2nUrb63nWi5aa1vJGTBiloC5gasRKHaDo07xpPR0trppz4PD1CAaO7jND+P2IQinwNclMBs7YZ/8W516saHWqz0GJGVaUpNg57Mfbw5V6XtPBUspC0vlmP55GAECum2M9uV8AiNQiOdyErmIUOeTi4RtTItei1JGp7d5MX2Hb348GySLOdCvizJnI7eZM1b1GLW6QSy8K9apzCcQzNn+a2ht2h3wVjOyvF7vTOfTAPE4rj1ctEgoYYdwvmOalXIIXg9DL+CWyk9eC23x7xnMTtZIS7pxN3gD2BPL2jpJCBPoIR/xgPX2sbhW6qSZA6Yf4hJchjz4pjvDwSDku/2d7Dr/DL64sQIIVAlsc4+lCdZ3253dlrgP40fY8WZIJaY928VCZQjxnDcYPF2anCA7qbk8qxV7t1V/qZ0Yuh73g8IPv0Gic8OK6KyKCRaobeGCZdftu9QI45RHiy3lraLGrPCdJWDRhR/dYuvGzZGOEov4LJm+GlQVZehz8/ZM1ovTpBcmsgChfuRW0Rd8wbR1VYk4Dnojq6+2EFT6GGAi5K41NJS67R2 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB3374.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-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+Ut6fwQGG5/H+UCTdN8DNWYgTc3UmcsJyoHWlRG7EqEki45uuehdwWdyxiv/X4rr8pnOIvGGfT7CIP3dVFgZprB7qdvYu1zUJUQGY7qiw65DibEeAupz9BRiSSve+GfX3H98vkTh1CibexsMBdWUOIymFgFde+AFR9m1kpz3C/LG1CZoj1/X7AvYTNYgOwzKL8oC+vHBm8CRPSzUSxo= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ba52fbe6-036b-46d4-f849-08dd3eea6ccc X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3374.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2025 15:51:12.6898 (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: FG2fWeUhD7OGjQnjT8lkdFrEpkHqt78tAn+gRIlaHSDm1YiKrfUJGG2uLOu4+FkYsH9TYeXukRIiq3N5sGPrc1abxv6nxc/lNksTg/d6D+U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR10MB6339 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-27_07,2025-01-27_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 bulkscore=0 phishscore=0 suspectscore=0 adultscore=0 spamscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501270126 X-Proofpoint-ORIG-GUID: nmxaFjJfenhCpPO_-RXR807U4uOcaFYX X-Proofpoint-GUID: nmxaFjJfenhCpPO_-RXR807U4uOcaFYX X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2CCB840009 X-Stat-Signature: gam8qr99xttg6o8e77duipqscp6afpc6 X-HE-Tag: 1737993078-972383 X-HE-Meta: U2FsdGVkX18G8Bl3fLDLtERSDONcrzyRKn9KYVd6AM3vyeLleFToYI9UTIau/wZx2oT/8IidSpqhGNA81A+hjZHwv5Z38v5MxJtf0bT00oR1iqUz3gnzqnkGw4GPRtCBQhQ4asI4ylYnte2t+Vg4yVSHtskFKGRnYbVq9Wes6oWSt4av6eA/9nNdquoiHnHTBdWkv/JtEysBsACqB29lLtmZ+a0Y3vWyzIFr06wclbltO4KKRJrj0M0Dq/6rEGdmyVSm70l3BI1BPcHE1Y5HUj1f8wZ6RRdBwT4vMrIElMyO71Mh3evjmeZHoU7tYbNZvAL9DNYGnO54dSmmm9OFNODELWlxF0wz6VMTaBOnejsqeUWCa1zdMC8BZgKwp5CjkH7ySuW7KVGwDHrFo5ndLWp8N92G/XCt5LluZg3ErApbh0qOmJIXuGL9x4sbR/InfXbcTK/G5tuUibPB/mHhfkdw4jJ355gKMac2AyJB7MLdqLsJa6itR40s8GbdyudmVCn4QMrt2Bvjzz6cyT3JbUBt5COK+qiGXS9NIQW5zvHQhTUzKQHQszbU5A3zwx5e9sKKCvzdJjSnfES89RHJK5AFU6zGGCj4+TGL+MX4qK7ViWKnF330RqF5cD0JbklQamWfHELfwPYiVsls6UdJdn81FE+g7buW4pGEe2zM3w5tLD/4hjw3VOW3HblABTdPgbOJ14M40KCcCMuY60XaT5g9xJREAvveBPjdtsC17OD/jXMbSl4s+FbyTW3cInXB8eFQcAeVXl3uhmWiK36uSX+lDMP3JhAG1awkaOq77E75U+U/N+RHSyLFY04//cX/oUU2yyi4MSas9o3syShF/oCPF8wwnOfFvJOZaoyNBeyxZQipWQiUMkoL9/mmGNHKw2iGndKsFkG9Pit++95SN2U443mWGB+mNx8OaFq99AdsxWIWqDkOdZBbdm5Mor65fQd2vR0cPke3jR6B1PY jjyv7Svn l94MvxGtAYUdNSMQ0grKmSqOengW1Ev+QksjSsbT8vRPlFmOytm1nJNaFwRbLkhe81oh5UJvJ/qiU09aGH6VCupB5RxlJK67NgchbQwmH0cUm6wuQku9cGB4Hz0qs5qE1AcKBT+V6ELm/JXtRh1e232fQ19IOAw2eedisdJyRyCYR2KVtKVmNNV7/fp34FanGYTd7HUT8RFdm9eFMO6mUkHDKL46VhjI2Z2PvZeMF/1Zm4rU3uMcG9zjQH94kBx5k3BHz6p+DbN9G7wX0KiI9i2lKvGFo9I8Xi8jEqYVzIZbe9mWVvD/3vJL13sWtirTdgkGtHLfN+4J8wrKOpHdlp+9321pGvUIIFQTzOIxpkVlFPGLBgJUT1VpfGkH1cQphh0poXgd9056TqKwGhAlHAwcHkVnXTj3vJzq/lzmXimlw8Ie1Y1y8wichTkSbndb694MWpRajh26BplL+N4whbhfcgJU8Aek1ndpb/mHnYFzpCCuUzWFtR3sx4YmHE+Zen+yhSOLKrxr+dJcG4uk1TNt1YeXDyyHLA4zTUzsSkW8vZ7KJpccPagqeKkNYEqILogztDkea3fLfp3LqYFYqiW4dS9YOOONfRNB8iFRTC6rEsm8= 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: It is confusing for vmg->target to sometimes be the target merged VMA and in one case not. Fix this by having commit_merge() use its awareness of the __VMG_FLAG_ADJUST_NEXT_START case to know that it is manipulating a separate vma, abstracted in the 'vma' local variable. Place removal and adjust VMA determination logic into init_multi_vma_prep(), as the flags give us enough information to do so, and since this is the function that sets up the vma_prepare struct it makes sense to do so here. Doing this significantly simplifies commit_merge(), allowing us to eliminate the 'merge_target' handling, initialise the VMA iterator in a more sensible place and simply return vmg->target consistently. This also allows us to simplify setting vmg->target in vma_merge_existing_range() since we are then left only with two cases - merge left (or both) where the target is vmg->prev or merge right in which the target is vmg->next. This makes it easy for somebody reading the code to know what VMA will actually be the one returned and merged into and removes a great deal of the confusing 'adjust' nonsense. This patch has no change in functional behaviour. Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- mm/vma.c | 122 ++++++++++++++++++++++++++++--------------------------- mm/vma.h | 6 +-- 2 files changed, 64 insertions(+), 64 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index e78d65de734b..cfcadca7b116 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -107,24 +107,41 @@ static inline bool are_anon_vmas_compatible(struct vm_area_struct *vma1, * init_multi_vma_prep() - Initializer for struct vma_prepare * @vp: The vma_prepare struct * @vma: The vma that will be altered once locked - * @next: The next vma if it is to be adjusted - * @remove: The first vma to be removed - * @remove2: The second vma to be removed + * @vmg: The merge state that will be used to determine adjustment and VMA + * removal. */ static void init_multi_vma_prep(struct vma_prepare *vp, struct vm_area_struct *vma, - struct vm_area_struct *next, - struct vm_area_struct *remove, - struct vm_area_struct *remove2) + struct vma_merge_struct *vmg) { + struct vm_area_struct *adjust; + struct vm_area_struct **remove = &vp->remove; + unsigned long flags = vmg ? vmg->merge_flags : 0; + memset(vp, 0, sizeof(struct vma_prepare)); vp->vma = vma; vp->anon_vma = vma->anon_vma; - vp->remove = remove ? remove : remove2; - vp->remove2 = remove ? remove2 : NULL; - vp->adj_next = next; - if (!vp->anon_vma && next) - vp->anon_vma = next->anon_vma; + + if (flags & __VMG_FLAG_REMOVE_MIDDLE) { + *remove = vmg->middle; + remove = &vp->remove2; + } + if (flags & __VMG_FLAG_REMOVE_NEXT) + *remove = vmg->next; + + if (flags & __VMG_FLAG_ADJUST_MIDDLE_START) + adjust = vmg->middle; + else if (flags & __VMG_FLAG_ADJUST_NEXT_START) + adjust = vmg->next; + else + adjust = NULL; + + vp->adj_next = adjust; + if (!vp->anon_vma && adjust) + vp->anon_vma = adjust->anon_vma; + + VM_WARN_ON(vp->anon_vma && adjust && adjust->anon_vma && + vp->anon_vma != adjust->anon_vma); vp->file = vma->vm_file; if (vp->file) @@ -361,7 +378,7 @@ static void vma_complete(struct vma_prepare *vp, struct vma_iterator *vmi, */ static void init_vma_prep(struct vma_prepare *vp, struct vm_area_struct *vma) { - init_multi_vma_prep(vp, vma, NULL, NULL, NULL); + init_multi_vma_prep(vp, vma, NULL); } /* @@ -635,77 +652,64 @@ void validate_mm(struct mm_struct *mm) */ static struct vm_area_struct *commit_merge(struct vma_merge_struct *vmg) { - struct vm_area_struct *remove = NULL; - struct vm_area_struct *remove2 = NULL; - unsigned long flags = vmg->merge_flags; + struct vm_area_struct *vma; struct vma_prepare vp; - struct vm_area_struct *adjust = NULL; + struct vm_area_struct *adjust; long adj_start; - bool merge_target; + unsigned long flags = vmg->merge_flags; /* * If modifying an existing VMA and we don't remove vmg->middle, then we * shrink the adjacent VMA. */ if (flags & __VMG_FLAG_ADJUST_MIDDLE_START) { + vma = vmg->target; adjust = vmg->middle; /* The POSITIVE value by which we offset vmg->middle->vm_start. */ adj_start = vmg->end - vmg->middle->vm_start; - merge_target = true; + + /* Note: vma iterator must be pointing to 'start'. */ + vma_iter_config(vmg->vmi, vmg->start, vmg->end); } else if (flags & __VMG_FLAG_ADJUST_NEXT_START) { + /* + * In this case alone, the VMA we manipulate is vmg->middle, but + * we ultimately return vmg->next. + */ + vma = vmg->middle; adjust = vmg->next; /* The NEGATIVE value by which we offset vmg->next->vm_start. */ adj_start = -(vmg->middle->vm_end - vmg->end); - /* - * In all cases but this - merge right, shrink next - we write - * vmg->target to the maple tree and return this as the merged VMA. - */ - merge_target = false; + + vma_iter_config(vmg->vmi, vmg->next->vm_start + adj_start, + vmg->next->vm_end); } else { + vma = vmg->target; adjust = NULL; adj_start = 0; - merge_target = true; - } - - if (flags & __VMG_FLAG_REMOVE_MIDDLE) - remove = vmg->middle; - if (vmg->merge_flags & __VMG_FLAG_REMOVE_NEXT) - remove2 = vmg->next; - - init_multi_vma_prep(&vp, vmg->target, adjust, remove, remove2); - - VM_WARN_ON(vp.anon_vma && adjust && adjust->anon_vma && - vp.anon_vma != adjust->anon_vma); - if (merge_target) { - /* Note: vma iterator must be pointing to 'start'. */ + /* Note: vma iterator must be pointing to 'start'. */ vma_iter_config(vmg->vmi, vmg->start, vmg->end); - } else { - vma_iter_config(vmg->vmi, adjust->vm_start + adj_start, - adjust->vm_end); } - if (vma_iter_prealloc(vmg->vmi, vmg->target)) + init_multi_vma_prep(&vp, vma, vmg); + + if (vma_iter_prealloc(vmg->vmi, vma)) return NULL; vma_prepare(&vp); - vma_adjust_trans_huge(vmg->target, vmg->start, vmg->end, adj_start); - vma_set_range(vmg->target, vmg->start, vmg->end, vmg->pgoff); - - if (merge_target) - vma_iter_store(vmg->vmi, vmg->target); + vma_adjust_trans_huge(vma, vmg->start, vmg->end, adj_start); + vma_set_range(vma, vmg->start, vmg->end, vmg->pgoff); if (adj_start) { adjust->vm_start += adj_start; adjust->vm_pgoff += PHYS_PFN(adj_start); - - if (!merge_target) - vma_iter_store(vmg->vmi, adjust); } - vma_complete(&vp, vmg->vmi, vmg->target->vm_mm); + vma_iter_store(vmg->vmi, vmg->target); + + vma_complete(&vp, vmg->vmi, vma->vm_mm); - return merge_target ? vmg->target : vmg->next; + return vmg->target; } /* We can only remove VMAs when merging if they do not have a close hook. */ @@ -836,11 +840,15 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( /* No matter what happens, we will be adjusting middle. */ vma_start_write(middle); - if (merge_left) - vma_start_write(prev); - - if (merge_right) + if (merge_right) { vma_start_write(next); + vmg->target = next; + } + + if (merge_left) { + vma_start_write(prev); + vmg->target = prev; + } if (merge_both) { /* @@ -850,7 +858,6 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( * extend delete delete */ - vmg->target = prev; vmg->start = prev->vm_start; vmg->end = next->vm_end; vmg->pgoff = prev->vm_pgoff; @@ -871,7 +878,6 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( * extend shrink/delete */ - vmg->target = prev; vmg->start = prev->vm_start; vmg->pgoff = prev->vm_pgoff; @@ -895,7 +901,6 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( VM_WARN_ON_VMG(vmg->start > middle->vm_start && prev && middle != prev, vmg); if (merge_will_delete_middle) { - vmg->target = next; vmg->end = next->vm_end; vmg->pgoff = next->vm_pgoff - pglen; } else { @@ -906,7 +911,6 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( * merged VMA is NOT vmg->target, but rather vmg->next. */ vmg->merge_flags |= __VMG_FLAG_ADJUST_NEXT_START; - vmg->target = middle; vmg->start = middle->vm_start; vmg->end = start; vmg->pgoff = middle->vm_pgoff; diff --git a/mm/vma.h b/mm/vma.h index ddf567359880..5be43e2bba3f 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -113,11 +113,7 @@ struct vma_merge_struct { struct vm_area_struct *prev; struct vm_area_struct *middle; struct vm_area_struct *next; - /* - * This is the VMA we ultimately target to become the merged VMA, except - * for the one exception of merge right, shrink next (for details of - * this scenario see vma_merge_existing_range()). - */ + /* This is the VMA we ultimately target to become the merged VMA. */ struct vm_area_struct *target; /* * Initially, the start, end, pgoff fields are provided by the caller From patchwork Mon Jan 27 15:50:44 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13951626 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 5B462C02188 for ; Mon, 27 Jan 2025 16:41:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7564028015C; Mon, 27 Jan 2025 11:41:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 705A4280148; Mon, 27 Jan 2025 11:41:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BB9028015C; Mon, 27 Jan 2025 11:41:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 252C9280148 for ; Mon, 27 Jan 2025 11:41:50 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id CE9361C6025 for ; Mon, 27 Jan 2025 16:41:49 +0000 (UTC) X-FDA: 83053798338.27.4254657 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf23.hostedemail.com (Postfix) with ESMTP id 620E1140013 for ; Mon, 27 Jan 2025 16:41:45 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="HXjdw/Vv"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Dk4m1gV5; spf=pass (imf23.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=1737996105; 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=7uviu8hul45H4tZf5iQNLGCckTDPU96fpah2kR9UPc4=; b=UYH9QeW9Z7xvzS6YHQ2K7lsUUz8ZxYreACNxxz71wbvQHMQwLYzlaA6ZvSREl+pYHwZmXe 8K+H+QDe4zAvqSM8f/i09keGhEYOI8gm+G++OjpDQqfKqa0RJQMC8yQSPhpdIY9m23Kpze llur62OX23F0Z/HzSRGto2w+bgJ+z18= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1737996105; a=rsa-sha256; cv=pass; b=I2gfYDaKZ9VC3D9SN++NLkqm6IRAA5RHZWx3Q+mbuoXmGHSFXwOueUY9Nq8RfoWvB5Uady IefPMetkfPqtybzGjeWEp+P44BAiglW/Em2dAT32VnzIcuZG77CDj0xs+d7tsY1KgFNZis 2WoCvDf0EAP46N10gvt4PbjBkt462K0= ARC-Authentication-Results: i=2; imf23.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="HXjdw/Vv"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Dk4m1gV5; spf=pass (imf23.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 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 50RFjSSP015964; Mon, 27 Jan 2025 15:51:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=7uviu8hul45H4tZf5iQNLGCckTDPU96fpah2kR9UPc4=; b= HXjdw/Vv82E3xdVn+aPaSaAcZPYIfgi0mm74RUpaS0b2XuCHjjK3UTAwuhN0dKdy H1IauILSh/gpGUsszxNDnNk9ua4+o3j5BHGuNMYp4aeXNszC9jTHkB8hSp9mqP/V +vP2DtD7LdbWASeh2L+PbX0UzHwcj0S/iJhxmz4AohiH7wkwVnEghMl2c/Uxxniw 1IZEsggpLWD3oMWi7kx7H1SZm/BkpwH0MPevlSykOH16DGORhEDb2P+46GhlRFrM dpXAhT2XYMciv+zfLPqo2QrzlI89GfBAdEKRuKg2fHnmvHZwCTtA6gp4bP8GrZN4 IYwUPsr5HN0YiovQGiGNBw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 44ed2br0e6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Jan 2025 15:51:18 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50RFes8v036983; Mon, 27 Jan 2025 15:51:17 GMT Received: from nam02-sn1-obe.outbound.protection.outlook.com (mail-sn1nam02lp2049.outbound.protection.outlook.com [104.47.57.49]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 44cpd73xue-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 27 Jan 2025 15:51:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sdHyYnQef37/GoB4HWgBhX9nVh1QUEZtB6PGTK+B76U5/HWWC+P6sCUXCN56iG5I2t7VS1/leGXlyP+/tTUB8KdPLuDpRlNMqoHxLzZBXOAvUPa7+y2561Tn0bJReLRhA0hsa4hmNm/gOJND/5vmfsM2O0FGTJuConDcebsJ2k7N1YWpQFEVtmEMaX+DXacMXbbyoBknfWEhsBwm9IBrFKY2iG2uLk6yFgWTpIkf4YTWhERtc70AL5Yol3cAwlLaIC0KF3OBdRddkqBqTb6z9UxdwAsVBGc1qzKwOWKDIgHYOPhEi3qxhmrwQ+s8p4tHGNqrqb6fEvWKER93CdY3Zg== 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=7uviu8hul45H4tZf5iQNLGCckTDPU96fpah2kR9UPc4=; b=b7oQxpZEPCPvz+/A8aDtFUGIGAw6ACMAumuFJCvIvtMlR9FGQ4ZcInMZGoy6qnwXj1Js41C/6Yl0Ul8GuDmagD2nEng3p/EbwSMpC4ko+OXiyey5IGdrmBvg4XIIKNUCcj3gmmrDhxbWBF+3yLyK7mEWSwZSKwATDw61NjHb6a7o62qRK5yOSIld/WUVPl4p3kHa6zo96cfJCh7zPtuB33BlK6x86P1sycWrR3kdLOUUb5mMIHTlyjb0AyjAhsYJBgb+6yBUIExOShWDyC21Zak90C2fxY6eS3mTgFntBe8IYOeTCHcf2LEkndANLqdZbjp9jV567gs/zT9fz9HTyg== 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=7uviu8hul45H4tZf5iQNLGCckTDPU96fpah2kR9UPc4=; b=Dk4m1gV5U+cAT0fVSiahNux/WEn1JXzrX0bPXsCJd6edH8MObdZnoumI5ZvvsqRn/IuUmKItgcqr2agIiKzSvPWFFL7QU8YR/SbGByAZ55CIU/stpuogdLdcoONb1P9g7xaHiCDr22Hnfh7bk57GRJeIHDhZxBREfP6QBUuGAQk= Received: from MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) by PH8PR10MB6339.namprd10.prod.outlook.com (2603:10b6:510:1ce::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.19; Mon, 27 Jan 2025 15:51:15 +0000 Received: from MN2PR10MB3374.namprd10.prod.outlook.com ([fe80::eab5:3c8c:1b35:4348]) by MN2PR10MB3374.namprd10.prod.outlook.com ([fe80::eab5:3c8c:1b35:4348%3]) with mapi id 15.20.8377.021; Mon, 27 Jan 2025 15:51:15 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/5] mm: completely abstract unnecessary adj_start calculation Date: Mon, 27 Jan 2025 15:50:44 +0000 Message-ID: X-Mailer: git-send-email 2.48.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0018.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:150::23) To MN2PR10MB3374.namprd10.prod.outlook.com (2603:10b6:208:12b::29) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB3374:EE_|PH8PR10MB6339:EE_ X-MS-Office365-Filtering-Correlation-Id: 59023535-4251-4f81-c22a-08dd3eea6e49 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: v9rebQ7yHUAom+SK5hzBjs+92UVw5Aczvf2cuSbmS49TXhoMD8SJjcSGDTTD3Z6kqepxa1tx+mGpODOiEze9Qe/B0/m2F02k8/6f1Tktkt94DkOjyZnkFCdueHdWzbRQ+6P69zPehl0iHCFNqXElLEUFcdTsG5wyWAFHOp1c/oEx5TffLt2lkoMxaVeQT2qYrb08XewJi5LMSNJis+zzdTxRrm5LizSIBj+yqxnwhoIuOf/9UEpzV2nwLLUqbSu2dbeVRg1nsMG5Gn7P/DhupPqrEnSi4QkKMym4GlL2XVGcb5sN4Mj9A3a6o26J5qe9SrNusYkKOwzLqxIdMVbo2nJTzGoZZr0J0hdcKK3Z9PwVm23UnRgvHLUXiByftLttAvi8di/Sakc6m072UoizXpS8gSEvMgRuiJbSbrGglv8LsV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.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: V7YJd+xvw7hLLqci3rpT8BROOcwENJuqRV2fHKFhqV5aBuddr3l0h6JZmtRe8JX3PYiJZgKwJCWV6zN5/sLEcuyReIJ2KQnFe6vc8O4TIXu/9VQtmsScUWTYSPA8ffXzs5SZ4J1KPS5aQe0yRloU1ZFKHtcnUxzvG8yFaCM7fvezpXovD2UECdEloYu005Kiz/IYrpOODBWIvzmfW/uh0knF8JWroK2ifrLiNMSLVgdoVMPDwo7yvg7NUYH0z5SunsKrrJXc621752mWP+czx1UUIwL8jpRB+bRzkLBeKJtpSaZTurkKkCCjnKw3ktLRO8hroL7XW3uYAt/BYNp8qKqdDk9XHqPIR7RlDNRxqcav1V0vFJ195U/LvIu82Y3JeEnVOcJ22qz+cNvQ+Fo2dmyKpOqHH0t0/OWwPyTQailBnW1syF6TTB6BogEDMy4ulpc2p0gdtF9gkrfUOn3ES7qs4QTyGaFq4BOO6DZ8diQ3AkyGBYVvnyMLsi4mGI3lyr/VMq8WUEgnQpH5IyKZwsS3GNaOqGQ5/fI6jhhmoEpE9bMI59IvFsl8POFEC6XN/nH+ye5dRUIFaYdEC0Iq44d3P+IS+hmfqzMdgsHJVzb/PG05xMMYR8FH+doLHkhj8oJlseMRUmwnW14t0lM29wLfObAU94wErgvO9LqJ2wT+cRy64fu1UpXakKJT15pzQHfkBrtLQ+g5OV2V9ccFXV4fxtTY9cBHxTovLAmVZ/GP2FGAcQgQewJAQvHC179YYHdnn/d7ld0AduJir3XwMZrxlTv070s/UlmVadOkOJqyqgDFviRg58JIrvj/TKtQlccbs2Rzm+TlsSkErh63bqN2hYuJXPxprJH5UGHb8N/AnwcqsDnJW/UQzrcefFx52eWJoaAK1WRqe002qew2ZtA6YN4MZuh0S+I1bUJfWBmZi7UliTj/FDDcQIa2SWHEzuXGKLn/x1FU+4r5iLZflIg9c++M/hq+s81cYg9oW0XGgu/zCz2t4S8DViwYxwZUeLd4wiRPOLufo1+OAh1pijcKOgmjIWPWXjgDt73+//slKpdabVWQD5mXA0B3KfTmFdbNbtn252xg6WDesopglnl4K+1lkSptqdSwrr5UCyDRRSCPNKVOEVUUMCzbpvvq/+q85fG+M+QSSrmi9GZbP0ApWmWLKgeJXOH4nea9Ui0XMIEr/gIMlOc5wJoKkvgyUw49c5Gof/XEaFs54BGyDcUs1BWLeJ47yrmJXsIOJ3pd1vg+CI2yjFP39fZ92Ay+JnALBrn/0huP2ipdZw49fZJorohc4i+3nHHcq7rKEY99V2zbSsfunZaF5RV4S6hHnwSbHCuJtSwvozuNwD9Am2y6MbuWiCOXdTcfauV+xLxdQ3XJlzP65HEGKFMgQlWXX5fh5HDw10N0QOjpo7BqH2eA+/1eLLk22FWrG0hcjTy/i17/AlkIjqty2Q69t11m6gJXChGTPdTrLSZyUbNzv+whTqv/fvFxdQt4FWRKgX7vAfo0zbB1hGzn4Mb9HT6l1RbMKCje+mn6B082KNHZnA2S8XrGD4bfxwS4hP/nu2ZBN+urYPtDagbLcH3qsW3QnZPRmZV1YcMygm6X060LYw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: O0wKc1aDonh8cZMFLu5EsTkv9MobcBCu+/GSbPcR3/8sNXCGgFGE3bDOfctoZCshGeqzDhRnLs0JP3ox3Sd/11xfGT1g2MwWoemK7Iz/mm/S+stklheMKfKVyCQC6lTCsg4II7a2ms2d1UY4QCLT4L8rCz+2/zfQTwsDPGlNGGzwThWgTzpE91XEdpM6S3U8k9mdQV3ObYuoDA+WzNvAJaNxHWyekvEoK6obVJrsKg65czy5H8We+vz8zypzZss/NFvIjQHz78FcPqgAzFtNRe8p5DCrdzEiZGbq5llBjdtCnd+tWEBykEG45if3MmXn/ivWRSCVkbzsKmxyQAPqTWv3pT9a3mF9V3YAblCm4+I26iJWY3o04IQcCdx3JEz7AWPn10Ytn5OqHToeHZEnT0MpJN3UyUOMGbQv9nlpmpY0eSGG/PYa2fcwiSuX/Bum/ntqDVQPHnfZTCVY5AGYKiVGyQY8yd8BI/EKKax2UvjNy3MIEIuC2di2LlLzRf9AyJDquT7zIwA0wUsrVjWzERbOjvi3dHBasLx7ULifZi9sk36M+/M1uwiQxfu/6Obx3C7X1zdDokIGGnzrclLs24VOCCoDaedy5CAtuQSUqZ0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 59023535-4251-4f81-c22a-08dd3eea6e49 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB3374.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Jan 2025 15:51:15.2099 (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: JQ/6fRQufDeIVpUJrNqvxpcduGbS259S1KVtVKxZIG9jDA1kM+OJRkukYuXcmY2RMUVdTHt/wSgsnjeU0wQi9B8BHMzToaoBpXQu36K7BZY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR10MB6339 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-01-27_07,2025-01-27_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 spamscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501270126 X-Proofpoint-ORIG-GUID: eyna2I2dl_N7AeoS0NgDRV8Ci7ddphod X-Proofpoint-GUID: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Qf1cOzrv3JudEIz/AUrDn/ShSLKfZ3qVnS+s6ugNVCxgJI0L24D9 myJP9EdV seAcGeahCY3zm4NCvs2GI3shDLre1V+ULzDkXPMeg9fD0/DubyWKjwVAsfjABIG2gVtze+raTpmUX88YpbrOzxSgy9V+nImkGCd5A8yzB88p5tTh0nkMM1iB1E696sma3YTpD8K/5YvcVoRuYvcb1KShOns/s+6SWAY35xDfzosjzf0kPuCIuUErUtN6PYgT3xVZ+Kd9I3dnShC7FfYPPRlfWlK2c0zvWHrE5mBeJ+i9fR4bdSFZRB0wPH1lDM24y7YgskmxVKzEy6R7Lc47hkVS8SuHnLBZOn+GukW4DJKrig3D/j6A38YsY9/5xu9ONpvwZYxQtIwZmH5fZp+sF+CbK6lUErYIkxUWvzk5TuTpClQvwnCqRT8REzsgU8NiOx+GemaPcVYtnzmadryoiHIrgUl1klcbaCqvbGWoEdro6v6g/EsjdjU9BXjyTntsMJBoYytCaH0heGok8SQ8Ns+llfhLkZZgqjBzx2BM8mtxNoKVI4TqFxFFAX1CDPugkdVC1YODIozRJJ4/pg8AHx8f8i+uF2hR+4jjwEv3+35Jg3gf/iXaIa3pwP55eSA90onV4xl6d/Lt4RoDQsRpcOmW+JURfc7F/Rv5P 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 adj_start calculation has been a constant source of confusion in the VMA merge code. There are two cases to consider, one where we adjust the start of the vmg->middle VMA (i.e. the __VMG_FLAG_ADJUST_MIDDLE_START merge flag is set), in which case adj_start is calculated as: (1) adj_start = vmg->end - vmg->middle->vm_start And the case where we adjust the start of the vmg->next VMA (i.e.t he __VMG_FLAG_ADJUST_NEXT_START merge flag is set), in which case adj_start is calculated as: (2) adj_start = -(vmg->middle->vm_end - vmg->end) We apply (1) thusly: vmg->middle->vm_start = vmg->middle->vm_start + vmg->end - vmg->middle->vm_start Which simplifies to: vmg->middle->vm_start = vmg->end Similarly, we apply (2) as: vmg->next->vm_start = vmg->next->vm_start + -(vmg->middle->vm_end - vmg->end) Noting that for these VMAs to be mergeable vmg->middle->vm_end == vmg->next->vm_start and so this simplifies to: vmg->next->vm_start = vmg->next->vm_start + -(vmg->next->vm_start - vmg->end) Which simplifies to: vmg->next->vm_start = vmg->end Therefore in each case, we simply need to adjust the start of the VMA to vmg->end (!) and can do away with this adj_start calculation. The only caveat is that we must ensure we update the vm_pgoff field correctly. We therefore abstract this entire calculation to a new function vmg_adjust_set_range() which performs this calculation and sets the adjusted VMA's new range using the general vma_set_range() function. We also must update vma_adjust_trans_huge() which expects the now-abstracted adj_start parameter. It turns out this is wholly unnecessary. In vma_adjust_trans_huge() the relevant code is: if (adjust_next > 0) { struct vm_area_struct *next = find_vma(vma->vm_mm, vma->vm_end); unsigned long nstart = next->vm_start; nstart += adjust_next; split_huge_pmd_if_needed(next, nstart); } The only case where this is relevant is when __VMG_FLAG_ADJUST_MIDDLE_START is specified (in which case adj_next would have been positive), i.e. the one in which the vma specified is vmg->prev and this the sought 'next' VMA would be vmg->middle. We can therefore eliminate the find_vma() invocation altogether and simply provide the vmg->middle VMA in this instance, or NULL otherwise. Again we have an adj_next offset calculation: next->vm_start + vmg->end - vmg->middle->vm_start Where next == vmg->middle this simplifies to vmg->end as previously demonstrated. Therefore nstart is equal to vmg->end, which is already passed to vma_adjust_trans_huge() via the 'end' parameter and so this code (rather delightfully) simplifies to: if (next) split_huge_pmd_if_needed(next, end); With these changes in place, it becomes silly for commit_merge() to return vmg->target, as it is always the same and threaded through vmg, so we finally change commit_merge() to return an error value once again. This patch has no change in functional behaviour. Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- include/linux/huge_mm.h | 2 +- mm/huge_memory.c | 19 ++---- mm/vma.c | 102 +++++++++++++++---------------- tools/testing/vma/vma_internal.h | 4 +- 4 files changed, 58 insertions(+), 69 deletions(-) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 93e509b6c00e..43f76b54b522 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -404,7 +404,7 @@ int madvise_collapse(struct vm_area_struct *vma, struct vm_area_struct **prev, unsigned long start, unsigned long end); void vma_adjust_trans_huge(struct vm_area_struct *vma, unsigned long start, - unsigned long end, long adjust_next); + unsigned long end, struct vm_area_struct *next); spinlock_t *__pmd_trans_huge_lock(pmd_t *pmd, struct vm_area_struct *vma); spinlock_t *__pud_trans_huge_lock(pud_t *pud, struct vm_area_struct *vma); diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 3d3ebdc002d5..c44599f9ad09 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3017,9 +3017,9 @@ static inline void split_huge_pmd_if_needed(struct vm_area_struct *vma, unsigned } void vma_adjust_trans_huge(struct vm_area_struct *vma, - unsigned long start, - unsigned long end, - long adjust_next) + unsigned long start, + unsigned long end, + struct vm_area_struct *next) { /* Check if we need to split start first. */ split_huge_pmd_if_needed(vma, start); @@ -3027,16 +3027,9 @@ void vma_adjust_trans_huge(struct vm_area_struct *vma, /* Check if we need to split end next. */ split_huge_pmd_if_needed(vma, end); - /* - * If we're also updating the next vma vm_start, - * check if we need to split it. - */ - if (adjust_next > 0) { - struct vm_area_struct *next = find_vma(vma->vm_mm, vma->vm_end); - unsigned long nstart = next->vm_start; - nstart += adjust_next; - split_huge_pmd_if_needed(next, nstart); - } + /* If we're incrementing next->vm_start, we might need to split it. */ + if (next) + split_huge_pmd_if_needed(next, end); } static void unmap_folio(struct folio *folio) diff --git a/mm/vma.c b/mm/vma.c index cfcadca7b116..48a7acc83a82 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -515,7 +515,7 @@ __split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma, init_vma_prep(&vp, vma); vp.insert = new; vma_prepare(&vp); - vma_adjust_trans_huge(vma, vma->vm_start, addr, 0); + vma_adjust_trans_huge(vma, vma->vm_start, addr, NULL); if (new_below) { vma->vm_start = addr; @@ -646,47 +646,46 @@ void validate_mm(struct mm_struct *mm) #endif /* CONFIG_DEBUG_VM_MAPLE_TREE */ /* - * Actually perform the VMA merge operation. - * - * On success, returns the merged VMA. Otherwise returns NULL. + * Based on the vmg flag indicating whether we need to adjust the vm_start field + * for the middle or next VMA, we calculate what the range of the newly adjusted + * VMA ought to be, and set the VMA's range accordingly. */ -static struct vm_area_struct *commit_merge(struct vma_merge_struct *vmg) +static void vmg_adjust_set_range(struct vma_merge_struct *vmg) { - struct vm_area_struct *vma; - struct vma_prepare vp; - struct vm_area_struct *adjust; - long adj_start; unsigned long flags = vmg->merge_flags; + struct vm_area_struct *adjust; + pgoff_t pgoff; - /* - * If modifying an existing VMA and we don't remove vmg->middle, then we - * shrink the adjacent VMA. - */ if (flags & __VMG_FLAG_ADJUST_MIDDLE_START) { - vma = vmg->target; adjust = vmg->middle; - /* The POSITIVE value by which we offset vmg->middle->vm_start. */ - adj_start = vmg->end - vmg->middle->vm_start; - - /* Note: vma iterator must be pointing to 'start'. */ - vma_iter_config(vmg->vmi, vmg->start, vmg->end); + pgoff = adjust->vm_pgoff + PHYS_PFN(vmg->end - adjust->vm_start); } else if (flags & __VMG_FLAG_ADJUST_NEXT_START) { - /* - * In this case alone, the VMA we manipulate is vmg->middle, but - * we ultimately return vmg->next. - */ - vma = vmg->middle; adjust = vmg->next; - /* The NEGATIVE value by which we offset vmg->next->vm_start. */ - adj_start = -(vmg->middle->vm_end - vmg->end); + pgoff = adjust->vm_pgoff - PHYS_PFN(adjust->vm_start - vmg->end); + } else { + return; + } + + vma_set_range(adjust, vmg->end, adjust->vm_end, pgoff); +} + +/* + * Actually perform the VMA merge operation. + * + * On success, returns the merged VMA. Otherwise returns NULL. + */ +static int commit_merge(struct vma_merge_struct *vmg) +{ + struct vm_area_struct *vma; + struct vma_prepare vp; + bool adj_middle = vmg->merge_flags & __VMG_FLAG_ADJUST_MIDDLE_START; - vma_iter_config(vmg->vmi, vmg->next->vm_start + adj_start, - vmg->next->vm_end); + if (vmg->merge_flags & __VMG_FLAG_ADJUST_NEXT_START) { + /* In this case we manipulate middle and return next. */ + vma = vmg->middle; + vma_iter_config(vmg->vmi, vmg->end, vmg->next->vm_end); } else { vma = vmg->target; - adjust = NULL; - adj_start = 0; - /* Note: vma iterator must be pointing to 'start'. */ vma_iter_config(vmg->vmi, vmg->start, vmg->end); } @@ -694,22 +693,22 @@ static struct vm_area_struct *commit_merge(struct vma_merge_struct *vmg) init_multi_vma_prep(&vp, vma, vmg); if (vma_iter_prealloc(vmg->vmi, vma)) - return NULL; + return -ENOMEM; vma_prepare(&vp); - vma_adjust_trans_huge(vma, vmg->start, vmg->end, adj_start); + /* + * THP pages may need to do additional splits if we increase + * middle->vm_start. + */ + vma_adjust_trans_huge(vma, vmg->start, vmg->end, + adj_middle ? vmg->middle : NULL); vma_set_range(vma, vmg->start, vmg->end, vmg->pgoff); - - if (adj_start) { - adjust->vm_start += adj_start; - adjust->vm_pgoff += PHYS_PFN(adj_start); - } - + vmg_adjust_set_range(vmg); vma_iter_store(vmg->vmi, vmg->target); vma_complete(&vp, vmg->vmi, vma->vm_mm); - return vmg->target; + return 0; } /* We can only remove VMAs when merging if they do not have a close hook. */ @@ -752,7 +751,7 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( { struct vm_area_struct *middle = vmg->middle; struct vm_area_struct *prev = vmg->prev; - struct vm_area_struct *next, *res; + struct vm_area_struct *next; struct vm_area_struct *anon_dup = NULL; unsigned long start = vmg->start; unsigned long end = vmg->end; @@ -904,12 +903,7 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( vmg->end = next->vm_end; vmg->pgoff = next->vm_pgoff - pglen; } else { - /* - * We shrink middle and expand next. - * - * IMPORTANT: This is the ONLY case where the final - * merged VMA is NOT vmg->target, but rather vmg->next. - */ + /* We shrink middle and expand next. */ vmg->merge_flags |= __VMG_FLAG_ADJUST_NEXT_START; vmg->start = middle->vm_start; vmg->end = start; @@ -927,8 +921,10 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( if (merge_will_delete_next) vmg->merge_flags |= __VMG_FLAG_REMOVE_NEXT; - res = commit_merge(vmg); - if (!res) { + err = commit_merge(vmg); + if (err) { + VM_WARN_ON(err != -ENOMEM); + if (anon_dup) unlink_anon_vmas(anon_dup); @@ -936,9 +932,9 @@ static __must_check struct vm_area_struct *vma_merge_existing_range( return NULL; } - khugepaged_enter_vma(res, vmg->flags); + khugepaged_enter_vma(vmg->target, vmg->flags); vmg->state = VMA_MERGE_SUCCESS; - return res; + return vmg->target; abort: vma_iter_set(vmg->vmi, start); @@ -1102,7 +1098,7 @@ int vma_expand(struct vma_merge_struct *vmg) if (remove_next) vmg->merge_flags |= __VMG_FLAG_REMOVE_NEXT; - if (!commit_merge(vmg)) + if (commit_merge(vmg)) goto nomem; return 0; @@ -1142,7 +1138,7 @@ int vma_shrink(struct vma_iterator *vmi, struct vm_area_struct *vma, init_vma_prep(&vp, vma); vma_prepare(&vp); - vma_adjust_trans_huge(vma, start, end, 0); + vma_adjust_trans_huge(vma, start, end, NULL); vma_iter_clear(vmi); vma_set_range(vma, start, end, pgoff); diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_internal.h index 1eae23039854..bb273927af0f 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -796,12 +796,12 @@ static inline void vma_start_write(struct vm_area_struct *vma) static inline void vma_adjust_trans_huge(struct vm_area_struct *vma, unsigned long start, unsigned long end, - long adjust_next) + struct vm_area_struct *next) { (void)vma; (void)start; (void)end; - (void)adjust_next; + (void)next; } static inline void vma_iter_free(struct vma_iterator *vmi)