1 // SPDX-License-Identifier: GPL-2.0
3 * io_uring opcode handling table
5 #include <linux/kernel.h>
6 #include <linux/errno.h>
8 #include <linux/file.h>
9 #include <linux/io_uring.h>
10 #include <linux/io_uring/cmd.h>
27 #include "openclose.h"
28 #include "uring_cmd.h"
42 static int io_no_issue(struct io_kiocb *req, unsigned int issue_flags)
48 static __maybe_unused int io_eopnotsupp_prep(struct io_kiocb *kiocb,
49 const struct io_uring_sqe *sqe)
54 const struct io_issue_def io_issue_defs[] = {
63 .unbound_nonreg_file = 1,
72 .async_size = sizeof(struct io_async_rw),
73 .prep = io_prep_readv,
76 [IORING_OP_WRITEV] = {
79 .unbound_nonreg_file = 1,
87 .async_size = sizeof(struct io_async_rw),
88 .prep = io_prep_writev,
94 .prep = io_fsync_prep,
97 [IORING_OP_READ_FIXED] = {
99 .unbound_nonreg_file = 1,
106 .async_size = sizeof(struct io_async_rw),
107 .prep = io_prep_read_fixed,
108 .issue = io_read_fixed,
110 [IORING_OP_WRITE_FIXED] = {
113 .unbound_nonreg_file = 1,
120 .async_size = sizeof(struct io_async_rw),
121 .prep = io_prep_write_fixed,
122 .issue = io_write_fixed,
124 [IORING_OP_POLL_ADD] = {
126 .unbound_nonreg_file = 1,
128 .prep = io_poll_add_prep,
129 .issue = io_poll_add,
131 [IORING_OP_POLL_REMOVE] = {
133 .prep = io_poll_remove_prep,
134 .issue = io_poll_remove,
136 [IORING_OP_SYNC_FILE_RANGE] = {
140 .issue = io_sync_file_range,
142 [IORING_OP_SENDMSG] = {
144 .unbound_nonreg_file = 1,
147 #if defined(CONFIG_NET)
148 .async_size = sizeof(struct io_async_msghdr),
149 .prep = io_sendmsg_prep,
152 .prep = io_eopnotsupp_prep,
155 [IORING_OP_RECVMSG] = {
157 .unbound_nonreg_file = 1,
161 #if defined(CONFIG_NET)
162 .async_size = sizeof(struct io_async_msghdr),
163 .prep = io_recvmsg_prep,
166 .prep = io_eopnotsupp_prep,
169 [IORING_OP_TIMEOUT] = {
171 .async_size = sizeof(struct io_timeout_data),
172 .prep = io_timeout_prep,
175 [IORING_OP_TIMEOUT_REMOVE] = {
176 /* used by timeout updates' prep() */
178 .prep = io_timeout_remove_prep,
179 .issue = io_timeout_remove,
181 [IORING_OP_ACCEPT] = {
183 .unbound_nonreg_file = 1,
186 .ioprio = 1, /* used for flags */
187 #if defined(CONFIG_NET)
188 .prep = io_accept_prep,
191 .prep = io_eopnotsupp_prep,
194 [IORING_OP_ASYNC_CANCEL] = {
196 .prep = io_async_cancel_prep,
197 .issue = io_async_cancel,
199 [IORING_OP_LINK_TIMEOUT] = {
201 .async_size = sizeof(struct io_timeout_data),
202 .prep = io_link_timeout_prep,
203 .issue = io_no_issue,
205 [IORING_OP_CONNECT] = {
207 .unbound_nonreg_file = 1,
209 #if defined(CONFIG_NET)
210 .async_size = sizeof(struct io_async_msghdr),
211 .prep = io_connect_prep,
214 .prep = io_eopnotsupp_prep,
217 [IORING_OP_FALLOCATE] = {
220 .prep = io_fallocate_prep,
221 .issue = io_fallocate,
223 [IORING_OP_OPENAT] = {
224 .prep = io_openat_prep,
227 [IORING_OP_CLOSE] = {
228 .prep = io_close_prep,
231 [IORING_OP_FILES_UPDATE] = {
234 .prep = io_files_update_prep,
235 .issue = io_files_update,
237 [IORING_OP_STATX] = {
239 .prep = io_statx_prep,
244 .unbound_nonreg_file = 1,
252 .async_size = sizeof(struct io_async_rw),
253 .prep = io_prep_read,
256 [IORING_OP_WRITE] = {
259 .unbound_nonreg_file = 1,
266 .async_size = sizeof(struct io_async_rw),
267 .prep = io_prep_write,
270 [IORING_OP_FADVISE] = {
273 .prep = io_fadvise_prep,
276 [IORING_OP_MADVISE] = {
278 .prep = io_madvise_prep,
283 .unbound_nonreg_file = 1,
288 #if defined(CONFIG_NET)
289 .async_size = sizeof(struct io_async_msghdr),
290 .prep = io_sendmsg_prep,
293 .prep = io_eopnotsupp_prep,
298 .unbound_nonreg_file = 1,
303 #if defined(CONFIG_NET)
304 .async_size = sizeof(struct io_async_msghdr),
305 .prep = io_recvmsg_prep,
308 .prep = io_eopnotsupp_prep,
311 [IORING_OP_OPENAT2] = {
312 .prep = io_openat2_prep,
315 [IORING_OP_EPOLL_CTL] = {
316 .unbound_nonreg_file = 1,
318 #if defined(CONFIG_EPOLL)
319 .prep = io_epoll_ctl_prep,
320 .issue = io_epoll_ctl,
322 .prep = io_eopnotsupp_prep,
325 [IORING_OP_SPLICE] = {
328 .unbound_nonreg_file = 1,
330 .prep = io_splice_prep,
333 [IORING_OP_PROVIDE_BUFFERS] = {
336 .prep = io_provide_buffers_prep,
337 .issue = io_manage_buffers_legacy,
339 [IORING_OP_REMOVE_BUFFERS] = {
342 .prep = io_remove_buffers_prep,
343 .issue = io_manage_buffers_legacy,
348 .unbound_nonreg_file = 1,
353 [IORING_OP_SHUTDOWN] = {
355 #if defined(CONFIG_NET)
356 .prep = io_shutdown_prep,
357 .issue = io_shutdown,
359 .prep = io_eopnotsupp_prep,
362 [IORING_OP_RENAMEAT] = {
363 .prep = io_renameat_prep,
364 .issue = io_renameat,
366 [IORING_OP_UNLINKAT] = {
367 .prep = io_unlinkat_prep,
368 .issue = io_unlinkat,
370 [IORING_OP_MKDIRAT] = {
371 .prep = io_mkdirat_prep,
374 [IORING_OP_SYMLINKAT] = {
375 .prep = io_symlinkat_prep,
376 .issue = io_symlinkat,
378 [IORING_OP_LINKAT] = {
379 .prep = io_linkat_prep,
382 [IORING_OP_MSG_RING] = {
385 .prep = io_msg_ring_prep,
386 .issue = io_msg_ring,
388 [IORING_OP_FSETXATTR] = {
390 .prep = io_fsetxattr_prep,
391 .issue = io_fsetxattr,
393 [IORING_OP_SETXATTR] = {
394 .prep = io_setxattr_prep,
395 .issue = io_setxattr,
397 [IORING_OP_FGETXATTR] = {
399 .prep = io_fgetxattr_prep,
400 .issue = io_fgetxattr,
402 [IORING_OP_GETXATTR] = {
403 .prep = io_getxattr_prep,
404 .issue = io_getxattr,
406 [IORING_OP_SOCKET] = {
408 #if defined(CONFIG_NET)
409 .prep = io_socket_prep,
412 .prep = io_eopnotsupp_prep,
415 [IORING_OP_URING_CMD] = {
420 .async_size = sizeof(struct io_async_cmd),
421 .prep = io_uring_cmd_prep,
422 .issue = io_uring_cmd,
424 [IORING_OP_SEND_ZC] = {
426 .unbound_nonreg_file = 1,
430 #if defined(CONFIG_NET)
431 .async_size = sizeof(struct io_async_msghdr),
432 .prep = io_send_zc_prep,
435 .prep = io_eopnotsupp_prep,
438 [IORING_OP_SENDMSG_ZC] = {
440 .unbound_nonreg_file = 1,
443 #if defined(CONFIG_NET)
444 .async_size = sizeof(struct io_async_msghdr),
445 .prep = io_send_zc_prep,
446 .issue = io_sendmsg_zc,
448 .prep = io_eopnotsupp_prep,
451 [IORING_OP_READ_MULTISHOT] = {
453 .unbound_nonreg_file = 1,
457 .async_size = sizeof(struct io_async_rw),
458 .prep = io_read_mshot_prep,
459 .issue = io_read_mshot,
461 [IORING_OP_WAITID] = {
462 .async_size = sizeof(struct io_waitid_async),
463 .prep = io_waitid_prep,
466 [IORING_OP_FUTEX_WAIT] = {
467 #if defined(CONFIG_FUTEX)
468 .prep = io_futex_prep,
469 .issue = io_futex_wait,
471 .prep = io_eopnotsupp_prep,
474 [IORING_OP_FUTEX_WAKE] = {
475 #if defined(CONFIG_FUTEX)
476 .prep = io_futex_prep,
477 .issue = io_futex_wake,
479 .prep = io_eopnotsupp_prep,
482 [IORING_OP_FUTEX_WAITV] = {
483 #if defined(CONFIG_FUTEX)
484 .prep = io_futexv_prep,
485 .issue = io_futexv_wait,
487 .prep = io_eopnotsupp_prep,
490 [IORING_OP_FIXED_FD_INSTALL] = {
492 .prep = io_install_fixed_fd_prep,
493 .issue = io_install_fixed_fd,
495 [IORING_OP_FTRUNCATE] = {
498 .prep = io_ftruncate_prep,
499 .issue = io_ftruncate,
502 #if defined(CONFIG_NET)
504 .prep = io_bind_prep,
506 .async_size = sizeof(struct io_async_msghdr),
508 .prep = io_eopnotsupp_prep,
511 [IORING_OP_LISTEN] = {
512 #if defined(CONFIG_NET)
514 .prep = io_listen_prep,
516 .async_size = sizeof(struct io_async_msghdr),
518 .prep = io_eopnotsupp_prep,
521 [IORING_OP_RECV_ZC] = {
523 .unbound_nonreg_file = 1,
526 #if defined(CONFIG_NET)
527 .prep = io_recvzc_prep,
530 .prep = io_eopnotsupp_prep,
533 [IORING_OP_EPOLL_WAIT] = {
537 #if defined(CONFIG_EPOLL)
538 .prep = io_epoll_wait_prep,
539 .issue = io_epoll_wait,
541 .prep = io_eopnotsupp_prep,
544 [IORING_OP_READV_FIXED] = {
546 .unbound_nonreg_file = 1,
554 .async_size = sizeof(struct io_async_rw),
555 .prep = io_prep_readv_fixed,
558 [IORING_OP_WRITEV_FIXED] = {
561 .unbound_nonreg_file = 1,
569 .async_size = sizeof(struct io_async_rw),
570 .prep = io_prep_writev_fixed,
574 .prep = io_pipe_prep,
579 const struct io_cold_def io_cold_defs[] = {
583 [IORING_OP_READV] = {
585 .cleanup = io_readv_writev_cleanup,
588 [IORING_OP_WRITEV] = {
590 .cleanup = io_readv_writev_cleanup,
593 [IORING_OP_FSYNC] = {
596 [IORING_OP_READ_FIXED] = {
597 .name = "READ_FIXED",
598 .cleanup = io_readv_writev_cleanup,
601 [IORING_OP_WRITE_FIXED] = {
602 .name = "WRITE_FIXED",
603 .cleanup = io_readv_writev_cleanup,
606 [IORING_OP_POLL_ADD] = {
609 [IORING_OP_POLL_REMOVE] = {
610 .name = "POLL_REMOVE",
612 [IORING_OP_SYNC_FILE_RANGE] = {
613 .name = "SYNC_FILE_RANGE",
615 [IORING_OP_SENDMSG] = {
617 #if defined(CONFIG_NET)
618 .cleanup = io_sendmsg_recvmsg_cleanup,
619 .fail = io_sendrecv_fail,
622 [IORING_OP_RECVMSG] = {
624 #if defined(CONFIG_NET)
625 .cleanup = io_sendmsg_recvmsg_cleanup,
626 .fail = io_sendrecv_fail,
629 [IORING_OP_TIMEOUT] = {
632 [IORING_OP_TIMEOUT_REMOVE] = {
633 .name = "TIMEOUT_REMOVE",
635 [IORING_OP_ACCEPT] = {
638 [IORING_OP_ASYNC_CANCEL] = {
639 .name = "ASYNC_CANCEL",
641 [IORING_OP_LINK_TIMEOUT] = {
642 .name = "LINK_TIMEOUT",
644 [IORING_OP_CONNECT] = {
647 [IORING_OP_FALLOCATE] = {
650 [IORING_OP_OPENAT] = {
652 .cleanup = io_open_cleanup,
654 [IORING_OP_CLOSE] = {
657 [IORING_OP_FILES_UPDATE] = {
658 .name = "FILES_UPDATE",
660 [IORING_OP_STATX] = {
662 .cleanup = io_statx_cleanup,
666 .cleanup = io_readv_writev_cleanup,
669 [IORING_OP_WRITE] = {
671 .cleanup = io_readv_writev_cleanup,
674 [IORING_OP_FADVISE] = {
677 [IORING_OP_MADVISE] = {
682 #if defined(CONFIG_NET)
683 .cleanup = io_sendmsg_recvmsg_cleanup,
684 .fail = io_sendrecv_fail,
689 #if defined(CONFIG_NET)
690 .cleanup = io_sendmsg_recvmsg_cleanup,
691 .fail = io_sendrecv_fail,
694 [IORING_OP_OPENAT2] = {
696 .cleanup = io_open_cleanup,
698 [IORING_OP_EPOLL_CTL] = {
701 [IORING_OP_SPLICE] = {
703 .cleanup = io_splice_cleanup,
705 [IORING_OP_PROVIDE_BUFFERS] = {
706 .name = "PROVIDE_BUFFERS",
708 [IORING_OP_REMOVE_BUFFERS] = {
709 .name = "REMOVE_BUFFERS",
713 .cleanup = io_splice_cleanup,
715 [IORING_OP_SHUTDOWN] = {
718 [IORING_OP_RENAMEAT] = {
720 .cleanup = io_renameat_cleanup,
722 [IORING_OP_UNLINKAT] = {
724 .cleanup = io_unlinkat_cleanup,
726 [IORING_OP_MKDIRAT] = {
728 .cleanup = io_mkdirat_cleanup,
730 [IORING_OP_SYMLINKAT] = {
732 .cleanup = io_link_cleanup,
734 [IORING_OP_LINKAT] = {
736 .cleanup = io_link_cleanup,
738 [IORING_OP_MSG_RING] = {
740 .cleanup = io_msg_ring_cleanup,
742 [IORING_OP_FSETXATTR] = {
744 .cleanup = io_xattr_cleanup,
746 [IORING_OP_SETXATTR] = {
748 .cleanup = io_xattr_cleanup,
750 [IORING_OP_FGETXATTR] = {
752 .cleanup = io_xattr_cleanup,
754 [IORING_OP_GETXATTR] = {
756 .cleanup = io_xattr_cleanup,
758 [IORING_OP_SOCKET] = {
761 [IORING_OP_URING_CMD] = {
763 .cleanup = io_uring_cmd_cleanup,
765 [IORING_OP_SEND_ZC] = {
767 #if defined(CONFIG_NET)
768 .cleanup = io_send_zc_cleanup,
769 .fail = io_sendrecv_fail,
772 [IORING_OP_SENDMSG_ZC] = {
773 .name = "SENDMSG_ZC",
774 #if defined(CONFIG_NET)
775 .cleanup = io_send_zc_cleanup,
776 .fail = io_sendrecv_fail,
779 [IORING_OP_READ_MULTISHOT] = {
780 .name = "READ_MULTISHOT",
781 .cleanup = io_readv_writev_cleanup,
783 [IORING_OP_WAITID] = {
786 [IORING_OP_FUTEX_WAIT] = {
787 .name = "FUTEX_WAIT",
789 [IORING_OP_FUTEX_WAKE] = {
790 .name = "FUTEX_WAKE",
792 [IORING_OP_FUTEX_WAITV] = {
793 .name = "FUTEX_WAITV",
795 [IORING_OP_FIXED_FD_INSTALL] = {
796 .name = "FIXED_FD_INSTALL",
798 [IORING_OP_FTRUNCATE] = {
804 [IORING_OP_LISTEN] = {
807 [IORING_OP_RECV_ZC] = {
810 [IORING_OP_EPOLL_WAIT] = {
811 .name = "EPOLL_WAIT",
813 [IORING_OP_READV_FIXED] = {
814 .name = "READV_FIXED",
815 .cleanup = io_readv_writev_cleanup,
818 [IORING_OP_WRITEV_FIXED] = {
819 .name = "WRITEV_FIXED",
820 .cleanup = io_readv_writev_cleanup,
828 const char *io_uring_get_opcode(u8 opcode)
830 if (opcode < IORING_OP_LAST)
831 return io_cold_defs[opcode].name;
835 bool io_uring_op_supported(u8 opcode)
837 if (opcode < IORING_OP_LAST &&
838 io_issue_defs[opcode].prep != io_eopnotsupp_prep)
843 void __init io_uring_optable_init(void)
847 BUILD_BUG_ON(ARRAY_SIZE(io_cold_defs) != IORING_OP_LAST);
848 BUILD_BUG_ON(ARRAY_SIZE(io_issue_defs) != IORING_OP_LAST);
850 for (i = 0; i < ARRAY_SIZE(io_issue_defs); i++) {
851 BUG_ON(!io_issue_defs[i].prep);
852 if (io_issue_defs[i].prep != io_eopnotsupp_prep)
853 BUG_ON(!io_issue_defs[i].issue);
854 WARN_ON_ONCE(!io_cold_defs[i].name);