diff mbox series

[RFC,v8,13/19] virtio/vsock: rest of SOCK_SEQPACKET support

Message ID 20210413124528.3404287-1-arseny.krasnov@kaspersky.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series virtio/vsock: introduce SOCK_SEQPACKET support | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Arseny Krasnov April 13, 2021, 12:45 p.m. UTC
This adds rest of logic for SEQPACKET:
1) Send SHUTDOWN on socket close for SEQPACKET type.
2) Set SEQPACKET packet type during send.
3) 'seqpacket_allow' flag to virtio transport.
4) Set 'VIRTIO_VSOCK_SEQ_EOR' bit in flags for last
   packet of message.

Signed-off-by: Arseny Krasnov <arseny.krasnov@kaspersky.com>
---
v7 -> v8:
 - MSG_EOR handling is removed, i didn't found exact description about
   how it works in POSIX.
 - SEQ_BEGIN, SEQ_END, etc. now removed.

 include/linux/virtio_vsock.h            |  6 ++++++
 net/vmw_vsock/virtio_transport_common.c | 16 ++++++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

Comments

Stefano Garzarella April 21, 2021, 9:12 a.m. UTC | #1
On Tue, Apr 13, 2021 at 03:45:25PM +0300, Arseny Krasnov wrote:
>This adds rest of logic for SEQPACKET:
>1) Send SHUTDOWN on socket close for SEQPACKET type.
>2) Set SEQPACKET packet type during send.
>3) 'seqpacket_allow' flag to virtio transport.
>4) Set 'VIRTIO_VSOCK_SEQ_EOR' bit in flags for last
>   packet of message.
>
>Signed-off-by: Arseny Krasnov <arseny.krasnov@kaspersky.com>
>---
>v7 -> v8:
> - MSG_EOR handling is removed, i didn't found exact description about
>   how it works in POSIX.
> - SEQ_BEGIN, SEQ_END, etc. now removed.
>
> include/linux/virtio_vsock.h            |  6 ++++++
> net/vmw_vsock/virtio_transport_common.c | 16 ++++++++++++++--
> 2 files changed, 20 insertions(+), 2 deletions(-)
>
>diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
>index 02acf6e9ae04..f00a01bfdd7e 100644
>--- a/include/linux/virtio_vsock.h
>+++ b/include/linux/virtio_vsock.h
>@@ -68,6 +68,8 @@ struct virtio_transport {
>
>       /* Takes ownership of the packet */
>       int (*send_pkt)(struct virtio_vsock_pkt *pkt);
>+
>+      bool seqpacket_allow;
> };
>
> ssize_t
>@@ -80,6 +82,10 @@ virtio_transport_dgram_dequeue(struct vsock_sock *vsk,
>                              struct msghdr *msg,
>                              size_t len, int flags);
>
>+int
>+virtio_transport_seqpacket_enqueue(struct vsock_sock *vsk,
>+                                 struct msghdr *msg,
>+                                 size_t len);
> ssize_t
> virtio_transport_seqpacket_dequeue(struct vsock_sock *vsk,
>                                  struct msghdr *msg,
>diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
>index 572869fef832..4c5b63601308 100644
>--- a/net/vmw_vsock/virtio_transport_common.c
>+++ b/net/vmw_vsock/virtio_transport_common.c
>@@ -74,6 +74,9 @@ virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info,
>               err = memcpy_from_msg(pkt->buf, info->msg, len);
>               if (err)
>                       goto out;
>+
>+              if (info->msg->msg_iter.count == 0)
>+                      pkt->hdr.flags |= VIRTIO_VSOCK_SEQ_EOR;

We should set the flag in info->flags and assign it using cpu_to_le32() 
or just the following:
			pkt->hdr.flags = cpu_to_le32(info->flags |
						VIRTIO_VSOCK_SEQ_EOR);


>       }
>
>       trace_virtio_transport_alloc_pkt(src_cid, src_port,
>@@ -187,7 +190,7 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,
>       struct virtio_vsock_pkt *pkt;
>       u32 pkt_len = info->pkt_len;
>
>-      info->type = VIRTIO_VSOCK_TYPE_STREAM;
>+      info->type = virtio_transport_get_type(sk_vsock(vsk));
>
>       t_ops = virtio_transport_get_ops(vsk);
>       if (unlikely(!t_ops))
>@@ -486,6 +489,15 @@ virtio_transport_seqpacket_dequeue(struct 
>vsock_sock *vsk,
> }
> EXPORT_SYMBOL_GPL(virtio_transport_seqpacket_dequeue);
>
>+int
>+virtio_transport_seqpacket_enqueue(struct vsock_sock *vsk,
>+                                 struct msghdr *msg,
>+                                 size_t len)
>+{
>+      return virtio_transport_stream_enqueue(vsk, msg, len);
>+}
>+EXPORT_SYMBOL_GPL(virtio_transport_seqpacket_enqueue);
>+
> int
> virtio_transport_dgram_dequeue(struct vsock_sock *vsk,
>                              struct msghdr *msg,
>@@ -905,7 +917,7 @@ void virtio_transport_release(struct vsock_sock *vsk)
>       struct sock *sk = &vsk->sk;
>       bool remove_sock = true;
>
>-      if (sk->sk_type == SOCK_STREAM)
>+      if (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET)
>               remove_sock = virtio_transport_close(vsk);
>
>       list_for_each_entry_safe(pkt, tmp, &vvs->rx_queue, list) {
>--
>2.25.1
>
Arseny Krasnov April 21, 2021, 2:50 p.m. UTC | #2
On 21.04.2021 12:12, Stefano Garzarella wrote:
> On Tue, Apr 13, 2021 at 03:45:25PM +0300, Arseny Krasnov wrote:
>> This adds rest of logic for SEQPACKET:
>> 1) Send SHUTDOWN on socket close for SEQPACKET type.
>> 2) Set SEQPACKET packet type during send.
>> 3) 'seqpacket_allow' flag to virtio transport.
>> 4) Set 'VIRTIO_VSOCK_SEQ_EOR' bit in flags for last
>>   packet of message.
>>
>> Signed-off-by: Arseny Krasnov <arseny.krasnov@kaspersky.com>
>> ---
>> v7 -> v8:
>> - MSG_EOR handling is removed, i didn't found exact description about
>>   how it works in POSIX.
>> - SEQ_BEGIN, SEQ_END, etc. now removed.
>>
>> include/linux/virtio_vsock.h            |  6 ++++++
>> net/vmw_vsock/virtio_transport_common.c | 16 ++++++++++++++--
>> 2 files changed, 20 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
>> index 02acf6e9ae04..f00a01bfdd7e 100644
>> --- a/include/linux/virtio_vsock.h
>> +++ b/include/linux/virtio_vsock.h
>> @@ -68,6 +68,8 @@ struct virtio_transport {
>>
>>       /* Takes ownership of the packet */
>>       int (*send_pkt)(struct virtio_vsock_pkt *pkt);
>> +
>> +      bool seqpacket_allow;
>> };
>>
>> ssize_t
>> @@ -80,6 +82,10 @@ virtio_transport_dgram_dequeue(struct vsock_sock *vsk,
>>                              struct msghdr *msg,
>>                              size_t len, int flags);
>>
>> +int
>> +virtio_transport_seqpacket_enqueue(struct vsock_sock *vsk,
>> +                                 struct msghdr *msg,
>> +                                 size_t len);
>> ssize_t
>> virtio_transport_seqpacket_dequeue(struct vsock_sock *vsk,
>>                                  struct msghdr *msg,
>> diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
>> index 572869fef832..4c5b63601308 100644
>> --- a/net/vmw_vsock/virtio_transport_common.c
>> +++ b/net/vmw_vsock/virtio_transport_common.c
>> @@ -74,6 +74,9 @@ virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info,
>>               err = memcpy_from_msg(pkt->buf, info->msg, len);
>>               if (err)
>>                       goto out;
>> +
>> +              if (info->msg->msg_iter.count == 0)
>> +                      pkt->hdr.flags |= VIRTIO_VSOCK_SEQ_EOR;
> We should set the flag in info->flags and assign it using cpu_to_le32() 
> or just the following:
> 			pkt->hdr.flags = cpu_to_le32(info->flags |
> 						VIRTIO_VSOCK_SEQ_EOR);
Ack
>
>
>>       }
>>
>>       trace_virtio_transport_alloc_pkt(src_cid, src_port,
>> @@ -187,7 +190,7 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,
>>       struct virtio_vsock_pkt *pkt;
>>       u32 pkt_len = info->pkt_len;
>>
>> -      info->type = VIRTIO_VSOCK_TYPE_STREAM;
>> +      info->type = virtio_transport_get_type(sk_vsock(vsk));
>>
>>       t_ops = virtio_transport_get_ops(vsk);
>>       if (unlikely(!t_ops))
>> @@ -486,6 +489,15 @@ virtio_transport_seqpacket_dequeue(struct 
>> vsock_sock *vsk,
>> }
>> EXPORT_SYMBOL_GPL(virtio_transport_seqpacket_dequeue);
>>
>> +int
>> +virtio_transport_seqpacket_enqueue(struct vsock_sock *vsk,
>> +                                 struct msghdr *msg,
>> +                                 size_t len)
>> +{
>> +      return virtio_transport_stream_enqueue(vsk, msg, len);
>> +}
>> +EXPORT_SYMBOL_GPL(virtio_transport_seqpacket_enqueue);
>> +
>> int
>> virtio_transport_dgram_dequeue(struct vsock_sock *vsk,
>>                              struct msghdr *msg,
>> @@ -905,7 +917,7 @@ void virtio_transport_release(struct vsock_sock *vsk)
>>       struct sock *sk = &vsk->sk;
>>       bool remove_sock = true;
>>
>> -      if (sk->sk_type == SOCK_STREAM)
>> +      if (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET)
>>               remove_sock = virtio_transport_close(vsk);
>>
>>       list_for_each_entry_safe(pkt, tmp, &vvs->rx_queue, list) {
>> --
>> 2.25.1
>>
>
diff mbox series

Patch

diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
index 02acf6e9ae04..f00a01bfdd7e 100644
--- a/include/linux/virtio_vsock.h
+++ b/include/linux/virtio_vsock.h
@@ -68,6 +68,8 @@  struct virtio_transport {
 
 	/* Takes ownership of the packet */
 	int (*send_pkt)(struct virtio_vsock_pkt *pkt);
+
+	bool seqpacket_allow;
 };
 
 ssize_t
@@ -80,6 +82,10 @@  virtio_transport_dgram_dequeue(struct vsock_sock *vsk,
 			       struct msghdr *msg,
 			       size_t len, int flags);
 
+int
+virtio_transport_seqpacket_enqueue(struct vsock_sock *vsk,
+				   struct msghdr *msg,
+				   size_t len);
 ssize_t
 virtio_transport_seqpacket_dequeue(struct vsock_sock *vsk,
 				   struct msghdr *msg,
diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
index 572869fef832..4c5b63601308 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -74,6 +74,9 @@  virtio_transport_alloc_pkt(struct virtio_vsock_pkt_info *info,
 		err = memcpy_from_msg(pkt->buf, info->msg, len);
 		if (err)
 			goto out;
+
+		if (info->msg->msg_iter.count == 0)
+			pkt->hdr.flags |= VIRTIO_VSOCK_SEQ_EOR;
 	}
 
 	trace_virtio_transport_alloc_pkt(src_cid, src_port,
@@ -187,7 +190,7 @@  static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,
 	struct virtio_vsock_pkt *pkt;
 	u32 pkt_len = info->pkt_len;
 
-	info->type = VIRTIO_VSOCK_TYPE_STREAM;
+	info->type = virtio_transport_get_type(sk_vsock(vsk));
 
 	t_ops = virtio_transport_get_ops(vsk);
 	if (unlikely(!t_ops))
@@ -486,6 +489,15 @@  virtio_transport_seqpacket_dequeue(struct vsock_sock *vsk,
 }
 EXPORT_SYMBOL_GPL(virtio_transport_seqpacket_dequeue);
 
+int
+virtio_transport_seqpacket_enqueue(struct vsock_sock *vsk,
+				   struct msghdr *msg,
+				   size_t len)
+{
+	return virtio_transport_stream_enqueue(vsk, msg, len);
+}
+EXPORT_SYMBOL_GPL(virtio_transport_seqpacket_enqueue);
+
 int
 virtio_transport_dgram_dequeue(struct vsock_sock *vsk,
 			       struct msghdr *msg,
@@ -905,7 +917,7 @@  void virtio_transport_release(struct vsock_sock *vsk)
 	struct sock *sk = &vsk->sk;
 	bool remove_sock = true;
 
-	if (sk->sk_type == SOCK_STREAM)
+	if (sk->sk_type == SOCK_STREAM || sk->sk_type == SOCK_SEQPACKET)
 		remove_sock = virtio_transport_close(vsk);
 
 	list_for_each_entry_safe(pkt, tmp, &vvs->rx_queue, list) {