Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2346000rwd; Fri, 2 Jun 2023 08:12:09 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7T5DhzytlfXs+iDSpcm2igbWMnxczCeewrV46dFeZSLR3KR3oPInLXQXRZfYB/nE4Qvgo8 X-Received: by 2002:a17:902:ee4c:b0:1b0:26f0:4c72 with SMTP id 12-20020a170902ee4c00b001b026f04c72mr273708plo.28.1685718728156; Fri, 02 Jun 2023 08:12:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685718728; cv=none; d=google.com; s=arc-20160816; b=clyq22s+VTzb6stvkZXIEYxw3L60mcYpnWUniw0A3AkxtpLDusqrhfZIA0qnlnNmGP hXHkeAhJJDuTAccEvCK4uByIszvLKMpwmVn8Jtg4BJVvnLye5J2U+0iFtzFuSeuUn3wI HQq/Fs/HAz3ieUaykJko+XzxNBgFoHDGwOwwbmtmJZ2qh3vc0w8aF5xmt4Xp34PHt1Ct 0C7lwQku1zYO457BHViKEEdEkp5ESIGytEey2OOZ/dm4reU0co87pNM79zMyjnJDLDMV u+RE1XBB4utmQ0BtAWwW8YiT4SxxDcRHnJzABKc90wOWFmSSZ3KeFz+ThfK6dKKvLd2x PkCw== 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=VkjM4EGYNz4bsSc92zEJRjklGPZ81HVRDlJ8Fsl+T7k=; b=GhZJEPzqZDUGuh1I2GZU4ti5tgf2MP3UkxN5EXWjgCOvvU28ZXSAyTuQLWiUJWKjb3 3d/wOzl88CVQIz5SrGMWny2N+zQvkiYbGiWgg4b8+GykWQ7e6bQdPtHchYlKDk79tsvZ GaIHoFViWV+Tkh0f3GocFx8ohVc7zijFuDJukXPxXzm4wzY6J4mJS0LV+jih8u2DeS67 M/CxYbhiJu6Bxnq9b9kuKbcOxQQz4J4rdM5Rg6yZ+aQy2PZ2AUy0CY9YgSidcQ8tZ0BB djA2zaX2+4BLeLVSF3kp6k+fzySvn7xK8U49UlY6E7sbl2X9QnaW4CII3/5yew5RlfwD b7cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CRZ+loX6; 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 k18-20020a170902c41200b0019aa0d010eesi1085255plk.308.2023.06.02.08.11.53; Fri, 02 Jun 2023 08:12:08 -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=CRZ+loX6; 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 S236480AbjFBPJe (ORCPT + 99 others); Fri, 2 Jun 2023 11:09:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236449AbjFBPJY (ORCPT ); Fri, 2 Jun 2023 11:09:24 -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 F3732E59 for ; Fri, 2 Jun 2023 08:08:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685718516; 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=VkjM4EGYNz4bsSc92zEJRjklGPZ81HVRDlJ8Fsl+T7k=; b=CRZ+loX6AIcvDMEHOvuFEDM/QYCDgkxX0VPtK5tGjDzb6kgIi3xj80YL4wwk9M5GSgw+xU YTkOP8E/gdbrHDzJc4OlLn9dE/qlxzELueataA4HO6K67HQ6RpqCm/UgDysCm5uFKp7/VC NbufJZXUq1XbPQ0twODJaAhf/1Rz+f0= 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-552-_zaZ26ErPBGk4yKO8qBKjw-1; Fri, 02 Jun 2023 11:08:32 -0400 X-MC-Unique: _zaZ26ErPBGk4yKO8qBKjw-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6021929AB3FA; Fri, 2 Jun 2023 15:08:31 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B13C40146F; Fri, 2 Jun 2023 15:08:29 +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 v3 07/11] tls/sw: Support MSG_SPLICE_PAGES Date: Fri, 2 Jun 2023 16:07:48 +0100 Message-ID: <20230602150752.1306532-8-dhowells@redhat.com> In-Reply-To: <20230602150752.1306532-1-dhowells@redhat.com> References: <20230602150752.1306532-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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=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 6aa6d17888f5..14636cc6c3a4 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); @@ -1021,6 +1053,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; @@ -1083,8 +1126,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; just_flush: if (full_record || eor) { ret = bpf_exec_tx_verdict(msg_pl, sk, full_record,