rust: bindgen: Preserve sched_statistics alignment
Subsystems (2)
PATCH v3 1/1 rust: bindgen: Preserve sched_statistics alignment
With CONFIG_SCHEDSTATS disabled, struct sched_statistics is empty but still cache-line aligned. Bindgen omits the alignment of the empty type. Bindgen 0.73.2 also stopped forcing padding before over-aligned fields, so fields following stats can be misplaced in the generated task_struct. On the reported arm64 build, Rust Binder reads the wrong pointer via CurrentTask::mm() and rejects mmap() with -EINVAL.
Make sched_statistics opaque so bindgen uses the C size and alignment. Rust has no callers that access the fields of this type.
---
Changes in v3:
- I generalized the comment to cover any types listed below it.
- Link to v2: https://lore.kernel.org/rust-for-linux/20261120-fix-schedstats-bindgen-layout-v2-1-1c42e4a996ae@gmail.com/
OpenAI Codex assisted with the bindgen change, validation and drafting.
--- rust/bindgen_parameters | 6 ++++++ 1 file changed, 6 insertions(+)
rust/bindgen_parameters +6 -0
@@ -26,6 +26,12 @@ # warning. We don't need to peek into it anyway. --opaque-type spinlock +# Bindgen omits the alignment of empty structs. Bindgen 0.73.2 also stopped +# forcing padding before over-aligned fields, so following fields can be +# misplaced. Making the types below opaque preserves their C alignment. +# https://github.com/rust-lang/rust-bindgen/issues/3549 +--opaque-type sched_statistics + # enums that appear in indirect function calls should specify a cfi type --newtype-enum fwctl_rpc_scope --with-attribute-custom-enum=fwctl_rpc_scope='#[cfi_encoding="15fwctl_rpc_scope"]'
---
base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
change-id: 20261119-fix-schedstats-bindgen-layout-0935b6434707
Best regards,
Signature · 1 line
Peder Bergan <[email protected]>