Re: [PATCH v2] rust: xarray: fix false positive lockdep warnings
From: Tamir Duberstein
Date: Fri Jun 05 2026 - 08:14:39 EST
On Fri, 05 Jun 2026 11:14:29 +0200, Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
> diff --git a/rust/helpers/xarray.c b/rust/helpers/xarray.c
> index 08979b304341..dce8b36492e6 100644
> --- a/rust/helpers/xarray.c
> +++ b/rust/helpers/xarray.c
> @@ -7,9 +7,21 @@ __rust_helper int rust_helper_xa_err(void *entry)
> return xa_err(entry);
> }
>
> -__rust_helper void rust_helper_xa_init_flags(struct xarray *xa, gfp_t flags)
> +/*
> + * `xa_init_flags()` expands `spin_lock_init()`, which generates one static
> + * `lock_class_key` per compilation unit. Going through a single Rust binding
> + * helper would make every Rust `XArray` instance share that one key, causing
> + * false-positive lock-ordering reports from lockdep. Re-register the
> + * spinlock's lockdep class with a key supplied by the caller so each Rust
> + * instantiation site can have its own.
> + */
This is an implementation comment rather than a useful comment for the
caller.
>
> diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs
> index 46e5f43223fe..78c9fbe8f0aa 100644
> --- a/rust/kernel/xarray.rs
> +++ b/rust/kernel/xarray.rs
> @@ -27,9 +42,10 @@
> ///
> /// ```rust
> /// use kernel::alloc::KBox;
> -/// use kernel::xarray::{AllocKind, XArray};
> +/// use kernel::xarray::{new_xarray, AllocKind, XArray};
> ///
> -/// let xa = KBox::pin_init(XArray::new(AllocKind::Alloc1), GFP_KERNEL)?;
> +/// let xa: Pin<KBox<XArray<KBox<u32>>>> =
> +/// KBox::pin_init(new_xarray!(AllocKind::Alloc1), GFP_KERNEL)?;
Was it necessary to add this type ascription on the LHS?
--
Tamir Duberstein <tamird@xxxxxxxxxx>