From patchwork Tue Oct 15 23:39:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13837427 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86B15D20682 for ; Tue, 15 Oct 2024 23:39:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 127476B0083; Tue, 15 Oct 2024 19:39:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D7DE6B0088; Tue, 15 Oct 2024 19:39:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF6CB6B008A; Tue, 15 Oct 2024 19:39:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id B71A56B0083 for ; Tue, 15 Oct 2024 19:39:34 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 3547AA198D for ; Tue, 15 Oct 2024 23:39:17 +0000 (UTC) X-FDA: 82677455700.16.B7BD698 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) by imf21.hostedemail.com (Postfix) with ESMTP id 370761C0017 for ; Tue, 15 Oct 2024 23:39:16 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=msP7sZgO; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729035525; a=rsa-sha256; cv=none; b=GJrN2WNsgjuTAK7R4Bd0J46XB4rS79KDrkafuphpODQWuQftojO3y2MxG8y1/VxujD1LUj gm+GuLr9MwaOgRnYXC3VTasij7X5nhuyC6Wyd5AiNDimrS7g+XgQYVtzO214LaN2LVRAIv m6EVY+Wh8K3Ts9CIZwkoIzAPu43jMrk= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=msP7sZgO; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.41 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729035525; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=HuSYYhE/JkpFSKLOeglwPqOvNxdz4SQPYnMe0bHyg7E=; b=kKlYo4kK3vhRnbCdMDY5fkYmMUaBqhJeJtb7E62NfY0hd06H+aI0ChnxwvfYggYZVBqZnX IXoljQVqW1vOZmD7eSpX/lE4AyfzZBd4iAuX98ai30goTIZMFkyVB0RNdZKgBGRT9+qGsu hYKdAy2+nK7o39GzbRT0+VIzNLGo5ag= Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a99f3a5a44cso414061666b.3 for ; Tue, 15 Oct 2024 16:39:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729035571; x=1729640371; darn=kvack.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=HuSYYhE/JkpFSKLOeglwPqOvNxdz4SQPYnMe0bHyg7E=; b=msP7sZgOLXJZ85udeQg/KkF2xiKUk8EGcvcJLvVw3D1wDNdKCocIqJ5kM5NFJ3dxdl llV/dldh4PJCkNOkQzCAbtrQJkGDVVbkHgDlmcvciAoS9Ce586Fq813seq7Mfb3OIJ1d cwSTO0SH61qNU53+gKfEXRbZNO6dXjV9CfJcQKPKlkmGAm/Dfo/EfZ8epQJkt3ZgcCro J/lxKza1Nbbo6oN+YmSVhkl0lIptTMLeOewheKRvoayq8dz/+bToJ75QRreqj+KFn3wy GOxpsefMEItg0WRsBwHH+7a5xuyBUDWJw+/02bwb1V88W6jw/dzbnRZiW7f8fbUekvbJ 1bww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729035571; x=1729640371; h=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=HuSYYhE/JkpFSKLOeglwPqOvNxdz4SQPYnMe0bHyg7E=; b=JBs27l+Bclr5Wr7/Tx7uviU9QyzNbE2NmuSNT8Iudb3/5HjpUqZEjmWvSD4U0qktaE Vhb767pXdZdtTKh80wYesI1vbAwNrOwExk7Gl2lVA/fdeVpyH4e42+92TseoFT4qXx08 P92dF+vqqyacQXChJ4WB/dnqUXqRjTuHVYaxGKw8qWfHMXOGMGeOu3aBgDFcO7xju+pS N0YpboGJgpu76ze/ECCCvB/piNL24o9wy3eUmGS9/Un2v3gHkZG8B19zpyBfs2WLw+dn jrDpDRXJ6pi6TfNz0fcIL2b6w+Ru/LY78uAp/vg9+L/529R7zd5gxEOq8+Sos3jHMtxA Z4Dg== X-Forwarded-Encrypted: i=1; AJvYcCV0UuWpkYyNDHVQpM7yS4mPydd4DPM3kgrO8VcmJSoac/dHASbQ9upTiMAp0azujBqr1ecDezxGsQ==@kvack.org X-Gm-Message-State: AOJu0YwbimOTmISNXh9tKO3d0FnBJzyER/g7GyiruGtYXc7MijvPFaEp dkGQuDLLyERiedjzv6SR3IvmkXmtLMVNInDIEFBa56/5IdNWnOCV X-Google-Smtp-Source: AGHT+IEkFxbVt2nizystO1bzmnWwbFtIEPHN4fPC2zeLlxQlLhfnvDqbrl4dATuniR3I8YdXD/xJdA== X-Received: by 2002:a17:907:d2df:b0:a99:f656:2bd8 with SMTP id a640c23a62f3a-a9a34dd96e5mr153545966b.42.1729035570803; Tue, 15 Oct 2024 16:39:30 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9a29717cc2sm120025866b.13.2024.10.15.16.39.29 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 Oct 2024 16:39:29 -0700 (PDT) From: Wei Yang To: Liam.Howlett@oracle.com, akpm@linux-foundation.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, Wei Yang , "Liam R . Howlett" , Sidhartha Kumar , Lorenzo Stoakes Subject: [PATCH 2/2] maple_tree: one single entry couldn't represent the whole range Date: Tue, 15 Oct 2024 23:39:09 +0000 Message-Id: <20241015233909.23592-3-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20241015233909.23592-1-richard.weiyang@gmail.com> References: <20241015233909.23592-1-richard.weiyang@gmail.com> X-Rspam-User: X-Rspamd-Queue-Id: 370761C0017 X-Rspamd-Server: rspam01 X-Stat-Signature: qb3k16546wr34rawex47dnixthy1o17o X-HE-Tag: 1729035556-990000 X-HE-Meta: U2FsdGVkX18urBl+1/YncESZccCJN/Kz8LTvqymWfeXruj+jvtg7k9TqjoKF5aweItpPkv0xO3EQBAbDpMICEeGfJMZDz76WkHxXbWnti/nI0NYos7nz9SB9noPIqd34mpDIamFr/1ZAmNSksDJyfxbNYU5aRP30yH7bYXFQrfd/23jnmnu9U1Vy24qQitXKnyaJvqGFIP4rE47HwHMVHob/JPs8CiFHQF0nWFlm1FQJ2ckyH8bfTFf4FjDWKUnGvqwaPYHGY/trf3GF5VbqMYp0KuxxqlSqbmO1nGU2lpTk61W1pJjfmg6oAudtAPSr2iIz6eWvwFpOpMdF1rqeyuLYJCiVkVjRxrgrA1fCEmPpV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s7D5k4MwGv1MWKgYo+/hSjm1+rWGhVA5YGN/Bq5m2AOUDJNuYVB1vRUhFKVjsRKpBE X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The current behavior of overwriting the whole range with NULL is not correct. For example, we store range [0, ULONG_MAX] to a new tree: mas_set_range(&ms, 0, ULONG_MAX); mas_store(&ms, NULL); mt_dump(mt, mt_dump_dec); The dump result shows: maple_tree(0x7ffd9506e350) flags 7, height 1 root 0x61500000010e 0-18446744073709551615: node 0x615000000100 depth 0 type 1 parent 0x7ffd9506e351 contents: (nil) 18446744073709551615 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0 (nil) 0-18446744073709551615: (nil) But if we do the store on a tree with value: mas_set_range(&ms, 5, ULONG_MAX); mas_store(&ms, NULL); mas_set_range(&ms, 0, ULONG_MAX); mas_store(&ms, NULL); mt_dump(mt, mt_dump_dec); The dump result shows: maple_tree(0x7ffd9506e350) flags 3, height 0 root (nil) 0: (nil) We can see even we write the same range, these two trees are different. The second tree only has an entry represent range [0, 0] instead of range [0, ULONG_MAX], which is not correct. The good news is it doesn't affect user, because mtree_load() still return NULL for each index. Let's create a node to represent the entire range even for NULL entry. Fixes: 54a611b60590 ("Maple Tree: add new data structure") Signed-off-by: Wei Yang CC: Liam R. Howlett CC: Sidhartha Kumar CC: Lorenzo Stoakes --- lib/maple_tree.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 3a12866a4a89..5dfc589a8cde 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3594,14 +3594,6 @@ static inline void mas_new_root(struct ma_state *mas, void *entry) void __rcu **slots; unsigned long *pivots; - if (!entry) { - mas->depth = 0; - mas_set_height(mas); - rcu_assign_pointer(mas->tree->ma_root, entry); - mas->status = ma_start; - goto done; - } - node = mas_pop_node(mas); pivots = ma_pivots(node, type); slots = ma_slots(node, type); @@ -3614,7 +3606,6 @@ static inline void mas_new_root(struct ma_state *mas, void *entry) mas_set_height(mas); rcu_assign_pointer(mas->tree->ma_root, mte_mk_root(mas->node)); -done: if (xa_is_node(root)) mte_destroy_walk(root, mas->tree);