Skip to contentSkip to conversation

io_uring: Add io_uring04 test for vectored I/O operations

PATCH In review Sachin Sant 3 participants 9 messages May 7 – Jun 8

lore
Share & tools
lore
#0 lore raw

PATCH v7 1/4 io_uring: Add io_uring04 test for vectored I/O operations

Add new test case io_uring04.c to validate IORING_OP_READV and IORING_OP_WRITEV operations with uniform buffer sizes.

Test performs:
- Vectored write using multiple uniform buffers (4 x 1024 bytes)
- Vectored read back into multiple uniform buffers
- Data integrity verification across all vectors

Also add helper functions to io_uring_common.h:
- io_uring_init_iovec_pattern(): Initialize iovec buffers with patterns
- io_uring_clear_iovec(): Clear iovec buffers by zeroing data
- io_uring_verify_iovec(): Verify data integrity between write/read iovecs

Update runtest/syscalls and .gitignore to include the new test.

---
V7 changes:
- Declare fd as static with file scope.
- Reset fd at the top of run(), and close it in cleanup()
- Link to v6 https://lore.kernel.org/ltp/[email protected]/T/#t

V6 changes:
- Split io_uring04.c into 3 independent tests
- Link to v5 https://lore.kernel.org/ltp/[email protected]/T/#t

V5 changes:
- Add clear_iovec_buffers() at the top of run()
- Link to v4 https://lore.kernel.org/ltp/[email protected]/T/

V4 changes:
- Updated commit message to remove references to non-existent function
- Removed extra blank line before test_writev_readv()
- Link to v3 https://lore.kernel.org/ltp/[email protected]/T/

V3 changes (2/3 io_uring04 only):
- 1/3 and 3/3 from the patch series already merged.
- Merged prepare_read_buffers() and clear_iovec_buffers() into
single clear_iovec_buffers() function
- Merged io_uring_init_buffer_pattern() into unified
init_iovec_buffers() function that supports both rotating and
simple character patterns
- Removed io_uring_init_buffer_pattern() from io_uring_common.h as it's
only used in io_uring04.c
- Link to V2: https://lore.kernel.org/ltp/[email protected]/T/

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

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/io_uring/.gitignore |  1 +
 .../kernel/syscalls/io_uring/io_uring04.c     | 89 +++++++++++++++++++
 .../syscalls/io_uring/io_uring_common.h       | 86 ++++++++++++++++++
 4 files changed, 177 insertions(+)
 create mode 100644 testcases/kernel/syscalls/io_uring/io_uring04.c
runtest/syscalls +1 -0
index f790e8f84..6b047b5fd 100644
@@ -1904,6 +1904,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 +89 -0

89 lines not on this page · raw message

testcases/kernel/syscalls/io_uring/io_uring_common.h +86 -0

90 lines not on this page · raw message

Signature · 5 lines
2.39.1


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

PATCH v2 2/4 io_uring: Add io_uring05 test for partial vector operations

Add new test case io_uring05.c to validate vectored I/O operations using partial vector sets with different file offsets.

The test performs:
- IORING_OP_WRITEV: Write first half using first 2 vectors at offset 0
- IORING_OP_WRITEV: Write second half using next 2 vectors at offset 2048
- IORING_OP_READV: Read entire file using all 4 vectors
- Data integrity verification across all vectors

This validates that io_uring correctly handles partial vector operations and maintains data integrity when using different vector subsets with specific file offsets.

---
V2 changes:
- Updated subject prefix to align with rest of the series
- Declare fd as static with file scope.
- Reset fd at the top of run(), and close it in cleanup()
- Remove extra blank line from description
- Link to v1 https://lore.kernel.org/ltp/[email protected]/T/#t

---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/io_uring/.gitignore |  1 +
 .../kernel/syscalls/io_uring/io_uring05.c     | 98 +++++++++++++++++++
 3 files changed, 100 insertions(+)
 create mode 100644 testcases/kernel/syscalls/io_uring/io_uring05.c
runtest/syscalls +1 -0
index 6b047b5fd..bab0e8f3b 100644
@@ -1905,6 +1905,7 @@ io_uring01 io_uring01
 io_uring02 io_uring02
 io_uring03 io_uring03
 io_uring04 io_uring04
+io_uring05 io_uring05
 
 # Tests below may cause kernel memory leak
 perf_event_open03 perf_event_open03
testcases/kernel/syscalls/io_uring/.gitignore +1 -0
index 36cd24662..bce7048cd 100644
@@ -2,3 +2,4 @@
 /io_uring02
 /io_uring03
 /io_uring04
+/io_uring05
testcases/kernel/syscalls/io_uring/io_uring05.c new file +98 -0

98 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

PATCH v2 3/4 io_uring: Add io_uring06 test for varying buffer sizes

In reply to Sachin Sant

Add io_uring06 test to validate vectored I/O operations (IORING_OP_READV and IORING_OP_WRITEV) with non-uniform buffer sizes including a zero-length buffer.

The test verifies:
- Writing data using iovec with varying sizes (512, 0, 1024, 256 bytes)
- Reading data back into buffers of the same varying sizes
- Data integrity verification with zero-length buffer handling
- Proper handling of iovec arrays with mixed buffer sizes

This test ensures the kernel correctly handles zero-length buffers in vectored I/O operations, which is important for applications that may dynamically construct iovec arrays.

---
V2 changes:
- Declare fd as static with file scope.
- Reset fd at the top of run(), and close it in cleanup()
- Remove extra blank line from description
- Link to v1 https://lore.kernel.org/ltp/[email protected]/T/#t

---
 runtest/syscalls                              |   1 +
 testcases/kernel/syscalls/io_uring/.gitignore |   1 +
 .../kernel/syscalls/io_uring/io_uring06.c     | 101 ++++++++++++++++++
 3 files changed, 103 insertions(+)
 create mode 100644 testcases/kernel/syscalls/io_uring/io_uring06.c
runtest/syscalls +1 -0
index bab0e8f3b..fc4892221 100644
@@ -1906,6 +1906,7 @@ io_uring02 io_uring02
 io_uring03 io_uring03
 io_uring04 io_uring04
 io_uring05 io_uring05
+io_uring06 io_uring06
 
 # Tests below may cause kernel memory leak
 perf_event_open03 perf_event_open03
testcases/kernel/syscalls/io_uring/.gitignore +1 -0
index bce7048cd..dfe7cca5a 100644
@@ -3,3 +3,4 @@
 /io_uring03
 /io_uring04
 /io_uring05
+/io_uring06
testcases/kernel/syscalls/io_uring/io_uring06.c new file +101 -0

101 lines not on this page · raw message

Signature · 5 lines
2.39.1


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

PATCH v2 4/4 io_uring: remove unused io_uring_init_buffer_pattern()

In reply to Sachin Sant

The io_uring04 test merged the functionality of io_uring_init_buffer_pattern() into the unified function io_uring_init_iovec_pattern(). Since io_uring_init_buffer_pattern() is not used by any existing test, remove it.

---
V2 changes:
- Update commit message to reflect correct function name
- Link to v1 https://lore.kernel.org/ltp/[email protected]/T/#t

---
 .../kernel/syscalls/io_uring/io_uring_common.h      | 13 -------------
 1 file changed, 13 deletions(-)
testcases/kernel/syscalls/io_uring/io_uring_common.h +0 -13
index 523f686f8..84f93c7b1 100644
@@ -230,19 +230,6 @@ static inline void io_uring_wait_cqe(struct io_uring_submit *s,
 	*cring->head = head + 1;
 }
 
-/*
- * Initialize buffer with a repeating character pattern
- * Useful for creating test data with predictable patterns
- */
-static inline void io_uring_init_buffer_pattern(char *buf, size_t size,
-						char pattern)
-{
-	size_t i;
-
-	for (i = 0; i < size; i++)
-		buf[i] = pattern;
-}
-
 /*
  * Submit and wait for a non-vectored I/O operation
  * Combines io_uring_submit_sqe() and io_uring_wait_cqe() with result reporting
Signature · 5 lines
2.39.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by LTP AI Reviewer on v7 1/4
#4 lore raw
In reply to Sachin Sant

Hi Sachin,

Quoted 4 lines · Sachin Sant

[PATCH 1/4] io_uring: Add io_uring04 test for vectored I/O operations [PATCH 2/4] io_uring: Add io_uring05 test for partial vector operations [PATCH 3/4] io_uring: Add io_uring06 test for varying buffer sizes [PATCH 4/4] io_uring: remove unused io_uring_init_buffer_pattern()

Series looks good. All four patches are clean — proper structure, correct SAFE_* usage, runtime detection via save_restore and io_uring_setup_supported_by_kernel(), and logical series ordering.

---
Note:

Our agent completed the review of the patch. The full review can be found at: (not available)

The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw
In reply to Sachin Sant

A gentle reminder.

Let me know if there are any additional review comments on this patch series.

Signature · 7 lines
Thanks
- Sachin



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

Hi Sachin

Quoted 5 lines · Sachin Sant

A gentle reminder.

Let me know if there are any additional review comments on this patch series.

I see some fundamental problems here which admittedly started before this series. I believe these need to be fixed before we apply more tests on top of it.

In io_uring_submit_sqe() and io_uring_submit_sqe_vec(), opcode is passed as user_data:
io_uring_submit_sqe_internal(s, fd, opcode, (unsigned long)buf,

                             len, offset, opcode);

user_data is supposed to be a unique per-request identifier for correlating CQEs back to their SQEs. Using opcode there is meaningless as a tag.

The existing tests happen to pass because io_uring_do_io_op() and io_uring_do_vec_io_op() always submit exactly one SQE and immediately block waiting for its CQE, so correlation is never actually needed. However, any test with multiple in-flight SQEs of the same opcode would pass;
the user_data check in io_uring_wait-cqe() would match regardless of which CQE corresponds to which request.

Please hold off on applying this series until the underlying issue is fixed. I will send a patch to correct the user_data handling.

I also think io_uring_do_io_op() and io_uring_do_vec_io_op() should not tightly couple SQE submission with waiting for a CQE.
Keeping them as a single helper makes the tests effectively synchronous and does not model real io_uring usage.
It would be cleaner to have separate helpers for submitting SQEs and waiting/reaping CQEs, and let each test handle CQE validation and result reporting in its own body.
Having basic smoke tests, sending single SQE and checking CQE makes sense in LTP, but I doubt we shall have this as a helper.

Quoted 6 lines

--
Thanks
- Sachin

Thanks and let me know if I misunderstand something here. It's the first time I look at this code really.
Sebastian

Quoted 3 lines

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

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Hi Sebastian

Quoted 20 lines

I see some fundamental problems here which admittedly started before this series. I believe these need to be fixed before we apply more tests on top of it.

In io_uring_submit_sqe() and io_uring_submit_sqe_vec(), opcode is passed as user_data:
io_uring_submit_sqe_internal(s, fd, opcode, (unsigned long)buf,

                              len, offset, opcode);

user_data is supposed to be a unique per-request identifier for correlating CQEs back to their SQEs. Using opcode there is meaningless as a tag.

The existing tests happen to pass because io_uring_do_io_op() and io_uring_do_vec_io_op() always submit exactly one SQE and immediately block waiting for its CQE, so correlation is never actually needed. However, any test with multiple in-flight SQEs of the same opcode would pass;
the user_data check in io_uring_wait-cqe() would match regardless of which CQE corresponds to which request.

Quoted 2 lines

Please hold off on applying this series until the underlying issue is fixed. I will send a patch to correct the user_data handling.

You're right.

In io_uring_submit_sqe() and io_uring_submit_sqe_vec(), we currently pass the opcode as user_data through io_uring_submit_sqe_internal().
As you pointed out, that is not a meaningful per-request identifier and it breaks CQE-to-SQE correlation once there is more than one in-flight request with the same opcode.

Quoted 9 lines

I also think io_uring_do_io_op() and io_uring_do_vec_io_op() should not tightly couple SQE submission with waiting for a CQE.
Keeping them as a single helper makes the tests effectively synchronous and does not model real io_uring usage.
It would be cleaner to have separate helpers for submitting SQEs and waiting/reaping CQEs, and let each test handle CQE validation and result reporting in its own body.
Having basic smoke tests, sending single SQE and checking CQE makes sense in LTP, but I doubt we shall have this as a helper.

The existing helpers
io_uring_do_io_op() and io_uring_do_vec_io_op() hide this because they submit a single SQE and immediately wait for a single CQE, so the tests are effectively synchronous. That makes the current code work for simple smoke coverage, but it is not a good base for adding more io_uring tests.

I agree that we should fix this first before applying more tests on top.

The right direction seems to be:

- stop using opcode as user_data
- make user_data a caller-provided per-request tag/context
- separate SQE submission from CQE waiting/reaping
- let each test validate CQEs and report results explicitly as needed

I'll wait for your patch and rework the helpers/tests on top of that approach.

Quoted 4 lines

Thanks and let me know if I misunderstand something here. It's the first time I look at this code really.
Sebastian

Nope, you are spot-on with the analysis. Let me know if I can help in any way.

Signature · 7 lines
Thanks
- Sachin



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

Hi Sachin,

Quoted 66 lines · Sachin Sant

Hi Sebastian

Quoted 2 lines

I see some fundamental problems here which admittedly started before this series. I believe these need to be fixed before we apply more tests on

top

Quoted 3 lines

of it.

In io_uring_submit_sqe() and io_uring_submit_sqe_vec(), opcode is passed

as

Quoted 5 lines

user_data:
io_uring_submit_sqe_internal(s, fd, opcode, (unsigned long)buf,

                              len, offset, opcode);

user_data is supposed to be a unique per-request identifier for

correlating

Quoted 8 lines

CQEs back to their SQEs. Using opcode there is meaningless as a tag.

The existing tests happen to pass because io_uring_do_io_op() and io_uring_do_vec_io_op() always submit exactly one SQE and immediately block waiting for its CQE, so correlation is never actually needed. However, any test with multiple in-flight SQEs of the same opcode would pass;
the user_data check in io_uring_wait-cqe() would match regardless of

which

Quoted 4 lines

CQE corresponds to which request.

Please hold off on applying this series until the underlying issue is fixed. I will send a patch to correct the user_data handling.

You're right.

In io_uring_submit_sqe() and io_uring_submit_sqe_vec(), we currently pass the
opcode as user_data through io_uring_submit_sqe_internal().
As you pointed out, that is not a meaningful per-request identifier and it breaks CQE-to-SQE correlation once there is more than one in-flight request with the same opcode.

Quoted 3 lines

I also think io_uring_do_io_op() and io_uring_do_vec_io_op() should not tightly couple SQE submission with waiting for a CQE. Keeping them as a single helper makes the tests effectively synchronous

and

Quoted 6 lines

does not model real io_uring usage.
It would be cleaner to have separate helpers for submitting SQEs and waiting/reaping CQEs, and let each test handle CQE validation and result reporting in its own body.
Having basic smoke tests, sending single SQE and checking CQE makes sense in LTP, but I doubt we shall have this as a helper.

The existing helpers
io_uring_do_io_op() and io_uring_do_vec_io_op() hide this because they submit a single SQE and immediately wait for a single CQE, so the tests are effectively synchronous. That makes the current code work for simple smoke coverage, but it is not a good base for adding more io_uring tests.

I agree that we should fix this first before applying more tests on top.

The right direction seems to be:

- stop using opcode as user_data
- make user_data a caller-provided per-request tag/context
- separate SQE submission from CQE waiting/reaping
- let each test validate CQEs and report results explicitly as needed

I'll wait for your patch and rework the helpers/tests on top of that approach.

Quoted 9 lines
Quoted 4 lines

Thanks and let me know if I misunderstand something here. It's the first time I look at this code really.
Sebastian

Nope, you are spot-on with the analysis. Let me know if I can help in any way.

I have the patches ready, so you could absolutely help with the review of those.
I'm about to send them to the mailing list

Thanks,
Sebastian

Quoted 6 lines

--
Thanks
- Sachin

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp