From mboxrd@z Thu Jan 1 00:00:00 1970 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 3E5CCC76188 for ; Mon, 3 Apr 2023 22:05:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D262A280003; Mon, 3 Apr 2023 18:05:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CD5CB280002; Mon, 3 Apr 2023 18:05:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9DF9280003; Mon, 3 Apr 2023 18:05:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A9F75280002 for ; Mon, 3 Apr 2023 18:05:08 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7A90BC0B3A for ; Mon, 3 Apr 2023 22:05:08 +0000 (UTC) X-FDA: 80641461096.25.A1C2E83 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id 8C39D100015 for ; Mon, 3 Apr 2023 22:05:06 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QFXApjRz; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.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=1680559506; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=jnFtkoqMUBk9VK4xaDY9JMCyJUvcWn5aEBYFQqTdOKA=; b=UBUrdiizF4vbqncV70rR8BB5asfaV31p7rNKs8fIGSdeAGLu7BPW1pRMboQkiaQXZFfC2g Sre569A6GB7mplWiCzTZ3SeJGvkkF+PF6Q/12Lk6sHuac3Y8pK21EJ21KzNo8gkIApTxo9 6CEFaCzWufQx5u1TxNPlFNCkyhxd4w0= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QFXApjRz; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf14.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=1680559506; a=rsa-sha256; cv=none; b=BME5skEVwUQqY03w6r4/S0XmTZupCy9i5mWgpZWhMp2s4GrN2/25WfqUkqk1HImZH0nAeB b8MLqOZf6Z2xocMMKolOsCetz3o/bH3hZ5S6gnprCnMZfk3P15rY9Z3uW4hO0zUWjlJVAk kjC43OIMv3se8qshK89iLtDbLRa+uNY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1680559505; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=jnFtkoqMUBk9VK4xaDY9JMCyJUvcWn5aEBYFQqTdOKA=; b=QFXApjRznKH8cQhJ8DjD+pr+qGZkmNHVVJv940oS6ZKGeptd/SfKvIDiPoYjwhcxMdecL2 Pa0VvpxdtUg3T6iqXHO9BxmVpdHtoN8Xmoa/PYJOBA0GrCd1mMjgoTYRNusyK8ujoVA57Z 1bakyHUxPgJ+xrIf+LRmrMXXnEqpB9k= 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-529-H5UpbnI2P_GZNe0obnlrBw-1; Mon, 03 Apr 2023 18:05:00 -0400 X-MC-Unique: H5UpbnI2P_GZNe0obnlrBw-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 906571C051A7; Mon, 3 Apr 2023 22:04:59 +0000 (UTC) Received: from warthog.procyon.org.uk (unknown [10.33.36.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4329A1121314; Mon, 3 Apr 2023 22:04:57 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: <642ad8b66acfe_302ae1208e7@willemb.c.googlers.com.notmuch> References: <642ad8b66acfe_302ae1208e7@willemb.c.googlers.com.notmuch> <64299af9e8861_2d2a20208e6@willemb.c.googlers.com.notmuch> <20230331160914.1608208-1-dhowells@redhat.com> <20230331160914.1608208-16-dhowells@redhat.com> <1818504.1680515446@warthog.procyon.org.uk> To: Willem de Bruijn Cc: dhowells@redhat.com, Matthew Wilcox , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , 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 Subject: Re: [PATCH v3 15/55] ip, udp: Support MSG_SPLICE_PAGES MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2258797.1680559496.1@warthog.procyon.org.uk> Date: Mon, 03 Apr 2023 23:04:56 +0100 Message-ID: <2258798.1680559496@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspamd-Queue-Id: 8C39D100015 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 4i3dw6y14zykzm435k68u754o8z1twhr X-HE-Tag: 1680559506-423351 X-HE-Meta: U2FsdGVkX19eec8vxRTdXy5Pn1+mYmbdlWn9Zab2DsjIFfpdiru4QtdVp4Uhdqt95H3WrFzQ8g3kI8WV3bmeo5OrjWgPItHRTo05dOoTz+hTQlgNq56G6t+TK1iu+Qi6NpJz8KS8AHrHSErh8zuIqCWyW5pFfZCbMBXtlKGFrzm8vcQiCV+6OGBvZMQdpDqeS1W4rSx/sQr5ZNVK9t7UhVv+G4kq3TY9iWTzNZZFkHcO9NsYA3AYl0ZjfUCVYv6vPweGHYPL2F6OrXNO88b9f3OIiNx1FYx8jQLROLOQ2Y9sZobbO2/JGKPQBNfg+MYL7yZFoi76z1rxW5SqYNmR+aWtd7ccg0qksu216x6qXx/ArhR0xGytryCjFVjchiAiQrtryIkehxlpl81SeVKAlIij3dbC/t8fOuJJ4fUhmXUxyZx9uiI4/wy69YP907JEuGSKoYrsIz4yu6oENCxV9kB/vpixyu3RRouRYMrDxmY1HolVNt1sIMYpnvrEiypoRB3vArTymDC0AFADnjfg3+rMVR3Wfb7WikOtum7L6Ap9163mSZ+COM41Pf38F1wRdT/T8fwRwa1DBm4ur+ce/+KGu+xStM/4nZipbCeDG9+BUOghTR1RdpY193zpekZCotZJ1v33IR4PyJj6Ek+3AGixKdze888m0lsZR/XUsCS0FhekyK0JqVHoNZr64ZmMg8BQPSeNgA2pdG795c/HjQ5jTk+MDRPENd3u2Qxq5ZR6qd+MAYQL1aa6TRMmCkhYhpZK0ZZEhD4b1AYz70uLqZMv66ESh9xKsT63AUK/pKn8ggJZRMpCk7q+OEPITd1f9muZr4htXDowEVTetUmUYaUJQyDVvPjFys40VuiCLDSuEhPIb2bGkHfTBUURWhpIiwpGtWYPx/+X6rfaR6Dug81wXnnOcmGsddvs9FV+/c2k038z1LRe9r1xzNHMNSWW4A47gQaTVx0IVRmIkqi EO7st4On lp8GfjX1MkfZILXt37plGZiQiqEoZoIUHgM70bGhAd+9hQOyfqLinBVvT1w6v9CjnWiNn+ufLj3eeNQQvWlkmKYHjLEmmS27n6EJ6xA92lzUlP5jx87HYZFkHgFp8BOHjj0A4lIhj8gsd+mSUFBvnCKKeXAARWPFa6/Tvc4WiC1upMvfGAeaAoIJLDJ/yEzH1E66LR7/0qxEnM2FRbgoflz8FvKndMnmetbgVMyrJ3dfXKnGNqgrMweFJbANXboAcb1yA9j1XsYM9xIMF8jtfcHOyKnPCzWhBySDJicp33HMuzf1bQkl9qYgRUb0ygbvzElMSQaeEEzJYCoWmu75bSiO87EYECDZm9I8xB0gaor+z+kRrCfj/UdT9ikPpcgoE1YkcWZguv/INaNLkic6B+eXzyVGBl09zAcbLFvJing2rYgtQyJ8gsttSTyvaqFBmzZY1FDHJwU3sUnIx+PaaHrW1MePO4+twlKtFYMywby3pqN2Ze4PYVug+kFhH/l6sxUzPLqIybwNCFmF3zfr8ET96QceSodk2VOYm 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: Willem de Bruijn wrote: > The code already has to avoid allocation in the MSG_ZEROCOPY case. I > added alloc_len and paged_len for that purpose. > > Only the transhdrlen will be copied with getfrag due to > > copy = datalen - transhdrlen - fraggap - pagedlen > > On next iteration in the loop, when remaining data fits in the skb, > there are three cases. The first is skipped due to !NETIF_F_SG. The > other two are either copy to page frags or zerocopy page frags. > > I think your code should be able to fit in. Maybe easier if it could > reuse the existing alloc_new_skb code to copy the transport header, as > MSG_ZEROCOPY does, rather than adding a new __ip_splice_alloc branch > that short-circuits that. Then __ip_splice_pages also does not need > code to copy the initial header. But this is trickier. It's fine to > leave as is. > > Since your code currently does call continue before executing the rest > of that branch, no need to modify any code there? Notably replacing > length with initial_length, which itself is initialized to length in > all cases expect for MSG_SPLICE_PAGES. Okay. How about the attached? This seems to work. Just setting "paged" to true seems to do the right thing in __ip_append_data() when allocating / setting up the skbuff, and then __ip_splice_pages() is called to add the pages. David --- commit 9ac72c83407c8aef4be0c84513ec27bac9cfbcaa Author: David Howells Date: Thu Mar 9 14:27:29 2023 +0000 ip, udp: Support MSG_SPLICE_PAGES 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 diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index 6109a86a8a4b..fe2e48874191 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -956,6 +956,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, @@ -1047,6 +1082,15 @@ 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; @@ -1206,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;