Re: [RFC net-next v3 05/29] net: bvec specific path in zerocopy_sg_from_iter

From: Pavel Begunkov
Date: Tue Jun 28 2022 - 17:36:23 EST


On 6/28/22 21:06, Al Viro wrote:
On Tue, Jun 28, 2022 at 07:56:27PM +0100, Pavel Begunkov wrote:
Add an bvec specialised and optimised path in zerocopy_sg_from_iter.
It'll be used later for {get,put}_page() optimisations.

If you need a variant that would not grab page references for ITER_BVEC
(and presumably other non-userland ones), the natural thing to do would

I don't see other iter types interesting in this context

be to provide just such a primitive, wouldn't it?

A helper returning a page array sounds like overshot and waste of cycles
considering that it copies one bvec into another, and especially since
iov_iter_get_pages() parses only the first struct bio_vec and so returns
only 1 page at a time.

I can actually use for_each_bvec(), but still leaves updating the iter
from bvec_iter.

The fun question here is by which paths ITER_BVEC can be passed to that
function and which all of them are currently guaranteed to hold the
underlying pages pinned...

It's the other way around, not all ITER_BVEC are managed but all users
asking to use managed frags (i.e. io_uring) should keep pages pinned and
provide ITER_BVEC. It's opt-in, both for users and protocols.

--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -66,9 +66,16 @@ struct msghdr {
};
bool msg_control_is_user : 1;
bool msg_get_inq : 1;/* return INQ after receive */
+ /*
+ * The data pages are pinned and won't be released before ->msg_ubuf
+ * is released. ->msg_iter should point to a bvec and ->msg_ubuf has
+ * to be non-NULL.
+ */
+ bool msg_managed_data : 1;
unsigned int msg_flags; /* flags on received message */
__kernel_size_t msg_controllen; /* ancillary data buffer length */
struct kiocb *msg_iocb; /* ptr to iocb for async requests */
+ struct ubuf_info *msg_ubuf;
};

The user sets ->msg_managed_data, then protocols find it and set
SKBFL_MANAGED_FRAG_REFS. If either of the steps didn't happen the
feature is not used.
The ->msg_managed_data part makes io_uring the only user, and io_uring
ensures pages are pinned.


And AFAICS you quietly assume that only ITER_BVEC ones will ever have that
"managed" flag of your set. Or am I misreading the next patch in the
series?

I hope a comment just above ->msg_managed_data should count as not quiet.

--
Pavel Begunkov