Skip to content

Commit

Permalink
io_uring: sendzc with fixed buffers
Browse files Browse the repository at this point in the history
Allow zerocopy sends to use fixed buffers.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
  • Loading branch information
isilence authored and intel-lab-lkp committed Nov 30, 2021
1 parent 94d32ba commit 6144f7b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
19 changes: 17 additions & 2 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -5041,7 +5041,7 @@ static int io_send(struct io_kiocb *req, unsigned int issue_flags)
return 0;
}

#define IO_SENDZC_VALID_FLAGS IORING_SENDZC_FLUSH
#define IO_SENDZC_VALID_FLAGS (IORING_SENDZC_FLUSH | IORING_SENDZC_FIXED_BUF)

static int io_sendzc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
{
Expand Down Expand Up @@ -5071,6 +5071,15 @@ static int io_sendzc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
if (req->msgzc.zc_flags & ~IO_SENDZC_VALID_FLAGS)
return -EINVAL;

if (req->msgzc.zc_flags & IORING_SENDZC_FIXED_BUF) {
idx = READ_ONCE(sqe->buf_index);
if (unlikely(idx >= ctx->nr_user_bufs))
return -EFAULT;
idx = array_index_nospec(idx, ctx->nr_user_bufs);
req->imu = READ_ONCE(ctx->user_bufs[idx]);
io_req_set_rsrc_node(req, ctx);
}

#ifdef CONFIG_COMPAT
if (req->ctx->compat)
sr->msg_flags |= MSG_CMSG_COMPAT;
Expand All @@ -5094,7 +5103,13 @@ static int io_sendzc(struct io_kiocb *req, unsigned int issue_flags)
if (unlikely(!sock))
return -ENOTSOCK;

ret = import_single_range(WRITE, sr->buf, sr->len, &iov, &msg.msg_iter);
if (req->msgzc.zc_flags & IORING_SENDZC_FIXED_BUF) {
ret = __io_import_fixed(WRITE, &msg.msg_iter, req->imu,
(u64)sr->buf, sr->len);
} else {
ret = import_single_range(WRITE, sr->buf, sr->len, &iov,
&msg.msg_iter);
}
if (unlikely(ret))
return ret;

Expand Down
1 change: 1 addition & 0 deletions include/uapi/linux/io_uring.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ enum {

enum {
IORING_SENDZC_FLUSH = (1U << 0),
IORING_SENDZC_FIXED_BUF = (1U << 1),
};

/*
Expand Down

0 comments on commit 6144f7b

Please sign in to comment.