Skip to contentSkip to conversation

rust: alloc: add ARCH_KMALLOC_MINALIGN to bindgen blocklist

PATCH Applied Danilo Krummrich 3 participants 4 messages Aug 18, 2025 – Aug 19, 2025

Subsystems (2)
lore
Share & tools
lore

Danilo Krummrich

author reviewer
#0 lore raw

PATCH 1/1 rust: alloc: add ARCH_KMALLOC_MINALIGN to bindgen blocklist

For some architectures, such as X86_64, ARCH_KMALLOC_MINALIGN is not resolvable for bindgen. E.g. due to being defined as __alignof__(unsigned long long).

Hence, we have to create a rust helper, i.e. let the C compiler evaluate the expression and store it in a const.

However, if for other architectures, such as arm64, ARCH_KMALLOC_MINALIGN does evaluate to something that can be directly processed by bindgen, we end up with multiple definitions of ARCH_KMALLOC_MINALIGN in the generated bindings.

	error[E0428]: the name `ARCH_KMALLOC_MINALIGN` is defined multiple times
	      --> /builddir/build/BUILD/kernel-6.17.0-build/kernel-next-20250818/linux-6.17.0-0.0.next.20250818.423.vanilla.fc44.aarch64/rust/bindings/bindings_generated.rs:134545:1
	       |
	9622   | pub const ARCH_KMALLOC_MINALIGN: u32 = 8;
	       | ----------------------------------------- previous definition of the value `ARCH_KMALLOC_MINALIGN` here
	...
	134545 | pub const ARCH_KMALLOC_MINALIGN: usize = 8;
	       | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ARCH_KMALLOC_MINALIGN` redefined here
	       |
	       = note: `ARCH_KMALLOC_MINALIGN` must be defined only once in the value namespace of this module

To fix this up, add ARCH_KMALLOC_MINALIGN to the blocklist of bindgen, such that we always only generate the symbol from the rust helper.

Fixes 1b1a946dc2b5 ("rust: alloc: specify the minimum alignment of each allocator")
---
 rust/bindgen_parameters | 1 +
 1 file changed, 1 insertion(+)
rust/bindgen_parameters +1 -0
index 0f96af8b9a7f..02b371b98b39 100644
@@ -34,3 +34,4 @@
 # We use const helpers to aid bindgen, to avoid conflicts when constants are
 # recognized, block generation of the non-helper constants.
 --blocklist-item ARCH_SLAB_MINALIGN
+--blocklist-item ARCH_KMALLOC_MINALIGN

base-commit: 7e25d84f460c59322bf01dfeb1fb4745b488f714

Signature · 1 line
2.50.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 24 lines · Danilo Krummrich

For some architectures, such as X86_64, ARCH_KMALLOC_MINALIGN is not resolvable for bindgen. E.g. due to being defined as __alignof__(unsigned long long).

Hence, we have to create a rust helper, i.e. let the C compiler evaluate the expression and store it in a const.

However, if for other architectures, such as arm64, ARCH_KMALLOC_MINALIGN does evaluate to something that can be directly processed by bindgen, we end up with multiple definitions of ARCH_KMALLOC_MINALIGN in the generated bindings.

        error[E0428]: the name `ARCH_KMALLOC_MINALIGN` is defined multiple times
              --> /builddir/build/BUILD/kernel-6.17.0-build/kernel-next-20250818/linux-6.17.0-0.0.next.20250818.423.vanilla.fc44.aarch64/rust/bindings/bindings_generated.rs:134545:1
               |
        9622   | pub const ARCH_KMALLOC_MINALIGN: u32 = 8;
               | ----------------------------------------- previous definition of the value `ARCH_KMALLOC_MINALIGN` here
        ...
        134545 | pub const ARCH_KMALLOC_MINALIGN: usize = 8;
               | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ARCH_KMALLOC_MINALIGN` redefined here
               |
               = note: `ARCH_KMALLOC_MINALIGN` must be defined only once in the value namespace of this module
Quoted 7 lines

To fix this up, add ARCH_KMALLOC_MINALIGN to the blocklist of bindgen, such that we always only generate the symbol from the rust helper.

Fixes 1b1a946dc2b5 ("rust: alloc: specify the minimum alignment of each allocator")
Tested-by on v1 1/1
#2 lore raw
In reply to Danilo Krummrich
Quoted 4 lines · Danilo Krummrich

For some architectures, such as X86_64, ARCH_KMALLOC_MINALIGN is not resolvable for bindgen. E.g. due to being defined as __alignof__(unsigned long long).

Quoted 8 lines

Hence, we have to create a rust helper, i.e. let the C compiler evaluate the expression and store it in a const.

However, if for other architectures, such as arm64, ARCH_KMALLOC_MINALIGN does evaluate to something that can be directly processed by bindgen, we end up with multiple definitions of ARCH_KMALLOC_MINALIGN in the generated bindings.
[...]

Thx, applied it on today's -next and everything went smoothly:

Ciao, Thorsten

author reviewer Applied
#3 lore raw
In reply to Danilo Krummrich
Quoted 23 lines · Danilo Krummrich

For some architectures, such as X86_64, ARCH_KMALLOC_MINALIGN is not resolvable for bindgen. E.g. due to being defined as __alignof__(unsigned long long).

Hence, we have to create a rust helper, i.e. let the C compiler evaluate the expression and store it in a const.

However, if for other architectures, such as arm64, ARCH_KMALLOC_MINALIGN does evaluate to something that can be directly processed by bindgen, we end up with multiple definitions of ARCH_KMALLOC_MINALIGN in the generated bindings.

	error[E0428]: the name `ARCH_KMALLOC_MINALIGN` is defined multiple times
	      --> /builddir/build/BUILD/kernel-6.17.0-build/kernel-next-20250818/linux-6.17.0-0.0.next.20250818.423.vanilla.fc44.aarch64/rust/bindings/bindings_generated.rs:134545:1
	       |
	9622   | pub const ARCH_KMALLOC_MINALIGN: u32 = 8;
	       | ----------------------------------------- previous definition of the value `ARCH_KMALLOC_MINALIGN` here
	...
	134545 | pub const ARCH_KMALLOC_MINALIGN: usize = 8;
	       | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `ARCH_KMALLOC_MINALIGN` redefined here
	       |
	       = note: `ARCH_KMALLOC_MINALIGN` must be defined only once in the value namespace of this module
Quoted 7 lines

To fix this up, add ARCH_KMALLOC_MINALIGN to the blocklist of bindgen, such that we always only generate the symbol from the rust helper.

Fixes 1b1a946dc2b5 ("rust: alloc: specify the minimum alignment of each allocator")

Applied to alloc-next, thanks!