Skip to content

Commit

Permalink
io_uring: implement decoding of IORING_REGISTER_PBUF_STATUS opcode
Browse files Browse the repository at this point in the history
This io_uring_register opcode was introduced by Linux kernel commit
v6.8-rc1~29^2~8.

* src/io_uring.c (print_io_uring_buf_status): New function.
(SYS_FUNC(io_uring_register)): Use it to decode
IORING_REGISTER_PBUF_STATUS opcode.
* tests/io_uring_register.c (main): Check it.
* NEWS: Mention this change.
  • Loading branch information
ldv-alt committed May 8, 2024
1 parent 602bcb9 commit 16334a9
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 2 deletions.
5 changes: 3 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ Noteworthy changes in release ?.? (????-??-??)
* Implemented --always-show-pid option.
* The --user|-u option has learned to recognize numeric UID:GID pair, allowing
e.g. statically-built strace to be used without invoking nss plugins.
* Implemented decoding of IORING_REGISTER_SYNC_CANCEL and
IORING_REGISTER_FILE_ALLOC_RANGE opcodes of io_uring_register syscall.
* Implemented decoding of IORING_REGISTER_SYNC_CANCEL,
IORING_REGISTER_FILE_ALLOC_RANGE, and IORING_REGISTER_PBUF_STATUS opcodes
of io_uring_register syscall.
* Updated decoding of pidfd_send_signal syscall.
* Updated lists of CAN_*, IORING_*, KEY_*, LSM_*, MPOL_*, NT_*, RWF_*,
PIDFD_*, PTP_*, TCP_*, and *_MAGIC constants.
Expand Down
36 changes: 36 additions & 0 deletions src/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,39 @@ print_io_uring_file_index_range(struct tcb *tcp, const kernel_ulong_t addr,
tprint_struct_end();
}

static int
print_io_uring_buf_status(struct tcb *tcp, const kernel_ulong_t addr,
const unsigned int nargs)
{
struct io_uring_buf_status arg;

if (nargs != 1) {
printaddr(addr);
return RVAL_DECODED;
}

if (entering(tcp))
return 0;

if (umove_or_printaddr(tcp, addr, &arg))
return RVAL_DECODED;

tprint_struct_begin();
PRINT_FIELD_X(arg, buf_group);

tprint_struct_next();
PRINT_FIELD_X(arg, head);

if (!IS_ARRAY_ZERO(arg.resv)) {
tprint_struct_next();
PRINT_FIELD_ARRAY(arg, resv, tcp, print_xint_array_member);
}

tprint_struct_end();

return RVAL_DECODED;
}

SYS_FUNC(io_uring_register)
{
const int fd = tcp->u_arg[0];
Expand Down Expand Up @@ -744,6 +777,9 @@ SYS_FUNC(io_uring_register)
case IORING_REGISTER_FILE_ALLOC_RANGE:
print_io_uring_file_index_range(tcp, arg, nargs);
break;
case IORING_REGISTER_PBUF_STATUS:
rc = print_io_uring_buf_status(tcp, arg, nargs);
break;
case IORING_UNREGISTER_BUFFERS:
case IORING_UNREGISTER_FILES:
case IORING_UNREGISTER_EVENTFD:
Expand Down
67 changes: 67 additions & 0 deletions tests/io_uring_register.c
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,73 @@ main(void)
}
}

/* IORING_REGISTER_PBUF_STATUS */
static const struct {
unsigned int op;
const char *str;
} buf_status_ops[] = {
{ 26, "IORING_REGISTER_PBUF_STATUS" },
};
TAIL_ALLOC_OBJECT_CONST_PTR(struct io_uring_buf_status, buf_status);

for (size_t i = 0; i < ARRAY_SIZE(buf_status_ops); i++) {
sys_io_uring_register(fd_null, buf_status_ops[i].op, 0,
0xdeadbeef);
printf("io_uring_register(%u<%s>, " XLAT_FMT ", NULL, %u)"
" = %s\n",
fd_null, path_null,
XLAT_SEL(buf_status_ops[i].op,
buf_status_ops[i].str),
0xdeadbeef, errstr);

sys_io_uring_register(fd_null, buf_status_ops[i].op,
buf_status + 1, 0);
printf("io_uring_register(%u<%s>, " XLAT_FMT ", %p, 0) = %s\n",
fd_null, path_null,
XLAT_SEL(buf_status_ops[i].op, buf_status_ops[i].str),
buf_status + 1, errstr);

for (size_t j = 0; j < (1U << 3); j++) {
memset(buf_status, 0, sizeof(*buf_status));
buf_status->buf_group = j & 1 ? 0xfacefeedU : 0;
buf_status->head = j & 2 ? 0xcafef00dU : 0;
buf_status->resv[7] = j & 4 ? 0xbadc0dedU : 0;

sys_io_uring_register(fd_null, buf_status_ops[i].op,
buf_status, 0x42);
printf("io_uring_register(%u<%s>, " XLAT_FMT ", %p, 66)"
" = %s\n",
fd_null, path_null,
XLAT_SEL(buf_status_ops[i].op,
buf_status_ops[i].str),
buf_status, errstr);

sys_io_uring_register(fd_null, buf_status_ops[i].op,
buf_status, 1);
printf("io_uring_register(%u<%s>, " XLAT_FMT ", "
#if RETVAL_INJECTED
"{buf_group=%#x, head=%#x",
#else
"%p",
#endif
fd_null, path_null,
XLAT_SEL(buf_status_ops[i].op,
buf_status_ops[i].str),
#if RETVAL_INJECTED
buf_status->buf_group, buf_status->head
#else
buf_status
#endif
);
#if RETVAL_INJECTED
if (j & 4)
printf(", resv=[0, 0, 0, 0, 0, 0, 0, 0xbadc0ded]");
printf("}");
#endif
printf(", 1) = %s\n", errstr);
}
}

puts("+++ exited with 0 +++");
return 0;
}

0 comments on commit 16334a9

Please sign in to comment.