Re: rust compile failure in next-20260730
"Gary Guo" <[email protected]> Mon, 03 Aug 2026 14:57:49 +0100
| Newsgroups | org.kernel.vger.linux-next,org.kernel.vger.linux-kernel,org.kernel.vger.rust-for-linux |
|---|---|
| Message-ID | <[email protected]> |
On Fri Jul 31, 2026 at 8:25 PM BST, Nathan Chancellor wrote:
> + folks from e5e86df8b666
>
> On Fri, Jul 31, 2026 at 02:28:25PM +0200, Bert Karwatzki wrote:
>> With next-20260730 building a kernel with CONFIG_RUST=3Dy fails with
>> the following error:
>>=20
>> RUSTC L rust/kernel.o
>> error[E0308]: mismatched types
>> --> rust/kernel/sync/poll.rs:175:44
>> |
>> 175 | unsafe { bindings::kvfree_call_rcu((*ptr).rcu.get(), ptr=
.cast::<ffi::c_void>()) };
>> | ------------------------- ^^^^^^^^^^^^^^^^ expe=
cted `*mut kvfree_rcu_head`, found `*mut callback_head`
>> | |
>> | arguments to this function are incorrect
>> |
>> =3D note: expected raw pointer `*mut bindings::kvfree_rcu_head`
>> found raw pointer `*mut bindings::callback_head`
>> note: function defined here
>> --> /mnt/data/linux-forest/linux-next/rust/bindings/bindings_genera=
ted.rs:73708:12
>> |
>> 73708 | pub fn kvfree_call_rcu(head: *mut kvfree_rcu_head, ptr: *mut=
ffi::c_void);
>> | ^^^^^^^^^^^^^^^
>>=20
>> error: aborting due to 1 previous error
>>=20
>> For more information about this error, try `rustc --explain E0308`.
>> make[5]: *** [rust/Makefile:781: rust/kernel.o] Fehler 1
>> make[4]: *** [Makefile:1420: prepare] Fehler 2
>> make[3]: *** [debian/rules:80: build-arch] Fehler 2
>>=20
>> Reverting the following commits:
>> ef32a74f8f6a ("mm/slab: introduce kfree_rcu_nolock()")
>> bdd0cc9f0ffc ("mm/slab: introduce struct kvfree_rcu_head for kvfree_rcu =
batching")
>> =20
>> make the compilation work again. =20
>
> This is a collision between commit e5e86df8b666 ("rust: poll: use
> kfree_rcu() for PollCondVar") in the char-misc tree and the
> aforementioned commit bdd0cc9f0ffc ("mm/slab: introduce struct
> kvfree_rcu_head for kvfree_rcu batching") in the slab tree.
>
> Something like this avoids the error for me but I am not sure if it is
> a proper fix.
>
> diff --git a/rust/kernel/sync/poll.rs b/rust/kernel/sync/poll.rs
> index 684dfa242b1a..5b12d5d4e9af 100644
> --- a/rust/kernel/sync/poll.rs
> +++ b/rust/kernel/sync/poll.rs
> @@ -124,6 +124,9 @@ pub struct PollCondVarBox {
> struct PollCondVarBoxInner {
> #[pin]
> inner: PollCondVar,
> + #[cfg(CONFIG_KVFREE_RCU_BATCHED)]
> + rcu: Opaque<bindings::kvfree_rcu_head>,
> + #[cfg(not(CONFIG_KVFREE_RCU_BATCHED))]
> rcu: Opaque<bindings::callback_head>,
We could also unconditionally use `kvfree_rcu_head` here, and
add
#[cfg(not(CONFIG_KVFREE_RCU_BATCHED))]
pub type kvfree_rcu_head =3D callback_head;
to bindings.rs?
(Or even better, changing `#define` to `typedef` so bindgen takes care of
everything).
Best,
Gary