* [PATCH] rust: bindings: derive Zeroable for bindgen's opaque array wrappers [not found] <27b58e47-723b-4d67-a1f0-ccb8b0ae66a9@kernel.dk> @ 2026-10-31 15:28 ` Sasha Levin 2026-10-31 16:17 ` Alice Ryhl 2026-11-01 0:48 ` Alexandre Courbot 0 siblings, 2 replies; 5+ messages in thread From: Sasha Levin @ 2026-10-31 15:28 UTC (permalink / raw) To: Miguel Ojeda, Jens Axboe Cc: Linus Torvalds, Josef Bacik, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich, Nathan Chancellor, rust-for-linux, linux-block, linux-kernel 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]>`. Commit 71ec3c7d6db8 ("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: 71ec3c7d6db8 ("blk-mq: quiesce a queue that joins a quiesced tag set") Signed-off-by: Sasha Levin <sashal@kernel.org> --- Jens, Linus: the block pull brought this in. 71ec3c7d6db8 puts the first spinlock_t into a struct that the Rust code zero-initializes, and since then a Rust allmodconfig build of mainline fails with bindgen 0.73. Sadly the commit wasn't in linux-next before the pull request went out, so the build breakage wasn't caught there. Build tested x86_64 and arm64 allmodconfig with bindgen 0.73.2, and the Rust code with bindgen 0.72.1 (no change to the generated bindings) and 0.73.0, with and without formatted bindgen output. rust/Makefile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rust/Makefile b/rust/Makefile index 0ac9ab28cc2b5..0165626decbe7 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -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) base-commit: 36aad21d50d1af3f6954bb0c988257a908202477 -- 2.53.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] rust: bindings: derive Zeroable for bindgen's opaque array wrappers 2026-10-31 15:28 ` [PATCH] rust: bindings: derive Zeroable for bindgen's opaque array wrappers Sasha Levin @ 2026-10-31 16:17 ` Alice Ryhl 2026-10-31 16:29 ` Sasha Levin 2026-11-01 0:48 ` Alexandre Courbot 1 sibling, 1 reply; 5+ messages in thread From: Alice Ryhl @ 2026-10-31 16:17 UTC (permalink / raw) To: Sasha Levin Cc: Miguel Ojeda, Jens Axboe, Linus Torvalds, Josef Bacik, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Nathan Chancellor, rust-for-linux, linux-block, linux-kernel On Sat, Oct 31, 2026 at 4:28 PM Sasha Levin <sashal@kernel.org> wrote: > > 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]>`. Commit 71ec3c7d6db8 > ("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: 71ec3c7d6db8 ("blk-mq: quiesce a queue that joins a quiesced tag set") > Signed-off-by: Sasha Levin <sashal@kernel.org> Is it possible to instead fix this by adding the impl of Zeroable in rust/bindings/lib.rs, similar to this piece of code that we already have: unsafe impl<Storage> Zeroable for __BindgenBitfieldUnit<Storage> where Storage: Zeroable {} Alice ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] rust: bindings: derive Zeroable for bindgen's opaque array wrappers 2026-10-31 16:17 ` Alice Ryhl @ 2026-10-31 16:29 ` Sasha Levin 2026-10-31 16:37 ` Alice Ryhl 0 siblings, 1 reply; 5+ messages in thread From: Sasha Levin @ 2026-10-31 16:29 UTC (permalink / raw) To: Alice Ryhl Cc: Miguel Ojeda, Jens Axboe, Linus Torvalds, Josef Bacik, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Nathan Chancellor, rust-for-linux, linux-block, linux-kernel On Sat, Oct 31, 2026 at 05:17:46PM +0100, Alice Ryhl wrote: >Is it possible to instead fix this by adding the impl of Zeroable in >rust/bindings/lib.rs, similar to this piece of code that we already >have: > >unsafe impl<Storage> Zeroable for __BindgenBitfieldUnit<Storage> where >Storage: Zeroable {} I looked at doing it that way, but the wrapper types don't always exist, so a fixed impl in lib.rs won't build everywhere: - bindgen 0.71 and 0.72 (we still support 0.71.1) don't generate them at all, the blob is a plain array there. - 0.73 only emits the alignments a config actually needs. On x86_64, allmodconfig gets __BindgenOpaqueArray, __BindgenOpaqueArray8, __BindgenOpaqueArray64 and __BindgenOpaqueArray4096, but defconfig with Rust enabled has no __BindgenOpaqueArray4096, so an impl for it would break the build there. __BindgenBitfieldUnit works because it's always generated. We could do it in lib.rs with a Kconfig symbol for the bindgen version plus some way to know which alignments a config ends up with, but tagging the wrappers right after bindgen runs seemed simpler. -- Thanks, Sasha ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] rust: bindings: derive Zeroable for bindgen's opaque array wrappers 2026-10-31 16:29 ` Sasha Levin @ 2026-10-31 16:37 ` Alice Ryhl 0 siblings, 0 replies; 5+ messages in thread From: Alice Ryhl @ 2026-10-31 16:37 UTC (permalink / raw) To: Sasha Levin Cc: Miguel Ojeda, Jens Axboe, Linus Torvalds, Josef Bacik, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Trevor Gross, Danilo Krummrich, Nathan Chancellor, rust-for-linux, linux-block, linux-kernel On Sat, Oct 31, 2026 at 5:29 PM Sasha Levin <sashal@kernel.org> wrote: > > On Sat, Oct 31, 2026 at 05:17:46PM +0100, Alice Ryhl wrote: > >Is it possible to instead fix this by adding the impl of Zeroable in > >rust/bindings/lib.rs, similar to this piece of code that we already > >have: > > > >unsafe impl<Storage> Zeroable for __BindgenBitfieldUnit<Storage> where > >Storage: Zeroable {} > > I looked at doing it that way, but the wrapper types don't always exist, > so a fixed impl in lib.rs won't build everywhere: > > - bindgen 0.71 and 0.72 (we still support 0.71.1) don't generate them > at all, the blob is a plain array there. > > - 0.73 only emits the alignments a config actually needs. On x86_64, > allmodconfig gets __BindgenOpaqueArray, __BindgenOpaqueArray8, > __BindgenOpaqueArray64 and __BindgenOpaqueArray4096, but defconfig > with Rust enabled has no __BindgenOpaqueArray4096, so an impl for it > would break the build there. > > __BindgenBitfieldUnit works because it's always generated. We could do it > in lib.rs with a Kconfig symbol for the bindgen version plus some way to > know which alignments a config ends up with, but tagging the wrappers > right after bindgen runs seemed simpler. Fair enough! Reviewed-by: Alice Ryhl <aliceryhl@google.com> ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] rust: bindings: derive Zeroable for bindgen's opaque array wrappers 2026-10-31 15:28 ` [PATCH] rust: bindings: derive Zeroable for bindgen's opaque array wrappers Sasha Levin 2026-10-31 16:17 ` Alice Ryhl @ 2026-11-01 0:48 ` Alexandre Courbot 1 sibling, 0 replies; 5+ messages in thread From: Alexandre Courbot @ 2026-11-01 0:48 UTC (permalink / raw) To: Sasha Levin Cc: Miguel Ojeda, Jens Axboe, Linus Torvalds, Josef Bacik, Boqun Feng, Gary Guo, Björn Roy Baron, Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross, Danilo Krummrich, Nathan Chancellor, rust-for-linux, linux-block, linux-kernel On Sun Nov 1, 2026 at 12:28 AM JST, Sasha Levin wrote: > 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]>`. Commit 71ec3c7d6db8 > ("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: 71ec3c7d6db8 ("blk-mq: quiesce a queue that joins a quiesced tag set") > Signed-off-by: Sasha Levin <sashal@kernel.org> I think this is going to be useful for Nova as well, so thanks! Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-01 0:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <27b58e47-723b-4d67-a1f0-ccb8b0ae66a9@kernel.dk>
2026-10-31 15:28 ` [PATCH] rust: bindings: derive Zeroable for bindgen's opaque array wrappers Sasha Levin
2026-10-31 16:17 ` Alice Ryhl
2026-10-31 16:29 ` Sasha Levin
2026-10-31 16:37 ` Alice Ryhl
2026-11-01 0:48 ` Alexandre Courbot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox