Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp812925rwd; Wed, 31 May 2023 05:58:31 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6JXPkojBCJ4YZKB7uO5mcDhFsH7jHO9oArvBCW5ga87uR03hkWdytKclOXHsIHsMdxOonC X-Received: by 2002:a17:902:e5c4:b0:1b0:6e16:b92c with SMTP id u4-20020a170902e5c400b001b06e16b92cmr4885878plf.54.1685537911640; Wed, 31 May 2023 05:58:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685537911; cv=none; d=google.com; s=arc-20160816; b=TJHY1yAR1ZgFoShRL8MP5c2n4RKqmQfMXQluYEHShBp/dg18lOlhWYGWkQvVKMT7G/ AXHUru3dUH81RT9pvOkm7/boSS35G4u6ZMh8KwwEL0Fzwd+0QrdELm+YBQN5FvUieqfe rq8+gmxzNSolU3xH4vc5Dizen0aHQl6fPJ0MgqZ/esmlMlhFrgVzeEMC4hdLciU7OzW/ wKqdt5ui3qIlwENeK4o1CEUPDl7EM4NFsu5qwvvmQgBudmFa02C6ugDMFsGWlR6nfHFR DmgYZEdgENdyL9jJoRneA7CkIKSCOZH1l92ieSYr+ZDIQi5AxANhCRkajFowL22Y6bGp b6FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xFpJiBMaV6haKLFUiEEfF2pWt3wFFqyfTnw9cLbfIuI=; b=VoQvtMvNEerWXOcwkzKU0Fon4x/7PrYuJE8BAQFrKfTq7I1uKK/ZqhX5A7++E5bAwS A4WYr9gsTz8pHSpWv15tNpgoOWj5bbryMEUzxdpWnWkuYm/f4zCgbZXDS4bleRXZKZBW 3i2NqfA+2dUFQ37zNLGcAUSxXUxs+zMwXLXeLI42bGizfaKlA78lUmdllksH/rg+UUY6 8JkMG1FfvjnyxK8a3tLVMbcF2N0khIMVmoR8Kx7wGrTvvRlwX0A6UArGvPiQ3BXyzYsD xSDvGC1DywwL+q3csNOcWlQCVVm/3f7ixHbhjSlR0Wl1j5D7UG/fL61OVCPBLD5CGwtO dmGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZE7fg6BI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l4-20020a170902ec0400b001b03a1a3169si844674pld.257.2023.05.31.05.58.06; Wed, 31 May 2023 05:58:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZE7fg6BI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235945AbjEaMrL (ORCPT + 99 others); Wed, 31 May 2023 08:47:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235902AbjEaMrI (ORCPT ); Wed, 31 May 2023 08:47:08 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BA9311F for ; Wed, 31 May 2023 05:45:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685537148; 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=ZE7fg6BIXSpMhLnW1clDpdZMGuwFlPPwrT4GfLeLtte4aZ40GZam6apjFQMk3M7vdDCbRm jokXXHV8C7jkofiVAF5OjRWlU2lDfl7umRAJ/aJ9On2aZLMxxM7Q3/OJbW5bArFCq4XdiR uqZQsMD3dYPzpLirFrtrRmS4DoOe+h8= 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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,