Skip to contentSkip to conversation

rust: helpers: add is_vmalloc_addr wrapper for NOMMU builds

PATCH Applied Shivam Kalra 4 participants 5 messages May 22 – May 28

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: helpers: add is_vmalloc_addr wrapper for NOMMU builds

Commit 47ac2a4b5cd8 ("rust: kvec: implement shrink_to for KVVec") introduced a call to bindings::is_vmalloc_addr(). However, this fails to compile on architectures where CONFIG_MMU is disabled, resulting in the following build error:

error[E0425]: cannot find function is_vmalloc_addr in crate bindings

When CONFIG_MMU is not set, is_vmalloc_addr() is defined as a static inline function in <linux/mm.h> that unconditionally returns false. Because bindgen skips static inline functions when generating bindings, the symbol is completely missing from the Rust bindings crate.

Fix this by providing a C helper wrapper, rust_helper_is_vmalloc_addr(), in rust/helpers/vmalloc.c. This ensures the function is reliably exposed to Rust regardless of the MMU configuration. On NOMMU builds, this allows KVVec::shrink_to() to successfully compile and correctly route all allocations through the kmalloc realloc path.

Fixes 47ac2a4b5cd8 ("rust: kvec: implement shrink_to for KVVec")
---
 rust/helpers/vmalloc.c | 6 ++++++
 1 file changed, 6 insertions(+)
rust/helpers/vmalloc.c +6 -0
index 326b030487a2..6aed13292313 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 
+#include <linux/mm.h>
 #include <linux/vmalloc.h>
 
 __rust_helper void *__must_check __realloc_size(2)
@@ -8,3 +9,8 @@ rust_helper_vrealloc_node_align(const void *p, size_t size, unsigned long align,
 {
 	return vrealloc_node_align(p, size, align, flags, node);
 }
+
+__rust_helper bool rust_helper_is_vmalloc_addr(const void *x)
+{
+	return is_vmalloc_addr(x);
+}

---
base-commit: 6779b50faa562e6cca1aa6a4649a4d764c6c7e28
change-id: 20260522-is-vmalloc-addr-build-fix-abc614b17877

Best regards,

Signature · 1 line
Shivam Kalra <[email protected]>
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 22 lines · On Fri, May 22, 2026 at 8:54 PM Shivam Kalra via B4 Relay…

From: Shivam Kalra <[email protected]>

Commit 47ac2a4b5cd8 ("rust: kvec: implement shrink_to for KVVec") introduced a call to bindings::is_vmalloc_addr(). However, this fails to compile on architectures where CONFIG_MMU is disabled, resulting in the following build error:

error[E0425]: cannot find function is_vmalloc_addr in crate bindings

When CONFIG_MMU is not set, is_vmalloc_addr() is defined as a static inline function in <linux/mm.h> that unconditionally returns false. Because bindgen skips static inline functions when generating bindings, the symbol is completely missing from the Rust bindings crate.

Fix this by providing a C helper wrapper, rust_helper_is_vmalloc_addr(), in rust/helpers/vmalloc.c. This ensures the function is reliably exposed to Rust regardless of the MMU configuration. On NOMMU builds, this allows KVVec::shrink_to() to successfully compile and correctly route all allocations through the kmalloc realloc path.

Quoted 4 lines
Fixes 47ac2a4b5cd8 ("rust: kvec: implement shrink_to for KVVec")
#2 lore raw
In reply to Shivam Kalra
Quoted 22 lines · On Fri, May 22, 2026 at 8:54 PM Shivam Kalra via B4 Relay…

From: Shivam Kalra <[email protected]>

Commit 47ac2a4b5cd8 ("rust: kvec: implement shrink_to for KVVec") introduced a call to bindings::is_vmalloc_addr(). However, this fails to compile on architectures where CONFIG_MMU is disabled, resulting in the following build error:

error[E0425]: cannot find function is_vmalloc_addr in crate bindings

When CONFIG_MMU is not set, is_vmalloc_addr() is defined as a static inline function in <linux/mm.h> that unconditionally returns false. Because bindgen skips static inline functions when generating bindings, the symbol is completely missing from the Rust bindings crate.

Fix this by providing a C helper wrapper, rust_helper_is_vmalloc_addr(), in rust/helpers/vmalloc.c. This ensures the function is reliably exposed to Rust regardless of the MMU configuration. On NOMMU builds, this allows KVVec::shrink_to() to successfully compile and correctly route all allocations through the kmalloc realloc path.

Quoted 4 lines
Fixes 47ac2a4b5cd8 ("rust: kvec: implement shrink_to for KVVec")

I can take this in my rust-fixes PR unless mm/akpm plans to do so.

Cc'ing akpm, Lorenzo, Liam and linux-mm, by the way.

Thanks!

Cheers,
Miguel

reviewer Reviewed-by on v1 1/1
#3 lore raw
In reply to Shivam Kalra
Quoted 21 lines · On 5/22/26 8:54 PM, Shivam Kalra via B4 Relay wrote:

From: Shivam Kalra <[email protected]>

Commit 47ac2a4b5cd8 ("rust: kvec: implement shrink_to for KVVec") introduced a call to bindings::is_vmalloc_addr(). However, this fails to compile on architectures where CONFIG_MMU is disabled, resulting in the following build error:

error[E0425]: cannot find function is_vmalloc_addr in crate bindings

When CONFIG_MMU is not set, is_vmalloc_addr() is defined as a static inline function in <linux/mm.h> that unconditionally returns false. Because bindgen skips static inline functions when generating bindings, the symbol is completely missing from the Rust bindings crate.

Fix this by providing a C helper wrapper, rust_helper_is_vmalloc_addr(), in rust/helpers/vmalloc.c. This ensures the function is reliably exposed to Rust regardless of the MMU configuration. On NOMMU builds, this allows KVVec::shrink_to() to successfully compile and correctly route all allocations through the kmalloc realloc path.

Quoted 4 lines
Fixes 47ac2a4b5cd8 ("rust: kvec: implement shrink_to for KVVec")
Applied
#4 lore raw
In reply to Shivam Kalra
Quoted 22 lines · On Fri, May 22, 2026 at 8:54 PM Shivam Kalra via B4 Relay…

From: Shivam Kalra <[email protected]>

Commit 47ac2a4b5cd8 ("rust: kvec: implement shrink_to for KVVec") introduced a call to bindings::is_vmalloc_addr(). However, this fails to compile on architectures where CONFIG_MMU is disabled, resulting in the following build error:

error[E0425]: cannot find function is_vmalloc_addr in crate bindings

When CONFIG_MMU is not set, is_vmalloc_addr() is defined as a static inline function in <linux/mm.h> that unconditionally returns false. Because bindgen skips static inline functions when generating bindings, the symbol is completely missing from the Rust bindings crate.

Fix this by providing a C helper wrapper, rust_helper_is_vmalloc_addr(), in rust/helpers/vmalloc.c. This ensures the function is reliably exposed to Rust regardless of the MMU configuration. On NOMMU builds, this allows KVVec::shrink_to() to successfully compile and correctly route all allocations through the kmalloc realloc path.

Quoted 4 lines
Fixes 47ac2a4b5cd8 ("rust: kvec: implement shrink_to for KVVec")

Applied to rust-fixes -- thanks everyone!

[ Pasted exact compiler output and expanded it. - Miguel ]

The compiler output did not seem to be an exact copy paste for some reason (at least from my testing when reproducing the issue), so I updated the compiler output.

Cheers,
Miguel