Re: [PATCH] rust: add `CacheAligned` for easy cache line alignment of values

From: Miguel Ojeda

Date: Wed Jan 28 2026 - 09:31:35 EST


On Wed, Jan 28, 2026 at 3:05 PM Andreas Hindborg <a.hindborg@xxxxxxxxxx> wrote:
>
> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxxx>
> ---
> Signed-off-by: Andreas Hindborg <a.hindborg@xxxxxxxxxx>

Something strange is going on with the tags.

> +// SPDX-License-Identifier: GPL-2.0

Please give a title to the module even if it is not public.

> +use kernel::try_pin_init;
> +use pin_init::{
> + pin_data,
> + pin_init,
> + PinInit, //
> +};
> +
> +/// Wrapper type that alings content to a 64 byte cache line.

Typo.

More importantly, please add some docs and examples -- the commit
message has more documentation than the code... :)

Also, it would be nice to show a user in a second patch.

> +#[repr(align(64))]

Even if 64 bytes is common, wouldn't this depend on the system?

> + /// Creates a fallible initializer for `CacheAligned<T>` form a fallible
> + /// initalizer for `T`

Two typos and missing period at the end.

Also just using [`CacheAligned`] would probably be simpler.

> + // SAFETY: by function safety requirements `ptr` is valid for read

// SAFETY: By the the safety requirement, `ptr` is valid for read.

> + try_pin_init!( CacheAligned {

This and another one is formatted differently than we usually do.

> +pub use cache_aligned::CacheAligned;

It seems you want this short, in which case it should perhaps go in
that case, but I think it is best to leave an extra level otherwise
and let users import it.

Thanks!

Cheers,
Miguel