summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/Makefile5
-rw-r--r--test/ce593a6c480a-test.c130
2 files changed, 133 insertions, 2 deletions
diff --git a/test/Makefile b/test/Makefile
index c80ad42..2d71db0 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -25,7 +25,7 @@ all_targets += poll poll-cancel ring-leak fsync io_uring_setup io_uring_register
short-read openat2 probe shared-wq personality eventfd \
send_recv eventfd-ring across-fork sq-poll-kthread splice \
lfs-openat lfs-openat-write iopoll d4ae271dfaae-test \
- eventfd-disable close-opath
+ eventfd-disable close-opath ce593a6c480a-test
include ../Makefile.quiet
@@ -65,7 +65,7 @@ test_srcs := poll.c poll-cancel.c ring-leak.c fsync.c io_uring_setup.c \
madvise.c short-read.c openat2.c probe.c shared-wq.c \
personality.c eventfd.c eventfd-ring.c across-fork.c sq-poll-kthread.c \
splice.c lfs-openat.c lfs-openat-write.c iopoll.c d4ae271dfaae-test.c \
- eventfd-disable.c close-opath.c
+ eventfd-disable.c close-opath.c ce593a6c480a-test.c
ifdef CONFIG_HAVE_STATX
test_srcs += statx.c
@@ -86,6 +86,7 @@ accept-link: XCFLAGS = -lpthread
submit-reuse: XCFLAGS = -lpthread
poll-v-poll: XCFLAGS = -lpthread
across-fork: XCFLAGS = -lpthread
+ce593a6c480a-test: XCFLAGS = -lpthread
install: $(all_targets) runtests.sh runtests-loop.sh
$(INSTALL) -D -d -m 755 $(datadir)/liburing-test/
diff --git a/test/ce593a6c480a-test.c b/test/ce593a6c480a-test.c
new file mode 100644
index 0000000..8763893
--- /dev/null
+++ b/test/ce593a6c480a-test.c
@@ -0,0 +1,130 @@
+/*
+ * Test 5.7 regression with task_work not being run while a task is
+ * waiting on another event in the kernel.
+ */
+#include <errno.h>
+#include <poll.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/eventfd.h>
+#include <unistd.h>
+#include <pthread.h>
+#include "liburing.h"
+
+static int use_sqpoll = 0;
+
+void notify_fd(int fd)
+{
+ char buf[8] = {0, 0, 0, 0, 0, 0, 1};
+ int ret;
+
+ ret = write(fd, &buf, 8);
+ if (ret < 0)
+ perror("write");
+}
+
+void *delay_set_fd_from_thread(void *data)
+{
+ int fd = (intptr_t) data;
+
+ sleep(1);
+ notify_fd(fd);
+ return NULL;
+}
+
+int main(int argc, char *argv[])
+{
+ struct io_uring_params p = {};
+ struct io_uring ring;
+ int loop_fd, other_fd;
+ struct io_uring_sqe *sqe;
+ struct io_uring_cqe *cqe = NULL;
+ int ret, use_fd;
+ char buf[8] = {0, 0, 0, 0, 0, 0, 1};
+ pthread_t tid;
+
+ /* Create an eventfd to be registered with the loop to be
+ * notified of events being ready
+ */
+ loop_fd = eventfd(0, EFD_CLOEXEC);
+ if (loop_fd == -1) {
+ fprintf(stderr, "eventfd errno=%d\n", errno);
+ return 1;
+ }
+
+ /* Create an eventfd that can create events */
+ use_fd = other_fd = eventfd(0, EFD_CLOEXEC);
+ if (other_fd == -1) {
+ fprintf(stderr, "eventfd errno=%d\n", errno);
+ return 1;
+ }
+
+ if (use_sqpoll)
+ p.flags = IORING_SETUP_SQPOLL;
+
+ /* Setup the ring with a registered event fd to be notified on events */
+ ret = io_uring_queue_init_params(8, &ring, &p);
+ if (ret) {
+ fprintf(stderr, "queue_init=%d\n", ret);
+ return 1;
+ }
+ ret = io_uring_register_eventfd(&ring, loop_fd);
+ if (ret < 0) {
+ fprintf(stderr, "register_eventfd=%d\n", ret);
+ return 1;
+ }
+
+ if (use_sqpoll) {
+ ret = io_uring_register_files(&ring, &other_fd, 1);
+ if (ret < 0) {
+ fprintf(stderr, "register_files=%d\n", ret);
+ return 1;
+ }
+ use_fd = 0;
+ }
+
+ /* Submit a poll operation to wait on an event in other_fd */
+ sqe = io_uring_get_sqe(&ring);
+ io_uring_prep_poll_add(sqe, use_fd, POLLIN);
+ sqe->user_data = 1;
+ if (use_sqpoll)
+ sqe->flags |= IOSQE_FIXED_FILE;
+ ret = io_uring_submit(&ring);
+ if (ret != 1) {
+ fprintf(stderr, "submit=%d\n", ret);
+ return 1;
+ }
+
+ /*
+ * CASE 3: Hangs forever in Linux 5.7.5; Works in Linux 5.6.0 When this
+ * code is uncommented, we don't se a notification on other_fd until
+ * _after_ we have started the read on loop_fd. In that case, the read() on
+ * loop_fd seems to hang forever.
+ */
+ pthread_create(&tid, NULL, delay_set_fd_from_thread,
+ (void*) (intptr_t) other_fd);
+
+ /* Wait on the event fd for an event to be ready */
+ ret = read(loop_fd, buf, 8);
+ if (ret < 0) {
+ perror("read");
+ return 1;
+ } else if (ret != 8) {
+ fprintf(stderr, "Odd-sized eventfd read: %d\n", ret);
+ return 1;
+ }
+
+
+ ret = io_uring_wait_cqe(&ring, &cqe);
+ if (ret) {
+ fprintf(stderr, "wait_cqe=%d\n", ret);
+ return ret;
+ }
+ if (cqe->res < 0) {
+ fprintf(stderr, "cqe->res=%d\n", cqe->res);
+ return 1;
+ }
+
+ io_uring_cqe_seen(&ring, cqe);
+ return 0;
+}