Re: rust compile failure in next-20260730

From: Gary Guo

Date: Mon Aug 03 2026 - 11:49:30 EST


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:
>>>
>>> We could also unconditionally use `kvfree_rcu_head` here, and
>>> add
>>>
>>> #[cfg(not(CONFIG_KVFREE_RCU_BATCHED))]
>>> pub type kvfree_rcu_head = callback_head;
>>>
>>> to bindings.rs?
>>>
>>
>> This option is currently not maintainable unless it becomes a
>> maintainer-aware way to handle things like this.
>>
>>> (Or even better, changing `#define` to `typedef` so bindgen takes care of
>>> everything).
>>>
>>
>> Yes, this is better IMO, but it's up to slab maintainers. :-)
>
> Can you elaborate a bit please, how would that look like?

I was thinking of doing `typedef struct rcu_head kvfree_rcu_head;` but of course
that didn't work because you can't use typedef to create `kvfree_rcu_head` :)

However, something like this could work?

#ifdef CONFIG_KVFREE_RCU_BATCHED
...
#else
struct kvfree_rcu_head {
struct rcu_head head;
};
#endif

and everywhere add a cast everywhere that expects kvfree_rcu_head == rcu_head.

but this would indeed be more complex :(

It's a bit unfortunate that C doesn't have a better way of doing struct type
aliases without doing textual replacement with macro.

Another approach is to have:

#ifdef __BINDGEN__
typedef struct rcu_head kvfree_rcu_head;
#endif
#define kvfree_rcu_head rcu_head

so bindgen can still see the typedef while it doesn't have effect for C users.
But this doesn't look perfect either.

Best,
Gary