Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5605523rwd; Mon, 5 Jun 2023 06:12:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ52Ai4hWL1A6o80DNGKOhS28KQapNcLcWm5Nqgb3PEKv8ETFvwcaO9ai1g9Z8ZxSucmHair X-Received: by 2002:a17:90a:598b:b0:255:6174:1588 with SMTP id l11-20020a17090a598b00b0025561741588mr6470628pji.42.1685970755615; Mon, 05 Jun 2023 06:12:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685970755; cv=none; d=google.com; s=arc-20160816; b=kcNkw0SW+s/VHzo9K5zqDzrKf5FoN1MNdE+gIA41eYohGUI3cEcEz/xGuNaOWfelsb Lhu+aiEumEs51azwtaWmjNqGrmbI9wdUgymrmswU97/cXaHavGvVulwjyBX+nbkxe11x AMszCHUnfIqZ31ZVk79m/xOZ6aj3SjyIXO1Q3D8Sk1D9RHajkC7uIbaKunULOmBKA7lm Pfd9VMRv6Uo8OBF1lr5ymfIZwTb4pjYOe9TL+elaTYwO+VuoKk5lvCgd9/x5ceoXzgx+ dF/aS/MWGJ+lQJbLSH0VMfH7VqI75ZhDZZ4mdPoSzz7RHG0R5zCDhkLwbjgE6WbHnXmV dVUQ== 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=W0FWRRqlHW2dml6zeyANP94ZNOMoghLMR9ZqTCxdb24=; b=D8W6w0TQ7olYeYKm6fSbVvoUyqaQNDMDUqkLa3o0FTcEWGuzUQ8GmE9rEookFL8EEc RLZRgOZVatbwvOFcdR8Ho/WzNrgjKxL6G33JZVbGYgpyrE8iJM4Nf7b5NcyNUjLoHIfI Bb+E0PxCni0hX4+NTRz4ru/BGKSr7kPFSi9sAFsbs5B8iWLsLZAt8nIa1W5atDqxdo1X L0GIDCfu7crbsRz74zH0IYSjzO/vHWyw6vE0BIq4vnLYGAxS5xz0NDsuxhnnccagULFf k2O+mAbVVz3LD6AcZBEH4W4R3856KtXpYuPc35RAjAtP0jgh8vQ/3nG3IZl9/pqwH1Hz x/SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ZmXjLkUq; 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 u9-20020a17090a2b8900b0024c1ddfa1bfsi7024881pjd.92.2023.06.05.06.12.20; Mon, 05 Jun 2023 06:12:35 -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=ZmXjLkUq; 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 S233757AbjFEMre (ORCPT + 99 others); Mon, 5 Jun 2023 08:47:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233657AbjFEMrO (ORCPT ); Mon, 5 Jun 2023 08:47:14 -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 3878BFD for ; Mon, 5 Jun 2023 05:46:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685969193; 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=W0FWRRqlHW2dml6zeyANP94ZNOMoghLMR9ZqTCxdb24=; b=ZmXjLkUqIViZ1v3uV3oYe8ThAujivfwlJagek8G7dsR9R8g+t3auPBG/YqZsxin5phOrnb 55iW89JTkh4AJKikZwehYGVZ3N+LkTdw/sALiFS7JL4f/kHM+rgkSJ/eBq9+cEnaDCM1+z QLPk5VHX62ha2DPCuhKipJpHXi9nGaU= 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-217-qmCbG5JcO_-fBCTGdBFm8w-1; Mon, 05 Jun 2023 08:46:30 -0400 X-MC-Unique: qmCbG5JcO_-fBCTGdBFm8w-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 9153980120A; Mon, 5 Jun 2023 12:46:29 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73B754087C62; Mon, 5 Jun 2023 12:46:27 +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 v4 08/11] tls/sw: Support MSG_SPLICE_PAGES Date: Mon, 5 Jun 2023 13:45:57 +0100 Message-ID: <20230605124600.1722160-9-dhowells@redhat.com> In-Reply-To: <20230605124600.1722160-1-dhowells@redhat.com> References: <20230605124600.1722160-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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 #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 7a6bb670073f..b85f92be7c9d 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,