Skip to contentSkip to conversation

liburing: patches for drain bug

PATCH Applied Dylan Yudaken 2 participants 4 messages Jan 27, 2023 io_uring

lore
Share & tools
lore
#0 lore raw

cover liburing: patches for drain bug

Two patches for the drain bug I just sent a patch for. Patch 1 definitely fails, but patch 2 I am sending just in case as it exercises some more code paths.

Dylan Yudaken (2): add a test using drain with IORING_SETUP_DEFER_TASKRUN
run link_drain test with defer_taskrun too

 test/defer-taskrun.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
 test/link_drain.c    | 34 +++++++++++++++++++++++++++++----
 2 files changed, 75 insertions(+), 4 deletions(-)

base-commit: 328cad5e53a38b07139c9059cdff6cee359a5313

Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/2 add a test using drain with IORING_SETUP_DEFER_TASKRUN

This exposes a bug in the kernels handling of drain on an empty ring.

---
 test/defer-taskrun.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
test/defer-taskrun.c +45 -0
index 624285ec9582..a013cfdf02d9 100644
@@ -283,6 +283,45 @@ static int test_ring_shutdown(void)
 	return 0;
 }
 
+static int test_drain(void)
+{
+	struct io_uring ring;
+	int ret, i, fd[2];
+	struct io_uring_sqe *sqe;
+	struct io_uring_cqe *cqe;
+	struct iovec iovecs[128];
+	char buff[ARRAY_SIZE(iovecs)];
+
+	ret = io_uring_queue_init(8, &ring, IORING_SETUP_SINGLE_ISSUER |
+					    IORING_SETUP_DEFER_TASKRUN |
+					    IORING_SETUP_TASKRUN_FLAG);
+	CHECK(!ret);
+
+	for (i = 0; i < ARRAY_SIZE(iovecs); i++) {
+		iovecs[i].iov_base = &buff[i];
+		iovecs[i].iov_len = 1;
+	}
+
+	ret = t_create_socket_pair(fd, true);
+	CHECK(!ret);
+
+	sqe = io_uring_get_sqe(&ring);
+	io_uring_prep_writev(sqe, fd[1], &iovecs[0], ARRAY_SIZE(iovecs), 0);
+	sqe->flags |= IOSQE_IO_DRAIN;
+	io_uring_submit(&ring);
+
+	for (i = 0; i < ARRAY_SIZE(iovecs); i++)
+		iovecs[i].iov_base = NULL;
+
+	CHECK(io_uring_wait_cqe(&ring, &cqe) == 0);
+	CHECK(cqe->res == 128);
+
+	close(fd[0]);
+	close(fd[1]);
+	io_uring_queue_exit(&ring);
+	return 0;
+}
+
 int main(int argc, char *argv[])
 {
 	int ret;
@@ -332,5 +371,11 @@ int main(int argc, char *argv[])
 		return T_EXIT_FAIL;
 	}
 
+	ret = test_drain();
+	if (ret) {
+		fprintf(stderr, "test_drain failed\n");
+		return T_EXIT_FAIL;
+	}
+
 	return T_EXIT_PASS;
 }
Signature · 1 line
2.30.2
#2 lore raw

PATCH 2/2 run link_drain test with defer_taskrun too

In reply to Dylan Yudaken

Defer_taskrun seems to expose odd codepaths, so also run link_drain tests using it.

---
 test/link_drain.c | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)
test/link_drain.c +30 -4
index 1a50c10d181d..86b0aa8db7fe 100644
@@ -198,15 +198,17 @@ err:
 
 }
 
-int main(int argc, char *argv[])
+static int test_drain(bool defer)
 {
 	struct io_uring ring;
 	int i, ret;
+	unsigned int flags = 0;
 
-	if (argc > 1)
-		return 0;
+	if (defer)
+		flags = IORING_SETUP_SINGLE_ISSUER |
+			IORING_SETUP_DEFER_TASKRUN;
 
-	ret = io_uring_queue_init(100, &ring, 0);
+	ret = io_uring_queue_init(100, &ring, flags);
 	if (ret) {
 		printf("ring setup failed\n");
 		return 1;
@@ -227,3 +229,27 @@ int main(int argc, char *argv[])
 
 	return ret;
 }
+
+int main(int argc, char *argv[])
+{
+	int ret;
+
+	if (argc > 1)
+		return T_EXIT_SKIP;
+
+	ret = test_drain(false);
+	if (ret) {
+		fprintf(stderr, "test_drain(false) failed\n");
+		return T_EXIT_FAIL;
+	}
+
+	if (t_probe_defer_taskrun()) {
+		ret = test_drain(true);
+		if (ret) {
+			fprintf(stderr, "test_drain(true) failed\n");
+			return T_EXIT_FAIL;
+		}
+	}
+
+	return T_EXIT_PASS;
+}
Signature · 1 line
2.30.2
maintainer Applied
#3 lore raw
In reply to Dylan Yudaken
Quoted 8 lines · Dylan Yudaken

Two patches for the drain bug I just sent a patch for. Patch 1 definitely fails, but patch 2 I am sending just in case as it exercises some more code paths.

Dylan Yudaken (2): add a test using drain with IORING_SETUP_DEFER_TASKRUN
run link_drain test with defer_taskrun too

[...]

Applied, thanks!

[1/2] add a test using drain with IORING_SETUP_DEFER_TASKRUN
(no commit info)
[2/2] run link_drain test with defer_taskrun too
(no commit info)

Best regards,

Signature · 1 line
Jens Axboe