From patchwork Wed May 31 12:45:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13262147 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 3B8C5C77B7A for ; Wed, 31 May 2023 12:45:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9CD38E0009; Wed, 31 May 2023 08:45:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C4CB78E0002; Wed, 31 May 2023 08:45:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B15798E0009; Wed, 31 May 2023 08:45:53 -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 9FCDC8E0002 for ; Wed, 31 May 2023 08:45:53 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 71B0E1C6E34 for ; Wed, 31 May 2023 12:45:53 +0000 (UTC) X-FDA: 80850522186.07.6A4A33E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf04.hostedemail.com (Postfix) with ESMTP id 88B9140010 for ; Wed, 31 May 2023 12:45:51 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZmL1paaQ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685537151; a=rsa-sha256; cv=none; b=sVRMoZ1IhRx+V9h3pow2WkImYPorFshqC2NeXdkPjkpqnkHpaCmDNQWTch7kEeTtN+GOun Yf4UUaJLtFqx4ITSaeVzREEFsDIopT4nfKSMQTOm8pHWwDb0YnE2B7PVJ/r9BctYIrTpYw dc9rDtbQN7ITluhfSizBiWmxTc1EMk0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZmL1paaQ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685537151; 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=xFpJiBMaV6haKLFUiEEfF2pWt3wFFqyfTnw9cLbfIuI=; b=MWKGnXXKzs+DxGcMbok8cWisX6a2TLGZlv36T69AmIiUcEk/GXvhUysWjvn9ilGN0U+nj0 9uYYZSqEh4gpoo5sKaq3h8FUvfXMNFySNBZIK2NQS/EVn6hYA8F8DimPbJmwBpgO5Qj1Kg Iawzv286exG1GmJ0XqBOV9TtzzgrUFo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685537150; 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=xFpJiBMaV6haKLFUiEEfF2pWt3wFFqyfTnw9cLbfIuI=; b=ZmL1paaQyFbbEeYw7tKJNUlewte+Te/q/hK7PT9wtgkJUKMdzim9mKMVjFm317cYq/wzv2 Bm47gd09Cq21Kj3sQf9bZCRAs1RyzlC+EFaghTU4pPuf5ldl0MBBppzcDdvnY7TvqRQcEx HyAjCON40gh4IFclVQnXrta7VusiR4U= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-116-ZBHr42RPMCeBYoDi-5JaaA-1; Wed, 31 May 2023 08:45:44 -0400 X-MC-Unique: ZBHr42RPMCeBYoDi-5JaaA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C5504811E7F; Wed, 31 May 2023 12:45:43 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99826112132C; Wed, 31 May 2023 12:45:41 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , Chuck Lever , Boris Pismenny , John Fastabend , Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 3/6] tls/sw: Support MSG_SPLICE_PAGES Date: Wed, 31 May 2023 13:45:25 +0100 Message-ID: <20230531124528.699123-4-dhowells@redhat.com> In-Reply-To: <20230531124528.699123-1-dhowells@redhat.com> References: <20230531124528.699123-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 88B9140010 X-Stat-Signature: 8cz5ykoi9krbjh9nd6yy8thhay68rjga X-HE-Tag: 1685537151-319108 X-HE-Meta: U2FsdGVkX199+5Jw1m56R6XvS1NokEOnR0RSDvOCPQr7NzRU1EsTOG9tWzZVK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/wG/hFflOc7XiUaIAVg9605KZeC7QlG/5iuo2Y7j9r/QQfwcehjykq6nZqMYB+kEPnAdRYJIeUY0xaANdd3SM86Dv+QRFgGb6teKoPiH1OQsQgfilC9ULAMEYeGybd0MjgBz9n3W/NUpZId7jn5XXEwneI1rbuEhyCY49pfZGLAcxh3r0TlMILsQ8p/rIO+JwjNCoCm6gvxmbIN4ApB2ZD4jmVVm2NfV75cii22pKIBSQTRfsn3bo2VdO+Eo6BmO9wm5vqW7xEGfeRwCRikt8Z8VCJy8ZV03IcNLKZhzLuA1cSNfeAS9BmhLC4dIps9LTSfIORHGaq0Y279spO3IdSZKV5B57um1PQW+ZDG3xBzLagJRxxTvEOF1gpKUFUB9sECSOI7l05UNd5TwVYb1inEuxjuByDuo8xw== 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. 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 --- Notes: ver #2) - "rls_" should be "tls_". net/tls/tls_sw.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index 6e6a7c37d685..60d807b63f75 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -929,6 +929,38 @@ static int tls_sw_push_pending_record(struct sock *sk, int flags) &copied, flags); } +static int tls_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 = NULL, **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 (WARN_ON_ONCE(!sendpage_ok(page))) { + iov_iter_revert(&msg->msg_iter, part); + return -EIO; + } + + 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); @@ -1018,6 +1050,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 = tls_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; @@ -1080,8 +1123,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,