Skip to contentSkip to conversation

Implement initial driver for virtio-RDMA devices(kernel), virtio-rdma device model(qemu) and vhost-user-RDMA backend device(dpdk)

PATCH New Xiong Weimin 1 participant 11 messages Dec 17, 2025

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

Hi all,

This testing instructions aims to introduce an emulating a soft ROCE device with normal NIC(no RDMA), we have finished a vhost-user RDMA device demo, which can work with RDMA features such as CM, QP type of UC/UD and so on.

There are testing instructions of the demo:

1.Test Environment Configuration
Hardware Environment
Servers: 1 identically configured servers

CPU: HUAWEI Kunpeng 920 (96 cores)

Memory: 3T DDR4

NIC: TAP (paired virtio-net device for RDMA)

Software Environment
Server Host OS: 6.4.0-10.1.0.20.oe2309.aarch64

Kernel: linux-6.16.8 (with kernel-vrdma module)

QEMU: 9.0.2 (compiled with vhost-user-rdma virtual device support)

DPDK: 24.07.0-rc2

Dependencies:

rdma-core

rdma_rxe

libibverbs-dev

2. Test Procedures
a. Starting DPDK with vhost-user-rdma first:
1). Configure Hugepages
echo 2048 | sudo tee /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
2). app start
/DPDKDIR/build/examples/dpdk-vhost_user_rdma -l 1-4 -n 4 --vdev "net_tap0" -- --socket-file /tmp/vhost-rdma0

b. Booting guest kernel with qemu, command line:
...
-netdev tap,id=hostnet1,ifname=tap1,script=no,downscript=no
-device virtio-net-pci,netdev=hostnet1,id=net1,mac=52:54:00:14:72:30,bus=pci.3,addr=0x0.0,multifunction=on -chardev socket,path=/tmp/vhost-rdma0,id=vurdma
-device vhost-user-rdma-pci,bus=pci.3,addr=0x0.1,page-per-vq=on,disable-legacy=on,chardev=vurdma
...

c. Guest Kernel Module Loading and Validation
# Load vhost_rdma kernel module
sudo modprobe vrdma

# Verify module loading
lsmod | grep vrdma

# Check kernel logs
dmesg | grep vhost_rdma

# Expected output:

[    4.935473] vrdma_init_device: Initializing vRDMA device with max_cq=64, max_qp=64
[    4.949888] [vrdma_init_device]: Successfully initialized, last qp_vq index=192
[    4.949907] [vrdma_init_netdev]: Found paired net_device 'enp3s0f0' (on 0000:03:00.0)
[    4.949924] Bound vRDMA device to net_device 'enp3s0f0'
[    5.026032] vrdma virtio2: vrdma_alloc_pd: allocated PD 1
[    5.028006] Successfully registered vRDMA device as 'vrdma0'
[    5.028020] [vrdma_probe]: Successfully probed VirtIO RDMA device (index=2)
[    5.028104] VirtIO RDMA driver initialized successfully

d. Inside VM, one rdma device fs node will be generated in /dev/infiniband:
[root@localhost ~]# ll -h /dev/infiniband/
total 0
drwxr-xr-x. 2 root root 60 Dec 17 11:24 by-ibdev
drwxr-xr-x. 2 root root 60 Dec 17 11:24 by-path
crw-rw-rw-. 1 root root 10, 259 Dec 17 11:24 rdma_cm crw-rw-rw-. 1 root root 231, 192 Dec 17 11:24 uverbs0

e. The following are to be done in the future version:
1). SRQ support
2). DPDK support for physical RDMA NIC for handling the datapath between front and backend 3). Reset of VirtQueue
4). Increase size of VirtQueue for PCI transport
5). Performance Testing

f. Test Results
1). Functional Test Results:
Kernel module loading PASS Module loaded without errors
DPDK startup PASS vhost-user-rdma backend initialized
QEMU VM launch PASS VM booted using RDMA device
Network connectivity PASS Host-VM communication established
RDMA device detection PASS Virtual RDMA device recognized

f.Test Conclusion
1). Full functional compliance with specifications 2). Stable operation under extended stress conditions

Recommendations:
1). Optimize memory copy paths for higher throughput 2). Enhance error handling and recovery mechanisms

#1 lore raw

PATCH 1/14 examples/vhost_user_rdma: implement core application initialization for supporting vhost_user_rdma device

From: xiongweimin <[email protected]>

This commit introduces the main initialization routine for vHost RDMA application built on DPDK. The implementation includes:

1. DPDK EAL environment initialization with proper signal handling
2. Argument parsing for application-specific configuration
3. Creation of shared memory resources:
- Packet buffer pools with per-core caching
- Optimized ring buffers for RX/TX with SP/MC synchronization flags
4. Backend network device detection and initialization
5. Worker thread launch across available cores
6. Multi-device support with shared/dedicated resource allocation
7. vHost device construction and driver registration

Key features:
- NUMA-aware resource allocation using rte_socket_id()
- Optimized ring flags (SP_ENQ, MC_HTS_DEQ) for lockless operation
- Graceful shutdown handling through signal interception
- Resource isolation for multi-device configurations

Change-Id I1a42aeaa04595d13fc392452c1c9ca3f97442acc
---
 examples/meson.build                      |   1 +
 examples/vhost_user_rdma/main.c           | 607 ++++++++++++++++++
 examples/vhost_user_rdma/meson.build      |  45 ++
 examples/vhost_user_rdma/vhost_rdma.c     | 697 +++++++++++++++++++++
 examples/vhost_user_rdma/vhost_rdma.h     | 444 ++++++++++++++
 examples/vhost_user_rdma/vhost_rdma_ib.c  | 647 ++++++++++++++++++++
 examples/vhost_user_rdma/vhost_rdma_ib.h  | 710 ++++++++++++++++++++++
 examples/vhost_user_rdma/vhost_rdma_log.h |  52 ++
 examples/vhost_user_rdma/vhost_rdma_pkt.h | 296 +++++++++
 9 files changed, 3499 insertions(+)
 create mode 100644 examples/vhost_user_rdma/main.c
 create mode 100644 examples/vhost_user_rdma/meson.build
 create mode 100644 examples/vhost_user_rdma/vhost_rdma.c
 create mode 100644 examples/vhost_user_rdma/vhost_rdma.h
 create mode 100644 examples/vhost_user_rdma/vhost_rdma_ib.c
 create mode 100644 examples/vhost_user_rdma/vhost_rdma_ib.h
 create mode 100644 examples/vhost_user_rdma/vhost_rdma_log.h
 create mode 100644 examples/vhost_user_rdma/vhost_rdma_pkt.h
