authorgravatar for igor.anic@gmail.comIgor Anić <igor.anic@gmail.com> 2024-06-14 11:07:50+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-06-20 18:03:28-04:00
logb8890f8ee1cb36e425afd96c0058fc382eb7cf39
tree2f466ca56c6322dad34252fdeec0046428169786
parente03026507f6e3f0b60947d9859c1346f64f480b6

io_uring: don't assume completions order (2)

In my first [try](https://github.com/ziglang/zig/pull/20224) to fix 20212 I didn't reproduce bug on required kernel (6.9.2) and wrongly concluded that first two completions have different order on newer kernel. On my current kernel (6.5.0) order of completions is: send1, recv, send2. On 6.9.2 order is send1, send2, recv. This fix allows second two completions to arrive in any order. Tested on both kernels. Fixes: #20212

1 files changed, 7 insertions(+), 7 deletions(-)

lib/std/os/linux/IoUring.zig+7-7
...@@ -3524,12 +3524,7 @@ test "accept/connect/send_zc/recv" {...@@ -3524,12 +3524,7 @@ test "accept/connect/send_zc/recv" {
3524 _ = try ring.recv(0xffffffff, socket_test_harness.server, .{ .buffer = buffer_recv[0..] }, 0);3524 _ = try ring.recv(0xffffffff, socket_test_harness.server, .{ .buffer = buffer_recv[0..] }, 0);
3525 try testing.expectEqual(@as(u32, 2), try ring.submit());3525 try testing.expectEqual(@as(u32, 2), try ring.submit());
35263526
3527 var cqe_send, const cqe_recv = brk: {3527 var cqe_send = try ring.copy_cqe();
3528 const cqe1 = try ring.copy_cqe();
3529 const cqe2 = try ring.copy_cqe();
3530 break :brk if (cqe1.user_data == 0xeeeeeeee) .{ cqe1, cqe2 } else .{ cqe2, cqe1 };
3531 };
3532
3533 // First completion of zero-copy send.3528 // First completion of zero-copy send.
3534 // IORING_CQE_F_MORE, means that there3529 // IORING_CQE_F_MORE, means that there
3535 // will be a second completion event / notification for the3530 // will be a second completion event / notification for the
...@@ -3541,6 +3536,12 @@ test "accept/connect/send_zc/recv" {...@@ -3541,6 +3536,12 @@ test "accept/connect/send_zc/recv" {
3541 .flags = linux.IORING_CQE_F_MORE,3536 .flags = linux.IORING_CQE_F_MORE,
3542 }, cqe_send);3537 }, cqe_send);
35433538
3539 cqe_send, const cqe_recv = brk: {
3540 const cqe1 = try ring.copy_cqe();
3541 const cqe2 = try ring.copy_cqe();
3542 break :brk if (cqe1.user_data == 0xeeeeeeee) .{ cqe1, cqe2 } else .{ cqe2, cqe1 };
3543 };
3544
3544 try testing.expectEqual(linux.io_uring_cqe{3545 try testing.expectEqual(linux.io_uring_cqe{
3545 .user_data = 0xffffffff,3546 .user_data = 0xffffffff,
3546 .res = buffer_recv.len,3547 .res = buffer_recv.len,
...@@ -3550,7 +3551,6 @@ test "accept/connect/send_zc/recv" {...@@ -3550,7 +3551,6 @@ test "accept/connect/send_zc/recv" {
35503551
3551 // Second completion of zero-copy send.3552 // Second completion of zero-copy send.
3552 // IORING_CQE_F_NOTIF in flags signals that kernel is done with send_buffer3553 // IORING_CQE_F_NOTIF in flags signals that kernel is done with send_buffer
3553 cqe_send = try ring.copy_cqe();
3554 try testing.expectEqual(linux.io_uring_cqe{3554 try testing.expectEqual(linux.io_uring_cqe{
3555 .user_data = 0xeeeeeeee,3555 .user_data = 0xeeeeeeee,
3556 .res = 0,3556 .res = 0,