polyphony 0.85 → 0.86
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/ext/polyphony/io_extensions.c +2 -3
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +1 -1
- data/test/test_backend.rb +1 -1
- data/test/test_signal.rb +3 -3
- data/vendor/liburing/.github/pull_request_template.md +86 -0
- data/vendor/liburing/.github/workflows/build.yml +85 -0
- data/vendor/liburing/.github/workflows/shellcheck.yml +20 -0
- data/vendor/liburing/.gitignore +149 -0
- data/vendor/liburing/COPYING +502 -0
- data/vendor/liburing/COPYING.GPL +339 -0
- data/vendor/liburing/LICENSE +7 -0
- data/vendor/liburing/Makefile +82 -0
- data/vendor/liburing/Makefile.common +5 -0
- data/vendor/liburing/Makefile.quiet +11 -0
- data/vendor/liburing/README +46 -0
- data/vendor/liburing/configure +486 -0
- data/vendor/liburing/debian/README.Debian +7 -0
- data/vendor/liburing/debian/changelog +27 -0
- data/vendor/liburing/debian/compat +1 -0
- data/vendor/liburing/debian/control +48 -0
- data/vendor/liburing/debian/copyright +49 -0
- data/vendor/liburing/debian/liburing-dev.install +4 -0
- data/vendor/liburing/debian/liburing-dev.manpages +6 -0
- data/vendor/liburing/debian/liburing1-udeb.install +1 -0
- data/vendor/liburing/debian/liburing1.install +1 -0
- data/vendor/liburing/debian/liburing1.symbols +32 -0
- data/vendor/liburing/debian/patches/series +1 -0
- data/vendor/liburing/debian/rules +81 -0
- data/vendor/liburing/debian/source/format +1 -0
- data/vendor/liburing/debian/source/local-options +2 -0
- data/vendor/liburing/debian/source/options +1 -0
- data/vendor/liburing/debian/watch +3 -0
- data/vendor/liburing/examples/Makefile +38 -0
- data/vendor/liburing/examples/io_uring-cp.c +282 -0
- data/vendor/liburing/examples/io_uring-test.c +112 -0
- data/vendor/liburing/examples/link-cp.c +193 -0
- data/vendor/liburing/examples/ucontext-cp.c +273 -0
- data/vendor/liburing/liburing.pc.in +12 -0
- data/vendor/liburing/liburing.spec +66 -0
- data/vendor/liburing/make-debs.sh +53 -0
- data/vendor/liburing/man/io_uring.7 +754 -0
- data/vendor/liburing/man/io_uring_cq_advance.3 +35 -0
- data/vendor/liburing/man/io_uring_cq_ready.3 +25 -0
- data/vendor/liburing/man/io_uring_cqe_get_data.3 +34 -0
- data/vendor/liburing/man/io_uring_cqe_seen.3 +32 -0
- data/vendor/liburing/man/io_uring_enter.2 +1483 -0
- data/vendor/liburing/man/io_uring_free_probe.3 +24 -0
- data/vendor/liburing/man/io_uring_get_probe.3 +29 -0
- data/vendor/liburing/man/io_uring_get_sqe.3 +38 -0
- data/vendor/liburing/man/io_uring_opcode_supported.3 +29 -0
- data/vendor/liburing/man/io_uring_prep_msg_ring.3 +58 -0
- data/vendor/liburing/man/io_uring_prep_read.3 +50 -0
- data/vendor/liburing/man/io_uring_prep_read_fixed.3 +54 -0
- data/vendor/liburing/man/io_uring_prep_readv.3 +51 -0
- data/vendor/liburing/man/io_uring_prep_readv2.3 +79 -0
- data/vendor/liburing/man/io_uring_prep_write.3 +50 -0
- data/vendor/liburing/man/io_uring_prep_write_fixed.3 +54 -0
- data/vendor/liburing/man/io_uring_prep_writev.3 +51 -0
- data/vendor/liburing/man/io_uring_prep_writev2.3 +78 -0
- data/vendor/liburing/man/io_uring_queue_exit.3 +27 -0
- data/vendor/liburing/man/io_uring_queue_init.3 +44 -0
- data/vendor/liburing/man/io_uring_register.2 +688 -0
- data/vendor/liburing/man/io_uring_register_buffers.3 +41 -0
- data/vendor/liburing/man/io_uring_register_files.3 +35 -0
- data/vendor/liburing/man/io_uring_setup.2 +534 -0
- data/vendor/liburing/man/io_uring_sq_ready.3 +25 -0
- data/vendor/liburing/man/io_uring_sq_space_left.3 +25 -0
- data/vendor/liburing/man/io_uring_sqe_set_data.3 +30 -0
- data/vendor/liburing/man/io_uring_sqe_set_flags.3 +60 -0
- data/vendor/liburing/man/io_uring_sqring_wait.3 +30 -0
- data/vendor/liburing/man/io_uring_submit.3 +29 -0
- data/vendor/liburing/man/io_uring_submit_and_wait.3 +34 -0
- data/vendor/liburing/man/io_uring_submit_and_wait_timeout.3 +49 -0
- data/vendor/liburing/man/io_uring_unregister_buffers.3 +26 -0
- data/vendor/liburing/man/io_uring_unregister_files.3 +26 -0
- data/vendor/liburing/man/io_uring_wait_cqe.3 +33 -0
- data/vendor/liburing/man/io_uring_wait_cqe_nr.3 +36 -0
- data/vendor/liburing/man/io_uring_wait_cqe_timeout.3 +39 -0
- data/vendor/liburing/man/io_uring_wait_cqes.3 +46 -0
- data/vendor/liburing/src/Makefile +89 -0
- data/vendor/liburing/src/arch/aarch64/syscall.h +95 -0
- data/vendor/liburing/src/arch/generic/lib.h +21 -0
- data/vendor/liburing/src/arch/generic/syscall.h +87 -0
- data/vendor/liburing/src/arch/syscall-defs.h +67 -0
- data/vendor/liburing/src/arch/x86/lib.h +32 -0
- data/vendor/liburing/src/arch/x86/syscall.h +160 -0
- data/vendor/liburing/src/include/liburing/barrier.h +81 -0
- data/vendor/liburing/src/include/liburing/io_uring.h +442 -0
- data/vendor/liburing/src/include/liburing.h +921 -0
- data/vendor/liburing/src/int_flags.h +8 -0
- data/vendor/liburing/src/lib.h +57 -0
- data/vendor/liburing/src/liburing.map +53 -0
- data/vendor/liburing/src/nolibc.c +48 -0
- data/vendor/liburing/src/queue.c +403 -0
- data/vendor/liburing/src/register.c +293 -0
- data/vendor/liburing/src/setup.c +332 -0
- data/vendor/liburing/src/syscall.c +47 -0
- data/vendor/liburing/src/syscall.h +103 -0
- data/vendor/liburing/test/232c93d07b74-test.c +306 -0
- data/vendor/liburing/test/35fa71a030ca-test.c +329 -0
- data/vendor/liburing/test/500f9fbadef8-test.c +89 -0
- data/vendor/liburing/test/7ad0e4b2f83c-test.c +93 -0
- data/vendor/liburing/test/8a9973408177-test.c +106 -0
- data/vendor/liburing/test/917257daa0fe-test.c +53 -0
- data/vendor/liburing/test/Makefile +244 -0
- data/vendor/liburing/test/a0908ae19763-test.c +58 -0
- data/vendor/liburing/test/a4c0b3decb33-test.c +180 -0
- data/vendor/liburing/test/accept-link.c +254 -0
- data/vendor/liburing/test/accept-reuse.c +164 -0
- data/vendor/liburing/test/accept-test.c +79 -0
- data/vendor/liburing/test/accept.c +477 -0
- data/vendor/liburing/test/across-fork.c +283 -0
- data/vendor/liburing/test/b19062a56726-test.c +53 -0
- data/vendor/liburing/test/b5837bd5311d-test.c +77 -0
- data/vendor/liburing/test/ce593a6c480a-test.c +136 -0
- data/vendor/liburing/test/close-opath.c +122 -0
- data/vendor/liburing/test/config +10 -0
- data/vendor/liburing/test/connect.c +398 -0
- data/vendor/liburing/test/cq-full.c +96 -0
- data/vendor/liburing/test/cq-overflow.c +294 -0
- data/vendor/liburing/test/cq-peek-batch.c +102 -0
- data/vendor/liburing/test/cq-ready.c +94 -0
- data/vendor/liburing/test/cq-size.c +64 -0
- data/vendor/liburing/test/d4ae271dfaae-test.c +96 -0
- data/vendor/liburing/test/d77a67ed5f27-test.c +65 -0
- data/vendor/liburing/test/defer.c +307 -0
- data/vendor/liburing/test/double-poll-crash.c +185 -0
- data/vendor/liburing/test/drop-submit.c +92 -0
- data/vendor/liburing/test/eeed8b54e0df-test.c +114 -0
- data/vendor/liburing/test/empty-eownerdead.c +45 -0
- data/vendor/liburing/test/eventfd-disable.c +151 -0
- data/vendor/liburing/test/eventfd-reg.c +76 -0
- data/vendor/liburing/test/eventfd-ring.c +97 -0
- data/vendor/liburing/test/eventfd.c +112 -0
- data/vendor/liburing/test/exec-target.c +6 -0
- data/vendor/liburing/test/exit-no-cleanup.c +117 -0
- data/vendor/liburing/test/fadvise.c +202 -0
- data/vendor/liburing/test/fallocate.c +249 -0
- data/vendor/liburing/test/fc2a85cb02ef-test.c +131 -0
- data/vendor/liburing/test/file-register.c +858 -0
- data/vendor/liburing/test/file-update.c +173 -0
- data/vendor/liburing/test/file-verify.c +629 -0
- data/vendor/liburing/test/files-exit-hang-poll.c +128 -0
- data/vendor/liburing/test/files-exit-hang-timeout.c +134 -0
- data/vendor/liburing/test/fixed-link.c +90 -0
- data/vendor/liburing/test/fpos.c +252 -0
- data/vendor/liburing/test/fsync.c +224 -0
- data/vendor/liburing/test/hardlink.c +136 -0
- data/vendor/liburing/test/helpers.c +135 -0
- data/vendor/liburing/test/helpers.h +67 -0
- data/vendor/liburing/test/io-cancel.c +550 -0
- data/vendor/liburing/test/io_uring_enter.c +296 -0
- data/vendor/liburing/test/io_uring_register.c +676 -0
- data/vendor/liburing/test/io_uring_setup.c +192 -0
- data/vendor/liburing/test/iopoll.c +372 -0
- data/vendor/liburing/test/lfs-openat-write.c +119 -0
- data/vendor/liburing/test/lfs-openat.c +275 -0
- data/vendor/liburing/test/link-timeout.c +1107 -0
- data/vendor/liburing/test/link.c +496 -0
- data/vendor/liburing/test/link_drain.c +229 -0
- data/vendor/liburing/test/madvise.c +195 -0
- data/vendor/liburing/test/mkdir.c +108 -0
- data/vendor/liburing/test/msg-ring.c +234 -0
- data/vendor/liburing/test/multicqes_drain.c +387 -0
- data/vendor/liburing/test/nop-all-sizes.c +99 -0
- data/vendor/liburing/test/nop.c +115 -0
- data/vendor/liburing/test/open-close.c +261 -0
- data/vendor/liburing/test/openat2.c +308 -0
- data/vendor/liburing/test/personality.c +204 -0
- data/vendor/liburing/test/pipe-eof.c +83 -0
- data/vendor/liburing/test/pipe-reuse.c +105 -0
- data/vendor/liburing/test/poll-cancel-ton.c +135 -0
- data/vendor/liburing/test/poll-cancel.c +228 -0
- data/vendor/liburing/test/poll-link.c +230 -0
- data/vendor/liburing/test/poll-many.c +208 -0
- data/vendor/liburing/test/poll-mshot-update.c +273 -0
- data/vendor/liburing/test/poll-ring.c +48 -0
- data/vendor/liburing/test/poll-v-poll.c +353 -0
- data/vendor/liburing/test/poll.c +109 -0
- data/vendor/liburing/test/pollfree.c +426 -0
- data/vendor/liburing/test/probe.c +135 -0
- data/vendor/liburing/test/read-write.c +876 -0
- data/vendor/liburing/test/register-restrictions.c +633 -0
- data/vendor/liburing/test/rename.c +135 -0
- data/vendor/liburing/test/ring-leak.c +173 -0
- data/vendor/liburing/test/ring-leak2.c +249 -0
- data/vendor/liburing/test/rsrc_tags.c +449 -0
- data/vendor/liburing/test/runtests-loop.sh +16 -0
- data/vendor/liburing/test/runtests.sh +170 -0
- data/vendor/liburing/test/rw_merge_test.c +97 -0
- data/vendor/liburing/test/self.c +91 -0
- data/vendor/liburing/test/send_recv.c +286 -0
- data/vendor/liburing/test/send_recvmsg.c +345 -0
- data/vendor/liburing/test/sendmsg_fs_cve.c +200 -0
- data/vendor/liburing/test/shared-wq.c +84 -0
- data/vendor/liburing/test/short-read.c +75 -0
- data/vendor/liburing/test/shutdown.c +165 -0
- data/vendor/liburing/test/sigfd-deadlock.c +74 -0
- data/vendor/liburing/test/skip-cqe.c +429 -0
- data/vendor/liburing/test/socket-rw-eagain.c +158 -0
- data/vendor/liburing/test/socket-rw-offset.c +157 -0
- data/vendor/liburing/test/socket-rw.c +145 -0
- data/vendor/liburing/test/splice.c +512 -0
- data/vendor/liburing/test/sq-full-cpp.cc +45 -0
- data/vendor/liburing/test/sq-full.c +45 -0
- data/vendor/liburing/test/sq-poll-dup.c +204 -0
- data/vendor/liburing/test/sq-poll-kthread.c +169 -0
- data/vendor/liburing/test/sq-poll-share.c +137 -0
- data/vendor/liburing/test/sq-space_left.c +159 -0
- data/vendor/liburing/test/sqpoll-cancel-hang.c +157 -0
- data/vendor/liburing/test/sqpoll-disable-exit.c +196 -0
- data/vendor/liburing/test/sqpoll-exit-hang.c +78 -0
- data/vendor/liburing/test/sqpoll-sleep.c +69 -0
- data/vendor/liburing/test/statx.c +172 -0
- data/vendor/liburing/test/stdout.c +232 -0
- data/vendor/liburing/test/submit-link-fail.c +154 -0
- data/vendor/liburing/test/submit-reuse.c +239 -0
- data/vendor/liburing/test/symlink.c +116 -0
- data/vendor/liburing/test/teardowns.c +58 -0
- data/vendor/liburing/test/thread-exit.c +143 -0
- data/vendor/liburing/test/timeout-new.c +252 -0
- data/vendor/liburing/test/timeout-overflow.c +204 -0
- data/vendor/liburing/test/timeout.c +1523 -0
- data/vendor/liburing/test/unlink.c +112 -0
- data/vendor/liburing/test/wakeup-hang.c +162 -0
- metadata +223 -2
@@ -0,0 +1,135 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Description: run various nop tests
|
4
|
+
*
|
5
|
+
*/
|
6
|
+
#include <errno.h>
|
7
|
+
#include <stdio.h>
|
8
|
+
#include <unistd.h>
|
9
|
+
#include <stdlib.h>
|
10
|
+
#include <string.h>
|
11
|
+
#include <fcntl.h>
|
12
|
+
#include <sys/stat.h>
|
13
|
+
|
14
|
+
#include "liburing.h"
|
15
|
+
|
16
|
+
static int test_rename(struct io_uring *ring, const char *old, const char *new)
|
17
|
+
{
|
18
|
+
struct io_uring_cqe *cqe;
|
19
|
+
struct io_uring_sqe *sqe;
|
20
|
+
int ret;
|
21
|
+
|
22
|
+
sqe = io_uring_get_sqe(ring);
|
23
|
+
if (!sqe) {
|
24
|
+
fprintf(stderr, "get sqe failed\n");
|
25
|
+
goto err;
|
26
|
+
}
|
27
|
+
|
28
|
+
memset(sqe, 0, sizeof(*sqe));
|
29
|
+
sqe->opcode = IORING_OP_RENAMEAT;
|
30
|
+
sqe->fd = AT_FDCWD;
|
31
|
+
sqe->addr2 = (unsigned long) new;
|
32
|
+
sqe->addr = (unsigned long) old;
|
33
|
+
sqe->len = AT_FDCWD;
|
34
|
+
|
35
|
+
ret = io_uring_submit(ring);
|
36
|
+
if (ret <= 0) {
|
37
|
+
fprintf(stderr, "sqe submit failed: %d\n", ret);
|
38
|
+
goto err;
|
39
|
+
}
|
40
|
+
|
41
|
+
ret = io_uring_wait_cqe(ring, &cqe);
|
42
|
+
if (ret < 0) {
|
43
|
+
fprintf(stderr, "wait completion %d\n", ret);
|
44
|
+
goto err;
|
45
|
+
}
|
46
|
+
ret = cqe->res;
|
47
|
+
io_uring_cqe_seen(ring, cqe);
|
48
|
+
return ret;
|
49
|
+
err:
|
50
|
+
return 1;
|
51
|
+
}
|
52
|
+
|
53
|
+
static int stat_file(const char *buf)
|
54
|
+
{
|
55
|
+
struct stat sb;
|
56
|
+
|
57
|
+
if (!stat(buf, &sb))
|
58
|
+
return 0;
|
59
|
+
|
60
|
+
return errno;
|
61
|
+
}
|
62
|
+
|
63
|
+
int main(int argc, char *argv[])
|
64
|
+
{
|
65
|
+
struct io_uring ring;
|
66
|
+
char src[32] = "./XXXXXX";
|
67
|
+
char dst[32] = "./XXXXXX";
|
68
|
+
int ret;
|
69
|
+
|
70
|
+
if (argc > 1)
|
71
|
+
return 0;
|
72
|
+
|
73
|
+
ret = io_uring_queue_init(1, &ring, 0);
|
74
|
+
if (ret) {
|
75
|
+
fprintf(stderr, "ring setup failed: %d\n", ret);
|
76
|
+
return 1;
|
77
|
+
}
|
78
|
+
|
79
|
+
ret = mkstemp(src);
|
80
|
+
if (ret < 0) {
|
81
|
+
perror("mkstemp");
|
82
|
+
return 1;
|
83
|
+
}
|
84
|
+
close(ret);
|
85
|
+
|
86
|
+
ret = mkstemp(dst);
|
87
|
+
if (ret < 0) {
|
88
|
+
perror("mkstemp");
|
89
|
+
return 1;
|
90
|
+
}
|
91
|
+
close(ret);
|
92
|
+
|
93
|
+
if (stat_file(src) != 0) {
|
94
|
+
perror("stat");
|
95
|
+
return 1;
|
96
|
+
}
|
97
|
+
if (stat_file(dst) != 0) {
|
98
|
+
perror("stat");
|
99
|
+
return 1;
|
100
|
+
}
|
101
|
+
|
102
|
+
ret = test_rename(&ring, src, dst);
|
103
|
+
if (ret < 0) {
|
104
|
+
if (ret == -EBADF || ret == -EINVAL) {
|
105
|
+
fprintf(stdout, "Rename not supported, skipping\n");
|
106
|
+
goto out;
|
107
|
+
}
|
108
|
+
fprintf(stderr, "rename: %s\n", strerror(-ret));
|
109
|
+
goto err;
|
110
|
+
} else if (ret)
|
111
|
+
goto err;
|
112
|
+
|
113
|
+
if (stat_file(src) != ENOENT) {
|
114
|
+
fprintf(stderr, "stat got %s\n", strerror(ret));
|
115
|
+
return 1;
|
116
|
+
}
|
117
|
+
|
118
|
+
if (stat_file(dst) != 0) {
|
119
|
+
perror("stat");
|
120
|
+
return 1;
|
121
|
+
}
|
122
|
+
|
123
|
+
ret = test_rename(&ring, "/x/y/1/2", "/2/1/y/x");
|
124
|
+
if (ret != -ENOENT) {
|
125
|
+
fprintf(stderr, "test_rename invalid failed: %d\n", ret);
|
126
|
+
return ret;
|
127
|
+
}
|
128
|
+
out:
|
129
|
+
unlink(dst);
|
130
|
+
return 0;
|
131
|
+
err:
|
132
|
+
unlink(src);
|
133
|
+
unlink(dst);
|
134
|
+
return 1;
|
135
|
+
}
|
@@ -0,0 +1,173 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Based on description from Al Viro - this demonstrates a leak of the
|
4
|
+
* io_uring instance, by sending the io_uring fd over a UNIX socket.
|
5
|
+
*
|
6
|
+
* See:
|
7
|
+
*
|
8
|
+
* https://lore.kernel.org/linux-block/20190129192702.3605-1-axboe@kernel.dk/T/#m6c87fc64e4d063786af6ec6fadce3ac1e95d3184
|
9
|
+
*
|
10
|
+
*/
|
11
|
+
#include <stdio.h>
|
12
|
+
#include <stdlib.h>
|
13
|
+
#include <stddef.h>
|
14
|
+
#include <signal.h>
|
15
|
+
#include <inttypes.h>
|
16
|
+
#include <sys/types.h>
|
17
|
+
#include <sys/syscall.h>
|
18
|
+
#include <sys/socket.h>
|
19
|
+
#include <sys/wait.h>
|
20
|
+
#include <fcntl.h>
|
21
|
+
#include <unistd.h>
|
22
|
+
#include <string.h>
|
23
|
+
#include <linux/fs.h>
|
24
|
+
|
25
|
+
#include "liburing.h"
|
26
|
+
#include "../src/syscall.h"
|
27
|
+
|
28
|
+
static int __io_uring_register_files(int ring_fd, int fd1, int fd2)
|
29
|
+
{
|
30
|
+
__s32 fds[2] = { fd1, fd2 };
|
31
|
+
|
32
|
+
return __sys_io_uring_register(ring_fd, IORING_REGISTER_FILES, fds, 2);
|
33
|
+
}
|
34
|
+
|
35
|
+
static int get_ring_fd(void)
|
36
|
+
{
|
37
|
+
struct io_uring_params p;
|
38
|
+
int fd;
|
39
|
+
|
40
|
+
memset(&p, 0, sizeof(p));
|
41
|
+
|
42
|
+
fd = __sys_io_uring_setup(2, &p);
|
43
|
+
if (fd < 0) {
|
44
|
+
perror("io_uring_setup");
|
45
|
+
return -1;
|
46
|
+
}
|
47
|
+
|
48
|
+
return fd;
|
49
|
+
}
|
50
|
+
|
51
|
+
static void send_fd(int socket, int fd)
|
52
|
+
{
|
53
|
+
char buf[CMSG_SPACE(sizeof(fd))];
|
54
|
+
struct cmsghdr *cmsg;
|
55
|
+
struct msghdr msg;
|
56
|
+
|
57
|
+
memset(buf, 0, sizeof(buf));
|
58
|
+
memset(&msg, 0, sizeof(msg));
|
59
|
+
|
60
|
+
msg.msg_control = buf;
|
61
|
+
msg.msg_controllen = sizeof(buf);
|
62
|
+
|
63
|
+
cmsg = CMSG_FIRSTHDR(&msg);
|
64
|
+
cmsg->cmsg_level = SOL_SOCKET;
|
65
|
+
cmsg->cmsg_type = SCM_RIGHTS;
|
66
|
+
cmsg->cmsg_len = CMSG_LEN(sizeof(fd));
|
67
|
+
|
68
|
+
memmove(CMSG_DATA(cmsg), &fd, sizeof(fd));
|
69
|
+
|
70
|
+
msg.msg_controllen = CMSG_SPACE(sizeof(fd));
|
71
|
+
|
72
|
+
if (sendmsg(socket, &msg, 0) < 0)
|
73
|
+
perror("sendmsg");
|
74
|
+
}
|
75
|
+
|
76
|
+
static int test_iowq_request_cancel(void)
|
77
|
+
{
|
78
|
+
char buffer[128];
|
79
|
+
struct io_uring ring;
|
80
|
+
struct io_uring_sqe *sqe;
|
81
|
+
int ret, fds[2];
|
82
|
+
|
83
|
+
ret = io_uring_queue_init(8, &ring, 0);
|
84
|
+
if (ret < 0) {
|
85
|
+
fprintf(stderr, "failed to init io_uring: %s\n", strerror(-ret));
|
86
|
+
return ret;
|
87
|
+
}
|
88
|
+
if (pipe(fds)) {
|
89
|
+
perror("pipe");
|
90
|
+
return -1;
|
91
|
+
}
|
92
|
+
ret = io_uring_register_files(&ring, fds, 2);
|
93
|
+
if (ret) {
|
94
|
+
fprintf(stderr, "file_register: %d\n", ret);
|
95
|
+
return ret;
|
96
|
+
}
|
97
|
+
close(fds[1]);
|
98
|
+
|
99
|
+
sqe = io_uring_get_sqe(&ring);
|
100
|
+
if (!sqe) {
|
101
|
+
fprintf(stderr, "%s: failed to get sqe\n", __FUNCTION__);
|
102
|
+
return 1;
|
103
|
+
}
|
104
|
+
/* potentially sitting in internal polling */
|
105
|
+
io_uring_prep_read(sqe, 0, buffer, 10, 0);
|
106
|
+
sqe->flags |= IOSQE_FIXED_FILE;
|
107
|
+
|
108
|
+
sqe = io_uring_get_sqe(&ring);
|
109
|
+
if (!sqe) {
|
110
|
+
fprintf(stderr, "%s: failed to get sqe\n", __FUNCTION__);
|
111
|
+
return 1;
|
112
|
+
}
|
113
|
+
/* staying in io-wq */
|
114
|
+
io_uring_prep_read(sqe, 0, buffer, 10, 0);
|
115
|
+
sqe->flags |= IOSQE_FIXED_FILE | IOSQE_ASYNC;
|
116
|
+
|
117
|
+
ret = io_uring_submit(&ring);
|
118
|
+
if (ret != 2) {
|
119
|
+
fprintf(stderr, "%s: got %d, wanted 1\n", __FUNCTION__, ret);
|
120
|
+
return 1;
|
121
|
+
}
|
122
|
+
|
123
|
+
/* should unregister files and close the write fd */
|
124
|
+
io_uring_queue_exit(&ring);
|
125
|
+
|
126
|
+
/*
|
127
|
+
* We're trying to wait for the ring to "really" exit, that will be
|
128
|
+
* done async. For that rely on the registered write end to be closed
|
129
|
+
* after ring quiesce, so failing read from the other pipe end.
|
130
|
+
*/
|
131
|
+
ret = read(fds[0], buffer, 10);
|
132
|
+
if (ret < 0)
|
133
|
+
perror("read");
|
134
|
+
return 0;
|
135
|
+
}
|
136
|
+
|
137
|
+
int main(int argc, char *argv[])
|
138
|
+
{
|
139
|
+
int sp[2], pid, ring_fd, ret;
|
140
|
+
|
141
|
+
if (argc > 1)
|
142
|
+
return 0;
|
143
|
+
|
144
|
+
ret = test_iowq_request_cancel();
|
145
|
+
if (ret) {
|
146
|
+
fprintf(stderr, "test_iowq_request_cancel() failed\n");
|
147
|
+
return 1;
|
148
|
+
}
|
149
|
+
|
150
|
+
if (socketpair(AF_UNIX, SOCK_DGRAM, 0, sp) != 0) {
|
151
|
+
perror("Failed to create Unix-domain socket pair\n");
|
152
|
+
return 1;
|
153
|
+
}
|
154
|
+
|
155
|
+
ring_fd = get_ring_fd();
|
156
|
+
if (ring_fd < 0)
|
157
|
+
return 1;
|
158
|
+
|
159
|
+
ret = __io_uring_register_files(ring_fd, sp[0], sp[1]);
|
160
|
+
if (ret < 0) {
|
161
|
+
perror("register files");
|
162
|
+
return 1;
|
163
|
+
}
|
164
|
+
|
165
|
+
pid = fork();
|
166
|
+
if (pid)
|
167
|
+
send_fd(sp[0], ring_fd);
|
168
|
+
|
169
|
+
close(ring_fd);
|
170
|
+
close(sp[0]);
|
171
|
+
close(sp[1]);
|
172
|
+
return 0;
|
173
|
+
}
|
@@ -0,0 +1,249 @@
|
|
1
|
+
/* SPDX-License-Identifier: MIT */
|
2
|
+
/*
|
3
|
+
* Description: Test two ring deadlock. A buggy kernel will end up
|
4
|
+
* having io_wq_* workers pending, as the circular reference
|
5
|
+
* will prevent full exit.
|
6
|
+
*
|
7
|
+
* Based on a test case from Josef <josef.grieb@gmail.com>
|
8
|
+
*
|
9
|
+
*/
|
10
|
+
#include <errno.h>
|
11
|
+
#include <fcntl.h>
|
12
|
+
#include <netinet/in.h>
|
13
|
+
#include <stdio.h>
|
14
|
+
#include <stdlib.h>
|
15
|
+
#include <string.h>
|
16
|
+
#include <strings.h>
|
17
|
+
#include <poll.h>
|
18
|
+
#include <sys/socket.h>
|
19
|
+
#include <unistd.h>
|
20
|
+
#include <sys/eventfd.h>
|
21
|
+
#include <pthread.h>
|
22
|
+
|
23
|
+
#include "liburing.h"
|
24
|
+
#include "../src/syscall.h"
|
25
|
+
|
26
|
+
enum {
|
27
|
+
ACCEPT,
|
28
|
+
READ,
|
29
|
+
WRITE,
|
30
|
+
POLLING_IN,
|
31
|
+
POLLING_RDHUP,
|
32
|
+
CLOSE,
|
33
|
+
EVENTFD_READ,
|
34
|
+
};
|
35
|
+
|
36
|
+
typedef struct conn_info {
|
37
|
+
__u32 fd;
|
38
|
+
__u16 type;
|
39
|
+
__u16 bid;
|
40
|
+
} conn_info;
|
41
|
+
|
42
|
+
static char read_eventfd_buffer[8];
|
43
|
+
|
44
|
+
static pthread_mutex_t lock;
|
45
|
+
static struct io_uring *client_ring;
|
46
|
+
|
47
|
+
static int client_eventfd = -1;
|
48
|
+
|
49
|
+
int setup_io_uring(struct io_uring *ring)
|
50
|
+
{
|
51
|
+
struct io_uring_params p = { };
|
52
|
+
int ret;
|
53
|
+
|
54
|
+
ret = io_uring_queue_init_params(8, ring, &p);
|
55
|
+
if (ret) {
|
56
|
+
fprintf(stderr, "Unable to setup io_uring: %s\n",
|
57
|
+
strerror(-ret));
|
58
|
+
return 1;
|
59
|
+
}
|
60
|
+
return 0;
|
61
|
+
}
|
62
|
+
|
63
|
+
static void add_socket_eventfd_read(struct io_uring *ring, int fd)
|
64
|
+
{
|
65
|
+
struct io_uring_sqe *sqe;
|
66
|
+
conn_info conn_i = {
|
67
|
+
.fd = fd,
|
68
|
+
.type = EVENTFD_READ,
|
69
|
+
};
|
70
|
+
|
71
|
+
sqe = io_uring_get_sqe(ring);
|
72
|
+
io_uring_prep_read(sqe, fd, &read_eventfd_buffer, 8, 0);
|
73
|
+
io_uring_sqe_set_flags(sqe, IOSQE_ASYNC);
|
74
|
+
|
75
|
+
memcpy(&sqe->user_data, &conn_i, sizeof(conn_i));
|
76
|
+
}
|
77
|
+
|
78
|
+
static void add_socket_pollin(struct io_uring *ring, int fd)
|
79
|
+
{
|
80
|
+
struct io_uring_sqe *sqe;
|
81
|
+
conn_info conn_i = {
|
82
|
+
.fd = fd,
|
83
|
+
.type = POLLING_IN,
|
84
|
+
};
|
85
|
+
|
86
|
+
sqe = io_uring_get_sqe(ring);
|
87
|
+
io_uring_prep_poll_add(sqe, fd, POLL_IN);
|
88
|
+
|
89
|
+
memcpy(&sqe->user_data, &conn_i, sizeof(conn_i));
|
90
|
+
}
|
91
|
+
|
92
|
+
static void *server_thread(void *arg)
|
93
|
+
{
|
94
|
+
struct sockaddr_in serv_addr;
|
95
|
+
int port = 0;
|
96
|
+
int sock_listen_fd, evfd;
|
97
|
+
const int val = 1;
|
98
|
+
struct io_uring ring;
|
99
|
+
|
100
|
+
sock_listen_fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
|
101
|
+
setsockopt(sock_listen_fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
|
102
|
+
|
103
|
+
memset(&serv_addr, 0, sizeof(serv_addr));
|
104
|
+
serv_addr.sin_family = AF_INET;
|
105
|
+
serv_addr.sin_port = htons(port);
|
106
|
+
serv_addr.sin_addr.s_addr = INADDR_ANY;
|
107
|
+
|
108
|
+
evfd = eventfd(0, EFD_CLOEXEC);
|
109
|
+
|
110
|
+
// bind and listen
|
111
|
+
if (bind(sock_listen_fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
|
112
|
+
perror("Error binding socket...\n");
|
113
|
+
exit(1);
|
114
|
+
}
|
115
|
+
if (listen(sock_listen_fd, 1) < 0) {
|
116
|
+
perror("Error listening on socket...\n");
|
117
|
+
exit(1);
|
118
|
+
}
|
119
|
+
|
120
|
+
setup_io_uring(&ring);
|
121
|
+
add_socket_eventfd_read(&ring, evfd);
|
122
|
+
add_socket_pollin(&ring, sock_listen_fd);
|
123
|
+
|
124
|
+
while (1) {
|
125
|
+
struct io_uring_cqe *cqe;
|
126
|
+
unsigned head;
|
127
|
+
unsigned count = 0;
|
128
|
+
|
129
|
+
io_uring_submit_and_wait(&ring, 1);
|
130
|
+
|
131
|
+
io_uring_for_each_cqe(&ring, head, cqe) {
|
132
|
+
struct conn_info conn_i;
|
133
|
+
|
134
|
+
count++;
|
135
|
+
memcpy(&conn_i, &cqe->user_data, sizeof(conn_i));
|
136
|
+
|
137
|
+
if (conn_i.type == ACCEPT) {
|
138
|
+
int sock_conn_fd = cqe->res;
|
139
|
+
// only read when there is no error, >= 0
|
140
|
+
if (sock_conn_fd > 0) {
|
141
|
+
add_socket_pollin(&ring, sock_listen_fd);
|
142
|
+
|
143
|
+
pthread_mutex_lock(&lock);
|
144
|
+
io_uring_submit(client_ring);
|
145
|
+
pthread_mutex_unlock(&lock);
|
146
|
+
|
147
|
+
}
|
148
|
+
} else if (conn_i.type == POLLING_IN) {
|
149
|
+
break;
|
150
|
+
}
|
151
|
+
}
|
152
|
+
io_uring_cq_advance(&ring, count);
|
153
|
+
}
|
154
|
+
}
|
155
|
+
|
156
|
+
static void *client_thread(void *arg)
|
157
|
+
{
|
158
|
+
struct io_uring ring;
|
159
|
+
int ret;
|
160
|
+
|
161
|
+
setup_io_uring(&ring);
|
162
|
+
client_ring = ˚
|
163
|
+
|
164
|
+
client_eventfd = eventfd(0, EFD_CLOEXEC);
|
165
|
+
pthread_mutex_lock(&lock);
|
166
|
+
add_socket_eventfd_read(&ring, client_eventfd);
|
167
|
+
pthread_mutex_unlock(&lock);
|
168
|
+
|
169
|
+
while (1) {
|
170
|
+
struct io_uring_cqe *cqe;
|
171
|
+
unsigned head;
|
172
|
+
unsigned count = 0;
|
173
|
+
|
174
|
+
pthread_mutex_lock(&lock);
|
175
|
+
io_uring_submit(&ring);
|
176
|
+
pthread_mutex_unlock(&lock);
|
177
|
+
|
178
|
+
ret = __sys_io_uring_enter(ring.ring_fd, 0, 1, IORING_ENTER_GETEVENTS, NULL);
|
179
|
+
if (ret < 0) {
|
180
|
+
perror("Error io_uring_enter...\n");
|
181
|
+
exit(1);
|
182
|
+
}
|
183
|
+
|
184
|
+
// go through all CQEs
|
185
|
+
io_uring_for_each_cqe(&ring, head, cqe) {
|
186
|
+
struct conn_info conn_i;
|
187
|
+
int type;
|
188
|
+
|
189
|
+
count++;
|
190
|
+
memcpy(&conn_i, &cqe->user_data, sizeof(conn_i));
|
191
|
+
|
192
|
+
type = conn_i.type;
|
193
|
+
if (type == READ) {
|
194
|
+
pthread_mutex_lock(&lock);
|
195
|
+
|
196
|
+
if (cqe->res <= 0) {
|
197
|
+
// connection closed or error
|
198
|
+
shutdown(conn_i.fd, SHUT_RDWR);
|
199
|
+
} else {
|
200
|
+
pthread_mutex_unlock(&lock);
|
201
|
+
break;
|
202
|
+
}
|
203
|
+
add_socket_pollin(&ring, conn_i.fd);
|
204
|
+
pthread_mutex_unlock(&lock);
|
205
|
+
} else if (type == WRITE) {
|
206
|
+
} else if (type == POLLING_IN) {
|
207
|
+
break;
|
208
|
+
} else if (type == POLLING_RDHUP) {
|
209
|
+
break;
|
210
|
+
} else if (type == CLOSE) {
|
211
|
+
} else if (type == EVENTFD_READ) {
|
212
|
+
add_socket_eventfd_read(&ring, client_eventfd);
|
213
|
+
}
|
214
|
+
}
|
215
|
+
|
216
|
+
io_uring_cq_advance(&ring, count);
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
static void sig_alrm(int sig)
|
221
|
+
{
|
222
|
+
exit(0);
|
223
|
+
}
|
224
|
+
|
225
|
+
int main(int argc, char *argv[])
|
226
|
+
{
|
227
|
+
pthread_t server_thread_t, client_thread_t;
|
228
|
+
struct sigaction act;
|
229
|
+
|
230
|
+
if (argc > 1)
|
231
|
+
return 0;
|
232
|
+
|
233
|
+
if (pthread_mutex_init(&lock, NULL) != 0) {
|
234
|
+
printf("\n mutex init failed\n");
|
235
|
+
return 1;
|
236
|
+
}
|
237
|
+
|
238
|
+
pthread_create(&server_thread_t, NULL, &server_thread, NULL);
|
239
|
+
pthread_create(&client_thread_t, NULL, &client_thread, NULL);
|
240
|
+
|
241
|
+
memset(&act, 0, sizeof(act));
|
242
|
+
act.sa_handler = sig_alrm;
|
243
|
+
act.sa_flags = SA_RESTART;
|
244
|
+
sigaction(SIGALRM, &act, NULL);
|
245
|
+
alarm(1);
|
246
|
+
|
247
|
+
pthread_join(server_thread_t, NULL);
|
248
|
+
return 0;
|
249
|
+
}
|