Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1138942rwd; Wed, 7 Jun 2023 11:33:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4gbya/Lpx8MkBXKMwR+Zg8K+01PstSg+LsdTSLm7ld7os/nOJOm3tLTRFkUvO5s5W6w1mX X-Received: by 2002:a17:902:d4c7:b0:1ad:7bc5:b9ea with SMTP id o7-20020a170902d4c700b001ad7bc5b9eamr3338307plg.60.1686162787684; Wed, 07 Jun 2023 11:33:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686162787; cv=none; d=google.com; s=arc-20160816; b=p9vN9qboonz3XUWcYlYhCuEwsEgMtH5TMw6px+DMz44Mme711xBWZ7cgQL775oDdqO oyCQJf2ijqAZ6zC1VzKDxyJEqF/RUYpmixp7HwEppDMty8yPUfuF9xmahuoM02Xq0fg4 7Me1s3I3br7WG7NMgTcfQldIJoSk/h1YzT5Ow49eKR0f1z8IlVWWJO80xe8C4zS5Vyx1 cwjQKsvAdlWY/54lEUSv8N3Hneun/GC3A7yCOqa72m0KtOikqxkqpv26suHDdUnajPVM YW97SIou84lLtBYUXRsQ5SUQjorMRsfyD9MDuPtcA9PueqRtGnyOUBXaA0HGSg9J+PTA AAwA== 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=6q5xbY97TlySjcT8Avdxpu9hvkIkBKUNCyWrMvUV8f8=; b=ILHx3UZ4pkjO4ulcX6EKs9+UeMSZPqOTlwG9E4VlLKeh6ks2tpUinheaUH7y2S0Qlu 3nBcH6CBvedXDpEM2szmWiekhcNRz+s0btdnZq9TdDUBTox9GHu9woYO8HzMxFc/zoHR K7j76o+TG+WpK02xegCjoNzW8iT7oDNCj4nn2bjUtk2hv4RWsx/5sU6wLekEgAevR5wP kxPbDH5fWJJiSHlFbmV74PxCV6M9dhA9jARtUh3gNwIRkMg9h2Cs9hcP+FjrV/cew7sG Y9hohuud5Wqe8krepztZ5OuJYl8to/WAlrmjPo5GAM4lJ1EBI9C6ChQabsH26Aur7oPN fWRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=W7WcGW+y; 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 d12-20020a170902cecc00b001b039693da8si9413416plg.635.2023.06.07.11.32.51; Wed, 07 Jun 2023 11:33:07 -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=W7WcGW+y; 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 S232149AbjFGSWN (ORCPT + 99 others); Wed, 7 Jun 2023 14:22:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231532AbjFGSVP (ORCPT ); Wed, 7 Jun 2023 14:21:15 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7E311FC3 for ; Wed, 7 Jun 2023 11:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686162025; 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=6q5xbY97TlySjcT8Avdxpu9hvkIkBKUNCyWrMvUV8f8=; b=W7WcGW+yfoSgtS7F748lozL7QxYzZVo9/PdMFwfbCIhCrXwBgTwTot6m0Bh4se55pF5th5 BYzVfvyEmU8QTDKuhr8dtVC8elJFMOUKyZ/M1wmkwF1idF8Gu+R7V4ogEOkYMxg9Bt3/cT CGfCp0BD9PCLw/WG2p8bFP5m615QR5w= 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-631-Eq-9mGkaPwauwtyewFdCog-1; Wed, 07 Jun 2023 14:20:19 -0400 X-MC-Unique: Eq-9mGkaPwauwtyewFdCog-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 25C4980027F; Wed, 7 Jun 2023 18:20:19 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AC5C2166B25; Wed, 7 Jun 2023 18:20:16 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org, Linus Torvalds 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 v6 11/14] tls/sw: Support MSG_SPLICE_PAGES Date: Wed, 7 Jun 2023 19:19:17 +0100 Message-ID: <20230607181920.2294972-12-dhowells@redhat.com> In-Reply-To: <20230607181920.2294972-1-dhowells@redhat.com> References: <20230607181920.2294972-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Spam-Status: No, score=-2.1 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=unavailable 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 #6) - In tls_sw_sendmsg_splice(), remove unused put_page. - In tls_sw_sendmsg(), don't set pending_open_record_frags twice. ver #2) - "rls_" should be "tls_". net/tls/tls_sw.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index a2fb0256ff1c..2d2bb933d2a6 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -931,6 +931,35 @@ 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; + + 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); + *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); @@ -1020,6 +1049,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; @@ -1084,6 +1124,7 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) */ tls_ctx->pending_open_record_frags = true; copied += try_to_copy; +copied: if (full_record || eor) { ret = bpf_exec_tx_verdict(msg_pl, sk, full_record, record_type, &copied,