Re: rust compile failure in next-20260730

"Gary Guo" <[email protected]> Tue, 04 Aug 2026 11:10:49 +0100
Newsgroups org.kernel.vger.rust-for-linux,org.kernel.vger.linux-kernel,org.kernel.vger.linux-next
Message-ID <[email protected]>
On Mon Aug 3, 2026 at 10:04 PM BST, Vlastimil Babka (SUSE) wrote:
> On 8/3/26 17:32, Gary Guo wrote:
>> On Mon Aug 3, 2026 at 4:10 PM BST, Vlastimil Babka (SUSE) wrote:
>>> On 8/3/26 16:23, Boqun Feng wrote:
>>>> On Mon, Aug 03, 2026 at 02:57:49PM +0100, Gary Guo wrote:
>>>>>=20
>>>>> We could also unconditionally use `kvfree_rcu_head` here, and
>>>>> add
>>>>>=20
>>>>>     #[cfg(not(CONFIG_KVFREE_RCU_BATCHED))]
>>>>>     pub type kvfree_rcu_head =3D callback_head;
>>>>>=20
>>>>> to bindings.rs?
>>>>>=20
>>>>=20
>>>> This option is currently not maintainable unless it becomes a
>>>> maintainer-aware way to handle things like this.
>>>>=20
>>>>> (Or even better, changing `#define` to `typedef` so bindgen takes car=
e of
>>>>> everything).
>>>>>=20
>>>>=20
>>>> Yes, this is better IMO, but it's up to slab maintainers. :-)
>>>
>>> Can you elaborate a bit please, how would that look like?
>>=20
>> I was thinking of doing `typedef struct rcu_head kvfree_rcu_head;` but o=
f course
>> that didn't work because you can't use typedef to create `kvfree_rcu_hea=
d` :)
>>=20
>> However, something like this could work?
>>=20
>>     #ifdef CONFIG_KVFREE_RCU_BATCHED
>>     ...
>>     #else
>>     struct kvfree_rcu_head {
>>         struct rcu_head head;
>>     };
>>     #endif
>>=20
>> and everywhere add a cast everywhere that expects kvfree_rcu_head =3D=3D=
 rcu_head.
>>=20
>> but this would indeed be more complex :(
>
> So you mean like this? Doesn't seem so complex and seems to compile here
> with CONFIG_KVFREE_RCU_BATCHED both disabled and enabled.

I thought that a lot more places have to be updated, but it looks from your=
 diff
below that this is simple enough.

Best,
Gary

> I can apply the slab part in slab tree, but AFAICS the poll.rs
> change still needs to be done in the merge commit. Unless there's
> some way to make things conditional on whether kvfree_rcu_head exists?
>
> diff --git a/include/linux/types.h b/include/linux/types.h
> index 79bf419c69e4..53e0adca4b9f 100644
> --- a/include/linux/types.h
> +++ b/include/linux/types.h
> @@ -262,7 +262,9 @@ struct kvfree_rcu_head {
>  	struct kvfree_rcu_head *next;
>  };
>  #else
> -#define kvfree_rcu_head rcu_head
> +struct kvfree_rcu_head {
> +	struct rcu_head head;
> +};
>  #endif
> =20
>  typedef void (*rcu_callback_t)(struct rcu_head *head);
> diff --git a/mm/slab_common.c b/mm/slab_common.c
> index 64845ac81b79..aecbe9b9df4c 100644
> --- a/mm/slab_common.c
> +++ b/mm/slab_common.c
> @@ -1325,11 +1325,11 @@ EXPORT_SYMBOL_GPL(kfree_call_rcu_nolock);
> =20
>  #ifndef CONFIG_KVFREE_RCU_BATCHED
> =20
> -void kvfree_call_rcu(struct rcu_head *head, void *ptr)
> +void kvfree_call_rcu(struct kvfree_rcu_head *head, void *ptr)
>  {
>  	if (head) {
>  		kasan_record_aux_stack(ptr);
> -		call_rcu(head, kvfree_rcu_cb);
> +		call_rcu(&head->head, kvfree_rcu_cb);
>  		return;
>  	}
> =20
> diff --git a/rust/kernel/sync/poll.rs b/rust/kernel/sync/poll.rs
> index 684dfa242b1a..f3cdf95db12d 100644
> --- a/rust/kernel/sync/poll.rs
> +++ b/rust/kernel/sync/poll.rs
> @@ -124,7 +124,7 @@ pub struct PollCondVarBox {
>  struct PollCondVarBoxInner {
>      #[pin]
>      inner: PollCondVar,
> -    rcu: Opaque<bindings::callback_head>,
> +    rcu: Opaque<bindings::kvfree_rcu_head>,
>  }
> =20
>  // SAFETY: PollCondVar is Send