From patchwork Mon Aug 5 12:13:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13753571 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CE24C3DA7F for ; Mon, 5 Aug 2024 12:15:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA6196B0096; Mon, 5 Aug 2024 08:15:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D56FD6B00AA; Mon, 5 Aug 2024 08:15:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B83E66B00AB; Mon, 5 Aug 2024 08:15:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 931C06B0096 for ; Mon, 5 Aug 2024 08:15:04 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 4DB3A161BC0 for ; Mon, 5 Aug 2024 12:15:04 +0000 (UTC) X-FDA: 82418086128.14.F264BEB Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf21.hostedemail.com (Postfix) with ESMTP id E791E1C0013 for ; Mon, 5 Aug 2024 12:15:00 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=X70FSOps; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=KKpOThSs; spf=pass (imf21.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722860093; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kkI6NNI0jXsxFrPLz75VTLqEXdGgi02HQ4yO6eKoi5M=; b=n4T9rCl3wKv9FPOvqDitwpblo2iPlC74wtw1LxJFxwPiPHLRG6ioWpUJXl1YX9DBGDQVQd IrcNkhVu1oA3jGrNmn4+XsEgNzEzTLuqe1wrZAlbNf6dfkWx3UUaBGmsgVCxphrYMyNM37 UVQK74XYglSE0uX8PBwvpCT/5elkmco= ARC-Authentication-Results: i=2; imf21.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=X70FSOps; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=KKpOThSs; spf=pass (imf21.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1722860093; a=rsa-sha256; cv=pass; b=SlqEVFpaQj+uvmzcG57xv2vlJefjB33LxhREuIScjG+5yifWT6OVIIARzZmXtLt+xKkUQe ar+WGF/sF/WLJMms8I7gdfPWljVIQY1eti5+FO4ALNztofZDhFSe+gk/ud2yukkHb1tyM7 +MepzUoT5jO5gkOL57a0FCJ6VyI3WIc= Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4758fbAB027532; Mon, 5 Aug 2024 12:14:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=kkI6NNI0jXsxFrPLz75VTLqEXdGgi02HQ4yO6eKoi5M=; b= X70FSOpsna+kzk15V5WOOIAGsGM0A5Vj2XRKn32xYVr9ARFyVJftPAG4amZauQv6 coSKeFOX2hVB55XzG1viy7/oyVzZPWo3tqOq/Yzbs/wBsd91WyKLD3FQ3/OOSi7F d5fEYEgXcuYcJkH4/tO61NZbCB8DQjHkn7ZKeuz//MHtTKvyOoGrYaMCLB3SNZq9 iZPi418O3ClwXHZEtO2xx4W1nWusCa5ptd8IEIHS36TpMRjaIlw6EQRE1XYhcTdL gY7PiucOYSXEBuXmuT/n9lzlkjL4xT3egrOKTIsuf2VABF5w3NSxy8EhDshS3yoY VkE3MSuH3z/jzfSrIYkgKg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 40sbfajgkr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:59 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 475B4jDr004673; Mon, 5 Aug 2024 12:14:52 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2049.outbound.protection.outlook.com [104.47.66.49]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 40sb0d6qsu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 05 Aug 2024 12:14:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=IKxYY564DvbI+nq6bJuKUwZMlYv4WSWIfwcSu8yC36jorLcMa/0iO5wM5OAR5G7GWkXlvA8Pz1i+l5woQJ+0Ckb/1I2xZGDtpZ9j3qRrFTCekg7lKFf3mZ0Lh2UaOtlBAt22JhNIMjmhMQ9SL2pKU5NYNoMY54hL9Bz70LdNy5IrOSLt9H+lgOmFcCh/sYLdCAhlneRlL+SvvP7rhWUo7NnMaCOa3hlMn++Vp2U1qkAUvs5aJEa5N2N/mmNGLtk2Lt8af7Sm7ONxlQL8Nsy1ziJcwcy6Z9HFCW3rBaHAGGJYX0mU4UFP92+MfjfZNcUkK5Mp7TDdBWf32wRCKBiwqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kkI6NNI0jXsxFrPLz75VTLqEXdGgi02HQ4yO6eKoi5M=; b=bOMR4UgxJrzpwjf45D2Vl9dhjMS1BFKcy7ck/+1VLfQkw1ivGKq1f0oH3dnReU3bqeWfAcXhL2dyxIEnknDbbnFutGOwRqS367D159qm1tpIU53+40W9GB4dnkcDyg3WkxvEX6hBFKPZ7QDqcfH83/acPZJ2tFUU3V8sEDE68XmqRBDci9ApGLb++FeSjVm5A4fqX8Thksa6UOxO9ERWgPWNNe7GvS26RE7zB1QUxhzZ1IsVl7p00iq6Agmzlodq7NX/uEGx1sjcWToDs518zzo2+5TqTk3H1xEnZ+Zs7Vf+ilL80JejjzEFa/yJ4z/wuYOOJPM3SKr3R+7msv5giw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kkI6NNI0jXsxFrPLz75VTLqEXdGgi02HQ4yO6eKoi5M=; b=KKpOThSs4MKe2l/NGjJlANsc1BAyUHFaKyLCu2GW9ybgjF6D/Ddkb5pS/MILIBSdCxB5dd4qChhO82dY8XO1QWKI6J2JGSG9FQLGoP2r7CqCydl+YjxKSWArr5NdlA/IhDcRvLpXtkcp9TzBLASBAm2HnlURAhT/V0/ag3SsXxU= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by SJ2PR10MB7760.namprd10.prod.outlook.com (2603:10b6:a03:574::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 12:14:49 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%6]) with mapi id 15.20.7828.023; Mon, 5 Aug 2024 12:14:49 +0000 From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka Subject: [PATCH 10/10] mm: rework vm_ops->close() handling on VMA merge Date: Mon, 5 Aug 2024 13:13:57 +0100 Message-ID: <0afd85543d46fd743c0c71b6f6520f9580174b4f.1722849860.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0198.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a4::23) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|SJ2PR10MB7760:EE_ X-MS-Office365-Filtering-Correlation-Id: 040b5a69-ebf7-434c-0f83-08dcb54833fe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016; X-Microsoft-Antispam-Message-Info: uKTxr0Xld4oWzfjFaeIqK0Vj9+O4GFYsM0GFUZdLMPSqJ2dtwJRHD4Th10gOPrl976vh4iWzNeyN82hlWBv4XsEExKd03phTD1FsF2XNN83+/iqVa8+7zo3Bl/+mT7nh2elzhRQ6Som4sWR+lnDBMnpYqiqWk0C7KTttHVcEMNyO9Lst5ap+2MbE/JqFADvpXHS/FTkIse1jrRW+EZTBXOKGHedJ6iJhSPBG32CeDwd/J+FMedM55hV2kQcSDzbjX13ZpVp3PBMi+S6prpP05XmDTu+JcOYZu0rFuXeZtVUgQViZY2T/yjQBxXnTtOudVEIReVKkj1dvbwxyLhT5AsOHkci4gRCByhznCYE13UvsgXE9kZr7+1gzoY5cwVBkKVKaWRGb90Hh6lx1FqlP0XnZ+xIDX8ByZGqMV23dXKJ1biY61np3tbjsBdZIQ/TWkbZR2NnGXV9W86kH+FMvumJmzEPd3B0RzE004Ri2lOWq5QyzyvcVMJAnoQpIcMrGD59gs417tBTAUH8rpVpA9/JiWN38G4V6NSBoA0F+P5s3OJNbE4eqUTXQMHpTTjP7CrHlFjsjRCGTZHjCdrTcMTgM3kvjJHWQID5lq5Sx4BAgb8ZUVP749eI3P4vyJ5in5xzZNDC81tZd+KvXAAdRYGlBeX61xf2JtJOifmN37fRJv2WHL/n3rZkBOVBHSbde7rJpUFpehD8kGyodemYUOdGIs20EeODnQfEZJSrbum+MggT1yExZfdNmp68j6lwHu4hz8h4c0i+Pj/SQi/BbMbspueEsU7qoiShUSYTs6SdzXbhJzBV00Gn1DkZMF2SQN7w+Pg12K/2NH/EWSbmQxG2XErMQBWtyv9Da4bVttg6pzshqZfEmarSgiuSVT5C6IvBK7vU8UXxF+F6aAgyAoV8HUhS+RU6/Cwxtg00T+gRHp2Nh6PiBlH/7qdsICwtdw8F/g7O5urJYAnzuVx/rslPyEi8FH60wYpyyHjIqznF3AR/FrZKtWA3AFV3l9cdXUwQFetwmnx1NzcxtfHlHPquyjcgTPvWbImYDsIsVzjI0qmkQwDBl+I/r5J2k9GO9wcuPM+Irj3xwJbJYhjs9A7J7NXea7Thr58tiX3TGMDISUmH92oQ3nHEq98X++z+UVRC2BSk9D906SPZn+tMEbhDknMzTz0cDp8T+f69hgYwP4qZ68aUZtAd2PwfFocXNKrctxw5aA5P4EGKHZh06y1xqZDOqDmS80tB0Hy9Di9hdB9+47qcdwuuXG/D8myZJmDLy0Dsl6f4C9r0gARADRz9b4wMK9ynf5B6Z0LFWnBLo4KnFnvU8NO8Ir/GG4jdpqUqwh+kBZsRKh5PDwq+UPg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Yre3cDxn5PdVrv2LxusvIyo/bdQNFQeKUw6ETx1hQFQlS4cHtin7o3nkek8Jwv1ndlZI5Rn8AAuqzfDGPmNabdi0wSUO7abhZOTCNC+1eiYYMqz9GyU1P6mBnOej9Q4/S5AfAsrDUygM+X2Pw0GWtpRKAOfFidW/BjrYiCS33o4G+qgP0erW2vJddKtJmbimf58sCbMFE0Y6pYmQ6Q3VMk82SMdPjvwTqIs9oUN/r9os0eLajPg6CDg/m/AuD3CicZCYLtWto+65/Uk5VtxwGpRqLJmA0x2xZtM+wSwv7yt7kfSRENghk9IwjPbFXslh3Gue7ZHPWYuBadNSZ6SYiwNXkyowcdEjcSx/X5rREXl60Ed87aPlstBVmiKwAIagVboh19D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F4mtwIZPDfGC+x6qzxddzsuLyONSj+xXXVOosaKrY8fgZ+h2ypHnwyKqPoj88upW0b3wOqIKhZwa3TWgTvoGaE1hfkyZA0Vm1BfOKfAKuETJwnbjGSMkgDhn6cugjIg8kJ5SR7+ydewgy6sIYte074HUQXZSmZm+c7bnGTJiyPipsdZsyrqANbRKJzxnD3GF3jz/z3ZR5BmeAiP4tlv8TiXw5j1w== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: /nTLI+8FTonmP3mwke8/MugwagNEedS1ef7Pkw00ZO5X7Drql4GzzlbAp5MPp0dAhcI9mLMfk/R2PnkioXBJNBLtJShBsO8kxWOGyeUlvS0JzvKRj4VAfQWmcsZJlB4xmKDXbuWKbaFCnDZvr4wlWD/mAR6c1fV4DtiejLMPaYHUPCYz0ISNgSWtuk7z89iTM7FL+exG+pQJv1xh5x2tpUG2Gs7RiJ00jubht7QdYviQ07UsA/9Ho02O3eQYuspWJ+7ChbR40Kyjvbvjy3JPiPtgIsU4hKWbPzP+Btg+QAwHULH3bcVl45dezG9JO9hIPGNvQV7OL2KFlUKxrVuAKSkRdcqmXRijoKFNwtkyVB4CfbbDf8GmEaPbj8/dDmbBuCT8A4rpjraCL/WCk6rEuC+YXZ7pQ6DBtC+ylW+i40ArqBVdwav0OIwHfLoQ5KlthkpGiPcl6mlZLKoDTgpN58+mLCa4t/fOk9ZBlEVWKKM3ydTdompji4TFm9YkbHv2G0DPyOZCv41mlZQBTz7AJiQKYvS6AcbENtRjwzL0rWhMUTfjS7OKKKhSxmGEfDLKgadC4uGJp+swikxAKAOKBBL1PZLzQAu25XTTSwC6cGc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 040b5a69-ebf7-434c-0f83-08dcb54833fe X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 12:14:49.6607 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: oJ+hiqfGmy9qcwqxDRWBhRAXH7h9XSal/vVM8VbwBV0RXE5T63DatWwX09jUykdptdfm2NXWcr00p/pEcX+31aKj+S0QEwdFV/mBIPlVHIk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR10MB7760 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-05_01,2024-08-02_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 spamscore=0 bulkscore=0 adultscore=0 mlxscore=0 phishscore=0 malwarescore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2407110000 definitions=main-2408050088 X-Proofpoint-GUID: rKOA1v5dUVHNKpVm3j_pxlc64ZMx3pVq X-Proofpoint-ORIG-GUID: rKOA1v5dUVHNKpVm3j_pxlc64ZMx3pVq X-Rspam-User: X-Stat-Signature: fjtjaug7qqtmg4fyg19xxywdshgk8hkc X-Rspamd-Queue-Id: E791E1C0013 X-Rspamd-Server: rspam11 X-HE-Tag: 1722860100-703210 X-HE-Meta: U2FsdGVkX1/n3JfqzZs7UBj9Bt2mJkbJmhFbiqqpLa9oz7qORv+hcWdcyi83yH8/w7M4DPEeuGODYFAdyvr+P0LuwPTpRyVV/HbJcusvOZuWMhdy9KvB4SnYdufxq+FGgnoqLosAE93UW8vKH/cpawSgEAwupp7nNKDydtNS39xMD3/sS1Q10DeImYKS+f0ZB+xXtrAZ3fpvgsUKN/bPUXgd70l9HjX+QUvPbszi5czXnh10l+SVfqT+1E8pOnWjOC47l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o6YivIBOQT4Qfxh18EqOSZGxY2YnGlTsKofOSlzJWHmAgwncmFt7xRET2l8QTOnZjp57/L4Bm63ZhUf0ot9zkB3tZDE2UCyIq0U2P9Y+9vNC7ffeENfkt76pnmAG+lJiDJQFeUvgJEK/n04nCzaG6eouJOEfFg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In commit 714965ca8252 ("mm/mmap: start distinguishing if vma can be removed in mergeability test") we relaxed the VMA merge rules for VMAs possessing a vm_ops->close() hook, permitting this operation in instances where we wouldn't delete the VMA as part of the merge operation. This was later corrected in commit fc0c8f9089c2 ("mm, mmap: fix vma_merge() case 7 with vma_ops->close") to account for a subtle case that the previous commit had not taken into account. In both instances, we first rely on is_mergeable_vma() to determine whether we might be dealing with a VMA that might be removed, taking advantage of the fact that a 'previous' VMA will never be deleted, only VMAs that follow it. The second patch corrects the instance where a merge of the previous VMA into a subsequent one did not correctly check whether the subsequent VMA had a vm_ops->close() handler. Both changes prevent merge cases that are actually permissible (for instance a merge of a VMA into a following VMA with a vm_ops->close(), but with no previous VMA, which would result in the next VMA being extended, not deleted). In addition, both changes fail to consider the case where a VMA that would otherwise be merged with the previous and next VMA might have vm_ops->close(), on the assumption that for this to be the case, all three would have to have the same vma->vm_file to be mergeable and thus the same vm_ops. And in addition both changes operate at 50,000 feet, trying to guess whether a VMA will be deleted. As we have majorly refactored the VMA merge operation and de-duplicated code to the point where we know precisely where deletions will occur, this patch removes the aforementioned checks altogether and instead explicitly checks whether a VMA will be deleted. In cases where a reduced merge is still possible (where we merge both previous and next VMA but the next VMA has a vm_ops->close hook, meaning we could just merge the previous and current VMA), we do so, otherwise the merge is not permitted. We take advantage of our userland testing to assert that this functions correctly - replacing the previous limited vm_ops->close() tests with tests for every single case where we delete a VMA. We also update all testing for both new and modified VMAs to set vma->vm_ops->close() in every single instance where this would not prevent the merge, to assert that we never do so. Signed-off-by: Lorenzo Stoakes Acked-by: Vlastimil Babka --- mm/vma.c | 69 ++++++++----- tools/testing/vma/vma.c | 213 ++++++++++++++++++++++++---------------- 2 files changed, 173 insertions(+), 109 deletions(-) -- 2.45.2 diff --git a/mm/vma.c b/mm/vma.c index c55ae035f5d6..9c779fc65ba8 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -10,14 +10,6 @@ static inline bool is_mergeable_vma(struct vma_merge_struct *vmg, bool merge_next) { struct vm_area_struct *vma = merge_next ? vmg->next : vmg->prev; - /* - * If the vma has a ->close operation then the driver probably needs to - * release per-vma resources, so we don't attempt to merge those if the - * caller indicates the current vma may be removed as part of the merge, - * which is the case if we are attempting to merge the next VMA into - * this one. - */ - bool may_remove_vma = merge_next; if (!mpol_equal(vmg->policy, vma_policy(vma))) return false; @@ -33,8 +25,6 @@ static inline bool is_mergeable_vma(struct vma_merge_struct *vmg, bool merge_nex return false; if (vma->vm_file != vmg->file) return false; - if (may_remove_vma && vma->vm_ops && vma->vm_ops->close) - return false; if (!is_mergeable_vm_userfaultfd_ctx(vma, vmg->uffd_ctx)) return false; if (!anon_vma_name_eq(anon_vma_name(vma), vmg->anon_name)) @@ -606,6 +596,12 @@ static int commit_merge(struct vma_merge_struct *vmg, return 0; } +/* We can only remove VMAs when merging if they do not have a close hook. */ +static bool can_merge_remove_vma(struct vm_area_struct *vma) +{ + return !vma->vm_ops || !vma->vm_ops->close; +} + /* * vma_merge_modified - Attempt to merge VMAs based on a VMA having its * attributes modified. @@ -710,9 +706,30 @@ static struct vm_area_struct *vma_merge_modified(struct vma_merge_struct *vmg) /* If we span the entire VMA, a merge implies it will be deleted. */ merge_will_delete_vma = left_side && right_side; - /* If we merge both VMAs, then next is also deleted. */ + + /* + * If we need to remove vma in its entirety but are unable to do so, + * we have no sensible recourse but to abort the merge. + */ + if (merge_will_delete_vma && !can_merge_remove_vma(vma)) + return NULL; + + /* + * If we merge both VMAs, then next is also deleted. This implies + * merge_will_delete_vma also. + */ merge_will_delete_next = merge_both; + /* + * If we cannot delete next, then we can reduce the operation to merging + * prev and vma (thereby deleting vma). + */ + if (merge_will_delete_next && !can_merge_remove_vma(next)) { + merge_will_delete_next = false; + merge_right = false; + merge_both = false; + } + /* No matter what happens, we will be adjusting vma. */ vma_start_write(vma); @@ -756,21 +773,12 @@ static struct vm_area_struct *vma_merge_modified(struct vma_merge_struct *vmg) vmg->start = prev->vm_start; vmg->pgoff = prev->vm_pgoff; - if (merge_will_delete_vma) { - /* - * can_vma_merge_after() assumed we would not be - * removing vma, so it skipped the check for - * vm_ops->close, but we are removing vma. - */ - if (vma->vm_ops && vma->vm_ops->close) - err = -EINVAL; - } else { + if (!merge_will_delete_vma) { adjust = vma; adj_start = end - vma->vm_start; } - if (!err) - err = dup_anon_vma(prev, vma, &anon_dup); + err = dup_anon_vma(prev, vma, &anon_dup); } else { /* merge_right */ /* * |<----->| OR @@ -886,6 +894,8 @@ struct vm_area_struct *vma_merge_new_vma(struct vma_merge_struct *vmg) unsigned long end = vmg->end; pgoff_t pgoff = vmg->pgoff; pgoff_t pglen = PHYS_PFN(end - start); + bool merge_next = false; + struct anon_vma *anon_vma = vmg->anon_vma; VM_WARN_ON(vmg->vma); @@ -916,8 +926,9 @@ struct vm_area_struct *vma_merge_new_vma(struct vma_merge_struct *vmg) vmg->end = next->vm_end; vmg->vma = next; vmg->pgoff = next->vm_pgoff - pglen; - vmg->anon_vma = next->anon_vma; + + merge_next = true; } /* If we can merge with the previous VMA, adjust vmg accordingly. */ @@ -925,6 +936,16 @@ struct vm_area_struct *vma_merge_new_vma(struct vma_merge_struct *vmg) vmg->start = prev->vm_start; vmg->vma = prev; vmg->pgoff = prev->vm_pgoff; + + /* + * If this merge would result in removal of the next VMA but we + * are not permitted to do so, reduce the operation to merging + * prev and vma. + */ + if (merge_next && !can_merge_remove_vma(next)) { + vmg->end = end; + vmg->anon_vma = anon_vma; + } } else if (prev) { vma_iter_next_range(vmg->vmi); } @@ -978,6 +999,8 @@ int vma_expand(struct vma_merge_struct *vmg) int ret; remove_next = true; + /* This should already have been checked by this point. */ + VM_WARN_ON(!can_merge_remove_vma(next)); vma_start_write(next); ret = dup_anon_vma(vma, next, &anon_dup); if (ret) diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index e465dc22e2d0..0c0a6ffcfc98 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -327,6 +327,9 @@ static bool test_vma_merge_new_vma(void) struct anon_vma_chain dummy_anon_vma_chain_d = { .anon_vma = &dummy_anon_vma, }; + const struct vm_operations_struct vm_ops = { + .close = dummy_close, + }; int count; struct vm_area_struct *vma, *vma_a, *vma_b, *vma_c, *vma_d; bool merged; @@ -370,6 +373,7 @@ static bool test_vma_merge_new_vma(void) * 0123456789abc * AA*B DD CC */ + vma_a->vm_ops = &vm_ops; /* This should have no impact. */ vma_b->anon_vma = &dummy_anon_vma; vma = try_merge_new_vma(&mm, &vmg, 0x2000, 0x3000, 2, flags, &merged); ASSERT_EQ(vma, vma_a); @@ -406,6 +410,7 @@ static bool test_vma_merge_new_vma(void) * AAAAA *DD CC */ vma_d->anon_vma = &dummy_anon_vma; + vma_d->vm_ops = &vm_ops; /* This should have no impact. */ vma = try_merge_new_vma(&mm, &vmg, 0x6000, 0x7000, 6, flags, &merged); ASSERT_EQ(vma, vma_d); /* Prepend. */ @@ -423,6 +428,7 @@ static bool test_vma_merge_new_vma(void) * 0123456789abc * AAAAA*DDD CC */ + vma_d->vm_ops = NULL; /* This would otherwise degrade the merge. */ vma = try_merge_new_vma(&mm, &vmg, 0x5000, 0x6000, 5, flags, &merged); ASSERT_EQ(vma, vma_a); /* Merge with A, delete D. */ @@ -573,120 +579,145 @@ static bool test_vma_merge_with_close(void) struct vma_merge_struct vmg = { .vmi = &vmi, }; - struct vm_operations_struct vm_ops = {}; - struct vm_area_struct *vma_next = - alloc_and_link_vma(&mm, 0x2000, 0x3000, 2, flags); - struct vm_area_struct *vma; + const struct vm_operations_struct vm_ops = { + .close = dummy_close, + }; + struct vm_area_struct *vma_prev, *vma_next, *vma; /* - * When we merge VMAs we sometimes have to delete others as part of the - * operation. - * - * Considering the two possible adjacent VMAs to which a VMA can be - * merged: - * - * [ prev ][ vma ][ next ] - * - * In no case will we need to delete prev. If the operation is - * mergeable, then prev will be extended with one or both of vma and - * next deleted. - * - * As a result, during initial mergeability checks, only - * can_vma_merge_before() (which implies the VMA being merged with is - * 'next' as shown above) bothers to check to see whether the next VMA - * has a vm_ops->close() callback that will need to be called when - * removed. - * - * If it does, then we cannot merge as the resources that the close() - * operation potentially clears down are tied only to the existing VMA - * range and we have no way of extending those to the nearly merged one. - * - * We must consider two scenarios: - * - * A. + * When merging VMAs we are not permitted to remove any VMA that has a + * vm_ops->close() hook. * - * vm_ops->close: - - !NULL - * [ prev ][ vma ][ next ] - * - * Where prev may or may not be present/mergeable. - * - * This is picked up by a specific check in can_vma_merge_before(). - * - * B. - * - * vm_ops->close: - !NULL - * [ prev ][ vma ] - * - * Where prev and vma are present and mergeable. - * - * This is picked up by a specific check in vma_merge_modified(). - * - * IMPORTANT NOTE: We make the assumption that the following case: + * This is because executing this hook may clear state that is pertinent + * to the VMA range as a whole. + */ + + /* + * The only case of a new VMA merge that results in a VMA being deleted + * is one where both the previous and next VMAs are merged - in this + * instance the next VMA is deleted, and the previous VMA is extended. * - * - !NULL NULL - * [ prev ][ vma ][ next ] + * If we are unable to do so, we reduce the operation to simply + * extending the prev VMA and not merging next. * - * Cannot occur, because vma->vm_ops being the same implies the same - * vma->vm_file, and therefore this would mean that next->vm_ops->close - * would be set too, and thus scenario A would pick this up. + * 0123456789 + * PPP**NNNN + * -> + * 0123456789 + * PPPPPPNNN */ - ASSERT_NE(vma_next, NULL); + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma_next = alloc_and_link_vma(&mm, 0x5000, 0x9000, 5, flags); + vma_next->vm_ops = &vm_ops; + + vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); + ASSERT_EQ(vma_merge_new_vma(&vmg), vma_prev); + ASSERT_EQ(vma_prev->vm_start, 0); + ASSERT_EQ(vma_prev->vm_end, 0x5000); + ASSERT_EQ(vma_prev->vm_pgoff, 0); + + ASSERT_EQ(cleanup_mm(&mm, &vmi), 2); /* - * SCENARIO A + * When modifying an existing VMA there are further cases where we + * delete VMAs. + * + * <> + * 0123456789 + * PPPVV * - * 0123 - * *N + * In this instance, if vma has a close hook, the merge simply cannot + * proceed. */ - /* Make the next VMA have a close() callback. */ - vm_ops.close = dummy_close; - vma_next->vm_ops = (const struct vm_operations_struct *)&vm_ops; + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, flags); + vma->vm_ops = &vm_ops; - /* Our proposed VMA has characteristics that would otherwise be merged. */ - vmg_set_range(&vmg, 0x1000, 0x2000, 1, flags); + vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); + vmg.prev = vma_prev; + vmg.vma = vma; - /* The next VMA having a close() operator should cause the merge to fail.*/ - ASSERT_EQ(vma_merge_new_vma(&vmg), NULL); + ASSERT_EQ(vma_merge_modified(&vmg), NULL); - /* Now create the VMA so we can merge via modified flags */ - vmg_set_range(&vmg, 0x1000, 0x2000, 1, flags); - vma = alloc_and_link_vma(&mm, 0x1000, 0x2000, 1, flags); - vmg.vma = vma; + ASSERT_EQ(cleanup_mm(&mm, &vmi), 2); /* - * The VMA being modified in a way that would otherwise merge should - * also fail. + * This case is mirrored if merging with next. + * + * <> + * 0123456789 + * VVNNNN + * + * In this instance, if vma has a close hook, the merge simply cannot + * proceed. */ + + vma = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, flags); + vma_next = alloc_and_link_vma(&mm, 0x5000, 0x9000, 5, flags); + vma->vm_ops = &vm_ops; + + vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); + vmg.vma = vma; + ASSERT_EQ(vma_merge_modified(&vmg), NULL); - /* SCENARIO B + ASSERT_EQ(cleanup_mm(&mm, &vmi), 2); + + /* + * Finally, we consider two variants of the case where we modify a VMA + * to merge with both the previous and next VMAs. * - * 0123 - * P* + * The first variant is where vma has a close hook. In this instance, no + * merge can proceed. * - * In order for this scenario to trigger, the VMA currently being - * modified must also have a .close(). + * <> + * 0123456789 + * PPPVVNNNN */ - /* Reset VMG state. */ - vmg_set_range(&vmg, 0x1000, 0x2000, 1, flags); + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, flags); + vma_next = alloc_and_link_vma(&mm, 0x5000, 0x9000, 5, flags); + vma->vm_ops = &vm_ops; + + vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); + vmg.prev = vma_prev; + vmg.vma = vma; + + ASSERT_EQ(vma_merge_modified(&vmg), NULL); + + ASSERT_EQ(cleanup_mm(&mm, &vmi), 3); + /* - * Make next unmergeable, and don't let the scenario A check pick this - * up, we want to reproduce scenario B only. + * The second variant is where next has a close hook. In this instance, + * we reduce the operation to a merge between prev and vma. + * + * <> + * 0123456789 + * PPPVVNNNN + * -> + * 0123456789 + * PPPPPNNNN */ - vma_next->vm_ops = NULL; - vma_next->__vm_flags &= ~VM_MAYWRITE; - /* Allocate prev. */ - vmg.prev = alloc_and_link_vma(&mm, 0, 0x1000, 0, flags); - /* Assign a vm_ops->close() function to VMA explicitly. */ - vma->vm_ops = (const struct vm_operations_struct *)&vm_ops; + + vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, flags); + vma_next = alloc_and_link_vma(&mm, 0x5000, 0x9000, 5, flags); + vma_next->vm_ops = &vm_ops; + + vmg_set_range(&vmg, 0x3000, 0x5000, 3, flags); + vmg.prev = vma_prev; vmg.vma = vma; - /* Make sure merge does not occur. */ - ASSERT_EQ(vma_merge_modified(&vmg), NULL); - cleanup_mm(&mm, &vmi); + ASSERT_EQ(vma_merge_modified(&vmg), vma_prev); + ASSERT_EQ(vma_prev->vm_start, 0); + ASSERT_EQ(vma_prev->vm_end, 0x5000); + ASSERT_EQ(vma_prev->vm_pgoff, 0); + + ASSERT_EQ(cleanup_mm(&mm, &vmi), 2); + return true; } @@ -699,6 +730,9 @@ static bool test_vma_merge_modified(void) struct vma_merge_struct vmg = { .vmi = &vmi, }; + const struct vm_operations_struct vm_ops = { + .close = dummy_close, + }; /* * Merge right case - partial span. @@ -711,7 +745,9 @@ static bool test_vma_merge_modified(void) * VNNNNNN */ vma = alloc_and_link_vma(&mm, 0x2000, 0x6000, 2, flags); + vma->vm_ops = &vm_ops; /* This should have no impact. */ vma_next = alloc_and_link_vma(&mm, 0x6000, 0x9000, 6, flags); + vma_next->vm_ops = &vm_ops; /* This should have no impact. */ vmg_set_range(&vmg, 0x3000, 0x6000, 3, flags); vmg.vma = vma; vmg.prev = vma; @@ -743,6 +779,7 @@ static bool test_vma_merge_modified(void) */ vma = alloc_and_link_vma(&mm, 0x2000, 0x6000, 2, flags); vma_next = alloc_and_link_vma(&mm, 0x6000, 0x9000, 6, flags); + vma_next->vm_ops = &vm_ops; /* This should have no impact. */ vmg_set_range(&vmg, 0x2000, 0x6000, 2, flags); vmg.vma = vma; vma->anon_vma = &dummy_anon_vma; @@ -768,7 +805,9 @@ static bool test_vma_merge_modified(void) * PPPPPPV */ vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma_prev->vm_ops = &vm_ops; /* This should have no impact. */ vma = alloc_and_link_vma(&mm, 0x3000, 0x7000, 3, flags); + vma->vm_ops = &vm_ops; /* This should have no impact. */ vmg_set_range(&vmg, 0x3000, 0x6000, 3, flags); vmg.prev = vma_prev; vmg.vma = vma; @@ -800,6 +839,7 @@ static bool test_vma_merge_modified(void) * PPPPPPP */ vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma_prev->vm_ops = &vm_ops; /* This should have no impact. */ vma = alloc_and_link_vma(&mm, 0x3000, 0x7000, 3, flags); vmg_set_range(&vmg, 0x3000, 0x7000, 3, flags); vmg.prev = vma_prev; @@ -827,6 +867,7 @@ static bool test_vma_merge_modified(void) * PPPPPPPPPP */ vma_prev = alloc_and_link_vma(&mm, 0, 0x3000, 0, flags); + vma_prev->vm_ops = &vm_ops; /* This should have no impact. */ vma = alloc_and_link_vma(&mm, 0x3000, 0x7000, 3, flags); vma_next = alloc_and_link_vma(&mm, 0x7000, 0x9000, 7, flags); vmg_set_range(&vmg, 0x3000, 0x7000, 3, flags);