From: Bijan Mottahedeh <[email protected]>
To: [email protected], [email protected]
Subject: [PATCH v2 07/10] test/buffer-share: add interruptible deadlock test
Date: Fri, 22 Jan 2021 14:54:56 -0800 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
Signed-off-by: Bijan Mottahedeh <[email protected]>
---
test/buffer-share.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 84 insertions(+), 1 deletion(-)
diff --git a/test/buffer-share.c b/test/buffer-share.c
index cbfbfb2..2997333 100644
--- a/test/buffer-share.c
+++ b/test/buffer-share.c
@@ -72,6 +72,7 @@ unsigned long shm_sz = SZ_2M;
int no_read;
int warned;
+int deadlock;
int private;
int verbose;
@@ -1095,6 +1096,82 @@ test_exit(int expect)
exit(ret);
}
+
+/*
+ * Test for deadlock scenario raised by Pavel.
+ * Test hangs but is interruptible.
+ *
+ * [Pavel's comments]
+ *
+ * Ok, now the original io_uring instance will wait until the attached
+ * once get rid of their references. That's a versatile ground to have
+ * in kernel deadlocks.
+ *
+ * task1: uring1 = create()
+ * task2: uring2 = create()
+ * task1: uring3 = create(share=uring2);
+ * task2: uring4 = create(share=uring1);
+ *
+ * task1: io_sqe_buffers_unregister(uring1)
+ * task2: io_sqe_buffers_unregister(uring2)
+ *
+ * If I skimmed through the code right, that should hang unkillably.
+ */
+static int test_deadlock(void)
+{
+ int i, pid, ret, fd0, fd1;
+ struct io_uring rings[4];
+ struct io_uring_params p;
+
+ for (i = 0; i < 2; i++) {
+ memset(&p, 0, sizeof(p));
+ p.flags = IORING_SETUP_SHARE_BUF;
+ ret = io_uring_queue_init_params(1, &rings[i], &p);
+ if (ret) {
+ verror("queue_init share");
+ return ret;
+ }
+ }
+
+ fd0 = rings[0].ring_fd;
+ fd1 = rings[1].ring_fd;
+
+ pid = fork();
+
+ memset(&p, 0, sizeof(p));
+ p.flags = IORING_SETUP_ATTACH_BUF;
+
+ if (pid) {
+ p.wq_fd = fd1;
+ ret = io_uring_queue_init_params(1, &rings[2], &p);
+ } else {
+ p.wq_fd = fd0;
+ ret = io_uring_queue_init_params(1, &rings[3], &p);
+ }
+
+ if (ret) {
+ verror("queue_init attach");
+ return ret;
+ }
+
+ vinfo(V1, "unregister\n");
+
+ if (pid) {
+ close(fd1);
+ ret = io_uring_unregister_buffers(&rings[0]);
+ } else {
+ close(fd0);
+ ret = io_uring_unregister_buffers(&rings[1]);
+ }
+
+ vinfo(V1, "unregister done\n");
+
+ if (ret)
+ verror("unregister");
+
+ return ret;
+}
+
/*
* main()
* -> shm_create()
@@ -1122,8 +1199,11 @@ main(int argc, char *argv[])
int shmid, pid, ret = 0;
char c;
- while ((c = getopt(argc, argv, "ps:v:")) != -1)
+ while ((c = getopt(argc, argv, "dps:v:")) != -1)
switch (c) {
+ case 'd':
+ deadlock++;
+ break;
case 'p':
private++;
break;
@@ -1146,6 +1226,9 @@ main(int argc, char *argv[])
if (!nids || nids > MAXID)
exit(1);
+ if (deadlock)
+ exit(test_deadlock());
+
shmstat = shmstat_create();
if (shmstat == MAP_FAILED)
exit(1);
--
1.8.3.1
next prev parent reply other threads:[~2021-01-22 22:58 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-22 22:54 [PATCH v2 00/10] liburing: buffer registration enhancements Bijan Mottahedeh
2021-01-22 22:54 ` [PATCH v2 01/10] liburing: support buffer registration updates Bijan Mottahedeh
2021-01-22 22:54 ` [PATCH v2 02/10] liburing: support buffer registration sharing Bijan Mottahedeh
2021-01-22 22:54 ` [PATCH v2 03/10] test/buffer-register: add buffer registration test Bijan Mottahedeh
2021-01-22 22:54 ` [PATCH v2 04/10] test/buffer-update: add buffer registration update test Bijan Mottahedeh
2021-01-22 22:54 ` [PATCH v2 05/10] test/buffer-share: add buffer registration sharing test Bijan Mottahedeh
2021-01-22 22:54 ` [PATCH v2 06/10] test/buffer-share: add private memory option Bijan Mottahedeh
2021-01-22 22:54 ` Bijan Mottahedeh [this message]
2021-01-22 22:54 ` [PATCH v2 08/10] man/io_uring_setup.2: document buffer registration sharing Bijan Mottahedeh
2021-01-22 22:54 ` [PATCH v2 09/10] man/io_uring_register.2: document buffer registration updates Bijan Mottahedeh
2021-01-22 22:54 ` [PATCH v2 10/10] man/io_uring_enter.2: document IORING_OP_BUFFERS_UPDATE Bijan Mottahedeh
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=1611356099-60732-8-git-send-email-bijan.mottahedeh@oracle.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: link
Be 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