Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

io_uring.c 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (c) 2019 Dmitry V. Levin <ldv@altlinux.org>
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: LGPL-2.1-or-later
  6. */
  7. #include "defs.h"
  8. #ifdef HAVE_LINUX_IO_URING_H
  9. # include "print_fields.h"
  10. # include <linux/io_uring.h>
  11. #endif
  12. #include "xlat/uring_setup_flags.h"
  13. #include "xlat/uring_enter_flags.h"
  14. #include "xlat/uring_register_opcodes.h"
  15. SYS_FUNC(io_uring_setup)
  16. {
  17. const uint32_t nentries = tcp->u_arg[0];
  18. const kernel_ulong_t params_addr = tcp->u_arg[1];
  19. #ifdef HAVE_LINUX_IO_URING_H
  20. struct io_uring_params params;
  21. if (entering(tcp)) {
  22. tprintf("%u, ", nentries);
  23. if (umove_or_printaddr(tcp, params_addr, &params))
  24. return RVAL_DECODED | RVAL_FD;
  25. PRINT_FIELD_FLAGS("{", params, flags, uring_setup_flags,
  26. "IORING_SETUP_???");
  27. PRINT_FIELD_X(", ", params, sq_thread_cpu);
  28. PRINT_FIELD_U(", ", params, sq_thread_idle);
  29. for (unsigned int i = 0; i < ARRAY_SIZE(params.resv); ++i) {
  30. if (params.resv[i]) {
  31. for (i = 0; i < ARRAY_SIZE(params.resv); ++i)
  32. tprintf("%s%#x",
  33. (i ? ", " : ", resv={"),
  34. params.resv[i]);
  35. tprints("}");
  36. break;
  37. }
  38. }
  39. return 0;
  40. } else {
  41. if (syserror(tcp)) {
  42. /* The remaining part of params is irrelevant. */
  43. } else if (umove(tcp, params_addr, &params)) {
  44. tprints(", ???");
  45. } else {
  46. PRINT_FIELD_U(", ", params, sq_entries);
  47. PRINT_FIELD_U(", ", params, cq_entries);
  48. PRINT_FIELD_U(", sq_off={", params.sq_off, head);
  49. PRINT_FIELD_U(", ", params.sq_off, tail);
  50. PRINT_FIELD_U(", ", params.sq_off, ring_mask);
  51. PRINT_FIELD_U(", ", params.sq_off, ring_entries);
  52. PRINT_FIELD_U(", ", params.sq_off, flags);
  53. PRINT_FIELD_U(", ", params.sq_off, dropped);
  54. PRINT_FIELD_U(", ", params.sq_off, array);
  55. PRINT_FIELD_U("}, cq_off={", params.cq_off, head);
  56. PRINT_FIELD_U(", ", params.cq_off, tail);
  57. PRINT_FIELD_U(", ", params.cq_off, ring_mask);
  58. PRINT_FIELD_U(", ", params.cq_off, ring_entries);
  59. PRINT_FIELD_U(", ", params.cq_off, overflow);
  60. PRINT_FIELD_U(", ", params.cq_off, cqes);
  61. tprints("}");
  62. }
  63. tprints("}");
  64. }
  65. #else /* !HAVE_LINUX_IO_URING_H */
  66. tprintf("%u, ", nentries);
  67. printaddr(params_addr);
  68. #endif
  69. return RVAL_DECODED | RVAL_FD;
  70. }
  71. SYS_FUNC(io_uring_enter)
  72. {
  73. const int fd = tcp->u_arg[0];
  74. const uint32_t to_submit = tcp->u_arg[1];
  75. const uint32_t min_complete = tcp->u_arg[2];
  76. const uint32_t flags = tcp->u_arg[3];
  77. const kernel_ulong_t sigset_addr = tcp->u_arg[4];
  78. const kernel_ulong_t sigset_size = tcp->u_arg[5];
  79. printfd(tcp, fd);
  80. tprintf(", %u, %u, ", to_submit, min_complete);
  81. printflags(uring_enter_flags, flags, "IORING_ENTER_???");
  82. tprints(", ");
  83. print_sigset_addr_len(tcp, sigset_addr, sigset_size);
  84. tprintf(", %" PRI_klu, sigset_size);
  85. return RVAL_DECODED;
  86. }
  87. static bool
  88. print_fd_array_member(struct tcb *tcp, void *elem_buf, size_t elem_size,
  89. void *data)
  90. {
  91. printfd(tcp, *(int *) elem_buf);
  92. return true;
  93. }
  94. SYS_FUNC(io_uring_register)
  95. {
  96. const int fd = tcp->u_arg[0];
  97. const unsigned int opcode = tcp->u_arg[1];
  98. const kernel_ulong_t arg = tcp->u_arg[2];
  99. const unsigned int nargs = tcp->u_arg[3];
  100. int buf;
  101. printfd(tcp, fd);
  102. tprints(", ");
  103. printxval(uring_register_opcodes, opcode, "IORING_REGISTER_???");
  104. tprints(", ");
  105. switch (opcode) {
  106. case IORING_REGISTER_BUFFERS:
  107. tprint_iov(tcp, nargs, arg, IOV_DECODE_ADDR);
  108. break;
  109. case IORING_REGISTER_FILES:
  110. print_array(tcp, arg, nargs, &buf, sizeof(buf),
  111. tfetch_mem, print_fd_array_member, NULL);
  112. break;
  113. default:
  114. printaddr(arg);
  115. break;
  116. }
  117. tprintf(", %u", nargs);
  118. return RVAL_DECODED;
  119. }