From patchwork Wed May 31 12:45:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13262149 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 DA989C77B7A for ; Wed, 31 May 2023 12:45:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 830E48E000B; Wed, 31 May 2023 08:45:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 793E28E0002; Wed, 31 May 2023 08:45:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65A548E000B; Wed, 31 May 2023 08:45:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 54F1C8E0002 for ; Wed, 31 May 2023 08:45:58 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 30D3C1A0193 for ; Wed, 31 May 2023 12:45:58 +0000 (UTC) X-FDA: 80850522396.16.87D9083 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 1F215A001E for ; Wed, 31 May 2023 12:45:55 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UAnF1UGX; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.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=1685537156; 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=uuYRuRqPrqYrWBy2myOfoGGw2Qio81ibrygQkKyKemI=; b=acdyFgnjpT6qXnDXQ0IT9WVjVXu9S2aFBz3aQPAy0uc2Z0VUOL8mGsxAmVK+cSWea9rGhv VQ6OAcchnK4BVXPHBo78Nx35MyY+JelQXzDrEa5HJ5CcGFrCmLtqNyVS3WNmFgW6P4BWxw NtPJ1l8wI4IkMmBuY6QQ9MoCpN4RiLY= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UAnF1UGX; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.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=1685537156; a=rsa-sha256; cv=none; b=kdiDkrQc8RQcTx90nm39mWybFedR0x0db6hYL8vuN0/7GnX6oitWy6bZjoZZRrbnfYXwA/ LKQWeTTfWYsMGCxZdV5yWPAsvl8yx5hhssAs7fY1P7rSIrPkiJTEOC0/C12U7uTcNb6flf f4+ApjZ5Hgb4f2Ju/K6vO6fDNe7xVQI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685537155; 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=uuYRuRqPrqYrWBy2myOfoGGw2Qio81ibrygQkKyKemI=; b=UAnF1UGXBA952Sq37/4ApDvy66IgcelMaaRx+Ecw28Be76ZHh5nSI0Ga00pDgQxBR45jcY MDPmnVn5H4lN2rHhuPtN9m1+Ft7Oe68o/HJwk0vHLksorhHcxVaQPhrJtJZMN1SfxCauJQ Hvk/yB9MG5o/ggEDpj9048Ln/6X9BeI= 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-54-R6gsZvE5P7aGqYDd_4hZXw-1; Wed, 31 May 2023 08:45:51 -0400 X-MC-Unique: R6gsZvE5P7aGqYDd_4hZXw-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 650F3811E7F; Wed, 31 May 2023 12:45:50 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.42.28.182]) by smtp.corp.redhat.com (Postfix) with ESMTP id 994162166B25; Wed, 31 May 2023 12:45:48 +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 5/6] tls/device: Support MSG_SPLICE_PAGES Date: Wed, 31 May 2023 13:45:27 +0100 Message-ID: <20230531124528.699123-6-dhowells@redhat.com> In-Reply-To: <20230531124528.699123-1-dhowells@redhat.com> References: <20230531124528.699123-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspam-User: X-Stat-Signature: h6ajr7zsdenggeegokeugdpnz88kseen X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1F215A001E X-HE-Tag: 1685537155-247204 X-HE-Meta: U2FsdGVkX181lf2JRylp9JiseW4WPG1QFmKwb5V87LbABFap37YPBiPckwon0i2Veu4zeRiS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p52jVKl0Yspg6uKGuqAY2XFGrJnoV2pIqfqjgbNqdMLhKvHw0ay+dfBgxP+Mhl07ByM1vorjKu6Jk0X00w04dPgCcwm4Fmns6fY/YJF/BX5bhkCUdXWLqN2FE+/zolLDAKybCcZKZBLnVOkqvJYmxjnGmYftkDZXj771Eep/U6wCsnPMaAlB9kl7dSqZf6JI4xxyvKjFtY1KelCb91mn1w4CLnLM2ExVZhcI5M+Y797rt669WCv5ckveEJQopy2kYUJ3h/KSjSImdWcXMsmgWQg6HIekzP0sfiL7BzI0LT8+bEOOaZYV8d8Y37ACsZN+rRG5T6cx9CRl4bS7NjUMO22dfOUJvXUoutV8Dlf6UTDOIeKKz7vfylxLCgLjs7mjo5ZTPFBWHGI05sb3N/0pct6gXu4BGg== 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 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 --- 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 a959572a816f..221fb30cba51 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -508,6 +508,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); @@ -571,6 +594,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);