[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAF=yD-LAC4QCfoGVKaW-GzU26=xp-6Wuq3jxAhJK1+KV0M+q2A@mail.gmail.com>
Date: Thu, 6 Apr 2023 22:01:42 -0400
From: Willem de Bruijn <willemdebruijn.kernel@...il.com>
To: David Howells <dhowells@...hat.com>
Cc: netdev@...r.kernel.org, "David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Matthew Wilcox <willy@...radead.org>,
Al Viro <viro@...iv.linux.org.uk>,
Christoph Hellwig <hch@...radead.org>,
Jens Axboe <axboe@...nel.dk>, Jeff Layton <jlayton@...nel.org>,
Christian Brauner <brauner@...nel.org>,
Chuck Lever III <chuck.lever@...cle.com>,
Linus Torvalds <torvalds@...ux-foundation.org>,
linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-mm@...ck.org, David Ahern <dsahern@...nel.org>
Subject: Re: [PATCH net-next v5 06/19] tcp: Make sendmsg(MSG_SPLICE_PAGES)
copy unspliceable data
On Thu, Apr 6, 2023 at 5:43 AM David Howells <dhowells@...hat.com> wrote:
>
> If sendmsg() with MSG_SPLICE_PAGES encounters a page that shouldn't be
> spliced - a slab page, for instance, or one with a zero count - make
> tcp_sendmsg() copy it.
>
> Signed-off-by: David Howells <dhowells@...hat.com>
> cc: Eric Dumazet <edumazet@...gle.com>
> cc: "David S. Miller" <davem@...emloft.net>
> cc: David Ahern <dsahern@...nel.org>
> cc: Jakub Kicinski <kuba@...nel.org>
> cc: Paolo Abeni <pabeni@...hat.com>
> cc: Jens Axboe <axboe@...nel.dk>
> cc: Matthew Wilcox <willy@...radead.org>
> cc: netdev@...r.kernel.org
> ---
> net/ipv4/tcp.c | 28 +++++++++++++++++++++++++---
> 1 file changed, 25 insertions(+), 3 deletions(-)
>
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index 510bacc7ce7b..238a8ad6527c 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -1418,10 +1418,10 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
> goto do_error;
> copy = err;
> } else if (zc == 2) {
> - /* Splice in data. */
> + /* Splice in data if we can; copy if we can't. */
> struct page *page = NULL, **pages = &page;
> size_t off = 0, part;
> - bool can_coalesce;
> + bool can_coalesce, put = false;
> int i = skb_shinfo(skb)->nr_frags;
>
> copy = iov_iter_extract_pages(&msg->msg_iter, &pages,
> @@ -1448,12 +1448,34 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size)
> goto wait_for_space;
> copy = part;
>
> + if (!sendpage_ok(page)) {
> + const void *p = kmap_local_page(page);
> + void *q;
> +
> + q = page_frag_memdup(NULL, p + off, copy,
> + sk->sk_allocation, ULONG_MAX);
> + kunmap_local(p);
> + if (!q) {
> + iov_iter_revert(&msg->msg_iter, copy);
> + err = copy ?: -ENOMEM;
> + goto do_error;
> + }
> + page = virt_to_page(q);
> + off = offset_in_page(q);
> + put = true;
> + can_coalesce = false;
> + }
> +
This is almost identical in the later udp and unix implementations.
Could this be a wrapper, something like
page = sendpage_copy_if_needed(&page, &off, copy, gfp, &put));
(it seems page is never needed if it would return NULL)
Powered by blists - more mailing lists