Skip to content

rust: bindgen: make sched_statistics opaque - #992

Merged
DjDeveloperr merged 2 commits into
integration/aurorafrom
fix/rust-sched-bindings
Nov 6, 2026
Merged

DjDeveloperr merged 2 commits into
integration/aurorafrom
fix/rust-sched-bindings

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Builds with stock bindgen 0.73.2 stop in rust/bindings.o and rust/uapi.o with two E0080 layout errors:

Assertion rustc C
align_of::<sched_statistics>() 1 64
offset_of!(task_struct, stats) 792 832

Cause

No recent struct change caused this. With CONFIG_SCHEDSTATS=n, struct sched_statistics is empty and ____cacheline_aligned. bindgen drops the alignment of a zero-sized non-opaque struct and emits pub struct sched_statistics {}.

The omacom tree (30a6518) passes --no-layout-tests by default, so a mismatch like this has nothing to catch it there. 7b563df made the assertions mandatory here, which turned the hidden mismatch into a build error.

tools/aurora-bindgen also repairs this, but someone has to prepare it by hand. Without it, Kbuild falls back to bindgen on PATH.

Fix

Add --opaque-type sched_statistics to rust/bindgen_parameters. bindgen takes an opaque type's layout from Clang, so stock 0.73.2 emits #[repr(align(64))]. The C layout doesn't change, every assertion stays on, and no Rust code reads these fields.

task_struct has a single assertion block and const evaluation stops at its first failure, so stats passing also lets the checks on all later fields run. None of them fail.

I also corrected the doc and the rust_is_available.sh warning, which said default Asahi builds fail on this type. The warning itself stays, since other aligned empty structs can still hit the bindgen bug.

Validation

Both runs used integration/aurora 11eccbe, the asahi profile and the build VM's stock bindgen 0.73.2 with make -k rust/bindings.o rust/uapi.o. Kbuild's prepare also builds rust/kernel.o.

Without the fix, ./linux-build/build exits 1. Both objects fail with the same two errors, and both generated files have pub struct sched_statistics {}:

error[E0080]: attempt to compute `1_usize - 64_usize`, which would overflow
    ["Alignment of sched_statistics"][::core::mem::align_of::<sched_statistics>() - 64usize];
error[E0080]: attempt to compute `792_usize - 832_usize`, which would overflow
    ["Offset of field: task_struct::stats"][::core::mem::offset_of!(task_struct, stats) - 832usize];

With the fix, in the same output directory, it exits 0. rust/bindings.o, rust/uapi.o and rust/kernel.o all build, with no E0080 across 26169 assertion lines in bindings_generated.rs and 13361 in uapi_generated.rs. The generated struct is now #[repr(C)] #[repr(align(64))] pub struct sched_statistics. The VM's post-build check passed, and a separate build verify reported checked 113373 files in 504 packages; 0 bad.

This branch now merges 11eccbe. Its tree, 6ae17468d9e, is the tree I tested with the fix.

scripts/rust_is_available_test.py passes all 35 tests.

I didn't rebuild Image modules on this base. Three from-scratch asahi Image modules builds on the earlier base (2661d71) ran make to completion with no E0080, including asahi_core.o and aurora.ko, but all three failed the VM's post-build check on corrupted guest memory (24, 31 and 408 bad package files). Treat those three as evidence that the code compiled and don't use them as artifacts.

Nothing has been boot-tested. The change only affects the build.

🤖 Generated with Claude Code

With CONFIG_SCHEDSTATS=n, struct sched_statistics is an empty
____cacheline_aligned struct. bindgen 0.73.2 drops the alignment of a
zero-sized non-opaque struct and emits `pub struct sched_statistics {}`
with alignment 1. Rust then puts task_struct::stats at offset 792 where C
has 832, and later fields, including mm, move with it.

Commit 7b563df ("rust: require checked binding layouts for every
kernel build") made the layout assertions mandatory, so a build with
stock bindgen stops with E0080. Trees that pass --no-layout-tests still
build, with the wrong offsets.

Declare the type opaque. bindgen takes an opaque type's layout from Clang,
so stock bindgen emits #[repr(align(64))] and the assertions pass without
preparing tools/aurora-bindgen. The C layout does not change and no Rust
code reads these fields.

Update the documentation and the rust_is_available.sh warning, which said
default Asahi builds fail on this type.

Signed-off-by: Diljit Singh <[email protected]>
@DjDeveloperr
DjDeveloperr merged commit 0943983 into integration/aurora Nov 6, 2026
DjDeveloperr added a commit that referenced this pull request Nov 6, 2026
Picks up the bindgen fix (#992), without which the asahi profile does not
build.

Signed-off-by: Diljit Singh <[email protected]>
RyanTheTide added a commit that referenced this pull request Nov 6, 2026
Keep linux#922 current with integration/aurora (#992 rust bindgen
layout) for the speakerguardd v2 cutover (option A).

Signed-off-by: Ryan Murray <[email protected]>
Assisted-by: LLM
@RyanTheTide
RyanTheTide deleted the fix/rust-sched-bindings branch November 7, 2026 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant