From nobody Sat Apr 11 21:51:11 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 580C3C6FD1F for ; Fri, 10 Mar 2023 14:11:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231747AbjCJOLG (ORCPT ); Fri, 10 Mar 2023 09:11:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231877AbjCJOKa (ORCPT ); Fri, 10 Mar 2023 09:10:30 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FE581AB for ; Fri, 10 Mar 2023 06:09:37 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id a2so5664614plm.4 for ; Fri, 10 Mar 2023 06:09:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1678457376; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YjLkk2c7qkyw5y4hjkb7TF+50UyVGFsleuClk20l+mY=; b=WphEF2oxgLVej3eE274fGsflhyHMgJ2dTa8s8OAIbv9LOvuOXfdF5Wd1/NaUe575sO jjgnHjjrsT0jG6nkB6+v3mF6Cr3KhiaHv6c32jK1u5+vbv0c5CRt2ZF0+PVT6Cbh4HTH MbTFqJrcrn9Gkh6LznsP0LnemRqAd0jDgk17BUrm8jORI2Z6HACdab9cSSXcHLhfmvI1 xh1BNcKau3ckNIcS2HIQZc9DrtBF1jIOIXioVCYTSReGIrRus1A7fySebJgKB4nf68ku I+9kznE7YYXqfpkGLKgIi/gzoqg00fpJ4qB1FyA7HcnqhHZOJqUFQ8om/zSdXIm75gBT DotA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678457376; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YjLkk2c7qkyw5y4hjkb7TF+50UyVGFsleuClk20l+mY=; b=nSr0OCIP9Hyu+VIBPdPI+mEEYbd21oIcvQPmuyyBFVitz1hV9GdvS+RppG4S+UJs4P fRcDskc+TI8T62XYmjkS4CfnZnBowSYgiq62X2cstLmrIxZuaVEi6WEChTO+c1YkUe+H UhZ8rl7HPrLrEI31au5tuuwvRNnms6LM58YyyOqkqKK5LZAIBh3pX2dytNNHH8JnGkHS Ud5HCJcA/7PV7Tebm4V9eQ5A3ObxwEy376jNRdLB7aRCk7NqfCwV2wLY9gIz8Fa7EQhT yKN7096kJDscrs7OSaS/4gV1Iu9coprrrLLckWpewytKK6MvL7FidQP67Ja5lsxhBbDx awmw== X-Gm-Message-State: AO0yUKWQPwylwrb73PvhZIandh6GBfI5EHuU6Akn04pmSFHm6s4luJ2W Puygk7lE7PbDqZNwjK4VJm3ahQ== X-Google-Smtp-Source: AK7set+QrOEa9fTlDbVV5pXLDfDbkYu/K29dJO9b63aMffjgrG9OR8N6Nz38PCDjMG+CznXz5kGPHw== X-Received: by 2002:a17:90b:4a4c:b0:237:9cc7:28a4 with SMTP id lb12-20020a17090b4a4c00b002379cc728a4mr27301326pjb.14.1678457376680; Fri, 10 Mar 2023 06:09:36 -0800 (PST) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.234]) by smtp.gmail.com with ESMTPSA id fu11-20020a17090ad18b00b002375c356b0csm6753pjb.19.2023.03.10.06.09.33 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Mar 2023 06:09:36 -0800 (PST) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH 1/4] maple_tree: Fix get wrong data_end in mtree_lookup_walk() Date: Fri, 10 Mar 2023 22:08:44 +0800 Message-Id: <20230310140848.94485-2-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230310140848.94485-1-zhangpeng.00@bytedance.com> References: <20230310140848.94485-1-zhangpeng.00@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" if (likely(offset > end)) max =3D pivots[offset]; The above code should be changed to if (likely(offset < end)), which is correct. This affects the correctness of ma_data_end(). Now it seems that the final result will not be wrong, but it is best to change it. This patch does not change the code as above, because it simplifies the code by the way. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 646297cae5d1..b3164266cfde 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3875,18 +3875,13 @@ static inline void *mtree_lookup_walk(struct ma_sta= te *mas) end =3D ma_data_end(node, type, pivots, max); if (unlikely(ma_dead_node(node))) goto dead_node; - - if (pivots[offset] >=3D mas->index) - goto next; - do { - offset++; - } while ((offset < end) && (pivots[offset] < mas->index)); - - if (likely(offset > end)) - max =3D pivots[offset]; + if (pivots[offset] >=3D mas->index) { + max =3D pivots[offset]; + break; + } + } while (++offset < end); =20 -next: slots =3D ma_slots(node, type); next =3D mt_slot(mas->tree, slots, offset); if (unlikely(ma_dead_node(node))) --=20 2.20.1 From nobody Sat Apr 11 21:51:11 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACC86C64EC4 for ; Fri, 10 Mar 2023 14:10:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231800AbjCJOKl (ORCPT ); Fri, 10 Mar 2023 09:10:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231733AbjCJOKM (ORCPT ); Fri, 10 Mar 2023 09:10:12 -0500 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E57D136C9 for ; Fri, 10 Mar 2023 06:09:40 -0800 (PST) Received: by mail-pl1-x62f.google.com with SMTP id y11so5685893plg.1 for ; Fri, 10 Mar 2023 06:09:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1678457379; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=f7DPt8nqxS2DR8+B+9WtRvCdWF3m9pKFBEKjw2IVbrY=; b=Vt7HmeQi/0l9PcitJbwAwTNB69hO/ue7yLU7cQTTmP4tGVuY+aE3gFyEMp8I6M+gd9 0vRhsPgpGy9FkvxG682ngJXJVQ8h7Q+tFj6pxUci1n4a90DrWTeC+BFdbqiLiR1QES06 8Zh5WuLrsn2iRx4YmU07ySYLIt08ka0rV7cMvePtiLF2pelRlbmHOFUpl1w4eow+HBzM 1NSEFkEOZT3RNO0m7kXJqqJiUWLffAlSDZDnSXEMmqRGz4ZspmHHeTzNUzH/X/BrtwDi vCxlaVIW0PhyKotrrKPuxWcz0ee1nfXSCt0hEtD0rmaCWbI22gsK/jKBS2RXZ0mSAr6Y Ikqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678457379; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f7DPt8nqxS2DR8+B+9WtRvCdWF3m9pKFBEKjw2IVbrY=; b=Vx3HGjECv2DuG1LaETBWTWhoVHa1Hc1It+JCh3tJeTFIjG7P5u9mtMkn4FKw6P6Dpu zRqxtxVdlcqkIorH/5VdauxiK76fc/N8JOEeYDxy1Mumul5SvpBhHoOAvtTygzO2tcgT 7Jn60yWRLpYak3SZ+358WFBi+ITHHD0YoG/CS/NIcVdb7Q4hPpAzJNhDfwgRTDEWAS4s DU6UQjHzAI7adsrhFLq90XDm898q3nPYOIE7wZRKqxk6PxVY3pJ6pwzpRhv05UIzR8aC pC5up7gjbhVywnFWfnQ5YwjQGfWkbTRzvVLPrrLc5rcvlzK3rsTuXCrgEYQ5yKE3l149 oItQ== X-Gm-Message-State: AO0yUKXsU0T93pawUVqooJyKL5KWbqf1cXvm6v/a9mFoI9VW1BaGL3uF FAWi92M7fQmUoaZUJXtJkFfo1g== X-Google-Smtp-Source: AK7set9df5/U3LQZqScgLIUjh/W7HucX2b8VJSDwe4PpGG5DxpP24J4aztf92cED6W3fDEZYoI0TUA== X-Received: by 2002:a17:90b:4f42:b0:236:76cb:99d2 with SMTP id pj2-20020a17090b4f4200b0023676cb99d2mr27006601pjb.8.1678457379677; Fri, 10 Mar 2023 06:09:39 -0800 (PST) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.234]) by smtp.gmail.com with ESMTPSA id fu11-20020a17090ad18b00b002375c356b0csm6753pjb.19.2023.03.10.06.09.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Mar 2023 06:09:39 -0800 (PST) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH 2/4] maple_tree: Simplify mas_wr_node_walk() Date: Fri, 10 Mar 2023 22:08:45 +0800 Message-Id: <20230310140848.94485-3-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230310140848.94485-1-zhangpeng.00@bytedance.com> References: <20230310140848.94485-1-zhangpeng.00@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Simplify code of mas_wr_node_walk() without changing functionality, and improve readability. Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index b3164266cfde..4d15202a0692 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -2251,9 +2251,7 @@ static inline struct maple_enode *mte_node_or_none(st= ruct maple_enode *enode) static inline void mas_wr_node_walk(struct ma_wr_state *wr_mas) { struct ma_state *mas =3D wr_mas->mas; - unsigned char count; - unsigned char offset; - unsigned long index, min, max; + unsigned char count, offset; =20 if (unlikely(ma_is_dense(wr_mas->type))) { wr_mas->r_max =3D wr_mas->r_min =3D mas->index; @@ -2266,34 +2264,12 @@ static inline void mas_wr_node_walk(struct ma_wr_st= ate *wr_mas) count =3D wr_mas->node_end =3D ma_data_end(wr_mas->node, wr_mas->type, wr_mas->pivots, mas->max); offset =3D mas->offset; - min =3D mas_safe_min(mas, wr_mas->pivots, offset); - if (unlikely(offset =3D=3D count)) - goto max; - - max =3D wr_mas->pivots[offset]; - index =3D mas->index; - if (unlikely(index <=3D max)) - goto done; - - if (unlikely(!max && offset)) - goto max; =20 - min =3D max + 1; - while (++offset < count) { - max =3D wr_mas->pivots[offset]; - if (index <=3D max) - goto done; - else if (unlikely(!max)) - break; - - min =3D max + 1; - } + while (offset < count && mas->index > wr_mas->pivots[offset]) + offset++; =20 -max: - max =3D mas->max; -done: - wr_mas->r_max =3D max; - wr_mas->r_min =3D min; + wr_mas->r_max =3D offset < count ? wr_mas->pivots[offset] : mas->max; + wr_mas->r_min =3D mas_safe_min(mas, wr_mas->pivots, offset); wr_mas->offset_end =3D mas->offset =3D offset; } =20 --=20 2.20.1 From nobody Sat Apr 11 21:51:11 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15B4AC742A7 for ; Fri, 10 Mar 2023 14:11:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231902AbjCJOLT (ORCPT ); Fri, 10 Mar 2023 09:11:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231784AbjCJOKi (ORCPT ); Fri, 10 Mar 2023 09:10:38 -0500 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F5795FE1 for ; Fri, 10 Mar 2023 06:09:43 -0800 (PST) Received: by mail-pl1-x62e.google.com with SMTP id i10so5645504plr.9 for ; Fri, 10 Mar 2023 06:09:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1678457382; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZI1NTxNQsncsBuSARtQ7gY1qx/Kaxg/acZj9mrc75oo=; b=R7ouu0Wktvvy/0biANU6/CsFYdvyqaelWm1/tm2k3z1xn1E58V6YQdhsRRE48Ukl0D xouTlAcz47ET0Gx71OmdRdZ1QQB46Fe9vBCaiXaGfk/dAdNoNJMwJmdyFhZ7pV/S7KcT qq/41cVbpI0VXpk7WAC/xbEO208+6SIYdhxXL+q7/v3/pnmJ5yey3oRrE45ykNAf9O+h 86/msFcANeTG0J4YQf4v66JfUdAcaAPu7V0w346WgpHPq+5Ozy9K7ywU+iLrHj5ieiIP /YBouzChgTtzGJRoD3jWioB/xzQHKJGT8lMCdNM7tcG+wvmYMAxcNNKEWgFrBZeD2ZvQ Cx/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678457382; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZI1NTxNQsncsBuSARtQ7gY1qx/Kaxg/acZj9mrc75oo=; b=zMrA0KjZhywy9hJsjrPFZAPPusTMnhRrPsYpWJWpG2XW2QTOW4p6xVSu6SUVQqhxzL jc5mQifbArTBTlXhLGYSJsYwpPRkhcW+tAbbCTh/UpsvgK3KMLaGviVZrubRwwq0vKvM DL6VE+6IiSFGTnPFaHmsQnWVzndB9/5KrFiEKVGvyI5PJ1+PzB0hhRwAMltLYlN5tas1 yNumFPQ0QbtQusO+Kd/Yp8U6P6t8p0tpTBITOWUmESWf2XOXgJP8PlFOWjdcAozhNMP5 7wjD5qZTCZwfqy5AUATcEpnNERSkASTaa9hbfnJh9BvnQWBREdL8DQ1PVTk7G78sUMNy nhRA== X-Gm-Message-State: AO0yUKUfgVNpBqgywap+I/9/f3Ihe6iyLyDaVd4RHESXBcNW5W2AQXWG mpaavTzcCkzpmsY/dW7GO3zoew== X-Google-Smtp-Source: AK7set8Z8bAhdNtk0KoMAdSO1/VatXK5WhDtaRNgSmexkSBtrCjRc8k4A5zuJ+DkJF+bE84k83di4A== X-Received: by 2002:a17:90b:33c4:b0:234:bf0:86bc with SMTP id lk4-20020a17090b33c400b002340bf086bcmr25736949pjb.31.1678457382536; Fri, 10 Mar 2023 06:09:42 -0800 (PST) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.234]) by smtp.gmail.com with ESMTPSA id fu11-20020a17090ad18b00b002375c356b0csm6753pjb.19.2023.03.10.06.09.40 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Mar 2023 06:09:42 -0800 (PST) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH 3/4] maple_tree: Fix a potential concurrency bug in RCU mode Date: Fri, 10 Mar 2023 22:08:46 +0800 Message-Id: <20230310140848.94485-4-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230310140848.94485-1-zhangpeng.00@bytedance.com> References: <20230310140848.94485-1-zhangpeng.00@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" There is a concurrency bug that may cause the wrong value to be loaded when a CPU is modifying the maple tree. CPU1: mtree_insert_range() mas_insert() mas_store_root() ... mas_root_expand() ... rcu_assign_pointer(mas->tree->ma_root, mte_mk_root(mas->node)); ma_set_meta(node, maple_leaf_64, 0, slot); <---IP CPU2: mtree_load() mtree_lookup_walk() ma_data_end(); When CPU1 is about to execute the instruction pointed to by IP, the ma_data_end() executed by CPU2 may return the wrong end position, which will cause the value loaded by mtree_load() to be wrong. An example of triggering the bug: Add mdelay(100) between rcu_assign_pointer() and ma_set_meta() in mas_root_expand(). static DEFINE_MTREE(tree); int work(void *p) { unsigned long val; for (int i =3D 0 ; i< 30; ++i) { val =3D (unsigned long)mtree_load(&tree, 8); mdelay(5); pr_info("%lu",val); } return 0; } mt_init_flags(&tree, MT_FLAGS_USE_RCU); mtree_insert(&tree, 0, (void*)12345, GFP_KERNEL); run_thread(work) mtree_insert(&tree, 1, (void*)56789, GFP_KERNEL); In RCU mode, mtree_load() should always return the value before or after the data structure is modified, and in this example mtree_load(&tree, 8) may return 56789 which is not expected, it should always return NULL. Fix it by put ma_set_meta() before rcu_assign_pointer(). Signed-off-by: Peng Zhang Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 4d15202a0692..de43ff19da72 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3635,10 +3635,9 @@ static inline int mas_root_expand(struct ma_state *m= as, void *entry) slot++; mas->depth =3D 1; mas_set_height(mas); - + ma_set_meta(node, maple_leaf_64, 0, slot); /* swap the new root into the tree */ rcu_assign_pointer(mas->tree->ma_root, mte_mk_root(mas->node)); - ma_set_meta(node, maple_leaf_64, 0, slot); return slot; } =20 --=20 2.20.1 From nobody Sat Apr 11 21:51:11 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBEFEC742A7 for ; Fri, 10 Mar 2023 14:11:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231842AbjCJOLX (ORCPT ); Fri, 10 Mar 2023 09:11:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231898AbjCJOKl (ORCPT ); Fri, 10 Mar 2023 09:10:41 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 251B810E252 for ; Fri, 10 Mar 2023 06:09:46 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id h11-20020a17090a2ecb00b00237c740335cso5269743pjs.3 for ; Fri, 10 Mar 2023 06:09:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1678457385; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u6SczCfFTY/KJFxBt0YFVietITxxXbodBIi134Qsi0M=; b=asKUtiJYwQqgvMbN60l/bVTcYy2W5TZi9AcVU4FhwMRejoM8MKEoTejGDXrB4L5qRb apETIhrKGJqUxZte8/van/OhvRDQPA6LTjZdPQYxQy56FIXwSfYtblPmPlJaMseRJfCk /yfIf/MqQYjQt0TQom3v4HX7d9OQO9QM0TLMhqyOmcyJNEW9vYdHhWIAHfGXKlMTIJG8 33aFH4rBUKRtz1XBQmXjUCY1FGm6mtprh9lqOS/mAuq0AE1VUTJcJYRCp14hiDaJ4m1/ bHLS+N/9p6xMEGCJSRATQivnN79niKr7Z/zt+6bOH/T7hEOAme9agNB41jtnTSqcXhxy msag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678457385; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u6SczCfFTY/KJFxBt0YFVietITxxXbodBIi134Qsi0M=; b=smjr0QLuNerKvAV+l83qSYwDPUkZ3sYVOTDZ03aGuOQ0Gz4AKQ/GFoNj6c58fVwETz UGAlsM6vOiICfm59vpf4kwhcUZiCrODnetq/Nf44awi+edd/mggG7zsgCjMKhCgzOYT0 iMS0UsCBV/M/VC+xYgVC5LiSw0HhAiuEn7QjkbGVNu/DdJAD2bdle9b7O+ICQm4RY+SY +as7+au2B8PNmFLtL7F9vpaA/xSUmCc1mfRVr3O9+IVdpp0jfP9vcjReq1tgh341wo4n GCq8zQmxTxAVH8psWHr4TWHUUBjSqNwMktQSEdBXwfnkAlO+x8PPbj9fvUm13ncejSnQ C3oQ== X-Gm-Message-State: AO0yUKUQOQ7eXfHR5gEx3gM3r9wto3Tj79DIAxmHJiv/x4DGudXECY3I WFvtnm+PCHX2tTZ3GvJ0GvZy2Q== X-Google-Smtp-Source: AK7set9+KnLDpZhKt5A/OsgVVC228AHdamUX5+ieIAuoF72IdXUgpKu58Km7GNjqb3S3CgyDiWDx5g== X-Received: by 2002:a17:90b:2353:b0:233:cea2:dac6 with SMTP id ms19-20020a17090b235300b00233cea2dac6mr26150338pjb.47.1678457385677; Fri, 10 Mar 2023 06:09:45 -0800 (PST) Received: from GL4FX4PXWL.bytedance.net ([139.177.225.234]) by smtp.gmail.com with ESMTPSA id fu11-20020a17090ad18b00b002375c356b0csm6753pjb.19.2023.03.10.06.09.43 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 10 Mar 2023 06:09:45 -0800 (PST) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang Subject: [PATCH 4/4] maple_tree: Simplify the code of mas_mab_cp() Date: Fri, 10 Mar 2023 22:08:47 +0800 Message-Id: <20230310140848.94485-5-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) In-Reply-To: <20230310140848.94485-1-zhangpeng.00@bytedance.com> References: <20230310140848.94485-1-zhangpeng.00@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Simplify the code of mas_mab_cp(), and improve readability. No change in functionality. Signed-off-by: Peng Zhang --- 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 de43ff19da72..688b062728a2 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1914,32 +1914,18 @@ static inline void mas_mab_cp(struct ma_state *mas,= unsigned char mas_start, void __rcu **slots; unsigned long *pivots, *gaps; int i =3D mas_start, j =3D mab_start; - unsigned char piv_end; =20 node =3D mas_mn(mas); mt =3D mte_node_type(mas->node); pivots =3D ma_pivots(node, mt); - if (!i) { - b_node->pivot[j] =3D pivots[i++]; - if (unlikely(i > mas_end)) - goto complete; - j++; - } =20 - piv_end =3D min(mas_end, mt_pivots[mt]); - for (; i < piv_end; i++, j++) { - b_node->pivot[j] =3D pivots[i]; - if (unlikely(!b_node->pivot[j])) + for (; i < min(mas_end, mt_pivots[mt]); i++, j++) { + if (unlikely(!pivots[i] && i) || + unlikely(mas->max =3D=3D pivots[i])) break; - - if (unlikely(mas->max =3D=3D b_node->pivot[j])) - goto complete; + b_node->pivot[j] =3D pivots[i]; } - - if (likely(i <=3D mas_end)) - b_node->pivot[j] =3D mas_safe_pivot(mas, pivots, i, mt); - -complete: + b_node->pivot[j] =3D mas_safe_pivot(mas, pivots, i, mt); b_node->b_end =3D ++j; j -=3D mab_start; slots =3D ma_slots(node, mt); --=20 2.20.1