From nobody Thu Nov 28 00:32:37 2024 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.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 E6BC73A8D2 for ; Sun, 6 Oct 2024 14:31:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728225108; cv=fail; b=JsIjgQ79fGfgmrgFm7o7qLzdahIAewwgq3TZwHvNI6XEzcOVHVXlHJ2LwMqf9afZL8ow8Sl7teO4c6BZQFVKlIKhv6AgGOSiBcMbT4osSJ7MDsiQp8x+cQZ4Vx6KUDh8YhLsY74uCZIwlnq0XB2rb6ivVwp+wvYcMOU5O+6Vu5E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728225108; c=relaxed/simple; bh=1H2KMb9qGIS2Ai9YNeYYe0gyaiwHEVcXggmOJ2wF5og=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=J1WMIJjaxfDPUI5YsomuLwcjXp0c4vyzqFH1mwTFL14DidFPUth+mS5eDVHzA3+60BXucysTbcrysfDHT6R8D0rdhdBN4WwTg0vy4yL0TN1vLT+jVlULvOp/RT4Rky6MSHERah299Z7BElDL9pmxJNEyWVW5WKpViedoNuU4jWA= 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=VYsZQh7+; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=b736EQUb; arc=fail smtp.client-ip=205.220.165.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="VYsZQh7+"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="b736EQUb" 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 496EC68n018991; Sun, 6 Oct 2024 14:31:24 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=7kVSLPU3S+DvH+QejgupjPx/n3kvGzT6vMAa/M7tGu4=; b= VYsZQh7+OcoWmRSewPaNYSy/40AI9lRxXhD3y2M8N0SZ4o/P+hE7ypebthQXj0xx YIHERoDjCynqtubQYs+TCnqGq4jBQSQi3LMLFxMnFG03+A8c5KSgG1b8Jf8e7yt8 M2T+Bm1XSr23MtfePDH9e0FblZpiVlmk4/s56RWsxTGOjamvbaHo3PwziKIqiljz 058L4o2pH57Edl62Msb35w3c8PlMofnC1UycjI+O47Qf0jz6ivO+oLbnV7jNPnkq AeEF2XwcV/b1yPwryaP9qRN6aScSOl1W8nlm53eWWnBjZxagKYAKEwqZpkr8dJ7C 4jvvwMHipfGexqQhhqfeFQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42302p9966-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 06 Oct 2024 14:31:23 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 496969MP001235; Sun, 6 Oct 2024 14:31:23 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2171.outbound.protection.outlook.com [104.47.57.171]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 422uw4xfwk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 06 Oct 2024 14:31:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ot4Jsa5CTJ/u+FarVnas1Gwe21a8CdwAUV/qQN4/vesKNHtUSkeLsz8hEj5ksMRzk2NsuNlrnIRnETVb2+0rvvjQUwTSJbyqd8Q94YWOOYFBdhExc0D8Y7qfvfCWwN+b6hRbVeQ4jkMP2HNZ9BQKmyvf3Bk+7GeIQFJO64XmanvtDfjtK9otysm49aSiiEy5Hx1/GIXX4CnZTekmrfOEHxCIJrLnlc8v9dVKTuUgFjyYX/9qwk2heboW07U3m6qkAJmk4yBg2OuivK3qbiNCLK8xz6yT7H+zJpr5NzRobyaVoaTwdgTtVouFEs1Q92zP/KW2QyOT3QI+CaoEL/RVBA== 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=7kVSLPU3S+DvH+QejgupjPx/n3kvGzT6vMAa/M7tGu4=; b=BZcTs5Qhucy7UT0F1RsXlIHcOX3bQFS+265bz72tXsm+sGStzbG7b4x/lEHWv6Y/51G9gP3Z80qLpHX5/WsxWZE8DljEVv9WsJOLsfh7Yod6uyo0VFcPqS3WKhGpoP8eyK63CUantZ1OzOOsiio+VYWQ81myEc5eEwvsLmQBlp0bx9jfF6/M/D2Y1BV9L56ehDsBQlsZ5lI9ng91lPy4vb/rr0qLfzafDZ+YrGfHzxAfYYCd7MHmj/Zt2B/eDP7XS2iZDlbhfi5NdkAjIF4PbQBApa8sY23yd9F2cmQtdCgv8WM51I/zIpwpOT51T3JWRWzSs4qVsx5fCnQjvsYZTg== 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=7kVSLPU3S+DvH+QejgupjPx/n3kvGzT6vMAa/M7tGu4=; b=b736EQUb05dY9AUNGxsgDM1VGVo/CJgA2HfpzCvqYP7/4ZW6bTIO1+LhgQ/A5HiytEeGLa+VDnLWuoIAYr8byoPGn02giNGwdoQT7lc/8+Cc4ZI9+gmdERVR4r+yfMxVA4uXxIxBJ3w9qBG/Z4agZRxbFJo99/jWePWxklFqC5A= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by PH8PR10MB6503.namprd10.prod.outlook.com (2603:10b6:510:229::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.21; Sun, 6 Oct 2024 14:31:20 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%5]) with mapi id 15.20.8026.019; Sun, 6 Oct 2024 14:31:20 +0000 From: Lorenzo Stoakes To: Andrew Morton , "Liam R . Howlett" Cc: Matthew Wilcox , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sidhartha Kumar , Bert Karwatzki , Mikhail Gavrilov , maple-tree@lists.infradead.org Subject: [PATCH v2 hotfix 6.12 1/2] maple_tree: correct tree corruption on spanning store Date: Sun, 6 Oct 2024 15:31:07 +0100 Message-ID: <964860c315780cf3a5b8929a34b68d8208333c16.1728223996.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO2P265CA0146.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::14) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) 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: SJ0PR10MB5613:EE_|PH8PR10MB6503:EE_ X-MS-Office365-Filtering-Correlation-Id: 1388fe6d-c0d4-4d0a-3448-08dce6138bb1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?U2PrAMTGBweTijD0Xytp+lOcX8TEMeFZXmorL9YXbeM9gIzR1NFSnE6t1SHz?= =?us-ascii?Q?2y4a88T/0dYSwhKTmsF3gO166uHytodA0hg44bLoOkHVoJFHqTI2T7Zyxmzz?= =?us-ascii?Q?/nBmtncD/n1RwRt+4aQqJ+rExG7YtUPaE4Xv5pDI+RBXS2y0+AXzl4iNRN3+?= =?us-ascii?Q?9TUM5oGTlf6B/0eGS67yu+5EscvTmf9p8+7zNcWcV3uWqPlHL5B0X5WGtsQE?= =?us-ascii?Q?ODYjqA97LrxHZIyHvke2TLYDld/rNntQ4Ic7hyQL5Vek+4NKedraCl6p5rQA?= =?us-ascii?Q?es4CF835SUCoAGH95Hr7PqUVQ6kNXNaO1HIhpHJgUvxtgGU1eSlb2d7BYpXm?= =?us-ascii?Q?N+HD4I8YKNCHhM3cZQ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ascii?Q?=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?LxDhpKjd8nIoNQrnMr49BqoAEWLvHfQlRb9quHUro866xQHaOIwnCcBWDPYw?= =?us-ascii?Q?vftfOx74neZyh2ZjZagjVp+wGO13F3Z/isgrLBxglyiiQjik/PJGT1YgQ+xf?= =?us-ascii?Q?FyOqt6fS/WAT6gB+wMI6rgO3o4iFGyo22gNgk0vEfMq467+83KiHsoJuxHvq?= =?us-ascii?Q?z3GaTao1LhJYaaGyU/mKokI7UH/jKK+8mIMRxiO8vzesGPL3TFO1YxcuqEW+?= =?us-ascii?Q?fp2oEr8cU9BjSjOXATFOgp0bH0l6XsaZMDqdZWtstMlZiGuWijxTJ0dx9nUd?= =?us-ascii?Q?zMZt3k83zHIvyPfOGqFOE3hmG50Id/IvPvYi3DeOlkCdQj9r/8yex/RYJ6MK?= =?us-ascii?Q?Rbx07hcDEOVcSOLqUIymWueDFLlDVzgeziHs+f+YzCRqZ1wOE4c7VACqlQB2?= =?us-ascii?Q?tXL/NNPoc6liEdhKANqCma0Es85q7kCj4NqgIk67drCGEq5X8ixqCp3gmBtZ?= =?us-ascii?Q?oAIfXT1dmpEC85Npt3KeQf4sBFwCSTflcxcxid8K/C8oA+dnJeM+o7lG0Nhc?= =?us-ascii?Q?JdzpJUgeXHPp01QM4qw5vGuvkFftRHHd68wYKPUaH7c0Xj+eq1lBjpz+LOa/?= =?us-ascii?Q?eGkKuUaYLmC8TiDDFJkOzzMMoJ4441A5BUtPD//b9WNLhMcYvu9C29S5VVyw?= =?us-ascii?Q?zkMFUqd9Tb7Jh5oUX1DvBRZUPKRJczf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kc5RwZ7ZQHCiPmANcEhnn6sy2f4WWnLTpENeNQxt+NpYetvkw3jsHPuJh?= =?us-ascii?Q?DA=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: BzQs9ogl+NSNiGU+aprM/IQ1IMxkLqRsn8dYOPwkdwHJCdrJ47toEuxKFNNY0zmLqvyAEf8SfQ7NEOHno2/QMXqDG5B/mWqlfn0LWWRRwrkGAvJhlzIMqjUfCDqeW322+Es9amDVjFvi2uGbxjR0clvcs+57eV9LLBseNet9IymwIJ1qv2dZJv/Wn/wkbv7ZeCOw+A0aCAbTJh5FkdbUf600fi2BJkp9m6CxDZcIVDcXLcmNgZkE9j2FWzl43GfECfkjW5BEOVZ5ZUMQQx2yfF8sr11pggeFhALzHnp86c6XNaItuQNPu9b9/Fkb5VkoAOWupwHBAMIVwRgMPWfShAaGOq/kODnYtYQH6Yc1CGucZSM2t6+ly3nw1hnwyQMj2xjcB4cYlLdGpj9U5H/YDrKWDH5NJHPdDUUFKkRc21MUWvYF9zKqy+vWqfNk+EkmvRUN+FzQ80CfaBlLVS4RVDSgA0QxsN1aQ3xfNSytpItPhiaB292/PyqMY1c3EyajbzCPvONZIaQYf+EnVMaqB+ijoiNBVL9pv693cFOgX9pf2frMi0WNCbB71rYemVyv9np+A+gm3URCriLFbTLu+6uj8uE8hRigByOTqxKoehY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1388fe6d-c0d4-4d0a-3448-08dce6138bb1 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Oct 2024 14:31:20.3439 (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: DOPTd/3YBkdaJ7AZCgzKF+S6VAoudrNTv/9wN7DXBjKA/mAzMYxjO99busoZdgxV2k5vI2gpyGVTnm2FMJWkJtCRFDGP1dcMQhqsTWqkCEI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR10MB6503 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-06_11,2024-10-04_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 suspectscore=0 adultscore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410060105 X-Proofpoint-ORIG-GUID: -5Ui-MUO9r24yUa2Z12x08gL2BhBZztk X-Proofpoint-GUID: -5Ui-MUO9r24yUa2Z12x08gL2BhBZztk Content-Type: text/plain; charset="utf-8" There has been a subtle bug present in the maple tree implementation from its inception. This arises from how stores are performed - when a store occurs, it will overwrite overlapping ranges and adjust the tree as necessary to accommodate this. A range may always ultimately span two leaf nodes. In this instance we walk the two leaf nodes, determine which elements are not overwritten to the left and to the right of the start and end of the ranges respectively and then rebalance the tree to contain these entries and the newly inserted one. This kind of store is dubbed a 'spanning store' and is implemented by mas_wr_spanning_store(). In order to reach this stage, mas_store_gfp() invokes mas_wr_preallocate(), mas_wr_store_type() and mas_wr_walk() in turn to walk the tree and update the object (mas) to traverse to the location where the write should be performed, determining its store type. When a spanning store is required, this function returns false stopping at the parent node which contains the target range, and mas_wr_store_type() marks the mas->store_type as wr_spanning_store to denote this fact. When we go to perform the store in mas_wr_spanning_store(), we first determine the elements AFTER the END of the range we wish to store (that is, to the right of the entry to be inserted) - we do this by walking to the NEXT pivot in the tree (i.e. r_mas.last + 1), starting at the node we have just determined contains the range over which we intend to write. We then turn our attention to the entries to the left of the entry we are inserting, whose state is represented by l_mas, and copy these into a 'big node', which is a special node which contains enough slots to contain two leaf node's worth of data. We then copy the entry we wish to store immediately after this - the copy and the insertion of the new entry is performed by mas_store_b_node(). After this we copy the elements to the right of the end of the range which we are inserting, if we have not exceeded the length of the node (i.e. r_mas.offset <=3D r_mas.end). Herein lies the bug - under very specific circumstances, this logic can break and corrupt the maple tree. Consider the following tree: Height 0 Root Node / \ pivot =3D 0xffff / \ pivot =3D ULONG_MAX / \ 1 A [-----] ... / \ pivot =3D 0x4fff / \ pivot =3D 0xffff / \ 2 (LEAVES) B [-----] [-----] C ^--- Last pivot 0xffff. Now imagine we wish to store an entry in the range [0x4000, 0xffff] (note that all ranges expressed in maple tree code are inclusive): 1. mas_store_gfp() descends the tree, finds node A at <=3D0xffff, then determines that this is a spanning store across nodes B and C. The mas state is set such that the current node from which we traverse further is node A. 2. In mas_wr_spanning_store() we try to find elements to the right of pivot 0xffff by searching for an index of 0x10000: - mas_wr_walk_index() invokes mas_wr_walk_descend() and mas_wr_node_walk() in turn. - mas_wr_node_walk() loops over entries in node A until EITHER it finds an entry whose pivot equals or exceeds 0x10000 OR it reaches the final entry. - Since no entry has a pivot equal to or exceeding 0x10000, pivot 0xffff is selected, leading to node C. - mas_wr_walk_traverse() resets the mas state to traverse node C. We loop around and invoke mas_wr_walk_descend() and mas_wr_node_walk() in turn once again. - Again, we reach the last entry in node C, which has a pivot of 0xffff. 3. We then copy the elements to the left of 0x4000 in node B to the big node via mas_store_b_node(), and insert the new [0x4000, 0xffff] entry too. 4. We determine whether we have any entries to copy from the right of the end of the range via - and with r_mas set up at the entry at pivot 0xffff, r_mas.offset <=3D r_mas.end, and then we DUPLICATE the entry at pivot 0xffff. 5. BUG! The maple tree is corrupted with a duplicate entry. This requires a very specific set of circumstances - we must be spanning the last element in a leaf node, which is the last element in the parent node. spanning store across two leaf nodes with a range that ends at that shared pivot. A potential solution to this problem would simply be to reset the walk each time we traverse r_mas, however given the rarity of this situation it seems that would be rather inefficient. Instead, this patch detects if the right hand node is populated, i.e. has anything we need to copy. We can do this easily in mas_wr_walk_index() by detecting if the pivot is either 0 (shorthand for the end of the range) or the required index is less than or equal to the last encountered pivot. This change is made in mas_wr_walk_index() which is only used by the spanning store so it has minimal impact. The work performed in commit f8d112a4e657 ("mm/mmap: avoid zeroing vma tree in mmap_region()") seems to have made the probability of this event much more likely, which is the point at which reports started to be submitted concerning this bug. The motivation for this change arose from Bert Karwatzki's report of encountering mm instability after the release of kernel v6.12-rc1 which, after the use of CONFIG_DEBUG_VM_MAPLE_TREE and similar configuration options, was identified as maple tree corruption. After Bert very generously provided his time and ability to reproduce this event consistently, I was able to finally identify that the issue discussed in this commit message was occurring for him. Reported-and-tested-by: Bert Karwatzki Closes: https://lore.kernel.org/all/20241001023402.3374-1-spasswolf@web.de/ Reported-by: Mikhail Gavrilov Closes: https://lore.kernel.org/all/CABXGCsOPwuoNOqSMmAvWO2Fz4TEmPnjFj-b7iF= +XFRu1h7-+Dg@mail.gmail.com/ Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Lorenzo Stoakes Acked-by: Vlastimil Babka --- lib/maple_tree.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 20990ecba2dd..f72e1a5a4dfa 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -2196,6 +2196,8 @@ static inline void mas_node_or_none(struct ma_state *= mas, /* * mas_wr_node_walk() - Find the correct offset for the index in the @mas. + * If @mas->index cannot be found within the containi= ng + * node, we traverse to the last entry in the node. * @wr_mas: The maple write state * * Uses mas_slot_locked() and does not need to worry about dead nodes. @@ -3532,6 +3534,12 @@ static bool mas_wr_walk(struct ma_wr_state *wr_mas) return true; } +/* + * Traverse the maple tree until the offset of mas->index is reached. + * + * Return: Is this node actually populated with entries possessing pivots = equal + * to or greater than mas->index? + */ static bool mas_wr_walk_index(struct ma_wr_state *wr_mas) { struct ma_state *mas =3D wr_mas->mas; @@ -3540,8 +3548,11 @@ static bool mas_wr_walk_index(struct ma_wr_state *wr= _mas) mas_wr_walk_descend(wr_mas); wr_mas->content =3D mas_slot_locked(mas, wr_mas->slots, mas->offset); - if (ma_is_leaf(wr_mas->type)) - return true; + if (ma_is_leaf(wr_mas->type)) { + unsigned long pivot =3D wr_mas->pivots[mas->offset]; + + return pivot =3D=3D 0 || mas->index <=3D pivot; + } mas_wr_walk_traverse(wr_mas); } @@ -3701,6 +3712,7 @@ static noinline void mas_wr_spanning_store(struct ma_= wr_state *wr_mas) struct maple_big_node b_node; struct ma_state *mas; unsigned char height; + bool r_populated; /* Left and Right side of spanning store */ MA_STATE(l_mas, NULL, 0, 0); @@ -3742,7 +3754,7 @@ static noinline void mas_wr_spanning_store(struct ma_= wr_state *wr_mas) r_mas.last++; r_mas.index =3D r_mas.last; - mas_wr_walk_index(&r_wr_mas); + r_populated =3D mas_wr_walk_index(&r_wr_mas); r_mas.last =3D r_mas.index =3D mas->last; /* Set up left side. */ @@ -3766,7 +3778,7 @@ static noinline void mas_wr_spanning_store(struct ma_= wr_state *wr_mas) /* Copy l_mas and store the value in b_node. */ mas_store_b_node(&l_wr_mas, &b_node, l_mas.end); /* Copy r_mas into b_node. */ - if (r_mas.offset <=3D r_mas.end) + if (r_populated && r_mas.offset <=3D r_mas.end) mas_mab_cp(&r_mas, r_mas.offset, r_mas.end, &b_node, b_node.b_end + 1); else -- 2.46.2 From nobody Thu Nov 28 00:32:37 2024 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.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 3CDA2AD55 for ; Sun, 6 Oct 2024 14:31:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728225108; cv=fail; b=KOSkYH4Cemx6CO+K8UpNRXThjm1U7vIl1x9LoSrE++f583V1lgcyYrhu3g+HNXPqLEO4LSwygD2Li77sEdr8F6WycayX7lNqfAWczgba8Wf8z/pL4VWLxmPQwriw+WweA2RQPf4iYjeyZ+MbohZLvUK2+FMMcOnFiLhbdHXFfTs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728225108; c=relaxed/simple; bh=s3vdWToQLynOhjrZS6JTUlFGNZPIyrvMirD/R+1macI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=Mqdjwt12FPoEV/FmkWsM+v+xsG6qBO8mDuJ3imRjHTAzCMhyOs9QNpp5WqEl9gy+OW3hfSEqRrMyw0+2Lz45kc42uEfdu9wQLszwCFJm/BzbTOm52j+jgbKIfNyoB0X64f2oNb0rnstf46fVVCpcRyeKXDTN9sH07Z0Mfe1bc4Y= 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=fmLUYvAj; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=iVJ6OCAP; arc=fail smtp.client-ip=205.220.165.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="fmLUYvAj"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="iVJ6OCAP" 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 4966XX8B004608; Sun, 6 Oct 2024 14:31:26 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=sk/AdneOvcPd+6OW0+cMIAMxl2oHVeqmx8xLwcLve40=; b= fmLUYvAjxOxLBKzW7tbBiOMQhmcT4UcRbJht2ocYRmewREAAYL0iiianOcohYqhj LcSqSVQU7UtgYb4PW6EhTl6fMsx8U1A9AHNZevPdJHM5q2nmbBx8M0+4JoOGd9+S /lYVYJsPohOC0XV0i4JNGrV2wxnvi2cBTrYeT4JKCZXTWeV0SxCHbzKt1fVdY28h Wp4MmhGDmEkSZ2oL+BSJsYp8dwT17IyWKrbj2a/VrOL3uu/ntKPENHbF3hxlLDT5 mw2L2mcmvHOBiKrClBbvW0CzzJqAHHLeP/AFeXyOBaakVJRPX7YgW5JIQb9Sifml Rkrl7reyEF/xzZhVnWK0EA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42302p9968-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 06 Oct 2024 14:31:26 +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 4969Z03Y012028; Sun, 6 Oct 2024 14:31:25 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2173.outbound.protection.outlook.com [104.47.56.173]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 422uw4x515-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 06 Oct 2024 14:31:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fJoe0pQR2HZ9+DNUi1/cqekY6yDicIGXWXGazfKuT+HiBw2TEqpd7OjYyFo2BkebaCJ09LlQirBHCp4QpwqBAExJz8WQSETJsKCzC+o61Qis9Q4guifTF9qkRKsfC4/IA4pL9fCyGOflmH4qlHMVALZ4QjGQD54vXtaV6Uz8J0r3Ubhi83oXN8JD14hQhMDTLV+C54SiWYHuUhIZ3WIsLyzvN3nIft9yGEF30trWwcwh8OXR7rZ+gf5loACYkfm2mD9rFGZWnaRJu6y9BQuCIU5ZBYWTSArm0lfS6v8dH1O27piNht5y7XlP4EvLIpcspbiE3l1ZDZzdX4EU0TVAxA== 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=sk/AdneOvcPd+6OW0+cMIAMxl2oHVeqmx8xLwcLve40=; b=N1O7OwbsZ0y0Byf7lERSJrB9QKxMaPqF2zKQe6RkrgFJaK9lo8dDjUsvlyAGQtI+B22rzk2fxLfCG8knoGYH4Sd5YPDfsbIAO41sNMmaHlkXasGD19nlY/5cRiUvFNQpQHq7SHlyPbfIXeVydKLJXGSyU/bCEXgXLhV85MpCOk9A8+wuoUPXhgv5QN1mUbfpovp/yPChYkIPRd08SdwY4kmJNhamUo4KVshTMoV/2a6PqSy+Dcys6fl7IbkDIwEGZPmUZpV/uG2uaScrBcOZovxnn7D2/IEKClALiN4fITCC+ks9tKG2LmjlMaRmHwUETPRNKFRxEp/7k60o8m2EZQ== 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=sk/AdneOvcPd+6OW0+cMIAMxl2oHVeqmx8xLwcLve40=; b=iVJ6OCAPsG1vlP4mIv96XDwBo15tCQNFqv+AVp8OF0L2kmCcz3Z9/lDKT87h16sa5eVOO/F80E9voro2h3Vf3fjuHs7NXcSFfazhFa59ddt49+93GCNkO4ulKTfoB/UA3OAzbWmxcowBeprZcCl1B92y0iZjx+jWFuoCdkg785Q= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by PH8PR10MB6503.namprd10.prod.outlook.com (2603:10b6:510:229::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.21; Sun, 6 Oct 2024 14:31:23 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%5]) with mapi id 15.20.8026.019; Sun, 6 Oct 2024 14:31:23 +0000 From: Lorenzo Stoakes To: Andrew Morton , "Liam R . Howlett" Cc: Matthew Wilcox , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sidhartha Kumar , Bert Karwatzki , Mikhail Gavrilov , maple-tree@lists.infradead.org Subject: [PATCH v2 hotfix 6.12 2/2] maple_tree: add regression test for spanning store bug Date: Sun, 6 Oct 2024 15:31:08 +0100 Message-ID: <12af588c6b3338bf6a73cd2d95943a83a44c3b42.1728223996.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.2 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO2P265CA0147.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9::15) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) 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: SJ0PR10MB5613:EE_|PH8PR10MB6503:EE_ X-MS-Office365-Filtering-Correlation-Id: 802234f9-2ebd-4e3b-86f9-08dce6138d6a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?+9e4TBeP+wIfZbn40pWa5YTy3YHHZjnbo1BbpiuRIlMciG22kLrPcEXpxhMQ?= =?us-ascii?Q?Y4gaucfwCoy+J1rKi1z2N7D74LaF+kHk9dhdyF3EuhHz4PFKzGtmFidw/S/1?= =?us-ascii?Q?zDnFgg6qHSeUZ1iSF4I71FRW9EHU1+IQwZ/QH++As2gQ3EDf2degy81U5RhG?= =?us-ascii?Q?ZM4fOn0TCLHnJIPNvR35Lqb1C64XmR1GBjawDUCQGBvwsLd59jkvJTHwgiER?= =?us-ascii?Q?LEeJOmar+Klj1lN70HUEwNlUtymfOwHghkqP7EifW+oqlna80CDCwnldc21x?= =?us-ascii?Q?P1ui4w+wwNO7G74mrM/Ghk0P3bScenIW+UgmAAJEIMcXZXpKwpfvY/tvrhgz?= =?us-ascii?Q?EJBCyqRrRPq+GPbriG4QGd7MEbwNTWg6Fsvv6Qtph/ZRbGACx42hLlib3lGL?= =?us-ascii?Q?nJv+0Kutrc+SsyPAo42gAIRk/tIo/rH6wtdFGOqeO5xhKxCYvaL8AxcByoNz?= =?us-ascii?Q?of6qbv92nprZEn0msFZ3U7wJJnk8hTwhr10pxBB76UczBUupA4yhE06/Khj2?= =?us-ascii?Q?0qRLRrZVBZdlKyGkmWvM4ork22Q/8K5u1vfFBq2wPBwuhEPkbhNWCG1U6ov3?= =?us-ascii?Q?1AhtN0PkpnL8Ec3CzOeT+C43y0Mari5IkGKjtiRZf2DsTSr1zo3Bqq4nvoyG?= =?us-ascii?Q?N2f7q/eed8DV1wDjZEFicuZEXpEN0y/Ouda0b+neGkbkKW5K2F9ghWZesybS?= =?us-ascii?Q?jfsMeIqOLBsXlM+CF4ipmZEh1fKPwgZnOX6Fl7BwOK0rg5NFIj0XI89iWMzt?= =?us-ascii?Q?mnuMeYOxRDSn3/lU+4colSPHL3nneqdATiyAr5qkGwwjH5wnB5RmJRk70PyU?= =?us-ascii?Q?rk5ucjYTcwSB8r7W1qm0SSpIMXg5VDMXuLuu6NRF2cLf1dqgV1rp9q+X+amU?= =?us-ascii?Q?Q+2yOnXLJzRTQkWf3LFD1BpSro/roiBHsqNJfJe88nAh51Zurl01vlZPvj7l?= =?us-ascii?Q?zJZiP2XNHczcamL8PBqe52MyqCn47ICclAwUcaHi+tyXOIlq8On1ugo2520b?= =?us-ascii?Q?4LlGMklzOJDt+41UwGkgLCWjsHBAxw5x6aIJWRk5/XiKhHeBjIrAE8mj44w2?= =?us-ascii?Q?glSoXFTbgM+GG2pC0JVLxOLaSAA2fIgWgrqDg27kA/Ie01AEVY2X/8q4KVDn?= =?us-ascii?Q?6eN3+8ngl6n3n3s+ugDqlJt9K/S9xyyEpv9JChv8FvyxLanuTbg5OX7q0gHh?= =?us-ascii?Q?N53Zxe0JV5waSeDuB/byKzi3eQhIpawz9PFsmRwB+2hhVIm2xk9rmR+8U0Iz?= =?us-ascii?Q?COu+kJ8b3X1FhXEkUPj7iRa/I/swJY+Q2m8nncf8ug=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?zB2PlB7VQd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lS4uXSm5qw?= =?us-ascii?Q?dBg9orAk+Zz6QMSY8et+IqWWWqmMssklYgVJEro1yLKqPyHG6U6yxH8sj+ra?= =?us-ascii?Q?6qa/1BraLDiUjpm1pXrDWhp0opj6M1Qcdvmm+iRk+hsARL8q5EuI533FWK4r?= =?us-ascii?Q?3yrnH0SX40mZedQkAkfd1/RHoK967ZrQETgT7Z1rRDbb4Ah7WPZaJYhiBjA+?= =?us-ascii?Q?AuLXMlb2JZQEitFDF5h3JFbQAtSodAofCH89f7pttOW8eJHsI0tzjp40Z7OB?= =?us-ascii?Q?vfT3X2zwWg+rEtwZqyt+7b2EhBOK25brkzKpg+xajYCa4nxDBDAONUBnUTkS?= =?us-ascii?Q?JHRL5uJu1K2lDzTYWbWMiwcMtcQ2cprVH12HQNvWITIh9gaaTBgRycTnomWe?= =?us-ascii?Q?IB1vjYNGH+NSget1ltk4GSMEkV+6vxwuB8QDHhzQzM5rX/r43gsZ5dKssGU9?= =?us-ascii?Q?VZEaGaHY/b6Y+DOhK/umUKtW5ir5khnOrDL5yHvUcm9Yiygreq2BHRyISzF3?= =?us-ascii?Q?mi5Rf202y0BDIZ/wIJQhyivJUVtT7rSFGQiH8XkiIQN0eHRKtCN1aXwMzfxn?= =?us-ascii?Q?jdcd+BPy6cp6nYZH/Jj6ijcSadfosrQjBSy1JIPjPAAWJE2IgScEY8NoaksR?= =?us-ascii?Q?tziIGVNPU1acBBDDqTIq+/S+YYnwQFk2hA6i45a+uOG/kAgQM4yRBrJtepRj?= =?us-ascii?Q?5msnfDHQ0gijR+2JRQvGzxXKq3JADVQPV10L+VhlwIzy4Qu8/HCxvXAVcroi?= =?us-ascii?Q?JQ=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: zEXyT5uOn1aA/R5Zh/+8pshUGaOoKZ+ljbPGd4GAuamlp0EckttCXM31apXi+z1dPMgF1x7fiyE+bAjKSg2LXIo/qR/LQVnVitbc3d3V08rd/s8N6RMaRhECpxTyA3OrWN5vZSV5htdU00YVzdoD36RDHyTLfjH03JJk4MN0uymJhPAE7P04U5/JgVHAKI7UKDF52437KFE6SPIh9atbge7j/ixUTTlaSs5fa/WCcL9iZ/3Rdw1UT8qv6tPabYkBpMl/3TmGHB202YJRwzSvrNUnlprpmaq27U4aeZK35yDy+kKmamG8spzxIV7Zpd/HbDarcQG1FZQEHDP6EkKnZCH/TQX65jtbi4R5aUQYpsbRbA2yskMOXEVjdwLUNNMc7TUNrkZOnkbya0hjXY5nwtpnjRa1mXIyePKel3G5ZVbw9ZRNxuZy7jM7h2I1nQBO08+2vhGmYzIsWaAAnXQqhg7UMihw7LJ3EIOJ0ryy6eG+u4hwpfveT/2YlmBapYClNl/Yzeaa+liw/Hfc2o6rooGsh9kwvnIm5n1Q5ggDdNt/s04niVexc01+yHBa/Ign5Mwco/rtSBWvDNqkkMkWyBdZVYWQFfkYrljk1Dw842k= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 802234f9-2ebd-4e3b-86f9-08dce6138d6a X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Oct 2024 14:31:23.1874 (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: lCLYufe0L4EGC3CkQ99Nsnq7CPgXul/LY9X+4nC1iLcXaoQmC9CUvgQdPBnntPrT9MNG96xvjr0QBMEwpo9074Sz+5b0rUl9XudoMfsbqcs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR10MB6503 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-06_11,2024-10-04_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 phishscore=0 mlxscore=0 suspectscore=0 bulkscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410060105 X-Proofpoint-ORIG-GUID: 7fgNrj8yXV3IuNJGH-JI5wt2RG6ECY1n X-Proofpoint-GUID: 7fgNrj8yXV3IuNJGH-JI5wt2RG6ECY1n Content-Type: text/plain; charset="utf-8" Add a regression test to assert that, when performing a spanning store which consumes the entirety of the rightmost right leaf node does not result in maple tree corruption when doing so. This achieves this by building a test tree of 3 levels and establishing a store which ultimately results in a spanned store of this nature. Signed-off-by: Lorenzo Stoakes Acked-by: Vlastimil Babka --- tools/testing/radix-tree/maple.c | 84 ++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/ma= ple.c index 1873ddbe16cc..5fde09999be4 100644 --- a/tools/testing/radix-tree/maple.c +++ b/tools/testing/radix-tree/maple.c @@ -36406,9 +36406,93 @@ void farmer_tests(void) check_nomem(&tree); } +static unsigned long get_last_index(struct ma_state *mas) +{ + struct maple_node *node =3D mas_mn(mas); + enum maple_type mt =3D mte_node_type(mas->node); + unsigned long *pivots =3D ma_pivots(node, mt); + unsigned long last_index =3D mas_data_end(mas); + + BUG_ON(last_index =3D=3D 0); + + return pivots[last_index - 1] + 1; +} + +/* + * Assert that we handle spanning stores that consume the entirety of the = right + * leaf node correctly. + */ +static void test_spanning_store_regression(void) +{ + unsigned long from =3D 0, to =3D 0; + DEFINE_MTREE(tree); + MA_STATE(mas, &tree, 0, 0); + + /* + * Build a 3-level tree. We require a parent node below the root node + * and 2 leaf nodes under it, so we can span the entirety of the right + * hand node. + */ + build_full_tree(&tree, 0, 3); + + /* Descend into position at depth 2. */ + mas_reset(&mas); + mas_start(&mas); + mas_descend(&mas); + mas_descend(&mas); + + /* + * We need to establish a tree like the below. + * + * Then we can try a store in [from, to] which results in a spanned + * store across nodes B and C, with the maple state at the time of the + * write being such that only the subtree at A and below is considered. + * + * Height + * 0 Root Node + * / \ + * pivot =3D to / \ pivot =3D ULONG_MAX + * / \ + * 1 A [-----] ... + * / \ + * pivot =3D from / \ pivot =3D to + * / \ + * 2 (LEAVES) B [-----] [-----] C + * ^--- Last pivot to. + */ + while (true) { + unsigned long tmp =3D get_last_index(&mas); + + if (mas_next_sibling(&mas)) { + from =3D tmp; + to =3D mas.max; + } else { + break; + } + } + + BUG_ON(from =3D=3D 0 && to =3D=3D 0); + + /* Perform the store. */ + mas_set_range(&mas, from, to); + mas_store_gfp(&mas, xa_mk_value(0xdead), GFP_KERNEL); + + /* If the regression occurs, the validation will fail. */ + mt_validate(&tree); + + /* Cleanup. */ + __mt_destroy(&tree); +} + +static void regression_tests(void) +{ + test_spanning_store_regression(); +} + void maple_tree_tests(void) { #if !defined(BENCH) + regression_tests(); farmer_tests(); #endif maple_tree_seed(); -- 2.46.2