Skip to contentSkip to conversation

support dmabuf

PATCH Superseded Cliff Burdick 5 participants 29 messages Jan 27 – Oct 6

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

cover support dmabuf

Add support for kernel dmabuf feature and integrate it in the mlx5 driver. This feature is needed to support GPUDirect on newer kernels.

Cliff Burdick (2):
eal: support dmabuf
common/mlx5: support dmabuf

 .mailmap                                      |   1 +
 drivers/common/mlx5/linux/meson.build         |   2 +
 drivers/common/mlx5/linux/mlx5_common_verbs.c |  48 ++++-
 drivers/common/mlx5/linux/mlx5_glue.c         |  19 ++
 drivers/common/mlx5/linux/mlx5_glue.h         |   3 +
 drivers/common/mlx5/mlx5_common.c             |  28 ++-
 drivers/common/mlx5/mlx5_common_mr.c          | 108 ++++++++++-
 drivers/common/mlx5/mlx5_common_mr.h          |  17 +-
 drivers/common/mlx5/windows/mlx5_common_os.c  |   8 +-
 drivers/crypto/mlx5/mlx5_crypto.h             |   1 +
 drivers/crypto/mlx5/mlx5_crypto_gcm.c         |   3 +-
 lib/eal/common/eal_common_memory.c            | 168 ++++++++++++++++++
 lib/eal/common/eal_memalloc.h                 |  21 +++
 lib/eal/common/malloc_heap.c                  |  27 +++
 lib/eal/common/malloc_heap.h                  |   5 +
 lib/eal/include/rte_memory.h                  | 125 +++++++++++++
 16 files changed, 576 insertions(+), 8 deletions(-)
Signature · 1 line
2.52.0
#1 lore raw

PATCH 1/2 eal: support dmabuf

dmabuf is a modern Linux kernel feature to allow DMA transfers between two drivers. Common examples of usage are streaming video devices and NIC to GPU transfers. Prior to dmabuf users had to load proprietary drivers to expose the DMA mappings. With dmabuf the proprietary drivers are no longer required.

A new api function rte_extmem_register_dmabuf is introduced to create the mapping from a dmabuf file descriptor. dmabuf uses a file descriptor and an offset that has been pre-opened with the kernel. The kernel uses the file descriptor to map to a VA pointer. To avoid ABI changes, a static struct is used inside of eal_common_memory.c, and lookups are done on this struct rather than from the rte_memseg_list.

Ideally we would like to add both the dmabuf file descriptor and offset to rte_memseg_list, but it's not clear if we can reuse existing fields when using the dmabuf API.

We could rename the external flag to a more generic "properties" flag where "external" is the lowest bit, then we can use the second bit to indicate the presence of dmabuf. In the presence of the flag for dmabuf we could reuse the base_va address field for the dmabuf offset, and the socket_id for the file descriptor.

Which option is preferred?

---
 .mailmap                           |   1 +
 lib/eal/common/eal_common_memory.c | 168 +++++++++++++++++++++++++++++
 lib/eal/common/eal_memalloc.h      |  21 ++++
 lib/eal/common/malloc_heap.c       |  27 +++++
 lib/eal/common/malloc_heap.h       |   5 +
 lib/eal/include/rte_memory.h       | 125 +++++++++++++++++++++
 6 files changed, 347 insertions(+)
.mailmap +1 -0
index 2f089326ff..4c2b2f921d 100644
@@ -291,6 +291,7 @@ Cian Ferriter <[email protected]>
 Ciara Loftus <[email protected]>
 Ciara Power <[email protected]>
 Claire Murphy <[email protected]>
+Cliff Burdick <[email protected]>
 Clemens Famulla-Conrad <[email protected]>
 Cody Doucette <[email protected]>
 Congwen Zhang <[email protected]>
lib/eal/common/eal_common_memory.c +168 -0

186 lines not on this page · raw message

lib/eal/common/eal_memalloc.h +21 -0
index 0c267066d9..bb2cfa0717 100644
@@ -90,6 +90,27 @@ eal_memalloc_set_seg_list_fd(int list_idx, int fd);
 int
 eal_memalloc_get_seg_fd_offset(int list_idx, int seg_idx, size_t *offset);
 
+/*
+ * Set dmabuf info for a memseg list.
+ * Returns 0 on success, -errno on failure.
+ */
+int
+eal_memseg_list_set_dmabuf_info(int list_idx, int fd, uint64_t offset);
+
+/*
+ * Get dmabuf fd for a memseg list.
+ * Returns fd (>= 0) on success, -1 if not dmabuf backed, -errno on error.
+ */
+int
+eal_memseg_list_get_dmabuf_fd(int list_idx);
+
+/*
+ * Get dmabuf offset for a memseg list.
+ * Returns 0 on success, -errno on failure.
+ */
+int
+eal_memseg_list_get_dmabuf_offset(int list_idx, uint64_t *offset);
+
 int
 eal_memalloc_init(void)
 	__rte_requires_shared_capability(rte_mcfg_mem_get_lock());
lib/eal/common/malloc_heap.c +27 -0
index 39240c261c..fd0376d13b 100644
@@ -1232,6 +1232,33 @@ malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[],
 	msl->version = 0;
 	msl->external = 1;
 
+	/* initialize dmabuf info to "not dmabuf backed" */
+	eal_memseg_list_set_dmabuf_info(i, -1, 0);
+
+	return msl;
+}
+
+struct rte_memseg_list *
+malloc_heap_create_external_seg_dmabuf(void *va_addr, rte_iova_t iova_addrs[],
+		unsigned int n_pages, size_t page_sz, const char *seg_name,
+		unsigned int socket_id, int dmabuf_fd, uint64_t dmabuf_offset)
+{
+	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_memseg_list *msl;
+	int msl_idx;
+
+	/* Create the base external segment */
+	msl = malloc_heap_create_external_seg(va_addr, iova_addrs, n_pages,
+			page_sz, seg_name, socket_id);
+	if (msl == NULL)
+		return NULL;
+
+	/* Get memseg list index */
+	msl_idx = msl - mcfg->memsegs;
+
+	/* Set dma-buf info in the internal side-table */
+	eal_memseg_list_set_dmabuf_info(msl_idx, dmabuf_fd, dmabuf_offset);
+
 	return msl;
 }
 
lib/eal/common/malloc_heap.h +5 -0
index dfc56d4ae3..87525d1a68 100644
@@ -51,6 +51,11 @@ malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[],
 		unsigned int n_pages, size_t page_sz, const char *seg_name,
 		unsigned int socket_id);
 
+struct rte_memseg_list *
+malloc_heap_create_external_seg_dmabuf(void *va_addr, rte_iova_t iova_addrs[],
+		unsigned int n_pages, size_t page_sz, const char *seg_name,
+		unsigned int socket_id, int dmabuf_fd, uint64_t dmabuf_offset);
+
 struct rte_memseg_list *
 malloc_heap_find_external_seg(void *va_addr, size_t len);
 
lib/eal/include/rte_memory.h +125 -0

137 lines not on this page · raw message

Signature · 1 line
2.52.0
#2 lore raw

Re: [PATCH 1/2] eal: support dmabuf

lib/eal/common/eal_common_memory.c line 58

Quoted 6 lines · On Tue, 27 Jan 2026 17:44:08 +0000 Cliff Burdick <[email protected]> wrote:
lib/eal/common/eal_common_memory.c +6 -0
+		int fd;          /**< dmabuf fd, -1 if not dmabuf backed */
+		uint64_t offset; /**< offset within dmabuf */
+	} dmabuf_info[RTE_MAX_MEMSEG_LISTS] = {
+	[0 ... RTE_MAX_MEMSEG_LISTS - 1] = { .fd = -1, .offset = 0 }
+};
+

Range initializer are a GCC extension not available in MSVC.

#3 lore raw

Re: [PATCH 1/2] eal: support dmabuf

In reply to Cliff Burdick
Quoted 5 lines · On Tue, 27 Jan 2026 17:44:08 +0000 Cliff Burdick <[email protected]> wrote:

+/**
+ * Get dma-buf file descriptor associated with a memseg list.
+ *
+ * @note This function does not perform any locking, and is only safe to call
+ * from within memory-related callback functions.

Maybe warning instead of note.

Review

Quoted 11 lines

+ *
+ * @param msl
+ * A pointer to memseg list for which to get dma-buf fd.
+ *
+ * @return
+ * Valid dma-buf file descriptor (>= 0) in case of success.
+ * -1 if not dma-buf backed or in case of error, with ``rte_errno`` set to:
+ * - EINVAL - ``msl`` pointer was NULL or did not point to a valid memseg list
+ */

(quoted diff) +2 -0
+int
+rte_memseg_list_get_dmabuf_fd_thread_unsafe(const struct rte_memseg_list *msl);

ENAMETOOLONG

At some point, you need to come up with a better naming convention.

#4 lore raw

PATCH 2/2 common/mlx5: support dmabuf

In reply to Cliff Burdick

dmabuf is a modern Linux kernel feature to allow DMA transfers between two drivers. Common examples of usage are streaming video devices and NIC to GPU transfers. Prior to dmabuf users had to load proprietary drivers to expose the DMA mappings. With dmabuf the proprietary drivers are no longer required.

---
 drivers/common/mlx5/linux/meson.build         |   2 +
 drivers/common/mlx5/linux/mlx5_common_verbs.c |  48 +++++++-
 drivers/common/mlx5/linux/mlx5_glue.c         |  19 +++
 drivers/common/mlx5/linux/mlx5_glue.h         |   3 +
 drivers/common/mlx5/mlx5_common.c             |  28 ++++-
 drivers/common/mlx5/mlx5_common_mr.c          | 108 +++++++++++++++++-
 drivers/common/mlx5/mlx5_common_mr.h          |  17 ++-
 drivers/common/mlx5/windows/mlx5_common_os.c  |   8 +-
 drivers/crypto/mlx5/mlx5_crypto.h             |   1 +
 drivers/crypto/mlx5/mlx5_crypto_gcm.c         |   3 +-
 10 files changed, 229 insertions(+), 8 deletions(-)
drivers/common/mlx5/linux/meson.build +2 -0
index 3767e7a69b..8e83104165 100644
@@ -203,6 +203,8 @@ has_sym_args = [
             'mlx5dv_dr_domain_allow_duplicate_rules' ],
         [ 'HAVE_MLX5_IBV_REG_MR_IOVA', 'infiniband/verbs.h',
             'ibv_reg_mr_iova' ],
