Re: [PATCH 10/10] rust: xarray: fix false positive lockdep warnings
From: Gary Guo
Date: Wed Jan 21 2026 - 10:59:32 EST
On Wed Dec 3, 2025 at 10:26 PM GMT, Andreas Hindborg wrote:
> Replace the `xa_init_flags` helper with direct initialization of XArray
> structures using `__spin_lock_init`. This allows each XArray to have
> its own lock class key for lockdep, preventing false positive warnings
> about lock ordering violations.
>
Isn't this potentially a problem on the C side as well? `xa_init_flags` is a
static inline function, which means that the lock class is going to be the same
if a single C compilation unit initializes multiple xarrays -- unlike when you
use spin_lock_init, where each callsite gets a different lock class.
Best,
Gary
> Add a `new_xarray!` macro that automatically generates a unique lock
> class key for each XArray instantiation site. The macro accepts an
> optional name parameter and uses the `optional_name!` and
> `static_lock_class!` macros to generate appropriate names and lock
> classes.
>
> Update the `XArray::new` method signature to accept explicit name and
> lock class key parameters. This enables proper lockdep tracking while
> maintaining flexibility for advanced use cases.
>
> Remove `rust_helper_xa_init_flags` as it is now dead code.
>
> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>
> ---
> rust/helpers/xarray.c | 5 ---
> rust/kernel/xarray.rs | 74 +++++++++++++++++++++++++++++++++------------
> rust/kernel/xarray/entry.rs | 55 ++++++++++++++++++---------------
> 3 files changed, 86 insertions(+), 48 deletions(-)