From patchwork Wed Apr 5 16:53:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13202269 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 B027FC761AF for ; Wed, 5 Apr 2023 16:54:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D9616B0071; Wed, 5 Apr 2023 12:54:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4AE9C6B008A; Wed, 5 Apr 2023 12:54:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 376E36B008C; Wed, 5 Apr 2023 12:54:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 29AD76B0071 for ; Wed, 5 Apr 2023 12:54:39 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0E2661A0C54 for ; Wed, 5 Apr 2023 16:54:39 +0000 (UTC) X-FDA: 80647936278.02.6D1C618 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 63510100002 for ; Wed, 5 Apr 2023 16:54:37 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UagTwg0I; spf=pass (imf14.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=1680713677; 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=4sRhyVsK/d5pgFDi65Wlb3WXN0jzDUhNbeQVzVbMamI=; b=gSLECFZZQDXCZDzd9P1h+ugz4Ssf7MjfqD9hoXqjJQfjWbxMXx2EQPta5+mSZ+u4GpAM1V WRKergwbhSohjaFmkJcyOVBlhxyaAMB67oWbUaKZiV8SNnqMi+0NsXL+dmcdC33YA03T9q nTAN5vV20+8xMC2zlakPPB+XhyAiay0= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UagTwg0I; spf=pass (imf14.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=1680713677; a=rsa-sha256; cv=none; b=Eq8o8Wi73KjFqZDkrINAnHz6BoGCUHrRe5IYaYb/64CJynqPZIkW0QKO029+sfMhj0F7uk l+utrOaOaE7kR4/+7VxQHbTO6rnb+j+r3s9OJqZU38Mz1BspzrWanVQZUOzOKNikrRrLzn r7rtWxUrlw1YsH7jYxcFFXiu3F/kZVo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680713676; 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=4sRhyVsK/d5pgFDi65Wlb3WXN0jzDUhNbeQVzVbMamI=; b=UagTwg0I7GGktVxFCC7PJZWJ2TnsjT3tRAzFRAPEXYwwoZSyS/ntOwOma2xhYP3xqGOj2z D7rKFZhkWmG3rPe1p6jbxMIm16Rhf/8opQb85xgPTWv8TSFaGLfkzvjlyKdkL5l9b668uR +PFToqVA45WCXDcwuEVFvKduluHK2J4= 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-68-CiPL6DpHNz2kv6EGD8VAcQ-1; Wed, 05 Apr 2023 12:54:32 -0400 X-MC-Unique: CiPL6DpHNz2kv6EGD8VAcQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 610BD185A78B; Wed, 5 Apr 2023 16:54:31 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F30A1121314; Wed, 5 Apr 2023 16:54:29 +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 16/20] ip, udp: Support MSG_SPLICE_PAGES Date: Wed, 5 Apr 2023 17:53:35 +0100 Message-Id: <20230405165339.3468808-17-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.3 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: 3pi7uorjhdegapzfmnsz6sqjkakot3ch X-Rspamd-Queue-Id: 63510100002 X-HE-Tag: 1680713677-44759 X-HE-Meta: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yLcNGw0Ld69MluiPu2/EzhsXRN5lfeBgekrSKa2l67tLSbd+LFzBev429691vhlghCy0V0798JROFPSkIhm9PnnEFZBaYZOmdbGrUCsHqWcLOq2OaLhrsfSQ5jF343e4SVIdsbHXWR6Easc5kTLv+thX4liha/Tbhw2GCfKAIOYofnKlyHDt2SvOG/Uj8IAZWTxMDvwZmzVIK3BZWP0QXLtsYozZwO9lN1bHNDV6Pw3Z+V6Gne09uxbdRvq5Cxk3q7CAqYXjs+ChZ3Y7pZujA4dFJe3MQOqArZwDbcMQ+/3lo17b0nkJbHwUjfiakvt3/bunVNehR5yGqSPVOzEV0ExsW8h/R6g7H80pXwXQTa+hI6XV1ORhrwr5gl7x5KCjogERhp53I+TYzSuRzOI20xtf/sMc2904NQYvlGd3CxgSuSn5w2ix4nooWqItUYFng== 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 IP/UDP sendmsg() support MSG_SPLICE_PAGES. This causes pages to be spliced from the source iterator. 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 --- net/ipv4/ip_output.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 2dacee1a1ed4..13d19867ffd3 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -957,6 +957,41 @@ csum_page(struct page *page, int offset, int copy) return csum; } +/* + * 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) +{ + struct msghdr *msg = from; + struct page *page = NULL, **pages = &page; + ssize_t copy = *pcopy; + size_t off; + int err; + + copy = iov_iter_extract_pages(&msg->msg_iter, &pages, copy, 1, 0, &off); + if (copy <= 0) + return copy ?: -EIO; + + err = skb_append_pagefrags(skb, page, off, copy); + if (err < 0) { + iov_iter_revert(&msg->msg_iter, copy); + return err; + } + + if (skb->ip_summed == CHECKSUM_NONE) { + __wsum csum; + + csum = csum_page(page, off, copy); + skb->csum = csum_block_add(skb->csum, csum, skb->len); + } + + skb_len_add(skb, copy); + refcount_add(copy, &sk->sk_wmem_alloc); + *pcopy = copy; + return 0; +} + static int __ip_append_data(struct sock *sk, struct flowi4 *fl4, struct sk_buff_head *queue, @@ -1048,6 +1083,14 @@ static int __ip_append_data(struct sock *sk, skb_zcopy_set(skb, uarg, &extra_uref); } } + } else if ((flags & MSG_SPLICE_PAGES) && length) { + if (inet->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; } cork->length += length; @@ -1207,6 +1250,10 @@ static int __ip_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;