mirror of
https://github.com/torvalds/linux.git
synced 2026-11-20 13:03:48 +00:00
rust: bindings: derive Zeroable for bindgen's opaque array wrappers
bindgen 0.73 emits the blob of some opaque types, such as ones aligned to more than 4 bytes, as a `__BindgenOpaqueArray` or `__BindgenOpaqueArray<align>` newtype instead of a plain array. The newtype only derives `PartialEq`, `Eq`, `Copy`, `Clone`, `Debug` and `Hash`, and the `MaybeZeroable` custom derive does not reach it, so a struct that embeds such an opaque type is no longer `Zeroable`. `spinlock` is opaque (see rust/bindgen_parameters), and with lockdep its blob becomes a `__BindgenOpaqueArray8<[u8; 72]>`. Commit71ec3c7d6d("blk-mq: quiesce a queue that joins a quiesced tag set") added a `spinlock_t` to `struct blk_mq_tag_set`, so an allmodconfig build with bindgen 0.73 now fails: error[E0277]: the trait bound `bindings::__BindgenOpaqueArray8<[u8; 72]>: pin_init::Zeroable` is not satisfied --> rust/kernel/block/mq/tag_set.rs:41:49 Which wrappers exist depends on the bindgen version and on the opaque types of the configuration, so they cannot be covered by unconditional impls in rust/bindings/lib.rs like `__BindgenBitfieldUnit` is. Derive `Zeroable` for each wrapper in the generated bindings instead. The pattern allows for the spacing of bindgen's output when rustfmt is not available. Fixes:71ec3c7d6d("blk-mq: quiesce a queue that joins a quiesced tag set") Signed-off-by: Sasha Levin <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Reviewed-by: Alexandre Courbot <[email protected]> Reported-by: Nathan Chancellor <[email protected]> Closes: https://lore.kernel.org/rust-for-linux/20261030223702.GA1673281@ax162/ Link: https://patch.msgid.link/[email protected] Signed-off-by: Miguel Ojeda <[email protected]>
This commit is contained in:
committed by
Miguel Ojeda
parent
62a40c7290
commit
57d916a3eb
+8
-1
@@ -514,13 +514,20 @@ endif
|
||||
bindgen_c_flags_final = $(bindgen_c_flags_lto) -fno-builtin -D__BINDGEN__
|
||||
|
||||
# `--rust-target` points to our minimum supported Rust version.
|
||||
#
|
||||
# `bindgen` 0.73 emits the blob of some opaque types as a
|
||||
# `__BindgenOpaqueArray[<align>]` newtype, which the custom derives do not
|
||||
# reach. Derive `Zeroable` for those wrappers, so that a struct embedding such
|
||||
# an opaque type (e.g. `spinlock_t` with lockdep) is still `Zeroable`. The
|
||||
# pattern also matches the unformatted output used when `rustfmt` is missing.
|
||||
quiet_cmd_bindgen = BINDGEN $@
|
||||
cmd_bindgen = \
|
||||
$(BINDGEN) $< $(bindgen_target_flags) --rust-target 1.85 \
|
||||
--use-core --with-derive-default --ctypes-prefix ffi --no-layout-tests \
|
||||
--no-debug '.*' --enable-function-attribute-detection \
|
||||
-o $@ -- $(bindgen_c_flags_final) -DMODULE \
|
||||
$(bindgen_target_cflags) $(bindgen_target_extra)
|
||||
$(bindgen_target_cflags) $(bindgen_target_extra); \
|
||||
sed -Ei 's/pub struct __BindgenOpaqueArray[0-9]* *< *T *> *\( *pub T *\) *;/$(pound)[derive(pin_init::Zeroable)] &/g' $@
|
||||
|
||||
$(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \
|
||||
$(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters)
|
||||
|
||||
Reference in New Issue
Block a user