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: 79821 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp455734vqo; Wed, 5 Apr 2023 10:00:33 -0700 (PDT) X-Google-Smtp-Source: AKy350YNNNQwIdbFrrmUllc608nkiBJujRdBvm98wKDejUqeA0QswaAKh69ylxidrO/EqenDVTM7 X-Received: by 2002:a17:906:cb8c:b0:92f:efdc:610e with SMTP id mf12-20020a170906cb8c00b0092fefdc610emr3925998ejb.66.1680714032799; Wed, 05 Apr 2023 10:00:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680714032; cv=none; d=google.com; s=arc-20160816; b=JNRt1h2McdM5bz2ID5UbXUye6Te4nSFGs4sPdtiO509rICaOhmDzGbdPY21FNxUB/1 HlBEgdPD18IWT9jmBd14oxT/J5FzMPP3Ko2vlkacUbQPMwI1jya+/BfRVvoFu7lXVabd Rmp/qjr33AxYVE4g9pDuX1fZO+ngLMZDfgmvwFGSiHWcCqv57LIw9CCJY5qb1AAdAADJ ctvgEdDLeKNkswe0E2FlaIf4keoTM451/g3FwkOrdVsP34RmVjDtDu1dUcEjrIGhGBbs Bs68NibAaACpPXxifqegykrtG3ed1rHsNweF32Zq4nuxooN9MKiH9TKca7nD//mpZ4Rz Mubg== 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=/JFI/23Tc+s/ig3NV2/20J93ojirddDNW00qNvViyfU=; b=afEbQ+O5uRbQwcF+GKI9zxfUlrXPh/PidHU4DjIY4g3c3afINO9Gyc64EpEBlVXvLT wkVVDk0eqcVO3x/MA2F4OIup53u5p0hPp5+bHYvcU5B2PYAaxUQAl+eiSJLXoShR/8QS pHE4x3oVgF9ObqGEI/sY7tp02ioeXzGMwp0CHMQY4GqJ9DEz6UogJbKGe7P3SGDgZDC3 GSAHhGfEpGVaAf9ob4Mj3vjDrxbsB1hhYi1ATmgM7c+G0EiV/2jMrNMhs6yS37myWvXt H2JHAFKZ5aDM1Ql+RgV98YvNO/c25gI/Q6csdaeUfA8gGHkkOoUs1BlQQjaVu6R/gOhd d9mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=ReqOQhGX; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pk25-20020a170906d7b900b008ca8e21134esi268312ejb.281.2023.04.05.10.00.08; Wed, 05 Apr 2023 10:00:32 -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=ReqOQhGX; 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 S230031AbjDEQ6M (ORCPT + 99 others); Wed, 5 Apr 2023 12:58:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230108AbjDEQ4l (ORCPT ); Wed, 5 Apr 2023 12:56:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F34026EA2 for ; Wed, 5 Apr 2023 09:54:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680713679; 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=ReqOQhGXwcfWg1FfIgVmuPPkkV+IiWeOeLaVuDlhFN0p7Fdafkj3e6ohqH8AQSlOLkxhSp vIvcDCu0fRiEQh3JHfzXucwvmp043i5zEPAMaM1pp6cxPIGxtmpeoISyhKC47SiQqRXxB4 I4AoHBTx1eB1hy26Y9ZWXDFFudLCnOs= 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-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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762356397862011187?= X-GMAIL-MSGID: =?utf-8?q?1762356397862011187?= 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;