Commit 29c1ac23 authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe

io_uring: keep sendrecv flags in ioprio

We waste a u64 SQE field for flags even though we don't need as many
bits and it can be used for something more useful later. Store io_uring
specific send/recv flags in sqe->ioprio instead of ->addr2.
Signed-off-by: default avatarPavel Begunkov <asml.silence@gmail.com>
Fixes: 0455d4cc ("io_uring: add POLL_FIRST support for send/sendmsg and recv/recvmsg")
[axboe: change comment in io_uring.h as well]
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 386e4fb6
...@@ -1183,6 +1183,7 @@ static const struct io_op_def io_op_defs[] = { ...@@ -1183,6 +1183,7 @@ static const struct io_op_def io_op_defs[] = {
.unbound_nonreg_file = 1, .unbound_nonreg_file = 1,
.pollout = 1, .pollout = 1,
.needs_async_setup = 1, .needs_async_setup = 1,
.ioprio = 1,
.async_size = sizeof(struct io_async_msghdr), .async_size = sizeof(struct io_async_msghdr),
}, },
[IORING_OP_RECVMSG] = { [IORING_OP_RECVMSG] = {
...@@ -1191,6 +1192,7 @@ static const struct io_op_def io_op_defs[] = { ...@@ -1191,6 +1192,7 @@ static const struct io_op_def io_op_defs[] = {
.pollin = 1, .pollin = 1,
.buffer_select = 1, .buffer_select = 1,
.needs_async_setup = 1, .needs_async_setup = 1,
.ioprio = 1,
.async_size = sizeof(struct io_async_msghdr), .async_size = sizeof(struct io_async_msghdr),
}, },
[IORING_OP_TIMEOUT] = { [IORING_OP_TIMEOUT] = {
...@@ -1266,6 +1268,7 @@ static const struct io_op_def io_op_defs[] = { ...@@ -1266,6 +1268,7 @@ static const struct io_op_def io_op_defs[] = {
.unbound_nonreg_file = 1, .unbound_nonreg_file = 1,
.pollout = 1, .pollout = 1,
.audit_skip = 1, .audit_skip = 1,
.ioprio = 1,
}, },
[IORING_OP_RECV] = { [IORING_OP_RECV] = {
.needs_file = 1, .needs_file = 1,
...@@ -1273,6 +1276,7 @@ static const struct io_op_def io_op_defs[] = { ...@@ -1273,6 +1276,7 @@ static const struct io_op_def io_op_defs[] = {
.pollin = 1, .pollin = 1,
.buffer_select = 1, .buffer_select = 1,
.audit_skip = 1, .audit_skip = 1,
.ioprio = 1,
}, },
[IORING_OP_OPENAT2] = { [IORING_OP_OPENAT2] = {
}, },
...@@ -6075,12 +6079,12 @@ static int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) ...@@ -6075,12 +6079,12 @@ static int io_sendmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{ {
struct io_sr_msg *sr = &req->sr_msg; struct io_sr_msg *sr = &req->sr_msg;
if (unlikely(sqe->file_index)) if (unlikely(sqe->file_index || sqe->addr2))
return -EINVAL; return -EINVAL;
sr->umsg = u64_to_user_ptr(READ_ONCE(sqe->addr)); sr->umsg = u64_to_user_ptr(READ_ONCE(sqe->addr));
sr->len = READ_ONCE(sqe->len); sr->len = READ_ONCE(sqe->len);
sr->flags = READ_ONCE(sqe->addr2); sr->flags = READ_ONCE(sqe->ioprio);
if (sr->flags & ~IORING_RECVSEND_POLL_FIRST) if (sr->flags & ~IORING_RECVSEND_POLL_FIRST)
return -EINVAL; return -EINVAL;
sr->msg_flags = READ_ONCE(sqe->msg_flags) | MSG_NOSIGNAL; sr->msg_flags = READ_ONCE(sqe->msg_flags) | MSG_NOSIGNAL;
...@@ -6311,12 +6315,12 @@ static int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) ...@@ -6311,12 +6315,12 @@ static int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{ {
struct io_sr_msg *sr = &req->sr_msg; struct io_sr_msg *sr = &req->sr_msg;
if (unlikely(sqe->file_index)) if (unlikely(sqe->file_index || sqe->addr2))
return -EINVAL; return -EINVAL;
sr->umsg = u64_to_user_ptr(READ_ONCE(sqe->addr)); sr->umsg = u64_to_user_ptr(READ_ONCE(sqe->addr));
sr->len = READ_ONCE(sqe->len); sr->len = READ_ONCE(sqe->len);
sr->flags = READ_ONCE(sqe->addr2); sr->flags = READ_ONCE(sqe->ioprio);
if (sr->flags & ~IORING_RECVSEND_POLL_FIRST) if (sr->flags & ~IORING_RECVSEND_POLL_FIRST)
return -EINVAL; return -EINVAL;
sr->msg_flags = READ_ONCE(sqe->msg_flags) | MSG_NOSIGNAL; sr->msg_flags = READ_ONCE(sqe->msg_flags) | MSG_NOSIGNAL;
......
...@@ -244,7 +244,7 @@ enum io_uring_op { ...@@ -244,7 +244,7 @@ enum io_uring_op {
#define IORING_ASYNC_CANCEL_ANY (1U << 2) #define IORING_ASYNC_CANCEL_ANY (1U << 2)
/* /*
* send/sendmsg and recv/recvmsg flags (sqe->addr2) * send/sendmsg and recv/recvmsg flags (sqe->ioprio)
* *
* IORING_RECVSEND_POLL_FIRST If set, instead of first attempting to send * IORING_RECVSEND_POLL_FIRST If set, instead of first attempting to send
* or receive and arm poll if that yields an * or receive and arm poll if that yields an
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment