[RFC 1/4] nvme: move dma-buf I/O context handling to nvme-core
Anuj Gupta
anuj20.g at samsung.com
Wed Nov 18 02:33:24 PST 2026
From: Nitesh Shetty <nj.shetty at samsung.com>
The dma-buf I/O context handling in pci-dmabuf.c is not specific to
PCI. Move it to nvme-core so it can be shared by other transports.
Keep the PCI-specific PRP and SGL construction in pci.c.
No functional change.
Signed-off-by: Nitesh Shetty <nj.shetty at samsung.com>
Signed-off-by: Anuj Gupta <anuj20.g at samsung.com>
---
drivers/nvme/host/Makefile | 2 +-
drivers/nvme/host/{pci-dmabuf.c => dmabuf.c} | 12 ++++++++----
drivers/nvme/host/{pci-dmabuf.h => dmabuf.h} | 12 ++++++------
drivers/nvme/host/pci.c | 5 ++---
4 files changed, 17 insertions(+), 14 deletions(-)
rename drivers/nvme/host/{pci-dmabuf.c => dmabuf.c} (92%)
rename drivers/nvme/host/{pci-dmabuf.h => dmabuf.h} (85%)
diff --git a/drivers/nvme/host/Makefile b/drivers/nvme/host/Makefile
index 8288b986d713..5082a2788b31 100644
--- a/drivers/nvme/host/Makefile
+++ b/drivers/nvme/host/Makefile
@@ -19,9 +19,9 @@ nvme-core-$(CONFIG_BLK_DEV_ZONED) += zns.o
nvme-core-$(CONFIG_FAULT_INJECTION_DEBUG_FS) += fault_inject.o
nvme-core-$(CONFIG_NVME_HWMON) += hwmon.o
nvme-core-$(CONFIG_NVME_HOST_AUTH) += auth.o
+nvme-core-$(CONFIG_DMA_SHARED_BUFFER) += dmabuf.o
nvme-y += pci.o
-nvme-$(CONFIG_DMA_SHARED_BUFFER) += pci-dmabuf.o
nvme-fabrics-y += fabrics.o
diff --git a/drivers/nvme/host/pci-dmabuf.c b/drivers/nvme/host/dmabuf.c
similarity index 92%
rename from drivers/nvme/host/pci-dmabuf.c
rename to drivers/nvme/host/dmabuf.c
index 161e4ffa6919..1f9104a5d75e 100644
--- a/drivers/nvme/host/pci-dmabuf.c
+++ b/drivers/nvme/host/dmabuf.c
@@ -1,12 +1,12 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
- * Code for supporting dma-buf I/O maps in the NVMe driver.
+ * Code for supporting dma-buf I/O maps in the NVMe host drivers.
* Copyright (C) 2026 Pavel Begunkov <asml.silence at gmail.com>
*/
#include <linux/dma-resv.h>
-#include "pci-dmabuf.h"
+#include "dmabuf.h"
static void nvme_dmabuf_invalidate_mappings(struct dma_buf_attachment *attach)
{
@@ -104,7 +104,7 @@ static void nvme_dma_buf_io_release(struct dma_buf_io_ctx *base_ctx)
kfree(ctx);
}
-void __nvme_pci_remove_dmabuf(struct nvme_dma_buf_list *list)
+void __nvme_remove_dmabufs(struct nvme_dma_buf_list *list)
{
struct nvme_dma_buf_io_ctx *ctx, *tmp;
@@ -117,8 +117,9 @@ void __nvme_pci_remove_dmabuf(struct nvme_dma_buf_list *list)
}
mutex_unlock(&list->lock);
}
+EXPORT_SYMBOL_GPL(__nvme_remove_dmabufs);
-const struct dma_buf_io_ops nvme_dma_buf_io_ops = {
+static const struct dma_buf_io_ops nvme_dma_buf_io_ops = {
.map = nvme_dma_buf_io_map,
.unmap = nvme_dma_buf_io_unmap,
.release = nvme_dma_buf_io_release,
@@ -167,3 +168,6 @@ int __nvme_init_dma_buf_io_ctx(struct nvme_ctrl *ctrl,
mutex_unlock(&buf_list->lock);
return ret;
}
+EXPORT_SYMBOL_GPL(__nvme_init_dma_buf_io_ctx);
+
+MODULE_IMPORT_NS("DMA_BUF");
diff --git a/drivers/nvme/host/pci-dmabuf.h b/drivers/nvme/host/dmabuf.h
similarity index 85%
rename from drivers/nvme/host/pci-dmabuf.h
rename to drivers/nvme/host/dmabuf.h
index b3c9fd485878..08a5b8e5d771 100644
--- a/drivers/nvme/host/pci-dmabuf.h
+++ b/drivers/nvme/host/dmabuf.h
@@ -3,8 +3,8 @@
* Copyright (C) 2026 Pavel Begunkov <asml.silence at gmail.com>
*/
-#ifndef _NVME_PCI_DMABUF_H
-#define _NVME_PCI_DMABUF_H
+#ifndef _NVME_DMABUF_H
+#define _NVME_DMABUF_H
#include <linux/dma-buf-io.h>
@@ -44,15 +44,15 @@ static inline struct nvme_dmabuf_map *nvme_req_to_map(struct request *req)
return to_nvme_dmabuf_map(map);
}
-void __nvme_pci_remove_dmabuf(struct nvme_dma_buf_list *list);
+void __nvme_remove_dmabufs(struct nvme_dma_buf_list *list);
int __nvme_init_dma_buf_io_ctx(struct nvme_ctrl *ctrl,
struct nvme_dma_buf_list *buf_list,
struct dma_buf_io_ctx *ctx);
-static inline void nvme_pci_remove_dmabuf(struct nvme_dma_buf_list *list)
+static inline void nvme_remove_dmabufs(struct nvme_dma_buf_list *list)
{
if (IS_ENABLED(CONFIG_DMA_SHARED_BUFFER))
- __nvme_pci_remove_dmabuf(list);
+ __nvme_remove_dmabufs(list);
}
static inline int nvme_init_dma_buf_io_ctx(struct nvme_ctrl *ctrl,
@@ -72,4 +72,4 @@ static inline void nvme_init_buf_list(struct nvme_dma_buf_list *buf_list)
}
-#endif /* _NVME_PCI_DMABUF_H */
\ No newline at end of file
+#endif /* _NVME_DMABUF_H */
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 076603df01ab..1af356abde0b 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -30,7 +30,7 @@
#include "trace.h"
#include "nvme.h"
-#include "pci-dmabuf.h"
+#include "dmabuf.h"
#define SQ_SIZE(q) ((q)->q_depth << (q)->sqes)
#define CQ_SIZE(q) ((q)->q_depth * sizeof(struct nvme_completion))
@@ -4129,7 +4129,7 @@ static void nvme_remove(struct pci_dev *pdev)
nvme_stop_ctrl(&dev->ctrl);
nvme_remove_namespaces(&dev->ctrl);
nvme_dev_disable(dev, true);
- nvme_pci_remove_dmabuf(&dev->dmabufs);
+ nvme_remove_dmabufs(&dev->dmabufs);
nvme_free_host_mem(dev);
nvme_dev_remove_admin(dev);
nvme_dbbuf_dma_free(dev);
@@ -4571,6 +4571,5 @@ MODULE_AUTHOR("Matthew Wilcox <willy at linux.intel.com>");
MODULE_LICENSE("GPL");
MODULE_VERSION("1.0");
MODULE_DESCRIPTION("NVMe host PCIe transport driver");
-MODULE_IMPORT_NS("DMA_BUF");
module_init(nvme_init);
module_exit(nvme_exit);
--
2.25.1
More information about the Linux-nvme
mailing list