From patchwork Wed Apr 5 16:53:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13202272 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 7684CC761AF for ; Wed, 5 Apr 2023 16:54:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB13B6B0092; Wed, 5 Apr 2023 12:54:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D60E36B0093; Wed, 5 Apr 2023 12:54:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C022F6B0095; Wed, 5 Apr 2023 12:54:44 -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 AF9C56B0092 for ; Wed, 5 Apr 2023 12:54:44 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9147980399 for ; Wed, 5 Apr 2023 16:54:44 +0000 (UTC) X-FDA: 80647936488.16.8544C04 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf24.hostedemail.com (Postfix) with ESMTP id A3338180011 for ; Wed, 5 Apr 2023 16:54:42 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gbMHLpA1; spf=pass (imf24.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=1680713682; a=rsa-sha256; cv=none; b=nIBPbKiKLGUdaxDqaQLRXGKL2iNIjacEfzBX2EPk8fVKHr2tbUXlvaqUgFvvYb0o7YDM7T pLQsqgpHRFu0bX2NJx/w5vfbFGAQxFQlJHSRUe7xz6OVlQ6hl73f4mwqB8hllaQRi8tPtV xNNk5j9NRcGiYcBfKdISM5ZPp/5vXCU= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=gbMHLpA1; spf=pass (imf24.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=1680713682; 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=/JFI/23Tc+s/ig3NV2/20J93ojirddDNW00qNvViyfU=; b=MKIcD4z/XMwcjqk2f0a8/vNilrQbnOot0L6Tu2UbOlHp9UlEeBz8ZostKM0UclhoSZ45Hf iceoaXq64maXjvlmjr5aDZjf7U0FV0BEVrOeOlyac07bvFiwnAE3zPUUCzIs8NcTBJ8FOr eDvRt8v0ekQFC2cQ/cov1pcF78bInho= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680713682; 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=/JFI/23Tc+s/ig3NV2/20J93ojirddDNW00qNvViyfU=; b=gbMHLpA1JUSgpEW0PJ5unzf0Ye3QBux5eb2Yr9AU9Q66j5cuLIUbLRd0Et/snHA5n8iQqo TOuKkJ9+o9Ha3iye4iOW5voOTmce8SPT/0LMkMilCvavW6GAyKmdSfTM7utbSIlnxfORQF ZUzOykAF+9PrE8jGehzqZrBgIjZjyJQ= 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-456-mGoavVuyPK63hF6pFvfXqA-1; Wed, 05 Apr 2023 12:54:37 -0400 X-MC-Unique: mGoavVuyPK63hF6pFvfXqA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B5FED101A531; Wed, 5 Apr 2023 16:54:36 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id B22C6C1602B; Wed, 5 Apr 2023 16:54: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 Subject: [PATCH net-next v4 18/20] ip6, udp6: Support MSG_SPLICE_PAGES Date: Wed, 5 Apr 2023 17:53:37 +0100 Message-Id: <20230405165339.3468808-19-dhowells@redhat.com> In-Reply-To: <20230405165339.3468808-1-dhowells@redhat.com> References: <20230405165339.3468808-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspam-User: X-Rspamd-Queue-Id: A3338180011 X-Rspamd-Server: rspam01 X-Stat-Signature: 8oi55c55g56qgmcco14c759stokcjcx9 X-HE-Tag: 1680713682-240293 X-HE-Meta: U2FsdGVkX1+d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M+1QsgExQoE8AbScQFBZ8HjWsqzZGCAWCaF+8zp8cdqFOA4vWrpbeZyLZagkNxCgY1MheWaiRn7nfoqFa13Jh23zGjMa6fp43sWEpzOHP4n7h+Jb0UPZYGQnxEROn+60+309AdQICI7ndRmXCS/b2YbfRIG2qaj2vlxKvZerpoc7hchsXKy9vVfNe4kRwejG7a6Rq8wjQTvRs9DAx7kXqfNw2i9fCEFzCAbAGDY0nn6IEi1K6vIQadrvJsE6WHHsQMuORAlBkZAn3DT7Odg049LM6m7hPFLE2rUymee/QMRksPaGKi0XmTS0RYFU8T1In/zXFfOAoF5Ljf3lX8nno2F58FyCgU8YQvUcI6tcMoxhD7Y490o8Ev4qdxhgJOzz4SRlwCWEz/rVi/DaFXxH47o8kBEyN1kRVK1lNs0XZZ7NoeMiIQ== 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 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 7627a4df893b..8a50341007bf 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 e34c86b1b59a..241a78d82766 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;