Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1302362rwl; Fri, 31 Mar 2023 09:13:53 -0700 (PDT) X-Google-Smtp-Source: AKy350ZSwtXTBMmKIQMGsgAD0VJmhmdZAPu70u2wTzG+FUpi0iHyRs5JZABMsUUfjmRYLnCo4sJo X-Received: by 2002:a05:6a20:8e07:b0:cd:2c0a:6ec0 with SMTP id y7-20020a056a208e0700b000cd2c0a6ec0mr8363256pzj.3.1680279233401; Fri, 31 Mar 2023 09:13:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680279233; cv=none; d=google.com; s=arc-20160816; b=VpYnY9O+6HbnYL1ocRQ7u2oB9lBaJFjv8FD4LsnLG+FdivJP+8NNO3JRqYAmi78nQh HmQ1QI7jwTrUkl2ch6LUlPj/Hx7s3DXH8WIFBdNjVbJanofSmHPHXDwBt3svcM1V/BFz FN+gN05ag7GzWqvqMW0SbfXiZhcLnb8gQk6L+MFtb9iBvt+NXiH2REak+DESqGQPaBpl lM1th9uGBH2RZWppnj41Mcmrb4S5k250EMVrC5vNi72BhpaqNgIZjNjzFcROei+rlgIg V7v3GJcdPvP1yOAu/qHKg98EwqsiHb+b4OAJMYFGJIBt05lrsuqKo+MocoKsHpDjiWuP 3Urg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3uNZWqu+MQKIO3OTB8U4ZJVMqWS1JR9mPIUS8nXZLn4=; b=E+O+lXV+HNHwHB3nrCHQc7X2ZII8c31nfJVwySL63oWBLFn1z9NelihpYEpPwNJtgz 0beBI64RlouiM3J/1bGYhMppeH5oMw3/zfmSYkqMrINp6DRyU472nuR7RzPqL4jKWOdY cQpckVVBkWWCOksTIy0aAzkrCh/rjJ/ImazuLn8wWOsSW1jKFomdmrqBKzH5F3Trsgnr D6c8WSS+DHvIBlcO1Iu/S+lrEVFHO0yJcmtayPIfLYqyl7rRoDEScGFgibZ8EHsOwR1P Cz5My3T3OGqaZwVn/Y5szb5p4uZpUXid3ZeP7qawbSOIXJEFYzpdioHMKwSjEva4D5Jo pEcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U+7Jfq5Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s128-20020a625e86000000b00627fd9b86ccsi2869966pfb.136.2023.03.31.09.13.40; Fri, 31 Mar 2023 09:13:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=U+7Jfq5Z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233260AbjCaQM4 (ORCPT + 99 others); Fri, 31 Mar 2023 12:12:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233033AbjCaQLy (ORCPT ); Fri, 31 Mar 2023 12:11:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B93452290C for ; Fri, 31 Mar 2023 09:10:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680279013; 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=U+7Jfq5ZuKrCpPxiJXNUrOqO1DlQxtLQ/IPbl9ePSHNc98ifd7EU2W2w1PPkHHlr8vl5gy G0FsrfA/SE/kjcsTtSQ3YjKlfUhHlcI+kQta3L8S55GKqmej1E2BbJQ/h4i9sK7OmACWpq +d775q+uLQlUEYCXG/SL6f4bWsiQTeY= 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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;