lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251217084422.4875-11-15927021679@163.com>
Date: Wed, 17 Dec 2025 16:43:35 +0800
From: Xiong Weimin <15927021679@....com>
To: Alexei Starovoitov <ast@...nel.org>,
	Daniel Borkmann <daniel@...earbox.net>,
	"David S . Miller" <davem@...emloft.net>,
	Jakub Kicinski <kuba@...nel.org>,
	Jesper Dangaard Brouer <hawk@...nel.org>,
	John Fastabend <john.fastabend@...il.com>,
	Stanislav Fomichev <sdf@...ichev.me>
Cc: linux-kernel@...r.kernel.org,
	netdev@...r.kernel.org,
	xiongweimin <xiongweimin@...inos.cn>
Subject: [PATCH 09/14] examples/vhost_user_rdma: implement P_Key query operation with default partition key

From: xiongweimin <xiongweimin@...inos.cn>

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

Signed-off-by: Xiong Weimin <xiongweimin@...inos.cn>
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(-)

diff --git a/examples/vhost_user_rdma/meson.build b/examples/vhost_user_rdma/meson.build
index 4948f709d9..89ff4fbbf1 100644
--- a/examples/vhost_user_rdma/meson.build
+++ b/examples/vhost_user_rdma/meson.build
@@ -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',
 )
 
diff --git a/examples/vhost_user_rdma/vhost_rdma_ib.c b/examples/vhost_user_rdma/vhost_rdma_ib.c
index aac5c28e9a..437d45c5ce 100644
--- a/examples/vhost_user_rdma/vhost_rdma_ib.c
+++ b/examples/vhost_user_rdma/vhost_rdma_ib.c
@@ -36,7 +36,7 @@
 		tp = iov->iov_base; \
 	} while(0); \
 
-#define DEFINE_VIRTIO_RDMA_CMD(cmd, handler) [cmd] = {handler, #cmd}
+#define DEFINE_VHOST_RDMA_CMD(cmd, handler) [cmd] = {handler, #cmd}
 
 #define CTRL_NO_CMD __rte_unused struct iovec *__in
 #define CTRL_NO_RSP __rte_unused struct iovec *__out
@@ -1089,25 +1089,41 @@ vhost_rdma_destroy_qp(struct vhost_rdma_device *dev, struct iovec *in, CTRL_NO_R
 	return 0;
 }
 
+static int
+vhost_rdma_query_pkey(__rte_unused struct vhost_rdma_device *dev,
+					CTRL_NO_CMD, struct iovec *out)
+{
+	struct vhost_rdma_cmd_query_pkey *pkey_rsp;
+	uint16_t pkey = IB_DEFAULT_PKEY_FULL;
+
+	CHK_IOVEC(pkey_rsp, out);
+
+	pkey_rsp->pkey = pkey;
+
+	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_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),
-	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),
-	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_CREATE_QP,				vhost_rdma_create_qp),
-	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_MODIFY_QP,				vhost_rdma_modify_qp),
-	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_QUERY_QP,				vhost_rdma_query_qp),
-	DEFINE_VIRTIO_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_DESTROY_QP,				vhost_rdma_destroy_qp),
+	DEFINE_VHOST_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_QUERY_DEVICE,			vhost_rdma_query_device),
+	DEFINE_VHOST_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_QUERY_PORT,				vhost_rdma_query_port),
+	DEFINE_VHOST_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_CREATE_CQ,				vhost_rdma_create_cq),
+	DEFINE_VHOST_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_DESTROY_CQ,				vhost_rdma_destroy_cq),
+	DEFINE_VHOST_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_CREATE_PD,				vhost_rdma_create_pd),
+	DEFINE_VHOST_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_DESTROY_PD,				vhost_rdma_destroy_pd),
+	DEFINE_VHOST_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_GET_DMA_MR,				vhost_rdma_get_dma_mr),
+	DEFINE_VHOST_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_ALLOC_MR,				vhost_rdma_alloc_mr),
+	DEFINE_VHOST_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_REG_USER_MR,				vhost_rdma_reg_user_mr),
+	DEFINE_VHOST_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_DEREG_MR,				vhost_rdma_dereg_mr),
+	DEFINE_VHOST_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_CREATE_QP,				vhost_rdma_create_qp),
+	DEFINE_VHOST_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_MODIFY_QP,				vhost_rdma_modify_qp),
+	DEFINE_VHOST_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_QUERY_QP,				vhost_rdma_query_qp),
+	DEFINE_VHOST_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_DESTROY_QP,				vhost_rdma_destroy_qp),
+	DEFINE_VHOST_RDMA_CMD(VHOST_RDMA_CTRL_ROCE_QUERY_PKEY,				vhost_rdma_query_pkey),
 };
 
 /**
diff --git a/examples/vhost_user_rdma/vhost_rdma_ib.h b/examples/vhost_user_rdma/vhost_rdma_ib.h
index 79575e735c..5a1787fabe 100644
--- a/examples/vhost_user_rdma/vhost_rdma_ib.h
+++ b/examples/vhost_user_rdma/vhost_rdma_ib.h
@@ -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
-- 
2.43.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