vsock: check for MSG_ZEROCOPY support on send
authorArseniy Krasnov <avkrasnov@salutedevices.com>
Tue, 10 Oct 2023 19:15:15 +0000 (22:15 +0300)
committerDavid S. Miller <davem@davemloft.net>
Sun, 15 Oct 2023 12:19:42 +0000 (13:19 +0100)
This feature totally depends on transport, so if transport doesn't
support it, return error.

Signed-off-by: Arseniy Krasnov <avkrasnov@salutedevices.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/af_vsock.h
net/vmw_vsock/af_vsock.c

index b01cf9ac243715489bacd8a66756905b275da9a2..e302c0e804d0f2ce6ef45aae51a2d2c5ee7c2c23 100644 (file)
@@ -177,6 +177,9 @@ struct vsock_transport {
 
        /* Read a single skb */
        int (*read_skb)(struct vsock_sock *, skb_read_actor_t);
+
+       /* Zero-copy. */
+       bool (*msgzerocopy_allow)(void);
 };
 
 /**** CORE ****/
@@ -241,4 +244,8 @@ static inline void __init vsock_bpf_build_proto(void)
 {}
 #endif
 
+static inline bool vsock_msgzerocopy_allow(const struct vsock_transport *t)
+{
+       return t->msgzerocopy_allow && t->msgzerocopy_allow();
+}
 #endif /* __AF_VSOCK_H__ */
index 38486efd3d05d6e98ab41bd971a3694d9d72cfbb..71108b1f0dfcc6b74ff7aab493c8555c5f4582c5 100644 (file)
@@ -1824,6 +1824,12 @@ static int vsock_connectible_sendmsg(struct socket *sock, struct msghdr *msg,
                goto out;
        }
 
+       if (msg->msg_flags & MSG_ZEROCOPY &&
+           !vsock_msgzerocopy_allow(transport)) {
+               err = -EOPNOTSUPP;
+               goto out;
+       }
+
        /* Wait for room in the produce queue to enqueue our user's data. */
        timeout = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT);