Skip to contentSkip to conversation

iommufd: fix building without dmabuf

PATCH In review Arnd Bergmann 3 participants 4 messages Dec 4, 2025 – Dec 5, 2025

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

PATCH 1/1 iommufd: fix building without dmabuf

From: Arnd Bergmann <[email protected]>

When DMABUF is disabled, trying to use it causes a link failure:

x86_64-linux-ld: drivers/iommu/iommufd/io_pagetable.o: in function `iopt_map_file_pages':
io_pagetable.c:(.text+0x1735): undefined reference to `dma_buf_get'
x86_64-linux-ld: io_pagetable.c:(.text+0x1775): undefined reference to `dma_buf_put'

Fixes 44ebaa1744fd ("iommufd: Accept a DMABUF through IOMMU_IOAS_MAP_FILE")
---
 drivers/iommu/iommufd/io_pagetable.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iommu/iommufd/io_pagetable.c +5 -1
index 54cf4d856179..d22e86de03e9 100644
@@ -495,7 +495,11 @@ int iopt_map_file_pages(struct iommufd_ctx *ictx, struct io_pagetable *iopt,
 		return -EOVERFLOW;
 
 	start_byte = start - ALIGN_DOWN(start, PAGE_SIZE);
-	dmabuf = dma_buf_get(fd);
+	if (IS_ENABLED(CONFIG_DMABUF_HEAPS))
+		dmabuf = dma_buf_get(fd);
+	else
+		dmabuf = ERR_PTR(-ENXIO);
+
 	if (!IS_ERR(dmabuf)) {
 		pages = iopt_alloc_dmabuf_pages(ictx, dmabuf, start_byte, start,
 						length,
Signature · 1 line
2.39.5
#1 lore raw
Quoted 19 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

When DMABUF is disabled, trying to use it causes a link failure:

x86_64-linux-ld: drivers/iommu/iommufd/io_pagetable.o: in function `iopt_map_file_pages':
io_pagetable.c:(.text+0x1735): undefined reference to `dma_buf_get'
x86_64-linux-ld: io_pagetable.c:(.text+0x1775): undefined reference to `dma_buf_put'

Fixes 44ebaa1744fd ("iommufd: Accept a DMABUF through IOMMU_IOAS_MAP_FILE")
---
 drivers/iommu/iommufd/io_pagetable.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/iommu/iommufd/io_pagetable.c +0 -0
index 54cf4d856179..d22e86de03e9 100644

drivers/iommu/iommufd/io_pagetable.c int iopt_map_file_pages(struct iommufd_ctx *ictx, struct io_pagetable *iopt, · line 501

Quoted 8 lines
drivers/iommu/iommufd/io_pagetable.c +4 -1
@@ -495,7 +495,11 @@ int iopt_map_file_pages(struct iommufd_ctx *ictx, struct io_pagetable *iopt,
 		return -EOVERFLOW;
 
 	start_byte = start - ALIGN_DOWN(start, PAGE_SIZE);
-	dmabuf = dma_buf_get(fd);
+	if (IS_ENABLED(CONFIG_DMABUF_HEAPS))
+		dmabuf = dma_buf_get(fd);
+	else
+		dmabuf = ERR_PTR(-ENXIO);

Shouldn't this be fixed in include/linux/dma-buf.h with a stub always fail inline?

Jason

#2 lore raw
In reply to Arnd Bergmann
Quoted 8 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

When DMABUF is disabled, trying to use it causes a link failure:

x86_64-linux-ld: drivers/iommu/iommufd/io_pagetable.o: in function `iopt_map_file_pages':
io_pagetable.c:(.text+0x1735): undefined reference to `dma_buf_get'
x86_64-linux-ld: io_pagetable.c:(.text+0x1775): undefined reference to `dma_buf_put'

Quoted 5 lines
Fixes 44ebaa1744fd ("iommufd: Accept a DMABUF through IOMMU_IOAS_MAP_FILE")
---
 drivers/iommu/iommufd/io_pagetable.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

I picked this up anyhow since it looked like adding #ifdef stubs to dma_buf.h was going to be a bigger thing

drivers/iommu/iommufd/io_pagetable.c int iopt_map_file_pages(struct iommufd_ctx *ictx, struct io_pagetable *iopt, · line 499

Quoted 2 lines
drivers/iommu/iommufd/io_pagetable.c +2 -0
+	if (IS_ENABLED(CONFIG_DMABUF_HEAPS))
+		dmabuf = dma_buf_get(fd);

But this needs to be:

	if (IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
		dmabuf = dma_buf_get(fd);

I fixed it

Thanks,
Jason

#3 lore raw
Quoted 9 lines · Jason Gunthorpe

I picked this up anyhow since it looked like adding #ifdef stubs to dma_buf.h was going to be a bigger thing

drivers/iommu/iommufd/io_pagetable.c int iopt_map_file_pages(struct iommufd_ctx *ictx, struct io_pagetable *iopt, · line 499

Quoted 2 lines
drivers/iommu/iommufd/io_pagetable.c +2 -0
+	if (IS_ENABLED(CONFIG_DMABUF_HEAPS))
+		dmabuf = dma_buf_get(fd);

But this needs to be:

Quoted 4 lines
	if (IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
		dmabuf = dma_buf_get(fd);

I fixed it

Ok, thanks a lot!

Arnd