From patchwork Wed May 24 15:33:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13254205 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 5C870C77B73 for ; Wed, 24 May 2023 15:34:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F398190001B; Wed, 24 May 2023 11:34:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE8F6900007; Wed, 24 May 2023 11:34:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD93890001B; Wed, 24 May 2023 11:34:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id CFAFD900007 for ; Wed, 24 May 2023 11:34:21 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6A2CDC0971 for ; Wed, 24 May 2023 15:34:21 +0000 (UTC) X-FDA: 80825545122.24.8A70830 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 885AD40016 for ; Wed, 24 May 2023 15:34:19 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VoNrEJou; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684942459; a=rsa-sha256; cv=none; b=k60e7KBfiundhwt6ay1uPsvkdQcJR/Vi6JIwGoD8FkZGb5M4CCgc35MsK0P+sWFucdxQno trXTEE7U+LI6PD5BVmb6hmgSsbTnSNiqv1aPdtslHmsEW8LJV5CsfJ63pERZ/bsRBb9u5S PDLhUJHphcIKDAxVi1Hsi658mzVZgsk= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VoNrEJou; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf12.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1684942459; 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=E1PF2dIIOP/VptjcBGEUgdHYPyQQ9EA3G7wUORmRH+w=; b=k3qEY8ylOxonNlQMOwTuuQ4wAh1I720Mx2PEca08+es8sbvtoTCQYBPRd1qt0V0o/VMhkB DiYrN8jU2p0pwwRZgeV625wWf4nEz/bcM35ByICDB4A6zLQ9nZMjvfyFGBNmUEisxpks8T uYMGfoyxqUdXYuKtHbQfGp8wXXUTTyY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1684942458; 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=E1PF2dIIOP/VptjcBGEUgdHYPyQQ9EA3G7wUORmRH+w=; b=VoNrEJouLUbgpU8tQUrwgIhCrVSTsUsVu3wKb/jVX/l3K1P9XDYIwFL/wW/d6IaGxmXJQl +tycxZO5r+OZ39qhn9BlAwFiTGddTr3MOk2klp1Ln3cnOAQHTK1UmYqeV8sHVaaR+6w+/Y TjauGB3VvdDrVGCrtcYybpe/vokg8/A= 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-237-qbT634KSMquY-3XAUHekDg-1; Wed, 24 May 2023 11:34:16 -0400 X-MC-Unique: qbT634KSMquY-3XAUHekDg-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 18F5B3C0F24B; Wed, 24 May 2023 15:34:11 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.39.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D91C2166B25; Wed, 24 May 2023 15:33:52 +0000 (UTC) From: David Howells To: netdev@vger.kernel.org Cc: David Howells , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Willem de Bruijn , David Ahern , Matthew Wilcox , Jens Axboe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Chuck Lever , Boris Pismenny , John Fastabend Subject: [PATCH net-next 11/12] tls/device: Support MSG_SPLICE_PAGES Date: Wed, 24 May 2023 16:33:10 +0100 Message-Id: <20230524153311.3625329-12-dhowells@redhat.com> In-Reply-To: <20230524153311.3625329-1-dhowells@redhat.com> References: <20230524153311.3625329-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 885AD40016 X-Stat-Signature: oddg6qbij3ygq9hq7xj5i39zexb8iogf X-HE-Tag: 1684942459-519360 X-HE-Meta: U2FsdGVkX1/vSSu6g6SlC/2cdeYL0zgb6dDV95RNhEiSbYYsV+SDGvLzTd6StwLrxcM/9tDiRHA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9D1JbZO3SdusK8XqfqQba16o14fcGkpZMmcz6fUq4znDbVteMAa6A0dS5vAVc0V4bQRyJYv0kx4ibMWXGiat2eXcQLMuaGxKa0gxzErA6/QM92pzw3F82orPnTN2LFNmtIwb+BT3ala+pzb92fGIdughBKXM0qjyt/RLOrhWCOc0ZgYsZydUbKejro+np3zJ9Bv/jBnIX3iI3TOXgkXEJT/BRke9BXkoEMCmr71X60ClTZfT+eobeIj2WezF8dJ6b1R41mlxZQYneBzgKXAUu1bl6gtfr7Xrv3wNU3Bu3+BKAwmw94rQUN4TkhBXTOdqTrp7DRHPIjMMbfX/txz3jpdw6aYEOe6k9FfRKASNNGVDhWEVi75wVfdgtTaeo5E6WqhF84metRat2S3ZstLRDQ1bg310QbQ== 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 and copied the data if not. 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 daeff54bdbfa..ee07f6e67d52 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -508,7 +508,30 @@ 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 (!sendpage_ok(zc_pfrag.page)) { + iov_iter_revert(iter_offset.msg_iter, copy); + goto no_zcopy_this_page; + } + + zc_pfrag.offset = off; + zc_pfrag.size = copy; + tls_append_frag(record, &zc_pfrag, copy); } else if (copy) { +no_zcopy_this_page: copy = min_t(size_t, copy, pfrag->size - pfrag->offset); rc = tls_device_copy_data(page_address(pfrag->page) + @@ -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);