Add basic test for nvme uring passthrough commands
A message that is not in the archive (sent off-list or not yet received): CGME20220728093902epcas5p40813f72b828e68e192f98819d29b2863@epcas5p4.samsung.com
v3 cover Add basic test for nvme uring passthrough commands
This patchset adds a way to test NVMe uring passthrough commands with nvme-ns character device. The uring passthrough was introduced with 5.19 io_uring.
To send nvme uring passthrough commands we require helpers to fetch NVMe char device (/dev/ngXnY) specific fields such as namespace id, lba size etc.
How to run:
./test/io_uring_passthrough.t /dev/ng0n1
It requires argument to be NVMe device, if not the test will be skipped.
The test covers write/read with verify for sqthread poll, vectored / nonvectored and fixed IO buffers, which can be extended in future. As of now iopoll is not supported for passthrough commands, there is a test for such case.
Changes from v2 to v3
- Skip test if argument is not nvme device and remove prints, as suggested by Jens.
- change nvme helper function name, as pointed by Jens.
- Remove wrong comment about command size, as per Kanchan's review
Ankit Kumar (5):
configure: check for nvme uring command support io_uring.h: sync sqe entry with 5.20 io_uring
nvme: add nvme opcodes, structures and helper functions
test: add io_uring passthrough test test/io_uring_passthrough: add test case for poll IO
configure | 20 ++ src/include/liburing/io_uring.h | 17 +- test/Makefile | 1 + test/io_uring_passthrough.c | 390 ++++++++++++++++++++++++++++++++ test/nvme.h | 168 ++++++++++++++ 5 files changed, 594 insertions(+), 2 deletions(-) create mode 100644 test/io_uring_passthrough.c create mode 100644 test/nvme.h
Signature · 1 line
2.17.1
PATCH v3 1/5 configure: check for nvme uring command support
Modify configure to check availability of nvme_uring_cmd. The follow up patch will have uring passthrough tests.
--- configure | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
configure +20 -0
@@ -367,6 +367,23 @@ if compile_prog "" "" "has_ucontext"; then fi print_config "has_ucontext" "$has_ucontext" +########################################## +# Check NVME_URING_CMD support +nvme_uring_cmd="no" +cat > $TMPC << EOF +#include <linux/nvme_ioctl.h> +int main(void) +{ + struct nvme_uring_cmd *cmd; + + return sizeof(struct nvme_uring_cmd); +} +EOF +if compile_prog "" "" "nvme uring cmd"; then + nvme_uring_cmd="yes" +fi +print_config "NVMe uring command support" "$nvme_uring_cmd" + ############################################################################# if test "$liburing_nolibc" = "yes"; then output_sym "CONFIG_NOLIBC"
@@ -402,6 +419,9 @@ fi if test "$array_bounds" = "yes"; then output_sym "CONFIG_HAVE_ARRAY_BOUNDS" fi +if test "$nvme_uring_cmd" = "yes"; then + output_sym "CONFIG_HAVE_NVME_URING" +fi echo "CC=$cc" >> $config_host_mak print_config "CC" "$cc"
Signature · 1 line
2.17.1
PATCH v3 2/5 io_uring.h: sync sqe entry with 5.20 io_uring
In reply to Ankit KumarAdd a few missing fields which was added for uring command
--- src/include/liburing/io_uring.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
src/include/liburing/io_uring.h +15 -2
@@ -26,6 +26,10 @@ struct io_uring_sqe {union {__u64 off;/* offset into file */ __u64 addr2; +struct { +__u32 cmd_op; +__u32 __pad1; + }; };union {__u64 addr;/* pointer to buffer or iovecs */
@@ -69,8 +73,17 @@ struct io_uring_sqe {__u16 addr_len; }; }; -__u64 addr3; -__u64 __pad2[1 ]; +union { +struct { +__u64 addr3; +__u64 __pad2[1 ]; + }; +/* +* If the ring is initialized with IORING_SETUP_SQE128, then +* this field is used for 80 bytes of arbitrary command data +*/ +__u8 cmd[0 ]; + }; };/*
Signature · 1 line
2.17.1
PATCH v3 3/5 nvme: add nvme opcodes, structures and helper functions
In reply to Ankit KumarAdd bare minimum structures and helper functions required for io_uring passthrough commands. This will enable the follow up patch to add tests for nvme-ns generic character device.
--- test/nvme.h | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 test/nvme.h
test/nvme.h new file +168 -0
@@ -0,0 +1,168 @@ +/* SPDX-License-Identifier: MIT */ +/* +* Description: Helpers for NVMe uring passthrough commands +*/ +#ifndef LIBURING_NVME_H +#define LIBURING_NVME_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <sys/ioctl.h> +#include <linux/nvme_ioctl.h> + +/* +* If the uapi headers installed on the system lacks nvme uring command +* support, use the local version to prevent compilation issues. +*/ +#ifndef CONFIG_HAVE_NVME_URING +struct nvme_uring_cmd { +__u8 opcode; +__u8 flags; +__u16 rsvd1; +__u32 nsid; +__u32 cdw2; +__u32 cdw3; +__u64 metadata; +__u64 addr; +__u32 metadata_len; +__u32 data_len; +__u32 cdw10; +__u32 cdw11; +__u32 cdw12; +__u32 cdw13; +__u32 cdw14; +__u32 cdw15; +__u32 timeout_ms; +__u32 rsvd2; +}; + +#define NVME_URING_CMD_IO _IOWR('N', 0x80, struct nvme_uring_cmd) +#define NVME_URING_CMD_IO_VEC _IOWR('N', 0x81, struct nvme_uring_cmd) +#endif /* CONFIG_HAVE_NVME_URING */ + +#define NVME_DEFAULT_IOCTL_TIMEOUT 0 +#define NVME_IDENTIFY_DATA_SIZE 4096 +#define NVME_IDENTIFY_CSI_SHIFT 24 +#define NVME_IDENTIFY_CNS_NS 0 +#define NVME_CSI_NVM 0 + +enum nvme_admin_opcode { + nvme_admin_identify =0x06 , +}; + +enum nvme_io_opcode { + nvme_cmd_write =0x01 , + nvme_cmd_read =0x02 , +}; + +int nsid; +__u32 lba_shift; + +struct nvme_lbaf { +__le16 ms; +__u8 ds; +__u8 rp; +}; + +struct nvme_id_ns { +__le64 nsze; +__le64 ncap; +__le64 nuse; +__u8 nsfeat; +__u8 nlbaf; +__u8 flbas; +__u8 mc; +__u8 dpc; +__u8 dps; +__u8 nmic; +__u8 rescap; +__u8 fpi; +__u8 dlfeat; +__le16 nawun; +__le16 nawupf; +__le16 nacwu; +__le16 nabsn; +__le16 nabo; +__le16 nabspf; +__le16 noiob; +__u8 nvmcap[16 ]; +__le16 npwg; +__le16 npwa; +__le16 npdg; +__le16 npda; +__le16 nows; +__le16 mssrl; +__le32 mcl; +__u8 msrc; +__u8 rsvd81[11 ]; +__le32 anagrpid; +__u8 rsvd96[3 ]; +__u8 nsattr; +__le16 nvmsetid; +__le16 endgid; +__u8 nguid[16 ]; +__u8 eui64[8 ]; +struct nvme_lbaf lbaf[16 ]; +__u8 rsvd192[192 ]; +__u8 vs[3712 ]; +}; + +static inline int ilog2 (uint32_t i) +{ +int log =-1 ; + +while (i) { + i >>=1 ; + log++; + } +return log; +} + +int nvme_get_info (const char *file) +{ +struct nvme_id_ns ns; +int fd, err; +__u32 lba_size; + + fd =open (file,O_RDONLY ); +if (fd <0 ) { +perror ("file open" ); +return -errno; + } + + nsid =ioctl (fd,NVME_IOCTL_ID ); +if (nsid <0 ) { +close (fd); +return -errno; + } + +struct nvme_passthru_cmd cmd = { + .opcode = nvme_admin_identify, + .nsid = nsid, + .addr = (__u64)(uintptr_t)&ns, + .data_len =NVME_IDENTIFY_DATA_SIZE , + .cdw10 =NVME_IDENTIFY_CNS_NS , + .cdw11 =NVME_CSI_NVM <<NVME_IDENTIFY_CSI_SHIFT , + .timeout_ms =NVME_DEFAULT_IOCTL_TIMEOUT , + }; + + err =ioctl (fd,NVME_IOCTL_ADMIN_CMD , &cmd); +if (err) { +close (fd); +return err; + } + + lba_size =1 << ns.lbaf[(ns.flbas &0x0f )].ds; + lba_shift =ilog2 (lba_size); + +close (fd); +return 0 ; +} + +#ifdef __cplusplus +} +#endif + +#endif
Signature · 1 line
2.17.1
PATCH v3 4/5 test: add io_uring passthrough test
In reply to Ankit KumarAdd a way to test uring passthrough commands, which was added with 5.19 kernel. This requires nvme-ns character device (/dev/ngXnY) as filename argument. It runs a combination of read/write tests with sqthread poll, vectored and non-vectored commands, fixed I/O buffers.
--- test/Makefile | 1 + test/io_uring_passthrough.c | 314 ++++++++++++++++++++++++++++++++++++ 2 files changed, 315 insertions(+) create mode 100644 test/io_uring_passthrough.c
test/Makefile +1 -0
@@ -90,6 +90,7 @@ test_srcs := \ io-cancel.c \ iopoll.c \ io_uring_enter.c \ + io_uring_passthrough.c \ io_uring_register.c \ io_uring_setup.c \ lfs-openat.c \
test/io_uring_passthrough.c new file +314 -0
314 lines not on this page · raw message
Signature · 1 line
2.17.1
Jens Axboe
maintainerQuoted 16 lines · Ankit Kumar
This patchset adds a way to test NVMe uring passthrough commands with nvme-ns character device. The uring passthrough was introduced with 5.19
io_uring.To send nvme uring passthrough commands we require helpers to fetch NVMe char device (
/dev/ngXnY) specific fields such as namespace id, lba size etc.How to run:
./test/io_uring_passthrough.t/dev/ng0n1It requires argument to be NVMe device, if not the test will be skipped.
The test covers write/read with verify for sqthread poll, vectored / nonvectored and fixed IO buffers, which can be extended in future. As of now iopoll is not supported for passthrough commands, there is a test for such case.
Quoted 5 lines
Changes from v2 to v3
- Skip test if argument is not nvme device and remove prints, as suggested by Jens.
- change nvme helper function name, as pointed by Jens.
- Remove wrong comment about command size, as per Kanchan's review
I didn't get patch 2/5, and lore didn't either. Can you resend the series?
Signature · 1 line
Jens Axboe
Quoted 17 lines · Jens Axboe
Quoted 16 lines · Ankit Kumar
This patchset adds a way to test NVMe uring passthrough commands with nvme-ns character device. The uring passthrough was introduced with 5.19
io_uring.To send nvme uring passthrough commands we require helpers to fetch NVMe char device (
/dev/ngXnY) specific fields such as namespace id, lba size etc.How to run:
./test/io_uring_passthrough.t/dev/ng0n1It requires argument to be NVMe device, if not the test will be skipped.
The test covers write/read with verify for sqthread poll, vectored / nonvectored and fixed IO buffers, which can be extended in future. As of now iopoll is not supported for passthrough commands, there is a test for such case.
Quoted 12 lines
Quoted 5 lines
Changes from v2 to v3
- Skip test if argument is not nvme device and remove prints, as suggested by Jens.
- change nvme helper function name, as pointed by Jens.
- Remove wrong comment about command size, as per Kanchan's reviewI didn't get patch 2/5, and lore didn't either. Can you resend the series?
Signature · 1 line
Jens Axboe
Sorry, issue from my side it. You should have 2/5 now and I see its there in lore as well. Hope its sufficient and doesn't require me to resend the entire series again.
Jens Axboe
maintainerQuoted 26 lines · Ankit Kumar
Quoted 25 lines · Jens Axboe
Quoted 16 lines · Ankit Kumar
This patchset adds a way to test NVMe uring passthrough commands with nvme-ns character device. The uring passthrough was introduced with 5.19
io_uring.To send nvme uring passthrough commands we require helpers to fetch NVMe char device (
/dev/ngXnY) specific fields such as namespace id, lba size etc.How to run:
./test/io_uring_passthrough.t/dev/ng0n1It requires argument to be NVMe device, if not the test will be skipped.
The test covers write/read with verify for sqthread poll, vectored / nonvectored and fixed IO buffers, which can be extended in future. As of now iopoll is not supported for passthrough commands, there is a test for such case.
Quoted 5 lines
Changes from v2 to v3
- Skip test if argument is not nvme device and remove prints, as suggested by Jens.
- change nvme helper function name, as pointed by Jens.
- Remove wrong comment about command size, as per Kanchan's reviewI didn't get patch 2/5, and lore didn't either. Can you resend the series?
Quoted 7 lines
Quoted 4 lines
Signature · 1 line
Jens AxboeSorry, issue from my side it. You should have 2/5 now and I see its there in lore as well. Hope its sufficient and doesn't require me to resend the entire series again.
Yep I got it, and I've now applied it. Did a few cleanups on top, but nothing major. Thanks!
Signature · 1 line
Jens Axboe
PATCH v3 5/5 test/io_uring_passthrough: add test case for poll IO
In reply to Ankit KumarFor uring passthrough add test case for poll IO completion. If poll IO is not supported return success.
--- test/io_uring_passthrough.c | 76 +++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+)
test/io_uring_passthrough.c +76 -0
@@ -10,6 +10,7 @@#include "helpers.h" #include "liburing.h" +#include "../src/syscall.h" #include "nvme.h" #define FILE_SIZE (256 * 1024)
@@ -278,6 +279,75 @@ static int test_io(const char *file, int tc, int read, int sqthread,return ret; } +extern int __io_uring_flush_sq (struct io_uring *ring); + +/* +* if we are polling io_uring_submit needs to always enter the +* kernel to fetch events +*/ +static int test_io_uring_submit_enters (const char *file) +{ +struct io_uring ring; +int fd, i, ret, ring_flags, open_flags; +unsigned head; +struct io_uring_cqe *cqe; + + ring_flags =IORING_SETUP_IOPOLL ; + ring_flags |=IORING_SETUP_SQE128 ; + ring_flags |=IORING_SETUP_CQE32 ; + + ret =io_uring_queue_init (64 , &ring, ring_flags); +if (ret) { +fprintf (stderr,"ring create failed: %d\n" , ret); +return 1 ; + } + + open_flags =O_WRONLY ; + fd =open (file, open_flags); +if (fd <0 ) { +perror ("file open" ); + goto err; + } + +for (i =0 ; i <BUFFERS ; i++) { +struct io_uring_sqe *sqe; +off_t offset =BS * (rand () %BUFFERS ); + + sqe =io_uring_get_sqe (&ring); +io_uring_prep_writev (sqe, fd, &vecs[i],1 , offset); + sqe->user_data =1 ; + } + +/* submit manually to avoid adding IORING_ENTER_GETEVENTS */ + ret =__sys_io_uring_enter (ring.ring_fd,__io_uring_flush_sq (&ring),0 , +0 ,NULL ); +if (ret <0 ) + goto err; + +for (i =0 ; i <500 ; i++) { + ret =io_uring_submit (&ring); +if (ret !=0 ) { +fprintf (stderr,"still had %d sqes to submit, this is unexpected" , ret); + goto err; + } + +io_uring_for_each_cqe (&ring, head, cqe) { +if (cqe->res == -EOPNOTSUPP ) +fprintf (stdout,"Device doesn't support polled IO\n" ); + goto ok; + } +usleep (10000 ); + } +err: + ret =1 ; +if (fd !=-1 ) +close (fd); + +ok: +io_uring_queue_exit (&ring); +return ret; +} +int main (int argc,char *argv[]) {int i, ret;
@@ -308,6 +378,12 @@ int main(int argc, char *argv[]) } } + ret =test_io_uring_submit_enters (fname); +if (ret) { +fprintf (stderr,"test_io_uring_submit_enters failed\n" ); + goto err; + } +return T_EXIT_PASS ; err:return T_EXIT_FAIL ;
Signature · 1 line
2.17.1
Quoted 8 lines · Ankit Kumar
This patchset adds a way to test NVMe uring passthrough commands with nvme-ns character device. The uring passthrough was introduced with 5.19
io_uring.To send nvme uring passthrough commands we require helpers to fetch NVMe char device (
/dev/ngXnY) specific fields such as namespace id, lba size etc.[...]
Applied, thanks!
[1/5] configure: check for nvme uring command support
commit: 7fc6c1e89f1b83f2bb80a974a40126d10ab95d46
[2/5] io_uring.h: sync sqe entry with 5.20 io_uring
commit: 893b9d13b7571eb99d124c0804c48e331b4dbe3b
[3/5] nvme: add nvme opcodes, structures and helper functions
commit: 612101cc61063eed06d5bd232b1ab7a43732f227
[4/5] test: add io_uring passthrough test
commit: b593422fd0d624b6d1a59d0cc5a674dfdf22db6e
[5/5] test/io_uring_passthrough: add test case for poll IO
commit: ba10a0e0b3039aab43352f08631845f25aa2b225Best regards,
Signature · 1 line
Jens Axboe