From patchwork Tue Apr 11 15:10:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 82033 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2663668vqo; Tue, 11 Apr 2023 08:32:23 -0700 (PDT) X-Google-Smtp-Source: AKy350aLLGlPAQB8/K/5pBBJt7QpPuDqDTMjZweWPDh4rjOwt6GQzuBAyfMY9yKgNFIYqm2GbWWG X-Received: by 2002:a05:6a20:4da8:b0:cc:cc27:9185 with SMTP id gj40-20020a056a204da800b000cccc279185mr12790107pzb.50.1681227143470; Tue, 11 Apr 2023 08:32:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681227143; cv=pass; d=google.com; s=arc-20160816; b=NHDTfn2gvLQfxc983oiWzHcujFSw8PAwV31Dv73bbL4BsTpxia9iELC2h+08SCBZeI tappaCNxbqA0FDacg1+SFj3SuB7MaNG30cVsQTsm4eQGkq3QLqH+n/07MaNas+LDGdS8 TQdj9TaWAQ01DHEe0Ge2l/fKfafhklascPlOQzwJjw87bz8E/YuISbHID4eZLTtvooL+ RZfVCgPDTkSZN452+CpyMo1uAdfLHQqL5jdyAyXRjiy5YIgzLMw69VxsCT3Xv9cP6Y0z ebVqWtBxl2Ti0TN5dtdspGOJcwh+r57ZRDVUjh+9+ynQWdNs7sRxC4FRzrg+jvHZPcyM m1nQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=Fg9T0m7X7w29GcvBtWyPWgaJzQWqhHR2/JH+eaFF9LE=; b=c+6gYyx9zrKptSvG7wtA1JLBtn9t3XscvB/g9eDytdvc+ouiP3qNw76WdMM83SRTYz lk+4q2OtULlVvN3D2l8MlOY6b7NnK0iPSRw/wqoab8iyTqDy16ALynebWl50hDynCh8A EbhGhJwTZ+q7+icD6reYoDegn2BfNlm6sEyMZyxrOZytY/1S7sbCUcx5RNzWwzPmDbbW HluMgkY+8xm3Ftw33NRVk7GFAfJnx9bLo3McbQ3T0j5wH3XGR8EatheDk4f+oTAQD1jE QmM/zTqG+xPxCdc4GDjlXz5XlTDWztBV/JUMZGKJAAe8R4QUotzxMEbuXDUJC+DgYrin D9dA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=A4GrUFiG; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=dedjmMCT; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s77-20020a632c50000000b005139a0984absi14544347pgs.654.2023.04.11.08.32.10; Tue, 11 Apr 2023 08:32:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=A4GrUFiG; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=dedjmMCT; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230303AbjDKPMx (ORCPT + 99 others); Tue, 11 Apr 2023 11:12:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230435AbjDKPMN (ORCPT ); Tue, 11 Apr 2023 11:12:13 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FA1D4C2C; Tue, 11 Apr 2023 08:11:59 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEwu5A022973; Tue, 11 Apr 2023 15:11:27 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-03-30; bh=Fg9T0m7X7w29GcvBtWyPWgaJzQWqhHR2/JH+eaFF9LE=; b=A4GrUFiGHC3sgpCTlnzlqio+Xr6xFWKf5LMZOpmmaM+NOn2350taFfHw94Hxqx4OxSVU KYQeoj10sDTuTW8dbsk4TvLQXlvPdoL7jX7KrJejNiBXCOHzcsvHlSTlYfOHAiii5MGV M6JnvZoDtfCjvPRNfpOZnlxjsU+knFahBSc/xFrzrNyj5wJp+lUESpmA4SIX8C+d9XRs e1sd3RyIwldhYKW3SX30q9R8NhL5Gw8w86cxePrEKyRcOX1LFYayWikdyP2St0ROAYB2 6zx1CdhX6XqHEbYmduicDyJoJbiWyKtUNkGtxJ9Jcf8v+yFT28hSS/hzYuxD7ioztRi2 pg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0bwdrvm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:27 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEQ4fN030631; Tue, 11 Apr 2023 15:11:26 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2101.outbound.protection.outlook.com [104.47.55.101]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3puw918d07-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nx5aSLVnpHnuamu6eI8MH8Y/CVaxHqUFGrK/Ix5EgeH6+NfezyDmp4PROlCWWaYF0llOmRc5aZ3fBsOUPIuhYelSrvdh1Bf5e70kWDeP31EmWykSyrDp1snl/lCr3051zePvReBnQrsxK334Rs4N8/orLF9NuP9GazN8TNKx+zOJOVvVFjaXV4Bedtka2zNEF2C/6pJ1SauKEO7E930aRAt4NrV8r0iX5lBqMQV0L/CRhg/iNCQChsDHYWkYUahgQU6h4/j0F2wn6A2RKgyfnDGDY6nLJ1Vyo9bmzQF6hXPMKGUNtZ9HS7qnYKJ8+R3qKF1tot374Q2YoD0MQ0ySPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Fg9T0m7X7w29GcvBtWyPWgaJzQWqhHR2/JH+eaFF9LE=; b=RtW7tmAp2hwfDz8wbWrKkrb960KYn5C28rekJ+PzE4h1ZBwXdQuZTsartkFBFPOGqIlrLyYHpnbtXOEwWL+RsDYBr3xtIbvbDCes4g3zmloM3BIbLu39Cs+eRi6jpsp0spTt2jeM79CeVUXBxv+IZ/lGwqMHOf/MleQPECl/tdKMppKXdhCuEEDrOiiqLoPLt7rEd+5doPrH44ZFBZbKx+kSt5/MPeat0ZV6au54hsC5IdwBH0XtC0gJrm1c+C1HxtxeFVwMpZOJIeAOzu1Xhobr8bYc+R+jsi0isYsK1na4BSRtr/mjgDcI9hmcm4fg7wACOlSt8lWjQXS3cL7GKg== 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=Fg9T0m7X7w29GcvBtWyPWgaJzQWqhHR2/JH+eaFF9LE=; b=dedjmMCTDj1gDfdp2du6TI09i8QrglRXn1qyKu7KyYlD9nz1zatUpGkmYBDlfvp//zGjAGsZSA+juc/Lo9ln2D4Gzsyy0UmQRVcf/YFlW7eiYINMm6JCIGUAImKTsRrMcqGa1dCCi30JB2I/KMJhvKIUruUHGBifYIGCyzsNdwQ= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by CY5PR10MB6120.namprd10.prod.outlook.com (2603:10b6:930:34::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.27; Tue, 11 Apr 2023 15:11:23 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da%7]) with mapi id 15.20.6277.035; Tue, 11 Apr 2023 15:11:23 +0000 From: "Liam R. Howlett" To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R. Howlett" , Liam Howlett , Jirka Hladky , Matthew Wilcox Subject: [PATCH 6.1 01/14] maple_tree: remove GFP_ZERO from kmem_cache_alloc() and kmem_cache_alloc_bulk() Date: Tue, 11 Apr 2023 11:10:42 -0400 Message-Id: <20230411151055.2910579-2-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411151055.2910579-1-Liam.Howlett@oracle.com> References: <20230411151055.2910579-1-Liam.Howlett@oracle.com> X-ClientProxiedBy: YT1PR01CA0135.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:2f::14) To SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR10MB3022:EE_|CY5PR10MB6120:EE_ X-MS-Office365-Filtering-Correlation-Id: 4690e2da-9dbc-4dbb-52f0-08db3a9f038f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(396003)(376002)(136003)(366004)(346002)(451199021)(38100700002)(36756003)(86362001)(316002)(26005)(6506007)(8936002)(5660300002)(6512007)(186003)(41300700001)(478600001)(6666004)(1076003)(2906002)(66556008)(66946007)(54906003)(8676002)(6486002)(966005)(2616005)(83380400001)(4326008)(66476007);DIR:OUT;SFP:1101; X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4690e2da-9dbc-4dbb-52f0-08db3a9f038f X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 15:11:23.8453 (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: IGqX3Be3QFRUrpVeHjWMKFTEULaUizDXgyKQsnLqyIujZt+vkWD8DMkRT23W6qhjG469ZQsUxiRQ17MAurCAsA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR10MB6120 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-11_10,2023-04-11_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 mlxscore=0 bulkscore=0 malwarescore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304110138 X-Proofpoint-ORIG-GUID: 7oL9yaXL_wjsNYL9kt4-TXh9E4iIaeXL X-Proofpoint-GUID: 7oL9yaXL_wjsNYL9kt4-TXh9E4iIaeXL X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762894433246487452?= X-GMAIL-MSGID: =?utf-8?q?1762894433246487452?= From: "Liam R. Howlett" commit 541e06b772c1aaffb3b6a245ccface36d7107af2 upstream. Preallocations are common in the VMA code to avoid allocating under certain locking conditions. The preallocations must also cover the worst-case scenario. Removing the GFP_ZERO flag from the kmem_cache_alloc() (and bulk variant) calls will reduce the amount of time spent zeroing memory that may not be used. Only zero out the necessary area to keep track of the allocations in the maple state. Zero the entire node prior to using it in the tree. This required internal changes to node counting on allocation, so the test code is also updated. This restores some micro-benchmark performance: up to +9% in mmtests mmap1 by my testing +10% to +20% in mmap, mmapaddr, mmapmany tests reported by Red Hat Link: https://bugzilla.redhat.com/show_bug.cgi?id=2149636 Link: https://lkml.kernel.org/r/20230105160427.2988454-1-Liam.Howlett@oracle.com Cc: stable@vger.kernel.org Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Liam Howlett Reported-by: Jirka Hladky Suggested-by: Matthew Wilcox (Oracle) --- lib/maple_tree.c | 80 +++++++++++++++++--------------- tools/testing/radix-tree/maple.c | 18 +++---- 2 files changed, 52 insertions(+), 46 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 69cb44b035ec..fd824b065ace 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -149,13 +149,12 @@ struct maple_subtree_state { /* Functions */ static inline struct maple_node *mt_alloc_one(gfp_t gfp) { - return kmem_cache_alloc(maple_node_cache, gfp | __GFP_ZERO); + return kmem_cache_alloc(maple_node_cache, gfp); } static inline int mt_alloc_bulk(gfp_t gfp, size_t size, void **nodes) { - return kmem_cache_alloc_bulk(maple_node_cache, gfp | __GFP_ZERO, size, - nodes); + return kmem_cache_alloc_bulk(maple_node_cache, gfp, size, nodes); } static inline void mt_free_bulk(size_t size, void __rcu **nodes) @@ -1123,9 +1122,10 @@ static inline struct maple_node *mas_pop_node(struct ma_state *mas) { struct maple_alloc *ret, *node = mas->alloc; unsigned long total = mas_allocated(mas); + unsigned int req = mas_alloc_req(mas); /* nothing or a request pending. */ - if (unlikely(!total)) + if (WARN_ON(!total)) return NULL; if (total == 1) { @@ -1135,27 +1135,25 @@ static inline struct maple_node *mas_pop_node(struct ma_state *mas) goto single_node; } - if (!node->node_count) { + if (node->node_count == 1) { /* Single allocation in this node. */ mas->alloc = node->slot[0]; - node->slot[0] = NULL; mas->alloc->total = node->total - 1; ret = node; goto new_head; } - node->total--; - ret = node->slot[node->node_count]; - node->slot[node->node_count--] = NULL; + ret = node->slot[--node->node_count]; + node->slot[node->node_count] = NULL; single_node: new_head: - ret->total = 0; - ret->node_count = 0; - if (ret->request_count) { - mas_set_alloc_req(mas, ret->request_count + 1); - ret->request_count = 0; + if (req) { + req++; + mas_set_alloc_req(mas, req); } + + memset(ret, 0, sizeof(*ret)); return (struct maple_node *)ret; } @@ -1174,21 +1172,20 @@ static inline void mas_push_node(struct ma_state *mas, struct maple_node *used) unsigned long count; unsigned int requested = mas_alloc_req(mas); - memset(reuse, 0, sizeof(*reuse)); count = mas_allocated(mas); - if (count && (head->node_count < MAPLE_ALLOC_SLOTS - 1)) { - if (head->slot[0]) - head->node_count++; - head->slot[head->node_count] = reuse; + reuse->request_count = 0; + reuse->node_count = 0; + if (count && (head->node_count < MAPLE_ALLOC_SLOTS)) { + head->slot[head->node_count++] = reuse; head->total++; goto done; } reuse->total = 1; if ((head) && !((unsigned long)head & 0x1)) { - head->request_count = 0; reuse->slot[0] = head; + reuse->node_count = 1; reuse->total += head->total; } @@ -1207,7 +1204,6 @@ static inline void mas_alloc_nodes(struct ma_state *mas, gfp_t gfp) { struct maple_alloc *node; unsigned long allocated = mas_allocated(mas); - unsigned long success = allocated; unsigned int requested = mas_alloc_req(mas); unsigned int count; void **slots = NULL; @@ -1223,24 +1219,29 @@ static inline void mas_alloc_nodes(struct ma_state *mas, gfp_t gfp) WARN_ON(!allocated); } - if (!allocated || mas->alloc->node_count == MAPLE_ALLOC_SLOTS - 1) { + if (!allocated || mas->alloc->node_count == MAPLE_ALLOC_SLOTS) { node = (struct maple_alloc *)mt_alloc_one(gfp); if (!node) goto nomem_one; - if (allocated) + if (allocated) { node->slot[0] = mas->alloc; + node->node_count = 1; + } else { + node->node_count = 0; + } - success++; mas->alloc = node; + node->total = ++allocated; requested--; } node = mas->alloc; + node->request_count = 0; while (requested) { max_req = MAPLE_ALLOC_SLOTS; - if (node->slot[0]) { - unsigned int offset = node->node_count + 1; + if (node->node_count) { + unsigned int offset = node->node_count; slots = (void **)&node->slot[offset]; max_req -= offset; @@ -1254,15 +1255,13 @@ static inline void mas_alloc_nodes(struct ma_state *mas, gfp_t gfp) goto nomem_bulk; node->node_count += count; - /* zero indexed. */ - if (slots == (void **)&node->slot) - node->node_count--; - - success += count; + allocated += count; node = node->slot[0]; + node->node_count = 0; + node->request_count = 0; requested -= count; } - mas->alloc->total = success; + mas->alloc->total = allocated; return; nomem_bulk: @@ -1271,7 +1270,7 @@ static inline void mas_alloc_nodes(struct ma_state *mas, gfp_t gfp) nomem_one: mas_set_alloc_req(mas, requested); if (mas->alloc && !(((unsigned long)mas->alloc & 0x1))) - mas->alloc->total = success; + mas->alloc->total = allocated; mas_set_err(mas, -ENOMEM); return; @@ -5740,6 +5739,7 @@ int mas_preallocate(struct ma_state *mas, void *entry, gfp_t gfp) void mas_destroy(struct ma_state *mas) { struct maple_alloc *node; + unsigned long total; /* * When using mas_for_each() to insert an expected number of elements, @@ -5762,14 +5762,20 @@ void mas_destroy(struct ma_state *mas) } mas->mas_flags &= ~(MA_STATE_BULK|MA_STATE_PREALLOC); - while (mas->alloc && !((unsigned long)mas->alloc & 0x1)) { + total = mas_allocated(mas); + while (total) { node = mas->alloc; mas->alloc = node->slot[0]; - if (node->node_count > 0) - mt_free_bulk(node->node_count, - (void __rcu **)&node->slot[1]); + if (node->node_count > 1) { + size_t count = node->node_count - 1; + + mt_free_bulk(count, (void __rcu **)&node->slot[1]); + total -= count; + } kmem_cache_free(maple_node_cache, node); + total--; } + mas->alloc = NULL; } EXPORT_SYMBOL_GPL(mas_destroy); diff --git a/tools/testing/radix-tree/maple.c b/tools/testing/radix-tree/maple.c index 2e91973fbaa6..aceb6011315c 100644 --- a/tools/testing/radix-tree/maple.c +++ b/tools/testing/radix-tree/maple.c @@ -172,11 +172,11 @@ static noinline void check_new_node(struct maple_tree *mt) if (!MAPLE_32BIT) { if (i >= 35) - e = i - 35; + e = i - 34; else if (i >= 5) - e = i - 5; + e = i - 4; else if (i >= 2) - e = i - 2; + e = i - 1; } else { if (i >= 4) e = i - 4; @@ -304,17 +304,17 @@ static noinline void check_new_node(struct maple_tree *mt) MT_BUG_ON(mt, mas.node != MA_ERROR(-ENOMEM)); MT_BUG_ON(mt, !mas_nomem(&mas, GFP_KERNEL)); MT_BUG_ON(mt, mas_allocated(&mas) != MAPLE_ALLOC_SLOTS + 1); - MT_BUG_ON(mt, mas.alloc->node_count != MAPLE_ALLOC_SLOTS - 1); + MT_BUG_ON(mt, mas.alloc->node_count != MAPLE_ALLOC_SLOTS); mn = mas_pop_node(&mas); /* get the next node. */ MT_BUG_ON(mt, mn == NULL); MT_BUG_ON(mt, not_empty(mn)); MT_BUG_ON(mt, mas_allocated(&mas) != MAPLE_ALLOC_SLOTS); - MT_BUG_ON(mt, mas.alloc->node_count != MAPLE_ALLOC_SLOTS - 2); + MT_BUG_ON(mt, mas.alloc->node_count != MAPLE_ALLOC_SLOTS - 1); mas_push_node(&mas, mn); MT_BUG_ON(mt, mas_allocated(&mas) != MAPLE_ALLOC_SLOTS + 1); - MT_BUG_ON(mt, mas.alloc->node_count != MAPLE_ALLOC_SLOTS - 1); + MT_BUG_ON(mt, mas.alloc->node_count != MAPLE_ALLOC_SLOTS); /* Check the limit of pop/push/pop */ mas_node_count(&mas, MAPLE_ALLOC_SLOTS + 2); /* Request */ @@ -322,14 +322,14 @@ static noinline void check_new_node(struct maple_tree *mt) MT_BUG_ON(mt, mas.node != MA_ERROR(-ENOMEM)); MT_BUG_ON(mt, !mas_nomem(&mas, GFP_KERNEL)); MT_BUG_ON(mt, mas_alloc_req(&mas)); - MT_BUG_ON(mt, mas.alloc->node_count); + MT_BUG_ON(mt, mas.alloc->node_count != 1); MT_BUG_ON(mt, mas_allocated(&mas) != MAPLE_ALLOC_SLOTS + 2); mn = mas_pop_node(&mas); MT_BUG_ON(mt, not_empty(mn)); MT_BUG_ON(mt, mas_allocated(&mas) != MAPLE_ALLOC_SLOTS + 1); - MT_BUG_ON(mt, mas.alloc->node_count != MAPLE_ALLOC_SLOTS - 1); + MT_BUG_ON(mt, mas.alloc->node_count != MAPLE_ALLOC_SLOTS); mas_push_node(&mas, mn); - MT_BUG_ON(mt, mas.alloc->node_count); + MT_BUG_ON(mt, mas.alloc->node_count != 1); MT_BUG_ON(mt, mas_allocated(&mas) != MAPLE_ALLOC_SLOTS + 2); mn = mas_pop_node(&mas); MT_BUG_ON(mt, not_empty(mn)); From patchwork Tue Apr 11 15:10:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 82029 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2661613vqo; Tue, 11 Apr 2023 08:29:55 -0700 (PDT) X-Google-Smtp-Source: AKy350Z7mmaetX6zA+Dp4qlHrXswqtXggB8/A6n39adI3XySyPsIVczcG/C+LhTq1EndDHLBuD6o X-Received: by 2002:a17:906:538d:b0:94a:582d:169f with SMTP id g13-20020a170906538d00b0094a582d169fmr8786086ejo.5.1681226995294; Tue, 11 Apr 2023 08:29:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681226995; cv=pass; d=google.com; s=arc-20160816; b=TNrvuuW+TzPXc1lkhO9PnyDEFJMmvVTFWhmfSXLjaAgF2YqbSOsRhRMWl2Oovtu7IM HYrJlbeeQt4/0ongHYr28PuJrPTRQSovoFZzHyX9dVUNARyHERJYuQOY2IhU4HlKF130 MdaJ+4IgRF5n4edW6LjMlLfabvorULztKKWsxjM1HZOk7UYP3TfJtFtYqpfNh1Fkkkst GdgLtb72rDBKSx7HSXZYwt5tsAbSBd6V0hM7xQESzg4wFiQ1Z0jdGqW8SxmXNRH9ESqv Ide0BHkPINPxYf8a8NWEQMqjrONJCg3M0i3+SN4a75BOTttRO+ykUosswMGc/ZACtHLU zbJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=1oOOUTfb248IgqNS+xJccQHN7l3v7SvGWHgke9MYpJ4=; b=bgGQSPMlM1yRCSx9l4ket3LMijEXCeXATnklxpxxCUBtZvuCNLSwsftF1MpzVocx09 92+SNJ6YuNYw1wnaZIbSvFW8X2qd49Y1HOL2V7/BwhMdrg9wDPO3dsu0sdQB2EQ3G6i6 Itf5UFEr8SSVVuNvd96yNoVRwo1j79T8VUzGjMuDAVZoaD/+Dr01/e/8Q0JuLsLufkd0 iE/hhS1LTe3/u67Qmfugf43VYO9HY93Xz0VC0HTr+m4btWFSFjVp4cZYMxMEAr4Ro8rL zUqMy5HohdK+4vHXOUNbbn87aDBYGdHkh4XKHuoiU6eankKLtlMavgVaxtVhoExoAMJV b6WA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=pg4X8opn; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=XFIHdVvq; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp9-20020a1709073e0900b0094e151454c2si684636ejc.47.2023.04.11.08.29.31; Tue, 11 Apr 2023 08:29:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=pg4X8opn; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=XFIHdVvq; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231158AbjDKPMe (ORCPT + 99 others); Tue, 11 Apr 2023 11:12:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230265AbjDKPMI (ORCPT ); Tue, 11 Apr 2023 11:12:08 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E29A75BA1; Tue, 11 Apr 2023 08:11:47 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEx01v023047; Tue, 11 Apr 2023 15:11:29 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-03-30; bh=1oOOUTfb248IgqNS+xJccQHN7l3v7SvGWHgke9MYpJ4=; b=pg4X8opnBVAUvGweLkT+OuQx/6hjXDOdAUsmQ9WQABfyzT4EOxyhpuF3fydyV62je8Vf 0MPXxj51m09E9FU6M0zbyjybqNCdAE3LZxOYyA/KncqpffN10BMiJmcZeseWzZxQkkkB G7QE+5H6xiWokZL1YfHRCuBNbsA31bR5WibdgToorZ1VHH5F9r18bIxHQg6Bh/boLJXd VMeFY3+F5NK8GV/42s0n3uGfZm+5/fHIwYXjQd4X7UQEVvmpRh5X7SSynhrbxDR3A4GB Zq0O2S2RHVVrCevxpAUM5ENXBKkUl4AyWdBc4gBI7vnuv0ntt0jfJLEIXgUH4UOAto9H 7g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0bwdrvp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:28 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEV8xL030604; Tue, 11 Apr 2023 15:11:28 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2104.outbound.protection.outlook.com [104.47.55.104]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3puw918d1h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mtJrRe9EgBHLa90AkNd07cZEmJeptKNKiYBkmPXfgTO1ODxmyIqGKzTH66TZZ7bU/ES4YDtP8ejvi4zg73/HWWJyZg0ajJ/FVmK5nmzxgTkn3uJ7UJ5sRM3Vh3RPu2QGBijbWAB5zXuIE9x6s7FQM6NZ+EUD218BCQ6OTTS5ZkwD+nd0tJJtVHG/iAKFUTLVubpK1sQ4rU7gUEqJmHKSAQHhzhAkNwW7CkQTXnSGqofAq5S45pdGZ5KoLASfzMlhlA8+Z/axAMFYzJaJdGfGc2KLc6rEWiehkUYqav2VEaxNqiKn8Glqb5PSA7WGDydMTKpVNAizkCyG6kGy8VWJEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1oOOUTfb248IgqNS+xJccQHN7l3v7SvGWHgke9MYpJ4=; b=M+Ybg4aQ9m9KLwTp2gt7+b745t0EraeXdj0SDpVH6YkKiSESaHGIYLeg5xyxYn2KtfRZUlWobDNYRniaAOpMY9tAYRf0Oqj70jKs27lwiFeImj/OVj7PpThuIb98VYZK5mmyn2lqEw39pXe+cdFbN/duUjKFjuC5FCQji/XVdzBsm7SlKLOB7E+upiwQnZNtVoIS138q7sKqd1RCaRpdEb0ijB2vX9gqiOT+yK7cu8wpkf4OsoAGJOX4v8BA30QKQ/fY7tX3w0lYN2GIuvEJyKmv+HEhwM/bxmtEMlrIdoJKCcmNY+2tNTbZwStw3PsvNHJ6yKOHyuAL9PGMxl7G8w== 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=1oOOUTfb248IgqNS+xJccQHN7l3v7SvGWHgke9MYpJ4=; b=XFIHdVvqIZp8419flTY5B0PSZx2wngseknfcrqQwelErnfWJRNf+rLIhXROsdNxGKmVnRDe5NHHUCkuJFTckZJR1CrWkRhFRp8N/ZM30GL7VgIktjEOW6PR1rMD7BP4glnLb+gizKpgnTEkf5t+g+F6DkKeHu6yFDb80Ps8sA0k= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by CY5PR10MB6120.namprd10.prod.outlook.com (2603:10b6:930:34::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.27; Tue, 11 Apr 2023 15:11:26 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da%7]) with mapi id 15.20.6277.035; Tue, 11 Apr 2023 15:11:26 +0000 From: "Liam R. Howlett" To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R. Howlett" , Stable@vger.kernel.org, "Liam R . Howlett" Subject: [PATCH 6.1 02/14] maple_tree: fix potential rcu issue Date: Tue, 11 Apr 2023 11:10:43 -0400 Message-Id: <20230411151055.2910579-3-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411151055.2910579-1-Liam.Howlett@oracle.com> References: <20230411151055.2910579-1-Liam.Howlett@oracle.com> X-ClientProxiedBy: YT4PR01CA0067.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:111::22) To SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR10MB3022:EE_|CY5PR10MB6120:EE_ X-MS-Office365-Filtering-Correlation-Id: 2042f5da-d54f-41af-3d4d-08db3a9f04e4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(396003)(376002)(136003)(366004)(346002)(451199021)(38100700002)(36756003)(86362001)(316002)(26005)(6506007)(8936002)(5660300002)(6512007)(186003)(41300700001)(478600001)(6666004)(1076003)(2906002)(107886003)(66556008)(66946007)(54906003)(8676002)(6486002)(966005)(2616005)(83380400001)(4326008)(66476007);DIR:OUT;SFP:1101; X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2042f5da-d54f-41af-3d4d-08db3a9f04e4 X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 15:11:26.0399 (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: 45gvSy/vd0XjocjDxi2MetBzSansUMotXV5Lm6JhjeuosX6zIzLFvboq5z+Gn/oVf4Yw/AkzT0pG3uR8PjfWaQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR10MB6120 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-11_10,2023-04-11_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 mlxscore=0 bulkscore=0 malwarescore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304110138 X-Proofpoint-ORIG-GUID: pncVu0SrkRU-YFmmzaZN2TVGQq9sFiip X-Proofpoint-GUID: pncVu0SrkRU-YFmmzaZN2TVGQq9sFiip X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762894278240722107?= X-GMAIL-MSGID: =?utf-8?q?1762894278240722107?= From: "Liam R. Howlett" commit 65be6f058b0eba98dc6c6f197ea9f62c9b6a519f upstream. Ensure the node isn't dead after reading the node end. Link: https://lkml.kernel.org/r/20230120162650.984577-3-Liam.Howlett@oracle.com Cc: Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index fd824b065ace..1ade7748cc9b 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4656,13 +4656,13 @@ static inline void *mas_next_nentry(struct ma_state *mas, pivots = ma_pivots(node, type); slots = ma_slots(node, type); mas->index = mas_safe_min(mas, pivots, mas->offset); + count = ma_data_end(node, type, pivots, mas->max); if (ma_dead_node(node)) return NULL; if (mas->index > max) return NULL; - count = ma_data_end(node, type, pivots, mas->max); if (mas->offset > count) return NULL; From patchwork Tue Apr 11 15:10:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 82024 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2655490vqo; Tue, 11 Apr 2023 08:20:44 -0700 (PDT) X-Google-Smtp-Source: AKy350ZXNSuHqMaUm8ogW348ZI8bSIJdNgoZpSl0vfrZRHIV1T3/0zVecfD3QKRG8REGKvMQkfQ1 X-Received: by 2002:aa7:9aeb:0:b0:63a:fae3:9890 with SMTP id y11-20020aa79aeb000000b0063afae39890mr512290pfp.24.1681226443611; Tue, 11 Apr 2023 08:20:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681226443; cv=pass; d=google.com; s=arc-20160816; b=BzeiOimRhtYvxktekb5yLN6Vtw3aRiX4Wa0EPccDJLc61oTa4Np6H7aJvGSr52If7C Kp/9AEqLhVl62cp6N8HVbLtFJmvNT3YZ8MoGyRnqKlPE3T5QVusxFu8tHLU8i0/2pLCN U8RRgSA85bG/7VtccCqJ+N99a7RlAyBhIl/w2YnS/IbqvpM+nnK7MWtyEd1d+IfsfLJO +EmaNW9RvzFos5jlvuvOY0rHrR082qXshvDWRVZR393Pq50CXNLi8D0SajvRHz0iTzi0 zLoybaMf6NowUZNt9b769LfaQpREBFuBYYfuIaV19N6rHQvlyBNxX62qHaWd1LXCD+QA qWwA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=Ncc5JoP9CP/6T60IokeCK6aY7GzhvHCWLWgIubZw00U=; b=uyxaqHgF3B1rDmu5PSxOMn9HMzZA/jWaGtffdgcMN8RUvrcPwYodwdw6phHVvrkzBN /mF7aiiwcWqTWWN0vBWMYxH/H91TzN1LObK36dX9YYYp2qyV/YixgqfaEnO6c3YtQC5v JgIAScz01fYL1BH7TEUqEjbpo2XhAETGxgi1euXqPdt7N3TiyZMpkL2wKyi2JW163Rz/ 1OQZZcT4a1WlQAYFiDZbgd3SjUo7Y7UxcnR0wzrBe3WE2URgsi9mL7xYEIkb8jJe1t/w fOEFMgfTT7SnU4gRken2wbj13yOIuxA2AiDpuLqPtbCZFWEiuIuv+cprY4PCxVaHB1ot AsBQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=Y8KvcD9W; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=QqUzSDM6; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 133-20020a63028b000000b0051b29733bc3si200289pgc.422.2023.04.11.08.20.29; Tue, 11 Apr 2023 08:20:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=Y8KvcD9W; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=QqUzSDM6; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231168AbjDKPMm (ORCPT + 99 others); Tue, 11 Apr 2023 11:12:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230422AbjDKPMJ (ORCPT ); Tue, 11 Apr 2023 11:12:09 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 851955B9D; Tue, 11 Apr 2023 08:11:52 -0700 (PDT) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33BF1tj6018377; Tue, 11 Apr 2023 15:11:32 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-03-30; bh=Ncc5JoP9CP/6T60IokeCK6aY7GzhvHCWLWgIubZw00U=; b=Y8KvcD9WCGySLMnkzW+R9SOLY5I64W1kew6UVURqFeSPqXnwTww8jW8roNDXb5NqByku zjXGVEV2sl7PYttEkublnrEnVVB/WhQvpCfEyXYkcDvWPeIPOC5BBNaxbRJF+G2/rwyh 7ooRzFIJnIFnVtcAHCEJymItS3g8y9fcwiBWAx90qfNyO+NIHpZgSvBMfLlBOCp6frWe rQbVStx/CboFWDXOpQ4I53HcQamhf8lRboCTupmAghC8Amb94d7+UyVP/Ly40XDbvBFV JUDQRd4tmrZQ718yUKBdo7pnKXtNHwKoOFrxIVa3U2pcAJ3SzsB5h54YBORWSRVrV2iW TQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0bvwr5w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:32 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEPpHv008084; Tue, 11 Apr 2023 15:11:31 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2045.outbound.protection.outlook.com [104.47.66.45]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3puwc4976c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OLip3fhb3/xsixGICv0YeL6gUoH+7YggeIPfSe0TMLf0wqmHFTzwB1bjxifqXBDaxwfzRt2VF6AM4RM72YfRoaZjspQjJfSHsCT1GZIV7d5R2yNw+cVc+9HzGaNbWAA1gsidEsGL8BIZBiI+wzPXz+hfrd7tDw3g4Sy7ezyLF1sdloupgu951/akAmZXVsiYadEFif3c2fCfkI8kxAL677LdG54/bFxtvSoXQTY+BbahBV5xZm+zfsigISkFVIBjuJSabt/Jp/hsS6AFSdiZ7c8pcQSoylcPyjlPbPq3b7hShNA+VjGSXzJPrdV+tdlrNxPb7Tz8URCkhRIkAUchDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ncc5JoP9CP/6T60IokeCK6aY7GzhvHCWLWgIubZw00U=; b=EXDm2GEoJQTDsXDUEjdoX0J7vX9kAVHcZIUJq6se/QzUQ9dJ/YIA42cIKtixuWi2Co07fzb5QVOICOzi62ez8YyCj6mKUkJoLCtxtcgHKCa79MBlkhJiF2Tht9A3XVPozF6Vm38HqjzVb2w1vx9sjebeogVJh0OMc6fjCEhm00DCNhYiilHNQ6KK2jJIxHahlR62T/Gl++miAhNcO6zIbWluFjf9gFNDEn4csQZ/R6YJzgrdvJIymfLw49oD9fQsHVbt8hl52uDm4k4K/edsCZf5uCUS7VNQTPuk429Upl4a04yCmGbr706sgA5OMv+T0l3i2Z/h3eb0xOEI/2mjjA== 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=Ncc5JoP9CP/6T60IokeCK6aY7GzhvHCWLWgIubZw00U=; b=QqUzSDM6uIH3rklADPf94OvP6jxQh2iKTv5oyNHMWyGG+1eQ9k1K2yp5yxQxawu1wdyDtcTPzL56gZbzp18PBg6i7sRpDeVmb+OLY0hKZo4CWqfgas+TDm0O4sRAgPBQ3WwiDycZjCBQyBK43kzNCYhqYkhteX18xNUBb/VVbd8= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by CY5PR10MB6120.namprd10.prod.outlook.com (2603:10b6:930:34::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.27; Tue, 11 Apr 2023 15:11:28 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da%7]) with mapi id 15.20.6277.035; Tue, 11 Apr 2023 15:11:28 +0000 From: "Liam R. Howlett" To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R. Howlett" , Stable@vger.kernel.org, "Liam R . Howlett" Subject: [PATCH 6.1 03/14] maple_tree: reduce user error potential Date: Tue, 11 Apr 2023 11:10:44 -0400 Message-Id: <20230411151055.2910579-4-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411151055.2910579-1-Liam.Howlett@oracle.com> References: <20230411151055.2910579-1-Liam.Howlett@oracle.com> X-ClientProxiedBy: YT4P288CA0048.CANP288.PROD.OUTLOOK.COM (2603:10b6:b01:d3::25) To SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR10MB3022:EE_|CY5PR10MB6120:EE_ X-MS-Office365-Filtering-Correlation-Id: b76c830f-f4f4-447d-aef3-08db3a9f0661 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(396003)(376002)(136003)(366004)(346002)(451199021)(38100700002)(36756003)(86362001)(316002)(26005)(6506007)(8936002)(5660300002)(6512007)(186003)(41300700001)(478600001)(6666004)(1076003)(2906002)(107886003)(66556008)(66946007)(54906003)(8676002)(6486002)(966005)(2616005)(83380400001)(4326008)(66476007);DIR:OUT;SFP:1101; X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b76c830f-f4f4-447d-aef3-08db3a9f0661 X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 15:11:28.5547 (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: 3AOfcycjbHBy0hxVijQQXLGmkGwkLgeVsfpAk4ozWa/x5KZph5+ns+TLpTS738gx2gog305EwypYRJ3bsL3YUA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR10MB6120 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-11_10,2023-04-11_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 adultscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304110138 X-Proofpoint-GUID: Co-of1uw6AXEjJWqNsK5PQa7Xc8G7O7I X-Proofpoint-ORIG-GUID: Co-of1uw6AXEjJWqNsK5PQa7Xc8G7O7I X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762893699456960629?= X-GMAIL-MSGID: =?utf-8?q?1762893699456960629?= From: "Liam R. Howlett" commit 50e81c82ad947045c7ed26ddc9acb17276b653b6 upstream. When iterating, a user may operate on the tree and cause the maple state to be altered and left in an unintuitive state. Detect this scenario and correct it by setting to the limit and invalidating the state. Link: https://lkml.kernel.org/r/20230120162650.984577-4-Liam.Howlett@oracle.com Cc: Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 1ade7748cc9b..819ba692940e 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4737,6 +4737,11 @@ static inline void *mas_next_entry(struct ma_state *mas, unsigned long limit) unsigned long last; enum maple_type mt; + if (mas->index > limit) { + mas->index = mas->last = limit; + mas_pause(mas); + return NULL; + } last = mas->last; retry: offset = mas->offset; @@ -4843,6 +4848,11 @@ static inline void *mas_prev_entry(struct ma_state *mas, unsigned long min) { void *entry; + if (mas->index < min) { + mas->index = mas->last = min; + mas_pause(mas); + return NULL; + } retry: while (likely(!mas_is_none(mas))) { entry = mas_prev_nentry(mas, min, mas->index); From patchwork Tue Apr 11 15:10:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 82035 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2668828vqo; Tue, 11 Apr 2023 08:40:36 -0700 (PDT) X-Google-Smtp-Source: AKy350aH18ayiZtww2VHPxYeOcZ0s/4hJ7E+PglZvJ3SlxV40ClDlY/vOjYvqidjKPVo0qVNO3GG X-Received: by 2002:a05:6a20:7aa3:b0:eb:69c3:38b4 with SMTP id u35-20020a056a207aa300b000eb69c338b4mr823656pzh.56.1681227635976; Tue, 11 Apr 2023 08:40:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681227635; cv=pass; d=google.com; s=arc-20160816; b=ePBYj0G5tpFoBkFJ5KOe/9JON5nMLY4Ac2+VratQ7AHSVke41IEEGJa5hdEXSDjdSp FE89GJYdOjX+OjwG/gSsSjBEwbasczJIhL62HNTDJEHOjBHEoxjMkp6/dKOBwjv//CSc XkJy166iWgrplW6Yc64zxvHOQaJjY+PEIgFAL3xUid7cjskATyTHDthp7c5Hue15kLaO P92rsRQwsmil/7iIut3aahyIXk0e4SSLLoaPs2SxvOd3/BldMBHaRSBKNpG64DSL6pZ1 EYtHYmCuN/b7Xot0LMn6crHQRipaw9kJ68R8kVZG2/Jjdf53aZRbN4sg0tBzDYy0cbjB Q6uw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=PDBjrlh+TRcUjgAfuYBeZMR5kawflhtWx3wWP5Go75U=; b=XytBig90WPAqiJkmyncccHw30/KcxEG65g5UF4h2eSSiRQR2vUdpnFAPEJPuNUInzE FJWDCFeL5HERNYYmjynyD+/SH55lUH+w6BmkTeXuxo6XOnu3Jl5CVustHIf9boZpmXMH nDmPuc2ZgH9DF6sO4gNNYAeGSXrlxnQINfcQmxRf0wM9jBPUePppU09LiOKgZFdVY0tA yD0EcdLuy7eop6AHSCNUoOT7u3dTBGiid2/K+CReVPY4ybHc9A553101lgp/Uvow1Tvk oO3JNLzT3ZmwppBSw9aiG3n+7eBEZeOBJ1BDdyLGybN51fDOkGNmAAu8iOujoc15jgIy CItg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=zt4XAEDB; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=cMEBvDma; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j14-20020a63fc0e000000b0051254e55499si13077539pgi.245.2023.04.11.08.40.23; Tue, 11 Apr 2023 08:40:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=zt4XAEDB; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=cMEBvDma; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231181AbjDKPMu (ORCPT + 99 others); Tue, 11 Apr 2023 11:12:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230483AbjDKPML (ORCPT ); Tue, 11 Apr 2023 11:12:11 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0E4F5270; Tue, 11 Apr 2023 08:11:57 -0700 (PDT) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33BF1Vjc017666; Tue, 11 Apr 2023 15:11:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-03-30; bh=PDBjrlh+TRcUjgAfuYBeZMR5kawflhtWx3wWP5Go75U=; b=zt4XAEDBnVEWTynpnx97DZ+4ylr9Wel0ZljRe+WnAZFdMR4B48fwAvMmT9JFCj6s+P/l ucEADgct55u6mKi0m+3cSEJoRDZMWGniwxA1hjSkY7I/bEOniRniEiyxZeY+8R3qdo0n 3HjiI1VVo36cY8YSnYU2G0YNcPIPPvhdoVDY9M0ZntPF57M82GqAuueXUf6pNkjcLs12 CVmzXKOTKdwGFPb8YCSSJib5TKERcRsagUzKl1Gtkp/XLL1mtnAzyB7a391KCdjI7beB 2gypuTJb6O8uGWsi635ie3IQMXcZBQCfUcmD5ajj454OTrxgsRKmfaVQoTwb1jUjHFOZ ZQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0bvwr61-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:34 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEUx3C010013; Tue, 11 Apr 2023 15:11:33 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2048.outbound.protection.outlook.com [104.47.66.48]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3puw870rgt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gYPcxgtWbMhNpMI2n1zT3yGxYzBGQm9wTwTWadBEDwE55Vvq1+jVQL90pblXLWxgdvkoikdu9EZYOuDsHkIaQA73A4d/2jYRtxspN0Y0ekdD7hhwpPq43rINyBOyFQyyjomawEl7ROfMZztg6SntvSK1akYzxJcaCH9KUKLaU2bLv7lapVaTYkS2FxvTqov8ov3jH9Ek49X/+qS6rkE/m80GtS6BRYt9DnxNSOp/v3ndaZNuHn0L9R54fw+6Sm6MB2mc/KabcudXD7e99kPk+VahvGKpDuK6vItliDavHjaeYnnyfi7stLyBB8Qw2JAtociiKKGZcKWpfxf7N2ETGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=PDBjrlh+TRcUjgAfuYBeZMR5kawflhtWx3wWP5Go75U=; b=c50Y4P/778kxbtKCACYg28hKpfJJtWa9CBluhSyF/R1aCiCYSOl312PO2DURq9WX3xL6LaBwuCqYUoqCdn4XDaOEQ0Drf0aV/DXmaT3fNibYk9vqjA21h9tl9mH1I9lWoE7hPSEdIUQ9z/rTrvzTgIX2QFuXH0IICJIlLyjxB6Zi8+JdEeUYfh25IYAxoXfPdm/JptBMz619CM6HE8VTGxCgfGgfmUGgCcykIPcQm+Xq8mwVJCAqdhFYKBkzzoiyzI/kRDec+CW0QFdINslZovzeRo0ccDmj7uWKqda1WXpWw+zh5/wvelvtswglTmPpa/3JcM2DUWiRRvX/ZmBWaA== 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=PDBjrlh+TRcUjgAfuYBeZMR5kawflhtWx3wWP5Go75U=; b=cMEBvDmaRjgeBZ4t0a2zauL3sggH/4Ba33xJQMio/aRRoPk1Cw7qBiiO67Jjxhv/4k+4krCH4MJ0BBV1WF3QSDAdXEKwPyWyhSqKbfYrlyCBgOEFXZETzSYWNb6eqVVkxP9vW2mVrjJPvAG75nj5XotIBLNlYdR5RWc9MCsxmHE= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by CY5PR10MB6120.namprd10.prod.outlook.com (2603:10b6:930:34::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.27; Tue, 11 Apr 2023 15:11:30 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da%7]) with mapi id 15.20.6277.035; Tue, 11 Apr 2023 15:11:30 +0000 From: "Liam R. Howlett" To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R. Howlett" , Stable@vger.kernel.org, "Liam R . Howlett" , SeongJae Park Subject: [PATCH 6.1 04/14] maple_tree: fix handle of invalidated state in mas_wr_store_setup() Date: Tue, 11 Apr 2023 11:10:45 -0400 Message-Id: <20230411151055.2910579-5-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411151055.2910579-1-Liam.Howlett@oracle.com> References: <20230411151055.2910579-1-Liam.Howlett@oracle.com> X-ClientProxiedBy: YT4PR01CA0146.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:ac::14) To SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR10MB3022:EE_|CY5PR10MB6120:EE_ X-MS-Office365-Filtering-Correlation-Id: 454e380b-c764-4b7a-1017-08db3a9f07ad X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(396003)(376002)(136003)(366004)(346002)(451199021)(38100700002)(36756003)(86362001)(316002)(26005)(6506007)(8936002)(5660300002)(6512007)(186003)(41300700001)(478600001)(6666004)(1076003)(2906002)(66556008)(66946007)(54906003)(8676002)(6486002)(966005)(2616005)(83380400001)(4326008)(66476007);DIR:OUT;SFP:1101; X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 454e380b-c764-4b7a-1017-08db3a9f07ad X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 15:11:30.7287 (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: w3/WrxyfXldYwPOb/KCUgzBsytFG7UcQOQnPGFn60kEoYCYxPMvwG4kI+pgj7eaVRtjIjTnRuOoXAlQZjr+qDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR10MB6120 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-11_10,2023-04-11_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 malwarescore=0 suspectscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304110138 X-Proofpoint-GUID: jmBk5keeSC1_cc_XWtuJN3rKRZzm0NgA X-Proofpoint-ORIG-GUID: jmBk5keeSC1_cc_XWtuJN3rKRZzm0NgA X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762894949880099611?= X-GMAIL-MSGID: =?utf-8?q?1762894949880099611?= From: "Liam R. Howlett" commit 1202700c3f8cc5f7e4646c3cf05ee6f7c8bc6ccf upstream. If an invalidated maple state is encountered during write, reset the maple state to MAS_START. This will result in a re-walk of the tree to the correct location for the write. Link: https://lore.kernel.org/all/20230107020126.1627-1-sj@kernel.org/ Link: https://lkml.kernel.org/r/20230120162650.984577-6-Liam.Howlett@oracle.com Cc: Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Liam R. Howlett Reported-by: SeongJae Park --- lib/maple_tree.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 819ba692940e..50604fecd476 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -5614,6 +5614,9 @@ static inline void mte_destroy_walk(struct maple_enode *enode, static void mas_wr_store_setup(struct ma_wr_state *wr_mas) { + if (unlikely(mas_is_paused(wr_mas->mas))) + mas_reset(wr_mas->mas); + if (!mas_is_start(wr_mas->mas)) { if (mas_is_none(wr_mas->mas)) { mas_reset(wr_mas->mas); From patchwork Tue Apr 11 15:10:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 82037 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2671243vqo; Tue, 11 Apr 2023 08:44:26 -0700 (PDT) X-Google-Smtp-Source: AKy350a8CvfZKfv0V0Fnc5CjSwGRF6IA1/OoNIWNxTGhXK5eM/esdzp+yKYqLlEWtRSNJLSfOKK7 X-Received: by 2002:a17:907:272a:b0:932:b7ce:2aaa with SMTP id d10-20020a170907272a00b00932b7ce2aaamr12646208ejl.28.1681227866499; Tue, 11 Apr 2023 08:44:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681227866; cv=pass; d=google.com; s=arc-20160816; b=hRv3i5xln7RSP6S8epAuy8/fHIP0rSWAhNL7BMUebwHLGYiSfY4T7uIQYFJQbp7iqd EYTF9Rs1BJTKq1Qi7u4a4hAWj5EWki3li5/N+JwTBuz3VZAbM7w3gusbRsM62db+VNxq CmGydjWhDDlQyATpL9UvLnjZgG+YjKNQb7Fpl6SV+dHPqJk0Vq4jnfZGThNblbMg80rL BzcpBjse+2HG8Qj84xN5gk6253rJmxR1/Ur7bnUQPWV1XmUqHGUFFMkVH/6srRoVxsyh fSDJS3f5saE/xset6SrpeYugww3Gh0yaUxdL4EOPgPETKGFYYV7oz/EENY0X8RNvuna0 0EjQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=YCmdLu6Drwx9ZBMzi2mLIBHa0w0b8jE3MogqeFXzZeY=; b=wAjX8JtUtEg4/MtiaE21lPdbOK4A47IWudrJLbRiQKOAoeBCGuavZta9FWMnfKjIeX lKoxUBpZOLL+u4NDcXO5JfDZasiDGqqwUPBRCAPS7+LQFQP6w0qAAjhegiiweQISHX0c H5fJG2R3+mHtcy8IHgpr9JhxgU+MFSVDtpgC+bKOSesG/NjlPrPFxIqxqSgBirgRkyDK ICttO1bk/2nogDy7as3gNPL7aMhY1PR7i5mDpTl5oVrNFpe+sWTqvS2yrcL5q1qxNTms oMUHipXTmYpfJnwmy/5RVzMu05uuDaAbUxrtVCVWNesij70h5rldYOcCrtzYtYvi3FWk kX9w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b="2dGgA1/a"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=K00UdnDe; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dd7-20020a1709069b8700b009334f7bc132si516692ejc.947.2023.04.11.08.44.02; Tue, 11 Apr 2023 08:44:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b="2dGgA1/a"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=K00UdnDe; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230460AbjDKPM5 (ORCPT + 99 others); Tue, 11 Apr 2023 11:12:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230418AbjDKPMO (ORCPT ); Tue, 11 Apr 2023 11:12:14 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4142259ED; Tue, 11 Apr 2023 08:12:00 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEwu5C022973; Tue, 11 Apr 2023 15:11:36 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-03-30; bh=YCmdLu6Drwx9ZBMzi2mLIBHa0w0b8jE3MogqeFXzZeY=; b=2dGgA1/aC/kA7EqezVAMKDQ8uudY8l4Sa5qzl0hq6zE9nr5UJMDmze6t4s9yhPbzKkiU 79yhxeTScH91XqQNBgtgOeiDP0MU5d2jvTqAZnJa+qEjZ4PjZGftWXFha+YOJXpchmSS r+iqZovsRlNWg4+QiQWZaWjZTxfFOSWSXmU5opZxTwcEKFPy6BcF1nsXYvXzSMsfajjX dnxnDooIpxiLVe9SxfdRdJ2PxM0sofScFTBwsJQXIA5WCfq1RfXz+GUQQRVue9w/D4KS i6/qHVkmon9pmTp/OXps+/jyASasaPQ+NGlLYG49v9uzAi9XhbzXFzi5sCqXCHTv6oF+ 0g== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0bwdrw2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:36 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33BESDYe031027; Tue, 11 Apr 2023 15:11:35 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2049.outbound.protection.outlook.com [104.47.66.49]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3puwbn8fwu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BLJT80aAmvXIEdIKgo8krmaXM+HJI91kAyaSXVt0kH0x/OUJsTa2yeU9KUfFX8P68wl9o7HjGu1dqlBW9hD28es+U0NrBI6OeE4OPdlvQ4h0G44fljbybDbFDkVSejpoK25mSQ0+EaF/XaOtX/SVVUh/TUX4GmDdp8iQJCCst0W1/dZZ5gDDhOwXZsvcpIQG2MjS4xsRRXuB2LqjZ/CfWyknzCxwZ9AOUzyB5kbMtHQjwOoBdN6kGsL+lkKhPTZHWw51pu5+up+WXTkDnUAsNeUZ1ztLH2lkUjFoQJ+deBWgyn/MWw823YKtXkHbt28s0831B6Z0WOdKR5GKmgRcTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YCmdLu6Drwx9ZBMzi2mLIBHa0w0b8jE3MogqeFXzZeY=; b=gVx0oqysdJRr2ZPpy0R6/YDrB2Q4sW6zoXHuFDciK/mc2qLXdwY00UhUNGtW3JCnBX2ycZE6qLY4wvM3AGPSsqXYGbB05l4HpX3RdjVJjU8sPHaJO4aAqVaw5GnDYs8P/l6JtJ5qEGUw0tQX+/YZLV1oKPHYy4BfesO5gJGXjLBLa1osOvnixvDCNLbHq7ebytvRPiBoRcVW/nVP+bBYhwgI60/B9iMIgkQ0CQJqkDvcLL2EHF5Yp/qiICjcJPICg+buyZgRAiVOEu+d8aXs+RUGaLjZtj+hZMLM0LxF7ZDP5leWdqBNtB7T+HbbXnzgizPIPgTb5vNgx1hYJFxJfg== 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=YCmdLu6Drwx9ZBMzi2mLIBHa0w0b8jE3MogqeFXzZeY=; b=K00UdnDeWdkztkrH/xZYzcGIknSRt9VVB7MWsM6iyA0lNUCn8hTNWPztdaqWPAbIjKhC0tePcwCso0YV88YaxW4TIX8XYdj2lUSWdobstw15thggpSwhcs9n568n//1f3+0EfMra3MJ4Z+UL/nOSgrmlaB666spyAvTvSBLF2i8= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by SJ0PR10MB4718.namprd10.prod.outlook.com (2603:10b6:a03:2dd::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.35; Tue, 11 Apr 2023 15:11:33 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da%7]) with mapi id 15.20.6277.035; Tue, 11 Apr 2023 15:11:33 +0000 From: "Liam R. Howlett" To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R. Howlett" , Stable@vger.kernel.org, "Liam R . Howlett" , syzbot+502859d610c661e56545@syzkaller.appspotmail.com Subject: [PATCH 6.1 05/14] maple_tree: fix mas_prev() and mas_find() state handling Date: Tue, 11 Apr 2023 11:10:46 -0400 Message-Id: <20230411151055.2910579-6-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411151055.2910579-1-Liam.Howlett@oracle.com> References: <20230411151055.2910579-1-Liam.Howlett@oracle.com> X-ClientProxiedBy: YT4PR01CA0146.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:ac::14) To SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR10MB3022:EE_|SJ0PR10MB4718:EE_ X-MS-Office365-Filtering-Correlation-Id: cdc2ef4d-1cad-4c3c-465b-08db3a9f092f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: i3iHZI/xplQ3seTKHHGyGg8E3l+Qh/RTB8zL8qrEoTjqnfl5iX6pMS34CRBvJdSxvRPRcG6FBMIoX7qa0yxkcq1ToIecprbGx60mWeSecozG5BLv6GSa93gNlDlvmtHuGlPNY6rmRjS5zc1tDsf/mrtQLCRCbIVd4pG0gDqiqCf9EOan+Jc+ITRkUJqD/5A5f0x56zxNqEv3t2gqEDzh8vT0+iERGICYRiKhBwY7nIL/lz4nxQ+yGBHP0HtbCl856Pp1lBuG2qPGrmSjM7+KmY26jv2dgQchzuQWJUcwWZjISBZUhJy19TaxSoDDh3d7izNIsO9xVRyPjwVi/q3PZhX9+9VMolc/97yONIIXktt/MCv7cLKJ63g8f04gNoWChSHLsFKSMfvkEPz3HAwkp0lkkha9oP+pS+22IuRhRQRPiGOUo387bH5Ixovvyp+ycCYIYgZhYXhn59qg0cg6KwHqStPJQcramk6DpxgEG/otAdsgqWjA4W+lE+g6kBVgzAHGOBM+OOqGmgV1AL2UkMsdt5pgpFOhBp55QUIEGk0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(136003)(346002)(396003)(366004)(376002)(39860400002)(451199021)(38100700002)(6512007)(6506007)(186003)(6666004)(26005)(1076003)(2616005)(8676002)(83380400001)(2906002)(6486002)(5660300002)(8936002)(966005)(36756003)(478600001)(4326008)(86362001)(316002)(66476007)(41300700001)(66556008)(54906003)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7kPiPbj5FPOYI/fLFQ4T+n8l8AK8lVY17QZVkRR091EjPqr+72gW83yDy/gscpdh0Ler5MQZvEOjhoQw/T12JufYtdQVMVtzqz5IIxze95WQni+xR+nvMNFU3X/J0ZZ14tMqzcLbeVk7C9dT97FGALQnkLtvoGrEijEhe3BJdvAQZrgjm1R+3DtmENVbSRmTUeSuY2wchI2DVj2+IfFvNW33Cjv7SHvJTUovRYZDBGV/IXFbFaLXQobWw+6//ljqqoG9NYshQMgWfRfPyivx8Bpj3A0YZ0dl0nqz4Cnr15dussVydCY+Jr0yBTHbSLICk+9iTbtmnqhphLauLwYghje1DSmfXtLbEwi8ZGfD7zO6deGT1YYsdfK+iPFZFzrnsOw6PNwYMTtAObE/tqvula7QXbxMJ5HiZ532vKUpgyDW4r0MuyDHZIfuXSdW4EgQbhPXJeC3yNSusE+QceFqcH7klYTkZHy4ONxg1Ri7IYQP5V4j7BmrTFKKFuQGmGPPLMn2telcFS9zdOmMs22ylNAmAlvkd+oK2/kjL3M2pCRIYLyfg5DPHTGbRFNRPp0zLrnBDX03KrJPmyjMLRJ202lPL1JUp1BkkDE7IrGjyjgqWsKGfM3ZmjaU8tuvKtaEXd6ZyaoQioU8F9GL1U/s/eYWO/s0ZDtCrV3bPsEbp+aUIUUqvDOvG4MooJStyEeN8uIdr4n/vK7TDI76I9c1qydU1XeMUXqq4zLcKAsTZtk3BfbHVUkEdOTCl9/Snk14WOQblpQByg5MwSjiagO8SH0nojzuqoUJL9lT6h5R9QcvZMHY2It+pHJhy7uwUyFhZ4sJHJF0lltGLuTlrxdUbgTGZauN4WeadWT0/4JLQjgJZAEnFvx8qxITqbkbvRpXy8cKhAABA0FK/7iNdq6uaLEKAZ36bIrUmXoloQ/Mfe7P2hELk3+ANoB8m3CFJfWFBCmclj6V+f2r9EzLyYUXvoIsE57ytLWTzGla+VXyzxkG6CPmsbiIT924aDZ/vkYHBbTaZ0jrxP05JuVuf9S64uhsE2XSvYXLkpVAzSX/XlrLdLLx3C8ZStUkvCtVCvRCf688lAhKUqyvH972A4bZ7nhEg4U144P4HE8Hn5DT9RGPMNWr97FU4LB9ZPngqHEW6VIyWScyvyL3cx4ViAE3DJCRaAMg4Ut2QXTUP+jBHLNf4sgqhVrGq+o6lWMr0Nak/xqPrLryfAqe2uV50fDDvdanPDYFWAV63RK5wVyb2cjpYBgmNLXcz0Bnq1q4z2GMpfU1/zmMmZdTPGrBc7T+DxMla5Nf6Af9DT753InoQAIpJ29F32H92KF3ZwBNiN3PSaY//XmQ/tVXYeO39YBp0qI587VO7Ww4wWFWWwwLwjPTf9209dglD92HJ5b1TSs8OrpBWWAHseuNeexb+jOUKWZzHuLf/X1v53b6Xvpl8+MijXe6ujg4rV4aB5NL4u54DfoA4sMeP4Aw7Z+IK297LmT9SsYUG1fMPYEaPR6IoRWOZXqJMM7XfUXZ28f95IN+6uKXJ7nyLAkPDAvH63FawG9dLQpO2SSzal0m09aAG3dbHQeDwYbCSktmsi0U5o6aMeZxxvOjt/PiRoLhxJqi6A== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: s0q4f9dPgBLzQNIXOHx2HD+8jQVjhSIZFiygUBn6g2O9y5/rDsgTUZOuyVKIu80KrseHXEIwygjFISjZ0olwUgwGl1Oq/KeYJHZ2ivwH2ihEUsN16SrWP7266sL6V1ayPglHCHPlYxIpN6vb0VMCPlKjB4YDezQKXEwa6oZpiXOnA+yf2j+ttf/ewadVLFFTMhYbl4Rc4xD7Da9nfnTbZFKwDm1Wov/j5tBeyAymhIhSJ4ThPjP+Z00NmfotkMMfIN9+oYhoYrf19ol9d1CneJwY53glebqu0myMKx9pcw7mbFL52itcmIsHFdEDDb5jIZHNTrGRz4jBK1I3Qk8/rH0KrjLR+BP1iuYy8U77IEHcUW4mQuii8NnUuTBwcbdTCxO5CZP3acg5BjTpeWoy8FIuhpYu4+86/UZjxXr6EvuJ8XxjpGQdubyJ5igOfi5uvkVLSAgIfRUVZxIhpZowMwgvCzKiL/65ZGYzFc4h1kxhe8cO57CqRTvK+3mu2iFfWa1Sl7wYmIjvCYkJ8WhZaCDzHE56jmnWdnH95i8yxfuJ3I+zMeQIECRrKjO1EhHh5Y68d5Qb6Jbziah71Ix6TH19BaJ1NA/cQkVNQkHAVevxPyWUlqS/gPFFKqONvrR+tGaMKeoy/Z4hXOZTO+Xdz/1s5urB++paG/XaZydRlo92eeBMmYhadKz38GWG1T6PACeESkRs1+sqoXjJ1pFQlLLdyTDS41KYtEzXAth1MXq4jc1KegxcvkiAGk/tKDQKCaiZlslHHT44Gjuw5yOkWYPO9/GWu39CxeCpKwomQuE1SvJgtEf6M6Ueln89Ly14Zq5lT679xCtpVfuioVREB59aszgFTTLrqakI1RSavTZPHgzZ6Q8qHouRyMlyW5nIf0YNi3Nt/vItap8Fxp9W+WWR9CIGSHVOoUhn29EG5v+C4GtnsXTzqeEu/XI9x560KIH4DgHlgEr/Yd3ij22Wgg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: cdc2ef4d-1cad-4c3c-465b-08db3a9f092f X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 15:11:33.2304 (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: jVlG9ZT+mH/ml7PbTu5C3rPTEH85NHA6h5zyVYXrzc6TaKlnzMBBOaD8AgfUcjarbE6zNqiW7CdIvRr7OLVKNw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4718 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-11_10,2023-04-11_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 malwarescore=0 suspectscore=0 bulkscore=0 spamscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304110138 X-Proofpoint-ORIG-GUID: fx5fl5F5qSMq6g0cmw94k0RuOq7x1Gd2 X-Proofpoint-GUID: fx5fl5F5qSMq6g0cmw94k0RuOq7x1Gd2 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762895191107070505?= X-GMAIL-MSGID: =?utf-8?q?1762895191107070505?= From: "Liam R. Howlett" commit 17dc622c7b0f94e49bed030726df4db12ecaa6b5 upstream. When mas_prev() does not find anything, set the state to MAS_NONE. Handle the MAS_NONE in mas_find() like a MAS_START. Link: https://lkml.kernel.org/r/20230120162650.984577-7-Liam.Howlett@oracle.com Cc: Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Liam R. Howlett Reported-by: --- lib/maple_tree.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 50604fecd476..fc3e22cff642 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4850,7 +4850,7 @@ static inline void *mas_prev_entry(struct ma_state *mas, unsigned long min) if (mas->index < min) { mas->index = mas->last = min; - mas_pause(mas); + mas->node = MAS_NONE; return NULL; } retry: @@ -5926,6 +5926,7 @@ void *mas_prev(struct ma_state *mas, unsigned long min) if (!mas->index) { /* Nothing comes before 0 */ mas->last = 0; + mas->node = MAS_NONE; return NULL; } @@ -6016,6 +6017,9 @@ void *mas_find(struct ma_state *mas, unsigned long max) mas->index = ++mas->last; } + if (unlikely(mas_is_none(mas))) + mas->node = MAS_START; + if (unlikely(mas_is_start(mas))) { /* First run or continue */ void *entry; From patchwork Tue Apr 11 15:10:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 82030 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2661720vqo; Tue, 11 Apr 2023 08:30:05 -0700 (PDT) X-Google-Smtp-Source: AKy350b2+EGkFl4duHrfgu6SUSViBT1GvBFOY3z4/uf0owj2dBptFsZMVv/Gw47fZ/IDlzgwpktN X-Received: by 2002:a17:902:fb90:b0:1a2:58f1:5e1d with SMTP id lg16-20020a170902fb9000b001a258f15e1dmr11224248plb.36.1681227004682; Tue, 11 Apr 2023 08:30:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681227004; cv=pass; d=google.com; s=arc-20160816; b=ZzjwIzcV1Zmnetq6EGubK//MLdj7bwP6pLXZ4JZKZUkT3xhhWvDh+wmyE+V2sskq3h xU3Ojz3xH+c3UPxEfSPI4Vi+ZVi5wpZbjqNfOQQRzU+zIApHs/skebmNtPoPvBonX0gX vuyyi/AIz5XoWkicLaQv/5TEGjDQPIDwCO6Pp3pRRXbQ3xqb44jgDtmWuLgOmpLZ0UHb ktTC1MT5R7hvTfplUytkrLL6hXekl1VoShq1YK11NCUzXFWh+YD6a4JsDRIfdWj76Pnj /9EJTErCCuQdghOE57TMg3KFm26ImlK/ShuK44ExjdxB1RotVSinrtwVrujo/vmcbahI cFrQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=7IzFpQHbhMFR2jvJUXKGwCFDQ7UBaF9JNyoesl1gmJc=; b=mjE2Ab9kMza0gshRg3ERLdcj7AAsX1rBPr0SnrKxKAP6UG95IDLVIW8tsoXc6pxKIR c8g5elrJr8ePpzCH73S/Bdyst4l50cxyY3NUtNB3/DgLtrKvu+EepxeOou1r23gu78eS UfnRfouDWYnHz5tKJ+FGS+DSPe4Hk/ZdHNwoo+yRQ95MB2ZyF0dtpzVT32RtktuBzRdf LJ+ExDTxNchN9dLjV4vU7NHyn0+SzhsqyglyFNrCoLu8k+EgS2TazUUQZKu/M96/uJEB 4T++nwTnoE2Q14rWgjZa83gOddFICWTdxGGLbk25jFBfl1zOYQNxveuttiDogDI65X+w QM1w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=W0TUsOia; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=TT3U3lXF; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e67-20020a636946000000b004fb8abdd188si13447386pgc.115.2023.04.11.08.29.51; Tue, 11 Apr 2023 08:30:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=W0TUsOia; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=TT3U3lXF; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231228AbjDKPN6 (ORCPT + 99 others); Tue, 11 Apr 2023 11:13:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230504AbjDKPNV (ORCPT ); Tue, 11 Apr 2023 11:13:21 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B2B46182; Tue, 11 Apr 2023 08:12:19 -0700 (PDT) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33BF1NOL018057; Tue, 11 Apr 2023 15:11:39 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-03-30; bh=7IzFpQHbhMFR2jvJUXKGwCFDQ7UBaF9JNyoesl1gmJc=; b=W0TUsOiaL0DjPT6+GYoPEqLC0naYd5Xk2rEU4kZLiuZcx1/RpZSk1hlptCeHhYzo2636 4i02csdURbRLNSXzjpWe61toz+b71419dt3OgM/Yh3dS998DAO3SMsOtSVZUcwftgL6b iwRYsinax/lz5y49NLjorkZTELCjwMTdHtKco42sIb8KnaysPVpx//ZLeRQcIymLx5nK qVVfEyRM/4MCGHM+SCaLVTwgWVvR/IKGPRESN5v4SXsc8WufUmp4Mqjogx/asjKj1YOY YMnhhpe/tuHs4+SywHVIoJI+MsTbOE3ggAOG6hMB+j6aWHQJasl+spkSk9jqu9ZkL3pq aQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0etnnuj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:39 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEO7qR012831; Tue, 11 Apr 2023 15:11:37 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2105.outbound.protection.outlook.com [104.47.58.105]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3puwdp0y23-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BL+Pu/joXANlO9FIY4XCuTepAczUI8Pw8sSnl1CG45O0DODuqmK13QJxSjkRDxF3RpFiBLfGcfE8fNZw5zMb1OLBGLtL7W9m0JPX4HSJWCdTM9McfCtwje6CYfLpHg0Sc6VTdq8rR0fZyoLcRTReBpaFeA88P5igybavVxxZmHJKHcWziMorGNDTTuHTTkOa3f6xUHX+sJ8/9/UDU07wGy2hSIuHkzY99MLcp8V6fg44RNkEvc+9QPDDPGYlJWn5vkegk5xdsro9a8M67CEaB5yDfMjr1YWyAYWGZc9UQ9B0MUHziOBUyIX4kMqZt6OPD7e1VRUhaycsQNbo1hcl/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=7IzFpQHbhMFR2jvJUXKGwCFDQ7UBaF9JNyoesl1gmJc=; b=m/uZp0Olw22DQSjOp5gF2ynN3m32eUMAbimi4VS9o7y8rRFHizPzpOYZ6jRFoM34VOQAtoal3PzUGEKVctY4YWt+2nrcDU0YqWO59arB9TesTfMl9gwVUoGSBNbu6H0LPtITM1psHMYi5J5fqVrhy56x7uytL46T0VPPFP6aaU5CZJkzCtHmmDTo3akExWVuk1A20XsCwYsn3Ym8XTpfq+vL6+Bdh5qioHyF7VZXxZ69ZSn184B0VoBChCXXAWpvyZ3CJT4CzjwqVly8dDAzRRDBlBq+phMhepXmbJzdZRxJ2xGU3OYHduVg+9JDCvo+i30Ls+VmqLKrpxgOWIs/hw== 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=7IzFpQHbhMFR2jvJUXKGwCFDQ7UBaF9JNyoesl1gmJc=; b=TT3U3lXFLYYN3ZtV+qhgl0x6KavCAKjJvSmv+X17hFaLpaosbr/CIQqTABFSBTLzuYFB7/1I++kmKnbxoOA/sIRIwNwaSjtYedaWcuDjowcjX3angWZglv80US5SupYp+YRvZ5r3O9XxBRDTKbkLJSuh3+WRpz8DfTpZYCxI2wU= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by SJ0PR10MB4718.namprd10.prod.outlook.com (2603:10b6:a03:2dd::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.35; Tue, 11 Apr 2023 15:11:35 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da%7]) with mapi id 15.20.6277.035; Tue, 11 Apr 2023 15:11:35 +0000 From: "Liam R. Howlett" To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R. Howlett" , "Liam R . Howlett" , Snild Dolkow , Peng Zhang , Andrew Morton Subject: [PATCH 6.1 06/14] maple_tree: fix mas_skip_node() end slot detection Date: Tue, 11 Apr 2023 11:10:47 -0400 Message-Id: <20230411151055.2910579-7-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411151055.2910579-1-Liam.Howlett@oracle.com> References: <20230411151055.2910579-1-Liam.Howlett@oracle.com> X-ClientProxiedBy: YT3PR01CA0139.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:83::31) To SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR10MB3022:EE_|SJ0PR10MB4718:EE_ X-MS-Office365-Filtering-Correlation-Id: eba02011-8ace-434e-cc6a-08db3a9f0aa0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vJrh0+DPC773epiiSfgPJ7r58z85tEmkls4VTelvlJCnZ/8iwsZxjlvPS8gJbmV+ZVaGPxt7e7MBKlt0Z5SGjnpyUPyHS14JBpyhU/fXABCvsfBIQxcksjeeUuSujNnQypLaAhh8a3Npu7fqB5K89jPiIbp9W7rHDJ5V/BGvtrnIMh+QoYETjePCKln7q9tA/mx/lT7HFt10aKGo51fExqVl25oZVGypZrgMI4uhXOD5HOEXzFl6MiFBtmYIDKMo80M2SBSLTjGEOGvWudk4iYss1lyTGDUUeWefwSO0L8M069iWrJmskYSbWBG/fwTlsSGHIdvcGUuwgTA+mcVexonPpN6p2YYr0mZst4FgbFjAN/J6CAP/G1SwOPwa1q79JZQWdvM5CL+3qIcFNujA4kyPM4eqq21AgoYdNi+25ZVv3V0tnl59u81BY9HgDHdEUtEsQEVAE7hk8jtQnBQFLp0jGLU1Jnwd/Tc9UhQKS+S1B4OMKIREFL38TQIOtouEe0euakrSWOMqZxKwR5QS7VqFV5Tthrn+JxRp+mNo5XjliOygJSgRyAhNS8Q28WVYXz0AK5R5PdPEWFnMT83BeA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(136003)(346002)(396003)(366004)(376002)(39860400002)(451199021)(38100700002)(6512007)(6506007)(186003)(6666004)(26005)(1076003)(2616005)(8676002)(83380400001)(2906002)(6486002)(5660300002)(8936002)(966005)(36756003)(478600001)(4326008)(86362001)(316002)(66476007)(41300700001)(66556008)(54906003)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5CsOkmSeTUMaxblAmBse1ZH2PFBRGG7IqUSZpxBltK4xebb4bdgqJ/lkqM8fPjx52j8KR5TQxSc9gXCZyWiZHDruYppSBLuDLlJxvWFbS/AAX6O/vlhLT2sZx4lL0E53dooqzJKMA5rFO4I2qFRrP9D05KaHD842HO0z1eywoMQyVIdopA+6HsZKQ2kGfdeaa7QLizrTI/OiZvzDU1y0RrTxMPf+wlSFVZjrD2JmZfUaRoMUeMY/DVNOmcRuVGPzB5XZfo4DF7gI9KHLYj5ljaCOpqkkAUdZp4mIEt7Srz9754DUF6nbpQKpDmNXbHlgZ88eU5O0nr9SjR171BFapI54HZGh5njgXVMhhSz56vn4c/exue7eQpn64Me3im5hEBt9VJzdIN0VeP9DUp/7u6do0hWfvbVj/LLhPuaf9/RpYE//hmwr/vdC7a8WpGBYqZ9N1ZZfO67MvE81O93o3awYCW/SwW8z4g5p7KCkYxZ151CFvikoe6qQTnIZk/yO3o7ll2eAK//UQ1xYVQ2lNirxhK4cLmBxYODhXmT0iy6+X5YXPdsQPRfHKFyZcfG6VrrYGZkXXt5J3eOsWRmkuFqzsyEDmEgPekiGKZSqQeCb4xjtbiL0ZtVSRUJyQPHqO+XCeHtYN8JjXVMbFDLqIWu2q4ePnNoWGQt8cK4kjA7wIL1SzbLq/F61hE5Ha+5q5h2xnc+DV3AclIrSeLf4bdn/szmYRckkdyndiR4WYgMasyoH6ISUDhun79pA1DN2hAP9g9Qo4excAWoIquVq1xTvcXwDjG8TpLhIsnLhbwGHp05s/eKbDaiZaii3JMvTG83eeoLOFoUHmYmHKlYkujDdzDM499VxKI1DCHAmlpMD6nzxbLJ6Wu1tu3g/4plR/S5pVwsX6DiJ49FcjkP0CvT8NVQpvgsuREsOsoVy/aTRp+Y1gRS9UO/OwmD0gpiVBoqntM99H2uL/jSbX3rlY+7Ok+DT43/BkNqX8hkKhUNA5STg9zTp9WqRwjoGL5swdrrK66tYnkYtqMXZ8KAGsowxTsiMtNMa6lMVg4jR7bb+ioSYP7kFe0QZC9niUf3riKdwvffZtnQ66E69YZDmcfGBzSZkn0qkAOO6+gYSfdJOOAcpEEmRHZB0sS74kw6OINIR+xSe9RJXk24FbbxjxK57AKoMchUhmWH0wg6E5KWah5SC9fMFd75+tUFSGdOEsxC84gcamcW58ZLJQNQP4Nbv4XJITPmQBzf1F0RDepTCkP7iY4neYzCsLgCiMC7UkMNlZ8utzfkKEBcbFiqikEacNfqCM42RFf3qUOZ7mYWp9fAKOrqJCXSvzN/PNSN9O9tTAdZeYhWeuw9yxSsQymDiMPv+52JRoZRqQePO3D4p554z8r15I/+uatP4ZF6cAU36q8850qwZX9hbhI91zSH3uRsTbrBFgT9msoNUO1J74LxoIU/vz2zblUxKbxBxZ70gju8/WuflHf7ERdi3Ry2dugHRLll0OAgwauqif4mAClPuOfRow5VSgwZWwY2QPboXKVPalbBdvFLVUid7CrIodY3nZOmu+dK63h0/EftqI6XE5tMzbnfK77TiokHz9sWa7YtT/C6fQe3BtGPkZQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: XYGwJEsCKs5Rn4hLw2H30eEqq83L+7EM7llFK8iVznOf1UimNsAPpHNZrYfBoSVoJ73UvdYfgsX7azc/KG1CnQEdyhJXlmLRIrR057o1Tyg4pSWMhIa9Ir3rW4UGC2L4+HjCgVGOP/Bd+JVeDzWOYmfoTEFk52VEBnCyp+rBk/p7fxE+cF89MIjMIenaaK3dbVgpvn3t/uclVkphzQMXqwGlRpJK+JjV+NOck1jsh9tmA0UTk+L0qVU04dUkiSdb1DRL7yaO1iEky3pSgaqcuMuViaIjlN+hvdAzc8NcLUaMfQ1N/c9ZDnhFdd34qtpxWP+cqn+VewIhf+ydjjWHuxU8zq5LhFyakfmCvK7Yw/em29uiZtUTaR+6prM6/QkWHhMnREYjLGlkcU3SBBZWEj7TTs+xrveVM9HDw7AxqzRPB3NekzAaIU2gVtP9Xy1i31wiQfThVnRrA28Wq5BS0bA2Zdgt4noZPyppU/9WL2b3VNsmMOO/hjddduWm5xF+kovp26BPvfbCWSkC2EtF18DPjfnuI3aDeBdvrXUsDvzyqcwDm8HUpU9uyv2UMFnx0oio8IMeX0/p7jbLvyqFiWvXXZOyDNuftw/V9/28v7jzCysAXUJg6uLucFyA3X77emS0H0UYE89DIQVozIAJs8Qgbzy2pKDngQrpcdC2oTUHx6dhj54f1szMZTiyWRoWqf0yElTQ/0rFnD8lLueoFYbfJlTrMv9zk5jz2wl+VNnwukdIDQ7hwV4+sWhIsWzNeAxQfK3/Ui0XFwA3rpegiAQsVttkFEh65ZLsaLTrqNJyIouL+0f2we0F3suK5SYvk7/LWPxHoyZjEpfgg1Upv/wH/1mDh0n0N9a3C7eiDrtJjZBXeE+Y8j/Mg72/soz1skocs1Z0z1wePF9LM/URSWZ6wcXP9Uhf+yUnNTL2ZlXk5NqGLek3niI2swrodX65EK6jw2flPWpKiRMq+P6gNlvodOiRnEbHUkwkeHlC8a1q2teWkWbW3uAH/UtV1/Eb X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: eba02011-8ace-434e-cc6a-08db3a9f0aa0 X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 15:11:35.6995 (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: dcG9uJQZzqQve0AAYGMKRhBF/CcdZQjb2/eAsVIjaIwZSJVqaCyUcSETejBCyL37n9HmL0k4zEUAlzOjYx7zfg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4718 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-11_10,2023-04-11_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304110138 X-Proofpoint-GUID: Yml7GVUvBqtyMrgnU1N7r1iLqE8eFbJI X-Proofpoint-ORIG-GUID: Yml7GVUvBqtyMrgnU1N7r1iLqE8eFbJI X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762894287522711671?= X-GMAIL-MSGID: =?utf-8?q?1762894287522711671?= From: "Liam R. Howlett" commit 0fa99fdfe1b38da396d0b2d1496a823bcd0ebea0 upstream. mas_skip_node() is used to move the maple state to the node with a higher limit. It does this by walking up the tree and increasing the slot count. Since slot count may not be able to be increased, it may need to walk up multiple times to find room to walk right to a higher limit node. The limit of slots that was being used was the node limit and not the last location of data in the node. This would cause the maple state to be shifted outside actual data and enter an error state, thus returning -EBUSY. The result of the incorrect error state means that mas_awalk() would return an error instead of finding the allocation space. The fix is to use mas_data_end() in mas_skip_node() to detect the nodes data end point and continue walking the tree up until it is safe to move to a node with a higher limit. The walk up the tree also sets the maple state limits so remove the buggy code from mas_skip_node(). Setting the limits had the unfortunate side effect of triggering another bug if the parent node was full and the there was no suitable gap in the second last child, but room in the next child. mas_skip_node() may also be passed a maple state in an error state from mas_anode_descend() when no allocations are available. Return on such an error state immediately. Link: https://lkml.kernel.org/r/20230307180247.2220303-1-Liam.Howlett@oracle.com Link: https://lkml.kernel.org/r/20230307180247.2220303-2-Liam.Howlett@oracle.com Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Liam R. Howlett Reported-by: Snild Dolkow Link: https://lore.kernel.org/linux-mm/cb8dc31a-fef2-1d09-f133-e9f7b9f9e77a@sony.com/ Tested-by: Snild Dolkow Cc: Peng Zhang Cc: Signed-off-by: Andrew Morton --- lib/maple_tree.c | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index fc3e22cff642..c50646fcb8ca 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -5097,35 +5097,21 @@ static inline bool mas_rewind_node(struct ma_state *mas) */ static inline bool mas_skip_node(struct ma_state *mas) { - unsigned char slot, slot_count; - unsigned long *pivots; - enum maple_type mt; + if (mas_is_err(mas)) + return false; - mt = mte_node_type(mas->node); - slot_count = mt_slots[mt] - 1; do { if (mte_is_root(mas->node)) { - slot = mas->offset; - if (slot > slot_count) { + if (mas->offset >= mas_data_end(mas)) { mas_set_err(mas, -EBUSY); return false; } } else { mas_ascend(mas); - slot = mas->offset; - mt = mte_node_type(mas->node); - slot_count = mt_slots[mt] - 1; } - } while (slot > slot_count); - - mas->offset = ++slot; - pivots = ma_pivots(mas_mn(mas), mt); - if (slot > 0) - mas->min = pivots[slot - 1] + 1; - - if (slot <= slot_count) - mas->max = pivots[slot]; + } while (mas->offset >= mas_data_end(mas)); + mas->offset++; return true; } From patchwork Tue Apr 11 15:10:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 82027 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2659717vqo; Tue, 11 Apr 2023 08:26:56 -0700 (PDT) X-Google-Smtp-Source: AKy350a79qqpYVoohAbP8ZQZksQLGTAH2Zv2dS+W26efgTOS4P485MXmkW5lW1xLGydoD5f3Ym+x X-Received: by 2002:a05:6a21:3391:b0:e3:f25b:613f with SMTP id yy17-20020a056a21339100b000e3f25b613fmr17169942pzb.14.1681226816078; Tue, 11 Apr 2023 08:26:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681226816; cv=pass; d=google.com; s=arc-20160816; b=D+KQWnP8mHOIp8XBiOYlcJKlSL/FOO8rIXUHCSgM/e6rNJ8VANoMAx++V/QbxwvzOS inp4da21qwFfrP7cbD5DluZ01coYWH1bZeLLOCwsYAtnQdD05QPvsjEuwEz5E04Hc2eP 3boCywUfo/l8JoOpzPGDkxDzsjeCOblWd3uCinKTkdVxI2slH/X0pUdP71iOLdo1gqzZ p79NMMNr/9poSUSWAIkN6GsAF7NmqDiPYwmfxXQIb65x7oMja5I6YEvDGHBSi990kbSc 50q8lsoD4dDLSk5lM4hPT1hS0cHzNGHfgJrg92ySm9qztCWxHZRLamlKT6DW9rKwc7u3 E/Qg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=As2pTY8AEIRrr3ZBhc3xaVfQxndlyj30QNcp40aojOg=; b=IJk0Q0zD/xhLaDp0qbTeMTqDufERT98p78Yhur+BgZUyUjiRKsExc8kETiS4dPa/X9 Ay7quqZEIXi1eeeOk2dum/kvS5XPz8dmFv+vHw5CBfKPkud3Se6L+YBomOsP52jI+ddI N6lHExJI1AU9+h8giyNGOuYjon+qgf9o/93hSfFp1gZMpNeWNFKLsfszY5hiURahrtpG js+iPLvjTwwwjD13C77KO3bTrcvNhg1DvdH9BBgiooakh0r7osc5R8sZXooKyjFo/m0E z5UQnAxwPVpMYS3iPYUm9XTHxnBvuvP7R6YFBQt3PGdQfKL2yPvV5FRqObw0IeYouLiN AICA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=VUwKXmdH; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=P0OMqmse; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e67-20020a636946000000b004fb8abdd188si13447386pgc.115.2023.04.11.08.26.43; Tue, 11 Apr 2023 08:26:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=VUwKXmdH; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=P0OMqmse; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230493AbjDKPNA (ORCPT + 99 others); Tue, 11 Apr 2023 11:13:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230454AbjDKPMW (ORCPT ); Tue, 11 Apr 2023 11:12:22 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61B105FD7; Tue, 11 Apr 2023 08:12:02 -0700 (PDT) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEx8pG019804; Tue, 11 Apr 2023 15:11:41 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-03-30; bh=As2pTY8AEIRrr3ZBhc3xaVfQxndlyj30QNcp40aojOg=; b=VUwKXmdHqSwbWwjpcuGjMoVsbDKGXNBp7Iuqxos826AmDZ+Ccs3OOey0SpsdPvGsoQUw MuyucYc9GBVSva/S75wUrcqcVp39ehjYCtJdnIe9tVxuqHwDFiq+3co8eGwVjtVtzRb0 i4bHVSJOf51o8K5qHpAQcvNEROA87FRS6q+esJptg7s994jeSXZ0CP1aP0EGXpV2vplQ hoPhLoG9A9Kd88qHjSerwVlrCYXruq0nDLu9BHIkQnSckcQO5b4quHfwxjCuFQx75moS x+RTZQChtFe6rvTww03l0XPY1UeQaXZbp53FbjJmgz2J9fN/WTyfqFSGIz8jjix4ELn3 cg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0b2wpqc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:40 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEStwi008056; Tue, 11 Apr 2023 15:11:40 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3puwc497fd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gpmwozvf59DJVdzuswDA3syUtRkIOvtR/p1exXm1My0FbTREv5ZgZhlOrJFu9sPnWchrrVGHKPGmmUKmIOInMZX1Bu2WlZtlH7jU8D7kK++8G9adcu10npGsx6E5KvtFayA2Jb3ICEXaut1S+xxiCgUp1qPU3F0lGapYfhkFZ8KbBNLoqX+vLpAJRPWb3El9P79ONEx9uDx6fciW/zEOEM3HXs5hHorGdAVt91oIQgE3ILZAqoKx7sG86Gvgfhj6f6WqEvXJvxMUGzIiO/iwDZCiVEUF9glE/b0z0TpMsJiEbfFvKHfVMdvrcb1is/CKpyLg1jjsgXzlh+x2Y0vBWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=As2pTY8AEIRrr3ZBhc3xaVfQxndlyj30QNcp40aojOg=; b=JEo7BVgX7zBDBBT+bZ0AN2quU0zQmWWAEdTC9V5Db+sih63KGZFQaJphj93/8TD8uJzvmg3veG5owerWnu5kmRIuS0FU8R8e3NzEKMVF7S4itQbgbjgBqemkedU3dmMSRhORw1geAQn/XTvlYQ7B3LWNzElZQKfA8Lv0WATBKb6WDXXKID2TGd6hfaMjtPfoNn/pszNaCgIoZ4Xxc/+jb+m6C86Ok/Ar6zqQ+gYDQG+xOjGKe4lydZ444uRq7BbbWBKbkyF7ZvlLaKehTfW6kJCjK/9yghIPjQacBJHfcemg2mUClY/KebM9OJ1hY+qfuMgcdZ1MfcOoune9bVY+Lg== 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=As2pTY8AEIRrr3ZBhc3xaVfQxndlyj30QNcp40aojOg=; b=P0OMqmse6XyimawsBv7RWjDEOo6TKDOTpXnQMyK9LzLzMJgo6CSQDAJYPVYZL6AiYDI74IMginwgjGA/ljgwCmS3P/X5fVVH92ZAnwVvLS/MrcXrWvEqn0wi6FVLw+X6TJKYdSrl3We/PxPJ22LSq0kJV+g5JdIrreFczLWcFX4= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by SJ0PR10MB4718.namprd10.prod.outlook.com (2603:10b6:a03:2dd::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.35; Tue, 11 Apr 2023 15:11:37 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da%7]) with mapi id 15.20.6277.035; Tue, 11 Apr 2023 15:11:37 +0000 From: "Liam R. Howlett" To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R. Howlett" , Stable@vger.kernel.org, Liam Howlett Subject: [PATCH 6.1 07/14] maple_tree: be more cautious about dead nodes Date: Tue, 11 Apr 2023 11:10:48 -0400 Message-Id: <20230411151055.2910579-8-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411151055.2910579-1-Liam.Howlett@oracle.com> References: <20230411151055.2910579-1-Liam.Howlett@oracle.com> X-ClientProxiedBy: YT4PR01CA0116.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:d7::27) To SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR10MB3022:EE_|SJ0PR10MB4718:EE_ X-MS-Office365-Filtering-Correlation-Id: be750c4b-9fb4-4879-91e6-08db3a9f0bcf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yRd/RKKg8gIqK1yRxkg+TakpD0YwDdmHMKPWBKN5Am3q2ykIFpW5ex39Y248g3TNwOHxOPtRM2nyzLZlvrzIIK5LCFr6JsyWiRaFSA+A6VZfxQTd+kB6+zXWFCn+la10r/p8BLhqb+5nSEL2prUgcILhwLhWauO/LNTPMdVAxKbia8Jb5bgFgw7puIBiPpQlVxhckRNniWy0ZPo2LiWcs/eG7c0mroTi0uFf+cDxbdsCG2xcNkxnutYZUMdlUv9rUB1VElTGOSSz8UImPwyjYQHcb55D1wXUdqF6BhdYuDqS0GqrgZpA43o/AM+Iy3134uDwfQ1xAvh6KO1ZZYt+tBM5DNr7NDnOB3rBku7md2UREm2W8rN640Tvi9hfsta66KHphxUsM3lZkcEUOhwaemWEKT3TgrnyrmJ6BeZniN8TTiVfLmZfgsCT0xWrWObHFJmr44Rb1vPDSzNUy3R9hR+v309otn6CokEEAAtEHhCkG2vjqanrBcVs1EqQixB6ntdEgbER1Mbgd0Xjs+vpsq5kWGExEZY3OR4s09E1H+tifIOFLhFolJEw6LnuNwIIw6WuLy4WLMokFL63nTK+mw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(136003)(346002)(396003)(366004)(376002)(39860400002)(451199021)(38100700002)(6512007)(6506007)(186003)(6666004)(26005)(1076003)(107886003)(2616005)(8676002)(83380400001)(2906002)(6486002)(5660300002)(8936002)(966005)(36756003)(478600001)(4326008)(86362001)(316002)(66476007)(41300700001)(66556008)(54906003)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FecQ8Ce4tkchlBTVOpcmyCF5T2YMFqtadKkxdjf6KCkNX/FhbRy5ZGlOFqC9uef7cmNPWXBvpXCvI9FA+8nW8OSDclCRSjZPp3O0PEo/roZSlVg/aLM4yesH7LRjCrXjV5EeCj7/KGD4zxqhuKRk9Mv0y/neAabW/b4g6lISE1qJ1J3W0lbqUSLtlEdvQaGDXInxqaqKoKFHnL28iacRhAsZCytCb1Rv7tXE/x7i637EENS2s5q12nfL+7CDJnuIajNlYBy2SwiDSOhkOMmL82/G/HaeF2DJGpg1SDgU4sEgDtmXjjR92PjWsJYe+r39GjbrN7dWqXmOkV78Kl+jupI97dRIKillcHnPr/YurPmTeBTBYxfT+BsjDcJmhT3DT7WkN2oMehf9txgM4hAaYJczbDZHngluIRx2uiI0ni+Whr0axo8ySou/fab+eIkrIsmwIumfh2kmp8iJoSGuH6LKsC7mYC9xB7BcbChqugp70AFQ/S9kWLbY6uVjZjPrspQ9UJ9RK5EE3sBAnviIzooyE7xaUVYW4pfYn7qTEkt37tOG3wyRd2dxvlWjwEsDBC0Twz47Eh0aKdupay+PtfIpF3EKR8HNYSwOHNlRA7tnd6rIll/ZOhiU+/ZYmJ8gAOBsXSf2Tmbq0xJ++1Px9oxdc/VQMmaNVYvK9QZLuOHZR2Tokf5hWDXSvRJqqONyZRTS0Qc4f58nfH6DtOVrqrUZ0ZgXrGzcxmLVYy+h09/x0CzLv/6pkzBd+1pnamx6zRKMjIfNTL4QROyYOZed0Xk1BG8VsAmPxYkPxxVDNHm3wFjme2OP/86gEoDzcNex1P5/Nb1lnJYcEMbT8tyQvPLsu+AYSeGLRGRn65LXfOK9pITF/m87dvXHxgzhgAGB878ODIsXW5uWsiYeAtBn9cOzA2ZDahKaPoMFOhpjktPlQ/XDYc9b3Z0RTiBiozSUNx+RgZ1ezW3ViYpR3yFINxBRPFNXMVBSCF03c8hLCyc0hvvzvbwk4XdkbK3sa5tgQnpb52P326vq65oIP5hmbj7Wq+uVqcfC8opoZj//uVO1TQSjpy81z/EY0nhHpoYaWu6PJPLXwBqfpkb93A96m2xsupETl0DCYQ1k5jxGYjSHZZXBJHCMGuaNNzT6raO9jjVCq5KSO0ErbYaLZJBzBVA57fRQYK3XtjlwJVCqg48HY+8tz1qpLq3zDCHmlm7uXqiqmmW39TCfdhS7AAN1t5DGZvfR5gQ2UINJDf0rmbuY5a1/yIuQG1yjlshtrVJ/Df2gzrdoiUCA5VDvDQguZELXhr7Fg4Z7zXoZcrSpOlya3YR5FdtSg5FwMqCgbpb0zDVWF9yRcRsFjoYRYt+IcvZFCctiz1gS4EqigagVlWs25sIx+5CA3aHA8ysfoCA6ogV8nxitgU0wapgW7tG5oodikWLY3DvRv+S2OPs6FTFKvsU6z76S+qC6WaCs9A6VU/8UvZaAAArgFX/4UTxahw1qxKwDdtOepGvIC+u80QlDEQq7nUd261/+4VcEO8soEGaVcdzuEv+JGWQXgeOTb8fRLB12zMqLyoJ156JuXaqBT8h8ZV8fRB+eAk4FOoWBtWXMI10ohu7FQa4YTON+mg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: lGfIkFAcl1UOAXh3BD8NnsxnS8pxoLw16eAEqKuUv4GKyXNvybO0buBfi4A8ZIil34zuyi4XagpVceUPfK4LHe2yejrHBAn1uwwOwSFgdFj9fFvt/aa17zQF0M8B0eK8rJVjpCQ3L9g9RQh/0DuLSQALjy3KG9x9iDXVwn+jd9p9w7ggu3uEpwbnGzH+N/2OkADdThOgtScSOdcULQAv+iBAgyttpCsAg+U0zq/0/v6higCt4pNEX482OqpYwpai5VIy3BhpKYxwKTK1S4A1Df2Y2iZUt1Utib1wg4ku6vQ6L0Ndwh+o+xMhgeJqsWECb0RBrhbw/XEG8v8coh7lME9iaLR/+zICmKsx3q+zaLoMKB7L01k6UqNKGiZnhH+PTLkpvcHeGXTSurk4Ily6GMw1bSKJMB4+GL9xM6nNZEGdF2WgM+MZe4knLoCpgKDI1ugeOZgSn8AyDKQ/4+d4RmvCZHEU8cxpbwbpx+csrXE+2RInbnsc5WwwEF5BJMubiUNCdTcyZ8u6ss2noq3bQuTfAqT1mvvv73DRkq3HzIbi9YKeH55opMzeh3kt2Rxck0lg8dy93Zvm/5xY67ITrVAAnMuLw4u0r2FYP8PsUViMAIPFbjRCNuEqdVo30Z/OWGedsnX9qHb7GG/ofyzu1eFaSxr/TS2LL081qvKit6/E6Iub9oisYFd9K7n/XM4XDGtaVZSvuFs30ZrKfK2O81HYYBbQZCG3PaQtOfoA6NxzR+0eSIGm3clQ0/omU+J+iCbXqSclO/nn97EBGjvkarLSkGTIpSVr0glXi5IcrKzc+2T7RzLzJO6zjT7Ya4+Cef6SwikfRCeC9Nwb/umArYc5QSgOOL83yEV1JGdt9v7HUdljHmTYsEJb5QipJsnawyHAYaXST+RBw+snyehMsg== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: be750c4b-9fb4-4879-91e6-08db3a9f0bcf X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 15:11:37.6722 (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: dQLX95wOr5QVxT0XGWPlR7+kcOy5x16Mgg8sR8+10b32+Atc1juWXEGx1NhWYOu1AYThbjyBufxkDfwvit535Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4718 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-11_10,2023-04-11_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 adultscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304110138 X-Proofpoint-GUID: 9urhPGAPaAvGomgLE0kIvOYsj3za_B-o X-Proofpoint-ORIG-GUID: 9urhPGAPaAvGomgLE0kIvOYsj3za_B-o X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762894090099218880?= X-GMAIL-MSGID: =?utf-8?q?1762894090099218880?= From: "Liam R. Howlett" commit 39d0bd86c499ecd6abae42a9b7112056c5560691 upstream. ma_pivots() and ma_data_end() may be called with a dead node. Ensure to that the node isn't dead before using the returned values. This is necessary for RCU mode of the maple tree. Link: https://lkml.kernel.org/r/20230227173632.3292573-1-surenb@google.com Link: https://lkml.kernel.org/r/20230227173632.3292573-2-surenb@google.com Fixes: 54a611b60590 ("Maple Tree: add new data structure") Cc: Signed-off-by: Liam Howlett --- lib/maple_tree.c | 52 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index c50646fcb8ca..7c8225e7df13 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -534,6 +534,7 @@ static inline bool ma_dead_node(const struct maple_node *node) return (parent == node); } + /* * mte_dead_node() - check if the @enode is dead. * @enode: The encoded maple node @@ -615,6 +616,8 @@ static inline unsigned int mas_alloc_req(const struct ma_state *mas) * @node - the maple node * @type - the node type * + * In the event of a dead node, this array may be %NULL + * * Return: A pointer to the maple node pivots */ static inline unsigned long *ma_pivots(struct maple_node *node, @@ -1086,8 +1089,11 @@ static int mas_ascend(struct ma_state *mas) a_type = mas_parent_enum(mas, p_enode); a_node = mte_parent(p_enode); a_slot = mte_parent_slot(p_enode); - pivots = ma_pivots(a_node, a_type); a_enode = mt_mk_node(a_node, a_type); + pivots = ma_pivots(a_node, a_type); + + if (unlikely(ma_dead_node(a_node))) + return 1; if (!set_min && a_slot) { set_min = true; @@ -1393,6 +1399,9 @@ static inline unsigned char ma_data_end(struct maple_node *node, { unsigned char offset; + if (!pivots) + return 0; + if (type == maple_arange_64) return ma_meta_end(node, type); @@ -1428,6 +1437,9 @@ static inline unsigned char mas_data_end(struct ma_state *mas) return ma_meta_end(node, type); pivots = ma_pivots(node, type); + if (unlikely(ma_dead_node(node))) + return 0; + offset = mt_pivots[type] - 1; if (likely(!pivots[offset])) return ma_meta_end(node, type); @@ -4499,6 +4511,9 @@ static inline int mas_prev_node(struct ma_state *mas, unsigned long min) node = mas_mn(mas); slots = ma_slots(node, mt); pivots = ma_pivots(node, mt); + if (unlikely(ma_dead_node(node))) + return 1; + mas->max = pivots[offset]; if (offset) mas->min = pivots[offset - 1] + 1; @@ -4520,6 +4535,9 @@ static inline int mas_prev_node(struct ma_state *mas, unsigned long min) slots = ma_slots(node, mt); pivots = ma_pivots(node, mt); offset = ma_data_end(node, mt, pivots, mas->max); + if (unlikely(ma_dead_node(node))) + return 1; + if (offset) mas->min = pivots[offset - 1] + 1; @@ -4568,6 +4586,7 @@ static inline int mas_next_node(struct ma_state *mas, struct maple_node *node, struct maple_enode *enode; int level = 0; unsigned char offset; + unsigned char node_end; enum maple_type mt; void __rcu **slots; @@ -4591,7 +4610,11 @@ static inline int mas_next_node(struct ma_state *mas, struct maple_node *node, node = mas_mn(mas); mt = mte_node_type(mas->node); pivots = ma_pivots(node, mt); - } while (unlikely(offset == ma_data_end(node, mt, pivots, mas->max))); + node_end = ma_data_end(node, mt, pivots, mas->max); + if (unlikely(ma_dead_node(node))) + return 1; + + } while (unlikely(offset == node_end)); slots = ma_slots(node, mt); pivot = mas_safe_pivot(mas, pivots, ++offset, mt); @@ -4607,6 +4630,9 @@ static inline int mas_next_node(struct ma_state *mas, struct maple_node *node, mt = mte_node_type(mas->node); slots = ma_slots(node, mt); pivots = ma_pivots(node, mt); + if (unlikely(ma_dead_node(node))) + return 1; + offset = 0; pivot = pivots[0]; } @@ -4653,11 +4679,14 @@ static inline void *mas_next_nentry(struct ma_state *mas, return NULL; } - pivots = ma_pivots(node, type); slots = ma_slots(node, type); - mas->index = mas_safe_min(mas, pivots, mas->offset); + pivots = ma_pivots(node, type); count = ma_data_end(node, type, pivots, mas->max); - if (ma_dead_node(node)) + if (unlikely(ma_dead_node(node))) + return NULL; + + mas->index = mas_safe_min(mas, pivots, mas->offset); + if (unlikely(ma_dead_node(node))) return NULL; if (mas->index > max) @@ -4815,6 +4844,11 @@ static inline void *mas_prev_nentry(struct ma_state *mas, unsigned long limit, slots = ma_slots(mn, mt); pivots = ma_pivots(mn, mt); + if (unlikely(ma_dead_node(mn))) { + mas_rewalk(mas, index); + goto retry; + } + if (offset == mt_pivots[mt]) pivot = mas->max; else @@ -6617,11 +6651,11 @@ static inline void *mas_first_entry(struct ma_state *mas, struct maple_node *mn, while (likely(!ma_is_leaf(mt))) { MT_BUG_ON(mas->tree, mte_dead_node(mas->node)); slots = ma_slots(mn, mt); - pivots = ma_pivots(mn, mt); - max = pivots[0]; entry = mas_slot(mas, slots, 0); + pivots = ma_pivots(mn, mt); if (unlikely(ma_dead_node(mn))) return NULL; + max = pivots[0]; mas->node = entry; mn = mas_mn(mas); mt = mte_node_type(mas->node); @@ -6641,13 +6675,13 @@ static inline void *mas_first_entry(struct ma_state *mas, struct maple_node *mn, if (likely(entry)) return entry; - pivots = ma_pivots(mn, mt); - mas->index = pivots[0] + 1; mas->offset = 1; entry = mas_slot(mas, slots, 1); + pivots = ma_pivots(mn, mt); if (unlikely(ma_dead_node(mn))) return NULL; + mas->index = pivots[0] + 1; if (mas->index > limit) goto none; From patchwork Tue Apr 11 15:10:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 82036 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2669873vqo; Tue, 11 Apr 2023 08:42:10 -0700 (PDT) X-Google-Smtp-Source: AKy350YKay7M5h/lro8ZKlPcEGCW7ApMkzn5wxHqKcoN1lgR2Rvp35NW1iv4oPrj5pGSjtMWh2Ov X-Received: by 2002:a17:906:bb11:b0:8b8:c06e:52d8 with SMTP id jz17-20020a170906bb1100b008b8c06e52d8mr11904232ejb.36.1681227730105; Tue, 11 Apr 2023 08:42:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681227730; cv=pass; d=google.com; s=arc-20160816; b=x3PbsmLuu6b0e69RitG+Q0f/2mFaKLZMy9K7ECJr4nrccPYxtFKA3r6mRFdJFSF4+Y HL7kun+xooB/I6hkfrCt/0kgDxxfhy7XQ65cdMm2Csj6fFoZrc5gIMq2iRE/kyCfz+FH uyoSV4lDnfJrzAP+bnAh/sbx9+SSwLsQ/wsvKvihNDVQa+NFXqOyLqNM3hCbZ9/hqFTL mOcxqzUNmF8xhZjk1CxLGBFtNaBXItO7/ZnzMjlu/Rqc5xVm/BJNcRSWIps2dfgZ+VBH C/zTVzZidTrx4AcunTOlW/c1fEP7V+2kn4kC5HO0a0VW3dJexvnbaJkCEbMkmFxnyhc3 lyhg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=AUVa6sK8DhZJT+qVwPZU2lRJ/B9yuxnT+mVXgCEhor8=; b=UWKrCUX44yT+GICum82XbsLA6tx6laRrPV3Z9JzjKgnXbTg91hQ+Wok+BKBMrXXLrb QDFhhb4WgxGbFLn8sxbVYPUJwhJ7Qc3ZXoyJlM2L9haAoWfpU8JlpIrbJc913qv6vXfA 1V1/RvPKLduygKL75dMbaURuQvEL3UiRUmp+WBga2gy/Yzs2UzU+mR1AKt0JhIKxPN/d t3SGs3D2QU65KHfPU3MMQwERtQHCnbetO++lX2am300UrUgD+NhK17dd2/kn37XDUdue rLpYUIQwU6miBvnrQoKxZfr+amWexbUJzzdcM67onoNYnJeQwiO2+r/loBQ6DMKiJ8FE yXOA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b="Quqsb/D0"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=vS0iys1J; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dd7-20020a1709069b8700b009334f7bc132si516692ejc.947.2023.04.11.08.41.46; Tue, 11 Apr 2023 08:42:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b="Quqsb/D0"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=vS0iys1J; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231210AbjDKPND (ORCPT + 99 others); Tue, 11 Apr 2023 11:13:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230455AbjDKPMW (ORCPT ); Tue, 11 Apr 2023 11:12:22 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFE765FF9; Tue, 11 Apr 2023 08:12:02 -0700 (PDT) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33BF1VMf017728; Tue, 11 Apr 2023 15:11:43 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-03-30; bh=AUVa6sK8DhZJT+qVwPZU2lRJ/B9yuxnT+mVXgCEhor8=; b=Quqsb/D0SyJBaBBYwxDPbGA5b9wh/iI1Qil7fal5vfi6xXQw+gFlNogIu6jd3ScF3+Cq D/1ZTG4KH2XFDWexP4tz5mnGDvHzb1X9cJVY36C2qeFhiHgvL+DDZ++m0yjC3aqn7LDc CGWmTh6tD+u0AVUuoZlWK0q1mB8otca+pKi5m+465M+e3bdXDJS1YHWboetYg7jvYplT QM3XVqJGNh0wetJ5+JiOO/rzKisAqczxyXPnS/Jpa6GV14Z0YW+UaeCF1qSAP6Y66kK6 HOWocZEPo8U94R3OKqP2EICcNo+WaWd70uBmeJAvqXU+wlaZhaRHPWO2i66d50ELG+8l aQ== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0bvwr6f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:42 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEQNaP009895; Tue, 11 Apr 2023 15:11:42 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3puw870rsx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mCSGoHRwT9msyiUy/RnxIGOoZXsekuSvkECIpDE4NbafJCGdFugNMP39ZqKWuEYdEnP9iizcztB/FpnTpYVV9ElBtOUqCvIQe/ddEgE6EkOfd9a7o7MpYlk2nNMbSfrEb8djd5cGM1Jqw2jUzz5d2P0R7c/xd5lwWWLjhDzJ1gID3S3jNkUnezvGNKCPBEBoQ5m0iTQg4HmdqVC+GdWM8COAzidJTYmzZe/xur5IWtVxo0FOE2gh+LBMsXQS0IECIpbcOBvTqo+rd5Swv/sshYzPcSR8VvPvdf9gGEjxzztjwT2M8DktkbheJWzk7cO0OMWBgtJWJdtV5EqW2VSr2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=AUVa6sK8DhZJT+qVwPZU2lRJ/B9yuxnT+mVXgCEhor8=; b=gWh+ueuhd4OB7jSwLY0sDIsSqOmdeUPEdlLXdxw4IApAdy7MK/TzjbZNkgnfjyyFmVVaOWmz/ey7mcLWjhkw9+7kHH9zzFT3wrq1UQSz7lSUFm364N+IMH2d1cJFb5d8Fv6oaPrLGsZdWveOOkXx68oq+IUwEf0Y5JMIe3TideBYNj1wmT8u7dj6pkshUtnqvRrVm6SgftzTRPMPrBr4t0iyWHhnTH/PBeCRI6NzyN2qMH1/UFu0j14WHB+OHoHav2ss/AgW5wpqKnyriqpKETATgM03bVb2fOeb/NwqxFxoBP+fLwUOibIGHQaBuzJcMU8mtjyNj7viGI+fvrrbtQ== 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=AUVa6sK8DhZJT+qVwPZU2lRJ/B9yuxnT+mVXgCEhor8=; b=vS0iys1JafNnszhxjZQHB/Ef1sWp0TSiGlpKdMnaaoxdKe6DFTF/GN3VAYKcsUr269zDbKcpjv/oazNtEwmV+sZuZwjI6ByyjOSBLvMhtqiB0FvkpmnINYwZ8rdGeiP1XHeOm2UO8Bip9i+tHK/vJAmZp17tO061MvU9GxRrrn0= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by CY5PR10MB6120.namprd10.prod.outlook.com (2603:10b6:930:34::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.27; Tue, 11 Apr 2023 15:11:40 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da%7]) with mapi id 15.20.6277.035; Tue, 11 Apr 2023 15:11:40 +0000 From: "Liam R. Howlett" To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R. Howlett" , Stable@vger.kernel.org, Vernon Yang , "Liam R . Howlett" Subject: [PATCH 6.1 08/14] maple_tree: refine ma_state init from mas_start() Date: Tue, 11 Apr 2023 11:10:49 -0400 Message-Id: <20230411151055.2910579-9-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411151055.2910579-1-Liam.Howlett@oracle.com> References: <20230411151055.2910579-1-Liam.Howlett@oracle.com> X-ClientProxiedBy: YT4PR01CA0269.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:109::25) To SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR10MB3022:EE_|CY5PR10MB6120:EE_ X-MS-Office365-Filtering-Correlation-Id: 103fd59d-afb7-4677-15f0-08db3a9f0d60 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(396003)(376002)(136003)(366004)(346002)(451199021)(38100700002)(36756003)(86362001)(316002)(26005)(6506007)(8936002)(5660300002)(6512007)(186003)(41300700001)(478600001)(1076003)(2906002)(107886003)(66556008)(66946007)(54906003)(8676002)(6486002)(966005)(2616005)(83380400001)(4326008)(66476007);DIR:OUT;SFP:1101; X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 103fd59d-afb7-4677-15f0-08db3a9f0d60 X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 15:11:40.2646 (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: hdzR5p6TgTHrJZ+lMaCQLARlP3JaXafj/NSQ0pzcU56fPBIP5zySQrrSB6SLhIQcSgDII+ZmPebU110vMWsQ7w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR10MB6120 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-11_10,2023-04-11_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 malwarescore=0 suspectscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304110138 X-Proofpoint-GUID: aWYkKSaky-7VOdy5vVNE1bqOSTeTrv4y X-Proofpoint-ORIG-GUID: aWYkKSaky-7VOdy5vVNE1bqOSTeTrv4y X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762895048159341731?= X-GMAIL-MSGID: =?utf-8?q?1762895048159341731?= From: "Liam R. Howlett" commit 46b345848261009477552d654cb2f65000c30e4d upstream. If mas->node is an MAS_START, there are three cases, and they all assign different values to mas->node and mas->offset. So there is no need to set them to a default value before updating. Update them directly to make them easier to understand and for better readability. Link: https://lkml.kernel.org/r/20221221060058.609003-7-vernon2gm@gmail.com Cc: Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Vernon Yang Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 7c8225e7df13..194963149c2d 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1334,7 +1334,7 @@ static void mas_node_count(struct ma_state *mas, int count) * mas_start() - Sets up maple state for operations. * @mas: The maple state. * - * If mas->node == MAS_START, then set the min, max, depth, and offset to + * If mas->node == MAS_START, then set the min, max and depth to * defaults. * * Return: @@ -1348,22 +1348,22 @@ static inline struct maple_enode *mas_start(struct ma_state *mas) if (likely(mas_is_start(mas))) { struct maple_enode *root; - mas->node = MAS_NONE; mas->min = 0; mas->max = ULONG_MAX; mas->depth = 0; - mas->offset = 0; root = mas_root(mas); /* Tree with nodes */ if (likely(xa_is_node(root))) { mas->depth = 1; mas->node = mte_safe_root(root); + mas->offset = 0; return NULL; } /* empty tree */ if (unlikely(!root)) { + mas->node = MAS_NONE; mas->offset = MAPLE_NODE_SLOTS; return NULL; } From patchwork Tue Apr 11 15:10:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 82020 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2650904vqo; Tue, 11 Apr 2023 08:14:41 -0700 (PDT) X-Google-Smtp-Source: AKy350ZY08CNebFmiYLa2BnZDkJYIWEBAdyakC6yShsOfxjf1JpPUBbiNvQBp4fvw0Xt8rwpAy93 X-Received: by 2002:a17:906:4115:b0:94e:3d6f:9c0f with SMTP id j21-20020a170906411500b0094e3d6f9c0fmr728918ejk.55.1681226081469; Tue, 11 Apr 2023 08:14:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681226081; cv=pass; d=google.com; s=arc-20160816; b=taDwJ27wzuj9RY8Wzbx3DI+E4c9tx08wpBBtytGd7G1eTdsz1o52LJXOX9Ck1Cqw5r /qA0bXdrq51tJIzRnQz2Zd1ywNg66f8W3Q8xIiod06PTO4MhCZgrUsd5fjN0LCXdGC+F 9ReOg17Cay5o5ENHDntG/JJw5f2jgR6SwNTLR9z/NNtDD4yEOPiultXXZS4//ZtkHVmw 2p2L/rs/msBNpRSz4mFXHrNjSolz4jKZ9ImKdzHOnKheGqQH4RcgzNLF4WhVTuclvWL0 nCddTL2tbe/CTt1Ks2n1H3eFmtuULcW+hlMWalfQv4ygfREvNWCh/pkIl0OJfxpyUOlU joWg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=CVmYIVax1Vnyg2HtZbsYqbTA54JV61exTJipRe9E61U=; b=TdpI0n5NA2emKp3E6tE4/gR7UUv472iMVQnOUYBfzUTJ5NK5WCBjovbWj8YZ4WQeD8 kBAzpksqfp43nY8kno1657NniFBrWvvLGE3mbgMmErQGtA8VloFQcTuiARi1XEXC7cb1 1ZHLO0D6LAnR6eQSi98IslVG3rneKEF93u2kVex75mUXGuKX00MIkxOcGwl/Occg9CTj gv+ll9NMyP9f6cyS+5Mj3x5dupX6yxQNbDMXFjPLJeAkkE6mXjKhylhA4RAslWvorQsI WYUP94J5RVR9dquwnaRRm3M5iI99VGchYYNwt3vOGjIfbZ+ldatuzXqb0EmjPbnDWAoC f1bw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=luUxPGbb; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Y9FtvLgI; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v1-20020a056402184100b004acdca4cb9asi13142239edy.636.2023.04.11.08.14.16; Tue, 11 Apr 2023 08:14:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=luUxPGbb; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Y9FtvLgI; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231134AbjDKPNM (ORCPT + 99 others); Tue, 11 Apr 2023 11:13:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230498AbjDKPMY (ORCPT ); Tue, 11 Apr 2023 11:12:24 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7CCF5BA9; Tue, 11 Apr 2023 08:12:03 -0700 (PDT) Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33BF0rEO016812; Tue, 11 Apr 2023 15:11:45 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-03-30; bh=CVmYIVax1Vnyg2HtZbsYqbTA54JV61exTJipRe9E61U=; b=luUxPGbbpuRX552nvf1yThtYWVdj/pChiYPbs8b5VJHo20o5wbpAIxgRZIOE1jA8ivtA co80kO/CwpTpw4Wc/Wr5eByB+bQO9JpRL8LjCe342a+ML4RI8k2dVa91s3HkSvNOtlG7 FBemwsW8T/niUuSrdNqIbgZx+3Si+zek3ff0YHrxHO5Huu6Cjdc5PikKmHfTLhseSDAb ye1cPmVOEcHXD8sXuUT5RNgri/xuC9knGpnMDWytHac1PwIvWG7s22vo99Cduv9QuVTy RBIyT2y5AAyfPwzogeE/KGl3MA3BcJ12UcEiNxL+JziECSHFGIqpxrMeq63x6uvdqCqk mw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0hc5qj0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:45 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEOV7g030894; Tue, 11 Apr 2023 15:11:44 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2107.outbound.protection.outlook.com [104.47.55.107]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3puwbn8g75-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hJZT4b55McYl9rqwgpwkg7S28bYwKPbkDkchApmvvEO3tNRIW0SYlec3etyHZYDooXDqy0AID5LLmNgOUVokaPAnGMrqO7PAShAAisPhmCKfHUbIETgnFC5EkWIMsjfOZ7PeLIQp5yfRIMKVWCmoNY+VxBtPk/J5G+wLmzSG4D3fHFaAjRorfLuVJzu3RZDFiRRKZy83nVcUeBRpV08GLzNT6KiL1UqVMI+s7xWTkIEKp8te/ywLzEhY4rTuHY7Dtgfq048w71AEvFwohpRYzAfKfNNjJEKOoHEa2fmluZZoFU03ZGNniLpqHLx4V7SHhtcXUsziPrmuaJGxxVk+MA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CVmYIVax1Vnyg2HtZbsYqbTA54JV61exTJipRe9E61U=; b=gqOqCYDvmKcIemq1q1NfqXkJx4N+XUFlx9vZEQV8+e/XRoRujgQ8HmEdUnPslEuF/Wi5a+wCbr3Ec2ArQsZxoawmeXrFWsEj3DilSVN3GaXGX+UJZoAVlpfp3gzqZVN3rlRL/kmb1NsG4UCj6Xe/LfdpZkU72/Lw1b+scQz7LzdChuz4/Y/T0/ef1sGfW/GsuMJ1djAxTD6p06u3u8TSqp2d4ez8YXoPNDeBAXEQ2FPLO+r7xRfCtUXqopDeCcospPkX/i4MSXeGas7Dt0LlIvSKm9zG+y1xjfOdNmS5Xshj79jv7ngiGY5uB2nTS4Iad3unak/h36Wf22QFWNFVrQ== 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=CVmYIVax1Vnyg2HtZbsYqbTA54JV61exTJipRe9E61U=; b=Y9FtvLgIn6sZbZ/rwnIMwdggsk7Ac98lyFhEfTNHs6KjiVXQZWS6JjnzyxOn5D3o9tN3uVVs4WuFsS9Yd2A5HVV87Cqy/mGxDm7gWvbxmwFUirSNXuAuHQwO7ozio5PfYa2XySfIw1cbCaiikIccguKTZkbipBAlG3kc4fT9cdU= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by CY5PR10MB6120.namprd10.prod.outlook.com (2603:10b6:930:34::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.27; Tue, 11 Apr 2023 15:11:42 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da%7]) with mapi id 15.20.6277.035; Tue, 11 Apr 2023 15:11:42 +0000 From: "Liam R. Howlett" To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R. Howlett" , Stable@vger.kernel.org, Liam Howlett Subject: [PATCH 6.1 09/14] maple_tree: detect dead nodes in mas_start() Date: Tue, 11 Apr 2023 11:10:50 -0400 Message-Id: <20230411151055.2910579-10-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411151055.2910579-1-Liam.Howlett@oracle.com> References: <20230411151055.2910579-1-Liam.Howlett@oracle.com> X-ClientProxiedBy: YT4PR01CA0263.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:10f::15) To SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR10MB3022:EE_|CY5PR10MB6120:EE_ X-MS-Office365-Filtering-Correlation-Id: 9fdfc090-8307-4fb4-751a-08db3a9f0eca X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(396003)(376002)(136003)(366004)(346002)(451199021)(38100700002)(36756003)(86362001)(316002)(26005)(6506007)(8936002)(5660300002)(6512007)(186003)(41300700001)(478600001)(6666004)(1076003)(2906002)(107886003)(66556008)(66946007)(54906003)(8676002)(6486002)(966005)(2616005)(83380400001)(4326008)(66476007);DIR:OUT;SFP:1101; X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9fdfc090-8307-4fb4-751a-08db3a9f0eca X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 15:11:42.6729 (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: 6kiPgRT5xvy3yqAcIrLwkzFaytAPC17enL/cPAIOob1njuO0wpUZCWOIAD98SBX3qFo/Z6SJEuqb27SNGVmy2A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR10MB6120 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-11_10,2023-04-11_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 mlxscore=0 malwarescore=0 suspectscore=0 bulkscore=0 spamscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304110138 X-Proofpoint-GUID: XOPPqxTTTKZt4G8uS5PLnlRUiHAk71GF X-Proofpoint-ORIG-GUID: XOPPqxTTTKZt4G8uS5PLnlRUiHAk71GF X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762893319423932642?= X-GMAIL-MSGID: =?utf-8?q?1762893319423932642?= From: "Liam R. Howlett" commit a7b92d59c885018cb7bb88539892278e4fd64b29 upstream. When initially starting a search, the root node may already be in the process of being replaced in RCU mode. Detect and restart the walk if this is the case. This is necessary for RCU mode of the maple tree. Link: https://lkml.kernel.org/r/20230227173632.3292573-3-surenb@google.com Cc: Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Liam Howlett --- lib/maple_tree.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 194963149c2d..6fcf08dbdbf9 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1352,12 +1352,16 @@ static inline struct maple_enode *mas_start(struct ma_state *mas) mas->max = ULONG_MAX; mas->depth = 0; +retry: root = mas_root(mas); /* Tree with nodes */ if (likely(xa_is_node(root))) { mas->depth = 1; mas->node = mte_safe_root(root); mas->offset = 0; + if (mte_dead_node(mas->node)) + goto retry; + return NULL; } From patchwork Tue Apr 11 15:10:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 82026 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2659637vqo; Tue, 11 Apr 2023 08:26:48 -0700 (PDT) X-Google-Smtp-Source: AKy350YOEUvKSCVhg0qfZcxkt7ARixTXbwLYRdzHUKX0Y2cEJ3R/JgXzOwMi/sk8QxElKmee1xuR X-Received: by 2002:a17:90b:4ac6:b0:23e:f855:79ed with SMTP id mh6-20020a17090b4ac600b0023ef85579edmr4482526pjb.28.1681226807820; Tue, 11 Apr 2023 08:26:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681226807; cv=pass; d=google.com; s=arc-20160816; b=w3IAsT2llDKt2AcbzTF9pz4+jij3weeDwb+d8Px/XXisnCmqG79JtYldEi5PSnAEkB ml1jOxDmGuZ8kN+CPQojxnPvkngKvLOvL64AQ7ZhNCvbday0Wxbwy4LFC++IBTzwOGud jCxp0NDB4as54h1j0GJZdsRGXLyPeS6oNMyu2qYa1+7OJeNB2IyE8KexcfGYgxZONai1 eqyEF85cZOMRhj3lOk2fnGMzSVm2WTURG8fb0HBrBncQWXdP9wEo9KYKSinzmO9grPc4 2Oivpx8F8Ql52ioMy1WHFq4bVAIo+v5Mt+hUJzGcpc5QfwvmEu0kYTroO1XeWFGAo8M5 1gSw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=xGnXTW5VC6tcdOlTLMFIueElZmHVbODoCfPsVjIEEzE=; b=zgP+5rY66oc7imBWlSY70K9IDsHJPXgdwJocRIcLOJKUK+1Jf5XAoE5Joiw2MkkrFE cJpCLwRSJF1g8WWqSx1zd48JKfjl612Q2NZZfwOtib0rVJ5+zXrXjBBoR+NOjvNi+Nfg 7a84lYKlEV/o6905+0v2A+w9I6GwCje2bIAhVPvAj8fku8Nf1AXXhk2zLsHdKCRO1UnT 0IesL1irHnIRPdGeVfXq0Ovzvn8FwQE/y9eRmaQpP+LG1jnFsRNLFJZeNm6TGASbs9kf LvIMXrdW9Hk6+cP9OEFzeuq1Tjf6SZj0YkF+ic7vXoSkU3wI4y9+G19JBjGCsmV8CYRL 9JVQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b="j/RlKkrH"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=TlhpPo6X; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jy14-20020a17090342ce00b001a652580118si2828654plb.237.2023.04.11.08.26.34; Tue, 11 Apr 2023 08:26:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b="j/RlKkrH"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=TlhpPo6X; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231179AbjDKPN1 (ORCPT + 99 others); Tue, 11 Apr 2023 11:13:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230522AbjDKPMb (ORCPT ); Tue, 11 Apr 2023 11:12:31 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED02E3ABF; Tue, 11 Apr 2023 08:12:08 -0700 (PDT) Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEx9qC019840; Tue, 11 Apr 2023 15:11:48 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-03-30; bh=xGnXTW5VC6tcdOlTLMFIueElZmHVbODoCfPsVjIEEzE=; b=j/RlKkrHH7sNp+/3UQ44q5OZO+DdoxeIV54nII3jH97c7IS/ELtt/PRymm65aVmng4rE Y7uohZNpca3Lh4ZmDWJvncLO0V6wwefKIsXWZUQyruTLQyjzCAAPuYLzQzQm9NOn2eBi 7bGZ5NUbJ2JdNAWr5GKKrqN+IaJAWJIF+FeUc1/hAzuqwm/gtV2qWkomDHSU3GC8BNOR DmZ8vM327ovEy43dG2B+9GP+WFxBlCXdozx789ec5TNhc0J2l8Iw3Zl+X8DHJfczJL9k X6LgcqrsaDA/peg91p2vKzuKKh6QihadEe5XHthz/Br6cd7pEXYEwTibiM7ymf4Io9IR hw== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0b2wpqr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:48 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEUkXk009948; Tue, 11 Apr 2023 15:11:47 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2048.outbound.protection.outlook.com [104.47.66.48]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3puw870rxu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:47 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fe1slJqt53lwF0RhWr73NtF1t+eV8EAZ/kVZuP162RiXpO4UmMDaIYalGk5ArFpOCxJcYUvunOs+53zTVFQRe51S4XxWuB1/BVB7yadFxfhbGeZH7sqPNnlvDo5bJV5Ff9KbkktABf3/Vh/BUuKfG0ATYSoe9mQakJIsFP34c/z+uKHIeP/IkOQ+PnIUuDz3JzuvYR4WkvDOEb9uSHfPUnXNmuhg3yX3FpANV7/fH8mD+i/ESyRuylWsq3k6TucgE78WP5WGhOasdKg4RizIFLRbVQb/bnmaaf9orLQ7Q3A/4jFZ2+aadQEM+cdNBNkh76XQ4dZGVU8rswgVMZgHxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xGnXTW5VC6tcdOlTLMFIueElZmHVbODoCfPsVjIEEzE=; b=duyV/r6R2wwNGQGQiCFDL72cIicq17Ru/MLWAwo14DcyuenE943dgBHgl8v5qJU/1nZ3wbeOUv3mRaVnH1nDzecv7Xr78yhvTGOO28ncW34aLtrbPnt8GJYu8gg0Wi3HJ5/7I4/8wh/qd/ik/o8/aN3kZtgZfeAQuYVE+vwUzLs1YvTSHey2UJG5i6N+xygrMZWCs/7K8WleqzbCYV8Px4+gKAvE90rxh3Y1T50uqqgSXCfz0F5kqlH80hURi/x04hKZLqoLFQHebIfKvqg0K8+i7wRBfcYNFNbEzmgp4O1i6qZpufqN4wXwedwKdWQRmvCMewvMo0axFOSHGV8r/Q== 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=xGnXTW5VC6tcdOlTLMFIueElZmHVbODoCfPsVjIEEzE=; b=TlhpPo6XiQfIvvNw6hIo0PdcSzHpZB4/hJGDdXNtBAhbU7/m6HQXCGFTS7kClVpV0dkR7USd3g0gERk5sTOCcR5O1fUuuxrJXAbJEtUDgP6yfbjqv42cS2hWOHK5O8C1mAiW5on20JASNLrzjQJQd1d40kQAe/H93fuJIhtKmdQ= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by CY5PR10MB6120.namprd10.prod.outlook.com (2603:10b6:930:34::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.27; Tue, 11 Apr 2023 15:11:45 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da%7]) with mapi id 15.20.6277.035; Tue, 11 Apr 2023 15:11:44 +0000 From: "Liam R. Howlett" To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R. Howlett" , Stable@vger.kernel.org, Liam Howlett Subject: [PATCH 6.1 10/14] maple_tree: fix freeing of nodes in rcu mode Date: Tue, 11 Apr 2023 11:10:51 -0400 Message-Id: <20230411151055.2910579-11-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411151055.2910579-1-Liam.Howlett@oracle.com> References: <20230411151055.2910579-1-Liam.Howlett@oracle.com> X-ClientProxiedBy: YT4PR01CA0042.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:fe::22) To SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR10MB3022:EE_|CY5PR10MB6120:EE_ X-MS-Office365-Filtering-Correlation-Id: 22ea3d3a-f7f3-455b-c1c7-08db3a9f1021 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(396003)(376002)(136003)(366004)(346002)(451199021)(38100700002)(36756003)(86362001)(316002)(26005)(6506007)(8936002)(5660300002)(6512007)(186003)(41300700001)(478600001)(6666004)(1076003)(2906002)(107886003)(66556008)(66946007)(54906003)(8676002)(6486002)(966005)(2616005)(83380400001)(4326008)(66476007);DIR:OUT;SFP:1101; X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 22ea3d3a-f7f3-455b-c1c7-08db3a9f1021 X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 15:11:44.9563 (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: VEtO3mikCSYF3tkFNtY/ldYXhjCisG6JPfLfn2w8zqVsxy2SvIk2X9V3/QaOer+V+MjeCNaoAFz63VC+qIRofw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR10MB6120 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-11_10,2023-04-11_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 phishscore=0 mlxscore=0 malwarescore=0 suspectscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304110138 X-Proofpoint-GUID: q_cYDzAUWgXFOG4g9smWkTKZqEC0NWrl X-Proofpoint-ORIG-GUID: q_cYDzAUWgXFOG4g9smWkTKZqEC0NWrl X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762894080779128087?= X-GMAIL-MSGID: =?utf-8?q?1762894080779128087?= From: "Liam R. Howlett" commit 2e5b4921f8efc9e845f4f04741797d16f36847eb upstream. The walk to destroy the nodes was not always setting the node type and would result in a destroy method potentially using the values as nodes. Avoid this by setting the correct node types. This is necessary for the RCU mode of the maple tree. Link: https://lkml.kernel.org/r/20230227173632.3292573-4-surenb@google.com Cc: Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Liam Howlett --- lib/maple_tree.c | 73 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 6fcf08dbdbf9..0f0a2d4850e8 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -892,6 +892,44 @@ static inline void ma_set_meta(struct maple_node *mn, enum maple_type mt, meta->end = end; } +/* + * mas_clear_meta() - clear the metadata information of a node, if it exists + * @mas: The maple state + * @mn: The maple node + * @mt: The maple node type + * @offset: The offset of the highest sub-gap in this node. + * @end: The end of the data in this node. + */ +static inline void mas_clear_meta(struct ma_state *mas, struct maple_node *mn, + enum maple_type mt) +{ + struct maple_metadata *meta; + unsigned long *pivots; + void __rcu **slots; + void *next; + + switch (mt) { + case maple_range_64: + pivots = mn->mr64.pivot; + if (unlikely(pivots[MAPLE_RANGE64_SLOTS - 2])) { + slots = mn->mr64.slot; + next = mas_slot_locked(mas, slots, + MAPLE_RANGE64_SLOTS - 1); + if (unlikely((mte_to_node(next) && mte_node_type(next)))) + return; /* The last slot is a node, no metadata */ + } + fallthrough; + case maple_arange_64: + meta = ma_meta(mn, mt); + break; + default: + return; + } + + meta->gap = 0; + meta->end = 0; +} + /* * ma_meta_end() - Get the data end of a node from the metadata * @mn: The maple node @@ -5439,20 +5477,22 @@ static inline int mas_rev_alloc(struct ma_state *mas, unsigned long min, * mas_dead_leaves() - Mark all leaves of a node as dead. * @mas: The maple state * @slots: Pointer to the slot array + * @type: The maple node type * * Must hold the write lock. * * Return: The number of leaves marked as dead. */ static inline -unsigned char mas_dead_leaves(struct ma_state *mas, void __rcu **slots) +unsigned char mas_dead_leaves(struct ma_state *mas, void __rcu **slots, + enum maple_type mt) { struct maple_node *node; enum maple_type type; void *entry; int offset; - for (offset = 0; offset < mt_slot_count(mas->node); offset++) { + for (offset = 0; offset < mt_slots[mt]; offset++) { entry = mas_slot_locked(mas, slots, offset); type = mte_node_type(entry); node = mte_to_node(entry); @@ -5471,14 +5511,13 @@ unsigned char mas_dead_leaves(struct ma_state *mas, void __rcu **slots) static void __rcu **mas_dead_walk(struct ma_state *mas, unsigned char offset) { - struct maple_node *node, *next; + struct maple_node *next; void __rcu **slots = NULL; next = mas_mn(mas); do { - mas->node = ma_enode_ptr(next); - node = mas_mn(mas); - slots = ma_slots(node, node->type); + mas->node = mt_mk_node(next, next->type); + slots = ma_slots(next, next->type); next = mas_slot_locked(mas, slots, offset); offset = 0; } while (!ma_is_leaf(next->type)); @@ -5542,11 +5581,14 @@ static inline void __rcu **mas_destroy_descend(struct ma_state *mas, node = mas_mn(mas); slots = ma_slots(node, mte_node_type(mas->node)); next = mas_slot_locked(mas, slots, 0); - if ((mte_dead_node(next))) + if ((mte_dead_node(next))) { + mte_to_node(next)->type = mte_node_type(next); next = mas_slot_locked(mas, slots, 1); + } mte_set_node_dead(mas->node); node->type = mte_node_type(mas->node); + mas_clear_meta(mas, node, node->type); node->piv_parent = prev; node->parent_slot = offset; offset = 0; @@ -5566,13 +5608,18 @@ static void mt_destroy_walk(struct maple_enode *enode, unsigned char ma_flags, MA_STATE(mas, &mt, 0, 0); - if (mte_is_leaf(enode)) + mas.node = enode; + if (mte_is_leaf(enode)) { + node->type = mte_node_type(enode); goto free_leaf; + } + ma_flags &= ~MT_FLAGS_LOCK_MASK; mt_init_flags(&mt, ma_flags); mas_lock(&mas); - mas.node = start = enode; + mte_to_node(enode)->ma_flags = ma_flags; + start = enode; slots = mas_destroy_descend(&mas, start, 0); node = mas_mn(&mas); do { @@ -5580,7 +5627,8 @@ static void mt_destroy_walk(struct maple_enode *enode, unsigned char ma_flags, unsigned char offset; struct maple_enode *parent, *tmp; - node->slot_len = mas_dead_leaves(&mas, slots); + node->type = mte_node_type(mas.node); + node->slot_len = mas_dead_leaves(&mas, slots, node->type); if (free) mt_free_bulk(node->slot_len, slots); offset = node->parent_slot + 1; @@ -5604,7 +5652,8 @@ static void mt_destroy_walk(struct maple_enode *enode, unsigned char ma_flags, } while (start != mas.node); node = mas_mn(&mas); - node->slot_len = mas_dead_leaves(&mas, slots); + node->type = mte_node_type(mas.node); + node->slot_len = mas_dead_leaves(&mas, slots, node->type); if (free) mt_free_bulk(node->slot_len, slots); @@ -5614,6 +5663,8 @@ static void mt_destroy_walk(struct maple_enode *enode, unsigned char ma_flags, free_leaf: if (free) mt_free_rcu(&node->rcu); + else + mas_clear_meta(&mas, node, node->type); } /* From patchwork Tue Apr 11 15:10:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 82032 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2662932vqo; Tue, 11 Apr 2023 08:31:31 -0700 (PDT) X-Google-Smtp-Source: AKy350ZcfBhHBZd/RLICQXJrQ3BwBGNTd1FOYWOjvVKMNXtT/9pKUCLA+zE5JCUmlyJZeCeCtqI3 X-Received: by 2002:a17:906:c242:b0:92d:591f:6586 with SMTP id bl2-20020a170906c24200b0092d591f6586mr9845511ejb.34.1681227091695; Tue, 11 Apr 2023 08:31:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681227091; cv=pass; d=google.com; s=arc-20160816; b=iXllZATjPUhK8QvvpriV3Vxjo2CTBlaXCdKv1rtFy7Fi6ekClW8d65wpJ8sTy1BeIt ZrfnU5JvMDWALGScAKv3MLOKyx45HCeiomu6yp9MxdIHc9610czvkFj8WSNUfVioqNbk znKULLUMgTmCeHXngEQyLa8cGqyKSpmZeKMstUNOCIV4pJHbD/ZQw8dGGjmOTwb99Z53 /AzVZatAv5q7GIek+7vHc+kZUEgdsYoaCotHervW4ZsD1oYL9YbGroNw/+34K0fURAyW NsI+tDnAaldNh9iEztf7r2AHxBks6j19jAb+olz1Gh4+mr+WXOy/Q+HdwWHeXKQvfZLA HGPQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=jQXH3slFlwhM6CF0XD0xGd+nWcVRiCshDHSzp1JjNsw=; b=yLgXn8gjuVXb6zZDk4XlpoopHw7mzIHL1xx7sT3KiajU7+ifUL5S0QNLatZKX5qll2 p1hnqLnEeTjgAIxioWir0GQP3dMB/9NPufs4J39xhSSNYo5CAmgJvr7ApegP+5TNUbil YmoWS1T9JZBPwKRAVRysFB8movHyCkKEz4U12/l33ZkN9al5K5a3P1kKyvPgaWCH6+9d AB6QGboFpvcy2Uz0BD86PSL2ycOPgKd0YLKsTiqx4FWe1U82CIiew9Cx34D+ECHwJCHG za9Asr9hGQtHGjxIX+jSpI8vhametCwcQennyWmq1Y0l9I6NvdsVH3wtbZbScV/L8lTX YkBg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=B+wS5Exb; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="E/ri12hI"; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hp41-20020a1709073e2900b0094c9d0ce996si335495ejc.475.2023.04.11.08.31.06; Tue, 11 Apr 2023 08:31:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=B+wS5Exb; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="E/ri12hI"; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231250AbjDKPNg (ORCPT + 99 others); Tue, 11 Apr 2023 11:13:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231187AbjDKPMv (ORCPT ); Tue, 11 Apr 2023 11:12:51 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D912525E; Tue, 11 Apr 2023 08:12:12 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEwtCZ022960; Tue, 11 Apr 2023 15:11:50 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-03-30; bh=jQXH3slFlwhM6CF0XD0xGd+nWcVRiCshDHSzp1JjNsw=; b=B+wS5ExbiB+yts5VISnvupGs7g1YvCChQjaFcpgu/eYKhha1TCC5/06Ssz4fFpiNpY9G wOtseVM2XBpgoL2Ph7Ng1mI9sOo4a0z/Rt9qwYEC185DM/AX/W3v/TGyY96nhXO9RfmQ S5daP0ksSTJwEOsemedI2KsWNl7aTEIL0p+jVK1IpS5jkKNxMxvrRvzrYyEpKunyz3Vt D6OKQN1KelXEfQyCI7IKekyc2jeqcOx9fav64D7Z8IjbcuUo/lZmESqk+Q2j24dZQwY5 4cziQb/6iCFdDipZmt2OPwE8eMA9JRzPKGaxLJzCY+11x/N7TEnUYV0DBLBwQy2RBOOC Pg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0bwdrwx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:50 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEV6Au012913; Tue, 11 Apr 2023 15:11:49 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2048.outbound.protection.outlook.com [104.47.66.48]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3puwdp0yc1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:49 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eEml9e1cXFpktysoaEbL5MHugC9fYdiNtTGGQArpwQRIgFIpzjqW8gAiJHRskQrbQ142nC0jSTaFCIQ8EZNeEc60DonXKaaCOx/IAY4CSs/iM/746f07kS3wFwqK+lfnVBhpJOR2F6+rKRxOk8hCvbjne4/DI+hL9iDYWPlGTWimK1BdTeqSj2514D9zMSO+pKOw0beSS3io1dQ+RljcF48Th6v0zlXrHuBMaiJMb2142GqJbGn/D0tZBH2X6mtL0rSsCEWvatkPuKwSTrHtBy4SpUxRuhCtTvUifd+QXU+rXD/74upolmkguBREJ39GQUHDvkjCcbxYVKowioy3mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jQXH3slFlwhM6CF0XD0xGd+nWcVRiCshDHSzp1JjNsw=; b=l17KLFEqVKbI4hmY+K9nD9VxYkzxM0wQurvspWJ1e6Ug6PbtMGLJg5/WQhKHziiMrEqikBCsW4nGpRGpOwLusdU7moC86NOkCyEBbj1ERz2hAQp/FYH6rhzg2SlfHowZuEHH4RwboocrN9W9WFppZL+bbIRa7f/NCslT8lJ4WlYd16Tf2oiryNZfPWGYq3Tx5UYX3zS3evq0C2xVlgfvpmS3egBmqo4t/8KZBBDzUd5h9SBFq0TnacoqaLjvIky5mrgdV+JEy5yTi6nLodTESdcPVjE7yEvvC9Mczwj3zJUGNdWwlvT57COrb23+7RI5p2QyQdPSAdi0NNVhT93pGA== 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=jQXH3slFlwhM6CF0XD0xGd+nWcVRiCshDHSzp1JjNsw=; b=E/ri12hI6RO8V72i8EtpNmYUI1D5Iar0hfh0p2qZM87QO5OAQ2C3LPvz7PiCJhQLSFmZm46l+RkXiwkz+uPf8cwJldV5I7kXfYoAB5tIl47IWE9HCgIO6MuJlrhL4a/yVMpeBCn3UHtu0/o89IEzKX9YeBm4n/FDTURhPP0Wi14= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by SJ0PR10MB4718.namprd10.prod.outlook.com (2603:10b6:a03:2dd::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.35; Tue, 11 Apr 2023 15:11:47 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da%7]) with mapi id 15.20.6277.035; Tue, 11 Apr 2023 15:11:47 +0000 From: "Liam R. Howlett" To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R. Howlett" , Liam Howlett Subject: [PATCH 6.1 11/14] maple_tree: remove extra smp_wmb() from mas_dead_leaves() Date: Tue, 11 Apr 2023 11:10:52 -0400 Message-Id: <20230411151055.2910579-12-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411151055.2910579-1-Liam.Howlett@oracle.com> References: <20230411151055.2910579-1-Liam.Howlett@oracle.com> X-ClientProxiedBy: YT3PR01CA0006.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:86::11) To SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR10MB3022:EE_|SJ0PR10MB4718:EE_ X-MS-Office365-Filtering-Correlation-Id: dc325e29-65a1-495b-8532-08db3a9f116f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lxvpAIJAqzL6hoGLc+KHdQ5j/p5Aipe2+xWZPVNzipLRyF3oGBS03cPKnTsSBJQTFCdCeIXiacr6+hjPp5CjNWNVUEo4RIo0EmstkQYF5HM5v1C1RLhvX6oYEwh1YW0e0dKu/dQoouaY+q0faCKwmGYc4+EnY/xvN+hvFt8EhMP2dP43LppU9gGJSAQWkgw3KCN+NVmZqebL6FippNCP9bLwFwG51tt2R7qW5ys7JmClzukoaOR0e2olUMAtj3wuuofwbXaiyMrER1DJ3pOhEMQJzuyyXTILv81skLUNxy0lPKERxkqiPcUtDco+IG3BmGaAP2iUtcyP/4Rv8nv+0M97R8nAFyr1D4H44d8cQE2tAsEv2LAsDLSlmgqbOmRab0JmsJyU3inrhBhKC4jw09ZqSh6WxS90lQ1BsRHjmrhZR0aVM//7CxXWr0ZJrTTi06jOHbyb064//icHfZQiNqxKVKMQG3A6NHfRxrWRCeqGh/VkfDfex47JYD233JE409t1jA+k+y7/LPcerctcJbMAHnqK8zaxMmUCbbabTmE= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(136003)(346002)(396003)(366004)(376002)(39860400002)(451199021)(38100700002)(6512007)(6506007)(186003)(6666004)(26005)(1076003)(107886003)(2616005)(4744005)(8676002)(83380400001)(2906002)(6486002)(5660300002)(8936002)(966005)(36756003)(478600001)(4326008)(86362001)(316002)(66476007)(41300700001)(66556008)(54906003)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Si2e+AoqHgWxkk7+RC6XPWctCN2RxtU/Tg7Z0Cj01I0mR868DdUfks68jy7Y4p7h01Xb3eY2d5zvAdcXvJQnmzHmDT04Xmkj5TzPiW36D9sX4qXlUxUI9hCk1JiJC+dd4K9Gk5P+JHU8er/aNUz7LK6X7doqiOxDH6c5iTP+OQdqMHIN8lsDV2JUTC6fr5ixUTAEfLmTOqjVAz3bwgsS5ksYzl0xga7L1QJK2qeSbPoPOuLPdGEft+bBHhJ0hdt0AiwDXWKjOaBC60zFJrmqfsmxzOSJv205AsnkcH35LMXOUaytZauhT4ybHzb986JApF5B5bsBCqy/tTc1IN/jjnwk879CtYlq30d8itwk+XThX9JHJ8dWncAhZPjcyVlQUnP3LEOrmnPMm4Ax1RaWHqwyOMNDtet/c3/CZTA1gNTeAr1bsL+McQhRBRzNR8McsE57k0UkrTwqPAookqc0WAjcXOvZQFb0yDtPmBOwNvYDg9YEpwBPGu6lL/IGQb07IX6RWkyhJXh3AVkFZCCGKd3B0poBe8uCRFZOkP29fvIFx6/LbAiaUiRSrGg0RJLQiurN4LGLnGAS5DpvUf+W3MM3DsV/Da6HW0nm+kAyrGM5RQZBNAV94gJxCsSHom/Gj582LvSyt22f6WcJ86rlWF3v7LTUNGQ2gsfzVkoa7yC0+ZqRsnTs28ujl/co1np/qXISkyLhsSQO9gqf8dxKALZ5R6xrJh3nsLd/x6C9QMUodpfmG9f6u9JDo+oUFm7dZDMiKydsbcl0Ov8LnHAGWArgEAPdOjbP7R/CJcIeNZTnmaYatQozMTD5SZWdG2S4/BgOy+CVB/hll2pRjWxLWkIS7RUwHsjxxfvJttVv/BSUk4BoMPncGmUKTi+1VLShzo17p6QXEgS5rjqStAH+eCYFXISKgpw45RfgT9aEL8I8MUosObo0jBF3fwTpAYxSR7rP1YjAzsHymv8MRlmyyp+t2Q7WVvAKvANP5xTSps1FgCGpxTuKQsiJKfd4WvEPI49SPRY2aLpsghbtwkyDXgQUDOthWvbKqSQruK4iaxoj8PGgQaVejCl7e78gIZZ7lBE0NJOec3E1QORa+T3CH9RymX1J3kYVtqcA21HiyC5ab24Usy6mP3Hmp3v1G/+ziyKP6qXF0RtttUJT7NMns79U7CYcFS+WXhOtCuoZAqiN2kxQ23adnmXCIixV2DtrZt/CK28scCUEC8nmZ6gLqkoMXDqd6CPg7awSW0Iz/RmpHvZxYOAt7Lwyb8gg6IOytlxtNcHHaXBPz9RNHhlgmSUCPr3aPKdDlaKX58yffP99CYFye6Un97Tie9mNpeRSMJAlVueO3p+AcYUhIkxRqJsbjI07fU+9Bs6CMEOo8I4GY2COpQtlI1xcFHs2Dt16xSygQnqhOxqN9ROHz/bbA0ET1MI9MfpX1Gd10bKtxvkbdS8ku1xwXmXs3Inl4Nwb9R/FzkIL8XLn2qnRjWulJRuFO+dOiDHxF08OWYJTVQx9wR6YErHMmUcbX+NlcGY4Id3WEdKZ7NKlcMNyvj5/0yg6kgxySsRdeJjRl86oDpN7bIdIa/WULA/hVI9maUvhNCPdrvbe1Ic9LlGgSPua6A== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: ul+rmDbF4v/QtkrjdytlduULWjAM2XFr/Yil3JW0Ybj4RaMiKAS+qXdgcbN8PGkoW4NjqM2PcsZA5gqz37FkMPAacLfb+BS9UqzXfo0Z3uH1QBCsjgq3FkY8YIrPoxIE6bk9bSYIRyR9eDI3ZUTTwmqRmujp3Y9Gi7AjZCvd9QGTlNUEjBTBePhUyNnRgaMRcprcI5V6earb1oU2rA01x6ByIi51TvoXu8NHcEC/89s48c8BptXAIM3nNBX3UnxptKDAK2RfjPxL+t7ExbNFTSXg4kp3sz5sT0SdP/6abqnKQvHR1F775idylPs63RsJFXJrqd88JQbiJZD9y/TRAt6yyfuo5IRnSHEo8CdwUzqOW/zxMtwPkzxgwIT0ffEAduQoI0j9GCpiGOwOanOGax9KGyttKmQkkzb5pj8mm5mM3fxWrCPX+9K+fAh/mTAs+XbzeRTc9bJFLfFL54AVuwHo2oxYPG4PokLT6hwcenf1OIm0KQyK6VWd7GwbrbjkTptWIEAYj33o53V+ItcQCSgVgCf+6uRrpUr6h7cB+MbmsIPMPPsW+36+LVsqYP8czdZayWYv1q2Jtsl6AzKFEWJItf88S9VYmwe7MLmKWWkafF18XFL8aKO7f8DOBu25tClAAXK1acjsbTC8/qNXd+5JFcru18CMGJyyrr4xb/DpJszOn++jC/DFRXOXrZ1AoiJ1x0Ufz5emqqpiw24OR6XdBjQwC7PCak0d0xgDLd/SuodvJmKiELsjVyyWkr8GGHkhaI0bkAx3Sm/9l+8DtuIjo6O3y6dM8Q8Kk/OTwmrD/YZhNhPslD0fCbQNOsbEgWSDHSWO517boY8/eFxibgwg/Pnp2Te040a3DbiWPts51eFzCZtUhbErGClRP7sigR5VHHSBes9nuqqZPi7cVw== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc325e29-65a1-495b-8532-08db3a9f116f X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 15:11:47.1084 (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: ZWDVSp7F8UlDT6O22aLHpZy4hpULHbCP6VW5jfPObhMwCZ/nc6Ji0RQl6zoj6o5R+HpqT6JSV1t3uimQuUmMHw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4718 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-11_10,2023-04-11_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304110138 X-Proofpoint-ORIG-GUID: SjhcaOHj6L9RN9-2k1-xQA54gax6L52f X-Proofpoint-GUID: SjhcaOHj6L9RN9-2k1-xQA54gax6L52f X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762894379068423752?= X-GMAIL-MSGID: =?utf-8?q?1762894379068423752?= From: "Liam R. Howlett" commit 8372f4d83f96f35915106093cde4565836587123 upstream. The call to mte_set_dead_node() before the smp_wmb() already calls smp_wmb() so this is not needed. This is an optimization for the RCU mode of the maple tree. Link: https://lkml.kernel.org/r/20230227173632.3292573-5-surenb@google.com Fixes: 54a611b60590 ("Maple Tree: add new data structure") Cc: stable@vger.kernel.org Signed-off-by: Liam Howlett --- lib/maple_tree.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 0f0a2d4850e8..281be0997e55 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -5501,7 +5501,6 @@ unsigned char mas_dead_leaves(struct ma_state *mas, void __rcu **slots, break; mte_set_node_dead(entry); - smp_wmb(); /* Needed for RCU */ node->type = type; rcu_assign_pointer(slots[offset], node); } From patchwork Tue Apr 11 15:10:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 82040 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2672244vqo; Tue, 11 Apr 2023 08:45:59 -0700 (PDT) X-Google-Smtp-Source: AKy350Z0runCNe4gsavmMDAy6kqc6BOwY03sRB1RjIO2zDAXpslD9mwJtoK39Ij2BayWLX70qCtw X-Received: by 2002:a17:902:fb90:b0:1a2:58f1:5e1d with SMTP id lg16-20020a170902fb9000b001a258f15e1dmr11276513plb.36.1681227959622; Tue, 11 Apr 2023 08:45:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681227959; cv=pass; d=google.com; s=arc-20160816; b=J05ZRM/EdE4Th4h9kISe36nL6cL+GW2ojkStbHj2ZXiDQjGxnFBHAk6UK6x93nFtNq yvN/R3auScnlWHgIbP5V7bwTffwsscoiU5Wu0bcolX6+ihQhiRmaeLhA47egCzgVARj6 N9lnditIJhDjZ1JDmA6EaoxhDbErosEMd0DVvMRnGrzfYY5cKFBcBw3oc7OIgzG9tZ84 pbfrAO408sgrrabw3cdyJ3sCTOtiHsZGs2OUKNHLYy0j5shkMRbnJD0x2GsmXDsO5A/0 RPXLRb3r+urRXPTOEUneOyPe64YFCJpQIn1340VM6HxHLGjyV3OviEN9t18+mASKz8jN 8wpQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=x17052nrhP8f+waEmBBkJqRQ2lxoNOo2YHzvNVbg+Ec=; b=Zo+JeqUDB6QRelrCdSrjUoOaqotsb0t27p8DOM2x9bAGOlRFSf1P2xyYjmuOQ4dnrB 4HGY3/hQUGFtj4JLU7OgPKxG3u5hQPdeptwltU2BvaOo70G0Ose4zKNyAigDOCfnIN0J KdSV3YVUiM1HMaMvlbSJIHj+jF7erpeW22SYKFrXcXk/wdugjcyjJNsCofOrZlUzDZwq jfoBiUi6SbiXJXWFQqgOz5jKUpOiqZQdHticQ7llVtiNL5CaDfaFDvXZ7Mp8aUAGEKaI zyj4xT42+gf8pChLjAnyzQdpJJ3w94j04NyTdvcmyt9DgVntv+TO3gctRcD4s2y9EcnS ZSxg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=L+HhAN0S; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=MJQijBUu; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s12-20020a632c0c000000b00517a9eb2729si9649179pgs.500.2023.04.11.08.45.46; Tue, 11 Apr 2023 08:45:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=L+HhAN0S; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=MJQijBUu; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230424AbjDKPNz (ORCPT + 99 others); Tue, 11 Apr 2023 11:13:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230502AbjDKPNU (ORCPT ); Tue, 11 Apr 2023 11:13:20 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0D6F5FE7; Tue, 11 Apr 2023 08:12:18 -0700 (PDT) Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEx5w1005446; Tue, 11 Apr 2023 15:11:53 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-03-30; bh=x17052nrhP8f+waEmBBkJqRQ2lxoNOo2YHzvNVbg+Ec=; b=L+HhAN0SJ28TRoqCq8tyVZXL5Wqn0Fzv2Dd5UaJTzbaIoUOlvBd1bmfSzi0xQx7n7e2J zHInGBLmN8whc/oeyw92t1M5UAdi2dO0BmOPtwWByxZKzD8BrDDVH4ySIdzqy17CdpLy cO0N46U8zBOBfph3iKCo8BFRbgz73reAwNDEeAT5MpSxtoQeijcPrCRYPYTz4/nWsRhL gdaAnTr5vH5dT5b26mxIrSCs2tJs66gf3ALwE2dEpGeUSzsS3Z52801tXfMqdh3eMdAv 9/0gFNYWx+F2VKZkK0eohkxUoGP15c+pa1doQ5hkYU1jEw4Ed1p+u0Z/frnQykMwG3MH cg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0e7dnp3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:53 +0000 Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33BER0x7008042; Tue, 11 Apr 2023 15:11:52 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2047.outbound.protection.outlook.com [104.47.66.47]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3puwc497w9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:52 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZcHK/ecRnuP5TNmJuaR/yChq7qd7wNi8aRj3AYarcb3nlxmd0ZKcZlUGyQ9ElGJj7M1+K0OoBqfEDcPkyeeTRRdxoOZcJ+IPDiv9ixXSbgNMmK/JnPHHmMClxG+IdBLzQMDqSXpmJyPZQtYNOBj81Kj7jiECtHuWseu9bGJm5NrnypAgOErmYKnORY7Z57LmJOdWJblZKACrqI0zrHyEvo4i5vjy6V7eCPAVhnF3NqWZeXRV6PMY0F2qFmz6Ku4qNa05Vp0mHq+lHWCJ2btRDT7R7V6PkcjTuz+S4qkUj4SnyRD2OVDhf7XcgWynvJMAqzN3FntGiBD9dI3iuY1H2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=x17052nrhP8f+waEmBBkJqRQ2lxoNOo2YHzvNVbg+Ec=; b=cbIZG0R/f7b10Aw0O4w7qJrl83YSFOuA1UmRZtGReczCnMJV0O3x9DkOG2ui0PXDSJVlYetvAHb27uv8GptTJ9WJpXH95dGo9LiecBmAyUbmBIbV+VGixgRwKUHOo5Usjs1sH9lDH5NLwp/PYnaBdcX33FfGbFS0UJWUcESGDC1xPehYHRgNnFb0mrSwevtzeDgawvoNlHV6XDOjfA+W9VJG58LzDzJ+qMGTV/xiHuRwErB+6u9oBTTnChERIvNqUyNzxONs3vQGgs5ZgvuTI6BeJCefmuyhuO1uC3haMKhzV9Ewj+WPN6jKF9CWYi4wgDPWunrEPui9vqkW2O3wuw== 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=x17052nrhP8f+waEmBBkJqRQ2lxoNOo2YHzvNVbg+Ec=; b=MJQijBUuh36pSN9FlOsZyR4SyQOLgIBMGQ7nvZ/VzGwzsfE0TUZLk41nCmaqLqSPsN+N2xwX+OHCSTivVoTBD0KXb7Dn7PcO40U5eyYg1LmGjIpvYMKXBmiRTJ8K4WhdO0m4BbelNvwjCJ4W6VQghS9hnaZLiltecBxh97bwqr4= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by SJ0PR10MB4718.namprd10.prod.outlook.com (2603:10b6:a03:2dd::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.35; Tue, 11 Apr 2023 15:11:50 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da%7]) with mapi id 15.20.6277.035; Tue, 11 Apr 2023 15:11:50 +0000 From: "Liam R. Howlett" To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R. Howlett" , "Liam R . Howlett" Subject: [PATCH 6.1 12/14] maple_tree: add smp_rmb() to dead node detection Date: Tue, 11 Apr 2023 11:10:53 -0400 Message-Id: <20230411151055.2910579-13-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411151055.2910579-1-Liam.Howlett@oracle.com> References: <20230411151055.2910579-1-Liam.Howlett@oracle.com> X-ClientProxiedBy: YT4P288CA0063.CANP288.PROD.OUTLOOK.COM (2603:10b6:b01:d2::28) To SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR10MB3022:EE_|SJ0PR10MB4718:EE_ X-MS-Office365-Filtering-Correlation-Id: 4ab880bd-4863-4462-7c45-08db3a9f1334 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fpOEcDjiGBmxPf8RmvzIaJCivIulZsIfRWJ3GtQ2GEweV9VlO7jhACl++1n+Br8EiRWl8RlUC0GThpHu7fimjNjQM1rKmV3IaNy5fJ+bf+QkxxPJxSK/vAYD0rOI4HX/Q/Y1s/6Q8yuOD/qUf9DzWJyOtuZt9zraFZcNbygVulku8ujveg+f/V1LqyisgoTW7HuZsWVlm96ecETvdngda7edFHhdB5nlBHzL20zSZTTptcxNwxi9D1GvZo+2eC50qzZUz6ewe9Vc8N9zgrHj6Xlzw3pUGTnzgK70vBgKWT8ruJmrexPQEKsEda8A7znclHuZg61w8n/PCK99c9L0uxplpiUt33FXWkUiOW+mu4abLwgjxFORZKPoNOcKsez+vg3EzuJapRCP1wlhBqzt3ee0ngjVsj4SEMH1O1+vuEhD9g40uDiUtu3dtiqp95p0KVVwwuIWLQ84jfuLx3oBPI98b5IwuCpk8YrxNOCp0Pt1h4c1lFv7lbK/tDQZcqVGsQf4f2ef2UjxaPFdhY0zYMD5wMK688lnWzpIXcME/Uw= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(136003)(346002)(396003)(366004)(376002)(39860400002)(451199021)(38100700002)(6512007)(6506007)(186003)(26005)(1076003)(107886003)(2616005)(8676002)(83380400001)(2906002)(6486002)(5660300002)(8936002)(966005)(36756003)(478600001)(4326008)(86362001)(316002)(66476007)(41300700001)(66556008)(54906003)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SIV9ZNotM0BmG9uYSNPysKoPhaRbEqed6IpO+vaytVXKVi235ct8NTvBQL0fB1pHTw17YZ0YL/3ZBRT1n8fGUk4aErO84yMXc1ZmTw4p0a3Zun0EPbmMpa8QFITJsZ3BoCYY8ThrM500TnsZt7qVfxqvlwkrPjI5UxQe6C85sdRJFSabxKs0csNPt6E8MxW5wNt3PsHuN4AGwqSwTneSE4ujaPrnkfoxDAHHW1UJ41mQ6NLzOpqpJwfe6YBX0inOo+Q6aKwR4sOE/SFl8XrTy9dVgCIvTGgfO+aPfSz68VLHOmnPs8hWRVXUMjZbJHXeS9VYCodh/3qq5sTFow06xeQD1RYZNK4epAFFzZndGZ2pYAiPIgaRZPoO449dsC/NYrDApEMf71Gm7uwlHpRJKNwLErgdc2tcVV0PmcVsO5uFXbNEcASLsT5Z8iokhoXLC3/nZi4kPUVkV8RXC7sIToectYXT5wsZU0a9xQwkwTRJyzbozr5mYWrg7fVD8BoMwYsQBFISHfjKsBa4+ewla8i2Dpidytz9dyQ274VpPH8GsQpozf8IXtN384TNcmeIRgyFi8utrHIVW//+l+fkdLUp3gfmL7ra6VzJykN+c56LEMdRKXpYyCi986dxQ4+q1Qw5Wd0fPVdrQ7Mg3uMKwCXvjCuLw7UrCFvSEPgc/BvLEGxvwtBWd6gzdv1wcBOQHr2Q3fX0MVzl5JUcI5KOEBj6dzF2aC6mWfSkeA/4p3ecUqWMfFuaVYQGAdpdGlQiWMu+uSDMb4lp2std4kaUcavylNjZ4hBbqogJXWVWwgfHLP4YtXQQc8cUuxxeloAYz/DtdA7Qx8bmPCwjy0mmYASOjKImUEYvO7/12igPgL2Z05LDDUxXYhO+kMtuUohebEp6ouXcQit5WakAE8OLx+LzPPrT12STffZzk/RC2W/R4vcAbzAKiFUkAUBAyAU/llPZGt2l9F4spbUpmkjLLdzv5ZxYo+FlfxioM3ySqpe6oHl2GO4aFGxhhAaXE/LgKdjFo/2c3niSiXpIWa12sJs2UXGtyxGwy1Y/ejUihV07xt5A4aFd3DOysbs5lWwVcnFRrliQ1QSqyGdG6wtGAYAoJifg++h3lu7aDE2EhmJHrA+Zi80hqxumuVN/VipFSYFXuBndsqI2YsZu6qNr7jSRbMle/ye9uXvObbm0rCNxI2fp1GhsbHD5nx4Okq7tVTprz02hw2BQCl1flDxHejwEkLYjaAmUqY9fA4smgTF2hPL235xZMRJKbItxzI0/w989PG/D25Ufk+8mq1xTpoEBJJCTuFzk7dz2xpb2cTGgXPueINlMMIAVWOMCttJxphonYhn3vyY0umx+Q63Z/WGsIUfglvhh1NLcD1aMmo+C1ULG+QnFfsvZTL7F8297amzkg0FyMXrfRZR5Ym8nra6nnXItuk2zukYUdNCLy5Aa6MKf0Mj+87/33lCznRt2/bd81FEV4I5Lo6whtLpjXmMawfovyrYBg14E1E+VYxcI0v4QGWR9ZirPF+/ith38CRVLBIr1BBbGKvHuOE9ITT7ZwgxFUR74S5+O42jOpi56iuTe7ZbZgEbY9HRYisNnYl7/qiOWMKbv+VV1/vGnog== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: fa1IrEhT1zTXhUG64Q0LAxRykuEGN+l/uHpaEc1NsSBiFlhzleiZQlQvEqvhkrJq8asOUngdrfBe2Su5ttwsYbNcwC8k7o64YuMxHGMBedEkt1y/pKTk9eUB1d37XXOPgX2ApfI7jEhpWP+KwPGiEgMHZYnJw/Ruzf8tGwcXbv1X+PQlcQ3W2ahh8BUGQ8nGuEYanzlMF1FXHGPCFE+YapWIzJlWXwtQ+PHLlQXXEoBKH9/iihsC5IqMvhkOxq+fUk+FpFDyXisiVaThkYdRJpeD052QHYv/PlkIILVme2TpAbB7s8y0WLUTuToSE0FteP0WX99ebEAIkxwFDPl/Rm4EiQPICLiaAaeUe8uWmf4yzri+NBGXCDyu26mYaIlMo7oEQ0gc26rkqBQ4JlxR0y10vb8bitvV5sJ1VeZfYI3CLfgi0im8s7kY0pymRH9yC9SdR3wbrHmA7J3az31y4+hPFFXEBOYYlSutLstJHSDexZgHosbSs/Bl1TF1xIcFsevhH+xC/KQx+1UiaIcMAwU9ItvIfhT9yVeOqDf9nN5F+N0bEtz1Px3EI8MOpgXWc7g59YU7sP84vuaSuHm5xU3GvagfCDJG8auxmvoxRCDAynudyEA+9PZQ/AfWE2OfClWJR8Jr72xMdRE1WIUYsWaUkJVnkpHYV8+bFr2dtLq2svcsT8XzV4eC0LeNz3iE5H1oVBecvzEH0DsjSthxNXw2bx6sh809IkWWI94nocNX+J1qONpmtkzaMZuRPT2dYKhddgtCZiMD9cwOAm8eK2ogCxE0NiL+NBGfPco5kSYOGmGedm9muXjm/CEXJ4iR0HpK8eENyD/GCdzUazbUnTctuPAQ7odmAdu9cSg2ucfH0cDWUiqhHfPLAu+a40JhUzjGoS502eDqtKk9P1osDA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4ab880bd-4863-4462-7c45-08db3a9f1334 X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 15:11:50.0437 (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: XEzoLyHKLvTDaGZup3pqXVHdcs2o26PkV5wAxXU9w+40aT8jHQbNAyOautjnFhNMTaSnse/irfjTVz4j29QWLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4718 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-11_10,2023-04-11_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 adultscore=0 suspectscore=0 phishscore=0 mlxlogscore=999 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304110138 X-Proofpoint-ORIG-GUID: EkAIHQrR67zW9_bDA1YeeHNJDv0HJ7UR X-Proofpoint-GUID: EkAIHQrR67zW9_bDA1YeeHNJDv0HJ7UR X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762895288760292933?= X-GMAIL-MSGID: =?utf-8?q?1762895288760292933?= From: "Liam R. Howlett" commit 0a2b18d948838e16912b3b627b504ab062b7d02a upstream. Add an smp_rmb() before reading the parent pointer to ensure that anything read from the node prior to the parent pointer hasn't been reordered ahead of this check. The is necessary for RCU mode. Link: https://lkml.kernel.org/r/20230227173632.3292573-7-surenb@google.com Fixes: 54a611b60590 ("Maple Tree: add new data structure") Cc: stable@vger.kernel.org Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 281be0997e55..2f9af64edad9 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -529,9 +529,11 @@ static inline struct maple_node *mte_parent(const struct maple_enode *enode) */ static inline bool ma_dead_node(const struct maple_node *node) { - struct maple_node *parent = (void *)((unsigned long) - node->parent & ~MAPLE_NODE_MASK); + struct maple_node *parent; + /* Do not reorder reads from the node prior to the parent check */ + smp_rmb(); + parent = (void *)((unsigned long) node->parent & ~MAPLE_NODE_MASK); return (parent == node); } @@ -546,6 +548,8 @@ static inline bool mte_dead_node(const struct maple_enode *enode) struct maple_node *parent, *node; node = mte_to_node(enode); + /* Do not reorder reads from the node prior to the parent check */ + smp_rmb(); parent = mte_parent(enode); return (parent == node); } From patchwork Tue Apr 11 15:10:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 82022 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2652631vqo; Tue, 11 Apr 2023 08:16:49 -0700 (PDT) X-Google-Smtp-Source: AKy350biPzqaTRmjjy1Fl05CrhrW6sNY88bqomXinNq5QjsT7PVq6rZBJ39kjUNcPYZgI3d69leE X-Received: by 2002:a17:906:bcc2:b0:94b:4a4:2836 with SMTP id lw2-20020a170906bcc200b0094b04a42836mr4778987ejb.69.1681226208989; Tue, 11 Apr 2023 08:16:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681226208; cv=pass; d=google.com; s=arc-20160816; b=D/ta45kkvmbQ5qXO9ReIBSkwIQ7trhwS+4bk10zWGg835jcW+zyHG6kgNflP6fgYt3 fnsT3uYYbtydtohtxV+RKF0ZIP4jRcK1iYItQhDBZSFQzuWmHyV7jOeQyw9RQ9RWiHpj GvwKW2reXZbLoAqy4DL6EZ/MJZqrQEfoIbmNrdHFqDoRVw3HjtfQMvk1IEj1LpnExwUu 8r3APNo9NzMkLb1CzicU/ZzwwaQ1XOqO9hatK4J19L/X9RvZbhIjBBpe9v2MWwznuBZC XECZNaCWusjMsCE7Lo6JJ/fzealKgmMzWNID3l2n/D/PXQWbm/Z5ZDtP9Ky+tlSzQlBw 0NUw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=70WhY/iq4hVIgzn5mnWWfTDRC8B2eF1U3/aQ9O7MvDI=; b=ZbjWfIlLLq/8GCvdfCOxNWYm7PavecetN8avKKBvCuaV2TpUS1B3LOGS3tNePHgD8t LR2l/t1+g6X3V++06aVXvaTJb1LqejowKAMxdWSmjftlEuhRwM8yW2iWTloqMfKvaOi5 ejogyt4GOtcRsW1IrsPN2+zxXZrvQWCMgcNmJs8sg3AJGILeUYxHIT5+AQHFn1Mzn/uZ a7Fa1piaiFC+KiwN7OzyO+mqYL6lCM/pxkHW5lXGt9ntImBEhmzIAW//YOH5ETSio6MW z5V7IthU0XQzLi/BwEmfAu29tZ2t7hOtDVi7WCRzdbPMaRAaRkBsJQ4YL4n8zJ80e5zT urlA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b="Nt/9lQGW"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="h7/VlL1B"; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qw16-20020a1709066a1000b0094aa4830d58si4222261ejc.395.2023.04.11.08.16.24; Tue, 11 Apr 2023 08:16:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b="Nt/9lQGW"; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="h7/VlL1B"; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231256AbjDKPNj (ORCPT + 99 others); Tue, 11 Apr 2023 11:13:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230457AbjDKPMz (ORCPT ); Tue, 11 Apr 2023 11:12:55 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 364C75BAC; Tue, 11 Apr 2023 08:12:16 -0700 (PDT) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEwu5G022973; Tue, 11 Apr 2023 15:11:56 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-03-30; bh=70WhY/iq4hVIgzn5mnWWfTDRC8B2eF1U3/aQ9O7MvDI=; b=Nt/9lQGWr2s0aSfo5j7j1whv4To+jX/PCjDSYkTLJzTa0HmjM8pEOY7FoQo26bThcM42 jQizf6E6qrnFUY4S7I499KD3BN9zhmTBR3/HOkD4ri6QpcvoyqIkxBGoa9PfxliUJUfO eitcZ4JsOJNTbuX22rf7IORLNRWduj3SAy9bGeRkpm6bl+p4fxmZOg5nwCT3BxAGuxb9 keRijE8wtZP+XQ/HamMd0o6ul/CSFGKiDOHwmPXLpK0qucj2+BBXLgQBhOSqTkB1FqIL LUFQ4M0DFDJ+IaGEy5LvjC76+j9ENFb+mMGbztMkiHkQqGMfVvzUvA5aSqvW51lqxxxx eg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0bwdrx6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:55 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33BEStdU030608; Tue, 11 Apr 2023 15:11:54 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2041.outbound.protection.outlook.com [104.47.66.41]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3puw918dr2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:54 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LWJz3CBGCUwEBKNIX6EOUaPEbcaSDUy/go7WWSesaUt7uv47D71zq0DkEa1uCOOLez86FmA50FwhfXmwCvKxrHrPe21lhpTOC2UHSv5MGdG0hKsOw7X+sqp2mbdlePkXbuby4OAY/RiavyolI+6aIx0XPm7Yd+iWQ2dj9zBmmRJCug6ePSieMyTBfHSpcDYvHHhuiZg4C5E6DmbTl72yPBFkEMMg0zm8Vsact7mEbE9htUZwpmsaQQiaMsnqxuTUcEE1KHSAhDEWKy1M140EOe5oKYMUDg4P74QmErHWrUpJRBypUiE17BnmcXXwUqgajiBTHDzlck1BpNKYnZsmVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=70WhY/iq4hVIgzn5mnWWfTDRC8B2eF1U3/aQ9O7MvDI=; b=GUx92sEljHQDI4KO0kcjcF6EbRijoSZ3ebMjNiZcv3UjmzZrw+SCE8Li06Cmu8otg/590rV08Pz0K3JdpTyWncfMgo23aO8xAiow8mnloZFV3QkA2nRvvG3auqeu4Xiot6CHJgZMC1veLL0663S4g0CkJBj8XLHLR8VtAjd3ZwiPO/0URdfDNuGL7AjCS34q07jTYvKRudRnzIvdUZ0ba/Y9s2DNTTCXVLatRihzjz7E26jyltlRn2PFZuJLijHN0698Q86Xa/g2cyktBG+OZghoCh411VMPbXbhKgTDmOUZXyVjIjd0e+g6o6JfN+yq/j69O16JSoYHvwX8Pr3Mgw== 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=70WhY/iq4hVIgzn5mnWWfTDRC8B2eF1U3/aQ9O7MvDI=; b=h7/VlL1BvYaWT9DVnaszhRBpjPHCe3kse3C15MZbBJBinUlTWW0oOVVZfmA24BqiCyJEdNZfRYWQR0fI1URtlFgNidGpowVip5da+VYNkltnsJ+EGWPwC6UhAqnxXLLZUMjq3Qx3bT0gZC0ypSbcIyAmWLq1FlRRNQsWTp41yR4= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by SJ0PR10MB4718.namprd10.prod.outlook.com (2603:10b6:a03:2dd::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.35; Tue, 11 Apr 2023 15:11:52 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da%7]) with mapi id 15.20.6277.035; Tue, 11 Apr 2023 15:11:52 +0000 From: "Liam R. Howlett" To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R. Howlett" , Suren Baghdasaryan , "Liam R . Howlett" Subject: [PATCH 6.1 13/14] maple_tree: add RCU lock checking to rcu callback functions Date: Tue, 11 Apr 2023 11:10:54 -0400 Message-Id: <20230411151055.2910579-14-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411151055.2910579-1-Liam.Howlett@oracle.com> References: <20230411151055.2910579-1-Liam.Howlett@oracle.com> X-ClientProxiedBy: YT4PR01CA0067.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:111::22) To SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR10MB3022:EE_|SJ0PR10MB4718:EE_ X-MS-Office365-Filtering-Correlation-Id: 047467f1-c50c-484b-6880-08db3a9f146a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KBCHEVpx8RIybaWGLBhwtWxc+xprB9MGMUCgqi5FYYtg4JRCxi9SlUNhM+/Xgw031FGdwCu6yssNVjDkM0lYnHXG8IGyz2vnOcDrzlRNEKVWr7mvrHY3GWUzvJp/3l3AgniKMald3LDASFiWONNFSj8LMj7Qfh6LxAkgYnUzQCsiQop5GthHDvvjmYcQIZSLbFqUKqVkuDqnHDWU7bq4bqSFnIv+3NPQN/K3sEg0VOWhynKOex4dtAdnDByda+TMFnze7pky11tFBfV0U0t+M4Q6nlfbdbKbUF2hvd7IKxX+vQu7aDyU5sx7Rh6JokGUJotoh/aI1dQxnRWcZnkYiLYBbq8oKuxP6zyE4ygmLZ4LHPSQFVkrtuQ2HFkTrI+p3yQRtGJ8fXXbtKoWa2SCLC7qusTUi9tL02z0EDsF1ZoyNaoLJC/EuXzWR4mbNnjpMxvFU68K6G0Wm5A+VGL2dDM0owD/EV7xAnsAD+OkadBCqGxsegRJrAp3jGTosZPsDLEU2UJj65QwXDa/ol84KzD2WO8/bokS+mXYEL+Lsy0= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(136003)(346002)(396003)(366004)(376002)(39860400002)(451199021)(38100700002)(6512007)(30864003)(6506007)(186003)(26005)(1076003)(107886003)(2616005)(8676002)(83380400001)(2906002)(6486002)(5660300002)(8936002)(966005)(36756003)(478600001)(4326008)(86362001)(316002)(66476007)(41300700001)(66556008)(54906003)(66946007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: loKj/4ArXykzEwrjPHZ8MD0tP9Di3lrDsp2xdLl75MHTkQCarv8bd5lLqrdBVwf+rG7b5oTMEU7qWal5/Jd63ACpltWgN+Hsqdxzl/e6uSvY4Y1cGHiVeqrlEHY7kywc2V4vNzJYRpLt+bv9ONte2l/GhI2RPu/QtcywbnZ64uCH3ciPtjFTm/TzdelrQE2GXUFCQFRKglw5J8TFQR/DysHck7mz1JVrZSlBscYsdi40T/asKl6nNFMCupg6ErOXrmk2viSJa7XnGpYUWb6KPQgSDhgp4b3VcrYfz3DlmlbM5Zkixq73YH8+c9sqG2WKoOq4hGSeUaiyRhI/rYw1ZgOJCxOP6wcFYoFAKdrUdq9barv+EmWQrO797gI5Eu2kcAAMpT2KmjhSZOJbZzpRFWXNYIWdurUsf3uGTgr9rVrk/cOkZwtCyUTR04ew2j2ny3OxuDiRVKh/SvUroR9tmlGQTrL9U33ffFAk2jwGYyobEVhY4mikz3CwfSVPBC9whm8dvsrNzFML+xaQ6SsLWisTD9AtiKPpL9zQ3ufZJqeLwpLeKSLVWLfmEUdEJKt4rzovwkrXidxEBX+3YJ9tZAG/eN0kdSvQWSqB7DyVYtDLNc+G3LkgCJ041Pwhe1XlirAtiwNN0lw7HUOkpUzp2X1XBNTpV53jC6BVtceB/E6DoB7JOhLsy0NxtA/4IlN+cPb3dqRpWwXg7+ucil1J38wyhcN7/L5qKDPCxkzq98cknuOUuPDWewBweARdGOn+ba3TEeqt7E8j6oCCsyfpEj+ttLVF1XLqMgL/z+3gaAPuaDIqB1dIl3kssG1fj7VOjTVVSEVTBH5SK44uzUTd4VIcOOuxU5+zaTKApQ19DyfJrH+BzsiP51fKa3H3Zrvrk5VS88JNmzFN8Ua1OiJYl7Hbs0lPmbWujIrzbMe726qkFyDhF48qStXsCr2wr3fmvwHTQ2j96qBxtSR602t7DzushPW+uH745ZJfNmmdPVmN1c113ORr+jnZ5K3tKtgJZE24PQs/MZnsMw5kY2l409eQrTESrnwYoSOb9XMqYqRGhyQ0ITRpKYrdc8r284yHvX1iyxk2qZ1y7EHuF4zuEG/x06GCoUl9MUPVYGQg0YlOpTUs2Otrgc+UDjj7p/DZE62/WekKer3m80ctLYbe7ykDJC7YwltrTHawkNTkd6NwFMpIRElcTkUwzgcbHXrIp/hB6Bi/q5svvtNBIWF2MY/Lk6z9UC9bgkM3FM8v0F0EfmVYIvr6MYq98OcVB2DgpSvJue4ydWt4yjVW9Lh+fATJZ6Qp8VcjVEUumYAwNPGuq66E2W6SJ2JQT07mXF4bUu2hDA62YIgh1DcRiaNnYx1i8JjtNPc/DSocxRkgJlY4D6e7o2usJbCNKr0sE/0/ISslJWSL2eTpgqH7ZB0RRZ1nn8npdFcyBAfAGWwf+ZDIHL1StgW2ayrtPvW8EFnW+jp4ZFTdNXonSmeewwgJCUfIETG8zdcOR19m0RpMfnXIioHcvLLgk5/x5PBt13YkP/sjVypWyNBzaam/DDGik1+z1uR+J7NfPjipxyVELhZ8juX+uqg0+MCxUXegdMBw/sosvyVVl7Wcdb8yJkRTLg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: tjqavJt4Pq7zw9IV0oxgUnvVR8msKJCZzbOSpKBoHeYxXL99PRCCuRnyvjFUsXDpnpeuYSuqp7rDGTld9snDnWcNfuw2EaxLDYVkJorYJP+86OzE1S3+av54ZT7moAShWnED81505kAoicfwXm/bcjavLRJjKgoVlAglMMDEGLjCpyYbu3FxVkkm4Rgm2ixCp4ueaeVG20Krt7VwMVNz7Ozde//U7UJRBHp1WXtVERR9iEVMnH/cfIACYuQW5+ET3JNinAHFUBoeEPHIoIsWfbCgrr6N1spJ5sv+cNGaHGchHVfrTwaoc8CdS4MoYRwUxdR3NOlHVTXpB57lrC5iihUEI4In2oTpMPpfyPjAwQdof5rrkun5xF2Tn77jN1SbY4mzZ+IPAWg1CVN6eZf8OtrjPxtVyi4H378ok0Eox1lOpj5YHaDyw4/jNRuqa1l8AICVo4ai7+q44ajBongdOv/tObCO29PtYGWX8bhfDXrqKSPqCDB31bKUQr/mfZYQkq4X55bYifd3qOMHC69EwuzzzXsBXIC4hZmmsvZLt2OPnW7yAW/qzycMWhbc3Bor0prlvtDhMyTmmriWaTIhLAfN+C641Rwf9ujejZnTkzTAuCy25VuRjrv3gBBfh7pO5HngM/vSzLQGu9Du0aBRpUjU9NbHEmW5w6kMk00H+WTy4n33NNEfh6SvppwQV4bWe8tbloQYsrIVc0OhkvW5fEFqTo4ppfsgG6DOzCcFptTr0ashI3LTJRm4WvFHrp4xI7DQfXlzQjapZbPV3eu0TEqyc5yZXl9eOEO+SvpVZw8wWrTjoKB9pxAiJnlp5ZWYgQG1zLjAdNOoBch2YTdv/vRVNbUQdutwGQZ9Hfhfn3Btl6rdvyD1p6ZNNPKcl220Zo36Fjdzm/3yudj3tthzxOWfi8ypyNCjKqJlouNs+b8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 047467f1-c50c-484b-6880-08db3a9f146a X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 15:11:52.1256 (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: ZfLRLJ1kClu9Xsxs1PXRi3elWScfssYFKjj2wWR3+5gD5qZyLDo/dAj2ZXOb3TVn556JLJjflGn7to0F2/yhew== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB4718 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-11_10,2023-04-11_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 adultscore=0 suspectscore=0 mlxscore=0 bulkscore=0 malwarescore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304110138 X-Proofpoint-ORIG-GUID: aSCaMUxqfSbgSz_lc2FdydzCgLLMBPWE X-Proofpoint-GUID: aSCaMUxqfSbgSz_lc2FdydzCgLLMBPWE X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762893453594250028?= X-GMAIL-MSGID: =?utf-8?q?1762893453594250028?= From: "Liam R. Howlett" commit 790e1fa86b340c2bd4a327e01c161f7a1ad885f6 upstream. Dereferencing RCU objects within the RCU callback without the RCU check has caused lockdep to complain. Fix the RCU dereferencing by using the RCU callback lock to ensure the operation is safe. Also stop creating a new lock to use for dereferencing during destruction of the tree or subtree. Instead, pass through a pointer to the tree that has the lock that is held for RCU dereferencing checking. It also does not make sense to use the maple state in the freeing scenario as the tree walk is a special case where the tree no longer has the normal encodings and parent pointers. Link: https://lkml.kernel.org/r/20230227173632.3292573-8-surenb@google.com Fixes: 54a611b60590 ("Maple Tree: add new data structure") Cc: stable@vger.kernel.org Reported-by: Suren Baghdasaryan Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 188 ++++++++++++++++++++++++----------------------- 1 file changed, 96 insertions(+), 92 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 2f9af64edad9..b6e29081d2cc 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -814,6 +814,11 @@ static inline void *mt_slot(const struct maple_tree *mt, return rcu_dereference_check(slots[offset], mt_locked(mt)); } +static inline void *mt_slot_locked(struct maple_tree *mt, void __rcu **slots, + unsigned char offset) +{ + return rcu_dereference_protected(slots[offset], mt_locked(mt)); +} /* * mas_slot_locked() - Get the slot value when holding the maple tree lock. * @mas: The maple state @@ -825,7 +830,7 @@ static inline void *mt_slot(const struct maple_tree *mt, static inline void *mas_slot_locked(struct ma_state *mas, void __rcu **slots, unsigned char offset) { - return rcu_dereference_protected(slots[offset], mt_locked(mas->tree)); + return mt_slot_locked(mas->tree, slots, offset); } /* @@ -897,34 +902,35 @@ static inline void ma_set_meta(struct maple_node *mn, enum maple_type mt, } /* - * mas_clear_meta() - clear the metadata information of a node, if it exists - * @mas: The maple state + * mt_clear_meta() - clear the metadata information of a node, if it exists + * @mt: The maple tree * @mn: The maple node - * @mt: The maple node type + * @type: The maple node type * @offset: The offset of the highest sub-gap in this node. * @end: The end of the data in this node. */ -static inline void mas_clear_meta(struct ma_state *mas, struct maple_node *mn, - enum maple_type mt) +static inline void mt_clear_meta(struct maple_tree *mt, struct maple_node *mn, + enum maple_type type) { struct maple_metadata *meta; unsigned long *pivots; void __rcu **slots; void *next; - switch (mt) { + switch (type) { case maple_range_64: pivots = mn->mr64.pivot; if (unlikely(pivots[MAPLE_RANGE64_SLOTS - 2])) { slots = mn->mr64.slot; - next = mas_slot_locked(mas, slots, - MAPLE_RANGE64_SLOTS - 1); - if (unlikely((mte_to_node(next) && mte_node_type(next)))) - return; /* The last slot is a node, no metadata */ + next = mt_slot_locked(mt, slots, + MAPLE_RANGE64_SLOTS - 1); + if (unlikely((mte_to_node(next) && + mte_node_type(next)))) + return; /* no metadata, could be node */ } fallthrough; case maple_arange_64: - meta = ma_meta(mn, mt); + meta = ma_meta(mn, type); break; default: return; @@ -5478,7 +5484,7 @@ static inline int mas_rev_alloc(struct ma_state *mas, unsigned long min, } /* - * mas_dead_leaves() - Mark all leaves of a node as dead. + * mte_dead_leaves() - Mark all leaves of a node as dead. * @mas: The maple state * @slots: Pointer to the slot array * @type: The maple node type @@ -5488,16 +5494,16 @@ static inline int mas_rev_alloc(struct ma_state *mas, unsigned long min, * Return: The number of leaves marked as dead. */ static inline -unsigned char mas_dead_leaves(struct ma_state *mas, void __rcu **slots, - enum maple_type mt) +unsigned char mte_dead_leaves(struct maple_enode *enode, struct maple_tree *mt, + void __rcu **slots) { struct maple_node *node; enum maple_type type; void *entry; int offset; - for (offset = 0; offset < mt_slots[mt]; offset++) { - entry = mas_slot_locked(mas, slots, offset); + for (offset = 0; offset < mt_slot_count(enode); offset++) { + entry = mt_slot(mt, slots, offset); type = mte_node_type(entry); node = mte_to_node(entry); /* Use both node and type to catch LE & BE metadata */ @@ -5512,162 +5518,160 @@ unsigned char mas_dead_leaves(struct ma_state *mas, void __rcu **slots, return offset; } -static void __rcu **mas_dead_walk(struct ma_state *mas, unsigned char offset) +/** + * mte_dead_walk() - Walk down a dead tree to just before the leaves + * @enode: The maple encoded node + * @offset: The starting offset + * + * Note: This can only be used from the RCU callback context. + */ +static void __rcu **mte_dead_walk(struct maple_enode **enode, unsigned char offset) { - struct maple_node *next; + struct maple_node *node, *next; void __rcu **slots = NULL; - next = mas_mn(mas); + next = mte_to_node(*enode); do { - mas->node = mt_mk_node(next, next->type); - slots = ma_slots(next, next->type); - next = mas_slot_locked(mas, slots, offset); + *enode = ma_enode_ptr(next); + node = mte_to_node(*enode); + slots = ma_slots(node, node->type); + next = rcu_dereference_protected(slots[offset], + lock_is_held(&rcu_callback_map)); offset = 0; } while (!ma_is_leaf(next->type)); return slots; } +/** + * mt_free_walk() - Walk & free a tree in the RCU callback context + * @head: The RCU head that's within the node. + * + * Note: This can only be used from the RCU callback context. + */ static void mt_free_walk(struct rcu_head *head) { void __rcu **slots; struct maple_node *node, *start; - struct maple_tree mt; + struct maple_enode *enode; unsigned char offset; enum maple_type type; - MA_STATE(mas, &mt, 0, 0); node = container_of(head, struct maple_node, rcu); if (ma_is_leaf(node->type)) goto free_leaf; - mt_init_flags(&mt, node->ma_flags); - mas_lock(&mas); start = node; - mas.node = mt_mk_node(node, node->type); - slots = mas_dead_walk(&mas, 0); - node = mas_mn(&mas); + enode = mt_mk_node(node, node->type); + slots = mte_dead_walk(&enode, 0); + node = mte_to_node(enode); do { mt_free_bulk(node->slot_len, slots); offset = node->parent_slot + 1; - mas.node = node->piv_parent; - if (mas_mn(&mas) == node) - goto start_slots_free; - - type = mte_node_type(mas.node); - slots = ma_slots(mte_to_node(mas.node), type); - if ((offset < mt_slots[type]) && (slots[offset])) - slots = mas_dead_walk(&mas, offset); - - node = mas_mn(&mas); + enode = node->piv_parent; + if (mte_to_node(enode) == node) + goto free_leaf; + + type = mte_node_type(enode); + slots = ma_slots(mte_to_node(enode), type); + if ((offset < mt_slots[type]) && + rcu_dereference_protected(slots[offset], + lock_is_held(&rcu_callback_map))) + slots = mte_dead_walk(&enode, offset); + node = mte_to_node(enode); } while ((node != start) || (node->slot_len < offset)); slots = ma_slots(node, node->type); mt_free_bulk(node->slot_len, slots); -start_slots_free: - mas_unlock(&mas); free_leaf: mt_free_rcu(&node->rcu); } -static inline void __rcu **mas_destroy_descend(struct ma_state *mas, - struct maple_enode *prev, unsigned char offset) +static inline void __rcu **mte_destroy_descend(struct maple_enode **enode, + struct maple_tree *mt, struct maple_enode *prev, unsigned char offset) { struct maple_node *node; - struct maple_enode *next = mas->node; + struct maple_enode *next = *enode; void __rcu **slots = NULL; + enum maple_type type; + unsigned char next_offset = 0; do { - mas->node = next; - node = mas_mn(mas); - slots = ma_slots(node, mte_node_type(mas->node)); - next = mas_slot_locked(mas, slots, 0); - if ((mte_dead_node(next))) { - mte_to_node(next)->type = mte_node_type(next); - next = mas_slot_locked(mas, slots, 1); - } + *enode = next; + node = mte_to_node(*enode); + type = mte_node_type(*enode); + slots = ma_slots(node, type); + next = mt_slot_locked(mt, slots, next_offset); + if ((mte_dead_node(next))) + next = mt_slot_locked(mt, slots, ++next_offset); - mte_set_node_dead(mas->node); - node->type = mte_node_type(mas->node); - mas_clear_meta(mas, node, node->type); + mte_set_node_dead(*enode); + node->type = type; node->piv_parent = prev; node->parent_slot = offset; - offset = 0; - prev = mas->node; + offset = next_offset; + next_offset = 0; + prev = *enode; } while (!mte_is_leaf(next)); return slots; } -static void mt_destroy_walk(struct maple_enode *enode, unsigned char ma_flags, +static void mt_destroy_walk(struct maple_enode *enode, struct maple_tree *mt, bool free) { void __rcu **slots; struct maple_node *node = mte_to_node(enode); struct maple_enode *start; - struct maple_tree mt; - - MA_STATE(mas, &mt, 0, 0); - mas.node = enode; if (mte_is_leaf(enode)) { node->type = mte_node_type(enode); goto free_leaf; } - ma_flags &= ~MT_FLAGS_LOCK_MASK; - mt_init_flags(&mt, ma_flags); - mas_lock(&mas); - - mte_to_node(enode)->ma_flags = ma_flags; start = enode; - slots = mas_destroy_descend(&mas, start, 0); - node = mas_mn(&mas); + slots = mte_destroy_descend(&enode, mt, start, 0); + node = mte_to_node(enode); // Updated in the above call. do { enum maple_type type; unsigned char offset; struct maple_enode *parent, *tmp; - node->type = mte_node_type(mas.node); - node->slot_len = mas_dead_leaves(&mas, slots, node->type); + node->slot_len = mte_dead_leaves(enode, mt, slots); if (free) mt_free_bulk(node->slot_len, slots); offset = node->parent_slot + 1; - mas.node = node->piv_parent; - if (mas_mn(&mas) == node) - goto start_slots_free; + enode = node->piv_parent; + if (mte_to_node(enode) == node) + goto free_leaf; - type = mte_node_type(mas.node); - slots = ma_slots(mte_to_node(mas.node), type); + type = mte_node_type(enode); + slots = ma_slots(mte_to_node(enode), type); if (offset >= mt_slots[type]) goto next; - tmp = mas_slot_locked(&mas, slots, offset); + tmp = mt_slot_locked(mt, slots, offset); if (mte_node_type(tmp) && mte_to_node(tmp)) { - parent = mas.node; - mas.node = tmp; - slots = mas_destroy_descend(&mas, parent, offset); + parent = enode; + enode = tmp; + slots = mte_destroy_descend(&enode, mt, parent, offset); } next: - node = mas_mn(&mas); - } while (start != mas.node); + node = mte_to_node(enode); + } while (start != enode); - node = mas_mn(&mas); - node->type = mte_node_type(mas.node); - node->slot_len = mas_dead_leaves(&mas, slots, node->type); + node = mte_to_node(enode); + node->slot_len = mte_dead_leaves(enode, mt, slots); if (free) mt_free_bulk(node->slot_len, slots); -start_slots_free: - mas_unlock(&mas); - free_leaf: if (free) mt_free_rcu(&node->rcu); else - mas_clear_meta(&mas, node, node->type); + mt_clear_meta(mt, node, node->type); } /* @@ -5683,10 +5687,10 @@ static inline void mte_destroy_walk(struct maple_enode *enode, struct maple_node *node = mte_to_node(enode); if (mt_in_rcu(mt)) { - mt_destroy_walk(enode, mt->ma_flags, false); + mt_destroy_walk(enode, mt, false); call_rcu(&node->rcu, mt_free_walk); } else { - mt_destroy_walk(enode, mt->ma_flags, true); + mt_destroy_walk(enode, mt, true); } } From patchwork Tue Apr 11 15:10:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Liam R. Howlett" X-Patchwork-Id: 82025 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2656484vqo; Tue, 11 Apr 2023 08:22:09 -0700 (PDT) X-Google-Smtp-Source: AKy350YF2uM8oDdQnhyvZiIgA1Qw6PLbWx7qn/44D/dqaVPjcsKiwa86OvvaHkxItT4xF61GyP6U X-Received: by 2002:a17:902:e548:b0:1a5:31f2:9036 with SMTP id n8-20020a170902e54800b001a531f29036mr11861558plf.11.1681226529193; Tue, 11 Apr 2023 08:22:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1681226529; cv=pass; d=google.com; s=arc-20160816; b=l2FcOinJeDLFWDovVQXoanK4tACb3ADxwwN04hrf+sii1zjyVlrOXQLx4g8rSxrAg0 hMJ6QBYFBqITjvS6/XotOI5c9x/2eO0Zi64DbqXCpbs16YJMyHmUvNi/92LR/TQiqu7c cRPlf0FD6yT4vWMxskx6cGOb/XKaiR04dUCIKIRixkL0OZQ+EHVntxd62I32VxVCXNNW CvAywvrX0iWpXckDW+lUg/y6j4EvUed2o62Q80R5eXsUQKNxdSifvfTpTEYpWJYzGucD aHdCIgvxAh7trDPvS9HmbZKyPILBjTkLoIouOmFw51yM0SN7ocTazKIkivnAZ+R1G+ZZ irCw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=KwTRZvfmXg8ueSr2QlXbeN2FLpmUcJMtKSU/NB0envU=; b=tL3pjIWsoHYlgnsLSEL+VkDFQQtymtl5kCoWyguIl4GGSBz1xo2WU7n7urnw1GfNKj 8BN7ZRWpoWVgRBM7kPmDul7VbK2cco1FgV/FoxBeMJThKpJOhj2QSnDSRKJKlxDvUdoL cnU9n9B923REk8J9Zk2oqrCo1cAyJDP75RWPSuw2+SEs7anE1E2zq32PL+SBSkDn6AXJ IhG+RZ1i2FE+C7C3PzK3hrsLbYkkhrjO8A9BqQNn+yrVt8fLNb6MwabdEI6cj3NXoKUe rdEX4p/7MQwdbkgsFHKizhQplJxJbIqSUYOEgWNGUzDlwV2BDOl8XiibBtnKZgBQDVDh BBqQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=m5m3eAl2; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=B5O5oSSP; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q24-20020a656258000000b004dccf388f93si13255727pgv.522.2023.04.11.08.21.56; Tue, 11 Apr 2023 08:22:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=m5m3eAl2; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=B5O5oSSP; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230511AbjDKPNu (ORCPT + 99 others); Tue, 11 Apr 2023 11:13:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231133AbjDKPNO (ORCPT ); Tue, 11 Apr 2023 11:13:14 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 753415FDE; Tue, 11 Apr 2023 08:12:18 -0700 (PDT) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33BF1VMh017728; Tue, 11 Apr 2023 15:11: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-03-30; bh=KwTRZvfmXg8ueSr2QlXbeN2FLpmUcJMtKSU/NB0envU=; b=m5m3eAl2Ck308B4f/Q0O6r/4wFLWBW22P5NE5jswH8sqRv4qDmmdhkkmahFqAfbRekPn fPsaNKo37SJiXCFW+u8merWcn5ps8C/m8hXm0M43XGQZVhX3FntI/RfmWzoGlFznluh+ TnMSMYuPVfHazZRF/PzV86JXQgEF3K0OMZdAYm2LvbNSXZtNH1YHX5s4FPOw8OIMolEr 4EjOADa9eyDuFC3xMjdXjzSQcOQzzGs6lcBDB6DKX6JQSyEcucz4ZJA5d+tkYDEVq6QB j3MpUbpcnMy7KufUOaLNvM2Ys1accOkH3wJo89zZafkxqIp/BQWnBLkftZ9zgHHt8VFN DA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pu0bvwr6v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:59 +0000 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 33BETset025052; Tue, 11 Apr 2023 15:11:58 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2102.outbound.protection.outlook.com [104.47.55.102]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3puwe78w90-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Apr 2023 15:11:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FG2MxUwNfere9JKzUKKZaqmTbN2YTfNlT13RwMDbHVjBDaDIMsOIvb1IB3pHxUvc/R7uk9+UED9NOwlsRSKofI2/M1dN00A+U45raOkfrVA80P7DzVZvEDOiJdwtbx48D+uo5GuwGOPwCqXlbtcd/LoKs4TEngqx8AUSr+RIAnZXZE2uswJwtXijAtS5kIk/+ar/0zGCseEELbjEz4Vt4yem5Si4ShC0udeEp4OPyDcu8pe13wb8J1yGBfVHhdvcMUcxNYp/xu3OZI9Ho2Al/X69bEIrZFi5wDZ/X1YEuDTT6SLpoxpwrWAUIeBEX/0P048ltOzIDGiwoukGJvCw3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KwTRZvfmXg8ueSr2QlXbeN2FLpmUcJMtKSU/NB0envU=; b=enilCYkoZdJ23RkETTB5yo2Rm8Nzogjh2+EGbnPsG17C1+Ok+4jO8pdxWdlzsAiPxj4MfX3U3LRiXW6TjQLLqY2g+9LCZK0s5NzDUELJo9fL5YpLZ6YuSsOPfl529hTCJ7XzHUlSfT5Y6rWYuqLFIIg97gc7HIRFsRQqWX8v+GZZydKkrjaUhYVrkzSKDk6OaxZMLH2AiW+a4PoW8BGoP2zIwiocbbffBWc7Pv3fwyTiqqmUwV+/JMteCMuChfW7GeA3sBZvCyNh/gv1zd7clPo8QWuPmZu1cfOStzp240g1VDtxQvKSJZUrrmYO70OZHqQsRUGOYFMPvXkOgV45Ig== 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=KwTRZvfmXg8ueSr2QlXbeN2FLpmUcJMtKSU/NB0envU=; b=B5O5oSSPGNpvlB7KuGCHOrtzo2dsnySDGfT0aEjqGA/F7RA2flJQe2PjjqJWlnyiJoe6P9q/SrQYanG0NFm75JMJQlDDN4AV2Cc2687j5Y1wwfsAh5aCwzYNSFbEMPdVEPPboyFENPtWqyH5MZzEz4+IVbQCY95XbyDsnyInoSs= Received: from SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) by PH0PR10MB4807.namprd10.prod.outlook.com (2603:10b6:510:3f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.35; Tue, 11 Apr 2023 15:11:55 +0000 Received: from SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da]) by SN6PR10MB3022.namprd10.prod.outlook.com ([fe80::8bb9:2bb7:3930:b5da%7]) with mapi id 15.20.6277.035; Tue, 11 Apr 2023 15:11:55 +0000 From: "Liam R. Howlett" To: Greg Kroah-Hartman , stable@vger.kernel.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Liam R. Howlett" , "Liam R . Howlett" , syzbot+8d95422d3537159ca390@syzkaller.appspotmail.com Subject: [PATCH 6.1 14/14] mm: enable maple tree RCU mode by default. Date: Tue, 11 Apr 2023 11:10:55 -0400 Message-Id: <20230411151055.2910579-15-Liam.Howlett@oracle.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230411151055.2910579-1-Liam.Howlett@oracle.com> References: <20230411151055.2910579-1-Liam.Howlett@oracle.com> X-ClientProxiedBy: YT4PR01CA0062.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:111::23) To SN6PR10MB3022.namprd10.prod.outlook.com (2603:10b6:805:d8::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR10MB3022:EE_|PH0PR10MB4807:EE_ X-MS-Office365-Filtering-Correlation-Id: 5a26aef0-c898-413c-368c-08db3a9f1647 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wQCHhqd2yiOW15ifxXZqka0drYtLzTqLOSYQlYtPSVzbf9Jt0oWui7QMARyYzVAB1bIpaDdSOKcNVBnbcm9Dv3IBPMS5aEon5+0Y/1xYM++RalN2+gl5Rv7KKmMqrWMC+NfiOyV+FYX0iwNUdGtlCht9LyGH8ajEQq5jE4K8GrzWMAbTPuHq+JYWdvsRaViAAk7mJMZwK/5a3/lvmUBESAJDbOpRLjtZjWNazv76FRaQxNb1mjodfqpdQt2dZpDunYVztwdnxFCG8r7JLpMOryhm6dVFbxOmoHtRYC+kqezuzkJ9ep0vC8z47c3EobCFRsaiQGehBLA+mB37OAJH+Aj4J0ivgC2ydLimSBvyPkR1XEjWWyQsRhyfBhQFhUSI/46bvGMo7sQ0YnXwjeZzu522ZeehNsHE2bKADrLcfamKd38lh1GfOapgOrphI87oJY3Z3oYIgA3i5iVTV0/U3WtyOVxiy7Xb8gnHO8SOfXwAZS1ZqwBRvEQFBER00kOYv1DwFcGQJpwbXGJpNTQudG9kBOdB9LEuqS/L0o9Pccw= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR10MB3022.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(396003)(136003)(366004)(346002)(376002)(39860400002)(451199021)(478600001)(1076003)(6506007)(316002)(6512007)(26005)(186003)(54906003)(966005)(6486002)(2906002)(66476007)(66946007)(4326008)(8936002)(66556008)(8676002)(5660300002)(41300700001)(38100700002)(83380400001)(86362001)(36756003)(2616005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EA3AGAnh94CTLQzCTUqeV70TWjxUYnnj+aCz1V3gA7o0/5xLeTwoyrDc+kUDwP0DaQwbZxuU4z8oIpA3Dm0u+pO9Q9mN3ZURz0J/VAKXR7dPGrqg4syHE/utotL1ZSE5mDgRfhij+xPwK+BguvNWSg/WKQBXTLgtJa77yos7KRv6tB9vznmZfixd7Up2wJHuMlZ4XknyfXTy7D74uWDybW2BpMUYex4zZGPq8v46sio8UVTBQEHqDFDeuCavYhIPx+8fA1gjORoNmw8D+612UqDt3kJHVx+DaNdsgmwFLJvT6zD17q0A7NEsxg0qvyFMhGqNdMD9SG2DeOxIdt6dZX3dHr2Pp5iA70J816WYlrBUa4iOimvMA4aefuzLNG2l5xHe+zGs6UNmD6PD9FEhZ+3PkroYhBxQYAdoSqCrn3TMRUz8gc1Qx/71A9Cy6YJ9tFHeoFG7V5L2Ke32KlXw36TkmZCpibl7uxfoh1KN7Bccr9nkAgGa0k9DQ3H/GqFLizeaD31OYRiEhTrhphHNlrvd4qHfYKSYATKm8n/4+g8P44nBdTkxz9PrLrG+mw4cte4K658g8zG8JyuAHq6HfjHTQBRxEgC5O1T6YUMm6RRx5GanIxtrU+TazRj+DbvHj37IZZAMZHAuADBZ+8X/rKh1n/aFZsXU8KSaRATDFNBYva7XsxaT81PY80bP6EUrpWqUcCqrB9F/D9+uRZoNPrtJCXRTJNu5cI4CzsyYeD/stQO/p3mgpQ6w/8Ub913K4GCeyUEo5Lm6iAs9sEQxZwzv7THCZXtFZ7wFsPf2Z6I7cj24U7NkmBliBhY7bEEJDXr9YIzGc40aTbcGY0YYnVVZATluKkj0g/8EcvMxVwbc/SI9E7dtDlYhoBlp5v/+H+UpKw4TtM3x7NhAlfIKhKYLSkWIBg9POVppKMvLpkoKCtfpyHZVf20CS+W0RXcgy5vix4B7CFu2evhu/8cjliP8J8uwzRZQU27uWFGjyc/tbPXmM5YTF3AYwEK2f80ZaGdXwKFFMU5zbLv1QeBUuPChmGCbgs3nMOgBvy+wfLHANMroR4yZw10NS4kl+lsxuoADGe29lLYVZ50AfTjzUVSUmONevbaPkITCOsMsMyim7GoKUcssJ02AfM+kY9qWUmzVWnBajfHzteAeTj/ZmS3wc1+VukKwtm8lxcHhG6OQEtrKYU+XHYO6HLMm+Cp4/KS9n4f5CwCtW4BI9tYyWWJuMq0b4zpUQf8W3wP0n7EPLOUqRxDSFKZvYl0NazqOxvJNeUfv7gbUoZrTapWiS3km7e5QPnz30N6FvJW+E06WCJXdfqkVs5kbZ0uMB8RkK2hyD9PFvVL61yHiovCvRGEghII+HOWmJOCfiOQTR8slFIef+kKhrvE42/NXqpWlpamVk5++gzv+26o9TQ9t0XTFENSw2zAsVQshellfAkSd/y6Ou8lyu0V6WapZUgy15/Lux1aP+E6+MTKR9tCIFYRUtLN1tNnSe8oUiT9OizxfvV4Wzc50Bue9IW8LfgWwL+jpyApMUMAOkqVtJ80qTTYO6WP3zIo5SXpI4kzXoa9H+t7f9iuD1qXJ0NIP30zvmrFBlc2zHyRQcsJrSUaV9Q== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: oZFFVcvED3/sy04GtX76RA3x+tZ8igdSetfWQayRREdK29TLI1ffHMFgps8T8tRVd/ySFNn7Rt3CjCxHVuS6JSDPXiNqo8ZGBE/Hox68SHfSx1fGkKLmZB0J7gb4sp+ewssO8kUv5N50OBBJsV+NkK0o9xw1BUqWDaV4bWo2/ySpjX1zRyjmlWDyR91us7qb1X3qQU3zekfu0UqFrOECQ7nZO6/zmb57TJzHNSl2Nn00ETw+TULmXJu5Nds2b13dHz+ejaqex2dPHJM3msVddeOoOJoZtyQomqUbH432/bDmkkmci9WRXt5EciQpKhux/U/ZzyggxVWsC3iGnbYbubdkfsfN3gN7tt9RrQsG4WbcejYPz4BCvboijLTuW6BvevtAxH3mB3aGPf59q7JX1jEKkyaw2Obtafg93t7EWrTFYvWiEWRgicCezbZBERP0M+Da3QcY6bOt6363lfXIJw2wf6KxHJGjL672Uzwb5qmBeb1aLdMUQV/WTjq58AcUKJO1sgRnOqzGSJP138Y1AHKQivHrQzY1daciFp5vK/O4mr9etBFI2MHXsbw8kdHn9VErAL1r7lZupRygteO2phhYIjTMPJgX1dxRwbGjZuFFtooZRIFvPgrbLjCCvApNvSTIUdgaaxPJFEJRelkXfFfzcLdrUHeIAWbt3vEhn27ndovYj+Crhf9bvo6b7fe7WfjMXBS5Y578lkKFcKmY2eF97bs4Z4046ZcNozgQUhKN6PBM9Adf+xuJFuOq2Z6vT8azQ2ipSvMArzNYYgS+xoCLVEy8ul23vrAhJYChl4ITOKDQAdYEWJiylwge31opDQNzGrE/ufH1obVUw4z03EwRhIM7roIH53BuuyeZPmi6iCpfijLxJ5Odo4g5L9vrShXoJj7Xn5Fy2wLWlIDTjmQTfi4e+dBm9RNlBtL4EmiQYU2FTwZsw5E3UJavFIJD4oMnOUSbThycpZ9S+YFtTA== X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a26aef0-c898-413c-368c-08db3a9f1647 X-MS-Exchange-CrossTenant-AuthSource: SN6PR10MB3022.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2023 15:11:55.2052 (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: 1F6ajSxra640PPO//3v/yjr1gwQ9oQ2ThwtjUBbq8V3XsdhfSCiUsnufWJYE8rOn8vrmFnCWh7UYBRMQnu8Mqw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB4807 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-11_10,2023-04-11_02,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 phishscore=0 adultscore=0 spamscore=0 suspectscore=0 bulkscore=0 mlxlogscore=501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304110138 X-Proofpoint-GUID: Wq1DbiT2f0YinvcTIZlN3kicYqXofriS X-Proofpoint-ORIG-GUID: Wq1DbiT2f0YinvcTIZlN3kicYqXofriS X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762893788972324786?= X-GMAIL-MSGID: =?utf-8?q?1762893788972324786?= From: "Liam R. Howlett" commit 3dd4432549415f3c65dd52d5c687629efbf4ece1 upstream. Use the maple tree in RCU mode for VMA tracking. The maple tree tracks the stack and is able to update the pivot (lower/upper boundary) in-place to allow the page fault handler to write to the tree while holding just the mmap read lock. This is safe as the writes to the stack have a guard VMA which ensures there will always be a NULL in the direction of the growth and thus will only update a pivot. It is possible, but not recommended, to have VMAs that grow up/down without guard VMAs. syzbot has constructed a testcase which sets up a VMA to grow and consume the empty space. Overwriting the entire NULL entry causes the tree to be altered in a way that is not safe for concurrent readers; the readers may see a node being rewritten or one that does not match the maple state they are using. Enabling RCU mode allows the concurrent readers to see a stable node and will return the expected result. Link: https://lkml.kernel.org/r/20230227173632.3292573-9-surenb@google.com Cc: stable@vger.kernel.org Fixes: d4af56c5c7c6 ("mm: start tracking VMAs with maple tree") Signed-off-by: Liam R. Howlett Reported-by: syzbot+8d95422d3537159ca390@syzkaller.appspotmail.com --- include/linux/mm_types.h | 3 ++- kernel/fork.c | 3 +++ mm/mmap.c | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 500e536796ca..247aedb18d5c 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -725,7 +725,8 @@ struct mm_struct { unsigned long cpu_bitmap[]; }; -#define MM_MT_FLAGS (MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN) +#define MM_MT_FLAGS (MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN | \ + MT_FLAGS_USE_RCU) extern struct mm_struct init_mm; /* Pointer magic because the dynamic array size confuses some compilers. */ diff --git a/kernel/fork.c b/kernel/fork.c index a6d243a50be3..ec913b13c5ed 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -617,6 +617,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, if (retval) goto out; + mt_clear_in_rcu(mas.tree); mas_for_each(&old_mas, mpnt, ULONG_MAX) { struct file *file; @@ -703,6 +704,8 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, retval = arch_dup_mmap(oldmm, mm); loop_out: mas_destroy(&mas); + if (!retval) + mt_set_in_rcu(mas.tree); out: mmap_write_unlock(mm); flush_tlb_mm(oldmm); diff --git a/mm/mmap.c b/mm/mmap.c index 177714886849..fe1db604dc49 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2308,7 +2308,7 @@ do_mas_align_munmap(struct ma_state *mas, struct vm_area_struct *vma, int count = 0; int error = -ENOMEM; MA_STATE(mas_detach, &mt_detach, 0, 0); - mt_init_flags(&mt_detach, MT_FLAGS_LOCK_EXTERN); + mt_init_flags(&mt_detach, mas->tree->ma_flags & MT_FLAGS_LOCK_MASK); mt_set_external_lock(&mt_detach, &mm->mmap_lock); if (mas_preallocate(mas, vma, GFP_KERNEL)) @@ -3095,6 +3095,7 @@ void exit_mmap(struct mm_struct *mm) */ set_bit(MMF_OOM_SKIP, &mm->flags); mmap_write_lock(mm); + mt_clear_in_rcu(&mm->mm_mt); free_pgtables(&tlb, &mm->mm_mt, vma, FIRST_USER_ADDRESS, USER_PGTABLES_CEILING); tlb_finish_mmu(&tlb);