On 19/05/2026 12:49, Stefano Garzarella wrote:
> On Tue, May 19, 2026 at 09:37:23AM +0300, Arseniy Krasnov wrote:
>> On 18/05/2026 14:08, Stefano Garzarella wrote:
>>> On Mon, May 18, 2026 at 11:50:05AM +0100, David Laight wrote:
>>>> On Mon, 18 May 2026 11:54:19 +0200
>>>> Stefano Garzarella <[email protected]> wrote:
>
> [...]
>
>>
>> Hi guys! Just some replies after quick look:
>>
>>>>> >> > Surely that block should only be done if can_zcopy is true?
>>
>> I guess no, since TCP also allocates uarg even if zerocopy is impossible -
>> it just sets uarg_to_msgzc(uarg)->zerocopy = 0;
>>
>>>>> >> > And shouldn't something unset it if info->op != VIRTIO_VSOCK_OP_RW ?
>>
>> Hm, we can't enter block 'if (info->msg) {' when 'info->op' is not equal to
>> 'VIRTIO_VSOCK_OP_RW',
>> because 'msg' is not NULL only for 'VIRTIO_VSOCK_OP_RW'. But anyway You
>> point to right thing - check for
>> 'VIRTIO_VSOCK_OP_RW' could be removed here. Just with comment why.
>>
>>>>> >> > If the msg_zerocopy_realloc() fails then can't you just set
>>>>> >> > can_zcopy to false.
>>
>> Here I guess it is better to follow TCP way to make same behaviour, because
>> exact
>> logic for MSG_ZEROCOPY is not documented. TCP also returns error and stops
>> tx loop.
>>
>>>>> >> >
>>>>> >> > It info->msg->msg_buf is already set then I think you have to
>>>>> >> > disable zero-copy.
>>>>> >> > The caller has already requested a callback - and you can't add
>>>>> >> > another.
>>
>> In TCP implementation if 'msg_ubuf' is set they just use it and check for
>> zerocopy in
>> the same way as 'msg_ubuf' is NULL.
>>
>>>>> >> >
>>>>> >> > In any case by the end of this can_zcopy and have_uref are really
>>>>> >> > the same flag.
>>>>> >>
>>
>> Need to check it more. But 'can_zcopy' means that we fill frags in skb,
>> have_uref means that we
>> allocated completion (but it could be reported with not set
>> 'SO_EE_CODE_ZEROCOPY_COPIED' if
>> 'can_zcopy' was false).
>>
>>
>> @Stefano, I guess current implementation differs from TCP in two cases (at
>> least from first
>> view):
>> 1) When 'msg_ubuf' is set: in TCP, already set 'msg_ubuf' is passed to
>> 'skb_zerocopy_iter_stream()'
>> (if zerocopy is possible) where it is used as in vsock in call
>> 'skb_zcopy_set()'. In vsock case if
>> 'msg_ubuf' is not NULL we will pass just NULL to 'skb_zcopy_set()'. Yes
>> this is will be
>> no-effect call today (due to checks in 'skb_zcopy_set()'), but anyway - in
>> future may be not.
>> 2) Also i see that 'skb_zerocopy_iter_stream()' in TCP version has some
>> extra checks which are
>> missed in vsock - we only just call '__zerocopy_sg_from_iter()' to fill
>> skb in zerocopy way.
>>
>> But, I think, instead of trying to compare vsock and TCP versions best way
>> is to just copy
>> current TCP flow as close as possible:
>> https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/tree/net/ipv4/tcp.c#n1144
>> 1) Use same flow of checks for 'msg_flags', 'msg_ubuf', SOCK_ZEROCOPY etc.
>> 2) To copy data we can use 'skb_zerocopy_iter_stream()'.
>> 3) The only thing that we don't need in vsock is dev mem related code from
>> TCP implementation.
>>
>> I can take this task, but pls need some time - may be two/three weeks due to
>> another tasks.
>>
>> What do You think?
>
> If you can work on it, please go head. They seems all pre-existing, so 2/3
> weeks are fine. Please let me know if you can't and I'll try to allocate some
> time.
No problem I'll take it. If something goes wrong or stuck - i'll let you know
Thanks
>
> Thanks for the help!
>
> Stefano
>