opdef.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * io_uring opcode handling table
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/errno.h>
  7. #include <linux/fs.h>
  8. #include <linux/file.h>
  9. #include <linux/io_uring.h>
  10. #include <linux/io_uring/cmd.h>
  11. #include "io_uring.h"
  12. #include "opdef.h"
  13. #include "refs.h"
  14. #include "tctx.h"
  15. #include "sqpoll.h"
  16. #include "fdinfo.h"
  17. #include "kbuf.h"
  18. #include "rsrc.h"
  19. #include "xattr.h"
  20. #include "nop.h"
  21. #include "fs.h"
  22. #include "splice.h"
  23. #include "sync.h"
  24. #include "advise.h"
  25. #include "openclose.h"
  26. #include "uring_cmd.h"
  27. #include "epoll.h"
  28. #include "statx.h"
  29. #include "net.h"
  30. #include "msg_ring.h"
  31. #include "timeout.h"
  32. #include "poll.h"
  33. #include "cancel.h"
  34. #include "rw.h"
  35. #include "waitid.h"
  36. #include "futex.h"
  37. #include "truncate.h"
  38. #include "zcrx.h"
  39. static int io_no_issue(struct io_kiocb *req, unsigned int issue_flags)
  40. {
  41. WARN_ON_ONCE(1);
  42. return -ECANCELED;
  43. }
  44. static __maybe_unused int io_eopnotsupp_prep(struct io_kiocb *kiocb,
  45. const struct io_uring_sqe *sqe)
  46. {
  47. return -EOPNOTSUPP;
  48. }
  49. const struct io_issue_def io_issue_defs[] = {
  50. [IORING_OP_NOP] = {
  51. .audit_skip = 1,
  52. .iopoll = 1,
  53. .prep = io_nop_prep,
  54. .issue = io_nop,
  55. },
  56. [IORING_OP_READV] = {
  57. .needs_file = 1,
  58. .unbound_nonreg_file = 1,
  59. .pollin = 1,
  60. .buffer_select = 1,
  61. .plug = 1,
  62. .audit_skip = 1,
  63. .ioprio = 1,
  64. .iopoll = 1,
  65. .iopoll_queue = 1,
  66. .vectored = 1,
  67. .async_size = sizeof(struct io_async_rw),
  68. .prep = io_prep_readv,
  69. .issue = io_read,
  70. },
  71. [IORING_OP_WRITEV] = {
  72. .needs_file = 1,
  73. .hash_reg_file = 1,
  74. .unbound_nonreg_file = 1,
  75. .pollout = 1,
  76. .plug = 1,
  77. .audit_skip = 1,
  78. .ioprio = 1,
  79. .iopoll = 1,
  80. .iopoll_queue = 1,
  81. .vectored = 1,
  82. .async_size = sizeof(struct io_async_rw),
  83. .prep = io_prep_writev,
  84. .issue = io_write,
  85. },
  86. [IORING_OP_FSYNC] = {
  87. .needs_file = 1,
  88. .audit_skip = 1,
  89. .prep = io_fsync_prep,
  90. .issue = io_fsync,
  91. },
  92. [IORING_OP_READ_FIXED] = {
  93. .needs_file = 1,
  94. .unbound_nonreg_file = 1,
  95. .pollin = 1,
  96. .plug = 1,
  97. .audit_skip = 1,
  98. .ioprio = 1,
  99. .iopoll = 1,
  100. .iopoll_queue = 1,
  101. .async_size = sizeof(struct io_async_rw),
  102. .prep = io_prep_read_fixed,
  103. .issue = io_read_fixed,
  104. },
  105. [IORING_OP_WRITE_FIXED] = {
  106. .needs_file = 1,
  107. .hash_reg_file = 1,
  108. .unbound_nonreg_file = 1,
  109. .pollout = 1,
  110. .plug = 1,
  111. .audit_skip = 1,
  112. .ioprio = 1,
  113. .iopoll = 1,
  114. .iopoll_queue = 1,
  115. .async_size = sizeof(struct io_async_rw),
  116. .prep = io_prep_write_fixed,
  117. .issue = io_write_fixed,
  118. },
  119. [IORING_OP_POLL_ADD] = {
  120. .needs_file = 1,
  121. .unbound_nonreg_file = 1,
  122. .audit_skip = 1,
  123. .prep = io_poll_add_prep,
  124. .issue = io_poll_add,
  125. },
  126. [IORING_OP_POLL_REMOVE] = {
  127. .audit_skip = 1,
  128. .prep = io_poll_remove_prep,
  129. .issue = io_poll_remove,
  130. },
  131. [IORING_OP_SYNC_FILE_RANGE] = {
  132. .needs_file = 1,
  133. .audit_skip = 1,
  134. .prep = io_sfr_prep,
  135. .issue = io_sync_file_range,
  136. },
  137. [IORING_OP_SENDMSG] = {
  138. .needs_file = 1,
  139. .unbound_nonreg_file = 1,
  140. .pollout = 1,
  141. .ioprio = 1,
  142. #if defined(CONFIG_NET)
  143. .async_size = sizeof(struct io_async_msghdr),
  144. .prep = io_sendmsg_prep,
  145. .issue = io_sendmsg,
  146. #else
  147. .prep = io_eopnotsupp_prep,
  148. #endif
  149. },
  150. [IORING_OP_RECVMSG] = {
  151. .needs_file = 1,
  152. .unbound_nonreg_file = 1,
  153. .pollin = 1,
  154. .buffer_select = 1,
  155. .ioprio = 1,
  156. #if defined(CONFIG_NET)
  157. .async_size = sizeof(struct io_async_msghdr),
  158. .prep = io_recvmsg_prep,
  159. .issue = io_recvmsg,
  160. #else
  161. .prep = io_eopnotsupp_prep,
  162. #endif
  163. },
  164. [IORING_OP_TIMEOUT] = {
  165. .audit_skip = 1,
  166. .async_size = sizeof(struct io_timeout_data),
  167. .prep = io_timeout_prep,
  168. .issue = io_timeout,
  169. },
  170. [IORING_OP_TIMEOUT_REMOVE] = {
  171. /* used by timeout updates' prep() */
  172. .audit_skip = 1,
  173. .prep = io_timeout_remove_prep,
  174. .issue = io_timeout_remove,
  175. },
  176. [IORING_OP_ACCEPT] = {
  177. .needs_file = 1,
  178. .unbound_nonreg_file = 1,
  179. .pollin = 1,
  180. .poll_exclusive = 1,
  181. .ioprio = 1, /* used for flags */
  182. #if defined(CONFIG_NET)
  183. .prep = io_accept_prep,
  184. .issue = io_accept,
  185. #else
  186. .prep = io_eopnotsupp_prep,
  187. #endif
  188. },
  189. [IORING_OP_ASYNC_CANCEL] = {
  190. .audit_skip = 1,
  191. .prep = io_async_cancel_prep,
  192. .issue = io_async_cancel,
  193. },
  194. [IORING_OP_LINK_TIMEOUT] = {
  195. .audit_skip = 1,
  196. .async_size = sizeof(struct io_timeout_data),
  197. .prep = io_link_timeout_prep,
  198. .issue = io_no_issue,
  199. },
  200. [IORING_OP_CONNECT] = {
  201. .needs_file = 1,
  202. .unbound_nonreg_file = 1,
  203. .pollout = 1,
  204. #if defined(CONFIG_NET)
  205. .async_size = sizeof(struct io_async_msghdr),
  206. .prep = io_connect_prep,
  207. .issue = io_connect,
  208. #else
  209. .prep = io_eopnotsupp_prep,
  210. #endif
  211. },
  212. [IORING_OP_FALLOCATE] = {
  213. .needs_file = 1,
  214. .hash_reg_file = 1,
  215. .prep = io_fallocate_prep,
  216. .issue = io_fallocate,
  217. },
  218. [IORING_OP_OPENAT] = {
  219. .filter_pdu_size = sizeof_field(struct io_uring_bpf_ctx, open),
  220. .prep = io_openat_prep,
  221. .issue = io_openat,
  222. .filter_populate = io_openat_bpf_populate,
  223. },
  224. [IORING_OP_CLOSE] = {
  225. .prep = io_close_prep,
  226. .issue = io_close,
  227. },
  228. [IORING_OP_FILES_UPDATE] = {
  229. .audit_skip = 1,
  230. .iopoll = 1,
  231. .prep = io_files_update_prep,
  232. .issue = io_files_update,
  233. },
  234. [IORING_OP_STATX] = {
  235. .audit_skip = 1,
  236. .prep = io_statx_prep,
  237. .issue = io_statx,
  238. },
  239. [IORING_OP_READ] = {
  240. .needs_file = 1,
  241. .unbound_nonreg_file = 1,
  242. .pollin = 1,
  243. .buffer_select = 1,
  244. .plug = 1,
  245. .audit_skip = 1,
  246. .ioprio = 1,
  247. .iopoll = 1,
  248. .iopoll_queue = 1,
  249. .async_size = sizeof(struct io_async_rw),
  250. .prep = io_prep_read,
  251. .issue = io_read,
  252. },
  253. [IORING_OP_WRITE] = {
  254. .needs_file = 1,
  255. .hash_reg_file = 1,
  256. .unbound_nonreg_file = 1,
  257. .pollout = 1,
  258. .plug = 1,
  259. .audit_skip = 1,
  260. .ioprio = 1,
  261. .iopoll = 1,
  262. .iopoll_queue = 1,
  263. .async_size = sizeof(struct io_async_rw),
  264. .prep = io_prep_write,
  265. .issue = io_write,
  266. },
  267. [IORING_OP_FADVISE] = {
  268. .needs_file = 1,
  269. .audit_skip = 1,
  270. .prep = io_fadvise_prep,
  271. .issue = io_fadvise,
  272. },
  273. [IORING_OP_MADVISE] = {
  274. .audit_skip = 1,
  275. .prep = io_madvise_prep,
  276. .issue = io_madvise,
  277. },
  278. [IORING_OP_SEND] = {
  279. .needs_file = 1,
  280. .unbound_nonreg_file = 1,
  281. .pollout = 1,
  282. .audit_skip = 1,
  283. .ioprio = 1,
  284. .buffer_select = 1,
  285. #if defined(CONFIG_NET)
  286. .async_size = sizeof(struct io_async_msghdr),
  287. .prep = io_sendmsg_prep,
  288. .issue = io_send,
  289. #else
  290. .prep = io_eopnotsupp_prep,
  291. #endif
  292. },
  293. [IORING_OP_RECV] = {
  294. .needs_file = 1,
  295. .unbound_nonreg_file = 1,
  296. .pollin = 1,
  297. .buffer_select = 1,
  298. .audit_skip = 1,
  299. .ioprio = 1,
  300. #if defined(CONFIG_NET)
  301. .async_size = sizeof(struct io_async_msghdr),
  302. .prep = io_recvmsg_prep,
  303. .issue = io_recv,
  304. #else
  305. .prep = io_eopnotsupp_prep,
  306. #endif
  307. },
  308. [IORING_OP_OPENAT2] = {
  309. .filter_pdu_size = sizeof_field(struct io_uring_bpf_ctx, open),
  310. .prep = io_openat2_prep,
  311. .issue = io_openat2,
  312. .filter_populate = io_openat_bpf_populate,
  313. },
  314. [IORING_OP_EPOLL_CTL] = {
  315. .unbound_nonreg_file = 1,
  316. .audit_skip = 1,
  317. #if defined(CONFIG_EPOLL)
  318. .prep = io_epoll_ctl_prep,
  319. .issue = io_epoll_ctl,
  320. #else
  321. .prep = io_eopnotsupp_prep,
  322. #endif
  323. },
  324. [IORING_OP_SPLICE] = {
  325. .needs_file = 1,
  326. .hash_reg_file = 1,
  327. .unbound_nonreg_file = 1,
  328. .audit_skip = 1,
  329. .prep = io_splice_prep,
  330. .issue = io_splice,
  331. },
  332. [IORING_OP_PROVIDE_BUFFERS] = {
  333. .audit_skip = 1,
  334. .iopoll = 1,
  335. .prep = io_provide_buffers_prep,
  336. .issue = io_manage_buffers_legacy,
  337. },
  338. [IORING_OP_REMOVE_BUFFERS] = {
  339. .audit_skip = 1,
  340. .iopoll = 1,
  341. .prep = io_remove_buffers_prep,
  342. .issue = io_manage_buffers_legacy,
  343. },
  344. [IORING_OP_TEE] = {
  345. .needs_file = 1,
  346. .hash_reg_file = 1,
  347. .unbound_nonreg_file = 1,
  348. .audit_skip = 1,
  349. .prep = io_tee_prep,
  350. .issue = io_tee,
  351. },
  352. [IORING_OP_SHUTDOWN] = {
  353. .needs_file = 1,
  354. #if defined(CONFIG_NET)
  355. .prep = io_shutdown_prep,
  356. .issue = io_shutdown,
  357. #else
  358. .prep = io_eopnotsupp_prep,
  359. #endif
  360. },
  361. [IORING_OP_RENAMEAT] = {
  362. .prep = io_renameat_prep,
  363. .issue = io_renameat,
  364. },
  365. [IORING_OP_UNLINKAT] = {
  366. .prep = io_unlinkat_prep,
  367. .issue = io_unlinkat,
  368. },
  369. [IORING_OP_MKDIRAT] = {
  370. .prep = io_mkdirat_prep,
  371. .issue = io_mkdirat,
  372. },
  373. [IORING_OP_SYMLINKAT] = {
  374. .prep = io_symlinkat_prep,
  375. .issue = io_symlinkat,
  376. },
  377. [IORING_OP_LINKAT] = {
  378. .prep = io_linkat_prep,
  379. .issue = io_linkat,
  380. },
  381. [IORING_OP_MSG_RING] = {
  382. .needs_file = 1,
  383. .iopoll = 1,
  384. .prep = io_msg_ring_prep,
  385. .issue = io_msg_ring,
  386. },
  387. [IORING_OP_FSETXATTR] = {
  388. .needs_file = 1,
  389. .prep = io_fsetxattr_prep,
  390. .issue = io_fsetxattr,
  391. },
  392. [IORING_OP_SETXATTR] = {
  393. .prep = io_setxattr_prep,
  394. .issue = io_setxattr,
  395. },
  396. [IORING_OP_FGETXATTR] = {
  397. .needs_file = 1,
  398. .prep = io_fgetxattr_prep,
  399. .issue = io_fgetxattr,
  400. },
  401. [IORING_OP_GETXATTR] = {
  402. .prep = io_getxattr_prep,
  403. .issue = io_getxattr,
  404. },
  405. [IORING_OP_SOCKET] = {
  406. .audit_skip = 1,
  407. #if defined(CONFIG_NET)
  408. .filter_pdu_size = sizeof_field(struct io_uring_bpf_ctx, socket),
  409. .prep = io_socket_prep,
  410. .issue = io_socket,
  411. .filter_populate = io_socket_bpf_populate,
  412. #else
  413. .prep = io_eopnotsupp_prep,
  414. #endif
  415. },
  416. [IORING_OP_URING_CMD] = {
  417. .buffer_select = 1,
  418. .needs_file = 1,
  419. .plug = 1,
  420. .iopoll = 1,
  421. .iopoll_queue = 1,
  422. .async_size = sizeof(struct io_async_cmd),
  423. .prep = io_uring_cmd_prep,
  424. .issue = io_uring_cmd,
  425. },
  426. [IORING_OP_SEND_ZC] = {
  427. .needs_file = 1,
  428. .unbound_nonreg_file = 1,
  429. .pollout = 1,
  430. .audit_skip = 1,
  431. .ioprio = 1,
  432. #if defined(CONFIG_NET)
  433. .async_size = sizeof(struct io_async_msghdr),
  434. .prep = io_send_zc_prep,
  435. .issue = io_send_zc,
  436. #else
  437. .prep = io_eopnotsupp_prep,
  438. #endif
  439. },
  440. [IORING_OP_SENDMSG_ZC] = {
  441. .needs_file = 1,
  442. .unbound_nonreg_file = 1,
  443. .pollout = 1,
  444. .ioprio = 1,
  445. #if defined(CONFIG_NET)
  446. .async_size = sizeof(struct io_async_msghdr),
  447. .prep = io_send_zc_prep,
  448. .issue = io_sendmsg_zc,
  449. #else
  450. .prep = io_eopnotsupp_prep,
  451. #endif
  452. },
  453. [IORING_OP_READ_MULTISHOT] = {
  454. .needs_file = 1,
  455. .unbound_nonreg_file = 1,
  456. .pollin = 1,
  457. .buffer_select = 1,
  458. .audit_skip = 1,
  459. .async_size = sizeof(struct io_async_rw),
  460. .prep = io_read_mshot_prep,
  461. .issue = io_read_mshot,
  462. },
  463. [IORING_OP_WAITID] = {
  464. .async_size = sizeof(struct io_waitid_async),
  465. .prep = io_waitid_prep,
  466. .issue = io_waitid,
  467. },
  468. [IORING_OP_FUTEX_WAIT] = {
  469. #if defined(CONFIG_FUTEX)
  470. .prep = io_futex_prep,
  471. .issue = io_futex_wait,
  472. #else
  473. .prep = io_eopnotsupp_prep,
  474. #endif
  475. },
  476. [IORING_OP_FUTEX_WAKE] = {
  477. #if defined(CONFIG_FUTEX)
  478. .prep = io_futex_prep,
  479. .issue = io_futex_wake,
  480. #else
  481. .prep = io_eopnotsupp_prep,
  482. #endif
  483. },
  484. [IORING_OP_FUTEX_WAITV] = {
  485. #if defined(CONFIG_FUTEX)
  486. .prep = io_futexv_prep,
  487. .issue = io_futexv_wait,
  488. #else
  489. .prep = io_eopnotsupp_prep,
  490. #endif
  491. },
  492. [IORING_OP_FIXED_FD_INSTALL] = {
  493. .needs_file = 1,
  494. .prep = io_install_fixed_fd_prep,
  495. .issue = io_install_fixed_fd,
  496. },
  497. [IORING_OP_FTRUNCATE] = {
  498. .needs_file = 1,
  499. .hash_reg_file = 1,
  500. .prep = io_ftruncate_prep,
  501. .issue = io_ftruncate,
  502. },
  503. [IORING_OP_BIND] = {
  504. #if defined(CONFIG_NET)
  505. .needs_file = 1,
  506. .prep = io_bind_prep,
  507. .issue = io_bind,
  508. .async_size = sizeof(struct io_async_msghdr),
  509. #else
  510. .prep = io_eopnotsupp_prep,
  511. #endif
  512. },
  513. [IORING_OP_LISTEN] = {
  514. #if defined(CONFIG_NET)
  515. .needs_file = 1,
  516. .prep = io_listen_prep,
  517. .issue = io_listen,
  518. .async_size = sizeof(struct io_async_msghdr),
  519. #else
  520. .prep = io_eopnotsupp_prep,
  521. #endif
  522. },
  523. [IORING_OP_RECV_ZC] = {
  524. .needs_file = 1,
  525. .unbound_nonreg_file = 1,
  526. .pollin = 1,
  527. .ioprio = 1,
  528. #if defined(CONFIG_NET)
  529. .prep = io_recvzc_prep,
  530. .issue = io_recvzc,
  531. #else
  532. .prep = io_eopnotsupp_prep,
  533. #endif
  534. },
  535. [IORING_OP_EPOLL_WAIT] = {
  536. .needs_file = 1,
  537. .audit_skip = 1,
  538. .pollin = 1,
  539. #if defined(CONFIG_EPOLL)
  540. .prep = io_epoll_wait_prep,
  541. .issue = io_epoll_wait,
  542. #else
  543. .prep = io_eopnotsupp_prep,
  544. #endif
  545. },
  546. [IORING_OP_READV_FIXED] = {
  547. .needs_file = 1,
  548. .unbound_nonreg_file = 1,
  549. .pollin = 1,
  550. .plug = 1,
  551. .audit_skip = 1,
  552. .ioprio = 1,
  553. .iopoll = 1,
  554. .iopoll_queue = 1,
  555. .vectored = 1,
  556. .async_size = sizeof(struct io_async_rw),
  557. .prep = io_prep_readv_fixed,
  558. .issue = io_read,
  559. },
  560. [IORING_OP_WRITEV_FIXED] = {
  561. .needs_file = 1,
  562. .hash_reg_file = 1,
  563. .unbound_nonreg_file = 1,
  564. .pollout = 1,
  565. .plug = 1,
  566. .audit_skip = 1,
  567. .ioprio = 1,
  568. .iopoll = 1,
  569. .iopoll_queue = 1,
  570. .vectored = 1,
  571. .async_size = sizeof(struct io_async_rw),
  572. .prep = io_prep_writev_fixed,
  573. .issue = io_write,
  574. },
  575. [IORING_OP_PIPE] = {
  576. .prep = io_pipe_prep,
  577. .issue = io_pipe,
  578. },
  579. [IORING_OP_NOP128] = {
  580. .audit_skip = 1,
  581. .iopoll = 1,
  582. .is_128 = 1,
  583. .prep = io_nop_prep,
  584. .issue = io_nop,
  585. },
  586. [IORING_OP_URING_CMD128] = {
  587. .buffer_select = 1,
  588. .needs_file = 1,
  589. .plug = 1,
  590. .iopoll = 1,
  591. .iopoll_queue = 1,
  592. .is_128 = 1,
  593. .async_size = sizeof(struct io_async_cmd),
  594. .prep = io_uring_cmd_prep,
  595. .issue = io_uring_cmd,
  596. },
  597. };
  598. const struct io_cold_def io_cold_defs[] = {
  599. [IORING_OP_NOP] = {
  600. .name = "NOP",
  601. },
  602. [IORING_OP_READV] = {
  603. .name = "READV",
  604. .cleanup = io_readv_writev_cleanup,
  605. .fail = io_rw_fail,
  606. },
  607. [IORING_OP_WRITEV] = {
  608. .name = "WRITEV",
  609. .cleanup = io_readv_writev_cleanup,
  610. .fail = io_rw_fail,
  611. },
  612. [IORING_OP_FSYNC] = {
  613. .name = "FSYNC",
  614. },
  615. [IORING_OP_READ_FIXED] = {
  616. .name = "READ_FIXED",
  617. .cleanup = io_readv_writev_cleanup,
  618. .fail = io_rw_fail,
  619. },
  620. [IORING_OP_WRITE_FIXED] = {
  621. .name = "WRITE_FIXED",
  622. .cleanup = io_readv_writev_cleanup,
  623. .fail = io_rw_fail,
  624. },
  625. [IORING_OP_POLL_ADD] = {
  626. .name = "POLL_ADD",
  627. },
  628. [IORING_OP_POLL_REMOVE] = {
  629. .name = "POLL_REMOVE",
  630. },
  631. [IORING_OP_SYNC_FILE_RANGE] = {
  632. .name = "SYNC_FILE_RANGE",
  633. },
  634. [IORING_OP_SENDMSG] = {
  635. .name = "SENDMSG",
  636. #if defined(CONFIG_NET)
  637. .cleanup = io_sendmsg_recvmsg_cleanup,
  638. .fail = io_sendrecv_fail,
  639. #endif
  640. },
  641. [IORING_OP_RECVMSG] = {
  642. .name = "RECVMSG",
  643. #if defined(CONFIG_NET)
  644. .cleanup = io_sendmsg_recvmsg_cleanup,
  645. .fail = io_sendrecv_fail,
  646. #endif
  647. },
  648. [IORING_OP_TIMEOUT] = {
  649. .name = "TIMEOUT",
  650. },
  651. [IORING_OP_TIMEOUT_REMOVE] = {
  652. .name = "TIMEOUT_REMOVE",
  653. },
  654. [IORING_OP_ACCEPT] = {
  655. .name = "ACCEPT",
  656. },
  657. [IORING_OP_ASYNC_CANCEL] = {
  658. .name = "ASYNC_CANCEL",
  659. },
  660. [IORING_OP_LINK_TIMEOUT] = {
  661. .name = "LINK_TIMEOUT",
  662. },
  663. [IORING_OP_CONNECT] = {
  664. .name = "CONNECT",
  665. },
  666. [IORING_OP_FALLOCATE] = {
  667. .name = "FALLOCATE",
  668. },
  669. [IORING_OP_OPENAT] = {
  670. .name = "OPENAT",
  671. .cleanup = io_open_cleanup,
  672. },
  673. [IORING_OP_CLOSE] = {
  674. .name = "CLOSE",
  675. },
  676. [IORING_OP_FILES_UPDATE] = {
  677. .name = "FILES_UPDATE",
  678. },
  679. [IORING_OP_STATX] = {
  680. .name = "STATX",
  681. .cleanup = io_statx_cleanup,
  682. },
  683. [IORING_OP_READ] = {
  684. .name = "READ",
  685. .cleanup = io_readv_writev_cleanup,
  686. .fail = io_rw_fail,
  687. },
  688. [IORING_OP_WRITE] = {
  689. .name = "WRITE",
  690. .cleanup = io_readv_writev_cleanup,
  691. .fail = io_rw_fail,
  692. },
  693. [IORING_OP_FADVISE] = {
  694. .name = "FADVISE",
  695. },
  696. [IORING_OP_MADVISE] = {
  697. .name = "MADVISE",
  698. },
  699. [IORING_OP_SEND] = {
  700. .name = "SEND",
  701. #if defined(CONFIG_NET)
  702. .cleanup = io_sendmsg_recvmsg_cleanup,
  703. .fail = io_sendrecv_fail,
  704. #endif
  705. },
  706. [IORING_OP_RECV] = {
  707. .name = "RECV",
  708. #if defined(CONFIG_NET)
  709. .cleanup = io_sendmsg_recvmsg_cleanup,
  710. .fail = io_sendrecv_fail,
  711. #endif
  712. },
  713. [IORING_OP_OPENAT2] = {
  714. .name = "OPENAT2",
  715. .cleanup = io_open_cleanup,
  716. },
  717. [IORING_OP_EPOLL_CTL] = {
  718. .name = "EPOLL",
  719. },
  720. [IORING_OP_SPLICE] = {
  721. .name = "SPLICE",
  722. .cleanup = io_splice_cleanup,
  723. },
  724. [IORING_OP_PROVIDE_BUFFERS] = {
  725. .name = "PROVIDE_BUFFERS",
  726. },
  727. [IORING_OP_REMOVE_BUFFERS] = {
  728. .name = "REMOVE_BUFFERS",
  729. },
  730. [IORING_OP_TEE] = {
  731. .name = "TEE",
  732. .cleanup = io_splice_cleanup,
  733. },
  734. [IORING_OP_SHUTDOWN] = {
  735. .name = "SHUTDOWN",
  736. },
  737. [IORING_OP_RENAMEAT] = {
  738. .name = "RENAMEAT",
  739. .cleanup = io_renameat_cleanup,
  740. },
  741. [IORING_OP_UNLINKAT] = {
  742. .name = "UNLINKAT",
  743. .cleanup = io_unlinkat_cleanup,
  744. },
  745. [IORING_OP_MKDIRAT] = {
  746. .name = "MKDIRAT",
  747. .cleanup = io_mkdirat_cleanup,
  748. },
  749. [IORING_OP_SYMLINKAT] = {
  750. .name = "SYMLINKAT",
  751. .cleanup = io_link_cleanup,
  752. },
  753. [IORING_OP_LINKAT] = {
  754. .name = "LINKAT",
  755. .cleanup = io_link_cleanup,
  756. },
  757. [IORING_OP_MSG_RING] = {
  758. .name = "MSG_RING",
  759. .cleanup = io_msg_ring_cleanup,
  760. },
  761. [IORING_OP_FSETXATTR] = {
  762. .name = "FSETXATTR",
  763. .cleanup = io_xattr_cleanup,
  764. },
  765. [IORING_OP_SETXATTR] = {
  766. .name = "SETXATTR",
  767. .cleanup = io_xattr_cleanup,
  768. },
  769. [IORING_OP_FGETXATTR] = {
  770. .name = "FGETXATTR",
  771. .cleanup = io_xattr_cleanup,
  772. },
  773. [IORING_OP_GETXATTR] = {
  774. .name = "GETXATTR",
  775. .cleanup = io_xattr_cleanup,
  776. },
  777. [IORING_OP_SOCKET] = {
  778. .name = "SOCKET",
  779. },
  780. [IORING_OP_URING_CMD] = {
  781. .name = "URING_CMD",
  782. .sqe_copy = io_uring_cmd_sqe_copy,
  783. .cleanup = io_uring_cmd_cleanup,
  784. },
  785. [IORING_OP_SEND_ZC] = {
  786. .name = "SEND_ZC",
  787. #if defined(CONFIG_NET)
  788. .cleanup = io_send_zc_cleanup,
  789. .fail = io_sendrecv_fail,
  790. #endif
  791. },
  792. [IORING_OP_SENDMSG_ZC] = {
  793. .name = "SENDMSG_ZC",
  794. #if defined(CONFIG_NET)
  795. .cleanup = io_send_zc_cleanup,
  796. .fail = io_sendrecv_fail,
  797. #endif
  798. },
  799. [IORING_OP_READ_MULTISHOT] = {
  800. .name = "READ_MULTISHOT",
  801. .cleanup = io_readv_writev_cleanup,
  802. },
  803. [IORING_OP_WAITID] = {
  804. .name = "WAITID",
  805. },
  806. [IORING_OP_FUTEX_WAIT] = {
  807. .name = "FUTEX_WAIT",
  808. },
  809. [IORING_OP_FUTEX_WAKE] = {
  810. .name = "FUTEX_WAKE",
  811. },
  812. [IORING_OP_FUTEX_WAITV] = {
  813. .name = "FUTEX_WAITV",
  814. },
  815. [IORING_OP_FIXED_FD_INSTALL] = {
  816. .name = "FIXED_FD_INSTALL",
  817. },
  818. [IORING_OP_FTRUNCATE] = {
  819. .name = "FTRUNCATE",
  820. },
  821. [IORING_OP_BIND] = {
  822. .name = "BIND",
  823. },
  824. [IORING_OP_LISTEN] = {
  825. .name = "LISTEN",
  826. },
  827. [IORING_OP_RECV_ZC] = {
  828. .name = "RECV_ZC",
  829. },
  830. [IORING_OP_EPOLL_WAIT] = {
  831. .name = "EPOLL_WAIT",
  832. },
  833. [IORING_OP_READV_FIXED] = {
  834. .name = "READV_FIXED",
  835. .cleanup = io_readv_writev_cleanup,
  836. .fail = io_rw_fail,
  837. },
  838. [IORING_OP_WRITEV_FIXED] = {
  839. .name = "WRITEV_FIXED",
  840. .cleanup = io_readv_writev_cleanup,
  841. .fail = io_rw_fail,
  842. },
  843. [IORING_OP_PIPE] = {
  844. .name = "PIPE",
  845. },
  846. [IORING_OP_NOP128] = {
  847. .name = "NOP128",
  848. },
  849. [IORING_OP_URING_CMD128] = {
  850. .name = "URING_CMD128",
  851. .sqe_copy = io_uring_cmd_sqe_copy,
  852. .cleanup = io_uring_cmd_cleanup,
  853. },
  854. };
  855. const char *io_uring_get_opcode(u8 opcode)
  856. {
  857. if (opcode < IORING_OP_LAST)
  858. return io_cold_defs[opcode].name;
  859. return "INVALID";
  860. }
  861. bool io_uring_op_supported(u8 opcode)
  862. {
  863. if (opcode < IORING_OP_LAST &&
  864. io_issue_defs[opcode].prep != io_eopnotsupp_prep)
  865. return true;
  866. return false;
  867. }
  868. void __init io_uring_optable_init(void)
  869. {
  870. int i;
  871. BUILD_BUG_ON(ARRAY_SIZE(io_cold_defs) != IORING_OP_LAST);
  872. BUILD_BUG_ON(ARRAY_SIZE(io_issue_defs) != IORING_OP_LAST);
  873. for (i = 0; i < ARRAY_SIZE(io_issue_defs); i++) {
  874. BUG_ON(!io_issue_defs[i].prep);
  875. if (io_issue_defs[i].prep != io_eopnotsupp_prep)
  876. BUG_ON(!io_issue_defs[i].issue);
  877. WARN_ON_ONCE(!io_cold_defs[i].name);
  878. }
  879. }