From patchwork Fri Mar 31 16:08:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13196192 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 5A2DBC761A6 for ; Fri, 31 Mar 2023 16:10:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC86C6B0099; Fri, 31 Mar 2023 12:10:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E79026B00A2; Fri, 31 Mar 2023 12:10:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D40B36B00A5; Fri, 31 Mar 2023 12:10:56 -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 C55D16B0099 for ; Fri, 31 Mar 2023 12:10:56 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9A1741A0D0B for ; Fri, 31 Mar 2023 16:10:56 +0000 (UTC) X-FDA: 80629682112.18.EC8270F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 2E15540021 for ; Fri, 31 Mar 2023 16:10:52 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EsCK6a1W; spf=pass (imf12.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680279053; a=rsa-sha256; cv=none; b=AN+nG/rx2WEj2qRn6o6cuf37iNl8Q6EigGlCa8aFFyXi1L8M8ORNq4jFRDJKnBmVZDednb yhQKXEMK2X/2mnFN5e0ppePlMagS6ENG4u5sQToxl/cJRmYOexfq/S0DhTF3cLJtLrrwv/ HzJ6Eyr6wuUYj23W8Nd6i/aousPAY8w= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EsCK6a1W; spf=pass (imf12.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680279053; 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=wy1bl7/wKEZT2hBAqmE7Plq7HNXSqd6J/GoEc2iata8=; b=Iku/3A5NpfyH5d9L6v+QQRvy0KUoP7tzyuuumEIYGkNIgzH06AdC45BiF8ywIop5/oB/+p pMBwx8/VJDRPNcxSWD0zEGl9sK6Cw42kMmJCxUnmgpgW7sTrj0St2zAaLQfmoeOrxqnldD nkBkZcrdAWJc1s++ljJBVyWI9ZHPuus= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680279052; 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=wy1bl7/wKEZT2hBAqmE7Plq7HNXSqd6J/GoEc2iata8=; b=EsCK6a1W+nKFEWwKCpVDu3Olg2rwtNfzxRWTBVUhccMbS461Z0aIdpDQxWHR27/5OGHwo8 hr/TznEJdbMc/DfqvJW6Ig4G+TC9/F506JNsmvgTAVSG3N074wqUbkYLKpa7VXlqlLcG+D XACZVCUIF/x9hTLw6NZiWfnyHho3b/4= 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-408-TWrdWqY9OgKCvKHcSyW2Nw-1; Fri, 31 Mar 2023 12:10:48 -0400 X-MC-Unique: TWrdWqY9OgKCvKHcSyW2Nw-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 1E33329ABA17; Fri, 31 Mar 2023 16:10:47 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 223762166B33; Fri, 31 Mar 2023 16:10:45 +0000 (UTC) From: David Howells To: Matthew Wilcox , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: David Howells , Al Viro , Christoph Hellwig , Jens Axboe , Jeff Layton , Christian Brauner , Chuck Lever III , Linus Torvalds , netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Ayush Sawal Subject: [PATCH v3 31/55] chelsio: Support MSG_SPLICE_PAGES Date: Fri, 31 Mar 2023 17:08:50 +0100 Message-Id: <20230331160914.1608208-32-dhowells@redhat.com> In-Reply-To: <20230331160914.1608208-1-dhowells@redhat.com> References: <20230331160914.1608208-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspam-User: X-Rspamd-Queue-Id: 2E15540021 X-Rspamd-Server: rspam01 X-Stat-Signature: msyrxf9cjuyddoqqocuonao1n9ne7wid X-HE-Tag: 1680279052-319480 X-HE-Meta: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+6skSuRELvuGpyK/48VxuwFzU4gZ5CknJ0ZtDTyJlJJN9rSOF+tmlB6IRLPOnqeS0kAXWuN5I6nysVLsaCd5x0xqkEH86hy8BGQgpCh/AaCe3s/wJ6eSUYrseDIn0X95x6jorswCMtKPyic7M8sXdLsW3AL6Zk4mdJGqjRQ2EPEetXp15sqXea61ICKdr8ccCiN+urkbQSDWpjohhzNixCcuoM9eIj08+7nPXVMoaVYGXHLXRCK+X80xFRA5C7XJ9RUSD6L94zBOZH80LNZQxR9tHZ98NdtVLTDDGT0+dVvKKG1nsvoL5JGdeD26ISaayu4/w5bp59Qw25q6xn8h1YUWdPBlI8gUsVxRwc6ws7x8rwFwxysdrYKvLsiNdlCyI3TIlKvoJL50WfjG3TQOfjog== 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 Chelsio's TLS offload sendmsg() support MSG_SPLICE_PAGES, splicing in pages from the source iterator if possible and copying the data in otherwise. This allows ->sendpage() to be replaced by something that can handle multiple multipage folios in a single transaction. Signed-off-by: David Howells cc: Ayush Sawal cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- .../chelsio/inline_crypto/chtls/chtls_io.c | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_io.c b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_io.c index ae6b17b96bf1..ca3daf5df95c 100644 --- a/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_io.c +++ b/drivers/net/ethernet/chelsio/inline_crypto/chtls/chtls_io.c @@ -1092,7 +1092,65 @@ int chtls_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) if (copy > size) copy = size; - if (skb_tailroom(skb) > 0) { + if (msg->msg_flags & MSG_SPLICE_PAGES) { + struct page *page, **pages = &page; + ssize_t part; + size_t off, spliced = 0; + bool put = false; + int i; + + do { + i = skb_shinfo(skb)->nr_frags; + part = iov_iter_extract_pages(&msg->msg_iter, &pages, + copy - spliced, 1, 0, &off); + if (part <= 0) { + err = part ?: -EIO; + goto do_fault; + } + + if (!sendpage_ok(page)) { + const void *p = kmap_local_page(page); + void *q; + + q = page_frag_memdup(NULL, p + off, part, + sk->sk_allocation, ULONG_MAX); + kunmap_local(p); + if (!q) { + iov_iter_revert(&msg->msg_iter, part); + return -ENOMEM; + } + page = virt_to_page(q); + off = offset_in_page(q); + put = true; + } + + if (skb_can_coalesce(skb, i, page, off)) { + skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], part); + spliced += part; + if (put) + put_page(page); + } else if (i < MAX_SKB_FRAGS) { + if (!put) + get_page(page); + skb_fill_page_desc(skb, i, page, off, spliced); + spliced += part; + put = false; + } else { + if (put) + put_page(page); + if (!spliced) + goto new_buf; + break; + } + } while (spliced < copy); + + copy = spliced; + skb->len += copy; + skb->data_len += copy; + skb->truesize += copy; + sk->sk_wmem_queued += copy; + + } else if (skb_tailroom(skb) > 0) { copy = min(copy, skb_tailroom(skb)); if (is_tls_tx(csk)) copy = min_t(int, copy, csk->tlshws.txleft);