Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vsock: read from socket's error queue

This adds handling of MSG_ERRQUEUE input flag in receive call. This flag
is used to read socket's error queue instead of data queue. Possible
scenario of error queue usage is receiving completions for transmission
with MSG_ZEROCOPY flag. This patch also adds new defines: 'SOL_VSOCK'
and 'VSOCK_RECVERR'.

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

authored by

Arseniy Krasnov and committed by
David S. Miller
49dbe25a 0064cfb4

+24
+1
include/linux/socket.h
··· 383 383 #define SOL_MPTCP 284 384 384 #define SOL_MCTP 285 385 385 #define SOL_SMC 286 386 + #define SOL_VSOCK 287 386 387 387 388 /* IPX options */ 388 389 #define IPX_TYPE 1
+17
include/uapi/linux/vm_sockets.h
··· 191 191 192 192 #define IOCTL_VM_SOCKETS_GET_LOCAL_CID _IO(7, 0xb9) 193 193 194 + /* MSG_ZEROCOPY notifications are encoded in the standard error format, 195 + * sock_extended_err. See Documentation/networking/msg_zerocopy.rst in 196 + * kernel source tree for more details. 197 + */ 198 + 199 + /* 'cmsg_level' field value of 'struct cmsghdr' for notification parsing 200 + * when MSG_ZEROCOPY flag is used on transmissions. 201 + */ 202 + 203 + #define SOL_VSOCK 287 204 + 205 + /* 'cmsg_type' field value of 'struct cmsghdr' for notification parsing 206 + * when MSG_ZEROCOPY flag is used on transmissions. 207 + */ 208 + 209 + #define VSOCK_RECVERR 1 210 + 194 211 #endif /* _UAPI_VM_SOCKETS_H */
+6
net/vmw_vsock/af_vsock.c
··· 89 89 #include <linux/types.h> 90 90 #include <linux/bitops.h> 91 91 #include <linux/cred.h> 92 + #include <linux/errqueue.h> 92 93 #include <linux/init.h> 93 94 #include <linux/io.h> 94 95 #include <linux/kernel.h> ··· 111 110 #include <linux/workqueue.h> 112 111 #include <net/sock.h> 113 112 #include <net/af_vsock.h> 113 + #include <uapi/linux/vm_sockets.h> 114 114 115 115 static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr); 116 116 static void vsock_sk_destruct(struct sock *sk); ··· 2139 2137 int err; 2140 2138 2141 2139 sk = sock->sk; 2140 + 2141 + if (unlikely(flags & MSG_ERRQUEUE)) 2142 + return sock_recv_errqueue(sk, msg, len, SOL_VSOCK, VSOCK_RECVERR); 2143 + 2142 2144 vsk = vsock_sk(sk); 2143 2145 err = 0; 2144 2146