Commit 3dc8976c authored by David Howells's avatar David Howells Committed by Jakub Kicinski

tls/device: Convert tls_device_sendpage() to use MSG_SPLICE_PAGES

Convert tls_device_sendpage() to use sendmsg() with MSG_SPLICE_PAGES rather
than directly splicing in the pages itself.  With that, the tls_iter_offset
union is no longer necessary and can be replaced with an iov_iter pointer
and the zc_page argument to tls_push_data() can also be removed.

This allows ->sendpage() to be replaced by something that can handle
multiple multipage folios in a single transaction.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Acked-by: default avatarJakub Kicinski <kuba@kernel.org>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Boris Pismenny <borisp@nvidia.com>
cc: John Fastabend <john.fastabend@gmail.com>
cc: Jens Axboe <axboe@kernel.dk>
cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 24763c9c
...@@ -422,16 +422,10 @@ static int tls_device_copy_data(void *addr, size_t bytes, struct iov_iter *i) ...@@ -422,16 +422,10 @@ static int tls_device_copy_data(void *addr, size_t bytes, struct iov_iter *i)
return 0; return 0;
} }
union tls_iter_offset {
struct iov_iter *msg_iter;
int offset;
};
static int tls_push_data(struct sock *sk, static int tls_push_data(struct sock *sk,
union tls_iter_offset iter_offset, struct iov_iter *iter,
size_t size, int flags, size_t size, int flags,
unsigned char record_type, unsigned char record_type)
struct page *zc_page)
{ {
struct tls_context *tls_ctx = tls_get_ctx(sk); struct tls_context *tls_ctx = tls_get_ctx(sk);
struct tls_prot_info *prot = &tls_ctx->prot_info; struct tls_prot_info *prot = &tls_ctx->prot_info;
...@@ -500,22 +494,13 @@ static int tls_push_data(struct sock *sk, ...@@ -500,22 +494,13 @@ static int tls_push_data(struct sock *sk,
record = ctx->open_record; record = ctx->open_record;
copy = min_t(size_t, size, max_open_record_len - record->len); copy = min_t(size_t, size, max_open_record_len - record->len);
if (copy && zc_page) { if (copy && (flags & MSG_SPLICE_PAGES)) {
struct page_frag zc_pfrag;
zc_pfrag.page = zc_page;
zc_pfrag.offset = iter_offset.offset;
zc_pfrag.size = copy;
tls_append_frag(record, &zc_pfrag, copy);
iter_offset.offset += copy;
} else if (copy && (flags & MSG_SPLICE_PAGES)) {
struct page_frag zc_pfrag; struct page_frag zc_pfrag;
struct page **pages = &zc_pfrag.page; struct page **pages = &zc_pfrag.page;
size_t off; size_t off;
rc = iov_iter_extract_pages(iter_offset.msg_iter, rc = iov_iter_extract_pages(iter, &pages,
&pages, copy, 1, 0, &off); copy, 1, 0, &off);
if (rc <= 0) { if (rc <= 0) {
if (rc == 0) if (rc == 0)
rc = -EIO; rc = -EIO;
...@@ -524,7 +509,7 @@ static int tls_push_data(struct sock *sk, ...@@ -524,7 +509,7 @@ static int tls_push_data(struct sock *sk,
copy = rc; copy = rc;
if (WARN_ON_ONCE(!sendpage_ok(zc_pfrag.page))) { if (WARN_ON_ONCE(!sendpage_ok(zc_pfrag.page))) {
iov_iter_revert(iter_offset.msg_iter, copy); iov_iter_revert(iter, copy);
rc = -EIO; rc = -EIO;
goto handle_error; goto handle_error;
} }
...@@ -537,7 +522,7 @@ static int tls_push_data(struct sock *sk, ...@@ -537,7 +522,7 @@ static int tls_push_data(struct sock *sk,
rc = tls_device_copy_data(page_address(pfrag->page) + rc = tls_device_copy_data(page_address(pfrag->page) +
pfrag->offset, copy, pfrag->offset, copy,
iter_offset.msg_iter); iter);
if (rc) if (rc)
goto handle_error; goto handle_error;
tls_append_frag(record, pfrag, copy); tls_append_frag(record, pfrag, copy);
...@@ -592,7 +577,6 @@ int tls_device_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) ...@@ -592,7 +577,6 @@ int tls_device_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
{ {
unsigned char record_type = TLS_RECORD_TYPE_DATA; unsigned char record_type = TLS_RECORD_TYPE_DATA;
struct tls_context *tls_ctx = tls_get_ctx(sk); struct tls_context *tls_ctx = tls_get_ctx(sk);
union tls_iter_offset iter;
int rc; int rc;
if (!tls_ctx->zerocopy_sendfile) if (!tls_ctx->zerocopy_sendfile)
...@@ -607,8 +591,8 @@ int tls_device_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) ...@@ -607,8 +591,8 @@ int tls_device_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
goto out; goto out;
} }
iter.msg_iter = &msg->msg_iter; rc = tls_push_data(sk, &msg->msg_iter, size, msg->msg_flags,
rc = tls_push_data(sk, iter, size, msg->msg_flags, record_type, NULL); record_type);
out: out:
release_sock(sk); release_sock(sk);
...@@ -620,8 +604,7 @@ void tls_device_splice_eof(struct socket *sock) ...@@ -620,8 +604,7 @@ void tls_device_splice_eof(struct socket *sock)
{ {
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
struct tls_context *tls_ctx = tls_get_ctx(sk); struct tls_context *tls_ctx = tls_get_ctx(sk);
union tls_iter_offset iter; struct iov_iter iter = {};
struct iov_iter iov_iter = {};
if (!tls_is_partially_sent_record(tls_ctx)) if (!tls_is_partially_sent_record(tls_ctx))
return; return;
...@@ -630,9 +613,8 @@ void tls_device_splice_eof(struct socket *sock) ...@@ -630,9 +613,8 @@ void tls_device_splice_eof(struct socket *sock)
lock_sock(sk); lock_sock(sk);
if (tls_is_partially_sent_record(tls_ctx)) { if (tls_is_partially_sent_record(tls_ctx)) {
iov_iter_bvec(&iov_iter, ITER_SOURCE, NULL, 0, 0); iov_iter_bvec(&iter, ITER_SOURCE, NULL, 0, 0);
iter.msg_iter = &iov_iter; tls_push_data(sk, &iter, 0, 0, TLS_RECORD_TYPE_DATA);
tls_push_data(sk, iter, 0, 0, TLS_RECORD_TYPE_DATA, NULL);
} }
release_sock(sk); release_sock(sk);
...@@ -642,44 +624,18 @@ void tls_device_splice_eof(struct socket *sock) ...@@ -642,44 +624,18 @@ void tls_device_splice_eof(struct socket *sock)
int tls_device_sendpage(struct sock *sk, struct page *page, int tls_device_sendpage(struct sock *sk, struct page *page,
int offset, size_t size, int flags) int offset, size_t size, int flags)
{ {
struct tls_context *tls_ctx = tls_get_ctx(sk); struct bio_vec bvec;
union tls_iter_offset iter_offset; struct msghdr msg = { .msg_flags = flags | MSG_SPLICE_PAGES, };
struct iov_iter msg_iter;
char *kaddr;
struct kvec iov;
int rc;
if (flags & MSG_SENDPAGE_NOTLAST) if (flags & MSG_SENDPAGE_NOTLAST)
flags |= MSG_MORE; msg.msg_flags |= MSG_MORE;
mutex_lock(&tls_ctx->tx_lock);
lock_sock(sk);
if (flags & MSG_OOB) { if (flags & MSG_OOB)
rc = -EOPNOTSUPP; return -EOPNOTSUPP;
goto out;
}
if (tls_ctx->zerocopy_sendfile) {
iter_offset.offset = offset;
rc = tls_push_data(sk, iter_offset, size,
flags, TLS_RECORD_TYPE_DATA, page);
goto out;
}
kaddr = kmap(page);
iov.iov_base = kaddr + offset;
iov.iov_len = size;
iov_iter_kvec(&msg_iter, ITER_SOURCE, &iov, 1, size);
iter_offset.msg_iter = &msg_iter;
rc = tls_push_data(sk, iter_offset, size, flags, TLS_RECORD_TYPE_DATA,
NULL);
kunmap(page);
out: bvec_set_page(&bvec, page, size, offset);
release_sock(sk); iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, size);
mutex_unlock(&tls_ctx->tx_lock); return tls_device_sendmsg(sk, &msg, size);
return rc;
} }
struct tls_record_info *tls_get_record(struct tls_offload_context_tx *context, struct tls_record_info *tls_get_record(struct tls_offload_context_tx *context,
...@@ -744,12 +700,10 @@ EXPORT_SYMBOL(tls_get_record); ...@@ -744,12 +700,10 @@ EXPORT_SYMBOL(tls_get_record);
static int tls_device_push_pending_record(struct sock *sk, int flags) static int tls_device_push_pending_record(struct sock *sk, int flags)
{ {
union tls_iter_offset iter; struct iov_iter iter;
struct iov_iter msg_iter;
iov_iter_kvec(&msg_iter, ITER_SOURCE, NULL, 0, 0); iov_iter_kvec(&iter, ITER_SOURCE, NULL, 0, 0);
iter.msg_iter = &msg_iter; return tls_push_data(sk, &iter, 0, flags, TLS_RECORD_TYPE_DATA);
return tls_push_data(sk, iter, 0, flags, TLS_RECORD_TYPE_DATA, NULL);
} }
void tls_device_write_space(struct sock *sk, struct tls_context *ctx) void tls_device_write_space(struct sock *sk, struct tls_context *ctx)
......
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