Skip to content

Commit

Permalink
io_uring: implement decoding of IORING_REGISTER_USE_REGISTERED_RING o…
Browse files Browse the repository at this point in the history
…pcode flag

This io_uring_register opcode flag was introduced by Linux kernel commit
v6.3-rc1~209^2.

* src/xlat/uring_register_opcode_flags.in: New file.
* src/io_uring.c: Include "xlat/uring_register_opcode_flags.h".
(print_io_uring_register_opcode): New function.
(SYS_FUNC(io_uring_register)): Use it to print opcodes.
* tests/io_uring_register.c (main): Check it.
* NEWS: Mention this change.
  • Loading branch information
ldv-alt committed May 10, 2024
1 parent 50a3ed2 commit f81f312
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
2 changes: 1 addition & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Noteworthy changes in release ?.? (????-??-??)
IORING_REGISTER_FILE_ALLOC_RANGE, IORING_REGISTER_PBUF_STATUS,
IORING_REGISTER_NAPI, and IORING_UNREGISTER_NAPI opcodes of
io_uring_register syscall.
* Updated decoding of pidfd_send_signal syscall.
* Updated decoding of io_uring_register and pidfd_send_signal syscalls.
* Updated lists of CAN_*, IORING_*, KEY_*, LSM_*, MPOL_*, NT_*, RWF_*,
PIDFD_*, PTP_*, TCP_*, and *_MAGIC constants.
* Updated lists of ioctl commands from Linux 6.9.
Expand Down
31 changes: 27 additions & 4 deletions src/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "xlat/uring_setup_flags.h"
#include "xlat/uring_sqe_flags.h"
#include "xlat/uring_register_opcodes.h"
#include "xlat/uring_register_opcode_flags.h"
#include "xlat/uring_register_rsrc_flags.h"
#include "xlat/uring_restriction_opcodes.h"

Expand Down Expand Up @@ -769,23 +770,45 @@ print_ioring_unregister_napi(struct tcb *tcp, const kernel_ulong_t addr,
return RVAL_DECODED;
}

static void
print_io_uring_register_opcode(struct tcb *tcp, const unsigned int opcode,
const unsigned int flags)
{
if (flags)
tprint_flags_begin();

printxval(uring_register_opcodes, opcode, "IORING_REGISTER_???");

if (flags) {
tprint_flags_or();
printflags_in(uring_register_opcode_flags, flags, NULL);
tprint_flags_end();
}

}

SYS_FUNC(io_uring_register)
{
const int fd = tcp->u_arg[0];
const unsigned int opcode = tcp->u_arg[1];
unsigned int opcode = tcp->u_arg[1];
const kernel_ulong_t arg = tcp->u_arg[2];
const unsigned int nargs = tcp->u_arg[3];
const unsigned int opcode_flags =
opcode & IORING_REGISTER_USE_REGISTERED_RING;
opcode &= ~IORING_REGISTER_USE_REGISTERED_RING;
int rc = RVAL_DECODED;
int buf;

if (entering(tcp)) {
/* fd */
printfd(tcp, fd);
if (opcode_flags)
PRINT_VAL_U(fd);
else
printfd(tcp, fd);
tprint_arg_next();

/* opcode */
printxval(uring_register_opcodes, opcode,
"IORING_REGISTER_???");
print_io_uring_register_opcode(tcp, opcode, opcode_flags);
tprint_arg_next();
}

Expand Down
2 changes: 2 additions & 0 deletions src/xlat/uring_register_opcode_flags.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#unconditional
IORING_REGISTER_USE_REGISTERED_RING
32 changes: 31 additions & 1 deletion tests/io_uring_register.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,13 @@ main(void)


/* Invalid op */
static const unsigned int invalid_ops[] = { 0xbadc0dedU, 29 };
static const unsigned int invalid_ops[] = { 0x7fffffffU, 29 };
static const struct {
unsigned int val;
const char *str;
} op_flags[] = {
{ ARG_STR(IORING_REGISTER_USE_REGISTERED_RING) },
};

for (size_t i = 0; i < ARRAY_SIZE(invalid_ops); i++) {
sys_io_uring_register(fd_null, invalid_ops[i], path_null,
Expand All @@ -181,6 +187,18 @@ main(void)
NRAW(" /* IORING_REGISTER_??? */") ", %p, %u) = %s\n",
fd_null, path_null, invalid_ops[i], path_null,
0xdeadbeef, errstr);

for (size_t j = 0; j < ARRAY_SIZE(op_flags); ++j) {
sys_io_uring_register(fd_null, invalid_ops[i] |
op_flags[j].val,
path_null, 0xdeadbeef);
printf("io_uring_register(%u, %#x"
NRAW(" /* IORING_REGISTER_??? */") "|" XLAT_FMT
", %p, %u) = %s\n",
fd_null, invalid_ops[i],
XLAT_SEL(op_flags[j].val, op_flags[j].str),
path_null, 0xdeadbeef, errstr);
}
}


Expand All @@ -205,6 +223,18 @@ main(void)
fd_null, path_null,
XLAT_SEL(no_arg_ops[i].op, no_arg_ops[i].str),
path_null, 0xdeadbeef, errstr);

for (size_t j = 0; j < ARRAY_SIZE(op_flags); ++j) {
sys_io_uring_register(fd_null, no_arg_ops[i].op |
op_flags[j].val,
path_null, 0xdeadbeef);
printf("io_uring_register(%u, " XLAT_FMT "|" XLAT_FMT
", %p, %u) = %s\n",
fd_null,
XLAT_SEL(no_arg_ops[i].op, no_arg_ops[i].str),
XLAT_SEL(op_flags[j].val, op_flags[j].str),
path_null, 0xdeadbeef, errstr);
}
}


Expand Down

0 comments on commit f81f312

Please sign in to comment.