Skip to contentSkip to conversation

io_uring READ(V), WRITE(v) operation tests

PATCH In review Sachin Sant 3 participants 10 messages Mar 24 – Apr 16

lore
Share & tools
lore
#0 lore raw

v2 cover io_uring READ(V), WRITE(v) operation tests

This patch series adds a set of test case to validate IOURING READ & WRITE (io_uring03), READV & WRITEV (io_uring04) operations. The patch also adds a common header file to avoid code duplication.

This patch series also refactors existing test io_uring01 to use the common structures and function defined in header.

---
V2 changes:
- Use guarded buffer(including iovec) allocation
- Move setup/cleanup code from run to appropriate path
- Add a function to map the OP to the enum name
- Define and use generic cleanup functions
- Add a buffer size 0 in the middle of the iovec
- Simplify setup_io_uring_test to use common code.
- Link to V1: https://lore.kernel.org/ltp/[email protected]/T/#t

Changes after RFC patch series:
- Addressed review comments
- Refactored io_uring01 test to use common code
- Removed git tags
- Link to RFC: https://lore.kernel.org/ltp/[email protected]/T/#t

Test run:

$ ./testcases/bin/io_uring03
tst_buffers.c:57: TINFO: Test is using guarded buffers
tst_tmpdir.c:308: TINFO: Using /tmp/LTP_io_o1kf2Z as tmpdir (tmpfs filesystem)
....
tst_kconfig.c:88: TINFO: Parsing kernel config '/proc/config.gz'
tst_kconfig.c:676: TINFO: CONFIG_FAULT_INJECTION kernel option detected which might slow the execution
tst_test.c:1887: TINFO: Overall timeout per run is 0h 02m 00s
io_uring03.c:62: TINFO: Testing IORING_OP_WRITE
io_uring_common.h:310: TPASS: OP=IORING_OP_WRITE (17) fd=4 buf=0x7fff83b0f000 len=4096 offset=0
io_uring03.c:68: TINFO: Testing IORING_OP_READ
io_uring_common.h:310: TPASS: OP=IORING_OP_READ (16) fd=4 buf=0x7fff83aef000 len=4096 offset=0
io_uring03.c:40: TPASS: Basic I/O data integrity verified
io_uring03.c:83: TINFO: Testing partial I/O operations
io_uring_common.h:310: TPASS: OP=IORING_OP_WRITE (17) fd=4 buf=0x7fff83b0f000 len=2048 offset=0
io_uring_common.h:310: TPASS: OP=IORING_OP_WRITE (17) fd=4 buf=0x7fff83b0f800 len=2048 offset=2048
io_uring_common.h:310: TPASS: OP=IORING_OP_READ (16) fd=4 buf=0x7fff83aef000 len=4096 offset=0
io_uring03.c:40: TPASS: Partial I/O data integrity verified