examples/meson.build +1 -0
index 8e8968a1fa..780d49d4b4 100644
@@ -54,6 +54,7 @@ all_examples = [
         'vdpa',
         'vhost',
         'vhost_blk',
+        'vhost_user_rdma',
         'vhost_crypto',
         'vm_power_manager',
         'vm_power_manager/guest_cli',
examples/vhost_user_rdma/main.c new file +607 -0

607 lines not on this page · raw message

examples/vhost_user_rdma/meson.build new file +45 -0

45 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma.c new file +697 -0

698 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma.h new file +444 -0

445 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_ib.c new file +647 -0

648 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_ib.h new file +710 -0

550 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_log.h new file +52 -0

52 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_pkt.h new file +296 -0

296 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.43.0

Part of the diff is not shown here. View the raw message.

#2 lore raw

PATCH 2/14 examples/vhost_user_rdma: implement device and port query commands

In reply to Xiong Weimin

From: xiongweimin <[email protected]>

Added RDMA control command handlers for:
- VHOST_RDMA_CTRL_ROCE_QUERY_DEVICE
- VHOST_RDMA_CTRL_ROCE_QUERY_PORT

Key features:
1. Device capability reporting:
- Maximum MR size and page size capabilities
- Queue Pair (QP) limits (max WR, SGE, CQE)
- Resource limits (MR, PD, AH counts)
- RDMA protocol capabilities

2. Port attribute reporting:
- GID table length and port state
- MTU settings (active, physical, maximum)
- Link speed and width capabilities
- Error counters and security attributes

3. Response validation:
- CHK_IOVEC macro ensures response buffer safety
- Fixed attribute values for standard RDMA v2 compliance
- Structured response formats matching IB specification

Change-Id I17ac65a0801ebf5e0b0d83a50877004a54840365
---
 examples/vhost_user_rdma/vhost_rdma_ib.c | 27 ++++++++++++
 examples/vhost_user_rdma/vhost_rdma_ib.h | 56 +++++++++++++++++++++++-
 2 files changed, 82 insertions(+), 1 deletion(-)
examples/vhost_user_rdma/vhost_rdma_ib.c +27 -0
index 5535a8696b..edb6e3fea3 100644
@@ -537,12 +537,39 @@ vhost_rdma_query_device(struct vhost_rdma_device *dev, CTRL_NO_CMD,
 	return 0;
 }
 
+static int
+vhost_rdma_query_port(__rte_unused struct vhost_rdma_device *dev,
+					CTRL_NO_CMD,
+					struct iovec *out)
+{
+	struct vhost_rdma_ack_query_port *rsp;
+
+	CHK_IOVEC(rsp, out);
+
+	rsp->gid_tbl_len = VHOST_MAX_GID_TBL_LEN;
+	rsp->max_msg_sz = 0x800000;
+	rsp->active_mtu = VHOST_RDMA_IB_MTU_256;
+	rsp->phys_mtu = VHOST_RDMA_IB_MTU_256;
+	rsp->port_cap_flags = 65536UL;
+	rsp->bad_pkey_cntr = 0UL;
+	rsp->phys_state = VHOST_RDMA_IB_PORT_PHYS_STATE_POLLING;
+	rsp->pkey_tbl_len = 1UL;
+	rsp->qkey_viol_cntr = 0UL;
+	rsp->state = VHOST_RDMA_IB_PORT_DOWN;
+	rsp->active_speed = 1UL;
+	rsp->active_width = VHOST_RDMA_IB_WIDTH_1X;
+	rsp->max_mtu = VHOST_RDMA_IB_MTU_4096;
+
+	return 0;
+}
+
 /* Command handler table declaration */
 struct {
 	int (*handler)(struct vhost_rdma_device *dev, struct iovec *in, struct iovec *out);
 	const char *name;  /* Name of the command (for logging) */
 } cmd_tbl[] = {
 	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_QUERY_DEVICE, vhost_rdma_query_device),
+	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_QUERY_PORT, vhost_rdma_query_port),
 };
 
 /**
examples/vhost_user_rdma/vhost_rdma_ib.h +55 -1

68 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

PATCH 3/14 examples/vhost_user_rdma: implement create and destroy completion queue commands

In reply to Xiong Weimin

From: xiongweimin <[email protected]>

This commit adds core functionality for managing RDMA Completion Queues (CQs):
1. CREATE_CQ command handler with resource allocation and initialization
2. DESTROY_CQ command with safe teardown procedures
3. Reference counting for lifecycle management
4. Concurrency control via spinlocks
5. Integration with device resource pools

Key features:
- Strict validation of CQ size against device capabilities
- Atomic state management with is_dying flag
- Virtual queue index reset during destruction
- Error logging for allocation failures
- Memory-safe buffer handling with CHK_IOVEC

Change-Id Ie4b51c90f36a1ceadfe4dbc622dc6fcaaaaf4261
---
 examples/vhost_user_rdma/vhost_rdma_ib.c | 59 +++++++++++++++++++++++-
 examples/vhost_user_rdma/vhost_rdma_ib.h | 33 ++++++++++++-
 2 files changed, 89 insertions(+), 3 deletions(-)
examples/vhost_user_rdma/vhost_rdma_ib.c +57 -2
index edb6e3fea3..5ec0de8ae7 100644
@@ -563,13 +563,68 @@ vhost_rdma_query_port(__rte_unused struct vhost_rdma_device *dev,
 	return 0;
 }
 
+static int
+vhost_rdma_create_cq(struct vhost_rdma_device *dev,
+					struct iovec *in,
+					struct iovec *out)
+{
+	struct vhost_rdma_cmd_create_cq *create_cmd;
+	struct vhost_rdma_ack_create_cq *create_rsp;
+	struct vhost_rdma_cq *cq;
+	uint32_t cqn;
+
+	CHK_IOVEC(create_cmd, in);
+	if (create_cmd->cqe > dev->attr.max_cqe)
+		return -EINVAL;
+
+	CHK_IOVEC(create_rsp, out);
+
+	cq = vhost_rdma_pool_alloc(&dev->cq_pool, &cqn);
+	if (cq == NULL) {
+		RDMA_LOG_ERR("cq alloc failed");
+	}
+	vhost_rdma_ref_init(cq);
+
+	rte_spinlock_init(&cq->cq_lock);
+	cq->is_dying = false;
+	cq->notify = 0;
+	cq->vq = &dev->cq_vqs[cqn];
+	cq->cqn = cqn;
+	create_rsp->cqn = cqn;
+
+	return 0;
+}
+
+static int
+vhost_rdma_destroy_cq(struct vhost_rdma_device *dev, struct iovec *in, CTRL_NO_RSP)
+{
+	struct vhost_rdma_cmd_destroy_cq *destroy_cmd;
+	struct vhost_rdma_cq *cq;
+
+	CHK_IOVEC(destroy_cmd, in);
+
+	cq = vhost_rdma_pool_get(&dev->cq_pool, destroy_cmd->cqn);
+
+	rte_spinlock_lock(&cq->cq_lock);
+	cq->is_dying = true;
+	cq->vq->last_avail_idx = 0;
+	cq->vq->last_used_idx = 0;
+	rte_spinlock_unlock(&cq->cq_lock);
+
+	vhost_rdma_drop_ref(cq, dev, cq);
+
+	return 0;
+}
+
 /* Command handler table declaration */
 struct {
 	int (*handler)(struct vhost_rdma_device *dev, struct iovec *in, struct iovec *out);
 	const char *name;  /* Name of the command (for logging) */
 } cmd_tbl[] = {
-	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_QUERY_DEVICE, vhost_rdma_query_device),
-	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_QUERY_PORT, vhost_rdma_query_port),
+	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_QUERY_DEVICE,			vhost_rdma_query_device),
+	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_QUERY_PORT,				vhost_rdma_query_port),
+	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_CREATE_CQ,				vhost_rdma_create_cq),
+	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_DESTROY_CQ,				vhost_rdma_destroy_cq),
 };
 
 /**
examples/vhost_user_rdma/vhost_rdma_ib.h +32 -1
index 664067b024..6420c8c7e2 100644
@@ -31,6 +31,12 @@
 
 #include "eal_interrupts.h"
 
+#define vhost_rdma_ref_init(obj) \
+	do{\
+		rte_atomic32_init(&(obj)->refcnt); \
+		rte_atomic32_inc(&(obj)->refcnt); \
+	}while(0)
+
 /* Forward declarations */
 struct vhost_rdma_device;
 struct vhost_queue;
