From patchwork Fri Mar 31 16:08:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13196190 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9ADE3C761A6 for ; Fri, 31 Mar 2023 16:10:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F4C46B009D; Fri, 31 Mar 2023 12:10:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CC096B00A4; Fri, 31 Mar 2023 12:10:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CF626B00A5; Fri, 31 Mar 2023 12:10:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 078066B009D for ; Fri, 31 Mar 2023 12:10:49 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 9DD1340458 for ; Fri, 31 Mar 2023 16:10:48 +0000 (UTC) X-FDA: 80629681776.30.595F643 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf09.hostedemail.com (Postfix) with ESMTP id A9A7C140016 for ; Fri, 31 Mar 2023 16:10:46 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ioa0UtKv; spf=pass (imf09.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680279046; a=rsa-sha256; cv=none; b=4SYaZWJRdMTkGpzB3La+dwWdzVjVkdDJBthb8Th2gEQR5EsPhpSNgFrZ06zVwS/rTXT0kb dytwsz6UyVrYIAhAkguEHYS2ZPrt4ZJZqGfgHoUfl7XtjHa943U+/CSnwYVbew+ds2/URF a+YbmRsDgocQyokL2jjA7hwhZ2IyNCs= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ioa0UtKv; spf=pass (imf09.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680279046; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NZJQb7iAop4LtoT19/C7V+Vk0vTB0ScTwxSGzzmAlmQ=; b=jhr/GnQTytKxnLvDBbXEPmSLbugFeF8g7iHneuHLbaZyrczq/niN9PsUo0LH4ag8WA5LHF D1983muugoj+tR0nRtxIp0QLjrUlHfWq9HiH66f35R2UJa3pQGmTKP+G0NypOYBTuedoz0 3oIXd9mvzaA3gHNZvD2xtzCYBa0rcPg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680279046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NZJQb7iAop4LtoT19/C7V+Vk0vTB0ScTwxSGzzmAlmQ=; b=ioa0UtKvTmua75QyXN1X77zHc/tVQin/xomX51fJSHILmG/kp8L5gX19JPo9JSI5dYfA6A tdOgAxaIypn6WI3NGYuzfQf2ZQB2R+8MdF4KE674hUz/l0okbxzsEl7ppGd66woMvu4KbB 4dqUfwx5WakHvgGYSfKPASNkHorQHCI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-380-s0-9Da1IPNaVGNWY3Pu9-w-1; Fri, 31 Mar 2023 12:10:42 -0400 X-MC-Unique: s0-9Da1IPNaVGNWY3Pu9-w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B8BF029ABA1D; Fri, 31 Mar 2023 16:10:41 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id A7E464020C82; Fri, 31 Mar 2023 16:10:39 +0000 (UTC) From: David Howells To: Matthew Wilcox , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: David Howells , Al Viro , Christoph Hellwig , Jens Axboe , Jeff Layton , Christian Brauner , Chuck Lever III , Linus Torvalds , netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Boris Pismenny , John Fastabend Subject: [PATCH v3 29/55] tls/sw: Support MSG_SPLICE_PAGES Date: Fri, 31 Mar 2023 17:08:48 +0100 Message-Id: <20230331160914.1608208-30-dhowells@redhat.com> In-Reply-To: <20230331160914.1608208-1-dhowells@redhat.com> References: <20230331160914.1608208-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspam-User: X-Rspamd-Queue-Id: A9A7C140016 X-Rspamd-Server: rspam01 X-Stat-Signature: 5k1i4af8hixzzbw4akp34p86k83tgbbn X-HE-Tag: 1680279046-667356 X-HE-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ub/Ap0aETI1pWENSv+kGeeDZTQBllidUyLqpnV6uhsqdYMxrwguAZyWmvowPyrIkuI/mERAN6DLjdqxRqByxnAA8+wXbxf3lE6n5P6PQ4TN3dY+y2OaLugUBbhr4Ky7TG1uyFH/qS8zLtFdXiIVGBhrCxHk9sVrOfLsBYcRv06JKd8Un/IdFMCMeZMmdF80Q9Ca0IFctMlDWDWO64nLhipr/CZDWnf54K1KGf5XImhgPXB42geTVgLabCFuYp7IbBWMvvNT7X598Szf0LbWGa05Yy+TgM/I41Mfa0Azqk5Clq2MIXKowj/Fnp3x7dgwjKWfwhCuZjyQfniLcZRLLuuHY02lAZXMQLR54YnMG1Z2kjn3PO8JrGwAwtCjw+9oi9gNP+ElMYVOukChEunxvl6VoMsvH1jg33J+Xsv830b/dwxiBhx1Q4ZZhwI7TDZBjWdXhTiCaju/RIF1W+RNYShCRxIn0G1gm445R7+Z2hAjHIQFW+6QBzYRPpvOxmrs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Make TLS's sendmsg() support MSG_SPLICE_PAGES. This causes pages to be spliced from the source iterator if possible and copied the data if not. This allows ->sendpage() to be replaced by something that can handle multiple multipage folios in a single transaction. Signed-off-by: David Howells cc: Chuck Lever cc: Boris Pismenny cc: John Fastabend cc: Jakub Kicinski cc: Eric Dumazet cc: "David S. Miller" cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- net/tls/tls_sw.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index 782d3701b86f..ce0c289e68ca 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -929,6 +929,49 @@ static int tls_sw_push_pending_record(struct sock *sk, int flags) &copied, flags); } +static int rls_sw_sendmsg_splice(struct sock *sk, struct msghdr *msg, + struct sk_msg *msg_pl, size_t try_to_copy, + ssize_t *copied) +{ + struct page *page, **pages = &page; + + do { + ssize_t part; + size_t off; + bool put = false; + + part = iov_iter_extract_pages(&msg->msg_iter, &pages, + try_to_copy, 1, 0, &off); + if (part <= 0) + return part ?: -EIO; + + if (!sendpage_ok(page)) { + const void *p = kmap_local_page(page); + void *q; + + q = page_frag_memdup(NULL, p + off, part, + sk->sk_allocation, ULONG_MAX); + kunmap_local(p); + if (!q) { + iov_iter_revert(&msg->msg_iter, part); + return -ENOMEM; + } + page = virt_to_page(q); + off = offset_in_page(q); + put = true; + } + + sk_msg_page_add(msg_pl, page, part, off); + sk_mem_charge(sk, part); + if (put) + put_page(page); + *copied += part; + try_to_copy -= part; + } while (try_to_copy && !sk_msg_full(msg_pl)); + + return 0; +} + int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) { long timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); @@ -1016,6 +1059,17 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) full_record = true; } + if (try_to_copy && (msg->msg_flags & MSG_SPLICE_PAGES)) { + ret = rls_sw_sendmsg_splice(sk, msg, msg_pl, + try_to_copy, &copied); + if (ret < 0) + goto send_end; + tls_ctx->pending_open_record_frags = true; + if (full_record || eor || sk_msg_full(msg_pl)) + goto copied; + continue; + } + if (!is_kvec && (full_record || eor) && !async_capable) { u32 first = msg_pl->sg.end; @@ -1078,8 +1132,9 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) /* Open records defined only if successfully copied, otherwise * we would trim the sg but not reset the open record frags. */ - tls_ctx->pending_open_record_frags = true; copied += try_to_copy; +copied: + tls_ctx->pending_open_record_frags = true; if (full_record || eor) { ret = bpf_exec_tx_verdict(msg_pl, sk, full_record, record_type, &copied,