+        [ 'HAVE_IBV_REG_DMABUF_MR', 'infiniband/verbs.h',
+            'ibv_reg_dmabuf_mr' ],
         [ 'HAVE_MLX5_IBV_IMPORT_CTX_PD_AND_MR', 'infiniband/verbs.h',
             'ibv_import_device' ],
         [ 'HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE', 'infiniband/mlx5dv.h',
drivers/common/mlx5/linux/mlx5_common_verbs.c +47 -1

66 lines not on this page · raw message

drivers/common/mlx5/linux/mlx5_glue.c +19 -0
index a91eaa429d..6fac7f2bcd 100644
@@ -291,6 +291,24 @@ mlx5_glue_reg_mr_iova(struct ibv_pd *pd, void *addr, size_t length,
 #endif
 }
 
+static struct ibv_mr *
+mlx5_glue_reg_dmabuf_mr(struct ibv_pd *pd, uint64_t offset, size_t length,
+			uint64_t iova, int fd, int access)
+{
+#ifdef HAVE_IBV_REG_DMABUF_MR
+	return ibv_reg_dmabuf_mr(pd, offset, length, iova, fd, access);
+#else
+	(void)pd;
+	(void)offset;
+	(void)length;
+	(void)iova;
+	(void)fd;
+	(void)access;
+	errno = ENOTSUP;
+	return NULL;
+#endif
+}
+
 static struct ibv_mr *
 mlx5_glue_alloc_null_mr(struct ibv_pd *pd)
 {
@@ -1619,6 +1637,7 @@ const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue) {
 	.modify_qp = mlx5_glue_modify_qp,
 	.reg_mr = mlx5_glue_reg_mr,
 	.reg_mr_iova = mlx5_glue_reg_mr_iova,
+	.reg_dmabuf_mr = mlx5_glue_reg_dmabuf_mr,
 	.alloc_null_mr = mlx5_glue_alloc_null_mr,
 	.dereg_mr = mlx5_glue_dereg_mr,
 	.create_counter_set = mlx5_glue_create_counter_set,
drivers/common/mlx5/linux/mlx5_glue.h +3 -0
index 81d6b0aaf9..66216d1194 100644
@@ -219,6 +219,9 @@ struct mlx5_glue {
 	struct ibv_mr *(*reg_mr_iova)(struct ibv_pd *pd, void *addr,
 				      size_t length, uint64_t iova,
 				      int access);
+	struct ibv_mr *(*reg_dmabuf_mr)(struct ibv_pd *pd, uint64_t offset,
+					size_t length, uint64_t iova,
+					int fd, int access);
 	struct ibv_mr *(*alloc_null_mr)(struct ibv_pd *pd);
 	int (*dereg_mr)(struct ibv_mr *mr);
 	struct ibv_counter_set *(*create_counter_set)
drivers/common/mlx5/mlx5_common.c +26 -2
index 84a93e7dbd..0ec59b0122 100644
@@ -13,6 +13,7 @@
 #include <rte_class.h>
 #include <rte_malloc.h>
 #include <rte_eal_paging.h>
+#include <rte_memory.h>
 
 #include "mlx5_common.h"
 #include "mlx5_common_os.h"
@@ -1125,6 +1126,7 @@ mlx5_common_dev_dma_map(struct rte_device *rte_dev, void *addr,
 	struct mlx5_common_device *dev;
 	struct mlx5_mr_btree *bt;
 	struct mlx5_mr *mr;
+	struct rte_memseg_list *msl;
 
 	dev = to_mlx5_device(rte_dev);
 	if (!dev) {
@@ -1134,8 +1136,30 @@ mlx5_common_dev_dma_map(struct rte_device *rte_dev, void *addr,
 		rte_errno = ENODEV;
 		return -1;
 	}
-	mr = mlx5_create_mr_ext(dev->pd, (uintptr_t)addr, len,
-				SOCKET_ID_ANY, dev->mr_scache.reg_mr_cb);
+	/* Check if this is dma-buf backed external memory */
+	msl = rte_mem_virt2memseg_list(addr);
+	if (msl != NULL && msl->external) {
+		int dmabuf_fd = rte_memseg_list_get_dmabuf_fd_thread_unsafe(msl);
+		if (dmabuf_fd >= 0) {
+			uint64_t dmabuf_off;
+			/* Get base offset from memseg list */
+			rte_memseg_list_get_dmabuf_offset_thread_unsafe(msl, &dmabuf_off);
+			/* Calculate offset within dmabuf for this specific address */
+			dmabuf_off += ((uintptr_t)addr - (uintptr_t)msl->base_va);
+			/* Use dma-buf MR registration */
+			mr = mlx5_create_mr_ext_dmabuf(dev->pd, (uintptr_t)addr, len,
+						SOCKET_ID_ANY, dmabuf_fd, dmabuf_off,
+						dev->mr_scache.reg_dmabuf_mr_cb);
+		} else {
+			/* Use regular MR registration */
+			mr = mlx5_create_mr_ext(dev->pd, (uintptr_t)addr, len,
+						SOCKET_ID_ANY, dev->mr_scache.reg_mr_cb);
+		}
+	} else {
+		/* Use regular MR registration */
+		mr = mlx5_create_mr_ext(dev->pd, (uintptr_t)addr, len,
+					SOCKET_ID_ANY, dev->mr_scache.reg_mr_cb);
+	}
 	if (!mr) {
 		DRV_LOG(WARNING, "Device %s unable to DMA map", rte_dev->name);
 		rte_errno = EINVAL;
drivers/common/mlx5/mlx5_common_mr.c +106 -2

133 lines not on this page · raw message

drivers/common/mlx5/mlx5_common_mr.h +16 -1
index cf7c685e9b..3b967b1323 100644
@@ -35,6 +35,9 @@ struct mlx5_pmd_mr {
  */
 typedef int (*mlx5_reg_mr_t)(void *pd, void *addr, size_t length,
 			     struct mlx5_pmd_mr *pmd_mr);
+typedef int (*mlx5_reg_dmabuf_mr_t)(void *pd, uint64_t offset, size_t length,
+				    uint64_t iova, int fd,
+				    struct mlx5_pmd_mr *pmd_mr);
 typedef void (*mlx5_dereg_mr_t)(struct mlx5_pmd_mr *pmd_mr);
 
 /* Memory Region object. */
@@ -87,6 +90,7 @@ struct __rte_packed_begin mlx5_mr_share_cache {
 	struct mlx5_mr_list mr_free_list; /* Freed MR list. */
 	struct mlx5_mempool_reg_list mempool_reg_list; /* Mempool database. */
 	mlx5_reg_mr_t reg_mr_cb; /* Callback to reg_mr func */
+	mlx5_reg_dmabuf_mr_t reg_dmabuf_mr_cb; /* Callback to reg_dmabuf_mr func */
 	mlx5_dereg_mr_t dereg_mr_cb; /* Callback to dereg_mr func */
 } __rte_packed_end;
 
@@ -233,6 +237,10 @@ mlx5_mr_lookup_list(struct mlx5_mr_share_cache *share_cache,
 struct mlx5_mr *
 mlx5_create_mr_ext(void *pd, uintptr_t addr, size_t len, int socket_id,
 		   mlx5_reg_mr_t reg_mr_cb);
+struct mlx5_mr *
+mlx5_create_mr_ext_dmabuf(void *pd, uintptr_t addr, size_t len, int socket_id,
+			  int dmabuf_fd, uint64_t dmabuf_offset,
+			  mlx5_reg_dmabuf_mr_t reg_dmabuf_mr_cb);
 void mlx5_mr_free(struct mlx5_mr *mr, mlx5_dereg_mr_t dereg_mr_cb);
 __rte_internal
 uint32_t
@@ -251,12 +259,19 @@ int
 mlx5_common_verbs_reg_mr(void *pd, void *addr, size_t length,
 			 struct mlx5_pmd_mr *pmd_mr);
 __rte_internal
+int
+mlx5_common_verbs_reg_dmabuf_mr(void *pd, uint64_t offset, size_t length,
+				uint64_t iova, int fd,
+				struct mlx5_pmd_mr *pmd_mr);
+__rte_internal
 void
 mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);
 
 __rte_internal
 void
-mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb, mlx5_dereg_mr_t *dereg_mr_cb);
+mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb,
+		      mlx5_reg_dmabuf_mr_t *reg_dmabuf_mr_cb,
+		      mlx5_dereg_mr_t *dereg_mr_cb);
 
 __rte_internal
 int
drivers/common/mlx5/windows/mlx5_common_os.c +7 -1
index 7fac361460..5e284742ab 100644
@@ -17,6 +17,7 @@
 #include "mlx5_common.h"
 #include "mlx5_common_os.h"
 #include "mlx5_malloc.h"
+#include "mlx5_common_mr.h"
 
 /**
  * Initialization routine for run-time dependency on external lib.
@@ -442,15 +443,20 @@ mlx5_os_dereg_mr(struct mlx5_pmd_mr *pmd_mr)
  *
  * @param[out] reg_mr_cb
  *   Pointer to reg_mr func
+ * @param[out] reg_dmabuf_mr_cb
+ *   Pointer to reg_dmabuf_mr func (NULL on Windows - not supported)
  * @param[out] dereg_mr_cb
  *   Pointer to dereg_mr func
  *
  */
 RTE_EXPORT_INTERNAL_SYMBOL(mlx5_os_set_reg_mr_cb)
 void
-mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb, mlx5_dereg_mr_t *dereg_mr_cb)
+mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb,
+		      mlx5_reg_dmabuf_mr_t *reg_dmabuf_mr_cb,
+		      mlx5_dereg_mr_t *dereg_mr_cb)
 {
 	*reg_mr_cb = mlx5_os_reg_mr;
+	*reg_dmabuf_mr_cb = NULL; /* dma-buf not supported on Windows */
 	*dereg_mr_cb = mlx5_os_dereg_mr;
 }
 
drivers/crypto/mlx5/mlx5_crypto.h +1 -0
index f9f127e9e6..b2712c9a8d 100644
@@ -41,6 +41,7 @@ struct mlx5_crypto_priv {
 	struct mlx5_common_device *cdev; /* Backend mlx5 device. */
 	struct rte_cryptodev *crypto_dev;
 	mlx5_reg_mr_t reg_mr_cb; /* Callback to reg_mr func */
+	mlx5_reg_dmabuf_mr_t reg_dmabuf_mr_cb; /* Callback to reg_dmabuf_mr func */
 	mlx5_dereg_mr_t dereg_mr_cb; /* Callback to dereg_mr func */
 	struct mlx5_uar uar; /* User Access Region. */
 	uint32_t max_segs_num; /* Maximum supported data segs. */
drivers/crypto/mlx5/mlx5_crypto_gcm.c +2 -1
index 89f32c7722..380689cfeb 100644
@@ -1186,7 +1186,8 @@ mlx5_crypto_gcm_init(struct mlx5_crypto_priv *priv)
 
 	/* Override AES-GCM specified ops. */
 	dev_ops->sym_session_configure = mlx5_crypto_sym_gcm_session_configure;
-	mlx5_os_set_reg_mr_cb(&priv->reg_mr_cb, &priv->dereg_mr_cb);
+	mlx5_os_set_reg_mr_cb(&priv->reg_mr_cb,  &priv->reg_dmabuf_mr_cb,
+			&priv->dereg_mr_cb);
 	dev_ops->queue_pair_setup = mlx5_crypto_gcm_qp_setup;
 	dev_ops->queue_pair_release = mlx5_crypto_gcm_qp_release;
 	if (mlx5_crypto_is_ipsec_opt(priv)) {
Signature · 1 line
2.52.0
#5 lore raw

[REVIEW] common/mlx5: support dmabuf

AI-generated review of bundle-1701-dmabuf.mbox
Reviewed using Claude (claude-opus-4-5-20251101)

This is an automated review. Please verify all suggestions.

---

# DPDK Patch Review: dmabuf Support

## Summary
This patch series adds dmabuf (DMA buffer) support to DPDK EAL and the MLX5 driver, enabling DMA transfers between drivers without proprietary kernel modules.

---

## Patch 1/2: eal: support dmabuf

### Commit Message Issues

**Warning: Subject line format**
- Subject "eal: support dmabuf" is acceptable but could be more descriptive
- Consider: "eal: add dmabuf external memory registration support"

**Warning: Body contains questions to reviewers**
The commit message contains design questions that should be resolved before submission:

```
Which option is preferred?
```

Remove these questions and state the chosen design approach clearly.

**Info: Body line length**
Some lines in the body exceed 75 characters but are within acceptable range.

### Code Issues

**Error: Double blank line**

```c
} dmabuf_info[RTE_MAX_MEMSEG_LISTS] = {
	[0 ... RTE_MAX_MEMSEG_LISTS - 1] = { .fd = -1, .offset = 0 }
};


#define MAX_MMAP_WITH_DEFINED_ADDR_TRIES 5
```

Remove the extra blank line after the struct initialization.

**Warning: Inconsistent indentation in struct**

```c
static struct {
		int fd;          /**< dmabuf fd, -1 if not dmabuf backed */
		uint64_t offset; /**< offset within dmabuf */
	} dmabuf_info[RTE_MAX_MEMSEG_LISTS] = {
```
The struct members are double-indented with tabs. Should use single tab for consistency:
```c
static struct {
	int fd;          /**< dmabuf fd, -1 if not dmabuf backed */
	uint64_t offset; /**< offset within dmabuf */
} dmabuf_info[RTE_MAX_MEMSEG_LISTS] = {
```

**Error: New public APIs missing __rte_experimental**
All new public API functions in rte_memory.h must be marked as experimental:
- rte_memseg_list_get_dmabuf_fd()
- rte_memseg_list_get_dmabuf_fd_thread_unsafe()
- rte_memseg_list_get_dmabuf_offset()
- rte_memseg_list_get_dmabuf_offset_thread_unsafe()
- rte_extmem_register_dmabuf()

Add __rte_experimental on the line before each function declaration in the header:

```c
__rte_experimental
int
rte_memseg_list_get_dmabuf_fd(const struct rte_memseg_list *msl);
```

**Warning: Missing release notes**
New API functions require documentation in doc/guides/rel_notes/release_XX_YY.rst.

**Warning: Missing version.map updates**
New exported symbols need to be added to lib/eal/version.map under the EXPERIMENTAL section.

**Warning: Missing testpmd hooks and functional tests**
New APIs should have tests in app/test/ and hooks in app/testpmd per guidelines.

**Info: Doxygen style**
The Doxygen comments use dma-buf inconsistently (sometimes dmabuf, sometimes dma-buf). Consider standardizing to one form throughout.

**Warning: Variable n unused context**

```c
	n = len / page_sz;
	if (malloc_heap_create_external_seg_dmabuf(va_addr, iova_addrs, n,
```

The variable n is computed but the result from len / page_sz could be used directly since it's only used once.

---

## Patch 2/2: common/mlx5: support dmabuf

### Commit Message Issues

**Info: Subject is acceptable**
"common/mlx5: support dmabuf" follows the format guidelines.

### Code Issues

**Warning: Long lines exceed 100 characters**
Several lines in mlx5_common.c and mlx5_common_mr.c exceed the 100-character limit:

```c
			mr = mlx5_create_mr_ext_dmabuf(dev->pd, (uintptr_t)addr, len,
						SOCKET_ID_ANY, dmabuf_fd, dmabuf_off,
						dev->mr_scache.reg_dmabuf_mr_cb);
```

Line 1149: mr = mlx5_create_mr_ext_dmabuf(dev->pd, (uintptr_t)addr, len, - OK But the continuation could be better formatted.

In mlx5_common_mr.c:

```c
				int dmabuf_fd = rte_memseg_list_get_dmabuf_fd_thread_unsafe(msl);
```
This line likely exceeds 100 characters. Break it up:
```c
				int dmabuf_fd;
				dmabuf_fd = rte_memseg_list_get_dmabuf_fd_thread_unsafe(msl);
```

**Warning: Missing __rte_internal attribute**
The function mlx5_create_mr_ext_dmabuf() is declared in mlx5_common_mr.h but lacks __rte_internal:

```c
struct mlx5_mr *
mlx5_create_mr_ext_dmabuf(void *pd, uintptr_t addr, size_t len, int socket_id,
			  int dmabuf_fd, uint64_t dmabuf_offset,
			  mlx5_reg_dmabuf_mr_t reg_dmabuf_mr_cb);
```

If this is internal to the driver, add __rte_internal on the line before.

**Error: Missing RTE_EXPORT_INTERNAL_SYMBOL for mlx5_create_mr_ext_dmabuf**
The function mlx5_create_mr_ext_dmabuf() in mlx5_common_mr.c is missing the export macro if it's meant to be used by other mlx5 components.

**Warning: Brace style inconsistency**

```c
		if (dmabuf_fd >= 0) {
			uint64_t dmabuf_off;
```

This is fine, but ensure consistency throughout.

**Info: Code duplication**
The dmabuf detection and registration logic is duplicated between mlx5_common_dev_dma_map() and mlx5_mr_mempool_register_primary(). Consider extracting to a helper function.

**Warning: Potential NULL dereference**
In mlx5_common.c:

```c
	msl = rte_mem_virt2memseg_list(addr);
	if (msl != NULL && msl->external) {
		int dmabuf_fd = rte_memseg_list_get_dmabuf_fd_thread_unsafe(msl);
```

The rte_memseg_list_get_dmabuf_fd_thread_unsafe() call happens without holding the memory lock, but the comment in the header says it's only safe within memory-related callbacks. This may be a race condition if memory configuration changes.

**Warning: Missing error check**

```c
				rte_memseg_list_get_dmabuf_offset_thread_unsafe(msl, &dmabuf_off);
```

The return value is not checked. If the function fails, dmabuf_off may be uninitialized.

**Info: Windows stub**

```c
	*reg_dmabuf_mr_cb = NULL; /* dma-buf not supported on Windows */
```

Good practice to document platform limitations.

---

## General Issues

**Warning: Missing documentation**
- No updates to programmer's guide documentation explaining dmabuf usage
- No updates to release notes

**Warning: ABI considerations**
The patch mentions avoiding ABI changes by using a side-table for dmabuf info. This design decision should be documented more clearly, and the commit message questions should be resolved.

**Info: Linux-only feature**
The dmabuf feature is Linux-specific. Consider adding explicit documentation about platform support.

---

## Checklist Summary

| Item | Status |
|------|--------|
| SPDX license | ✓ OK (existing files) |
| Signed-off-by | ✓ Present |
| Subject line length | ✓ OK |
| Subject format | ✓ OK |
| Body line wrap | ⚠ Some lines long |
| `__rte_experimental` on new APIs | ✗ Missing |
| Release notes | ✗ Missing |
| version.map updates | ✗ Missing |
| Tests | ✗ Missing |
| Documentation | ✗ Missing |
| Code style | ⚠ Minor issues |
#6 lore raw

Re: [REVIEW] common/mlx5: support dmabuf

Hello Stephen,

Quoted 13 lines · Stephen Hemminger

AI-generated review of bundle-1701-dmabuf.mbox
Reviewed using Claude (claude-opus-4-5-20251101)

This is an automated review. Please verify all suggestions.

---

# DPDK Patch Review: dmabuf Support

## Summary
This patch series adds dmabuf (DMA buffer) support to DPDK EAL and the MLX5 driver, enabling DMA transfers between drivers without proprietary kernel modules.

[snip]

Quoted 2 lines

**Warning: Missing version.map updates**
New exported symbols need to be added to lib/eal/version.map under the EXPERIMENTAL section.

I noticed similar comments on other series.
There is no version.map update needed anymore, since v25.07.

Signature · 1 line
David Marchand
#7 lore raw

Re: [REVIEW] common/mlx5: support dmabuf

Quoted 17 lines · On Wed, 28 Jan 2026 15:30:17 +0100 David Marchand <[email protected]>…

Hello Stephen,

Quoted 4 lines · Stephen Hemminger

AI-generated review of bundle-1701-dmabuf.mbox
Reviewed using Claude (claude-opus-4-5-20251101)

Quoted 9 lines

This is an automated review. Please verify all suggestions.

---

# DPDK Patch Review: dmabuf Support

## Summary
This patch series adds dmabuf (DMA buffer) support to DPDK EAL and the MLX5 driver, enabling DMA transfers between drivers without proprietary kernel modules.

Quoted 9 lines

[snip]

Quoted 2 lines

**Warning: Missing version.map updates**
New exported symbols need to be added to lib/eal/version.map under the EXPERIMENTAL section.

I noticed similar comments on other series.
There is no version.map update needed anymore, since v25.07.

I know, there is nothing in the AGENTS file about it, not sure where that neuron is coming from.

#8 lore raw

Re: [REVIEW] common/mlx5: support dmabuf

In reply to David Marchand
Quoted 17 lines · On Wed, 28 Jan 2026 15:30:17 +0100 David Marchand <[email protected]>…

Hello Stephen,

Quoted 4 lines · Stephen Hemminger

AI-generated review of bundle-1701-dmabuf.mbox
Reviewed using Claude (claude-opus-4-5-20251101)

Quoted 9 lines

This is an automated review. Please verify all suggestions.

---

# DPDK Patch Review: dmabuf Support

## Summary
This patch series adds dmabuf (DMA buffer) support to DPDK EAL and the MLX5 driver, enabling DMA transfers between drivers without proprietary kernel modules.

Quoted 9 lines

[snip]

Quoted 2 lines

**Warning: Missing version.map updates**
New exported symbols need to be added to lib/eal/version.map under the EXPERIMENTAL section.

I noticed similar comments on other series.
There is no version.map update needed anymore, since v25.07.

I got AI to fix itself :-)

Now I understand the issue. The AGENTS.md says "New external functions must be exported properly" but doesn't explain the current mechanism. The AI is filling in with outdated knowledge about version.map files.

DPDK has moved to automatic symbol map generation using export macros.

#9 lore raw

RE: [REVIEW] common/mlx5: support dmabuf

In reply to Stephen Hemminger
Quoted 28 lines

External email: Use caution opening links or attachments


AI-generated review of bundle-1701-dmabuf.mbox Reviewed using Claude (claude-opus-4-5-20251101)

This is an automated review. Please verify all suggestions.

---

# DPDK Patch Review: dmabuf Support

## Summary
This patch series adds dmabuf (DMA buffer) support to DPDK EAL and the MLX5 driver, enabling DMA transfers between drivers without proprietary kernel modules.
---

## Patch 1/2: eal: support dmabuf

### Commit Message Issues

**Warning: Subject line format**
- Subject "eal: support dmabuf" is acceptable but could be more descriptive
- Consider: "eal: add dmabuf external memory registration support"

**Warning: Body contains questions to reviewers** The commit message contains design questions that should be resolved before submission:

```
Which option is preferred?
```
Quoted 12 lines

Remove these questions and state the chosen design approach clearly.
**Info: Body line length**
Some lines in the body exceed 75 characters but are within acceptable range.
### Code Issues

**Error: Double blank line**
```c
} dmabuf_info[RTE_MAX_MEMSEG_LISTS] = {
        [0 ... RTE_MAX_MEMSEG_LISTS - 1] = { .fd = -1, .offset = 0 } };

Fixed

Quoted 11 lines

#define MAX_MMAP_WITH_DEFINED_ADDR_TRIES 5 ``` Remove the extra blank line after the struct initialization.
**Warning: Inconsistent indentation in struct**

```c static struct {
                int fd;          /**< dmabuf fd, -1 if not dmabuf backed */
                uint64_t offset; /**< offset within dmabuf */
        } dmabuf_info[RTE_MAX_MEMSEG_LISTS] = { ```
The struct members are double-indented with tabs. Should use single tab for consistency:
```c
Quoted 4 lines

static struct {
        int fd;          /**< dmabuf fd, -1 if not dmabuf backed */
        uint64_t offset; /**< offset within dmabuf */ } dmabuf_info[RTE_MAX_MEMSEG_LISTS] = { ```

Removed as part of refactoring away from the init struct syntax.

Quoted 5 lines


**Error: New public APIs missing __rte_experimental** All new public API functions in rte_memory.h must be marked as experimental:
- rte_memseg_list_get_dmabuf_fd()
- rte_memseg_list_get_dmabuf_fd_thread_unsafe()
- rte_memseg_list_get_dmabuf_offset()

Quoted 9 lines

- rte_memseg_list_get_dmabuf_offset_thread_unsafe()
- rte_extmem_register_dmabuf()

Add __rte_experimental on the line before each function declaration in the header:
```c
__rte_experimental
int
rte_memseg_list_get_dmabuf_fd(const struct rte_memseg_list *msl); ```

Done

Quoted 3 lines


**Warning: Missing release notes**
New API functions require documentation in doc/guides/rel_notes/release_XX_YY.rst.

Done

Quoted 7 lines


**Warning: Missing version.map updates**
New exported symbols need to be added to lib/eal/version.map under the EXPERIMENTAL section.
**Warning: Missing testpmd hooks and functional tests**
New APIs should have tests in app/test/ and hooks in app/testpmd per guidelines.

Quoted 8 lines

**Info: Doxygen style**
The Doxygen comments use dma-buf inconsistently (sometimes dmabuf, sometimes dma-buf). Consider standardizing to one form throughout.
**Warning: Variable n unused context**
```c
        n = len / page_sz;
        if (malloc_heap_create_external_seg_dmabuf(va_addr, iova_addrs, n, ```
The variable n is computed but the result from len / page_sz could be used directly since it's only used once.

Fixed as part of refactoring.

Quoted 35 lines


---

## Patch 2/2: common/mlx5: support dmabuf

### Commit Message Issues

**Info: Subject is acceptable**
"common/mlx5: support dmabuf" follows the format guidelines.

### Code Issues

**Warning: Long lines exceed 100 characters**
Several lines in mlx5_common.c and mlx5_common_mr.c exceed the 100-character limit:

```c
                        mr = mlx5_create_mr_ext_dmabuf(dev->pd, (uintptr_t)addr, len,
                                                SOCKET_ID_ANY, dmabuf_fd, dmabuf_off,
                                                dev->mr_scache.reg_dmabuf_mr_cb); ```
Line 1149: `mr = mlx5_create_mr_ext_dmabuf(dev->pd, (uintptr_t)addr, len,` - OK
But the continuation could be better formatted.
 
In `mlx5_common_mr.c`:
```c
                                int dmabuf_fd = rte_memseg_list_get_dmabuf_fd_thread_unsafe(msl);
```
This line likely exceeds 100 characters. Break it up:
```c
                                int dmabuf_fd;
                                dmabuf_fd = rte_memseg_list_get_dmabuf_fd_thread_unsafe(msl);
```
 
**Warning: Missing `__rte_internal` attribute**
The function `mlx5_create_mr_ext_dmabuf()` is declared in `mlx5_common_mr.h` but lacks `__rte_internal`:
```c
Quoted 8 lines

struct mlx5_mr *
mlx5_create_mr_ext_dmabuf(void *pd, uintptr_t addr, size_t len, int socket_id,
int dmabuf_fd, uint64_t dmabuf_offset, mlx5_reg_dmabuf_mr_t reg_dmabuf_mr_cb); ```
If this is internal to the driver, add __rte_internal on the line before.

**Error: Missing RTE_EXPORT_INTERNAL_SYMBOL for mlx5_create_mr_ext_dmabuf**
The function mlx5_create_mr_ext_dmabuf() in mlx5_common_mr.c is missing the export macro if it's meant to be used by other mlx5 components.

Fixed

Quoted 16 lines

**Warning: Brace style inconsistency**

```c
                if (dmabuf_fd >= 0) {
                        uint64_t dmabuf_off; ```
This is fine, but ensure consistency throughout.
 
**Info: Code duplication**
The dmabuf detection and registration logic is duplicated between `mlx5_common_dev_dma_map()` and `mlx5_mr_mempool_register_primary()`. Consider extracting to a helper function.
 
**Warning: Potential NULL dereference**
In `mlx5_common.c`:
```c
        msl = rte_mem_virt2memseg_list(addr);
        if (msl != NULL && msl->external) {
                int dmabuf_fd = rte_memseg_list_get_dmabuf_fd_thread_unsafe(msl);
Quoted 2 lines

```
The rte_memseg_list_get_dmabuf_fd_thread_unsafe() call happens without holding the memory lock, but the comment in the header says it's only safe within memory-related callbacks. This may be a race condition if memory configuration changes.

Switched to safe version of the functions

Quoted 5 lines

**Warning: Missing error check**
```c
rte_memseg_list_get_dmabuf_offset_thread_unsafe(msl, &dmabuf_off); ```
The return value is not checked. If the function fails, dmabuf_off may be uninitialized.

Checked errors

Quoted 31 lines

**Info: Windows stub**
```c
*reg_dmabuf_mr_cb = NULL; /* dma-buf not supported on Windows */ ```
Good practice to document platform limitations.

---

## General Issues

**Warning: Missing documentation**
- No updates to programmer's guide documentation explaining dmabuf usage
- No updates to release notes

**Warning: ABI considerations**
The patch mentions avoiding ABI changes by using a side-table for dmabuf info. This design decision should be documented more clearly, and the commit message questions should be resolved.

**Info: Linux-only feature**
The dmabuf feature is Linux-specific. Consider adding explicit documentation about platform support.

---

## Checklist Summary

| Item | Status |
|------|--------|
| SPDX license | ✓ OK (existing files) | Signed-off-by | ✓ Present |
| Subject line length | ✓ OK | Subject format | ✓ OK | Body line wrap |
| ⚠ Some lines long | `__rte_experimental` on new APIs | ✗ Missing |
| Release notes | ✗ Missing | version.map updates | ✗ Missing | Tests |
| ✗ Missing | Documentation | ✗ Missing | Code style | ⚠ Minor issues |
#10 lore raw

Re: [PATCH 2/2] common/mlx5: support dmabuf

In reply to Cliff Burdick
Quoted 7 lines · On Tue, 27 Jan 2026 17:44:09 +0000 Cliff Burdick <[email protected]> wrote:
drivers/common/mlx5/linux/mlx5_glue.c +7 -0
+static struct ibv_mr *
+mlx5_glue_reg_dmabuf_mr(struct ibv_pd *pd, uint64_t offset, size_t length,
+			uint64_t iova, int fd, int access)
+{
+#ifdef HAVE_IBV_REG_DMABUF_MR
+	return ibv_reg_dmabuf_mr(pd, offset, length, iova, fd, access);
+#else

drivers/common/mlx5/linux/mlx5_glue.c mlx5_glue_reg_mr_iova(struct ibv_pd *pd, void *addr, size_t length, · line 310

Quoted 10 lines
drivers/common/mlx5/linux/mlx5_glue.c +10 -0
+	(void)pd;
+	(void)offset;
+	(void)length;
+	(void)iova;
+	(void)fd;
+	(void)access;
+	errno = ENOTSUP;
+	return NULL;
+#endif
+}

I would prefer the callback hook did not exist (was NULL) if you don't have your #ifdef.

The (void) change looks messy and better handled by caller.

#11 lore raw
In reply to Cliff Burdick
Quoted 16 lines · On Tue, 27 Jan 2026 17:44:07 +0000 Cliff Burdick <[email protected]> wrote:

Add support for kernel dmabuf feature and integrate it in the mlx5 driver. This feature is needed to support GPUDirect on newer kernels.

Cliff Burdick (2):
eal: support dmabuf
common/mlx5: support dmabuf

 .mailmap                                      |   1 +
 drivers/common/mlx5/linux/meson.build         |   2 +
 drivers/common/mlx5/linux/mlx5_common_verbs.c |  48 ++++-
 drivers/common/mlx5/linux/mlx5_glue.c         |  19 ++
 drivers/common/mlx5/linux/mlx5_glue.h         |   3 +
 drivers/common/mlx5/mlx5_common.c             |  28 ++-
 drivers/common/mlx5/mlx5_common_mr.c          | 108 ++++++++++-
 drivers/common/mlx5/mlx5_common_mr.h          |  17 +-
 drivers/common/mlx5/windows/mlx5_common_os.c  |   8 +-
Quoted 9 lines
 drivers/crypto/mlx5/mlx5_crypto.h             |   1 +
 drivers/crypto/mlx5/mlx5_crypto_gcm.c         |   3 +-
 lib/eal/common/eal_common_memory.c            | 168 ++++++++++++++++++
 lib/eal/common/eal_memalloc.h                 |  21 +++
 lib/eal/common/malloc_heap.c                  |  27 +++
 lib/eal/common/malloc_heap.h                  |   5 +
 lib/eal/include/rte_memory.h                  | 125 +++++++++++++
 16 files changed, 576 insertions(+), 8 deletions(-)

Build fails (on MSVC) fix and resubmit.

"cl" "-Ilib\librte_eal.a.p" "-Ilib" "-I..\lib" "-Ilib\eal\common" "-I..\lib\eal\common" "-I." "-I.." "-Iconfig" "-I..\config" "-Ilib\eal\include" "-I..\lib\eal\include" "-Ilib\eal\windows\include" "-I..\lib\eal\windows\include" "-Ilib\eal\x86\include" "-I..\lib\eal\x86\include" "-Ilib\eal" "-I..\lib\eal" "-Ilib\argparse" "-I..\lib\argparse" "-Ilib\log" "-I..\lib\log" "-Ilib\kvargs" "-I..\lib\kvargs" "/MD" "/nologo" "/showIncludes" "/utf-8" "/W3" "/WX" "/std:c11" "/O2" "/Gw" "/wd4244" "/wd4267" "/wd4146" "/experimental:c11atomics" "/d1experimental:typeof" "/experimental:statementExpressions" "/FI" "rte_config.h" "-D_GNU_SOURCE" "-D_WIN32_WINNT=0x0A00" "-DALLOW_EXPERIMENTAL_API" "-DALLOW_INTERNAL_API" "-DABI_VERSION=\"26.1\"" "-DRTE_LOG_DEFAULT_LOGTYPE=lib.eal" "/Fdlib\librte_eal.a.p\eal_common_eal_common_memory.c.pdb" /Folib/librte_eal.a.p/eal_common_eal_common_memory.c.obj "/c" ../lib/eal/common/eal_common_memory.c ../lib/eal/common/eal_common_memory.c(56): error C2143: syntax error: missing ']' before '...'
../lib/eal/common/eal_common_memory.c(56): error C2059: syntax error: '...'
../lib/eal/common/eal_common_memory.c(57): error C2059: syntax error: '}'

#12 lore raw
Quoted 41 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Tuesday, January 27, 2026 4:04 PM
To: Cliff Burdick <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [PATCH 0/2] support dmabuf

External email: Use caution opening links or attachments

Quoted 16 lines · On Tue, 27 Jan 2026 17:44:07 +0000 Cliff Burdick <[email protected]> wrote:

Add support for kernel dmabuf feature and integrate it in the mlx5 driver.
This feature is needed to support GPUDirect on newer kernels.

Cliff Burdick (2):
eal: support dmabuf
common/mlx5: support dmabuf

 .mailmap                                      |   1 +
 drivers/common/mlx5/linux/meson.build         |   2 +
 drivers/common/mlx5/linux/mlx5_common_verbs.c |  48 ++++-
 drivers/common/mlx5/linux/mlx5_glue.c         |  19 ++
 drivers/common/mlx5/linux/mlx5_glue.h         |   3 +
 drivers/common/mlx5/mlx5_common.c             |  28 ++-
 drivers/common/mlx5/mlx5_common_mr.c          | 108 ++++++++++-
 drivers/common/mlx5/mlx5_common_mr.h          |  17 +-
 drivers/common/mlx5/windows/mlx5_common_os.c  |   8 +-
Quoted 9 lines
 drivers/crypto/mlx5/mlx5_crypto.h             |   1 +
 drivers/crypto/mlx5/mlx5_crypto_gcm.c         |   3 +-
 lib/eal/common/eal_common_memory.c            | 168 ++++++++++++++++++
 lib/eal/common/eal_memalloc.h                 |  21 +++
 lib/eal/common/malloc_heap.c                  |  27 +++
 lib/eal/common/malloc_heap.h                  |   5 +
 lib/eal/include/rte_memory.h                  | 125 +++++++++++++
 16 files changed, 576 insertions(+), 8 deletions(-)
Quoted 6 lines

Build fails (on MSVC) fix and resubmit.

"cl" "-Ilib\librte_eal.a.p" "-Ilib" "-I..\lib" "-Ilib\eal\common" "-I..\lib\eal\common" "-I." "-I.." "-Iconfig" "-I..\config" "-Ilib\eal\include" "-I..\lib\eal\include" "-Ilib\eal\windows\include" "-I..\lib\eal\windows\include" "-Ilib\eal\x86\include" "-I..\lib\eal\x86\include" "-Ilib\eal" "-I..\lib\eal" "-Ilib\argparse" "-> I..\lib\argparse" "-Ilib\log" "-I..\lib\log" "-Ilib\kvargs" "-I..\lib\kvargs" "/MD" "/nologo" "/showIncludes" "/utf-8" "/W3" "/WX" "/std:c11" "/O2" "/Gw" "/wd4244" "/wd4267" "/wd4146" "/experimental:c11atomics" "/d1experimental:typeof" "/experimental:statementExpressions" "/FI" "rte_config.h" "-> D_GNU_SOURCE" "-D_WIN32_WINNT=0x0A00" "-DALLOW_EXPERIMENTAL_API" "-DALLOW_INTERNAL_API" "-DABI_VERSION=\"26.1\"" "-DRTE_LOG_DEFAULT_LOGTYPE=lib.eal" "/Fdlib\librte_eal.a.p\eal_common_eal_common_memory.c.pdb" /Folib/librte_eal.a.p/eal_common_eal_common_memory.c.obj > "/c" ../lib/eal/common/eal_common_memory.c ../lib/eal/common/eal_common_memory.c(56): error C2143: syntax error: missing ']' before '...'
../lib/eal/common/eal_common_memory.c(56): error C2059: syntax error: '...'
../lib/eal/common/eal_common_memory.c(57): error C2059: syntax error: '}'

Fixed by moving to an init function

#13 lore raw

v2 cover support dmabuf

In reply to Cliff Burdick

Fixed since v1:
* Fixed issue with MSVC compilation
* Fixed style issues from code review

Add support for kernel dmabuf feature and integrate it in the mlx5 driver. This feature is needed to support GPUDirect on newer kernels.

Cliff Burdick (2):
eal: support dmabuf
common/mlx5: support dmabuf

 .mailmap                                      |   1 +
 doc/guides/rel_notes/release_26_03.rst        |   6 +
 drivers/common/mlx5/linux/meson.build         |   2 +
 drivers/common/mlx5/linux/mlx5_common_verbs.c |  48 ++++-
 drivers/common/mlx5/linux/mlx5_glue.c         |  19 ++
 drivers/common/mlx5/linux/mlx5_glue.h         |   3 +
 drivers/common/mlx5/mlx5_common.c             |  42 ++++-
 drivers/common/mlx5/mlx5_common_mr.c          | 113 +++++++++++-
 drivers/common/mlx5/mlx5_common_mr.h          |  17 +-
 drivers/common/mlx5/windows/mlx5_common_os.c  |   8 +-
 drivers/crypto/mlx5/mlx5_crypto.h             |   1 +
 drivers/crypto/mlx5/mlx5_crypto_gcm.c         |   3 +-
 lib/eal/common/eal_common_memory.c            | 165 +++++++++++++++++-
 lib/eal/common/eal_memalloc.h                 |  21 +++
 lib/eal/common/malloc_heap.c                  |  27 +++
 lib/eal/common/malloc_heap.h                  |   5 +
 lib/eal/include/rte_memory.h                  | 145 +++++++++++++++
 17 files changed, 612 insertions(+), 14 deletions(-)
Signature · 1 line
2.52.0
#14 lore raw

PATCH v2 1/2 eal: support dmabuf

dmabuf is a modern Linux kernel feature to allow DMA transfers between two drivers. Common examples of usage are streaming video devices and NIC to GPU transfers. Prior to dmabuf users had to load proprietary drivers to expose the DMA mappings. With dmabuf the proprietary drivers are no longer required.

A new api function rte_extmem_register_dmabuf is introduced to create the mapping from a dmabuf file descriptor. dmabuf uses a file descriptor and an offset that has been pre-opened with the kernel. The kernel uses the file descriptor to map to a VA pointer. To avoid ABI changes, a static struct is used inside of eal_common_memory.c, and lookups are done on this struct rather than from the rte_memseg_list.

Ideally we would like to add both the dmabuf file descriptor and offset to rte_memseg_list, but it's not clear if we can reuse existing fields when using the dmabuf API.

We could rename the external flag to a more generic "properties" flag where "external" is the lowest bit, then we can use the second bit to indicate the presence of dmabuf. In the presence of the flag for dmabuf we could reuse the base_va address field for the dmabuf offset, and the socket_id for the file descriptor.

---
 .mailmap                               |   1 +
 doc/guides/rel_notes/release_26_03.rst |   6 +
 lib/eal/common/eal_common_memory.c     | 165 ++++++++++++++++++++++++-
 lib/eal/common/eal_memalloc.h          |  21 ++++
 lib/eal/common/malloc_heap.c           |  27 ++++
 lib/eal/common/malloc_heap.h           |   5 +
 lib/eal/include/rte_memory.h           | 145 ++++++++++++++++++++++
 7 files changed, 364 insertions(+), 6 deletions(-)
.mailmap +1 -0
index 2f089326ff..4c2b2f921d 100644
@@ -291,6 +291,7 @@ Cian Ferriter <[email protected]>
 Ciara Loftus <[email protected]>
 Ciara Power <[email protected]>
 Claire Murphy <[email protected]>
+Cliff Burdick <[email protected]>
 Clemens Famulla-Conrad <[email protected]>
 Cody Doucette <[email protected]>
 Congwen Zhang <[email protected]>
doc/guides/rel_notes/release_26_03.rst +6 -0
index 15dabee7a1..56457d0382 100644
@@ -55,6 +55,12 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Added dma-buf-backed external memory support.**
+
+  Added EAL support for registering dma-buf-backed external memory with
+  ``rte_extmem_register_dmabuf``, and enabled mlx5 common code to consume
+  dma-buf mappings for device access.
+
 
 Removed Items
 -------------
lib/eal/common/eal_common_memory.c +159 -6

197 lines not on this page · raw message

lib/eal/common/eal_memalloc.h +21 -0
index 0c267066d9..e7e807ddcb 100644
@@ -90,6 +90,27 @@ eal_memalloc_set_seg_list_fd(int list_idx, int fd);
 int
 eal_memalloc_get_seg_fd_offset(int list_idx, int seg_idx, size_t *offset);
 
+/*
+ * Set dma-buf info for a memseg list.
+ * Returns 0 on success, -errno on failure.
+ */
+int
+eal_memseg_list_set_dmabuf_info(int list_idx, int fd, uint64_t offset);
+
+/*
+ * Get dma-buf fd for a memseg list.
+ * Returns fd (>= 0) on success, -1 if not dma-buf backed, -errno on error.
+ */
+int
+eal_memseg_list_get_dmabuf_fd(int list_idx);
+
+/*
+ * Get dma-buf offset for a memseg list.
+ * Returns 0 on success, -errno on failure.
+ */
+int
+eal_memseg_list_get_dmabuf_offset(int list_idx, uint64_t *offset);
+
 int
 eal_memalloc_init(void)
 	__rte_requires_shared_capability(rte_mcfg_mem_get_lock());
lib/eal/common/malloc_heap.c +27 -0
index 39240c261c..bf986fe654 100644
@@ -1232,6 +1232,33 @@ malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[],
 	msl->version = 0;
 	msl->external = 1;
 
+	/* initialize dma-buf info to "not dma-buf backed" */
+	eal_memseg_list_set_dmabuf_info(i, -1, 0);
+
+	return msl;
+}
+
+struct rte_memseg_list *
+malloc_heap_create_external_seg_dmabuf(void *va_addr, rte_iova_t iova_addrs[],
+		unsigned int n_pages, size_t page_sz, const char *seg_name,
+		unsigned int socket_id, int dmabuf_fd, uint64_t dmabuf_offset)
+{
+	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_memseg_list *msl;
+	int msl_idx;
+
+	/* Create the base external segment */
+	msl = malloc_heap_create_external_seg(va_addr, iova_addrs, n_pages,
+			page_sz, seg_name, socket_id);
+	if (msl == NULL)
+		return NULL;
+
+	/* Get memseg list index */
+	msl_idx = msl - mcfg->memsegs;
+
+	/* Set dma-buf info in the internal side-table */
+	eal_memseg_list_set_dmabuf_info(msl_idx, dmabuf_fd, dmabuf_offset);
+
 	return msl;
 }
 
lib/eal/common/malloc_heap.h +5 -0
index dfc56d4ae3..87525d1a68 100644
@@ -51,6 +51,11 @@ malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[],
 		unsigned int n_pages, size_t page_sz, const char *seg_name,
 		unsigned int socket_id);
 
+struct rte_memseg_list *
+malloc_heap_create_external_seg_dmabuf(void *va_addr, rte_iova_t iova_addrs[],
+		unsigned int n_pages, size_t page_sz, const char *seg_name,
+		unsigned int socket_id, int dmabuf_fd, uint64_t dmabuf_offset);
+
 struct rte_memseg_list *
 malloc_heap_find_external_seg(void *va_addr, size_t len);
 
lib/eal/include/rte_memory.h +145 -0

157 lines not on this page · raw message

Signature · 1 line
2.52.0
#15 lore raw

PATCH v2 2/2 common/mlx5: support dmabuf

In reply to Cliff Burdick

dmabuf is a modern Linux kernel feature to allow DMA transfers between two drivers. Common examples of usage are streaming video devices and NIC to GPU transfers. Prior to dmabuf users had to load proprietary drivers to expose the DMA mappings. With dmabuf the proprietary drivers are no longer required.

---
 .mailmap                                      |   2 +-
 drivers/common/mlx5/linux/meson.build         |   2 +
 drivers/common/mlx5/linux/mlx5_common_verbs.c |  48 +++++++-
 drivers/common/mlx5/linux/mlx5_glue.c         |  19 +++
 drivers/common/mlx5/linux/mlx5_glue.h         |   3 +
 drivers/common/mlx5/mlx5_common.c             |  42 ++++++-
 drivers/common/mlx5/mlx5_common_mr.c          | 113 +++++++++++++++++-
 drivers/common/mlx5/mlx5_common_mr.h          |  17 ++-
 drivers/common/mlx5/windows/mlx5_common_os.c  |   8 +-
 drivers/crypto/mlx5/mlx5_crypto.h             |   1 +
 drivers/crypto/mlx5/mlx5_crypto_gcm.c         |   3 +-
 11 files changed, 249 insertions(+), 9 deletions(-)
.mailmap +1 -1
index 4c2b2f921d..0a8a67098f 100644
@@ -291,8 +291,8 @@ Cian Ferriter <[email protected]>
 Ciara Loftus <[email protected]>
 Ciara Power <[email protected]>
 Claire Murphy <[email protected]>
-Cliff Burdick <[email protected]>
 Clemens Famulla-Conrad <[email protected]>
+Cliff Burdick <[email protected]>
 Cody Doucette <[email protected]>
 Congwen Zhang <[email protected]>
 Conor Fogarty <[email protected]>
drivers/common/mlx5/linux/meson.build +2 -0
index 3767e7a69b..8e83104165 100644
@@ -203,6 +203,8 @@ has_sym_args = [
             'mlx5dv_dr_domain_allow_duplicate_rules' ],
         [ 'HAVE_MLX5_IBV_REG_MR_IOVA', 'infiniband/verbs.h',
             'ibv_reg_mr_iova' ],
+        [ 'HAVE_IBV_REG_DMABUF_MR', 'infiniband/verbs.h',
+            'ibv_reg_dmabuf_mr' ],
         [ 'HAVE_MLX5_IBV_IMPORT_CTX_PD_AND_MR', 'infiniband/verbs.h',
             'ibv_import_device' ],
         [ 'HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE', 'infiniband/mlx5dv.h',
drivers/common/mlx5/linux/mlx5_common_verbs.c +47 -1

66 lines not on this page · raw message

drivers/common/mlx5/linux/mlx5_glue.c +19 -0
index a91eaa429d..6fac7f2bcd 100644
@@ -291,6 +291,24 @@ mlx5_glue_reg_mr_iova(struct ibv_pd *pd, void *addr, size_t length,
 #endif
 }
 
+static struct ibv_mr *
+mlx5_glue_reg_dmabuf_mr(struct ibv_pd *pd, uint64_t offset, size_t length,
+			uint64_t iova, int fd, int access)
+{
+#ifdef HAVE_IBV_REG_DMABUF_MR
+	return ibv_reg_dmabuf_mr(pd, offset, length, iova, fd, access);
+#else
+	(void)pd;
+	(void)offset;
+	(void)length;
+	(void)iova;
+	(void)fd;
+	(void)access;
+	errno = ENOTSUP;
+	return NULL;
+#endif
+}
+
 static struct ibv_mr *
 mlx5_glue_alloc_null_mr(struct ibv_pd *pd)
 {
@@ -1619,6 +1637,7 @@ const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue) {
 	.modify_qp = mlx5_glue_modify_qp,
 	.reg_mr = mlx5_glue_reg_mr,
 	.reg_mr_iova = mlx5_glue_reg_mr_iova,
+	.reg_dmabuf_mr = mlx5_glue_reg_dmabuf_mr,
 	.alloc_null_mr = mlx5_glue_alloc_null_mr,
 	.dereg_mr = mlx5_glue_dereg_mr,
 	.create_counter_set = mlx5_glue_create_counter_set,
drivers/common/mlx5/linux/mlx5_glue.h +3 -0
index 81d6b0aaf9..66216d1194 100644
@@ -219,6 +219,9 @@ struct mlx5_glue {
 	struct ibv_mr *(*reg_mr_iova)(struct ibv_pd *pd, void *addr,
 				      size_t length, uint64_t iova,
 				      int access);
+	struct ibv_mr *(*reg_dmabuf_mr)(struct ibv_pd *pd, uint64_t offset,
+					size_t length, uint64_t iova,
+					int fd, int access);
 	struct ibv_mr *(*alloc_null_mr)(struct ibv_pd *pd);
 	int (*dereg_mr)(struct ibv_mr *mr);
 	struct ibv_counter_set *(*create_counter_set)
drivers/common/mlx5/mlx5_common.c +40 -2

60 lines not on this page · raw message

drivers/common/mlx5/mlx5_common_mr.c +111 -2

138 lines not on this page · raw message

drivers/common/mlx5/mlx5_common_mr.h +16 -1
index cf7c685e9b..3b967b1323 100644
@@ -35,6 +35,9 @@ struct mlx5_pmd_mr {
  */
 typedef int (*mlx5_reg_mr_t)(void *pd, void *addr, size_t length,
 			     struct mlx5_pmd_mr *pmd_mr);
+typedef int (*mlx5_reg_dmabuf_mr_t)(void *pd, uint64_t offset, size_t length,
+				    uint64_t iova, int fd,
+				    struct mlx5_pmd_mr *pmd_mr);
 typedef void (*mlx5_dereg_mr_t)(struct mlx5_pmd_mr *pmd_mr);
 
 /* Memory Region object. */
@@ -87,6 +90,7 @@ struct __rte_packed_begin mlx5_mr_share_cache {
 	struct mlx5_mr_list mr_free_list; /* Freed MR list. */
 	struct mlx5_mempool_reg_list mempool_reg_list; /* Mempool database. */
 	mlx5_reg_mr_t reg_mr_cb; /* Callback to reg_mr func */
+	mlx5_reg_dmabuf_mr_t reg_dmabuf_mr_cb; /* Callback to reg_dmabuf_mr func */
 	mlx5_dereg_mr_t dereg_mr_cb; /* Callback to dereg_mr func */
 } __rte_packed_end;
 
@@ -233,6 +237,10 @@ mlx5_mr_lookup_list(struct mlx5_mr_share_cache *share_cache,
 struct mlx5_mr *
 mlx5_create_mr_ext(void *pd, uintptr_t addr, size_t len, int socket_id,
 		   mlx5_reg_mr_t reg_mr_cb);
+struct mlx5_mr *
+mlx5_create_mr_ext_dmabuf(void *pd, uintptr_t addr, size_t len, int socket_id,
+			  int dmabuf_fd, uint64_t dmabuf_offset,
+			  mlx5_reg_dmabuf_mr_t reg_dmabuf_mr_cb);
 void mlx5_mr_free(struct mlx5_mr *mr, mlx5_dereg_mr_t dereg_mr_cb);
 __rte_internal
 uint32_t
@@ -251,12 +259,19 @@ int
 mlx5_common_verbs_reg_mr(void *pd, void *addr, size_t length,
 			 struct mlx5_pmd_mr *pmd_mr);
 __rte_internal
+int
+mlx5_common_verbs_reg_dmabuf_mr(void *pd, uint64_t offset, size_t length,
+				uint64_t iova, int fd,
+				struct mlx5_pmd_mr *pmd_mr);
+__rte_internal
 void
 mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);
 
 __rte_internal
 void
-mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb, mlx5_dereg_mr_t *dereg_mr_cb);
+mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb,
+		      mlx5_reg_dmabuf_mr_t *reg_dmabuf_mr_cb,
+		      mlx5_dereg_mr_t *dereg_mr_cb);
 
 __rte_internal
 int
drivers/common/mlx5/windows/mlx5_common_os.c +7 -1
index 7fac361460..5e284742ab 100644
@@ -17,6 +17,7 @@
 #include "mlx5_common.h"
 #include "mlx5_common_os.h"
 #include "mlx5_malloc.h"
+#include "mlx5_common_mr.h"
 
 /**
  * Initialization routine for run-time dependency on external lib.
@@ -442,15 +443,20 @@ mlx5_os_dereg_mr(struct mlx5_pmd_mr *pmd_mr)
  *
  * @param[out] reg_mr_cb
  *   Pointer to reg_mr func
+ * @param[out] reg_dmabuf_mr_cb
+ *   Pointer to reg_dmabuf_mr func (NULL on Windows - not supported)
  * @param[out] dereg_mr_cb
  *   Pointer to dereg_mr func
  *
  */
 RTE_EXPORT_INTERNAL_SYMBOL(mlx5_os_set_reg_mr_cb)
 void
-mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb, mlx5_dereg_mr_t *dereg_mr_cb)
+mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb,
+		      mlx5_reg_dmabuf_mr_t *reg_dmabuf_mr_cb,
+		      mlx5_dereg_mr_t *dereg_mr_cb)
 {
 	*reg_mr_cb = mlx5_os_reg_mr;
+	*reg_dmabuf_mr_cb = NULL; /* dma-buf not supported on Windows */
 	*dereg_mr_cb = mlx5_os_dereg_mr;
 }
 
drivers/crypto/mlx5/mlx5_crypto.h +1 -0
index f9f127e9e6..b2712c9a8d 100644
@@ -41,6 +41,7 @@ struct mlx5_crypto_priv {
 	struct mlx5_common_device *cdev; /* Backend mlx5 device. */
 	struct rte_cryptodev *crypto_dev;
 	mlx5_reg_mr_t reg_mr_cb; /* Callback to reg_mr func */
+	mlx5_reg_dmabuf_mr_t reg_dmabuf_mr_cb; /* Callback to reg_dmabuf_mr func */
 	mlx5_dereg_mr_t dereg_mr_cb; /* Callback to dereg_mr func */
 	struct mlx5_uar uar; /* User Access Region. */
 	uint32_t max_segs_num; /* Maximum supported data segs. */
drivers/crypto/mlx5/mlx5_crypto_gcm.c +2 -1
index 89f32c7722..380689cfeb 100644
@@ -1186,7 +1186,8 @@ mlx5_crypto_gcm_init(struct mlx5_crypto_priv *priv)
 
 	/* Override AES-GCM specified ops. */
 	dev_ops->sym_session_configure = mlx5_crypto_sym_gcm_session_configure;
-	mlx5_os_set_reg_mr_cb(&priv->reg_mr_cb, &priv->dereg_mr_cb);
+	mlx5_os_set_reg_mr_cb(&priv->reg_mr_cb,  &priv->reg_dmabuf_mr_cb,
+			&priv->dereg_mr_cb);
 	dev_ops->queue_pair_setup = mlx5_crypto_gcm_qp_setup;
 	dev_ops->queue_pair_release = mlx5_crypto_gcm_qp_release;
 	if (mlx5_crypto_is_ipsec_opt(priv)) {
Signature · 1 line
2.52.0
#16 lore raw

v3 cover support dmabuf

In reply to Cliff Burdick

Fixes since v2:
* Fixed missing EXPERIMENTAL macro on new symbols
* Fixed style issue

Add support for kernel dmabuf feature and integrate it in the mlx5 driver. This feature is needed to support GPUDirect on newer kernels.

Cliff Burdick (2):
eal: support dmabuf
common/mlx5: support dmabuf

 .mailmap                                      |   1 +
 doc/guides/rel_notes/release_26_03.rst        |   6 +
 drivers/common/mlx5/linux/meson.build         |   2 +
 drivers/common/mlx5/linux/mlx5_common_verbs.c |  48 ++++-
 drivers/common/mlx5/linux/mlx5_glue.c         |  19 ++
 drivers/common/mlx5/linux/mlx5_glue.h         |   3 +
 drivers/common/mlx5/mlx5_common.c             |  42 ++++-
 drivers/common/mlx5/mlx5_common_mr.c          | 113 +++++++++++-
 drivers/common/mlx5/mlx5_common_mr.h          |  17 +-
 drivers/common/mlx5/windows/mlx5_common_os.c  |   8 +-
 drivers/crypto/mlx5/mlx5_crypto.h             |   1 +
 drivers/crypto/mlx5/mlx5_crypto_gcm.c         |   3 +-
 lib/eal/common/eal_common_memory.c            | 165 +++++++++++++++++-
 lib/eal/common/eal_memalloc.h                 |  21 +++
 lib/eal/common/malloc_heap.c                  |  27 +++
 lib/eal/common/malloc_heap.h                  |   5 +
 lib/eal/include/rte_memory.h                  | 145 +++++++++++++++
 17 files changed, 612 insertions(+), 14 deletions(-)
Signature · 1 line
2.52.0
#17 lore raw

PATCH v3 1/2 eal: support dmabuf

dmabuf is a modern Linux kernel feature to allow DMA transfers between two drivers. Common examples of usage are streaming video devices and NIC to GPU transfers. Prior to dmabuf users had to load proprietary drivers to expose the DMA mappings. With dmabuf the proprietary drivers are no longer required.

A new api function rte_extmem_register_dmabuf is introduced to create the mapping from a dmabuf file descriptor. dmabuf uses a file descriptor and an offset that has been pre-opened with the kernel. The kernel uses the file descriptor to map to a VA pointer. To avoid ABI changes, a static struct is used inside of eal_common_memory.c, and lookups are done on this struct rather than from the rte_memseg_list.

Ideally we would like to add both the dmabuf file descriptor and offset to rte_memseg_list, but it's not clear if we can reuse existing fields when using the dmabuf API.

We could rename the external flag to a more generic "properties" flag where "external" is the lowest bit, then we can use the second bit to indicate the presence of dmabuf. In the presence of the flag for dmabuf we could reuse the base_va address field for the dmabuf offset, and the socket_id for the file descriptor.

---
 .mailmap                               |   1 +
 doc/guides/rel_notes/release_26_03.rst |   6 +
 lib/eal/common/eal_common_memory.c     | 165 ++++++++++++++++++++++++-
 lib/eal/common/eal_memalloc.h          |  21 ++++
 lib/eal/common/malloc_heap.c           |  27 ++++
 lib/eal/common/malloc_heap.h           |   5 +
 lib/eal/include/rte_memory.h           | 145 ++++++++++++++++++++++
 7 files changed, 364 insertions(+), 6 deletions(-)
.mailmap +1 -0
index 2f089326ff..4c2b2f921d 100644
@@ -291,6 +291,7 @@ Cian Ferriter <[email protected]>
 Ciara Loftus <[email protected]>
 Ciara Power <[email protected]>
 Claire Murphy <[email protected]>
+Cliff Burdick <[email protected]>
 Clemens Famulla-Conrad <[email protected]>
 Cody Doucette <[email protected]>
 Congwen Zhang <[email protected]>
doc/guides/rel_notes/release_26_03.rst +6 -0
index 15dabee7a1..56457d0382 100644
@@ -55,6 +55,12 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Added dma-buf-backed external memory support.**
+
+  Added EAL support for registering dma-buf-backed external memory with
+  ``rte_extmem_register_dmabuf``, and enabled mlx5 common code to consume
+  dma-buf mappings for device access.
+
 
 Removed Items
 -------------
lib/eal/common/eal_common_memory.c +159 -6

197 lines not on this page · raw message

lib/eal/common/eal_memalloc.h +21 -0
index 0c267066d9..e7e807ddcb 100644
@@ -90,6 +90,27 @@ eal_memalloc_set_seg_list_fd(int list_idx, int fd);
 int
 eal_memalloc_get_seg_fd_offset(int list_idx, int seg_idx, size_t *offset);
 
+/*
+ * Set dma-buf info for a memseg list.
+ * Returns 0 on success, -errno on failure.
+ */
+int
+eal_memseg_list_set_dmabuf_info(int list_idx, int fd, uint64_t offset);
+
+/*
+ * Get dma-buf fd for a memseg list.
+ * Returns fd (>= 0) on success, -1 if not dma-buf backed, -errno on error.
+ */
+int
+eal_memseg_list_get_dmabuf_fd(int list_idx);
+
+/*
+ * Get dma-buf offset for a memseg list.
+ * Returns 0 on success, -errno on failure.
+ */
+int
+eal_memseg_list_get_dmabuf_offset(int list_idx, uint64_t *offset);
+
 int
 eal_memalloc_init(void)
 	__rte_requires_shared_capability(rte_mcfg_mem_get_lock());
lib/eal/common/malloc_heap.c +27 -0
index 39240c261c..bf986fe654 100644
@@ -1232,6 +1232,33 @@ malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[],
 	msl->version = 0;
 	msl->external = 1;
 
+	/* initialize dma-buf info to "not dma-buf backed" */
+	eal_memseg_list_set_dmabuf_info(i, -1, 0);
+
+	return msl;
+}
+
+struct rte_memseg_list *
+malloc_heap_create_external_seg_dmabuf(void *va_addr, rte_iova_t iova_addrs[],
+		unsigned int n_pages, size_t page_sz, const char *seg_name,
+		unsigned int socket_id, int dmabuf_fd, uint64_t dmabuf_offset)
+{
+	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_memseg_list *msl;
+	int msl_idx;
+
+	/* Create the base external segment */
+	msl = malloc_heap_create_external_seg(va_addr, iova_addrs, n_pages,
+			page_sz, seg_name, socket_id);
+	if (msl == NULL)
+		return NULL;
+
+	/* Get memseg list index */
+	msl_idx = msl - mcfg->memsegs;
+
+	/* Set dma-buf info in the internal side-table */
+	eal_memseg_list_set_dmabuf_info(msl_idx, dmabuf_fd, dmabuf_offset);
+
 	return msl;
 }
 
lib/eal/common/malloc_heap.h +5 -0
index dfc56d4ae3..87525d1a68 100644
@@ -51,6 +51,11 @@ malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[],
 		unsigned int n_pages, size_t page_sz, const char *seg_name,
 		unsigned int socket_id);
 
+struct rte_memseg_list *
+malloc_heap_create_external_seg_dmabuf(void *va_addr, rte_iova_t iova_addrs[],
+		unsigned int n_pages, size_t page_sz, const char *seg_name,
+		unsigned int socket_id, int dmabuf_fd, uint64_t dmabuf_offset);
+
 struct rte_memseg_list *
 malloc_heap_find_external_seg(void *va_addr, size_t len);
 
lib/eal/include/rte_memory.h +145 -0

157 lines not on this page · raw message

Signature · 1 line
2.52.0
#18 lore raw

PATCH v3 2/2 common/mlx5: support dmabuf

In reply to Cliff Burdick

dmabuf is a modern Linux kernel feature to allow DMA transfers between two drivers. Common examples of usage are streaming video devices and NIC to GPU transfers. Prior to dmabuf users had to load proprietary drivers to expose the DMA mappings. With dmabuf the proprietary drivers are no longer required.

---
 .mailmap                                      |   2 +-
 drivers/common/mlx5/linux/meson.build         |   2 +
 drivers/common/mlx5/linux/mlx5_common_verbs.c |  48 +++++++-
 drivers/common/mlx5/linux/mlx5_glue.c         |  19 +++
 drivers/common/mlx5/linux/mlx5_glue.h         |   3 +
 drivers/common/mlx5/mlx5_common.c             |  42 ++++++-
 drivers/common/mlx5/mlx5_common_mr.c          | 113 +++++++++++++++++-
 drivers/common/mlx5/mlx5_common_mr.h          |  17 ++-
 drivers/common/mlx5/windows/mlx5_common_os.c  |   8 +-
 drivers/crypto/mlx5/mlx5_crypto.h             |   1 +
 drivers/crypto/mlx5/mlx5_crypto_gcm.c         |   3 +-
 11 files changed, 249 insertions(+), 9 deletions(-)
.mailmap +1 -1
index 4c2b2f921d..0a8a67098f 100644
@@ -291,8 +291,8 @@ Cian Ferriter <[email protected]>
 Ciara Loftus <[email protected]>
 Ciara Power <[email protected]>
 Claire Murphy <[email protected]>
-Cliff Burdick <[email protected]>
 Clemens Famulla-Conrad <[email protected]>
+Cliff Burdick <[email protected]>
 Cody Doucette <[email protected]>
 Congwen Zhang <[email protected]>
 Conor Fogarty <[email protected]>
drivers/common/mlx5/linux/meson.build +2 -0
index 3767e7a69b..8e83104165 100644
@@ -203,6 +203,8 @@ has_sym_args = [
             'mlx5dv_dr_domain_allow_duplicate_rules' ],
         [ 'HAVE_MLX5_IBV_REG_MR_IOVA', 'infiniband/verbs.h',
             'ibv_reg_mr_iova' ],
+        [ 'HAVE_IBV_REG_DMABUF_MR', 'infiniband/verbs.h',
+            'ibv_reg_dmabuf_mr' ],
         [ 'HAVE_MLX5_IBV_IMPORT_CTX_PD_AND_MR', 'infiniband/verbs.h',
             'ibv_import_device' ],
         [ 'HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE', 'infiniband/mlx5dv.h',
drivers/common/mlx5/linux/mlx5_common_verbs.c +47 -1

66 lines not on this page · raw message

drivers/common/mlx5/linux/mlx5_glue.c +19 -0
index a91eaa429d..6fac7f2bcd 100644
@@ -291,6 +291,24 @@ mlx5_glue_reg_mr_iova(struct ibv_pd *pd, void *addr, size_t length,
 #endif
 }
 
+static struct ibv_mr *
+mlx5_glue_reg_dmabuf_mr(struct ibv_pd *pd, uint64_t offset, size_t length,
+			uint64_t iova, int fd, int access)
+{
+#ifdef HAVE_IBV_REG_DMABUF_MR
+	return ibv_reg_dmabuf_mr(pd, offset, length, iova, fd, access);
+#else
+	(void)pd;
+	(void)offset;
+	(void)length;
+	(void)iova;
+	(void)fd;
+	(void)access;
+	errno = ENOTSUP;
+	return NULL;
+#endif
+}
+
 static struct ibv_mr *
 mlx5_glue_alloc_null_mr(struct ibv_pd *pd)
 {
@@ -1619,6 +1637,7 @@ const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue) {
 	.modify_qp = mlx5_glue_modify_qp,
 	.reg_mr = mlx5_glue_reg_mr,
 	.reg_mr_iova = mlx5_glue_reg_mr_iova,
+	.reg_dmabuf_mr = mlx5_glue_reg_dmabuf_mr,
 	.alloc_null_mr = mlx5_glue_alloc_null_mr,
 	.dereg_mr = mlx5_glue_dereg_mr,
 	.create_counter_set = mlx5_glue_create_counter_set,
drivers/common/mlx5/linux/mlx5_glue.h +3 -0
index 81d6b0aaf9..66216d1194 100644
@@ -219,6 +219,9 @@ struct mlx5_glue {
 	struct ibv_mr *(*reg_mr_iova)(struct ibv_pd *pd, void *addr,
 				      size_t length, uint64_t iova,
 				      int access);
+	struct ibv_mr *(*reg_dmabuf_mr)(struct ibv_pd *pd, uint64_t offset,
+					size_t length, uint64_t iova,
+					int fd, int access);
 	struct ibv_mr *(*alloc_null_mr)(struct ibv_pd *pd);
 	int (*dereg_mr)(struct ibv_mr *mr);
 	struct ibv_counter_set *(*create_counter_set)
drivers/common/mlx5/mlx5_common.c +40 -2

60 lines not on this page · raw message

drivers/common/mlx5/mlx5_common_mr.c +111 -2

138 lines not on this page · raw message

drivers/common/mlx5/mlx5_common_mr.h +16 -1
index cf7c685e9b..3b967b1323 100644
@@ -35,6 +35,9 @@ struct mlx5_pmd_mr {
  */
 typedef int (*mlx5_reg_mr_t)(void *pd, void *addr, size_t length,
 			     struct mlx5_pmd_mr *pmd_mr);
+typedef int (*mlx5_reg_dmabuf_mr_t)(void *pd, uint64_t offset, size_t length,
+				    uint64_t iova, int fd,
+				    struct mlx5_pmd_mr *pmd_mr);
 typedef void (*mlx5_dereg_mr_t)(struct mlx5_pmd_mr *pmd_mr);
 
 /* Memory Region object. */
@@ -87,6 +90,7 @@ struct __rte_packed_begin mlx5_mr_share_cache {
 	struct mlx5_mr_list mr_free_list; /* Freed MR list. */
 	struct mlx5_mempool_reg_list mempool_reg_list; /* Mempool database. */
 	mlx5_reg_mr_t reg_mr_cb; /* Callback to reg_mr func */
+	mlx5_reg_dmabuf_mr_t reg_dmabuf_mr_cb; /* Callback to reg_dmabuf_mr func */
 	mlx5_dereg_mr_t dereg_mr_cb; /* Callback to dereg_mr func */
 } __rte_packed_end;
 
@@ -233,6 +237,10 @@ mlx5_mr_lookup_list(struct mlx5_mr_share_cache *share_cache,
 struct mlx5_mr *
 mlx5_create_mr_ext(void *pd, uintptr_t addr, size_t len, int socket_id,
 		   mlx5_reg_mr_t reg_mr_cb);
+struct mlx5_mr *
+mlx5_create_mr_ext_dmabuf(void *pd, uintptr_t addr, size_t len, int socket_id,
+			  int dmabuf_fd, uint64_t dmabuf_offset,
+			  mlx5_reg_dmabuf_mr_t reg_dmabuf_mr_cb);
 void mlx5_mr_free(struct mlx5_mr *mr, mlx5_dereg_mr_t dereg_mr_cb);
 __rte_internal
 uint32_t
@@ -251,12 +259,19 @@ int
 mlx5_common_verbs_reg_mr(void *pd, void *addr, size_t length,
 			 struct mlx5_pmd_mr *pmd_mr);
 __rte_internal
+int
+mlx5_common_verbs_reg_dmabuf_mr(void *pd, uint64_t offset, size_t length,
+				uint64_t iova, int fd,
+				struct mlx5_pmd_mr *pmd_mr);
+__rte_internal
 void
 mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);
 
 __rte_internal
 void
-mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb, mlx5_dereg_mr_t *dereg_mr_cb);
+mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb,
+		      mlx5_reg_dmabuf_mr_t *reg_dmabuf_mr_cb,
+		      mlx5_dereg_mr_t *dereg_mr_cb);
 
 __rte_internal
 int
drivers/common/mlx5/windows/mlx5_common_os.c +7 -1
index 7fac361460..5e284742ab 100644
@@ -17,6 +17,7 @@
 #include "mlx5_common.h"
 #include "mlx5_common_os.h"
 #include "mlx5_malloc.h"
+#include "mlx5_common_mr.h"
 
 /**
  * Initialization routine for run-time dependency on external lib.
@@ -442,15 +443,20 @@ mlx5_os_dereg_mr(struct mlx5_pmd_mr *pmd_mr)
  *
  * @param[out] reg_mr_cb
  *   Pointer to reg_mr func
+ * @param[out] reg_dmabuf_mr_cb
+ *   Pointer to reg_dmabuf_mr func (NULL on Windows - not supported)
  * @param[out] dereg_mr_cb
  *   Pointer to dereg_mr func
  *
  */
 RTE_EXPORT_INTERNAL_SYMBOL(mlx5_os_set_reg_mr_cb)
 void
-mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb, mlx5_dereg_mr_t *dereg_mr_cb)
+mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb,
+		      mlx5_reg_dmabuf_mr_t *reg_dmabuf_mr_cb,
+		      mlx5_dereg_mr_t *dereg_mr_cb)
 {
 	*reg_mr_cb = mlx5_os_reg_mr;
+	*reg_dmabuf_mr_cb = NULL; /* dma-buf not supported on Windows */
 	*dereg_mr_cb = mlx5_os_dereg_mr;
 }
 
drivers/crypto/mlx5/mlx5_crypto.h +1 -0
index f9f127e9e6..b2712c9a8d 100644
@@ -41,6 +41,7 @@ struct mlx5_crypto_priv {
 	struct mlx5_common_device *cdev; /* Backend mlx5 device. */
 	struct rte_cryptodev *crypto_dev;
 	mlx5_reg_mr_t reg_mr_cb; /* Callback to reg_mr func */
+	mlx5_reg_dmabuf_mr_t reg_dmabuf_mr_cb; /* Callback to reg_dmabuf_mr func */
 	mlx5_dereg_mr_t dereg_mr_cb; /* Callback to dereg_mr func */
 	struct mlx5_uar uar; /* User Access Region. */
 	uint32_t max_segs_num; /* Maximum supported data segs. */
drivers/crypto/mlx5/mlx5_crypto_gcm.c +2 -1
index 89f32c7722..380689cfeb 100644
@@ -1186,7 +1186,8 @@ mlx5_crypto_gcm_init(struct mlx5_crypto_priv *priv)
 
 	/* Override AES-GCM specified ops. */
 	dev_ops->sym_session_configure = mlx5_crypto_sym_gcm_session_configure;
-	mlx5_os_set_reg_mr_cb(&priv->reg_mr_cb, &priv->dereg_mr_cb);
+	mlx5_os_set_reg_mr_cb(&priv->reg_mr_cb,  &priv->reg_dmabuf_mr_cb,
+			&priv->dereg_mr_cb);
 	dev_ops->queue_pair_setup = mlx5_crypto_gcm_qp_setup;
 	dev_ops->queue_pair_release = mlx5_crypto_gcm_qp_release;
 	if (mlx5_crypto_is_ipsec_opt(priv)) {
Signature · 1 line
2.52.0
#19 lore raw

v4 cover support dmabuf

In reply to Cliff Burdick

Fixes since v3:
* Fixed version in RTE_EXPORT_EXPERIMENTAL_SYMBOL

Add support for kernel dmabuf feature and integrate it in the mlx5 driver. This feature is needed to support GPUDirect on newer kernels.

I apologize for all the patches. Still trying to learn how to submit these.

Cliff Burdick (2):
eal: support dmabuf
common/mlx5: support dmabuf

 .mailmap                                      |   1 +
 doc/guides/rel_notes/release_26_03.rst        |   6 +
 drivers/common/mlx5/linux/meson.build         |   2 +
 drivers/common/mlx5/linux/mlx5_common_verbs.c |  48 ++++-
 drivers/common/mlx5/linux/mlx5_glue.c         |  19 ++
 drivers/common/mlx5/linux/mlx5_glue.h         |   3 +
 drivers/common/mlx5/mlx5_common.c             |  42 ++++-
 drivers/common/mlx5/mlx5_common_mr.c          | 113 +++++++++++-
 drivers/common/mlx5/mlx5_common_mr.h          |  17 +-
 drivers/common/mlx5/windows/mlx5_common_os.c  |   8 +-
 drivers/crypto/mlx5/mlx5_crypto.h             |   1 +
 drivers/crypto/mlx5/mlx5_crypto_gcm.c         |   3 +-
 lib/eal/common/eal_common_memory.c            | 165 +++++++++++++++++-
 lib/eal/common/eal_memalloc.h                 |  21 +++
 lib/eal/common/malloc_heap.c                  |  27 +++
 lib/eal/common/malloc_heap.h                  |   5 +
 lib/eal/include/rte_memory.h                  | 145 +++++++++++++++
 17 files changed, 612 insertions(+), 14 deletions(-)
Signature · 1 line
2.52.0
#20 lore raw

PATCH v4 1/2 eal: support dmabuf

dmabuf is a modern Linux kernel feature to allow DMA transfers between two drivers. Common examples of usage are streaming video devices and NIC to GPU transfers. Prior to dmabuf users had to load proprietary drivers to expose the DMA mappings. With dmabuf the proprietary drivers are no longer required.

A new api function rte_extmem_register_dmabuf is introduced to create the mapping from a dmabuf file descriptor. dmabuf uses a file descriptor and an offset that has been pre-opened with the kernel. The kernel uses the file descriptor to map to a VA pointer. To avoid ABI changes, a static struct is used inside of eal_common_memory.c, and lookups are done on this struct rather than from the rte_memseg_list.

Ideally we would like to add both the dmabuf file descriptor and offset to rte_memseg_list, but it's not clear if we can reuse existing fields when using the dmabuf API.

We could rename the external flag to a more generic "properties" flag where "external" is the lowest bit, then we can use the second bit to indicate the presence of dmabuf. In the presence of the flag for dmabuf we could reuse the base_va address field for the dmabuf offset, and the socket_id for the file descriptor.

---
 .mailmap                               |   1 +
 doc/guides/rel_notes/release_26_03.rst |   6 +
 lib/eal/common/eal_common_memory.c     | 165 ++++++++++++++++++++++++-
 lib/eal/common/eal_memalloc.h          |  21 ++++
 lib/eal/common/malloc_heap.c           |  27 ++++
 lib/eal/common/malloc_heap.h           |   5 +
 lib/eal/include/rte_memory.h           | 145 ++++++++++++++++++++++
 7 files changed, 364 insertions(+), 6 deletions(-)
.mailmap +1 -0
index 2f089326ff..4c2b2f921d 100644
@@ -291,6 +291,7 @@ Cian Ferriter <[email protected]>
 Ciara Loftus <[email protected]>
 Ciara Power <[email protected]>
 Claire Murphy <[email protected]>
+Cliff Burdick <[email protected]>
 Clemens Famulla-Conrad <[email protected]>
 Cody Doucette <[email protected]>
 Congwen Zhang <[email protected]>
doc/guides/rel_notes/release_26_03.rst +6 -0
index 15dabee7a1..56457d0382 100644
@@ -55,6 +55,12 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Added dma-buf-backed external memory support.**
+
+  Added EAL support for registering dma-buf-backed external memory with
+  ``rte_extmem_register_dmabuf``, and enabled mlx5 common code to consume
+  dma-buf mappings for device access.
+
 
 Removed Items
 -------------
lib/eal/common/eal_common_memory.c +159 -6

197 lines not on this page · raw message

lib/eal/common/eal_memalloc.h +21 -0
index 0c267066d9..e7e807ddcb 100644
@@ -90,6 +90,27 @@ eal_memalloc_set_seg_list_fd(int list_idx, int fd);
 int
 eal_memalloc_get_seg_fd_offset(int list_idx, int seg_idx, size_t *offset);
 
+/*
+ * Set dma-buf info for a memseg list.
+ * Returns 0 on success, -errno on failure.
+ */
+int
+eal_memseg_list_set_dmabuf_info(int list_idx, int fd, uint64_t offset);
+
+/*
+ * Get dma-buf fd for a memseg list.
+ * Returns fd (>= 0) on success, -1 if not dma-buf backed, -errno on error.
+ */
+int
+eal_memseg_list_get_dmabuf_fd(int list_idx);
+
+/*
+ * Get dma-buf offset for a memseg list.
+ * Returns 0 on success, -errno on failure.
+ */
+int
+eal_memseg_list_get_dmabuf_offset(int list_idx, uint64_t *offset);
+
 int
 eal_memalloc_init(void)
 	__rte_requires_shared_capability(rte_mcfg_mem_get_lock());
lib/eal/common/malloc_heap.c +27 -0
index 39240c261c..bf986fe654 100644
@@ -1232,6 +1232,33 @@ malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[],
 	msl->version = 0;
 	msl->external = 1;
 
+	/* initialize dma-buf info to "not dma-buf backed" */
+	eal_memseg_list_set_dmabuf_info(i, -1, 0);
+
+	return msl;
+}
+
+struct rte_memseg_list *
+malloc_heap_create_external_seg_dmabuf(void *va_addr, rte_iova_t iova_addrs[],
+		unsigned int n_pages, size_t page_sz, const char *seg_name,
+		unsigned int socket_id, int dmabuf_fd, uint64_t dmabuf_offset)
+{
+	struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
+	struct rte_memseg_list *msl;
+	int msl_idx;
+
+	/* Create the base external segment */
+	msl = malloc_heap_create_external_seg(va_addr, iova_addrs, n_pages,
+			page_sz, seg_name, socket_id);
+	if (msl == NULL)
+		return NULL;
+
+	/* Get memseg list index */
+	msl_idx = msl - mcfg->memsegs;
+
+	/* Set dma-buf info in the internal side-table */
+	eal_memseg_list_set_dmabuf_info(msl_idx, dmabuf_fd, dmabuf_offset);
+
 	return msl;
 }
 
lib/eal/common/malloc_heap.h +5 -0
index dfc56d4ae3..87525d1a68 100644
@@ -51,6 +51,11 @@ malloc_heap_create_external_seg(void *va_addr, rte_iova_t iova_addrs[],
 		unsigned int n_pages, size_t page_sz, const char *seg_name,
 		unsigned int socket_id);
 
+struct rte_memseg_list *
+malloc_heap_create_external_seg_dmabuf(void *va_addr, rte_iova_t iova_addrs[],
+		unsigned int n_pages, size_t page_sz, const char *seg_name,
+		unsigned int socket_id, int dmabuf_fd, uint64_t dmabuf_offset);
+
 struct rte_memseg_list *
 malloc_heap_find_external_seg(void *va_addr, size_t len);
 
lib/eal/include/rte_memory.h +145 -0

157 lines not on this page · raw message

Signature · 1 line
2.52.0
#21 lore raw

Re: [PATCH v4 1/2] eal: support dmabuf

Quoted 17 lines · Cliff Burdick

dmabuf is a modern Linux kernel feature to allow DMA transfers between two drivers. Common examples of usage are streaming video devices and NIC to GPU transfers. Prior to dmabuf users had to load proprietary drivers to expose the DMA mappings. With dmabuf the proprietary drivers are no longer required.

A new api function rte_extmem_register_dmabuf is introduced to create the mapping from a dmabuf file descriptor. dmabuf uses a file descriptor and an offset that has been pre-opened with the kernel. The kernel uses the file descriptor to map to a VA pointer. To avoid ABI changes, a static struct is used inside of eal_common_memory.c, and lookups are done on this struct rather than from the rte_memseg_list.

Ideally we would like to add both the dmabuf file descriptor and offset to rte_memseg_list, but it's not clear if we can reuse existing fields when using the dmabuf API.

Quoted 8 lines

We could rename the external flag to a more generic "properties" flag where "external" is the lowest bit, then we can use the second bit to indicate the presence of dmabuf. In the presence of the flag for dmabuf we could reuse the base_va address field for the dmabuf offset, and the socket_id for the file descriptor.

---

Hi,

A few random thoughts about the patchset.

For one, this API is obviously Linux-only. This in itself is not a problem (we do have VFIO API...) but I would really like to avoid that if possible.

For another, I don't see any support for secondary processes - the dmabuf array is process-local, and calling register() from secondary process would presumably either fail or create a duplicate segment, depending on exactly what you pass into the register call. If this scenario isn't supported, it should at least be explicitly disallowed and documented to be such.

My biggest concern is that this is creating another type of external memory segment and thus segregating the API, but isn't doing it in a way that is generic. I can see a valid usecase for this, but what we're essentially doing here is storing some metadata together with the segment. So, perhaps, this is what we should do? That would seem like a cleanest solution for me, and it would extend usefulness of the API to other use cases where there may be a requirement to store some metadata/fd/whatever with the segment.

You could then build another API on top of this (a library?) that would handle things like secondary process synchronization with IPC, so that you have all fd's valid in all processes.

Thoughts?

Signature · 2 lines
Thanks,
Anatoly
#22 lore raw

RE: [PATCH v4 1/2] eal: support dmabuf

Quoted 45 lines

[-----Original Message-----
From: Burakov, Anatoly <[email protected]>
Sent: Thursday, February 12, 2026 5:58 AM
To: Cliff Burdick <[email protected]>; [email protected]
Cc: NBU-Contact-Thomas Monjalon (EXTERNAL) <[email protected]>
Subject: Re: [PATCH v4 1/2] eal: support dmabuf]()

External email: Use caution opening links or attachments

Quoted 17 lines · Cliff Burdick

dmabuf is a modern Linux kernel feature to allow DMA transfers between two drivers. Common examples of usage are streaming video devices and NIC to GPU transfers. Prior to dmabuf users had to load proprietary drivers to expose the DMA mappings. With dmabuf the proprietary drivers are no longer required.

A new api function rte_extmem_register_dmabuf is introduced to create the mapping from a dmabuf file descriptor. dmabuf uses a file descriptor and an offset that has been pre-opened with the kernel. The kernel uses the file descriptor to map to a VA pointer. To avoid ABI changes, a static struct is used inside of eal_common_memory.c, and lookups are done on this struct rather than from the rte_memseg_list.

Ideally we would like to add both the dmabuf file descriptor and offset to rte_memseg_list, but it's not clear if we can reuse existing fields when using the dmabuf API.

Quoted 8 lines

We could rename the external flag to a more generic "properties" flag where "external" is the lowest bit, then we can use the second bit to indicate the presence of dmabuf. In the presence of the flag for dmabuf we could reuse the base_va address field for the dmabuf offset, and the socket_id for the file descriptor.

---

Hi,

A few random thoughts about the patchset.

For one, this API is obviously Linux-only. This in itself is not a problem (we do have VFIO API...) but I would really like to avoid that if possible.

For another, I don't see any support for secondary processes - the dmabuf array is process-local, and calling register() from secondary process would presumably either fail or create a duplicate segment, depending on exactly what you pass into the register call. If this scenario isn't supported, it should at least be explicitly disallowed and documented to be such.

Quoted 8 lines

My biggest concern is that this is creating another type of external memory segment and thus segregating the API, but isn't doing it in a way that is generic. I can see a valid usecase for this, but what we're essentially doing here is storing some metadata together with the segment. So, perhaps, this is what we should do? That would seem like a cleanest solution for me, and it would extend usefulness of the API to other use cases where there may be a requirement to store some metadata/fd/whatever with the segment.

You could then build another API on top of this (a library?) that would handle things like secondary process synchronization with IPC, so that you have all fd's valid in all processes.

Thoughts?
--
Thanks,
Anatoly

Hi Anatoly, sorry for the delay. It is true that it's Linux-only. I did not see either BSD or Windows having an equivalent to dmabuf, but I'm not very familiar with them.

Adding support for secondary processes is something I'd rather delay for a later release if possible since it could be a lot more work. I can add a guard that says it's not supported if a secondary process calls the register function.

For a more generic API are you suggesting something like rte_extmem_register_ex() that would take an enum type along with some opaque metadata, of which DMABUF is one type?

#23 lore raw

Re: [PATCH v4 1/2] eal: support dmabuf

Hello,

It's a pity this patch didn't move.
How can we make the design discussion progressing?

23/04/2026 19:06, Cliff Burdick:

Quoted 50 lines

From: Burakov, Anatoly <[email protected]>

Quoted 35 lines · Cliff Burdick
Quoted 17 lines

dmabuf is a modern Linux kernel feature to allow DMA transfers between two drivers. Common examples of usage are streaming video devices and NIC to GPU transfers. Prior to dmabuf users had to load proprietary drivers to expose the DMA mappings. With dmabuf the proprietary drivers are no longer required.

A new api function rte_extmem_register_dmabuf is introduced to create the mapping from a dmabuf file descriptor. dmabuf uses a file descriptor and an offset that has been pre-opened with the kernel. The kernel uses the file descriptor to map to a VA pointer. To avoid ABI changes, a static struct is used inside of eal_common_memory.c, and lookups are done on this struct rather than from the rte_memseg_list.

Ideally we would like to add both the dmabuf file descriptor and offset to rte_memseg_list, but it's not clear if we can reuse existing fields when using the dmabuf API.

Quoted 8 lines

We could rename the external flag to a more generic "properties" flag where "external" is the lowest bit, then we can use the second bit to indicate the presence of dmabuf. In the presence of the flag for dmabuf we could reuse the base_va address field for the dmabuf offset, and the socket_id for the file descriptor.

---

Hi,

A few random thoughts about the patchset.

For one, this API is obviously Linux-only. This in itself is not a problem (we do have VFIO API...) but I would really like to avoid that if possible.

For another, I don't see any support for secondary processes - the dmabuf array is process-local, and calling register() from secondary process would presumably either fail or create a duplicate segment, depending on exactly what you pass into the register call. If this scenario isn't supported, it should at least be explicitly disallowed and documented to be such.

Quoted 8 lines

My biggest concern is that this is creating another type of external memory segment and thus segregating the API, but isn't doing it in a way that is generic. I can see a valid usecase for this, but what we're essentially doing here is storing some metadata together with the segment. So, perhaps, this is what we should do? That would seem like a cleanest solution for me, and it would extend usefulness of the API to other use cases where there may be a requirement to store some metadata/fd/whatever with the segment.

You could then build another API on top of this (a library?) that would handle things like secondary process synchronization with IPC, so that you have all fd's valid in all processes.

Thoughts?
--
Thanks,
Anatoly

Hi Anatoly, sorry for the delay. It is true that it's Linux-only. I did not see either BSD or Windows having an equivalent to dmabuf, but I'm not very familiar with them.

Adding support for secondary processes is something I'd rather delay for a later release if possible since it could be a lot more work. I can add a guard that says it's not supported if a secondary process calls the register function.

For a more generic API are you suggesting something like rte_extmem_register_ex() that would take an enum type along with some opaque metadata, of which DMABUF is one type?

#24 lore raw

PATCH v4 2/2 common/mlx5: support dmabuf

In reply to Cliff Burdick

dmabuf is a modern Linux kernel feature to allow DMA transfers between two drivers. Common examples of usage are streaming video devices and NIC to GPU transfers. Prior to dmabuf users had to load proprietary drivers to expose the DMA mappings. With dmabuf the proprietary drivers are no longer required.

---
 .mailmap                                      |   2 +-
 drivers/common/mlx5/linux/meson.build         |   2 +
 drivers/common/mlx5/linux/mlx5_common_verbs.c |  48 +++++++-
 drivers/common/mlx5/linux/mlx5_glue.c         |  19 +++
 drivers/common/mlx5/linux/mlx5_glue.h         |   3 +
 drivers/common/mlx5/mlx5_common.c             |  42 ++++++-
 drivers/common/mlx5/mlx5_common_mr.c          | 113 +++++++++++++++++-
 drivers/common/mlx5/mlx5_common_mr.h          |  17 ++-
 drivers/common/mlx5/windows/mlx5_common_os.c  |   8 +-
 drivers/crypto/mlx5/mlx5_crypto.h             |   1 +
 drivers/crypto/mlx5/mlx5_crypto_gcm.c         |   3 +-
 11 files changed, 249 insertions(+), 9 deletions(-)
.mailmap +1 -1
index 4c2b2f921d..0a8a67098f 100644
@@ -291,8 +291,8 @@ Cian Ferriter <[email protected]>
 Ciara Loftus <[email protected]>
 Ciara Power <[email protected]>
 Claire Murphy <[email protected]>
-Cliff Burdick <[email protected]>
 Clemens Famulla-Conrad <[email protected]>
+Cliff Burdick <[email protected]>
 Cody Doucette <[email protected]>
 Congwen Zhang <[email protected]>
 Conor Fogarty <[email protected]>
drivers/common/mlx5/linux/meson.build +2 -0
index 3767e7a69b..8e83104165 100644
@@ -203,6 +203,8 @@ has_sym_args = [
             'mlx5dv_dr_domain_allow_duplicate_rules' ],
         [ 'HAVE_MLX5_IBV_REG_MR_IOVA', 'infiniband/verbs.h',
             'ibv_reg_mr_iova' ],
+        [ 'HAVE_IBV_REG_DMABUF_MR', 'infiniband/verbs.h',
+            'ibv_reg_dmabuf_mr' ],
         [ 'HAVE_MLX5_IBV_IMPORT_CTX_PD_AND_MR', 'infiniband/verbs.h',
             'ibv_import_device' ],
         [ 'HAVE_MLX5DV_DR_ACTION_CREATE_DEST_ROOT_TABLE', 'infiniband/mlx5dv.h',
drivers/common/mlx5/linux/mlx5_common_verbs.c +47 -1

66 lines not on this page · raw message

drivers/common/mlx5/linux/mlx5_glue.c +19 -0
index a91eaa429d..6fac7f2bcd 100644
@@ -291,6 +291,24 @@ mlx5_glue_reg_mr_iova(struct ibv_pd *pd, void *addr, size_t length,
 #endif
 }
 
+static struct ibv_mr *
+mlx5_glue_reg_dmabuf_mr(struct ibv_pd *pd, uint64_t offset, size_t length,
+			uint64_t iova, int fd, int access)
+{
+#ifdef HAVE_IBV_REG_DMABUF_MR
+	return ibv_reg_dmabuf_mr(pd, offset, length, iova, fd, access);
+#else
+	(void)pd;
+	(void)offset;
+	(void)length;
+	(void)iova;
+	(void)fd;
+	(void)access;
+	errno = ENOTSUP;
+	return NULL;
+#endif
+}
+
 static struct ibv_mr *
 mlx5_glue_alloc_null_mr(struct ibv_pd *pd)
 {
@@ -1619,6 +1637,7 @@ const struct mlx5_glue *mlx5_glue = &(const struct mlx5_glue) {
 	.modify_qp = mlx5_glue_modify_qp,
 	.reg_mr = mlx5_glue_reg_mr,
 	.reg_mr_iova = mlx5_glue_reg_mr_iova,
+	.reg_dmabuf_mr = mlx5_glue_reg_dmabuf_mr,
 	.alloc_null_mr = mlx5_glue_alloc_null_mr,
 	.dereg_mr = mlx5_glue_dereg_mr,
 	.create_counter_set = mlx5_glue_create_counter_set,
drivers/common/mlx5/linux/mlx5_glue.h +3 -0
index 81d6b0aaf9..66216d1194 100644
@@ -219,6 +219,9 @@ struct mlx5_glue {
 	struct ibv_mr *(*reg_mr_iova)(struct ibv_pd *pd, void *addr,
 				      size_t length, uint64_t iova,
 				      int access);
+	struct ibv_mr *(*reg_dmabuf_mr)(struct ibv_pd *pd, uint64_t offset,
+					size_t length, uint64_t iova,
+					int fd, int access);
 	struct ibv_mr *(*alloc_null_mr)(struct ibv_pd *pd);
 	int (*dereg_mr)(struct ibv_mr *mr);
 	struct ibv_counter_set *(*create_counter_set)
drivers/common/mlx5/mlx5_common.c +40 -2

60 lines not on this page · raw message

drivers/common/mlx5/mlx5_common_mr.c +111 -2

138 lines not on this page · raw message

drivers/common/mlx5/mlx5_common_mr.h +16 -1
index cf7c685e9b..3b967b1323 100644
@@ -35,6 +35,9 @@ struct mlx5_pmd_mr {
  */
 typedef int (*mlx5_reg_mr_t)(void *pd, void *addr, size_t length,
 			     struct mlx5_pmd_mr *pmd_mr);
+typedef int (*mlx5_reg_dmabuf_mr_t)(void *pd, uint64_t offset, size_t length,
+				    uint64_t iova, int fd,
+				    struct mlx5_pmd_mr *pmd_mr);
 typedef void (*mlx5_dereg_mr_t)(struct mlx5_pmd_mr *pmd_mr);
 
 /* Memory Region object. */
@@ -87,6 +90,7 @@ struct __rte_packed_begin mlx5_mr_share_cache {
 	struct mlx5_mr_list mr_free_list; /* Freed MR list. */
 	struct mlx5_mempool_reg_list mempool_reg_list; /* Mempool database. */
 	mlx5_reg_mr_t reg_mr_cb; /* Callback to reg_mr func */
+	mlx5_reg_dmabuf_mr_t reg_dmabuf_mr_cb; /* Callback to reg_dmabuf_mr func */
 	mlx5_dereg_mr_t dereg_mr_cb; /* Callback to dereg_mr func */
 } __rte_packed_end;
 
@@ -233,6 +237,10 @@ mlx5_mr_lookup_list(struct mlx5_mr_share_cache *share_cache,
 struct mlx5_mr *
 mlx5_create_mr_ext(void *pd, uintptr_t addr, size_t len, int socket_id,
 		   mlx5_reg_mr_t reg_mr_cb);
+struct mlx5_mr *
+mlx5_create_mr_ext_dmabuf(void *pd, uintptr_t addr, size_t len, int socket_id,
+			  int dmabuf_fd, uint64_t dmabuf_offset,
+			  mlx5_reg_dmabuf_mr_t reg_dmabuf_mr_cb);
 void mlx5_mr_free(struct mlx5_mr *mr, mlx5_dereg_mr_t dereg_mr_cb);
 __rte_internal
 uint32_t
@@ -251,12 +259,19 @@ int
 mlx5_common_verbs_reg_mr(void *pd, void *addr, size_t length,
 			 struct mlx5_pmd_mr *pmd_mr);
 __rte_internal
+int
+mlx5_common_verbs_reg_dmabuf_mr(void *pd, uint64_t offset, size_t length,
+				uint64_t iova, int fd,
+				struct mlx5_pmd_mr *pmd_mr);
+__rte_internal
 void
 mlx5_common_verbs_dereg_mr(struct mlx5_pmd_mr *pmd_mr);
 
 __rte_internal
 void
-mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb, mlx5_dereg_mr_t *dereg_mr_cb);
+mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb,
+		      mlx5_reg_dmabuf_mr_t *reg_dmabuf_mr_cb,
+		      mlx5_dereg_mr_t *dereg_mr_cb);
 
 __rte_internal
 int
drivers/common/mlx5/windows/mlx5_common_os.c +7 -1
index 7fac361460..5e284742ab 100644
@@ -17,6 +17,7 @@
 #include "mlx5_common.h"
 #include "mlx5_common_os.h"
 #include "mlx5_malloc.h"
+#include "mlx5_common_mr.h"
 
 /**
  * Initialization routine for run-time dependency on external lib.
@@ -442,15 +443,20 @@ mlx5_os_dereg_mr(struct mlx5_pmd_mr *pmd_mr)
  *
  * @param[out] reg_mr_cb
  *   Pointer to reg_mr func
+ * @param[out] reg_dmabuf_mr_cb
+ *   Pointer to reg_dmabuf_mr func (NULL on Windows - not supported)
  * @param[out] dereg_mr_cb
  *   Pointer to dereg_mr func
  *
  */
 RTE_EXPORT_INTERNAL_SYMBOL(mlx5_os_set_reg_mr_cb)
 void
-mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb, mlx5_dereg_mr_t *dereg_mr_cb)
+mlx5_os_set_reg_mr_cb(mlx5_reg_mr_t *reg_mr_cb,
+		      mlx5_reg_dmabuf_mr_t *reg_dmabuf_mr_cb,
+		      mlx5_dereg_mr_t *dereg_mr_cb)
 {
 	*reg_mr_cb = mlx5_os_reg_mr;
+	*reg_dmabuf_mr_cb = NULL; /* dma-buf not supported on Windows */
 	*dereg_mr_cb = mlx5_os_dereg_mr;
 }
 
drivers/crypto/mlx5/mlx5_crypto.h +1 -0
index f9f127e9e6..b2712c9a8d 100644
@@ -41,6 +41,7 @@ struct mlx5_crypto_priv {
 	struct mlx5_common_device *cdev; /* Backend mlx5 device. */
 	struct rte_cryptodev *crypto_dev;
 	mlx5_reg_mr_t reg_mr_cb; /* Callback to reg_mr func */
+	mlx5_reg_dmabuf_mr_t reg_dmabuf_mr_cb; /* Callback to reg_dmabuf_mr func */
 	mlx5_dereg_mr_t dereg_mr_cb; /* Callback to dereg_mr func */
 	struct mlx5_uar uar; /* User Access Region. */
 	uint32_t max_segs_num; /* Maximum supported data segs. */
drivers/crypto/mlx5/mlx5_crypto_gcm.c +2 -1
index 89f32c7722..380689cfeb 100644
@@ -1186,7 +1186,8 @@ mlx5_crypto_gcm_init(struct mlx5_crypto_priv *priv)
 
 	/* Override AES-GCM specified ops. */
 	dev_ops->sym_session_configure = mlx5_crypto_sym_gcm_session_configure;
-	mlx5_os_set_reg_mr_cb(&priv->reg_mr_cb, &priv->dereg_mr_cb);
+	mlx5_os_set_reg_mr_cb(&priv->reg_mr_cb,  &priv->reg_dmabuf_mr_cb,
+			&priv->dereg_mr_cb);
 	dev_ops->queue_pair_setup = mlx5_crypto_gcm_qp_setup;
 	dev_ops->queue_pair_release = mlx5_crypto_gcm_qp_release;
 	if (mlx5_crypto_is_ipsec_opt(priv)) {
Signature · 1 line
2.52.0
#25 lore raw
In reply to Cliff Burdick
Quoted 22 lines · On Wed, 4 Feb 2026 15:50:07 +0000 Cliff Burdick <[email protected]> wrote:

Fixes since v3:
* Fixed version in RTE_EXPORT_EXPERIMENTAL_SYMBOL

Add support for kernel dmabuf feature and integrate it in the mlx5 driver. This feature is needed to support GPUDirect on newer kernels.

I apologize for all the patches. Still trying to learn how to submit these.

Cliff Burdick (2):
eal: support dmabuf
common/mlx5: support dmabuf

 .mailmap                                      |   1 +
 doc/guides/rel_notes/release_26_03.rst        |   6 +
 drivers/common/mlx5/linux/meson.build         |   2 +
 drivers/common/mlx5/linux/mlx5_common_verbs.c |  48 ++++-
 drivers/common/mlx5/linux/mlx5_glue.c         |  19 ++
 drivers/common/mlx5/linux/mlx5_glue.h         |   3 +
 drivers/common/mlx5/mlx5_common.c             |  42 ++++-
 drivers/common/mlx5/mlx5_common_mr.c          | 113 +++++++++++-
 drivers/common/mlx5/mlx5_common_mr.h          |  17 +-
 drivers/common/mlx5/windows/mlx5_common_os.c  |   8 +-
Quoted 9 lines
 drivers/crypto/mlx5/mlx5_crypto.h             |   1 +
 drivers/crypto/mlx5/mlx5_crypto_gcm.c         |   3 +-
 lib/eal/common/eal_common_memory.c            | 165 +++++++++++++++++-
 lib/eal/common/eal_memalloc.h                 |  21 +++
 lib/eal/common/malloc_heap.c                  |  27 +++
 lib/eal/common/malloc_heap.h                  |   5 +
 lib/eal/include/rte_memory.h                  | 145 +++++++++++++++
 17 files changed, 612 insertions(+), 14 deletions(-)

Any new library like this needs standalone tests so that it gets covered in CI etc.

#26 lore raw
Quoted 43 lines

-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Thursday, February 5, 2026 10:49 AM
To: Cliff Burdick <[email protected]>
Cc: [email protected]; [email protected]
Subject: Re: [PATCH v4 0/2] support dmabuf]()

External email: Use caution opening links or attachments

Quoted 22 lines · On Wed, 4 Feb 2026 15:50:07 +0000 Cliff Burdick <[email protected]> wrote:

Fixes since v3:
* Fixed version in RTE_EXPORT_EXPERIMENTAL_SYMBOL

Add support for kernel dmabuf feature and integrate it in the mlx5 driver. This feature is needed to support GPUDirect on newer kernels.

I apologize for all the patches. Still trying to learn how to submit these.

Cliff Burdick (2):
eal: support dmabuf
common/mlx5: support dmabuf

 .mailmap                              |   1 +
 doc/guides/rel_notes/release_26_03.rst        |   6 +
 drivers/common/mlx5/linux/meson.build         |   2 +
 drivers/common/mlx5/linux/mlx5_common_verbs.c |  48 ++++-
 drivers/common/mlx5/linux/mlx5_glue.c         |  19 ++
 drivers/common/mlx5/linux/mlx5_glue.h         |   3 +
 drivers/common/mlx5/mlx5_common.c             |  42 ++++-
 drivers/common/mlx5/mlx5_common_mr.c          | 113 +++++++++++-
 drivers/common/mlx5/mlx5_common_mr.h          |  17 +-
 drivers/common/mlx5/windows/mlx5_common_os.c  |   8 +-
Quoted 9 lines
 drivers/crypto/mlx5/mlx5_crypto.h             |   1 +
 drivers/crypto/mlx5/mlx5_crypto_gcm.c         |   3 +-
 lib/eal/common/eal_common_memory.c            | 165 +++++++++++++++++-
 lib/eal/common/eal_memalloc.h                 |  21 +++
 lib/eal/common/malloc_heap.c                  |  27 +++
 lib/eal/common/malloc_heap.h                  |   5 +
 lib/eal/include/rte_memory.h                  | 145 +++++++++++++++
 17 files changed, 612 insertions(+), 14 deletions(-)
Quoted 1 line

Any new library like this needs standalone tests so that it gets covered in CI etc.

I did not see any existing GPU tests, and this would require a GPU to test along with a 5.15+ Linux kernel. Do those systems exist in the test infrastructure?

#27 lore raw
Quoted 3 lines · On Thu, 5 Feb 2026 20:25:01 +0000 Cliff Burdick <[email protected]> wrote:
Quoted 1 line

Any new library like this needs standalone tests so that it gets covered in CI etc.

I did not see any existing GPU tests, and this would require a GPU to test along with a 5.15+ Linux kernel. Do those systems exist in the test infrastructure?

That was a mistake in allowing them in.
The problem was GPU requires CUDA, but that could have been handled.

Reviewed-by on the v4 series
#28 lore raw
In reply to Cliff Burdick
Quoted 22 lines · On Wed, 4 Feb 2026 15:50:07 +0000 Cliff Burdick <[email protected]> wrote:

Fixes since v3:
* Fixed version in RTE_EXPORT_EXPERIMENTAL_SYMBOL

Add support for kernel dmabuf feature and integrate it in the mlx5 driver. This feature is needed to support GPUDirect on newer kernels.

I apologize for all the patches. Still trying to learn how to submit these.

Cliff Burdick (2):
eal: support dmabuf
common/mlx5: support dmabuf

 .mailmap                                      |   1 +
 doc/guides/rel_notes/release_26_03.rst        |   6 +
 drivers/common/mlx5/linux/meson.build         |   2 +
 drivers/common/mlx5/linux/mlx5_common_verbs.c |  48 ++++-
 drivers/common/mlx5/linux/mlx5_glue.c         |  19 ++
 drivers/common/mlx5/linux/mlx5_glue.h         |   3 +
 drivers/common/mlx5/mlx5_common.c             |  42 ++++-
 drivers/common/mlx5/mlx5_common_mr.c          | 113 +++++++++++-
 drivers/common/mlx5/mlx5_common_mr.h          |  17 +-
 drivers/common/mlx5/windows/mlx5_common_os.c  |   8 +-
Quoted 9 lines
 drivers/crypto/mlx5/mlx5_crypto.h             |   1 +
 drivers/crypto/mlx5/mlx5_crypto_gcm.c         |   3 +-
 lib/eal/common/eal_common_memory.c            | 165 +++++++++++++++++-
 lib/eal/common/eal_memalloc.h                 |  21 +++
 lib/eal/common/malloc_heap.c                  |  27 +++
 lib/eal/common/malloc_heap.h                  |   5 +
 lib/eal/include/rte_memory.h                  | 145 +++++++++++++++
 17 files changed, 612 insertions(+), 14 deletions(-)

I don't think anyone look at the details here. If they did they would see the same thing as what AI did.

Review: [PATCH v4 1/2] eal: support dmabuf
[PATCH v4 2/2] common/mlx5: support dmabuf

Good approach using a side-table to avoid ABI changes to rte_memseg_list. The dmabuf support for mlx5 is well-structured with proper compile-time gating via HAVE_IBV_REG_DMABUF_MR.

Patch 1/2 - eal: support dmabuf

Error: rte_extmem_register is broken by rte_extmem_register_dmabuf.

rte_extmem_register now calls rte_extmem_register_dmabuf with fd=-1. But rte_extmem_register_dmabuf rejects dmabuf_fd < 0:

  int
  rte_extmem_register_dmabuf(void *va_addr, size_t len,
      int dmabuf_fd, uint64_t dmabuf_offset,
      rte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz)
  {
      if (dmabuf_fd < 0) {
          rte_errno = EINVAL;
          return -1;
      }
      ...

So every call to rte_extmem_register will now fail with EINVAL. rte_extmem_register should call extmem_register directly (with fd=-1), not rte_extmem_register_dmabuf:

int
rte_extmem_register(void *va_addr, size_t len, rte_iova_t iova_addrs[],
unsigned int n_pages, size_t page_sz)
{
return extmem_register(va_addr, len, -1, 0, iova_addrs,
n_pages, page_sz);
}

Error: Input validation from rte_extmem_register is lost.

The original rte_extmem_register validated va_addr, page_sz, len, alignment, and n_pages before doing anything. The new extmem_register function has no input validation -- it only has the locking and memseg creation logic. The parameter checks that were in the original function (va_addr == NULL, page_sz == 0, len == 0, power-of-2, alignment) need to be in extmem_register or duplicated in both rte_extmem_register and rte_extmem_register_dmabuf.

Error: eal_memseg_list_init uses type_msl_idx to index dmabuf_info but this is not the same as the memseg list index in mcfg->memsegs.

eal_memseg_list_init initializes dmabuf_info[type_msl_idx], but type_msl_idx is a per-type index used for naming, not the global memseg list position. When malloc_heap_create_external_seg_dmabuf later sets dmabuf_info[msl_idx] where msl_idx = msl - mcfg->memsegs, these are different index spaces. The init in eal_memseg_list_init may write to wrong slots, and external segments may use indices that were never initialized by eal_memseg_list_init. The static dmabuf_info array is zero-initialized at program start (fd=0, offset=0), but fd=0 is a valid file descriptor (stdin), so fd should be initialized to -1 for all entries, or the eal_memseg_list_init initialization should be removed and initialization done only in malloc_heap_create_external_seg and malloc_heap_create_external_seg_dmabuf.

Warning: malloc_heap_create_external_seg now redundantly initializes dmabuf_info.

malloc_heap_create_external_seg calls eal_memseg_list_set_dmabuf_info(i, -1, 0) at the end, but malloc_heap_create_external_seg_dmabuf also calls malloc_heap_create_external_seg (which sets fd=-1) and then immediately overwrites with the actual fd. This works but is confusing -- the redundant initialization in the base function was added for non-dmabuf paths but makes the dmabuf path do a useless set-then-overwrite.

Warning: dmabuf_info is process-local static storage.

The side-table approach means dmabuf metadata is not shared with secondary processes via shared memory. The commit message mentions rte_extmem_attach for cross-process use, but secondary processes will not have the dmabuf_info populated. If a secondary process calls rte_memseg_list_get_dmabuf_fd, it will always get -1. This limitation should be documented in the Doxygen for rte_extmem_register_dmabuf.

Warning: dmabuf fd lifetime / ownership is not documented.

The API does not specify whether DPDK takes ownership of the dmabuf_fd (will it close it?) or whether the caller must keep it open. Since ibv_reg_dmabuf_mr likely holds a reference through the kernel, the fd can probably be closed after registration, but this should be explicitly documented in the Doxygen. Also, rte_extmem_unregister does not clean up the dmabuf_info entry (reset fd to -1), so stale metadata remains after unregistration.

Warning: the public API functions in eal_memalloc.h have the same names as the public API functions in rte_memory.h but different signatures.

eal_memalloc.h declares:
int eal_memseg_list_get_dmabuf_fd(int list_idx);
int eal_memseg_list_get_dmabuf_offset(int list_idx, uint64_t *offset);

rte_memory.h declares:
int rte_memseg_list_get_dmabuf_fd(const struct rte_memseg_list *msl); int rte_memseg_list_get_dmabuf_offset(const struct rte_memseg_list *msl, ...);

These are distinct functions, but the eal_memalloc.h header claims to declare:
"Get dma-buf fd for a memseg list."
"Get dma-buf offset for a memseg list."
...with names prefixed eal_ vs rte_. This is fine functionally but the internal and public function signatures should use the same error convention. The internal eal_memseg_list_get_dmabuf_fd returns -EINVAL on error, while the public rte_memseg_list_get_dmabuf_fd_unsafe returns -1 with rte_errno. The public function does not call the internal function at all -- it accesses dmabuf_info directly. The internal functions in eal_memalloc.h appear unused.

Patch 2/2 - common/mlx5: support dmabuf

Warning: mlx5_os_set_reg_mr_cb signature change is an internal ABI break.

The function signature changes from 2 to 3 parameters. This is an internal symbol so it's not a public ABI break, but all callers must be updated atomically. The Windows and Linux implementations are both updated, and the crypto caller is updated, so this appears complete. Verify no other callers exist outside this patch.

Warning: duplicate dmabuf detection logic in mlx5_common.c and mlx5_common_mr.c.

The pattern of checking msl->external, getting dmabuf_fd, getting dmabuf_offset, and calculating the adjusted offset is repeated nearly identically in mlx5_common_dev_dma_map and mlx5_mr_mempool_register_primary. This should be factored into a helper function to avoid the code duplication and ensure consistent behavior.

Info: mlx5_common_verbs_reg_dmabuf_mr passes addr as iova.

The call is:
reg_dmabuf_mr_cb(pd, dmabuf_offset, len, addr, dmabuf_fd, ...)

where addr is the user-space virtual address. For ibv_reg_dmabuf_mr, the iova parameter is the "IO virtual address the device will use to access the region." Using the user-space VA as iova means the MR maps virtual addresses 1:1. This is the common pattern for DPDK but worth noting that it won't work if the device expects different IO addresses.