@@ -370,7 +376,7 @@ struct vhost_user_rdma_msg {
  * @brief Completion Queue (CQ)
  */
 struct vhost_rdma_cq {
-	struct vhost_queue *vq;			/**< Notification V-ring */
+	struct vhost_user_queue *vq;         /**< Notification V-ring */
 	rte_spinlock_t cq_lock;			/**< Protect CQ operations */
 	uint8_t notify;					/**< Notify pending flag */
 	bool is_dying;					/**< Being destroyed */
@@ -676,6 +682,31 @@ struct vhost_rdma_ack_query_port {
 	uint32_t			reserved[32];	/* For future extensions */
 }__rte_packed;
 
+struct vhost_rdma_cmd_create_cq {
+        /* Size of CQ */
+        uint32_t cqe;
+};
+
+struct vhost_rdma_ack_create_cq {
+        /* The index of CQ */
+        uint32_t cqn;
+};
+
+struct vhost_rdma_cmd_destroy_cq {
+        /* The index of CQ */
+        uint32_t cqn;
+};
+
+struct vhost_rdma_ack_create_pd {
+        /* The handle of PD */
+        uint32_t pdn;
+};
+
+struct vhost_rdma_cmd_destroy_pd {
+        /* The handle of PD */
+        uint32_t pdn;
+};
+
 /**
  * @brief Convert IB MTU enum to byte size
  * @param mtu The MTU enum value
Signature · 1 line
2.43.0
#4 lore raw

PATCH 4/14 examples/vhost_user_rdma: implement protection domain create/destroy commands

In reply to Xiong Weimin

From: xiongweimin <[email protected]>

Added core functionality for managing RDMA Protection Domains (PDs):
1. CREATE_PD command for resource allocation and initialization
2. DESTROY_PD command with reference-counted teardown
3. Integration with device-specific PD resource pool
4. Minimalist state management for security domains
5. Robust input validation and error handling

Key features:
- PD identifier (pdn) generation and return to guest
- Atomic reference counting for lifecycle management
- Device association for resource tracking
- Memory-safe buffer handling with CHK_IOVEC
- ENOMEM handling for allocation failures

Change-Id I36d841a76067813c1880069c71b2eba90337609b
---
 examples/vhost_user_rdma/vhost_rdma_ib.c | 38 ++++++++++++++++++++++++
 examples/vhost_user_rdma/vhost_rdma_ib.h | 30 +++++++++----------
 2 files changed, 53 insertions(+), 15 deletions(-)
examples/vhost_user_rdma/vhost_rdma_ib.c +38 -0
index 5ec0de8ae7..e590b555d3 100644
@@ -616,6 +616,42 @@ vhost_rdma_destroy_cq(struct vhost_rdma_device *dev, struct iovec *in, CTRL_NO_R
 	return 0;
 }
 
+static int
+vhost_rdma_create_pd(struct vhost_rdma_device *dev, CTRL_NO_CMD, struct iovec *out)
+{
+	struct vhost_rdma_ack_create_pd *create_rsp;
+	struct vhost_rdma_pd *pd;
+	uint32_t idx;
+
+	CHK_IOVEC(create_rsp, out);
+
+	pd = vhost_rdma_pool_alloc(&dev->pd_pool, &idx);
+	if(pd == NULL) {
+		return -ENOMEM;
+	}
+	vhost_rdma_ref_init(pd);
+
+	pd->dev = dev;
+	pd->pdn = idx;
+	create_rsp->pdn = idx;
+
+	return 0;
+}
+
+static int
+vhost_rdma_destroy_pd(struct vhost_rdma_device *dev, struct iovec *in, CTRL_NO_RSP)
+{
+	struct vhost_rdma_cmd_destroy_pd *create_cmd;
+	struct vhost_rdma_pd *pd;
+
+	CHK_IOVEC(create_cmd, in);
+
+	pd = vhost_rdma_pool_get(&dev->pd_pool, create_cmd->pdn);
+	vhost_rdma_drop_ref(pd, dev, pd);
+
+	return 0;
+}
+
 /* Command handler table declaration */
 struct {
 	int (*handler)(struct vhost_rdma_device *dev, struct iovec *in, struct iovec *out);
@@ -625,6 +661,8 @@ struct {
 	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_QUERY_PORT,				vhost_rdma_query_port),
 	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_CREATE_CQ,				vhost_rdma_create_cq),
 	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_DESTROY_CQ,				vhost_rdma_destroy_cq),
+	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_CREATE_PD,				vhost_rdma_create_pd),
+	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_DESTROY_PD,				vhost_rdma_destroy_pd),
 };
 
 /**
examples/vhost_user_rdma/vhost_rdma_ib.h +15 -15
index 6420c8c7e2..6356abc65a 100644
@@ -667,44 +667,44 @@ struct vhost_rdma_ctrl_hdr {
 
 struct vhost_rdma_ack_query_port {
 	enum vhost_rdma_ib_port_state	state;
-	enum vhost_rdma_ib_mtu		    max_mtu;
-	enum vhost_rdma_ib_mtu		    active_mtu;
+	enum vhost_rdma_ib_mtu			max_mtu;
+	enum vhost_rdma_ib_mtu			active_mtu;
 	uint32_t			phys_mtu;
-	int			        gid_tbl_len;
+	int					gid_tbl_len;
 	uint32_t			port_cap_flags;
 	uint32_t			max_msg_sz;
 	uint32_t			bad_pkey_cntr;
 	uint32_t			qkey_viol_cntr;
 	uint16_t			pkey_tbl_len;
 	uint16_t			active_speed;
-	uint8_t			    active_width;
-	uint8_t			    phys_state;
+	uint8_t				active_width;
+	uint8_t				phys_state;
 	uint32_t			reserved[32];	/* For future extensions */
 }__rte_packed;
 
 struct vhost_rdma_cmd_create_cq {
-        /* Size of CQ */
-        uint32_t cqe;
+	/* Size of CQ */
+	uint32_t cqe;
 };
 
 struct vhost_rdma_ack_create_cq {
-        /* The index of CQ */
-        uint32_t cqn;
+	/* The index of CQ */
+	uint32_t cqn;
 };
 
 struct vhost_rdma_cmd_destroy_cq {
-        /* The index of CQ */
-        uint32_t cqn;
+	/* The index of CQ */
+	uint32_t cqn;
 };
 
 struct vhost_rdma_ack_create_pd {
-        /* The handle of PD */
-        uint32_t pdn;
+	/* The handle of PD */
+	uint32_t pdn;
 };
 
 struct vhost_rdma_cmd_destroy_pd {
-        /* The handle of PD */
-        uint32_t pdn;
+	/* The handle of PD */
+	uint32_t pdn;
 };
 
 /**
Signature · 1 line
2.43.0
#5 lore raw

PATCH 5/14 examples/vhost_user_rdma: implement comprehensive memory region management

In reply to Xiong Weimin

From: xiongweimin <[email protected]>

This commit adds core functionality for RDMA Memory Region (MR) handling:
1. DMA MR registration for physical memory access
2. Pre-allocated MR creation for optimized buffer handling
3. User-space MR registration with GPA->VVA translation
4. MR deregistration with reference-counted cleanup
5. Secure key generation and validation mechanisms

Key features:
- Random lkey/rkey generation with collision avoidance
- Three MR types: DMA, pre-allocated, and user-mapped
- Page mapping for user-space memory regions
- State management (VALID/ZOMBIE) for safe deregistration
- Reference counting integration with PDs
- Comprehensive error handling and logging

Change-Id I4c26d47181f895c05b8ba125fdf0959bd0827d99
---
 examples/vhost_user_rdma/vhost_rdma_ib.c | 199 +++++++++++++++++++++++
 examples/vhost_user_rdma/vhost_rdma_ib.h |  74 +++++++++
 2 files changed, 273 insertions(+)
examples/vhost_user_rdma/vhost_rdma_ib.c +199 -0
index e590b555d3..3002498151 100644
@@ -18,6 +18,7 @@
 #include <rte_ethdev.h>
 #include <rte_spinlock.h>
 #include <rte_malloc.h>
+#include <rte_random.h>
 
 #include "vhost_rdma.h"
 #include "vhost_rdma_ib.h"
@@ -652,6 +653,200 @@ vhost_rdma_destroy_pd(struct vhost_rdma_device *dev, struct iovec *in, CTRL_NO_R
 	return 0;
 }
 
+uint8_t
+vhost_rdma_get_next_key(uint32_t last_key)
+{
+	uint8_t key;
+
+	do {
+		key = rte_rand();
+	} while (key == last_key);
+
+	return key;
+}
+
+void
+vhost_rdma_mr_init_key(struct vhost_rdma_mr *mr, uint32_t mrn)
+{
+	uint32_t lkey = mrn << 8 | vhost_rdma_get_next_key(-1);
+	uint32_t rkey = (mr->access & VHOST_RDMA_IB_ACCESS_REMOTE) ? lkey : 0;
+
+	mr->lkey = lkey;
+	mr->rkey = rkey;
+}
+
+static int
+vhost_rdma_get_dma_mr(struct vhost_rdma_device *dev, struct iovec *in,
+					struct iovec *out)
+{
+	struct vhost_rdma_cmd_get_dma_mr *get_cmd;
+	struct vhost_rdma_ack_get_dma_mr *ack_rsp;
+	struct vhost_rdma_pd *pd;
+	struct vhost_rdma_mr *mr;
+	uint32_t mrn;
+
+	CHK_IOVEC(get_cmd, in);
+	CHK_IOVEC(ack_rsp, out);
+
+	pd = vhost_rdma_pool_get(&dev->pd_pool, get_cmd->pdn);
+	if (unlikely(pd == NULL)) {
+		RDMA_LOG_ERR("pd is not found");
+		return -EINVAL;
+	}
+
+	mr = vhost_rdma_pool_alloc(&dev->mr_pool, &mrn);
+	if (mr == NULL) {
+		RDMA_LOG_ERR("mr alloc failed");
+		return -ENOMEM;
+	}
+
+	vhost_rdma_ref_init(mr);
+	vhost_rdma_add_ref(pd);
+
+	mr->type = VHOST_MR_TYPE_DMA;
+	mr->state = VHOST_MR_STATE_VALID;
+	mr->access = get_cmd->access_flags;
+	mr->pd = pd;
+	vhost_rdma_mr_init_key(mr, mrn);
+	mr->mrn = mrn;
+
+	ack_rsp->lkey = mr->lkey;
+	ack_rsp->rkey = mr->rkey;
+	ack_rsp->mrn = mrn;
+
+	return 0;
+}
+
+static int
+vhost_rdma_alloc_mr(struct vhost_rdma_device *dev, struct iovec *in,
+					struct iovec *out)
+{
+	struct vhost_rdma_cmd_alloc_mr *alloc_cmd;
+	struct vhost_rdma_ack_get_dma_mr *ack_rsp;
+	struct vhost_rdma_pd *pd;
+	struct vhost_rdma_mr *mr;
+	uint32_t mrn;
+
+	CHK_IOVEC(alloc_cmd, in);
+	CHK_IOVEC(ack_rsp, out);
+
+	pd = vhost_rdma_pool_get(&dev->pd_pool, alloc_cmd->pdn);
+	if (unlikely(pd == NULL)) {
+		RDMA_LOG_ERR("pd is not found");
+		return -EINVAL;
+	}
+
+	mr = vhost_rdma_pool_alloc(&dev->mr_pool, &mrn);
+	if (mr == NULL) {
+		RDMA_LOG_ERR("mr alloc failed");
+		return -ENOMEM;
+	}
+
+	vhost_rdma_ref_init(mr);
+	vhost_rdma_add_ref(pd);	
+
+	mr->type = VHOST_MR_TYPE_DMA;
+	mr->state = VHOST_MR_STATE_VALID;
+	mr->access = alloc_cmd->access_flags;
+	mr->pd = pd;
+	mr->max_pages = alloc_cmd->max_num_sg;
+	vhost_rdma_mr_init_key(mr, mrn);
+	mr->mrn = mrn;
+
+	ack_rsp->lkey = mr->lkey;
+	ack_rsp->rkey = mr->rkey;
+	ack_rsp->mrn = mrn;
+
+	return 0;	
+}
+
+void
+vhost_rdma_map_pages(struct rte_vhost_memory *mem, uint64_t *pages,
+			uint64_t *dma_pages, uint32_t npages)
+{
+	uint32_t i;
+	uint64_t len = USER_MMAP_TARGET_PAGE_SIZE;
+
+	for (i = 0; i < npages; i++) {
+		pages[i] = gpa_to_vva(mem, dma_pages[i], &len);
+		assert(len == USER_MMAP_TARGET_PAGE_SIZE);
+	}
+}
+
+static int
+vhost_rdma_reg_user_mr(struct vhost_rdma_device *dev, struct iovec *in,
+					struct iovec *out)
+{
+	struct vhost_rdma_cmd_reg_user_mr *reg_cmd;
+	struct vhost_rdma_ack_reg_user_mr *ack_rsp;
+	struct vhost_rdma_mr *mr;
+	struct vhost_rdma_pd *pd;
+	uint32_t mrn;
+
+	CHK_IOVEC(reg_cmd, in);
+	CHK_IOVEC(ack_rsp, out);
+
+	pd = vhost_rdma_pool_get(&dev->pd_pool, reg_cmd->pdn);
+	if (unlikely(pd == NULL)) {
+		RDMA_LOG_ERR("pd is not found");
+		return -EINVAL;
+	}
+
+	mr = vhost_rdma_pool_alloc(&dev->mr_pool, &mrn);
+	if (mr == NULL) {
+		return -ENOMEM;
+	}
+
+	mr->pages = malloc(sizeof(uint64_t) * reg_cmd->npages);
+	if (mr->pages == NULL) {
+		return -ENOMEM;
+	}
+
+	vhost_rdma_ref_init(mr);
+	vhost_rdma_add_ref(pd);
+
+	vhost_rdma_map_pages(dev->mem, mr->pages, (uint64_t *)reg_cmd->pages, reg_cmd->npages);
+
+	mr->pd = pd;
+	mr->access = reg_cmd->access_flags;
+	mr->length = reg_cmd->length;
+	mr->iova = reg_cmd->virt_addr & USER_MMAP_PAGE_MASK;
+	mr->npages = reg_cmd->npages;
+	mr->type = VHOST_MR_TYPE_MR;
+	mr->state = VHOST_MR_STATE_VALID;
+	vhost_rdma_mr_init_key(mr, mrn);
+	mr->mrn = mrn;
+
+	ack_rsp->lkey = mr->lkey;
+	ack_rsp->rkey = mr->rkey;
+	ack_rsp->mrn = mrn;
+
+	return 0;
+}
+
+static int
+vhost_rdma_dereg_mr(struct vhost_rdma_device *dev, struct iovec *in, CTRL_NO_RSP)
+{
+	struct vhost_rdma_cmd_dereg_mr *dereg_cmd;
+	struct vhost_rdma_mr *mr;
+
+	CHK_IOVEC(dereg_cmd, in);
+
+	mr = vhost_rdma_pool_get(&dev->mr_pool, dereg_cmd->mrn);
+	if (unlikely(mr == NULL)) {
+		RDMA_LOG_ERR("mr not found");
+	}
+
+	mr->state = VHOST_MR_STATE_ZOMBIE;
+
+	vhost_rdma_drop_ref(mr->pd, dev, pd);
+	vhost_rdma_drop_ref(mr, dev, mr);
+
+	RDMA_LOG_DEBUG("destroy mr %u", dereg_cmd->mrn);
+
+	return 0;
+}
+
 /* Command handler table declaration */
 struct {
 	int (*handler)(struct vhost_rdma_device *dev, struct iovec *in, struct iovec *out);
@@ -663,6 +858,10 @@ struct {
 	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_DESTROY_CQ,				vhost_rdma_destroy_cq),
 	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_CREATE_PD,				vhost_rdma_create_pd),
 	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_DESTROY_PD,				vhost_rdma_destroy_pd),
