Skip to contentSkip to conversation

rust: helpers: guard dma_resv helpers with CONFIG_DMA_SHARED_BUFFER

PATCH In review Andreas Hindborg 2 participants 2 messages Jul 8 – Jul 11

Subsystems (4)
lore
Share & tools
lore

Andreas Hindborg

author reviewer
#0 lore raw

PATCH 1/1 rust: helpers: guard dma_resv helpers with CONFIG_DMA_SHARED_BUFFER

Commit 9b836641d3bf ("rust: helpers: Add bindings/wrappers for dma_resv_lock") added rust_helper_dma_resv_lock() and rust_helper_dma_resv_unlock() unconditionally. However, the dma-resv functionality is only available when CONFIG_DMA_SHARED_BUFFER is enabled, resulting in the following link error when it is not:

LD .tmp_vmlinux1
ld.lld: error: undefined symbol: dma_resv_reset_max_fences >>> referenced by dma-resv.h:463
>>> rust/helpers/helpers.o:(rust_helper_dma_resv_unlock) in archive vmlinux.a

The dma_resv_unlock() inline in <linux/dma-resv.h> calls dma_resv_reset_max_fences(), which is only compiled into drivers/dma-buf/dma-resv.c when CONFIG_DMA_SHARED_BUFFER is set. With the option disabled the symbol is never defined, so the helper fails to link.

Fix this by guarding the helper definitions with #ifdef CONFIG_DMA_SHARED_BUFFER.

The only user of this helper is the DRM shmem abstractions, which already depend on CONFIG_DMA_SHARED_BUFFER.

Fixes 9b836641d3bf ("rust: helpers: Add bindings/wrappers for dma_resv_lock")
---
 rust/helpers/dma-resv.c | 4 ++++
 1 file changed, 4 insertions(+)
rust/helpers/dma-resv.c +4 -0
index 71914d8241e2..1698092b9317 100644
@@ -1,5 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 
+#ifdef CONFIG_DMA_SHARED_BUFFER
+
 #include <linux/dma-resv.h>
 
 __rust_helper
@@ -12,3 +14,5 @@ __rust_helper void rust_helper_dma_resv_unlock(struct dma_resv *obj)
 {
 	dma_resv_unlock(obj);
 }
+
+#endif

---
base-commit: dc59e4fea9d83f03bad6bddf3fa2e52491777482
change-id: 20260708-dma-shared-buffer-config-bb135fdb61f4

Best regards,

Signature · 1 line
Andreas Hindborg <[email protected]>
#1 lore raw
Quoted 21 lines · Andreas Hindborg

Commit 9b836641d3bf ("rust: helpers: Add bindings/wrappers for dma_resv_lock") added rust_helper_dma_resv_lock() and rust_helper_dma_resv_unlock() unconditionally. However, the dma-resv functionality is only available when CONFIG_DMA_SHARED_BUFFER is enabled, resulting in the following link error when it is not:

LD .tmp_vmlinux1
ld.lld: error: undefined symbol: dma_resv_reset_max_fences >>> referenced by dma-resv.h:463
>>> rust/helpers/helpers.o:(rust_helper_dma_resv_unlock) in archive vmlinux.a

The dma_resv_unlock() inline in <linux/dma-resv.h> calls dma_resv_reset_max_fences(), which is only compiled into drivers/dma-buf/dma-resv.c when CONFIG_DMA_SHARED_BUFFER is set. With the option disabled the symbol is never defined, so the helper fails to link.

Fix this by guarding the helper definitions with #ifdef CONFIG_DMA_SHARED_BUFFER.

Quoted 6 lines

The only user of this helper is the DRM shmem abstractions, which already depend on CONFIG_DMA_SHARED_BUFFER.

Fixes 9b836641d3bf ("rust: helpers: Add bindings/wrappers for dma_resv_lock")

Please see:

https://lore.kernel.org/rust-for-linux/[email protected]/

Cheers,
Miguel