From patchwork Fri Mar 31 16:08:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13196178 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 7FA04C77B62 for ; Fri, 31 Mar 2023 16:10:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C5A616B0092; Fri, 31 Mar 2023 12:10:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BBA5B6B0093; Fri, 31 Mar 2023 12:10:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A81C96B0095; Fri, 31 Mar 2023 12:10:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 95D456B0092 for ; Fri, 31 Mar 2023 12:10:16 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5E9FF80473 for ; Fri, 31 Mar 2023 16:10:16 +0000 (UTC) X-FDA: 80629680432.11.75BF17D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 9BA621C0010 for ; Fri, 31 Mar 2023 16:10:14 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RtCSvynC; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.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=1680279014; 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=3uNZWqu+MQKIO3OTB8U4ZJVMqWS1JR9mPIUS8nXZLn4=; b=wOPOpljo5vRqfsY3A3MLgRXpulgJxY2Yc2v3g12OMRrYUPeTYhzmvKmdoGXVRnMQcvTFRy vrIAd/ZdiWKYHnF+zF7zyhBIgIGnuMbzbT/cxVV/n6maXGPHfEzn08k4MKNXcoSlTgCT/T MlXdFOMCgndAaoNhSA//LzCeLuKWefo= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RtCSvynC; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.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=1680279014; a=rsa-sha256; cv=none; b=rduY7GAb5l+YCTF5jda4EUsTJEe6zhtVYX1l5gAZCeSkZ6OfeXMKsUny4SLcfIJFsHgL4R 1ilQZUu1/afpWiAyDoAnCYgyYIJsE60c+gIPdF9Bso9b1lIXUefNjWGx3G+/ATAV/JqKis iMIr8gmCn1hMtGMOePa63u1kf5V23U4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680279014; 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=3uNZWqu+MQKIO3OTB8U4ZJVMqWS1JR9mPIUS8nXZLn4=; b=RtCSvynC3uKTYhNIDtyC0SGMwicXgrlO3b/z+o5L6b0hZ/r9yOX7anYNZDhcRC2O1VA9rN hIQQzFm+iQZDTXA/FA6lPPl0o6BRleyHAdmMGrnCdfcLwWFcQUSBHaL99LEAt02WjNBNpX TEVPF8pg8nBKNKTg5wC0FuX6Sg1dgw8= 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-635-jQiJhrbpN_2494oFduAemA-1; Fri, 31 Mar 2023 12:10:10 -0400 X-MC-Unique: jQiJhrbpN_2494oFduAemA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 66A7829ABA23; Fri, 31 Mar 2023 16:10:09 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B0F74020C82; Fri, 31 Mar 2023 16:10:07 +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, Willem de Bruijn Subject: [PATCH v3 17/55] ip6, udp6: Support MSG_SPLICE_PAGES Date: Fri, 31 Mar 2023 17:08:36 +0100 Message-Id: <20230331160914.1608208-18-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.2 X-Rspamd-Queue-Id: 9BA621C0010 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: kckusejisijqafng51uxk4uy6xtz7ijf X-HE-Tag: 1680279014-823703 X-HE-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rGMAHib6AQuceO97bVvNlp8mxY9CzhW/f45L/uEuC6a5mGj2i+gHChLXdHuj/ik4BHkuSJhHOhg8mzS5fAO4zEzZxIvMfLL5e0C6i8PK0Nvx+EC1t2KBowreC3v0qbIuzLtPXFJZbFpFWmBIA0nVzy/xHnbeDAL+kIkeFbaie010K4+Me6StmdrviUTFn5WdSedXM8s3sFIiCnw+FND/dBR/C8H5BwPngZsO+dkCYe2z9+sRcz7jPm94Ksk6Add6Y7TXnGFobb8ciTUvfgn/41c9IxFSa6uTdrq/jAuRxc208xsL79FwQBwHC54rq+auNXUQSKYOcjKa3w8CAoflY5hS1XpnqpXeDyLSx4NtW1uSeop3VkmPmwDaQvxIqojsrhv8kp0hVJ5L76dT0QO18nCattZq0WkdceZJECm7TMI7h4B6l90DQ8q/BTvO1msaz0t7E+6QA== 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 | 4 ++++ net/ipv4/ip_output.c | 11 ++++++----- net/ipv6/ip6_output.c | 28 +++++++++++++++++++++++++--- 3 files changed, 35 insertions(+), 8 deletions(-) diff --git a/include/net/ip.h b/include/net/ip.h index c3fffaa92d6e..e27d2ceffcfa 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -211,6 +211,10 @@ 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_alloc(struct sock *sk, struct sk_buff **pskb, + unsigned int fragheaderlen, unsigned int maxfraglen, + unsigned int hh_len); +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 41a954ac9e1a..fa2546d944bc 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -959,9 +959,9 @@ csum_page(struct page *page, int offset, int copy) /* * Allocate a packet for MSG_SPLICE_PAGES. */ -static int __ip_splice_alloc(struct sock *sk, struct sk_buff **pskb, - unsigned int fragheaderlen, unsigned int maxfraglen, - unsigned int hh_len) +int __ip_splice_alloc(struct sock *sk, struct sk_buff **pskb, + unsigned int fragheaderlen, unsigned int maxfraglen, + unsigned int hh_len) { struct sk_buff *skb_prev = *pskb, *skb; unsigned int fraggap = skb_prev->len - maxfraglen; @@ -993,12 +993,12 @@ static int __ip_splice_alloc(struct sock *sk, struct sk_buff **pskb, *pskb = skb; return 0; } +EXPORT_SYMBOL_GPL(__ip_splice_alloc); /* * 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; @@ -1047,6 +1047,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 c314fdde0097..c95d034cb45a 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1486,7 +1486,7 @@ static int __ip6_append_data(struct sock *sk, struct rt6_info *rt = (struct rt6_info *)cork->dst; struct ipv6_txoptions *opt = v6_cork->opt; int csummode = CHECKSUM_NONE; - unsigned int maxnonfragsize, headersize; + unsigned int maxnonfragsize, headersize, initial_length; unsigned int wmem_alloc_delta = 0; bool paged, extra_uref = false; @@ -1559,6 +1559,7 @@ static int __ip6_append_data(struct sock *sk, rt->dst.dev->features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM)) csummode = CHECKSUM_PARTIAL; + initial_length = length; if ((flags & MSG_ZEROCOPY) && length) { struct msghdr *msg = from; @@ -1589,6 +1590,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 */ + initial_length = transhdrlen; + else + flags &= ~MSG_SPLICE_PAGES; } /* @@ -1624,6 +1633,15 @@ static int __ip6_append_data(struct sock *sk, unsigned int fraggap; unsigned int alloclen, alloc_extra; unsigned int pagedlen; + + if (unlikely(flags & MSG_SPLICE_PAGES)) { + err = __ip_splice_alloc(sk, &skb, fragheaderlen, + maxfraglen, hh_len); + if (err < 0) + goto error; + continue; + } + initial_length = length; alloc_new_skb: /* There's no room in the current skb */ if (skb) @@ -1642,7 +1660,7 @@ static int __ip6_append_data(struct sock *sk, * If remaining data exceeds the mtu, * we know we need more fragment(s). */ - datalen = length + fraggap; + datalen = initial_length + fraggap; if (datalen > (cork->length <= mtu && !(cork->flags & IPCORK_ALLFRAG) ? mtu : maxfraglen) - fragheaderlen) datalen = maxfraglen - fragheaderlen - rt->dst.trailer_len; @@ -1672,7 +1690,7 @@ static int __ip6_append_data(struct sock *sk, } alloclen += alloc_extra; - if (datalen != length + fraggap) { + if (datalen != initial_length + fraggap) { /* * this is not the last fragment, the trailer * space is regarded as data space. @@ -1778,6 +1796,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;