Skip to contentSkip to conversation

rust: bindgen: Preserve sched_statistics alignment

PATCH New Peder Bergan 1 participant 1 message Nov 23

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 5bab3cf063360..ef9379312fce9 100644
@@ -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]>