.....
ltcden8-lp8:/opt/ltp # ./testcases/bin/io_uring04
tst_buffers.c:57: TINFO: Test is using guarded buffers
tst_tmpdir.c:308: TINFO: Using /tmp/LTP_io_reAIwJ as tmpdir (tmpfs filesystem)
......
tst_kconfig.c:88: TINFO: Parsing kernel config '/proc/config.gz'
tst_kconfig.c:676: TINFO: CONFIG_FAULT_INJECTION kernel option detected which might slow the execution tst_test.c:1887: TINFO: Overall timeout per run is 0h 02m 00s
io_uring04.c:102: TINFO: Testing IORING_OP_WRITEV and IORING_OP_READV
io_uring04.c:106: TINFO: Writing 4096 bytes using 4 vectors
io_uring_common.h:326: TPASS: OP=IORING_OP_WRITEV (02) fd=4 iovs=0x7fffb832ffc0 nvecs=4 offset=0 expected_size=4096 io_uring04.c:112: TINFO: Reading 4096 bytes using 4 vectors
io_uring_common.h:326: TPASS: OP=IORING_OP_READV (01) fd=4 iovs=0x7fffb7bcffc0 nvecs=4 offset=0 expected_size=4096 io_uring04.c:92: TPASS: Basic vectored I/O: data integrity verified across 4 vectors io_uring04.c:126: TINFO: Testing partial vector operations
io_uring_common.h:326: TPASS: OP=IORING_OP_WRITEV (02) fd=4 iovs=0x7fffb832ffc0 nvecs=2 offset=0 expected_size=2048 io_uring_common.h:326: TPASS: OP=IORING_OP_WRITEV (02) fd=4 iovs=0x7fffb832ffe0 nvecs=2 offset=2048 expected_size=2048 io_uring_common.h:326: TPASS: OP=IORING_OP_READV (01) fd=4 iovs=0x7fffb7bcffc0 nvecs=4 offset=0 expected_size=4096 io_uring04.c:92: TPASS: Partial vector I/O: data integrity verified across 4 vectors io_uring04.c:154: TINFO: Testing vectors with varying sizes including zero-length buffer io_uring_common.h:326: TPASS: OP=IORING_OP_WRITEV (02) fd=4 iovs=0x7fffb7b2ffc0 nvecs=4 offset=0 expected_size=1792 io_uring_common.h:326: TPASS: OP=IORING_OP_READV (01) fd=4 iovs=0x7fffb7aaffc0 nvecs=4 offset=0 expected_size=1792 io_uring04.c:92: TPASS: Varying size vector I/O with zero-length buffer: data integrity verified across 4 vectors

.....
$

---

Sachin Sant (3):
io_uring: Test IORING READ and WRITE operations
io_uring: Test READV and WRITEV operations
io_uring: Refactor io_uring01 to use common code

 runtest/syscalls                              |   2 +
 testcases/kernel/syscalls/io_uring/.gitignore |   2 +
 .../kernel/syscalls/io_uring/io_uring01.c     | 145 ++-------
 .../kernel/syscalls/io_uring/io_uring03.c     | 140 +++++++++
 .../kernel/syscalls/io_uring/io_uring04.c     | 216 ++++++++++++++
 .../syscalls/io_uring/io_uring_common.h       | 278 ++++++++++++++++++
 6 files changed, 660 insertions(+), 123 deletions(-)
 create mode 100644 testcases/kernel/syscalls/io_uring/io_uring03.c
 create mode 100644 testcases/kernel/syscalls/io_uring/io_uring04.c
 create mode 100644 testcases/kernel/syscalls/io_uring/io_uring_common.h
Signature · 5 lines
2.39.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v2 1/3 io_uring: Test IORING READ and WRITE operations

This test validates basic read and write operations using io_uring. It tests:
1. IORING_OP_WRITE - Writing data to a file
2. IORING_OP_READ - Reading data from a file
3. Data integrity verification

This patch also introduces a header file for common functions.

---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/io_uring/.gitignore |   1 +
 .../kernel/syscalls/io_uring/io_uring03.c     | 140 +++++++++
 .../syscalls/io_uring/io_uring_common.h       | 278 ++++++++++++++++++
 4 files changed, 420 insertions(+)
 create mode 100644 testcases/kernel/syscalls/io_uring/io_uring03.c
 create mode 100644 testcases/kernel/syscalls/io_uring/io_uring_common.h
runtest/syscalls +1 -0
index 2179e007c..7dc80fe29 100644
@@ -1898,6 +1898,7 @@ membarrier01 membarrier01
 
 io_uring01 io_uring01
 io_uring02 io_uring02
+io_uring03 io_uring03
 
 # Tests below may cause kernel memory leak
 perf_event_open03 perf_event_open03
testcases/kernel/syscalls/io_uring/.gitignore +1 -0
index 749db17db..9382ae413 100644
@@ -1,2 +1,3 @@
 /io_uring01
 /io_uring02
+/io_uring03
testcases/kernel/syscalls/io_uring/io_uring03.c new file +140 -0

140 lines not on this page · raw message

testcases/kernel/syscalls/io_uring/io_uring_common.h new file +278 -0

278 lines not on this page · raw message

Signature · 5 lines
2.39.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Re: [LTP] [PATCH v2 1/3] io_uring: Test IORING READ and WRITE operations

