From: "Liam R. Howlett" <Liam.Howlett@oracle.com>
To: Boudewijn van der Heide <boudewijn@delta-utec.com>
Cc: akpm@linux-foundation.org, aliceryhl@google.com,
andrewjballance@gmail.com, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, maple-tree@lists.infradead.org
Subject: Re: [PATCH v2] maple_tree: Add lockdep assertion in mas_dup_alloc()
Date: Tue, 20 Jan 2026 13:42:06 -0500 [thread overview]
Message-ID: <h54uysfjc62hxcxdnhpj4fnc3smufwiocdkzp3uiah3e2323hc@ljfkxmstxnbo> (raw)
In-Reply-To: <20260106210757.465586-1-boudewijn@delta-utec.com>
* Boudewijn van der Heide <boudewijn@delta-utec.com> [260106 16:08]:
> The __mt_dup() function requires callers to hold the appropriate write
> lock when duplicating a maple tree. Without proper locking, concurrent
> modifications during duplication could access invalid node slots.
>
> Add a lockdep assertion to catch such API misuse during development.
> This is API hardening rather than a bug fix - all in-tree callers
> already follow the proper locking rules as documented above __mt_dup().
>
> Signed-off-by: Boudewijn van der Heide <boudewijn@delta-utec.com>
> ---
> Changes in v2:
> - Replaced runtime deadnode check with a lockdep assertion
> v1:
> https://lore.kernel.org/lkml/20260103165758.74094-1-boudewijn@delta-utec.com/
>
> diff --git a/lib/maple_tree.c b/lib/maple_tree.c
> index 5aa4c9500018..3b4357f16352 100644
> --- a/lib/maple_tree.c
> +++ b/lib/maple_tree.c
> @@ -6248,6 +6248,8 @@ static inline void mas_dup_alloc(struct ma_state *mas, struct ma_state *new_mas,
> void __rcu **new_slots;
> unsigned long val;
>
> + lockdep_assert(mt_write_locked(mas->tree));
> +
This is still the wrong place. You are validating the lock is held in a
function that is called in a loop without any unlocking.
mas_dup_build() is the only caller of mas_dup_alloc(), and that is only
called from two functions: __mt_dup() and mtree_dup().
This would be better served in __mt_dup() since the other caller,
mtree_dup(), already does the locking so there's no way this will
trigger from that call path.
That way, we don't spend a lot of cycles checking lockdep when forking
for no reason.
> /* Allocate memory for child nodes. */
> type = mte_node_type(mas->node);
> new_slots = ma_slots(new_node, type);
> --
> 2.47.3
>
>
next prev parent reply other threads:[~2026-01-20 18:42 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-03 16:57 [PATCH] maple_tree: Add dead node check " Boudewijn van der Heide
2026-01-03 18:32 ` Andrew Morton
2026-01-03 20:06 ` Boudewijn van der Heide
2026-01-06 1:33 ` Andrew Morton
2026-01-06 2:49 ` Matthew Wilcox
2026-01-06 3:40 ` Andrew Morton
2026-01-06 13:24 ` Boudewijn van der Heide
2026-01-06 16:01 ` Liam R. Howlett
2026-01-06 16:48 ` Boudewijn van der Heide
2026-01-06 18:29 ` Matthew Wilcox
2026-01-06 20:07 ` Liam R. Howlett
2026-01-06 21:07 ` [PATCH v2] maple_tree: Add lockdep assertion " Boudewijn van der Heide
2026-01-20 18:42 ` Liam R. Howlett [this message]
2026-01-21 13:52 ` Boudewijn van der Heide
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=h54uysfjc62hxcxdnhpj4fnc3smufwiocdkzp3uiah3e2323hc@ljfkxmstxnbo \
--to=liam.howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=aliceryhl@google.com \
--cc=andrewjballance@gmail.com \
--cc=boudewijn@delta-utec.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=maple-tree@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox