From 640b2b1e95e271b00ceab6aa597f8c42401e8f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Anic=CC=81?= Date: Fri, 14 Jun 2024 11:07:50 +0200 Subject: [PATCH] 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 --- lib/std/os/linux/IoUring.zig | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/std/os/linux/IoUring.zig b/lib/std/os/linux/IoUring.zig index e29290af42db..281f4e4bf12e 100644 --- a/lib/std/os/linux/IoUring.zig +++ b/lib/std/os/linux/IoUring.zig @@ -3524,12 +3524,7 @@ test "accept/connect/send_zc/recv" { _ = try ring.recv(0xffffffff, socket_test_harness.server, .{ .buffer = buffer_recv[0..] }, 0); try testing.expectEqual(@as(u32, 2), try ring.submit()); - var cqe_send, const cqe_recv = brk: { - const cqe1 = try ring.copy_cqe(); - const cqe2 = try ring.copy_cqe(); - break :brk if (cqe1.user_data == 0xeeeeeeee) .{ cqe1, cqe2 } else .{ cqe2, cqe1 }; - }; - + var cqe_send = try ring.copy_cqe(); // First completion of zero-copy send. // IORING_CQE_F_MORE, means that there // will be a second completion event / notification for the @@ -3541,6 +3536,12 @@ test "accept/connect/send_zc/recv" { .flags = linux.IORING_CQE_F_MORE, }, cqe_send); + cqe_send, const cqe_recv = brk: { + const cqe1 = try ring.copy_cqe(); + const cqe2 = try ring.copy_cqe(); + break :brk if (cqe1.user_data == 0xeeeeeeee) .{ cqe1, cqe2 } else .{ cqe2, cqe1 }; + }; + try testing.expectEqual(linux.io_uring_cqe{ .user_data = 0xffffffff, .res = buffer_recv.len, @@ -3550,7 +3551,6 @@ test "accept/connect/send_zc/recv" { // Second completion of zero-copy send. // IORING_CQE_F_NOTIF in flags signals that kernel is done with send_buffer - cqe_send = try ring.copy_cqe(); try testing.expectEqual(linux.io_uring_cqe{ .user_data = 0xeeeeeeee, .res = 0,