+	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_GET_DMA_MR,				vhost_rdma_get_dma_mr),
+	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_ALLOC_MR,				vhost_rdma_alloc_mr),
+	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_REG_USER_MR,			vhost_rdma_reg_user_mr),
+	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_DEREG_MR,				vhost_rdma_dereg_mr),
 };
 
 /**
examples/vhost_user_rdma/vhost_rdma_ib.h +74 -0

97 lines not on this page · raw message

Signature · 1 line
2.43.0
#6 lore raw

PATCH 6/14 examples/vhost_user_rdma: implement comprehensive queue pair lifecycle management

In reply to Xiong Weimin

From: xiongweimin <[email protected]>

This commit adds core functionality for managing RDMA Queue Pairs (QPs):
1. QP creation with type-specific handling (RC/UC/UD/GSI)
2. QP state modification and validation
3. QP attribute querying
4. QP destruction with resource cleanup
5. Address vector to attribute conversion

Key features:
- Special handling for General Service Interface (GSI) QPs
- Detailed QP state tracking (RESET, INIT, RTR, RTS, SQD, ERROR)
- Timer management for reliable connections (retransmit, RNR NAK)
- Virtual queue initialization and cleanup
- Atomic reference counting for lifecycle management
- Comprehensive attribute reporting for QP query

Change-Id I6bc5d82867e49ac1bfd83993b28620f91f17ce4f
---
 examples/vhost_user_rdma/meson.build         |    2 +
 examples/vhost_user_rdma/vhost_rdma.h        |   70 +-
 examples/vhost_user_rdma/vhost_rdma_ib.c     |  284 ++++-
 examples/vhost_user_rdma/vhost_rdma_ib.h     |  255 ++++-
 examples/vhost_user_rdma/vhost_rdma_opcode.c |  894 +++++++++++++++
 examples/vhost_user_rdma/vhost_rdma_opcode.h |  330 ++++++
 examples/vhost_user_rdma/vhost_rdma_pkt.h    |  238 ----
 examples/vhost_user_rdma/vhost_rdma_queue.c  | 1056 ++++++++++++++++++
 examples/vhost_user_rdma/vhost_rdma_queue.h  |  338 ++++++
 9 files changed, 3169 insertions(+), 298 deletions(-)
 create mode 100644 examples/vhost_user_rdma/vhost_rdma_opcode.c
 create mode 100644 examples/vhost_user_rdma/vhost_rdma_opcode.h
 create mode 100644 examples/vhost_user_rdma/vhost_rdma_queue.c
 create mode 100644 examples/vhost_user_rdma/vhost_rdma_queue.h
examples/vhost_user_rdma/meson.build +2 -0
index d6ccaf32a4..a032a27767 100644
@@ -41,5 +41,7 @@ sources = files(
     'main.c',
     'vhost_rdma.c',
     'vhost_rdma_ib.c',
+    'vhost_rdma_queue.c',
+    'vhost_rdma_opcode.c',
 )
 
examples/vhost_user_rdma/vhost_rdma.h +55 -15

100 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_ib.c +265 -19

324 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_ib.h +229 -26

349 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_opcode.c new file +894 -0

895 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_opcode.h new file +330 -0

331 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_pkt.h +0 -238

244 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_queue.c new file +1056 -0

750 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_queue.h new file +338 -0

338 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.43.0

Part of the diff is not shown here. View the raw message.

#7 lore raw

PATCH 7/14 examples/vhost_user_rdma: Implement high-performance requester engine with advanced flow control

In reply to Xiong Weimin

From: xiongweimin <[email protected]>

This commit adds the core requester engine for RDMA operations:
1. Work Queue Element (WQE) processing state machine
2. Flow control with window-based congestion avoidance
3. MTU-aware packet segmentation
4. Error handling with automatic retry mechanisms
5. Atomic operation support and resource management

Key features:
- PSN-based flow control for reliable connections (RC)
- UD MTU handling with simulated success for oversize packets
- Work request state management (DONE, ERROR, RETRY)
- Packet construction and transmission pipeline
- Memory buffer (mbuf) accounting for congestion control
- Atomic reference counting for safe resource handling

Change-Id Ib0873f3d56ff71ed9f51e47edfa972054145f226
---
 examples/vhost_user_rdma/meson.build         |   2 +
 examples/vhost_user_rdma/vhost_rdma.h        |   9 +
 examples/vhost_user_rdma/vhost_rdma_crc.c    | 163 ++++
 examples/vhost_user_rdma/vhost_rdma_opcode.c | 141 +++-
 examples/vhost_user_rdma/vhost_rdma_opcode.h | 335 ++++++--
 examples/vhost_user_rdma/vhost_rdma_pkt.c    | 221 +++++
 examples/vhost_user_rdma/vhost_rdma_pkt.h    |  31 +-
 examples/vhost_user_rdma/vhost_rdma_queue.c  | 826 ++++++++++++++++++-
 examples/vhost_user_rdma/vhost_rdma_queue.h  | 221 ++++-
 9 files changed, 1855 insertions(+), 94 deletions(-)
 create mode 100644 examples/vhost_user_rdma/vhost_rdma_crc.c
 create mode 100644 examples/vhost_user_rdma/vhost_rdma_pkt.c
examples/vhost_user_rdma/meson.build +2 -0
index a032a27767..2a0a6ffc15 100644
@@ -43,5 +43,7 @@ sources = files(
     'vhost_rdma_ib.c',
     'vhost_rdma_queue.c',
     'vhost_rdma_opcode.c',
+    'vhost_rdma_pkt.c',
+    'vhost_rdma_crc.c',
 )
 
examples/vhost_user_rdma/vhost_rdma.h +9 -0
index 980bb74beb..bf772283b8 100644
@@ -72,6 +72,8 @@ extern "C" {
 #define VHOST_NET_RXQ 0
 #define VHOST_NET_TXQ 1
 
+#define ROCE_V2_UDP_DPORT 4791
+
 /* VIRTIO_F_EVENT_IDX is NOT supported now */
 #define VHOST_RDMA_FEATURE ((1ULL << VIRTIO_F_VERSION_1) |\
 	(1ULL << VIRTIO_RING_F_INDIRECT_DESC) | \
@@ -457,6 +459,13 @@ static inline enum vhost_rdma_network_type rdma_gid_attr_network_type(const stru
 		return VHOST_RDMA_NETWORK_IPV6;
 }
 
+static __rte_always_inline void
+vhost_rdma_counter_inc(struct vhost_rdma_device *dev,
+		       enum vhost_rdma_counters index)
+{
+	rte_atomic64_inc(&dev->stats_counters[index]);
+}
+
 int vhost_rdma_construct(struct vhost_rdma_device *dev, const char *path, int idx);
 void vhost_rdma_net_construct(struct vhost_user_queue *queues, int idx);
 void vs_vhost_rdma_net_setup(int vid);
examples/vhost_user_rdma/vhost_rdma_crc.c new file +163 -0

163 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_opcode.c +140 -1

146 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_opcode.h +261 -74

374 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_pkt.c new file +221 -0

221 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_pkt.h +25 -6
index e6a605f574..f012edd8ec 100644
@@ -22,9 +22,13 @@
 #include <stdint.h>
 #include <stddef.h>
 
+#include <netinet/in.h>
 #include <rte_byteorder.h>
 #include <rte_mbuf.h> /* For struct rte_mbuf if needed later */
 
+#include "vhost_rdma.h"
+#include "vhost_rdma_ib.h"
+
 /* Forward declarations */
 struct vhost_rdma_dev;
 struct vhost_rdma_qp;
