Re: [PATCH] rust: bindgen: Preserve sched_statistics alignment
From: Miguel Ojeda
Date: Fri Nov 20 2026 - 07:32:15 EST
On Thu, Nov 19, 2026 at 8:33 PM Peder Bergan via B4 Relay
<devnull+peder.bergan.gmail.com@xxxxxxxxxx> wrote:
>
> With CONFIG_SCHEDSTATS disabled, struct sched_statistics is empty but
> still cache-line aligned. Bindgen emits the empty definition without
> that alignment.
Link: https://github.com/rust-lang/rust-bindgen/issues/3549
Most importantly, this is about a bug that happens to be exposed in
bindgen 0.73.2 only, as far as I can see -- could you please confirm?
> In the reported arm64 build, Rust
> Binder reads the wrong pointer via CurrentTask::mm() and rejects mmap()
> with -EINVAL.
Cc'ing the Binder folks.
> Fixes: 313c4281bc9d ("rust: add basic `Task`")
Given this is a `bindgen` bug, this tag should instead be:
Cc: stable@xxxxxxxxxxxxxxx # 6.12.x (Rust is pinned in older LTSs)
> Jules Mercier reported the layout mismatch on arm64.
Reported-by: Jules Mercier
(I asked Jules about an email in the issue)
> +# Bindgen drops the alignment of empty structs. Keep the cache-line alignment
> +# of sched_statistics when CONFIG_SCHEDSTATS is disabled.
> +--opaque-type sched_statistics
This seems OK as a temporary workaround, but I would probably write
something like:
# Bindgen drops the alignment of empty structs and bindgen 0.73.2
does not add
# explicit padding before over-aligned fields either, thus the
fields that follow
# get misplaced: https://github.com/rust-lang/rust-bindgen/issues/3549
# By making these structs opaque, we recover their alignment.
(In addition, it would still be nice to have a debug Kconfig symbol to
enable the layout tests as discussed in the issue, but that is an
independent patch, of course -- I am thinking of gating it under a new
`BINDGEN_VERSION`, plus particular architectures where we can confirm
it is clean, and maybe `!COMPILE_TEST` in the beginning too...).
Thanks!
Cheers,
Miguel