From: Pavel Begunkov <[email protected]> To: Jens Axboe <[email protected]>, [email protected] Subject: [PATCH liburing 1/1] tests: test that ring exit cancels io-wq Date: Sat, 6 Mar 2021 10:57:16 +0000 [thread overview] Message-ID: <25463f90290f69c08ba38edf0c40aafd5df50114.1615028231.git.asml.silence@gmail.com> (raw) Test that io_uring_queue_exit() does proper cancellation of io-wq. Note that there are worse cases with multiple tasks that can hang in the kernel due to failing to do io-wq cancellations properly. Signed-off-by: Pavel Begunkov <[email protected]> --- test/ring-leak.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/test/ring-leak.c b/test/ring-leak.c index 4ddc8ff..7ff1d87 100644 --- a/test/ring-leak.c +++ b/test/ring-leak.c @@ -73,6 +73,65 @@ static void send_fd(int socket, int fd) perror("sendmsg"); } +static int test_iowq_request_cancel(void) +{ + char buffer[128]; + struct io_uring ring; + struct io_uring_sqe *sqe; + int ret, fds[2]; + + ret = io_uring_queue_init(8, &ring, 0); + if (ret < 0) { + fprintf(stderr, "failed to init io_uring: %s\n", strerror(-ret)); + return ret; + } + if (pipe(fds)) { + perror("pipe"); + return -1; + } + ret = io_uring_register_files(&ring, fds, 2); + if (ret) { + fprintf(stderr, "file_register: %d\n", ret); + return ret; + } + close(fds[1]); + + sqe = io_uring_get_sqe(&ring); + if (!sqe) { + fprintf(stderr, "%s: failed to get sqe\n", __FUNCTION__); + return 1; + } + /* potentially sitting in internal polling */ + io_uring_prep_read(sqe, 0, buffer, 10, 0); + sqe->flags |= IOSQE_FIXED_FILE; + + sqe = io_uring_get_sqe(&ring); + if (!sqe) { + fprintf(stderr, "%s: failed to get sqe\n", __FUNCTION__); + return 1; + } + /* staying in io-wq */ + io_uring_prep_read(sqe, 0, buffer, 10, 0); + sqe->flags |= IOSQE_FIXED_FILE | IOSQE_ASYNC; + + ret = io_uring_submit(&ring); + if (ret != 2) { + fprintf(stderr, "%s: got %d, wanted 1\n", __FUNCTION__, ret); + return 1; + } + + /* should unregister files and close the write fd */ + io_uring_queue_exit(&ring); + + /* + * We're trying to wait for the ring to "really" exit, that will be + * done async. For that rely on the registered write end to be closed + * after ring quiesce, so failing read from the other pipe end. + */ + read(fds[0], buffer, 10); + return 0; +} + int main(int argc, char *argv[]) { int sp[2], pid, ring_fd, ret; @@ -80,6 +139,12 @@ int main(int argc, char *argv[]) if (argc > 1) return 0; + ret = test_iowq_request_cancel(); + if (ret) { + fprintf(stderr, "test_iowq_request_cancel() failed\n"); + return 1; + } + if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sp) != 0) { perror("Failed to create Unix-domain socket pair\n"); return 1; -- 2.24.0
WARNING: multiple messages have this Message-ID (diff)
From: Pavel Begunkov <[email protected]> To: Jens Axboe <[email protected]>, [email protected] Subject: [PATCH liburing 1/1] tests: test that ring exit cancels io-wq Date: Sat, 6 Mar 2021 10:58:10 +0000 [thread overview] Message-ID: <25463f90290f69c08ba38edf0c40aafd5df50114.1615028231.git.asml.silence@gmail.com> (raw) Message-ID: <20210306105810.xkHR0Sx3BP9fLe4SXbl4AKgFJ5tNaDndXtOJrBKeSVQ@z> (raw) Test that io_uring_queue_exit() does proper cancellation of io-wq. Note that there are worse cases with multiple tasks that can hang in the kernel due to failing to do io-wq cancellations properly. Signed-off-by: Pavel Begunkov <[email protected]> --- test/ring-leak.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/test/ring-leak.c b/test/ring-leak.c index 4ddc8ff..7ff1d87 100644 --- a/test/ring-leak.c +++ b/test/ring-leak.c @@ -73,6 +73,65 @@ static void send_fd(int socket, int fd) perror("sendmsg"); } +static int test_iowq_request_cancel(void) +{ + char buffer[128]; + struct io_uring ring; + struct io_uring_sqe *sqe; + int ret, fds[2]; + + ret = io_uring_queue_init(8, &ring, 0); + if (ret < 0) { + fprintf(stderr, "failed to init io_uring: %s\n", strerror(-ret)); + return ret; + } + if (pipe(fds)) { + perror("pipe"); + return -1; + } + ret = io_uring_register_files(&ring, fds, 2); + if (ret) { + fprintf(stderr, "file_register: %d\n", ret); + return ret; + } + close(fds[1]); + + sqe = io_uring_get_sqe(&ring); + if (!sqe) { + fprintf(stderr, "%s: failed to get sqe\n", __FUNCTION__); + return 1; + } + /* potentially sitting in internal polling */ + io_uring_prep_read(sqe, 0, buffer, 10, 0); + sqe->flags |= IOSQE_FIXED_FILE; + + sqe = io_uring_get_sqe(&ring); + if (!sqe) { + fprintf(stderr, "%s: failed to get sqe\n", __FUNCTION__); + return 1; + } + /* staying in io-wq */ + io_uring_prep_read(sqe, 0, buffer, 10, 0); + sqe->flags |= IOSQE_FIXED_FILE | IOSQE_ASYNC; + + ret = io_uring_submit(&ring); + if (ret != 2) { + fprintf(stderr, "%s: got %d, wanted 1\n", __FUNCTION__, ret); + return 1; + } + + /* should unregister files and close the write fd */ + io_uring_queue_exit(&ring); + + /* + * We're trying to wait for the ring to "really" exit, that will be + * done async. For that rely on the registered write end to be closed + * after ring quiesce, so failing read from the other pipe end. + */ + read(fds[0], buffer, 10); + return 0; +} + int main(int argc, char *argv[]) { int sp[2], pid, ring_fd, ret; @@ -80,6 +139,12 @@ int main(int argc, char *argv[]) if (argc > 1) return 0; + ret = test_iowq_request_cancel(); + if (ret) { + fprintf(stderr, "test_iowq_request_cancel() failed\n"); + return 1; + } + if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sp) != 0) { perror("Failed to create Unix-domain socket pair\n"); return 1; -- 2.24.0
next reply other threads:[~2021-03-06 11:01 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-03-06 10:57 Pavel Begunkov [this message] 2021-03-06 10:58 ` [PATCH liburing 1/1] tests: test that ring exit cancels io-wq Pavel Begunkov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=25463f90290f69c08ba38edf0c40aafd5df50114.1615028231.git.asml.silence@gmail.com \ [email protected] \ [email protected] \ [email protected] \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox