From patchwork Wed Jun 7 18:19:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13271099 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 894A5C7EE25 for ; Wed, 7 Jun 2023 18:20:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B248900004; Wed, 7 Jun 2023 14:20:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 23BA7900003; Wed, 7 Jun 2023 14:20:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0DC95900004; Wed, 7 Jun 2023 14:20:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id ED721900003 for ; Wed, 7 Jun 2023 14:20:36 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B5EED140492 for ; Wed, 7 Jun 2023 18:20:36 +0000 (UTC) X-FDA: 80876767272.30.3C50B60 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id A7655100027 for ; Wed, 7 Jun 2023 18:20:34 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="B/4/wTGG"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.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=1686162034; 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=4vaOjJ4V8cBQxw4FBR0piHsYWVs4rIzqgZ7rDnK+p44=; b=GYC9urPZKEbVT/+UiHoCRHIdUs9IX8yXi6WTVO/mteEEbzKkcrhXHYqt/Ky2IIJJMMuxg6 OOqsjBjoF8vJ+i8ish9Vxp/BIsBD64OCwbm6sVaJ7b+NicV+ICCVwri80EWiysZxhLynAZ c++eQjpgu6560D1ladBlXCyN9k/uGP0= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="B/4/wTGG"; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.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=1686162034; a=rsa-sha256; cv=none; b=iO1AbthKsZP+agEG54NEj1htMETPJgfRXvLZH+jCKYD1uxYUAHryAeA/T6psh5B3LCgldb jOECw47aaZAhSfNwdeMB9hW/+54O6RYr9Q+7bNt74Vv508LJQ1e2jARG35liZ2p7LaKZNa 2kcrNNnfPwZ3QGZN9B2b5T0sk2D6Wlg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686162034; 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=4vaOjJ4V8cBQxw4FBR0piHsYWVs4rIzqgZ7rDnK+p44=; b=B/4/wTGG76x1SaJ72/IyMbos2lpiA89VOodyKBRR/SDWsypNAg24qph1bZENoLw6p3gRWt cB7T1RR82GOW6h7CQIUiy/6rp+FmGqxPPDzDZW9YItYU5oohRAQLxcP/eMMRDx1Op4ppQ4 LN+FRazBMvysXUi1+JMYLqVVTG4x0VA= 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-354-LRCuNYAMOOq4Tm5Pxw5q1A-1; Wed, 07 Jun 2023 14:20:25 -0400 X-MC-Unique: LRCuNYAMOOq4Tm5Pxw5q1A-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5340480027F; Wed, 7 Jun 2023 18:20:24 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87D23403367; Wed, 7 Jun 2023 18:20:22 +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 13/14] tls/device: Support MSG_SPLICE_PAGES Date: Wed, 7 Jun 2023 19:19:19 +0100 Message-ID: <20230607181920.2294972-14-dhowells@redhat.com> In-Reply-To: <20230607181920.2294972-1-dhowells@redhat.com> References: <20230607181920.2294972-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A7655100027 X-Stat-Signature: ubqhb1bjhxezdqgsffgo79m1grjkqzo6 X-HE-Tag: 1686162034-859303 X-HE-Meta: U2FsdGVkX1/Zf4++sjojUJbVl05ZBuYm47K9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jF6dm26GLV874duWIS1xLoPh0qbEgAotv4PAaoKKR34i8ZAhJYcPFvt2gCC1rzlVJArJy1DwD+dRNDySt3TlI0aia9qmIGvREmZ/VAZsKRz+cHWTLFtia0fu0h9OiF34OoAUL87BHBdrr2Fd6HMPbXEv59hhVn2WWCat4z1Cbg6c2SGVMG76v1RpbLRLh02W0Ne8uaUxyyGJXVZEJxcbYibyPEtUXoGxCCb7wdpp4oZr6Z9Ed2zGvDvFEZFiYW8qq5vEFKm37kB7kvI5JST6IwJ4wrlXMYTvur7qxgBUhS69A2lED4esIU8uz2Vi4pNqFZ5b4YIh8BZM+mV+3LwoA10Ma/uqhnoBVOKvf9OxO/EY4nP37qdhcZPETgCxJmnEGuHO2iXQrUlV1D87tlo+7Ga20RWx8NLvCUrodzlFDfeZwz7AQRbuPbBa7jNZwPxo+HDnRSt9pWWA== 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 device 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 Reviewed-by: Jakub Kicinski cc: Chuck Lever cc: Boris Pismenny cc: John Fastabend cc: Eric Dumazet cc: "David S. Miller" cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- net/tls/tls_device.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index 439be833dcf9..bb3bb523544e 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -509,6 +509,29 @@ static int tls_push_data(struct sock *sk, tls_append_frag(record, &zc_pfrag, copy); iter_offset.offset += copy; + } else if (copy && (flags & MSG_SPLICE_PAGES)) { + struct page_frag zc_pfrag; + struct page **pages = &zc_pfrag.page; + size_t off; + + rc = iov_iter_extract_pages(iter_offset.msg_iter, + &pages, copy, 1, 0, &off); + if (rc <= 0) { + if (rc == 0) + rc = -EIO; + goto handle_error; + } + copy = rc; + + if (WARN_ON_ONCE(!sendpage_ok(zc_pfrag.page))) { + iov_iter_revert(iter_offset.msg_iter, copy); + rc = -EIO; + goto handle_error; + } + + zc_pfrag.offset = off; + zc_pfrag.size = copy; + tls_append_frag(record, &zc_pfrag, copy); } else if (copy) { copy = min_t(size_t, copy, pfrag->size - pfrag->offset); @@ -572,6 +595,9 @@ int tls_device_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) union tls_iter_offset iter; int rc; + if (!tls_ctx->zerocopy_sendfile) + msg->msg_flags &= ~MSG_SPLICE_PAGES; + mutex_lock(&tls_ctx->tx_lock); lock_sock(sk);