Quoted 4 lines · Sachin Sant
testcases/kernel/syscalls/io_uring/io_uring_common.h new file +4 -0
+/*
+ * Map io_uring operation code to human-readable name
+ */
+static inline const char *ioring_op_name(int op)

testcases/kernel/syscalls/io_uring/io_uring_common.h line 189

Quoted 10 lines
testcases/kernel/syscalls/io_uring/io_uring_common.h new file +10 -0
+{
+	switch (op) {
+	case IORING_OP_READV:
+		return "IORING_OP_READV";
+	case IORING_OP_WRITEV:
+		return "IORING_OP_WRITEV";
+	case IORING_OP_READ:
+		return "IORING_OP_READ";
+	case IORING_OP_WRITE:
+		return "IORING_OP_WRITE";

Hi,
IORING_OP_READ and IORING_OP_WRITE have been added in kernel v5.6. Some older distros currently fail to build LTP due to their missing declarations so you'll need to add those constants to lapi headers.

Signature · 10 lines
Martin Doucha   [email protected]
SW Quality Engineer
SUSE LINUX, s.r.o.
CORSO IIa
Krizikova 148/34
186 00 Prague 8
Czech Republic

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] [PATCH v2 1/3] io_uring: Test IORING READ and WRITE operations

Quoted 10 lines · Martin Doucha
Quoted 9 lines · Sachin Sant
testcases/kernel/syscalls/io_uring/io_uring_common.h new file +9 -0
+/*
+ * Map io_uring operation code to human-readable name
+ */
+static inline const char *ioring_op_name(int op)
+{
+    switch (op) {
+    case IORING_OP_READV:
+        return "IORING_OP_READV";
+    case IORING_OP_WRITEV:
Quoted 9 lines
Quoted 5 lines

+        return "IORING_OP_WRITEV";
+    case IORING_OP_READ:
+        return "IORING_OP_READ";
+    case IORING_OP_WRITE:
+        return "IORING_OP_WRITE";

Hi,
IORING_OP_READ and IORING_OP_WRITE have been added in kernel v5.6. Some older distros currently fail to build LTP due to their missing declarations so you'll need to add those constants to lapi headers.

Thank you for the report. I will send a fix to address this.

Signature · 7 lines
Thanks
- Sachin



-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

PATCH v2 2/3 io_uring: Test READV and WRITEV operations

In reply to Sachin Sant

This test validates vectored read and write operations using io_uring.

1. IORING_OP_WRITEV - Writing data using multiple buffers (scatter)
2. IORING_OP_READV - Reading data into multiple buffers (gather)
3. Data integrity verification across multiple iovecs
4. Edge cases with different iovec configurations including zero buffer length

---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/io_uring/.gitignore |   1 +
 .../kernel/syscalls/io_uring/io_uring04.c     | 216 ++++++++++++++++++
 3 files changed, 218 insertions(+)
 create mode 100644 testcases/kernel/syscalls/io_uring/io_uring04.c
runtest/syscalls +1 -0
index 7dc80fe29..eacf946c5 100644
@@ -1899,6 +1899,7 @@ membarrier01 membarrier01
 io_uring01 io_uring01
 io_uring02 io_uring02
 io_uring03 io_uring03
+io_uring04 io_uring04
 
 # Tests below may cause kernel memory leak
 perf_event_open03 perf_event_open03
testcases/kernel/syscalls/io_uring/.gitignore +1 -0
index 9382ae413..36cd24662 100644
@@ -1,3 +1,4 @@
 /io_uring01
 /io_uring02
 /io_uring03
+/io_uring04
testcases/kernel/syscalls/io_uring/io_uring04.c new file +216 -0

216 lines not on this page · raw message

Signature · 5 lines
2.39.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Re: [LTP] [PATCH v2 2/3] io_uring: Test READV and WRITEV operations

Hi!

Quoted 34 lines
testcases/kernel/syscalls/io_uring/io_uring04.c new file +34 -0
+#include "io_uring_common.h"
+
+#define TEST_FILE "io_uring_test_file"
+#define QUEUE_DEPTH 2
+#define NUM_VECS 4
+#define VEC_SIZE 1024
+#define VAR_BUF1_SIZE 512
+#define VAR_BUF2_SIZE 1024
+#define VAR_BUF3_SIZE 256
+
+static struct iovec *write_iovs, *read_iovs;
+static struct iovec *var_write_iovs, *var_read_iovs;
+static struct io_uring_submit s;
+static sigset_t sig;
+
+static void prepare_write_buffers(void)
+{
+	size_t i, j;
+	char *buf;
+
+	for (i = 0; i < NUM_VECS; i++) {
+		buf = (char *)write_iovs[i].iov_base;
+		for (j = 0; j < write_iovs[i].iov_len; j++) {
+			/* Each vector has a different pattern */
+			buf[j] = 'A' + i + (j % 26);
+		}
+	}
+}
+
+static void prepare_read_buffers(void)
+{
+	size_t i;
+
+	for (i = 0; i < NUM_VECS; i++)

testcases/kernel/syscalls/io_uring/io_uring04.c line 60

Quoted 10 lines
testcases/kernel/syscalls/io_uring/io_uring04.c new file +10 -0
+		memset(read_iovs[i].iov_base, 0, read_iovs[i].iov_len);
+}
+
+static void clear_iovec_buffers(struct iovec *iovs, int nvecs)
+{
+	int i;
+
+	for (i = 0; i < nvecs; i++)
+		memset(iovs[i].iov_base, 0, iovs[i].iov_len);
+}

These two functions are nearly identical, we really need only one function to clear the buffers.

Quoted 87 lines
testcases/kernel/syscalls/io_uring/io_uring04.c new file +87 -0
+static void verify_iovec_data(struct iovec *write_iovs, struct iovec *read_iovs,
+			      int nvecs, const char *test_name)
+{
+	int i;
+	size_t j;
+
+	for (i = 0; i < nvecs; i++) {
+		if (write_iovs[i].iov_len != read_iovs[i].iov_len) {
+			tst_res(TFAIL, "%s: iovec %d length mismatch: write=%zu read=%zu",
+				test_name, i, write_iovs[i].iov_len, read_iovs[i].iov_len);
+			return;
+		}
+
+		if (memcmp(write_iovs[i].iov_base, read_iovs[i].iov_base,
+			   write_iovs[i].iov_len) != 0) {
+			tst_res(TFAIL, "%s: data mismatch in vector %d", test_name, i);
+			for (j = 0; j < write_iovs[i].iov_len && j < 64; j++) {
+				char *wbuf = (char *)write_iovs[i].iov_base;
+				char *rbuf = (char *)read_iovs[i].iov_base;
+				if (wbuf[j] != rbuf[j]) {
+					tst_res(TINFO, "Vector %d: first mismatch at "
+						"offset %zu: wrote 0x%02x, read 0x%02x",
+						i, j, wbuf[j], rbuf[j]);
+					break;
+				}
+			}
+			return;
+		}
+	}
+
+	tst_res(TPASS, "%s: data integrity verified across %d vectors",
+		test_name, nvecs);
+}
+
+
+static void test_writev_readv(void)
+{
+	int fd;
+	int total_size = NUM_VECS * VEC_SIZE;
+
+	tst_res(TINFO, "Testing IORING_OP_WRITEV and IORING_OP_READV");
+
+	fd = SAFE_OPEN(TEST_FILE, O_RDWR | O_CREAT | O_TRUNC, 0644);
+
+	tst_res(TINFO, "Writing %d bytes using %d vectors", total_size, NUM_VECS);
+	io_uring_do_vec_io_op(&s, fd, IORING_OP_WRITEV, write_iovs, NUM_VECS,
+			      0, total_size, &sig);
+
+	SAFE_FSYNC(fd);
+
+	tst_res(TINFO, "Reading %d bytes using %d vectors", total_size, NUM_VECS);
+	io_uring_do_vec_io_op(&s, fd, IORING_OP_READV, read_iovs, NUM_VECS,
+			      0, total_size, &sig);
+
+	verify_iovec_data(write_iovs, read_iovs, NUM_VECS, "Basic vectored I/O");
+
+	SAFE_CLOSE(fd);
+}
+
+static void test_partial_vectors(void)
+{
+	int fd;
+	int half_size = 2 * VEC_SIZE;
+
+	tst_res(TINFO, "Testing partial vector operations");
+
+	fd = SAFE_OPEN(TEST_FILE, O_RDWR | O_CREAT | O_TRUNC, 0644);
+
+	/* Write first half using first 2 vectors at offset 0 */
+	io_uring_do_vec_io_op(&s, fd, IORING_OP_WRITEV, write_iovs, 2, 0,
+			      half_size, &sig);
+
+	/* Write second half using next 2 vectors at offset half_size */
+	io_uring_do_vec_io_op(&s, fd, IORING_OP_WRITEV, &write_iovs[2], 2,
+			      half_size, half_size, &sig);
+
+	SAFE_FSYNC(fd);
+
+	/* Read back entire file using all 4 vectors */
+	io_uring_do_vec_io_op(&s, fd, IORING_OP_READV, read_iovs, NUM_VECS, 0,
+			      NUM_VECS * VEC_SIZE, &sig);
+
+	verify_iovec_data(write_iovs, read_iovs, NUM_VECS, "Partial vector I/O");
+
+	SAFE_CLOSE(fd);
+}
+

testcases/kernel/syscalls/io_uring/io_uring04.c line 158

Quoted 10 lines
testcases/kernel/syscalls/io_uring/io_uring04.c new file +10 -0
+static void test_varying_sizes(void)
+{
+	int fd;
+	int expected_size = VAR_BUF1_SIZE + VAR_BUF2_SIZE + VAR_BUF3_SIZE;
+
+	tst_res(TINFO, "Testing vectors with varying sizes including zero-length buffer");
+
+	io_uring_init_buffer_pattern(var_write_iovs[0].iov_base, VAR_BUF1_SIZE, 'X');
+	io_uring_init_buffer_pattern(var_write_iovs[2].iov_base, VAR_BUF2_SIZE, 'Y');
+	io_uring_init_buffer_pattern(var_write_iovs[3].iov_base, VAR_BUF3_SIZE, 'Z');

Can we handle this with the prepare_write_buffers() as well?

Quoted 60 lines
testcases/kernel/syscalls/io_uring/io_uring04.c new file +57 -0
+	clear_iovec_buffers(var_read_iovs, 4);
+
+	fd = SAFE_OPEN(TEST_FILE, O_RDWR | O_CREAT | O_TRUNC, 0644);
+
+	io_uring_do_vec_io_op(&s, fd, IORING_OP_WRITEV, var_write_iovs, 4, 0,
+			      expected_size, &sig);
+
+	SAFE_FSYNC(fd);
+
+	io_uring_do_vec_io_op(&s, fd, IORING_OP_READV, var_read_iovs, 4, 0,
+			      expected_size, &sig);
+
+	verify_iovec_data(var_write_iovs, var_read_iovs, 4, "Varying size vector I/O with zero-length buffer");
+
+	SAFE_CLOSE(fd);
+}
+
+static void run(void)
+{
+	test_writev_readv();
+	test_partial_vectors();
+	test_varying_sizes();
+}
+
+static void setup(void)
+{
+	io_uring_setup_supported_by_kernel();
+	sigemptyset(&sig);
+	memset(&s, 0, sizeof(s));
+	io_uring_setup_queue(&s, QUEUE_DEPTH, 0);
+	prepare_write_buffers();
+	prepare_read_buffers();
+}
+
+static void cleanup(void)
+{
+	io_uring_cleanup_queue(&s, QUEUE_DEPTH);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+	.bufs = (struct tst_buffers []) {
+		{&write_iovs, .iov_sizes = (int[]){VEC_SIZE, VEC_SIZE, VEC_SIZE, VEC_SIZE, -1}},
+		{&read_iovs, .iov_sizes = (int[]){VEC_SIZE, VEC_SIZE, VEC_SIZE, VEC_SIZE, -1}},
+		{&var_write_iovs, .iov_sizes = (int[]){VAR_BUF1_SIZE, 0, VAR_BUF2_SIZE, VAR_BUF3_SIZE, -1}},
+		{&var_read_iovs, .iov_sizes = (int[]){VAR_BUF1_SIZE, 0, VAR_BUF2_SIZE, VAR_BUF3_SIZE, -1}},
+		{}
+	},
+	.save_restore = (const struct tst_path_val[]) {
+		{"/proc/sys/kernel/io_uring_disabled", "0",
+			TST_SR_SKIP_MISSING | TST_SR_TCONF_RO},
+		{}
+	}
+};
Signature · 1 line
2.39.1
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Re: [LTP] [PATCH v2 2/3] io_uring: Test READV and WRITEV operations

Quoted 9 lines
Quoted 9 lines
testcases/kernel/syscalls/io_uring/io_uring04.c new file +9 -0
+static void prepare_read_buffers(void)
+{
+	size_t i;
+
+	for (i = 0; i < NUM_VECS; i++)
+		memset(read_iovs[i].iov_base, 0, read_iovs[i].iov_len);
+}
+
+static void clear_iovec_buffers(struct iovec *iovs, int nvecs)
Quoted 9 lines

testcases/kernel/syscalls/io_uring/io_uring04.c line 60

Quoted 6 lines
testcases/kernel/syscalls/io_uring/io_uring04.c new file +6 -0
+{
+	int i;
+
+	for (i = 0; i < nvecs; i++)
+		memset(iovs[i].iov_base, 0, iovs[i].iov_len);
+}

These two functions are nearly identical, we really need only one function to clear the buffers.

Indeed. Good catch. Will merge them.

Quoted 11 lines

testcases/kernel/syscalls/io_uring/io_uring04.c line 158

Quoted 10 lines
testcases/kernel/syscalls/io_uring/io_uring04.c new file +10 -0
+static void test_varying_sizes(void)
+{
+	int fd;
+	int expected_size = VAR_BUF1_SIZE + VAR_BUF2_SIZE + VAR_BUF3_SIZE;
+
+	tst_res(TINFO, "Testing vectors with varying sizes including zero-length buffer");
+
+	io_uring_init_buffer_pattern(var_write_iovs[0].iov_base, VAR_BUF1_SIZE, 'X');
+	io_uring_init_buffer_pattern(var_write_iovs[2].iov_base, VAR_BUF2_SIZE, 'Y');
+	io_uring_init_buffer_pattern(var_write_iovs[3].iov_base, VAR_BUF3_SIZE, 'Z');

Can we handle this with the prepare_write_buffers() as well?

These two functions implement different logic. prepare_write_buffers() create a rotating pattern unique to each vector while io_uring_init_buffer_pattern() fills a buffer with a single repeating character.

But I see your point. I will merge these two as well.

Thank You for the detailed review.

Signature · 7 lines
Thanks
- Sachin



-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

PATCH v2 3/3 io_uring: Refactor io_uring01 to use common code

In reply to Sachin Sant

No functional change.

Refactor io_uring01 test case to use
- common definitions from io_uring_common.h
- remove duplicate structure definitions
- Replace manual munmap/close calls with io_uring_cleanup_queue() helper function
- Submit SQE using common helper

---
 .../kernel/syscalls/io_uring/io_uring01.c     | 145 +++---------------
 1 file changed, 22 insertions(+), 123 deletions(-)
testcases/kernel/syscalls/io_uring/io_uring01.c +22 -123
index ab1ec00d6..4c64e562b 100644
@@ -11,13 +11,7 @@
  * registered in the kernel for long term operation using io_uring_register().
  * This tests initiates I/O operations with the help of io_uring_enter().
  */
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <fcntl.h>
-#include "config.h"
-#include "tst_test.h"
-#include "lapi/io_uring.h"
+#include "io_uring_common.h"
 
 #define TEST_FILE "test_file"
 
@@ -32,96 +26,19 @@ static struct tcase {
 	{0, IORING_REGISTER_BUFFERS, IORING_OP_READ_FIXED},
 };
 
-struct io_sq_ring {
-	unsigned int *head;
-	unsigned int *tail;
-	unsigned int *ring_mask;
-	unsigned int *ring_entries;
-	unsigned int *flags;
-	unsigned int *array;
-};
-
-struct io_cq_ring {
-	unsigned int *head;
-	unsigned int *tail;
-	unsigned int *ring_mask;
-	unsigned int *ring_entries;
-	struct io_uring_cqe *cqes;
-};
-
-struct submitter {
-	int ring_fd;
-	struct io_sq_ring sq_ring;
-	struct io_uring_sqe *sqes;
-	struct io_cq_ring cq_ring;
-};
-
-static struct submitter sub_ring;
-static struct submitter *s = &sub_ring;
+static struct io_uring_submit s;
 static sigset_t sig;
 static struct iovec *iov;
 
-
-static void *sptr;
-static size_t sptr_size;
-static void *cptr;
-static size_t cptr_size;
-
-static int setup_io_uring_test(struct submitter *s, struct tcase *tc)
+static int setup_io_uring_test(struct io_uring_submit *s, struct tcase *tc)
 {
-	struct io_sq_ring *sring = &s->sq_ring;
-	struct io_cq_ring *cring = &s->cq_ring;
-	struct io_uring_params p;
+	int ret;
 
-	memset(&p, 0, sizeof(p));
-	p.flags |= tc->setup_flags;
-	s->ring_fd = io_uring_setup(QUEUE_DEPTH, &p);
-	if (s->ring_fd != -1) {
+	ret = io_uring_setup_queue(s, QUEUE_DEPTH, tc->setup_flags);
+	if (ret == 0)
 		tst_res(TPASS, "io_uring_setup() passed");
-	} else {
-		tst_res(TFAIL | TERRNO, "io_uring_setup() failed");
-		return 1;
-	}
-
-	sptr_size = p.sq_off.array + p.sq_entries * sizeof(unsigned int);
-
-	/* Submission queue ring buffer mapping */
-	sptr = SAFE_MMAP(0, sptr_size,
-			PROT_READ | PROT_WRITE,
-			MAP_SHARED | MAP_POPULATE,
-			s->ring_fd, IORING_OFF_SQ_RING);
-
-	/* Save global submission queue struct info */
-	sring->head = sptr + p.sq_off.head;
-	sring->tail = sptr + p.sq_off.tail;
-	sring->ring_mask = sptr + p.sq_off.ring_mask;
-	sring->ring_entries = sptr + p.sq_off.ring_entries;
-	sring->flags = sptr + p.sq_off.flags;
-	sring->array = sptr + p.sq_off.array;
-
-	/* Submission queue entries ring buffer mapping */
-	s->sqes = SAFE_MMAP(0, p.sq_entries *
-			sizeof(struct io_uring_sqe),
-			PROT_READ | PROT_WRITE,
-			MAP_SHARED | MAP_POPULATE,
-			s->ring_fd, IORING_OFF_SQES);
-
-	cptr_size = p.cq_off.cqes + p.cq_entries * sizeof(struct io_uring_cqe);
-
-	/* Completion queue ring buffer mapping */
-	cptr = SAFE_MMAP(0, cptr_size,
-			PROT_READ | PROT_WRITE,
-			MAP_SHARED | MAP_POPULATE,
-			s->ring_fd, IORING_OFF_CQ_RING);
-
-	/* Save global completion queue struct info */
-	cring->head = cptr + p.cq_off.head;
-	cring->tail = cptr + p.cq_off.tail;
-	cring->ring_mask = cptr + p.cq_off.ring_mask;
-	cring->ring_entries = cptr + p.cq_off.ring_entries;
-	cring->cqes = cptr + p.cq_off.cqes;
 
-	return 0;
+	return ret;
 }
 
 static void check_buffer(char *buffer, size_t len)
@@ -139,7 +56,7 @@ static void check_buffer(char *buffer, size_t len)
 		tst_res(TPASS, "Buffer filled in correctly");
 }
 
-static void drain_uring_cq(struct submitter *s, unsigned int exp_events)
+static void drain_uring_cq(struct io_uring_submit *s, unsigned int exp_events)
 {
 	struct io_cq_ring *cring = &s->cq_ring;
 	unsigned int head = *cring->head;
@@ -175,12 +92,10 @@ static void drain_uring_cq(struct submitter *s, unsigned int exp_events)
 	        events, exp_events);
 }
 
-static int submit_to_uring_sq(struct submitter *s, struct tcase *tc)
+static int submit_to_uring_sq(struct io_uring_submit *s, struct tcase *tc)
 {
-	unsigned int index = 0, tail = 0, next_tail = 0;
-	struct io_sq_ring *sring = &s->sq_ring;
-	struct io_uring_sqe *sqe;
 	int ret;
+	int fd;
 
 	memset(iov->iov_base, 0, iov->iov_len);
 
@@ -193,26 +108,13 @@ static int submit_to_uring_sq(struct submitter *s, struct tcase *tc)
 		return 1;
 	}
 
-	int fd = SAFE_OPEN(TEST_FILE, O_RDONLY);
-
-	/* Submission queue entry addition to SQE ring buffer tail */
-	tail = *sring->tail;
-	next_tail = tail + 1;
-	index = tail & *s->sq_ring.ring_mask;
-	sqe = &s->sqes[index];
-	sqe->flags = 0;
-	sqe->fd = fd;
-	sqe->opcode = tc->enter_flags;
-	sqe->addr = (unsigned long)iov->iov_base;
-	sqe->len = BLOCK_SZ;
-	sqe->off = 0;
-	sqe->user_data = (unsigned long long)iov;
-	sring->array[index] = index;
-	tail = next_tail;
-
-	/* Kernel to notice the tail update */
-	if (*sring->tail != tail)
-		*sring->tail = tail;
+	fd = SAFE_OPEN(TEST_FILE, O_RDONLY);
+
+	/* Submit SQE using common helper */
+	io_uring_submit_sqe_internal(s, fd, tc->enter_flags,
+				     (unsigned long)iov->iov_base,
+				     BLOCK_SZ, 0,
+				     (unsigned long long)iov);
 
 	ret = io_uring_enter(s->ring_fd, 1, 1, IORING_ENTER_GETEVENTS, &sig);
 	if (ret == 1) {
@@ -229,23 +131,20 @@ static int submit_to_uring_sq(struct submitter *s, struct tcase *tc)
 
 static void cleanup_io_uring_test(void)
 {
-	io_uring_register(s->ring_fd, IORING_UNREGISTER_BUFFERS,
+	io_uring_register(s.ring_fd, IORING_UNREGISTER_BUFFERS,
 			  NULL, QUEUE_DEPTH);
-	SAFE_MUNMAP(s->sqes, sizeof(struct io_uring_sqe));
-	SAFE_MUNMAP(cptr, cptr_size);
-	SAFE_MUNMAP(sptr, sptr_size);
-	SAFE_CLOSE(s->ring_fd);
+	io_uring_cleanup_queue(&s, QUEUE_DEPTH);
 }
 
 static void run(unsigned int n)
 {
 	struct tcase *tc = &tcases[n];
 
-	if (setup_io_uring_test(s, tc))
+	if (setup_io_uring_test(&s, tc))
 		return;
 
-	if (!submit_to_uring_sq(s, tc))
-		drain_uring_cq(s, 1);
+	if (!submit_to_uring_sq(&s, tc))
+		drain_uring_cq(&s, 1);
 
 	cleanup_io_uring_test();
 }
Signature · 5 lines
2.39.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw
Quoted 3 lines · Cyril Hrubis

Hi!
I've merged 1/3 and 3/3 since these two patches were ready, thanks. I will add a few minor comments for 2/3.

Thank You Cyril.
 I will send an updated patch for 2/3.

Signature · 7 lines
Thanks
- Sachin



-- 
Mailing list info: https://lists.linux.it/listinfo/ltp