From patchwork Thu Apr 6 09:42:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13203062 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 9335DC77B6C for ; Thu, 6 Apr 2023 09:43:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 348EE6B0099; Thu, 6 Apr 2023 05:43:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2D1E56B009A; Thu, 6 Apr 2023 05:43:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14A276B009B; Thu, 6 Apr 2023 05:43:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 036CD6B0099 for ; Thu, 6 Apr 2023 05:43:44 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C93941A0F0D for ; Thu, 6 Apr 2023 09:43:43 +0000 (UTC) X-FDA: 80650479126.27.34BEF3D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 2F9B514000F for ; Thu, 6 Apr 2023 09:43:41 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dv5iGZgr; spf=pass (imf09.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1680774222; 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=DdOAoT9+lQC5BMkbFi+53knWSKBAKQi3HhFM4xBQ4Wc=; b=Ng4JAqYXDr66SHorL3TY48WUSNGkfdT7u2sF0QtRS4SvDWbHlD/hDskadwxeIaUG6uC+kp m/Uu4+ZrC+afpyWwfE/symS6IrwymzFSC7iOrsyaygsIDkvu7zbf72h6XOePR9cGiiNAfj 6/FPaAKeGYWeHA2dmFfEr8HASplb9Sk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dv5iGZgr; spf=pass (imf09.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.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=1680774222; a=rsa-sha256; cv=none; b=HRGH4W00uxI5eGwBGHtC4MXfyvaUcv0CuhQkgC9wegEcqk33fhqfm0pBKD1F1O22oKHcv0 vpFiWEv/KYj7LWWN1e5eAv3eK7RbQIj5JWjMLPgpOzRH4ltfeM8oIWjjle3PCYzHc422kG 666iR6AbSvfm/PFS8xydcSwkIZlW4as= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680774221; 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=DdOAoT9+lQC5BMkbFi+53knWSKBAKQi3HhFM4xBQ4Wc=; b=dv5iGZgrw5wCF7hFyQKCQ0Ana1KfaxruRxMp5CvhHybZuppL8Qb2egU0iOGQ2jpoW4CGct ToLeAySH80EyGnlImnJi5E2i/w9otnl8d0AmyFGNiqXvp7N0UJajLiQeEmlE7HLQ94wgr3 mhDWiIzgWZdEeiJ4JF6i21v1IsQPuwA= 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-245-8xTpgCDVMpmC5orYHYQeQw-1; Thu, 06 Apr 2023 05:43:37 -0400 X-MC-Unique: 8xTpgCDVMpmC5orYHYQeQw-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 88C731C068E1; Thu, 6 Apr 2023 09:43:36 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79E6B2166B26; Thu, 6 Apr 2023 09:43:34 +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 , Matthew Wilcox , Al Viro , Christoph Hellwig , Jens Axboe , Jeff Layton , Christian Brauner , Chuck Lever III , Linus Torvalds , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, David Ahern Subject: [PATCH net-next v5 15/19] ip6, udp6: Support MSG_SPLICE_PAGES Date: Thu, 6 Apr 2023 10:42:41 +0100 Message-Id: <20230406094245.3633290-16-dhowells@redhat.com> In-Reply-To: <20230406094245.3633290-1-dhowells@redhat.com> References: <20230406094245.3633290-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: rspam04 X-Rspamd-Queue-Id: 2F9B514000F X-Stat-Signature: xzphk9rhzygbk6w1bop4n315u1aj6ymq X-HE-Tag: 1680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vIZ65+RhHjfqMNBihk3SOaJJmIKXCTAMu58hx4biodsAleNajoFKXCejQnM5g6UUA63CcO7TAWf28f6pAvAnoqxYLNBXAV4nNeN8+Lv9JK3Ms2OeFQACh6USxWg16Quq31STmiTUhcoUSu6Zn32jN3vW4sZ4A3EohBWQkzw168Y9FR5UX+4kF3WfbsdQvbgRENoJq0moT9BuOsl+G7AfKGqVHkNbslwIwArXKifFB8h9jQv6HpcWR/uk++UDjMTp6HgqvUttQmZ3IRfaLtTm/1XqEsXmORf7ubVrAtb8gjy6JN2KUOu2JXifAWCO1BAe/148+qqkLuDJn+EECD64KtTgWpY9UwJafdPSseyf0l9S/lz4OP1ce/CdIsly21aeYADjMakRM+ekvBP+s52Dj31uvRkLPHH3Nu2htxuykAXPS9OgZMpKuADTqaFCbnMevscXOeTw== 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 IP6/UDP6 sendmsg() support MSG_SPLICE_PAGES. This causes pages to be spliced from the source iterator if possible, copying 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: Willem de Bruijn cc: David Ahern cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: Jens Axboe cc: Matthew Wilcox cc: netdev@vger.kernel.org --- include/net/ip.h | 1 + net/ipv4/ip_output.c | 4 ++-- net/ipv6/ip6_output.c | 12 ++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/net/ip.h b/include/net/ip.h index c3fffaa92d6e..dcbedeffab60 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -211,6 +211,7 @@ int ip_local_out(struct net *net, struct sock *sk, struct sk_buff *skb); int __ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl, __u8 tos); void ip_init(void); +int __ip_splice_pages(struct sock *sk, struct sk_buff *skb, void *from, int *pcopy); int ip_append_data(struct sock *sk, struct flowi4 *fl4, int getfrag(void *from, char *to, int offset, int len, int odd, struct sk_buff *skb), diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 48db7bf475df..5b66c28c2e41 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -960,8 +960,7 @@ csum_page(struct page *page, int offset, int copy) /* * Add (or copy) data pages for MSG_SPLICE_PAGES. */ -static int __ip_splice_pages(struct sock *sk, struct sk_buff *skb, - void *from, int *pcopy) +int __ip_splice_pages(struct sock *sk, struct sk_buff *skb, void *from, int *pcopy) { struct msghdr *msg = from; struct page *page = NULL, **pages = &page; @@ -1010,6 +1009,7 @@ static int __ip_splice_pages(struct sock *sk, struct sk_buff *skb, *pcopy = copy; return 0; } +EXPORT_SYMBOL_GPL(__ip_splice_pages); static int __ip_append_data(struct sock *sk, struct flowi4 *fl4, diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index 0b6140f0179d..82846d18cf22 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1589,6 +1589,14 @@ static int __ip6_append_data(struct sock *sk, skb_zcopy_set(skb, uarg, &extra_uref); } } + } else if ((flags & MSG_SPLICE_PAGES) && length) { + if (inet_sk(sk)->hdrincl) + return -EPERM; + if (rt->dst.dev->features & NETIF_F_SG) + /* We need an empty buffer to attach stuff to */ + paged = true; + else + flags &= ~MSG_SPLICE_PAGES; } /* @@ -1778,6 +1786,10 @@ static int __ip6_append_data(struct sock *sk, err = -EFAULT; goto error; } + } else if (flags & MSG_SPLICE_PAGES) { + err = __ip_splice_pages(sk, skb, from, ©); + if (err < 0) + goto error; } else if (!zc) { int i = skb_shinfo(skb)->nr_frags;