From nobody Mon Feb 9 20:31:49 2026 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1475B3112BD for ; Sun, 18 Jan 2026 14:52:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768747979; cv=fail; b=i8WXxeaNc2c9jJEfV6oZlfF+uJWejp02k3W64xI72ZtcHs1GDkY225cUlH9twBsaYi9zuRX2br+rfpYeQ4zjCvt2xN5zeFkaGGqj2M6+Nd1GXxATGGqQcGTOEyfGcSFtu0EM4sqmEpxM8GUIZ/irQrxw5wSi8f06oJ+vUg95Hhc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768747979; c=relaxed/simple; bh=0tx+QiLczBdFU1TYrx7sfHU3SPXnfZJH1dcUqqLCVKo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=OrC5KhJj87STKW93n+gQtLLuXr9ccp57UjayTdHIyuGLdF0vE0t7+8aoriicWsO2RyHbUxJQRIrxpkolajTMuEixYSWNfRMx4jutmVbdk28w6G4BNr46q/yWhCvU/ryquetRnHt1fK8kiH7hU6IbvBTovvGLT+KELPiJA7MZhJQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=cTm3Tg+H; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=l3B3mChu; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="cTm3Tg+H"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="l3B3mChu" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 60IEoFTo3690593; Sun, 18 Jan 2026 14:51:49 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-2025-04-25; bh=i8ZBwvo3FR/dBKpFyyh00VweLyM7/LYGelOu70S7kPo=; b= cTm3Tg+HozVqIfMbE1WxkWzOojoTeSLGBgMN2bAx7tyrj3+tSFTGRIoNk93krdm4 cwLv4WtdHC+aZqWRAiN3n3F5AVPWY5UN7DpCxSQTJ3unbWdY2GIc8huOhdBKJQQT 9C6ebf5heEO3A4hBXUumRZzkvGJIwUU6lULNqDiox9K9iYBDqRu2T7ERzuujs71v nxIYFBa2bXsMRaWgdUvmGxq7hXECxh6Np2XZmopZuPMrxuFuXpyK52NJsWkG7LNb Pbx6Fo8AxwRJXDbX1jCndVqo/cYYu1nFoK/0ZxdlIg1MS/hOivEwQtqvj2G3dbCt x22y/Ir2cqSnT4CBtgUUsA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4br0u9hcdr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 18 Jan 2026 14:51:48 +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 60IBt4ce032145; Sun, 18 Jan 2026 14:51:48 GMT Received: from dm1pr04cu001.outbound.protection.outlook.com (mail-centralusazon11010064.outbound.protection.outlook.com [52.101.61.64]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4br0vb7ctx-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 18 Jan 2026 14:51:48 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AWMK92q8sI/X0acrlFbjuZoe3OSDzzI8jLEg6HNitzjNO5I7hQ2BLJO/6sR8MeXKmEvtOrKAuKIJsTJNfwdFGhU00qzypF7EMH22FZVw0z77RU+Ow71j5oyydCfIfv7T2LgtPjlT9LbsGqltB5StHnIFHeHEC+kqxAAcM6X/84yeIOEiwLzauDbOql3VQW3XTE6oarWxHwz6JChYewIciLt2SVi01KSFd+eTYnmvWp0yzQrDdZGTYCuu+irfJ3002lIK2iKW5cpPbjZMd82ZLJAIPfoJYGQJ1Gn0gxtAAkTu2CZOwqZjFJ1xMJ9EZ6eSXWsYcgh3P+9ZA8XATZ+rVA== 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=i8ZBwvo3FR/dBKpFyyh00VweLyM7/LYGelOu70S7kPo=; b=KlTZQpU0alqFE8xZunjBtprPfh7ARw0cgDUVAUxHHDtvdlWwT6mrL98mDOBFNrc7vnGfcSTUJxRmiyLUSL34OgQtsYioNFifFMV28wqBbYGf4ln+lOWlrrcWAVKKxNlQE5puihyxFYy0IipPEgK+Zn3CTRcW4AvgNQwyU9kRZL/dgW9btPmENel1XflvZvFI6qppr8kSUzySLmd9EgXq7H+dTeu+QTnDfxc/2998uV7YRqlKzmEJ+AU5qZZl3VkbEtJ15oEfLhAHw5z9wVC/60/5jdlxsz/qjklILyegsDBsulUif5LZGAfn7Rlsp0orjhEMlZ+OLvyZQyBre4m0pA== 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=i8ZBwvo3FR/dBKpFyyh00VweLyM7/LYGelOu70S7kPo=; b=l3B3mChugrF/CM/M5H2RlJ+JM9YFd+MezsKDlVyA5FlxyD5M61te7UkU/D4HhjpFCq5KdLn6YGkQfAzFV2ZlmNGbCEXF3/NJ9Y0Nk8trzPBcAn8hzRhz3bneSPE/zv+a2RjL04A5s47kCVu/NX94d25jWClhircD2n4Eph6Zql4= Received: from BL4PR10MB8229.namprd10.prod.outlook.com (2603:10b6:208:4e6::14) by IA0PR10MB6723.namprd10.prod.outlook.com (2603:10b6:208:43f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9520.11; Sun, 18 Jan 2026 14:51:46 +0000 Received: from BL4PR10MB8229.namprd10.prod.outlook.com ([fe80::552b:16d2:af:c582]) by BL4PR10MB8229.namprd10.prod.outlook.com ([fe80::552b:16d2:af:c582%6]) with mapi id 15.20.9520.005; Sun, 18 Jan 2026 14:51:46 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Suren Baghdasaryan , "Liam R . Howlett" , Vlastimil Babka , Shakeel Butt , David Hildenbrand , Rik van Riel , Harry Yoo , Jann Horn , Mike Rapoport , Michal Hocko , Pedro Falcato , Chris Li , Barry Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/9] mm/rmap: improve anon_vma_clone(), unlink_anon_vmas() comments, add asserts Date: Sun, 18 Jan 2026 14:50:37 +0000 Message-ID: <8644e89369be0cc89d7ac57443dff9e822803c91.1768746221.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO4P123CA0235.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a7::6) To BL4PR10MB8229.namprd10.prod.outlook.com (2603:10b6:208:4e6::14) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL4PR10MB8229:EE_|IA0PR10MB6723:EE_ X-MS-Office365-Filtering-Correlation-Id: 599d50e4-48bf-456e-234a-08de56a11a0b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?eT0QXWJ7AA0HgycOGI5jsNM5gnW/wuB+qP03KeD4dk7pPXMwhGEV81KNOJ8p?= =?us-ascii?Q?6pFP+nVLlXphcm6+m5AW3dlGxFovylwcY4bHyzA4y8p8TyKfzYONyfACCsAn?= =?us-ascii?Q?Wkap64isAo4/UDMur28GgXgiVcBGhhqMAR85sdunwjnrd5f686gWpd0j8eCq?= =?us-ascii?Q?GpUsx4K0DGZ6Uc/JWfitC8Btg4pqFxLvCVYafY0P85GwEPl9ZCr/sQNu1lYd?= =?us-ascii?Q?mKyjOG1TYe4g5DP4L37djSGnO1DPxNnPbrdFrur8PtGczzalhbluwv3TpKgy?= =?us-ascii?Q?K74TYi9LTFHfmiIxJsHHz/BEsy/i5xOzkOR0dlBYvsqDSNbOK73IjPbreqea?= =?us-ascii?Q?U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gx16KOSEwe0adGu22v?= =?us-ascii?Q?2fSmEQo8bp4gGGIoPUgHxDSANb8yOLQt9X8qR7psGoUKH7KAD3GjUXJmfYrM?= =?us-ascii?Q?xOC1wTUdyGhnfLyjcuiigATxP/1SA6sqojFdUdE63WLVJl6fXxGQMV1kztiU?= =?us-ascii?Q?21ASe9dtFxjMaBRnHKIk92D9VGI5EZl1kSh7jcoLQmCT2VurH6uCaoEPG5Td?= =?us-ascii?Q?v4MrEQ1OnMEwTHwyaUDhjUPcdZhbbJzxHrQFCxpp9xG+mpfc2YoTCRdL8hhz?= =?us-ascii?Q?juLC7pe8VQqX2OOvCey/j6B3beKNWFgyCX7ow6FlLmaUJ40FHeMGkD/oCuUb?= =?us-ascii?Q?EjxgwFRTIRukcOlkHC8=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BL4PR10MB8229.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?gs9ZPgR3PTsJ6asihU7r2WypKTXyt+f3JtMyhZIzAd/Kplew8yJI7OrYlkPa?= =?us-ascii?Q?urD+JRb4Xv/OK/L3Om3uYMme5GWC7UXBapQ3mUYL/1uBp4wtersxl9KJD+6h?= =?us-ascii?Q?cgXp6aj1YE+v1fHzqUBsQ1w9ngA6jBPilkmLhk+D8t+D75iT973ECFK/pqeE?= =?us-ascii?Q?rKjiTtz7EfNuzfnG/UDW4yPS/Jkl0yC6wsGGRqzWHTopBVVpWlyfNofM6Zdw?= =?us-ascii?Q?lyoC1AI6dsGRmnurkze4p7Qf0rXslzrXsRWwHaYh4ZwlG+TYWad8MWPl9UQY?= =?us-ascii?Q?IbcHGTKv8lC5DRsp8cYSz23ONRmO0sPyW6TRJJReTlP8BalP96zG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NCXkQKRN/VdHV+V1UeRhQeiNRlWvpyE9eQQ23mdYsICnDFoxgpXoL87cdaAXA+AAKmDNbty3qfUfdKrWvL+TtSNbXuSIxG23pU+krfyUSnl129OgujY1E0wSN8KK+zL6CHRCsQjHwjkyfWZEQtJ0zL3t79Ql4ClIHuLFxjlyqLvM2ZP1IXiRLAWQ2XkrzfelguzqoLuP9pBsxSaJW3V7cUpQy2ACOGO49QMSNS4HtiBoeqCb1QwzlN9QQxa1haykCxrxulc8c8a7Fg20Fg2CXifhjzsdu7sb801SQSghWpk1dGc2N4d2XMyU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 599d50e4-48bf-456e-234a-08de56a11a0b X-MS-Exchange-CrossTenant-AuthSource: BL4PR10MB8229.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2026 14:51:46.1052 (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: 2jWMw9fJpYeNVlr+7FLAGuBqZhM9X5mrNhSXum8F+bh6SCw94X9U6WeYCuXpcwJCUhDCm+fGx5nJ3phFpdbNcZLernXBSYrwDb2Y2uBUqBw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB6723 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2026-01-17_03,2026-01-15_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 bulkscore=0 adultscore=0 spamscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2601150000 definitions=main-2601180130 X-Authority-Analysis: v=2.4 cv=OJUqHCaB c=1 sm=1 tr=0 ts=696cf384 b=1 cx=c_pps a=e1sVV491RgrpLwSTMOnk8w==:117 a=e1sVV491RgrpLwSTMOnk8w==:17 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=z/mQ4Ysz8XfWz/Q5cLBRGdckG28=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=xqWC_Br6kY4A:10 a=vUbySO9Y5rIA:10 a=GoEa3M9JfhUA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=TS5ZMjQafXG62o6CVrQA:9 cc=ntf awl=host:13654 X-Proofpoint-GUID: etE5OhbUMQa83ODW-kA7R1ovmYlAZBOc X-Proofpoint-ORIG-GUID: etE5OhbUMQa83ODW-kA7R1ovmYlAZBOc X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwMTE4MDEzMSBTYWx0ZWRfX/VcCe6Jp0Mu8 C7v/eSB+U2FMSnbqRqIXRL85HZpHbzAmQD/XWInY0yw/jmyGMvJX/1yFaQ4+KJq4RQJ4Ye1oWTE 96JqRqc4boGIC1l1pcHHFqWQXqg08wYyxeVFKFNsZb7oG/DCOTOn++O1ft7zZR7+JqxmOx+dJhn tXx9zyqCwFWEoDsHnh409wel3X4kn7v66CUpoCCOBoM9Kw6YEkNdtguyvqz/R+ZQNqEfP5SZUVz PlxzRQAelomxHo079b0A+v0jSCbeEEXzJgeN0JYCt2an/A9Or07S7k44Ynwj9R6XxkKNKwNwIAN +ZqYn5huHXu25mHxR9IfT7dtBpau52uD9Dtl/WKtKJJM3VREH0pga6oEj/gEgsmJC0b9pS2cFqj tS+PLFoXYC+Zou/stnoFmmBfUkhIA5eSAmwkbMYERW/RLfIbEHoJtvfYOjJmjharusC+wlTGdK6 HlvcLZw/8/YZbqcdX0m8nPRJ4/CbZHyKoyaxcFTM= Content-Type: text/plain; charset="utf-8" Add kdoc comments and describe exactly what these functions are used for in detail, pointing out importantly that the anon_vma_clone() !dst->anon_vma && src->anon_vma dance is ONLY for fork. Both are confusing functions that will be refactored in a subsequent patch but the first stage is establishing documentation and some invariants. Add some basic CONFIG_DEBUG_VM asserts that help document expected state, specifically: anon_vma_clone() - mmap write lock held. - We do nothing if src VMA is not faulted. - The destination VMA has no anon_vma_chain yet. - We are always operating on the same active VMA (i.e. vma->anon_vma). - If not forking, must operate on the same mm_struct. unlink_anon_vmas() - mmap lock held (write lock except when freeing page tables). - That unfaulted VMAs are no-ops. We are presented with a special case when anon_vma_clone() fails to allocate memory, where we have a VMA with partially set up anon_vma state. Since we hold the exclusive mmap write lock, and since we are cloning from a source VMA which consequently can't also have its anon_vma state modified, we know no anon_vma referenced can be empty. This allows us to significantly simplify this case and just remove anon_vma_chain objects associated with the VMA, so we add a specific partial cleanup path for this scenario. This also allows us to drop the hack of setting vma->anon_vma to NULL before unlinking anon_vma state in this scenario. Signed-off-by: Lorenzo Stoakes Reviewed-by: Liam R. Howlett --- mm/rmap.c | 133 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 107 insertions(+), 26 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 262bebe6f947..cdb7618c10b1 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -258,30 +258,62 @@ static inline void unlock_anon_vma_root(struct anon_v= ma *root) up_write(&root->rwsem); } =20 -/* - * Attach the anon_vmas from src to dst. - * Returns 0 on success, -ENOMEM on failure. - * - * anon_vma_clone() is called by vma_expand(), vma_merge(), __split_vma(), - * copy_vma() and anon_vma_fork(). The first four want an exact copy of sr= c, - * while the last one, anon_vma_fork(), may try to reuse an existing anon_= vma to - * prevent endless growth of anon_vma. Since dst->anon_vma is set to NULL = before - * call, we can identify this case by checking (!dst->anon_vma && - * src->anon_vma). - * - * If (!dst->anon_vma && src->anon_vma) is true, this function tries to fi= nd - * and reuse existing anon_vma which has no vmas and only one child anon_v= ma. - * This prevents degradation of anon_vma hierarchy to endless linear chain= in - * case of constantly forking task. On the other hand, an anon_vma with mo= re - * than one child isn't reused even if there was no alive vma, thus rmap - * walker has a good chance of avoiding scanning the whole hierarchy when = it - * searches where page is mapped. +static void check_anon_vma_clone(struct vm_area_struct *dst, + struct vm_area_struct *src) +{ + /* The write lock must be held. */ + mmap_assert_write_locked(src->vm_mm); + /* If not a fork (implied by dst->anon_vma) then must be on same mm. */ + VM_WARN_ON_ONCE(dst->anon_vma && dst->vm_mm !=3D src->vm_mm); + + /* If we have anything to do src->anon_vma must be provided. */ + VM_WARN_ON_ONCE(!src->anon_vma && !list_empty(&src->anon_vma_chain)); + VM_WARN_ON_ONCE(!src->anon_vma && dst->anon_vma); + /* We are establishing a new anon_vma_chain. */ + VM_WARN_ON_ONCE(!list_empty(&dst->anon_vma_chain)); + /* + * On fork, dst->anon_vma is set NULL (temporarily). Otherwise, anon_vma + * must be the same across dst and src. + */ + VM_WARN_ON_ONCE(dst->anon_vma && dst->anon_vma !=3D src->anon_vma); +} + +static void cleanup_partial_anon_vmas(struct vm_area_struct *vma); + +/** + * anon_vma_clone - Establishes new anon_vma_chain objects in @dst linking= to + * all of the anon_vma objects contained within @src anon_vma_chain's. + * @dst: The destination VMA with an empty anon_vma_chain. + * @src: The source VMA we wish to duplicate. + * + * This is the heart of the VMA side of the anon_vma implementation - we i= nvoke + * this function whenever we need to set up a new VMA's anon_vma state. + * + * This is invoked for: + * + * - VMA Merge, but only when @dst is unfaulted and @src is faulted - mean= ing we + * clone @src into @dst. + * - VMA split. + * - VMA (m)remap. + * - Fork of faulted VMA. + * + * In all cases other than fork this is simply a duplication. Fork additio= nally + * adds a new active anon_vma. + * + * ONLY in the case of fork do we try to 'reuse' existing anon_vma's in an + * anon_vma hierarchy, reusing anon_vma's which have no VMA associated wit= h them + * but do have a single child. This is to avoid waste of memory when repea= tedly + * forking. + * + * Returns: 0 on success, -ENOMEM on failure. */ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src) { struct anon_vma_chain *avc, *pavc; struct anon_vma *root =3D NULL; =20 + check_anon_vma_clone(dst, src); + list_for_each_entry_reverse(pavc, &src->anon_vma_chain, same_vma) { struct anon_vma *anon_vma; =20 @@ -315,14 +347,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct = vm_area_struct *src) return 0; =20 enomem_failure: - /* - * dst->anon_vma is dropped here otherwise its num_active_vmas can - * be incorrectly decremented in unlink_anon_vmas(). - * We can safely do this because callers of anon_vma_clone() don't care - * about dst->anon_vma if anon_vma_clone() failed. - */ - dst->anon_vma =3D NULL; - unlink_anon_vmas(dst); + cleanup_partial_anon_vmas(dst); return -ENOMEM; } =20 @@ -393,11 +418,67 @@ int anon_vma_fork(struct vm_area_struct *vma, struct = vm_area_struct *pvma) return -ENOMEM; } =20 +/* + * In the unfortunate case of anon_vma_clone() failing to allocate memory = we + * have to clean things up. + * + * On clone we hold the exclusive mmap write lock, so we can't race + * unlink_anon_vmas(). Since we're cloning, we know we can't have empty + * anon_vma's, since existing anon_vma's are what we're cloning from. + * + * So this function needs only traverse the anon_vma_chain and free each + * allocated anon_vma_chain. + */ +static void cleanup_partial_anon_vmas(struct vm_area_struct *vma) +{ + struct anon_vma_chain *avc, *next; + struct anon_vma *root =3D NULL; + + /* + * We exclude everybody else from being able to modify anon_vma's + * underneath us. + */ + mmap_assert_locked(vma->vm_mm); + + list_for_each_entry_safe(avc, next, &vma->anon_vma_chain, same_vma) { + struct anon_vma *anon_vma =3D avc->anon_vma; + + /* All anon_vma's share the same root. */ + if (!root) { + root =3D anon_vma->root; + anon_vma_lock_write(root); + } + + anon_vma_interval_tree_remove(avc, &anon_vma->rb_root); + list_del(&avc->same_vma); + anon_vma_chain_free(avc); + } + + if (root) + anon_vma_unlock_write(root); +} + +/** + * unlink_anon_vmas() - remove all links between a VMA and anon_vma's, fre= eing + * anon_vma_chain objects. + * @vma: The VMA whose links to anon_vma objects is to be severed. + * + * As part of the process anon_vma_chain's are freed, + * anon_vma->num_children,num_active_vmas is updated as required and, if t= he + * relevant anon_vma references no further VMAs, its reference count is + * decremented. + */ void unlink_anon_vmas(struct vm_area_struct *vma) { struct anon_vma_chain *avc, *next; struct anon_vma *root =3D NULL; =20 + /* Always hold mmap lock, read-lock on unmap possibly. */ + mmap_assert_locked(vma->vm_mm); + + /* Unfaulted is a no-op. */ + VM_WARN_ON_ONCE(!vma->anon_vma && !list_empty(&vma->anon_vma_chain)); + /* * Unlink each anon_vma chained to the VMA. This list is ordered * from newest to oldest, ensuring the root anon_vma gets freed last. --=20 2.52.0