@@ -34,16 +38,23 @@ struct vhost_rdma_send_wqe;
 #define BIT(x) (1U << (x))	/**< Generate bitmask from bit index */
 #endif
 
+#define ip_hdr(p) ((struct rte_ipv4_hdr*) \
+	(RTE_PTR_SUB(p->hdr, \
+		sizeof(struct rte_udp_hdr) + sizeof(struct rte_ipv4_hdr))))
+#define ipv6_hdr(p) ((struct rte_ipv6_hdr*) \
+	(RTE_PTR_SUB(p->hdr, \
+		sizeof(struct rte_udp_hdr) + sizeof(struct rte_ipv6_hdr))))
+
 /**
- * @defgroup constants Constants & Limits
- * @{
- */
+* @defgroup constants Constants & Limits
+* @{
+*/
 
 /**
- * @brief Runtime packet context used during processing
- */
+* @brief Runtime packet context used during processing
+*/
 struct vhost_rdma_pkt_info {
-	struct vhost_rdma_dev		*dev;			/**< Owning device */
+	struct vhost_rdma_device	*dev;			/**< Owning device */
 	struct vhost_rdma_qp		*qp;			/**< Associated QP */
 	struct vhost_rdma_send_wqe	*wqe;			/**< Corresponding send WQE (if applicable) */
 	uint8_t						*hdr;			/**< Pointer to BTH (Base Transport Header) */
@@ -55,4 +66,12 @@ struct vhost_rdma_pkt_info {
 	uint8_t						opcode;			/**< BTH opcode field */
 };
 
+int vhost_rdma_prepare(struct vhost_rdma_pkt_info *pkt,
+					struct rte_mbuf *m,
+					uint32_t *crc);
+
+uint32_t vhost_rdma_icrc_hdr(struct vhost_rdma_pkt_info *pkt, struct rte_mbuf *mbuf);
+
+uint32_t crc32(uint32_t crc, void* buf, uint32_t len);
+
 #endif /* __VHOST_RDMA_PKT_H__ */
\ No newline at end of file
examples/vhost_user_rdma/vhost_rdma_queue.c +824 -2

842 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_queue.h +210 -11

254 lines not on this page · raw message

Signature · 1 line
2.43.0
#8 lore raw

PATCH 8/14 examples/vhost_user_rdma: implement advanced completer engine with reliability features

In reply to Xiong Weimin

From: xiongweimin <[email protected]>

This commit adds the completer engine for RDMA operations with:
1. State machine for ACK packet processing
2. PSN-based sequence validation
3. Reliability mechanisms (retry, RNR backoff)
4. Atomic operation execution
5. Comprehensive error handling
6. Performance counters for diagnostics

Key features:
- 11-state processing pipeline for response handling
- Dynamic retransmission timer management
- RNR NAK timer for flow control
- Packet lifetime tracking (mbuf release)
- Work completion error propagation
- Congestion-aware task scheduling

Change-Id I12a7baf03edffcd66da7bdc84218001c6bf3a0de
---
 examples/vhost_user_rdma/meson.build          |   1 +
 .../vhost_user_rdma/vhost_rdma_complete.c     | 850 ++++++++++++++++++
 examples/vhost_user_rdma/vhost_rdma_opcode.h  | 437 +++++----
 examples/vhost_user_rdma/vhost_rdma_queue.c   |   6 -
 examples/vhost_user_rdma/vhost_rdma_queue.h   |   5 +
 5 files changed, 1096 insertions(+), 203 deletions(-)
 create mode 100644 examples/vhost_user_rdma/vhost_rdma_complete.c
examples/vhost_user_rdma/meson.build +1 -0
index 2a0a6ffc15..4948f709d9 100644
@@ -45,5 +45,6 @@ sources = files(
     'vhost_rdma_opcode.c',
     'vhost_rdma_pkt.c',
     'vhost_rdma_crc.c',
+    'vhost_rdma_complete.c',
 )
 
examples/vhost_user_rdma/vhost_rdma_complete.c new file +850 -0

850 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_opcode.h +240 -197

543 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_queue.c +0 -6
index 7d0c45592c..5f9f7fd3c7 100644
@@ -1388,12 +1388,6 @@ int vhost_rdma_requester(void *arg)
 	return -EAGAIN;
 }
 
-int vhost_rdma_completer(void* arg)
-{
-	//TODO: handle complete
-	return 0;
-}
-
 int vhost_rdma_responder(void* arg)
 {
 	//TODO: handle response
examples/vhost_user_rdma/vhost_rdma_queue.h +5 -0
index fb5a90235f..d8af86cdf2 100644
@@ -24,6 +24,11 @@
 #include "vhost_rdma.h"
 #include "vhost_rdma_log.h"
 
+#define PKT_TO_MBUF(p) ((struct rte_mbuf *) \
+			(RTE_PTR_SUB(p, sizeof(struct rte_mbuf))))
+#define MBUF_TO_PKT(m) ((struct vhost_rdma_pkt_info *) \
+			(RTE_PTR_ADD(m, sizeof(struct rte_mbuf))))
+
 #define QP_OPCODE_INVAILD (-1)
 
 /******************************************************************************
Signature · 1 line
2.43.0
#9 lore raw

PATCH 9/14 examples/vhost_user_rdma: implement P_Key query operation with default partition key

In reply to Xiong Weimin

From: xiongweimin <[email protected]>

This commit adds support for the IB_QUERY_PKEY command:
1. Implements mandatory InfiniBand partition key query
2. Provides default full-membership P_Key (0xFFFF)
3. Includes I/O vector safety validation
4. Maintains compatibility with standard IB management tools

Key features:
- Hardcoded default P_Key for simplified management
- Buffer size validation using CHK_IOVEC macro
- Zero-copy response writing via iovec
- Minimal overhead for frequent management operations

Change-Id Ibc7be3488989285da205aff7400be38995a435fd
---
 examples/vhost_user_rdma/meson.build     | 52 ++++++++++++------------
 examples/vhost_user_rdma/vhost_rdma_ib.c | 46 ++++++++++++++-------
 examples/vhost_user_rdma/vhost_rdma_ib.h |  4 ++
 3 files changed, 61 insertions(+), 41 deletions(-)
examples/vhost_user_rdma/meson.build +26 -26
index 4948f709d9..89ff4fbbf1 100644
@@ -7,8 +7,8 @@
 # DPDK instance, use 'make'
 
 if not is_linux
-    build = false
-    subdir_done()
+	build = false
+	subdir_done()
 endif
 
 deps += ['vhost', 'timer']
@@ -16,35 +16,35 @@ deps += ['vhost', 'timer']
 allow_experimental_apis = true
 
 cflags_options = [
-        '-std=c11',
-        '-Wno-strict-prototypes',
-        '-Wno-pointer-arith',
-        '-Wno-maybe-uninitialized',
-        '-Wno-discarded-qualifiers',
-        '-Wno-old-style-definition',
-        '-Wno-sign-compare',
-        '-Wno-stringop-overflow',
-        '-O3',
-        '-g',
-        '-DALLOW_EXPERIMENTAL_API',
-        '-DDEBUG_RDMA',
-        '-DDEBUG_RDMA_DP',
+	'-std=c11',
+	'-Wno-strict-prototypes',
+	'-Wno-pointer-arith',
+	'-Wno-maybe-uninitialized',
+	'-Wno-discarded-qualifiers',
+	'-Wno-old-style-definition',
+	'-Wno-sign-compare',
+	'-Wno-stringop-overflow',
+	'-O3',
+	'-g',
+	'-DALLOW_EXPERIMENTAL_API',
+	'-DDEBUG_RDMA',
+	'-DDEBUG_RDMA_DP',
 ]
 
 foreach option:cflags_options
-    if cc.has_argument(option)
-        cflags += option
-    endif
+	if cc.has_argument(option)
+		cflags += option
+	endif
 endforeach
 
 sources = files(
-    'main.c',
-    'vhost_rdma.c',
-    'vhost_rdma_ib.c',
-    'vhost_rdma_queue.c',
-    'vhost_rdma_opcode.c',
-    'vhost_rdma_pkt.c',
-    'vhost_rdma_crc.c',
-    'vhost_rdma_complete.c',
+	'main.c',
+	'vhost_rdma.c',
+	'vhost_rdma_ib.c',
+	'vhost_rdma_queue.c',
+	'vhost_rdma_opcode.c',
+	'vhost_rdma_pkt.c',
+	'vhost_rdma_crc.c',
+	'vhost_rdma_complete.c',
 )
 
examples/vhost_user_rdma/vhost_rdma_ib.c +31 -15

63 lines not on this page · raw message

examples/vhost_user_rdma/vhost_rdma_ib.h +4 -0
index 79575e735c..5a1787fabe 100644
@@ -957,6 +957,10 @@ struct vhost_rdma_cmd_destroy_qp {
 	uint32_t qpn;
 };
 
+struct vhost_rdma_cmd_query_pkey{
+	uint16_t pkey;
+};
+
 /**
  * @brief Convert IB MTU enum to byte size
  * @param mtu The MTU enum value
Signature · 1 line
2.43.0
#10 lore raw

PATCH 1/1 hw/rdma: Implement vhost-user RDMA device with PCI support

In reply to Xiong Weimin

From: xiongweimin <[email protected]>

This commit introduces a complete vhost-user RDMA device implementation including PCI interface bindings. The implementation enables RDMA operations through a vhost-user backend and provides a PCI device interface for guests.

Key components included:
1. PCI device binding layer:
- Automatic MSI-X vector allocation (queues + 1)
- Virtio 1.0 compliance (no legacy support)
- Standard Red Hat vendor/device IDs
- Bootindex property passthrough
- Transitional/non-transitional device variants

2. Core vhost-user RDMA device:
- Chardev-based backend communication
- Dynamic connection management with reconnect
- 256 virtqueues (512 entries each)
- Feature negotiation (VIRTIO_F_VERSION_1, INDIRECT_DESC, etc.)
- Config space handling with live updates
- VM state preservation for migration
- Graceful start/stop sequences
- Host notifier management

3. Key functionalities:
- Automatic backend connection management
- Config change notification handling
- Queue enablement on guest activity
- Error handling for backend disconnections
- Resource cleanup on device unrealize

The implementation follows virtio and vhost-user standards, providing a foundation for RDMA virtualization using user-space backends.

Change-Id I3299219282bc98800422e132298006ed1b3637da
---
 hw/rdma/Kconfig                             |   5 +
 hw/rdma/meson.build                         |   5 +
 hw/rdma/vhost-user-rdma.c                   | 463 ++++++++++++++++++++
 hw/virtio/meson.build                       |   1 +
 hw/virtio/vhost-user-rdma-pci.c             |  93 ++++
 hw/virtio/vhost-user.c                      |  11 +
 hw/virtio/vhost.c                           |   2 +
 hw/virtio/virtio.c                          |   1 +
 include/hw/pci/pci.h                        |   1 +
 include/hw/virtio/vhost-user-rdma.h         |  43 ++
 include/hw/virtio/virtio.h                  |   2 +-
 include/standard-headers/linux/virtio_ids.h |   1 +
 include/standard-headers/rdma/virtio_rdma.h |  60 +++
 13 files changed, 687 insertions(+), 1 deletion(-)
 create mode 100644 hw/rdma/vhost-user-rdma.c
 create mode 100644 hw/virtio/vhost-user-rdma-pci.c
 create mode 100644 include/hw/virtio/vhost-user-rdma.h
 create mode 100644 include/standard-headers/rdma/virtio_rdma.h
hw/rdma/Kconfig +5 -0
index 840320bdc0..1cb7ee72ab 100644
@@ -1,3 +1,8 @@
 config VMW_PVRDMA
     default y if PCI_DEVICES
     depends on PVRDMA && MSI_NONBROKEN && VMXNET3_PCI
+
+config VHOST_USER_RDMA
+    bool
+    default y if VIRTIO_PCI
+    depends on VIRTIO && VHOST_USER && LINUX
hw/rdma/meson.build +5 -0
index 363c9b8c83..51c47b2d44 100644
@@ -10,3 +10,8 @@ specific_ss.add(when: 'CONFIG_VMW_PVRDMA', if_true: files(
   'vmw/pvrdma_dev_ring.c',
   'vmw/pvrdma_main.c',
 ))
+
+
+specific_ss.add(when: 'CONFIG_VHOST_USER_RDMA', if_true: files(
+  'vhost-user-rdma.c',
+))
hw/rdma/vhost-user-rdma.c new file +463 -0

463 lines not on this page · raw message

hw/virtio/meson.build +1 -0
index d7f18c96e6..3f0a7da910 100644
@@ -63,6 +63,7 @@ virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c'
 virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-user-vsock-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-blk-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_SCSI', if_true: files('vhost-user-scsi-pci.c'))
+virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_RDMA', if_true: files('vhost-user-rdma-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('vhost-scsi-pci.c'))
 virtio_pci_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs-pci.c'))
 
hw/virtio/vhost-user-rdma-pci.c new file +93 -0

93 lines not on this page · raw message

hw/virtio/vhost-user.c +11 -0
index cdf9af4a4b..eb0813bddd 100644
@@ -460,6 +460,7 @@ static int vhost_user_set_log_base(struct vhost_dev *dev, uint64_t base,
     }
 
     if (shmfd) {
+        error_report("vhost_user_read: vhost_user_set_log_base");
         msg.hdr.size = 0;
         ret = vhost_user_read(dev, &msg);
         if (ret < 0) {
@@ -753,6 +754,7 @@ static int send_add_regions(struct vhost_dev *dev,
             if (track_ramblocks) {
                 uint64_t reply_gpa;
 
+                error_report("vhost_user_read: send_add_regions");
                 ret = vhost_user_read(dev, &msg_reply);
                 if (ret < 0) {
                     return ret;
@@ -930,6 +932,7 @@ static int vhost_user_set_mem_table_postcopy(struct vhost_dev *dev,
             return ret;
         }
 
+        error_report("vhost_user_read: vhost_user_set_mem_table_postcopy");
         ret = vhost_user_read(dev, &msg_reply);
         if (ret < 0) {
             return ret;
@@ -1287,6 +1290,7 @@ static int vhost_user_get_vring_base(struct vhost_dev *dev,
         return ret;
     }
 
+    error_report("vhost_user_read: vhost_user_get_vring_base");
     ret = vhost_user_read(dev, &msg);
     if (ret < 0) {
         return ret;
@@ -1433,6 +1437,7 @@ static int vhost_user_set_features(struct vhost_dev *dev,
      * VHOST_USER_F_PROTOCOL_FEATURES bit for enabling protocol
      * features.
      */
