2023-07-01 07:13:04

by Arseniy Krasnov

[permalink] [raw]
Subject: [RFC PATCH v5 07/17] 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 'SOL_VSOCK' define.

Signed-off-by: Arseniy Krasnov <[email protected]>
---
Changelog:
v4 -> v5:
* Update commit message by adding sentence that 'SOL_VSOCK' is also
added.

include/linux/socket.h | 1 +
net/vmw_vsock/af_vsock.c | 5 +++++
2 files changed, 6 insertions(+)

diff --git a/include/linux/socket.h b/include/linux/socket.h
index bd1cc3238851..d79efd026880 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -382,6 +382,7 @@ struct ucred {
#define SOL_MPTCP 284
#define SOL_MCTP 285
#define SOL_SMC 286
+#define SOL_VSOCK 287

/* IPX options */
#define IPX_TYPE 1
diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
index 45fd20c4ed50..07803d9fbf6d 100644
--- a/net/vmw_vsock/af_vsock.c
+++ b/net/vmw_vsock/af_vsock.c
@@ -110,6 +110,7 @@
#include <linux/workqueue.h>
#include <net/sock.h>
#include <net/af_vsock.h>
+#include <linux/errqueue.h>

static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr);
static void vsock_sk_destruct(struct sock *sk);
@@ -2135,6 +2136,10 @@ vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
int err;

sk = sock->sk;
+
+ if (unlikely(flags & MSG_ERRQUEUE))
+ return sock_recv_errqueue(sk, msg, len, SOL_VSOCK, 0);
+
vsk = vsock_sk(sk);
err = 0;

--
2.25.1



2023-07-06 17:15:38

by Stefano Garzarella

[permalink] [raw]
Subject: Re: [RFC PATCH v5 07/17] vsock: read from socket's error queue

On Sat, Jul 01, 2023 at 09:39:37AM +0300, Arseniy Krasnov wrote:
>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 'SOL_VSOCK' define.
>
>Signed-off-by: Arseniy Krasnov <[email protected]>
>---
> Changelog:
> v4 -> v5:
> * Update commit message by adding sentence that 'SOL_VSOCK' is also
> added.

Reviewed-by: Stefano Garzarella <[email protected]>

>
> include/linux/socket.h | 1 +
> net/vmw_vsock/af_vsock.c | 5 +++++
> 2 files changed, 6 insertions(+)
>
>diff --git a/include/linux/socket.h b/include/linux/socket.h
>index bd1cc3238851..d79efd026880 100644
>--- a/include/linux/socket.h
>+++ b/include/linux/socket.h
>@@ -382,6 +382,7 @@ struct ucred {
> #define SOL_MPTCP 284
> #define SOL_MCTP 285
> #define SOL_SMC 286
>+#define SOL_VSOCK 287
>
> /* IPX options */
> #define IPX_TYPE 1
>diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>index 45fd20c4ed50..07803d9fbf6d 100644
>--- a/net/vmw_vsock/af_vsock.c
>+++ b/net/vmw_vsock/af_vsock.c
>@@ -110,6 +110,7 @@
> #include <linux/workqueue.h>
> #include <net/sock.h>
> #include <net/af_vsock.h>
>+#include <linux/errqueue.h>
>
> static int __vsock_bind(struct sock *sk, struct sockaddr_vm *addr);
> static void vsock_sk_destruct(struct sock *sk);
>@@ -2135,6 +2136,10 @@ vsock_connectible_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
> int err;
>
> sk = sock->sk;
>+
>+ if (unlikely(flags & MSG_ERRQUEUE))
>+ return sock_recv_errqueue(sk, msg, len, SOL_VSOCK, 0);
>+
> vsk = vsock_sk(sk);
> err = 0;
>
>--
>2.25.1
>