Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1030814rwr; Fri, 5 May 2023 08:12:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4EmnKxRr2zc0xuLealRzyZDWyg9kp4KXClKECjTgZBKTM/Qnn8269JRpLk5D0xyjpHiw0Y X-Received: by 2002:a05:6a20:42a7:b0:f2:817c:2038 with SMTP id o39-20020a056a2042a700b000f2817c2038mr2419043pzj.18.1683299567110; Fri, 05 May 2023 08:12:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683299567; cv=none; d=google.com; s=arc-20160816; b=Hv+KhZ2Si0q0sPTxF9ZQE8dfC/ZfrnhQ/THxUC9r9KLkOF7zVmc30qHsx72GBvF/RO L4X7Yze3C/85AGAHyQLzF6PjEF4C92mtbVeHa27cRNoloHUSyfby45qEp1hjgabAmrj1 b5WOrvYqpmrdIHlwJZHNvJ2QFsH9b2JVeHAIBW+mlo1ARLQrTfueYk/MbeFGay+DZxC6 ZGo1YOoJvUaZYYS+SvntF2i9F9ihMtGO7pqTpjAtmUpbJKBLfubDbda0dw3uSDWxvfDD uMOL5SX5Lqs9bExqUJ6U/OQ6IJmz7ir4wWTKVKcniOnPiudaPw3lGV1ut1LJ+JVoBAzo ddMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=bMT3CTvNOAP4fCjxDVg1BNstksZl3tnW2Myn+79x8Cw=; b=SRpd5iguISk+u1M8RJknAjzbwc9MxKBEBDJWbdssJtDMCeV92pgNxtoE2RjhwM91Z2 AWqncwD3pfm7rJayt+icygPHszg2JZnMVdpouXfrFf1iOEGqRYJfS3A+ZYXZS2CQwrKl DlZ8JjwYTxOcvBz1AjOtBMFQa8XCWHdS1NAYh17BvCxxKXFus2/pfAOaQugQRTkPsNka jvM01wdmZM3Qv5a59nM7REIZzaUnw5Z9KeyG4FTM2RokHivh9eBZVPeMonT+8cGQO3gn 5OjDelwDuna3PD5YY8IMGxZ1/XbsHmm6F3hgYxW/qlMTPyRJm148rrYeHSdblPpXnWIM Yjeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=QwEB81Il; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y65-20020a626444000000b0063b61b49a30si2200314pfb.253.2023.05.05.08.12.31; Fri, 05 May 2023 08:12:46 -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=@bytedance.com header.s=google header.b=QwEB81Il; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231852AbjEEPAQ (ORCPT + 99 others); Fri, 5 May 2023 11:00:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231941AbjEEPAP (ORCPT ); Fri, 5 May 2023 11:00:15 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C60217DD6 for ; Fri, 5 May 2023 07:59:50 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-64115eef620so20215718b3a.1 for ; Fri, 05 May 2023 07:59:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1683298789; x=1685890789; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=bMT3CTvNOAP4fCjxDVg1BNstksZl3tnW2Myn+79x8Cw=; b=QwEB81Ilrk88iqDgvmlnlkgY1xH/viUbnGvJIFCcTSa1/z5yxz10LKsGBVYzgcsZuX Y8VncuvEQdxKiuu7XU6cI7UiCWnAo9hy/57xcgqHl8Uh9DQL6odiJWFInMmVUsIpPNOd 6ReuzFiIJXtbdqvB2l+niWIPjPMXMNEPYa9kCThz6rmWzhRfqTEQzE5n+4wTiZ6M5Hrl DtpC2hpUpDLpRKS9Z+8qut8FG0ln+rashaBjgrXavbCRk2Xc6tRHV56kiXRYZXQlI4iK PtLyGq62Icg65t0xI0NHnRbh483/MfTaI0Jlg/KH7u9uiHE7bJU8MhB9Ag5bUHb/QDSg byGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683298789; x=1685890789; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bMT3CTvNOAP4fCjxDVg1BNstksZl3tnW2Myn+79x8Cw=; b=WQM3EjeppZ1MNRB7SjN7u6h/9EgPAj5AHzMulVV3H6QJjI6MDGKNDSah9p6LFM0uB/ BUEosfAtt4mcdXPqZ/w7YcY67XLyvurAs1AIXTiE7qsnx/k9LcxmA1QCFFVmBxcNdvuw QCdqDT4aAMRDwnWLPpKHcTuGvo5hfHH7K5+70QeoCPKYnDY0cgs1Ia0Fkul4qIZTOF3m UGHwew8lllEhhFvOwGwIjdXVoTFng2F6c/67Fkvec2/cnGmvXxkvBRcPY4fuMoEJxmPF Eu1+k+LNk8idGOLIzjWtbc9O+0acGT/1NdDMj//ZEoECj5TGdliw2iqT0CkmBCwPvZvA Fn7Q== X-Gm-Message-State: AC+VfDw1TNESZxWOAjYcCy+8i7rlQ1S3QMiexmIbCdIjd2Zr5WIrdhwZ VXSqO9NfwLPpTWAHdCaWOMV6+w== X-Received: by 2002:a17:90b:350d:b0:246:9517:30b6 with SMTP id ls13-20020a17090b350d00b00246951730b6mr7007998pjb.4.1683298789614; Fri, 05 May 2023 07:59:49 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.232]) by smtp.gmail.com with ESMTPSA id jx12-20020a17090b46cc00b0024e0141353dsm5193761pjb.28.2023.05.05.07.59.38 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 05 May 2023 07:59:49 -0700 (PDT) From: Peng Zhang To: Liam.Howlett@oracle.com Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Peng Zhang , "Edgecombe, Rick P" , Tad , Michael Keyes , Stable@vger.kernel.org Subject: [PATCH v2] maple_tree: Make maple state reusable after mas_empty_area() Date: Fri, 5 May 2023 22:58:29 +0800 Message-Id: <20230505145829.74574-1-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Make mas->min and mas->max point to a node range instead of a leaf entry range. This allows mas to still be usable after mas_empty_area() returns. Users would get unexpected results from other operations on the maple state after calling the affected function. Reported-by: "Edgecombe, Rick P" Reported-by: Tad Reported-by: Michael Keyes Link: https://lore.kernel.org/linux-mm/32f156ba80010fd97dbaf0a0cdfc84366608624d.camel@intel.com/ Link: https://lore.kernel.org/linux-mm/e6108286ac025c268964a7ead3aab9899f9bc6e9.camel@spotco.us/ Fixes: 54a611b60590 ("Maple Tree: add new data structure") Cc: Signed-off-by: Peng Zhang --- lib/maple_tree.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 110a36479dced..8ebc43d4cc8c5 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -5317,15 +5317,9 @@ int mas_empty_area(struct ma_state *mas, unsigned long min, mt = mte_node_type(mas->node); pivots = ma_pivots(mas_mn(mas), mt); - if (offset) - mas->min = pivots[offset - 1] + 1; - - if (offset < mt_pivots[mt]) - mas->max = pivots[offset]; - - if (mas->index < mas->min) - mas->index = mas->min; - + min = mas_safe_min(mas, pivots, offset); + if (mas->index < min) + mas->index = min; mas->last = mas->index + size - 1; return 0; } -- 2.20.1