Re: [PATCH v2] rust: xarray: fix false positive lockdep warnings

From: Alice Ryhl

Date: Fri Jun 05 2026 - 07:25:58 EST


On Fri, Jun 05, 2026 at 11:14:29AM +0200, Andreas Hindborg wrote:
> `xa_init_flags()` is a static inline that expands `spin_lock_init()`,
> which generates a single static `lock_class_key` per compilation unit.
> When used through the Rust binding helper, every Rust `XArray`
> instance ends up sharing that single key. Lockdep then sees concurrent
> locking of distinct Rust `XArray`s as recursive locking on the same
> class and emits false-positive lock-ordering reports.
>
> Add a custom helper `xa_init_flags_with_key()` that mirrors
> `xa_init_flags()` but takes an explicit name and `struct
> lock_class_key` from the caller. Update `XArray::new` to take a name
> and a `LockClassKey`, and add a `new_xarray!` macro that uses
> `optional_name!` and `static_lock_class!` to generate a unique class
> per instantiation site.
>
> Remove the now unused `rust_helper_xa_init_flags`.
>
> This was previously part of the series at [1].
>
> Link: https://lore.kernel.org/r/20251203-xarray-entry-send-v1-0-9e5ffd5e3cf0@xxxxxxxxxx [1]
> Fixes: 210b81578efbe ("rust: xarray: Add an abstraction for XArray")
> Suggested-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
> Acked-by: Tamir Duberstein <tamird@xxxxxxxxxx>
> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>

Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>