All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: Yunsheng Lin <linyunsheng@huawei.com>
Cc: dhowells@redhat.com, netdev@vger.kernel.org,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemdebruijn.kernel@gmail.com>,
	David Ahern <dsahern@kernel.org>,
	Matthew Wilcox <willy@infradead.org>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Christoph Hellwig <hch@infradead.org>,
	Jens Axboe <axboe@kernel.dk>, Jeff Layton <jlayton@kernel.org>,
	Christian Brauner <brauner@kernel.org>,
	Chuck Lever III <chuck.lever@oracle.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH net-next v10 03/16] net: Add a function to splice pages into an skbuff for MSG_SPLICE_PAGES
Date: Wed, 24 May 2023 14:21:34 +0100	[thread overview]
Message-ID: <3587228.1684934494@warthog.procyon.org.uk> (raw)
In-Reply-To: <82041a42-e7b0-bde3-0f70-8ad180565794@huawei.com>

Yunsheng Lin <linyunsheng@huawei.com> wrote:

> > + * Returns the amount of data spliced/copied or -EMSGSIZE if there's
> 
> I am not seeing any copying done directly in the skb_splice_from_iter(),
> maybe iov_iter_extract_pages() has done copying for it?

Ah, I took the code for that out and deferred it.  The comment needs amending.

> > +			ret = skb_append_pagefrags(skb, page, off, part,
> > +						   frag_limit);
> > +			if (ret < 0) {
> > +				iov_iter_revert(iter, len);
> 
> I am not sure I understand the error handling here, doesn't 'len'
> indicate the remaining size of the data to be appended to skb,

Yes.

> maybe we should revert the size of data that is already appended to skb
> here?  Does 'spliced' need to be adjusted accordingly?

Neither.

> I am not very familiar with the 'struct iov_iter' yet

An iov_iter struct is a cursor over a buffer.  It advances as we draw data or
space from that buffer.  Sometimes we overdraw and have to back up a bit -
hence the revert function.  It could possibly be renamed to something more
appropriate as (if/when ITER_PIPE is removed) it doesn't actually change the
buffer.

So looking at skb_splice_from_iter():

iov_iter_extract_pages() is used to get a list of pages from the buffer that
we think we're going to be able to handle.  If the buffer is of type IOVEC or
UBUF those pages would have pins inserted into them also; otherwise no pin or
ref will be taken on them.  MSG_SPLICE_PAGES should not be used with IOVEC or
UBUF types for the moment as the network layer does not yet handle pins.

iov_iter_extract_pages() will advance the iterator past the page fragments it
has returned.  If skb_append_pagefrags() indicates that it could not attach
the page, this isn't necessarily fatal - it could return -EMSGSIZE to indicate
there was no space, in which case we return to the caller to create a new
skbuff.

If a non-fatal error occurs, we may already have committed some parts of the
buffer to the skbuff and rewinding into that part of the buffer would cause a
repeat of the data which would be bad.

What the iov_iter_revert() is doing is rewinding iterator back past the part
of the extracted pages that we didn't get to use so that we will pick up where
we left off next time we're called.  It does *not* and must not revert the
data we've already transferred.

Arguably, I should revert when I return -EIO because sendpage_ok() returned
false, but that's a fatal error.

David


  parent reply	other threads:[~2023-05-24 13:23 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-22 12:11 [PATCH net-next v10 00/16] splice, net: Replace sendpage with sendmsg(MSG_SPLICE_PAGES), part 1 David Howells
2023-05-22 12:11 ` [PATCH net-next v10 01/16] net: Declare MSG_SPLICE_PAGES internal sendmsg() flag David Howells
2023-05-22 12:11 ` [PATCH net-next v10 02/16] net: Pass max frags into skb_append_pagefrags() David Howells
2023-05-22 12:11 ` [PATCH net-next v10 03/16] net: Add a function to splice pages into an skbuff for MSG_SPLICE_PAGES David Howells
2023-05-24 12:24   ` Yunsheng Lin
2023-05-24 13:21   ` David Howells [this message]
2023-05-22 12:11 ` [PATCH net-next v10 04/16] tcp: Support MSG_SPLICE_PAGES David Howells
2023-05-22 12:11 ` [PATCH net-next v10 05/16] tcp: Convert do_tcp_sendpages() to use MSG_SPLICE_PAGES David Howells
2023-05-22 12:11 ` [PATCH net-next v10 06/16] tcp_bpf: Inline do_tcp_sendpages as it's now a wrapper around tcp_sendmsg David Howells
2023-05-22 12:11 ` [PATCH net-next v10 07/16] espintcp: Inline do_tcp_sendpages() David Howells
2023-05-22 12:11 ` [PATCH net-next v10 08/16] tls: " David Howells
2023-06-07 14:17   ` Tariq Toukan
2023-06-07 15:03   ` David Howells
2023-06-13 11:15     ` Tariq Toukan
2023-06-19  8:23       ` Tariq Toukan
2023-06-19  9:35       ` David Howells
2023-06-27 16:49         ` Tariq Toukan
2023-06-30 17:21           ` Jakub Kicinski
2023-07-04 20:06             ` Tariq Toukan
2023-07-05 16:19               ` Jakub Kicinski
2023-07-23  6:35                 ` Tariq Toukan
2023-07-26  0:30                   ` Jakub Kicinski
2023-07-26 19:20                     ` Tariq Toukan
2023-07-26 20:08                       ` Jakub Kicinski
2023-08-03 11:52                         ` Tariq Toukan
2023-08-03 11:47                     ` Tariq Toukan
2023-08-04  3:12                       ` Jakub Kicinski
2023-08-08  7:29                         ` Tariq Toukan
2023-07-26 10:51                 ` David Howells
2023-07-26 11:43                   ` Tariq Toukan
2023-07-26 14:57                     ` Jakub Kicinski
2023-08-10 13:07             ` David Howells
2023-06-27 16:55         ` David Howells
2023-06-27 17:06         ` David Howells
2023-05-22 12:11 ` [PATCH net-next v10 09/16] siw: " David Howells
2023-05-22 12:11 ` [PATCH net-next v10 10/16] tcp: Fold do_tcp_sendpages() into tcp_sendpage_locked() David Howells
2023-05-22 12:11 ` [PATCH net-next v10 11/16] ip, udp: Support MSG_SPLICE_PAGES David Howells
2023-05-22 12:11 ` [PATCH net-next v10 12/16] ip6, udp6: " David Howells
2023-05-22 12:11 ` [PATCH net-next v10 13/16] udp: Convert udp_sendpage() to use MSG_SPLICE_PAGES David Howells
2023-05-22 12:11 ` [PATCH net-next v10 14/16] ip: Remove ip_append_page() David Howells
2023-05-22 12:11 ` [PATCH net-next v10 15/16] af_unix: Support MSG_SPLICE_PAGES David Howells
2023-05-22 12:11 ` [PATCH net-next v10 16/16] unix: Convert unix_stream_sendpage() to use MSG_SPLICE_PAGES David Howells
2023-05-24  4:20 ` [PATCH net-next v10 00/16] splice, net: Replace sendpage with sendmsg(MSG_SPLICE_PAGES), part 1 patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3587228.1684934494@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=brauner@kernel.org \
    --cc=chuck.lever@oracle.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=hch@infradead.org \
    --cc=jlayton@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linyunsheng@huawei.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willemdebruijn.kernel@gmail.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.