Skip to content

Commit

Permalink
io_uring: decode struct io_uring_rsrc_register.flags field
Browse files Browse the repository at this point in the history
Introduced by Linux commit v5.19-rc1~251^2~20.

* configure.ac: Remove struct io_uring_rsrc_register.resv check.
* src/xlat/uring_register_rsrc_flags.in: New file.
* src/io_uring.c: Include "xlat/uring_register_rsrc_flags.h".
(print_io_uring_register_rsrc): Remove CHECK_TYPE_SIZE for arg.resv,
decode flags field using PRINT_FIELD_FLAGS instead of optional decoding
of no longer existing resv field.
* tests/io_uring_register.c: Update expected output.
  • Loading branch information
esyr committed Aug 11, 2022
1 parent 3361fdf commit a30e5de
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 31 deletions.
6 changes: 0 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,6 @@ AC_CHECK_MEMBERS(m4_normalize([
struct iocb.aio_rw_flags
]),,, [#include <linux/aio_abi.h>])

AC_CHECK_TYPES([struct io_uring_rsrc_register], [
AC_CHECK_MEMBERS(m4_normalize([
struct io_uring_rsrc_register.resv
]),,, [#include <linux/io_uring.h>])
],, [#include <linux/io_uring.h>])

CPPFLAGS="$saved_CPPFLAGS"

st_CHECK_ENUMS
Expand Down
19 changes: 4 additions & 15 deletions src/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "xlat/uring_setup_flags.h"
#include "xlat/uring_sqe_flags.h"
#include "xlat/uring_register_opcodes.h"
#include "xlat/uring_register_rsrc_flags.h"
#include "xlat/uring_restriction_opcodes.h"

static void
Expand Down Expand Up @@ -385,20 +386,12 @@ print_io_uring_rsrc_tags(struct tcb *tcp, const uint64_t tags,
tfetch_mem, print_xint_array_member, NULL);
}

/* Work around field name change in Linux commit v5.19-rc1~251^2~20. */
#ifdef HAVE_STRUCT_IO_URING_RSRC_REGISTER_RESV
# define RESV resv
#else
# define RESV flags
#endif

static void
print_io_uring_register_rsrc(struct tcb *tcp, const kernel_ulong_t addr,
const unsigned int size, const unsigned int opcode)
{
struct io_uring_rsrc_register arg;
CHECK_TYPE_SIZE(arg, 32);
CHECK_TYPE_SIZE(arg.RESV, sizeof(uint32_t));
CHECK_TYPE_SIZE(arg.resv2, sizeof(uint64_t));

if (size < 32) {
Expand All @@ -412,11 +405,9 @@ print_io_uring_register_rsrc(struct tcb *tcp, const kernel_ulong_t addr,
tprint_struct_begin();
PRINT_FIELD_U(arg, nr);

if (arg.RESV) {
tprint_struct_next();
tprints_field_name("resv");
PRINT_VAL_X(arg.RESV);
}
tprint_struct_next();
PRINT_FIELD_FLAGS(arg, flags, uring_register_rsrc_flags,
"IORING_RSRC_REGISTER_???");

if (arg.resv2) {
tprint_struct_next();
Expand All @@ -435,8 +426,6 @@ print_io_uring_register_rsrc(struct tcb *tcp, const kernel_ulong_t addr,
tprint_struct_end();
}

#undef RESV

static void
print_io_uring_update_rsrc(struct tcb *tcp, const kernel_ulong_t addr,
const unsigned int size, const unsigned int opcode)
Expand Down
2 changes: 2 additions & 0 deletions src/xlat/uring_register_rsrc_flags.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#unconditional
IORING_RSRC_REGISTER_SPARSE
20 changes: 10 additions & 10 deletions tests/io_uring_register.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@

#define ARR_ITEM(arr_, idx_) ((arr_)[(idx_) % ARRAY_SIZE(arr_)])

/* Work around field name change in Linux commit v5.19-rc1~251^2~20. */
#ifdef HAVE_STRUCT_IO_URING_RSRC_REGISTER_RESV
# define RESV resv
#else
# define RESV flags
#endif

static const char path_null[] = "/dev/null";
static const char path_full[] = "/dev/full";

Expand Down Expand Up @@ -652,6 +645,13 @@ main(void)
{ 13, "IORING_REGISTER_FILES2" },
{ 15, "IORING_REGISTER_BUFFERS2" },
};
static const struct strval32 rsrc_flags[] = {
{ ARG_STR(0) },
{ ARG_XLAT_KNOWN(0x1, "IORING_RSRC_REGISTER_SPARSE") },
{ ARG_XLAT_UNKNOWN(0x2, "IORING_RSRC_REGISTER_???") },
{ ARG_XLAT_KNOWN(0xbadc0ded,
"IORING_RSRC_REGISTER_SPARSE|0xbadc0dec") },
};
static const uint64_t tags[] = { 0x1337, 1, 0xdead, 0xfacefeed,
0xbadc0deddadfacedULL, 0 };
const uint64_t *arg_tags = tail_memdup(tags, sizeof(tags));
Expand Down Expand Up @@ -709,7 +709,7 @@ main(void)
rsrc_reg->nr += !!(j & 16);
rsrc_reg->nr &= ~-!(j & 32);

rsrc_reg->RESV = j & 64 ? 0xbadc0ded : 0;
rsrc_reg->flags = ARR_ITEM(rsrc_flags, j >> 6).val;
rsrc_reg->resv2 = j & 128 ? 0xfacecafebeeffeedULL : 0;

memcpy(big_rsrc_reg, rsrc_reg, sizeof(*rsrc_reg));
Expand All @@ -722,14 +722,14 @@ main(void)
sizeof(*rsrc_reg)
+ (k / 2) * 8);
printf("io_uring_register(%u<%s>, " XLAT_FMT
", {nr=%zu%s%s",
", {nr=%zu, flags=%s%s",
fd_null, path_null,
XLAT_SEL(rsrc_reg_ops[i].op,
rsrc_reg_ops[i].str),
j & 32 ? (i ? ARRAY_SIZE(iov)
: ARRAY_SIZE(fds))
+ !!(j & 16) : 0,
j & 64 ? ", resv=0xbadc0ded" : "",
ARR_ITEM(rsrc_flags, j >> 6).str,
j & 128 ? ", resv2=0xfacecafebeeffeed"
: "");
print_rsrc_data(arg_iov, iov, arg_fds, fds,
Expand Down

0 comments on commit a30e5de

Please sign in to comment.