vsock/virtio: MSG_ZEROCOPY flag support
authorArseniy Krasnov <avkrasnov@salutedevices.com>
Sat, 16 Sep 2023 13:09:18 +0000 (16:09 +0300)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 21 Sep 2023 10:34:00 +0000 (12:34 +0200)
commit581512a6dc939ef122e49336626ae159f3b8a345
tree51f6d95d49a03ac93ccb42c74f85ae50e78fe662
parent4b0bf10eb077cb43c09746251ef3608d62c45667
vsock/virtio: MSG_ZEROCOPY flag support

This adds handling of MSG_ZEROCOPY flag on transmission path:

1) If this flag is set and zerocopy transmission is possible (enabled
   in socket options and transport allows zerocopy), then non-linear
   skb will be created and filled with the pages of user's buffer.
   Pages of user's buffer are locked in memory by 'get_user_pages()'.
2) Replaces way of skb owning: instead of 'skb_set_owner_sk_safe()' it
   calls 'skb_set_owner_w()'. Reason of this change is that
   '__zerocopy_sg_from_iter()' increments 'sk_wmem_alloc' of socket, so
   to decrease this field correctly, proper skb destructor is needed:
   'sock_wfree()'. This destructor is set by 'skb_set_owner_w()'.
3) Adds new callback to 'struct virtio_transport': 'can_msgzerocopy'.
   If this callback is set, then transport needs extra check to be able
   to send provided number of buffers in zerocopy mode. Currently, the
   only transport that needs this callback set is virtio, because this
   transport adds new buffers to the virtio queue and we need to check,
   that number of these buffers is less than size of the queue (it is
   required by virtio spec). vhost and loopback transports don't need
   this check.

Signed-off-by: Arseniy Krasnov <avkrasnov@salutedevices.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
include/linux/virtio_vsock.h
include/trace/events/vsock_virtio_transport_common.h
net/vmw_vsock/virtio_transport.c
net/vmw_vsock/virtio_transport_common.c