+
     ret = vhost_user_set_u64(dev, VHOST_USER_SET_FEATURES,
                               features | dev->backend_features,
                               log_enabled);
@@ -1673,6 +1678,7 @@ int vhost_user_get_shared_object(struct vhost_dev *dev, unsigned char *uuid,
         return ret;
     }
 
+    error_report("vhost_user_read: vhost_user_get_shared_object");
     ret = vhost_user_read(dev, &msg);
     if (ret < 0) {
         return ret;
@@ -1998,6 +2004,7 @@ static int vhost_user_postcopy_advise(struct vhost_dev *dev, Error **errp)
         return ret;
     }
 
+    error_report("vhost_user_read: vhost_user_postcopy_advise");
     ret = vhost_user_read(dev, &msg);
     if (ret < 0) {
         error_setg(errp, "Failed to get postcopy_advise reply from vhost");
@@ -2435,6 +2442,7 @@ static int vhost_user_get_config(struct vhost_dev *dev, uint8_t *config,
         return ret;
     }
 
+    error_report("vhost_user_read: vhost_user_get_config");
     ret = vhost_user_read(dev, &msg);
     if (ret < 0) {
         error_setg_errno(errp, -ret, "vhost_get_config failed");
@@ -2578,6 +2586,7 @@ static int vhost_user_crypto_create_session(struct vhost_dev *dev,
         return ret;
     }
 
+    error_report("vhost_user_read: vhost_user_crypto_create_session");
     ret = vhost_user_read(dev, &msg);
     if (ret < 0) {
         error_report("vhost_user_read() return %d, create session failed",
@@ -2923,6 +2932,7 @@ static int vhost_user_set_device_state_fd(struct vhost_dev *dev,
         return ret;
     }
 
+    error_report("vhost_user_read: vhost_user_set_device_state_fd");
     ret = vhost_user_read(dev, &msg);
     if (ret < 0) {
         error_setg_errno(errp, -ret,
@@ -2985,6 +2995,7 @@ static int vhost_user_check_device_state(struct vhost_dev *dev, Error **errp)
         return ret;
     }
 
+    error_report("vhost_user_read: vhost_user_check_device_state");
     ret = vhost_user_read(dev, &msg);
     if (ret < 0) {
         error_setg_errno(errp, -ret,
hw/virtio/vhost.c +2 -0
index f50180e60e..87cec36828 100644
@@ -934,6 +934,7 @@ static int vhost_dev_set_features(struct vhost_dev *dev,
             features |= 0x1ULL << VIRTIO_F_IOMMU_PLATFORM;
        }
     }
+
     r = dev->vhost_ops->vhost_set_features(dev, features);
     if (r < 0) {
         VHOST_OPS_DEBUG(r, "vhost_set_features failed");
@@ -1804,6 +1805,7 @@ void vhost_ack_features(struct vhost_dev *hdev, const int *feature_bits,
                         uint64_t features)
 {
     const int *bit = feature_bits;
+    info_report("vhost_ack_features");
     while (*bit != VHOST_INVALID_FEATURE_BIT) {
         uint64_t bit_mask = (1ULL << *bit);
         if (features & bit_mask) {
hw/virtio/virtio.c +1 -0
index fd2dfe3a6b..bee7156e6d 100644
@@ -181,6 +181,7 @@ const char *virtio_device_names[] = {
     [VIRTIO_ID_FS] = "virtio-user-fs",
     [VIRTIO_ID_PMEM] = "virtio-pmem",
     [VIRTIO_ID_RPMB] = "virtio-rpmb",
+    [VIRTIO_ID_RDMA] = "virtio-rdma",
     [VIRTIO_ID_MAC80211_HWSIM] = "virtio-mac-hwsim",
     [VIRTIO_ID_VIDEO_ENCODER] = "virtio-vid-encoder",
     [VIRTIO_ID_VIDEO_DECODER] = "virtio-vid-decoder",
include/hw/pci/pci.h +1 -0
index eaa3fc99d8..a1eccfb78b 100644
@@ -85,6 +85,7 @@ extern bool pci_available;
 #define PCI_DEVICE_ID_VIRTIO_RNG         0x1005
 #define PCI_DEVICE_ID_VIRTIO_9P          0x1009
 #define PCI_DEVICE_ID_VIRTIO_VSOCK       0x1012
+#define PCI_DEVICE_ID_VIRTIO_RDMA        0x1016
 
 /*
  * modern virtio-pci devices get their id assigned automatically,
include/hw/virtio/vhost-user-rdma.h new file +43 -0

43 lines not on this page · raw message

include/hw/virtio/virtio.h +1 -1
index 7d5ffdc145..f74da61477 100644
@@ -369,7 +369,7 @@ typedef struct VirtIORNGConf VirtIORNGConf;
     DEFINE_PROP_BIT64("packed", _state, _field, \
                       VIRTIO_F_RING_PACKED, false), \
     DEFINE_PROP_BIT64("queue_reset", _state, _field, \
-                      VIRTIO_F_RING_RESET, true)
+                      VIRTIO_F_RING_RESET, false)
 
 hwaddr virtio_queue_get_desc_addr(VirtIODevice *vdev, int n);
 bool virtio_queue_enabled_legacy(VirtIODevice *vdev, int n);
include/standard-headers/linux/virtio_ids.h +1 -0
index 7aa2eb7662..ff2d0b01b4 100644
@@ -68,6 +68,7 @@
 #define VIRTIO_ID_AUDIO_POLICY		39 /* virtio audio policy */
 #define VIRTIO_ID_BT			40 /* virtio bluetooth */
 #define VIRTIO_ID_GPIO			41 /* virtio gpio */
+#define VIRTIO_ID_RDMA          42 /* virtio rdma */
 
 /*
  * Virtio Transitional IDs
include/standard-headers/rdma/virtio_rdma.h new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
2.43.0