From: Xiong Weimin <15927021679@163.com>
To: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Jesper Dangaard Brouer <hawk@kernel.org>,
John Fastabend <john.fastabend@gmail.com>,
Stanislav Fomichev <sdf@fomichev.me>
Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
xiongweimin <xiongweimin@kylinos.cn>
Subject: [PATCH 09/14] examples/vhost_user_rdma: implement P_Key query operation with default partition key
Date: Wed, 17 Dec 2025 16:43:35 +0800 [thread overview]
Message-ID: <20251217084422.4875-11-15927021679@163.com> (raw)
In-Reply-To: <20251217084422.4875-1-15927021679@163.com>
From: xiongweimin <xiongweimin@kylinos.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@kylinos.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
next prev parent reply other threads:[~2025-12-17 8:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-17 8:43 Implement initial driver for virtio-RDMA devices(kernel), virtio-rdma device model(qemu) and vhost-user-RDMA backend device(dpdk) Xiong Weimin
2025-12-17 8:43 ` [PATCH 01/14] examples/vhost_user_rdma: implement core application initialization for supporting vhost_user_rdma device Xiong Weimin
2025-12-17 8:43 ` [PATCH] hw/rdma: Implement vhost-user RDMA device with PCI support Xiong Weimin
2025-12-17 8:43 ` [PATCH 02/14] examples/vhost_user_rdma: implement device and port query commands Xiong Weimin
2025-12-17 8:43 ` [PATCH 03/14] examples/vhost_user_rdma: implement create and destroy completion queue commands Xiong Weimin
2025-12-17 8:43 ` [PATCH 04/14] examples/vhost_user_rdma: implement protection domain create/destroy commands Xiong Weimin
2025-12-17 8:43 ` [PATCH 05/14] examples/vhost_user_rdma: implement comprehensive memory region management Xiong Weimin
2025-12-17 8:43 ` [PATCH 06/14] examples/vhost_user_rdma: implement comprehensive queue pair lifecycle management Xiong Weimin
2025-12-17 8:43 ` [PATCH 07/14] examples/vhost_user_rdma: Implement high-performance requester engine with advanced flow control Xiong Weimin
2025-12-17 8:43 ` [PATCH 08/14] examples/vhost_user_rdma: implement advanced completer engine with reliability features Xiong Weimin
2025-12-17 8:43 ` Xiong Weimin [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-12-17 8:49 Implement initial driver for virtio-RDMA devices(kernel), virtio-rdma device model(qemu) and vhost-user-RDMA backend device(dpdk) Xiong Weimin
2025-12-17 8:49 ` [PATCH 09/14] examples/vhost_user_rdma: implement P_Key query operation with default partition key Xiong Weimin
2025-12-17 8:05 Implement initial driver for virtio-RDMA devices(kernel), virtio-rdma device model(qemu) and vhost-user-RDMA backend device(dpdk) 15927021679
2025-12-17 8:05 ` [PATCH 09/14] examples/vhost_user_rdma: implement P_Key query operation with default partition key 15927021679
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251217084422.4875-11-15927021679@163.com \
--to=15927021679@163.com \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=hawk@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sdf@fomichev.me \
--cc=xiongweimin@kylinos.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox