Skip to content

Commit 24763c9

Browse files
dhowellskuba-moo
authored andcommitted
tls/device: Support MSG_SPLICE_PAGES
Make TLS's device sendmsg() support MSG_SPLICE_PAGES. This causes pages to be spliced from the source iterator if possible. This allows ->sendpage() to be replaced by something that can handle multiple multipage folios in a single transaction. Signed-off-by: David Howells <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> cc: Chuck Lever <[email protected]> cc: Boris Pismenny <[email protected]> cc: John Fastabend <[email protected]> cc: Jens Axboe <[email protected]> cc: Matthew Wilcox <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 45e5be8 commit 24763c9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

net/tls/tls_device.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,29 @@ static int tls_push_data(struct sock *sk,
509509
tls_append_frag(record, &zc_pfrag, copy);
510510

511511
iter_offset.offset += copy;
512+
} else if (copy && (flags & MSG_SPLICE_PAGES)) {
513+
struct page_frag zc_pfrag;
514+
struct page **pages = &zc_pfrag.page;
515+
size_t off;
516+
517+
rc = iov_iter_extract_pages(iter_offset.msg_iter,
518+
&pages, copy, 1, 0, &off);
519+
if (rc <= 0) {
520+
if (rc == 0)
521+
rc = -EIO;
522+
goto handle_error;
523+
}
524+
copy = rc;
525+
526+
if (WARN_ON_ONCE(!sendpage_ok(zc_pfrag.page))) {
527+
iov_iter_revert(iter_offset.msg_iter, copy);
528+
rc = -EIO;
529+
goto handle_error;
530+
}
531+
532+
zc_pfrag.offset = off;
533+
zc_pfrag.size = copy;
534+
tls_append_frag(record, &zc_pfrag, copy);
512535
} else if (copy) {
513536
copy = min_t(size_t, copy, pfrag->size - pfrag->offset);
514537

@@ -572,6 +595,9 @@ int tls_device_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
572595
union tls_iter_offset iter;
573596
int rc;
574597

598+
if (!tls_ctx->zerocopy_sendfile)
599+
msg->msg_flags &= ~MSG_SPLICE_PAGES;
600+
575601
mutex_lock(&tls_ctx->tx_lock);
576602
lock_sock(sk);
577603

0 commit comments

Comments
 (0)