2021-07-26 16:41:29

by Arseny Krasnov

[permalink] [raw]
Subject: [RFC PATCH v1 0/7] virtio/vsock: introduce MSG_EOR flag for SEQPACKET

This patchset implements support of MSG_EOR bit for SEQPACKET
AF_VSOCK sockets over virtio transport.
Idea is to distinguish concepts of 'messages' and 'records'.
Message is result of sending calls: 'write()', 'send()', 'sendmsg()'
etc. It has fixed maximum length, and it bounds are visible using
return from receive calls: 'read()', 'recv()', 'recvmsg()' etc.
Current implementation based on message definition above.
Record has unlimited length, it consists of multiple message,
and bounds of record are visible via MSG_EOR flag returned from
'recvmsg()' call. Sender passes MSG_EOR to sending system call and
receiver will see MSG_EOR when corresponding message will be processed.
To support MSG_EOR new bit was added along with existing
'VIRTIO_VSOCK_SEQ_EOR': 'VIRTIO_VSOCK_SEQ_EOM'(end-of-message) - now it
works in the same way as 'VIRTIO_VSOCK_SEQ_EOR'. But 'VIRTIO_VSOCK_SEQ_EOR'
is used to mark 'MSG_EOR' bit passed from userspace.
This patchset includes simple test for MSG_EOR.
Also i've added new vsock test for '-EAGAIN' receive result.

Arseny Krasnov(7):
virtio/vsock: add 'VIRTIO_VSOCK_SEQ_EOM' bit
vsock: rename implementation from 'record' to 'message'
vhost/vsock: support MSG_EOR bit processing
virito/vsock: support MSG_EOR bit processing
af_vsock: rename variables in receive loop
vsock_test: update message bounds test for MSG_EOR
vsock_test: 'SO_RCVTIMEO' test for SEQPACKET

drivers/vhost/vsock.c | 28 +++++++----
include/uapi/linux/virtio_vsock.h | 1 +
net/vmw_vsock/af_vsock.c | 10 ++--
net/vmw_vsock/virtio_transport_common.c | 23 +++++----
tools/testing/vsock/vsock_test.c | 57 ++++++++++++++++++++++-
5 files changed, 96 insertions(+), 23 deletions(-)

Signed-off-by: Arseny Krasnov <[email protected]>

--
2.25.1


2021-07-26 16:41:53

by Arseny Krasnov

[permalink] [raw]
Subject: [RFC PATCH v1 6/7] vsock_test: update message bounds test for MSG_EOR

Set 'MSG_EOR' in one of message sent, check that 'MSG_EOR'
is visible in corresponding message at receiver.

Signed-off-by: Arseny Krasnov <[email protected]>
---
tools/testing/vsock/vsock_test.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c
index 67766bfe176f..2a3638c0a008 100644
--- a/tools/testing/vsock/vsock_test.c
+++ b/tools/testing/vsock/vsock_test.c
@@ -282,6 +282,7 @@ static void test_stream_msg_peek_server(const struct test_opts *opts)
}

#define MESSAGES_CNT 7
+#define MSG_EOR_IDX (MESSAGES_CNT / 2)
static void test_seqpacket_msg_bounds_client(const struct test_opts *opts)
{
int fd;
@@ -294,7 +295,7 @@ static void test_seqpacket_msg_bounds_client(const struct test_opts *opts)

/* Send several messages, one with MSG_EOR flag */
for (int i = 0; i < MESSAGES_CNT; i++)
- send_byte(fd, 1, 0);
+ send_byte(fd, 1, (i == MSG_EOR_IDX) ? MSG_EOR : 0);

control_writeln("SENDDONE");
close(fd);
@@ -324,6 +325,11 @@ static void test_seqpacket_msg_bounds_server(const struct test_opts *opts)
perror("message bound violated");
exit(EXIT_FAILURE);
}
+
+ if ((i == MSG_EOR_IDX) ^ !!(msg.msg_flags & MSG_EOR)) {
+ perror("MSG_EOR");
+ exit(EXIT_FAILURE);
+ }
}

close(fd);
--
2.25.1

2021-07-26 16:43:08

by Arseny Krasnov

[permalink] [raw]
Subject: [RFC PATCH v1 3/7] vhost/vsock: support MSG_EOR bit processing

It works in the same way as 'end-of-message' bit: if packet has
'EOM' bit, also check for 'EOR' bit.

Signed-off-by: Arseny Krasnov <[email protected]>
---
drivers/vhost/vsock.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
index 3b55de70ac77..3e2b150f9c6f 100644
--- a/drivers/vhost/vsock.c
+++ b/drivers/vhost/vsock.c
@@ -115,6 +115,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
size_t iov_len, payload_len;
int head;
bool restore_msg_eom_flag = false;
+ bool restore_msg_eor_flag = false;

spin_lock_bh(&vsock->send_pkt_list_lock);
if (list_empty(&vsock->send_pkt_list)) {
@@ -188,6 +189,11 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
if (le32_to_cpu(pkt->hdr.flags) & VIRTIO_VSOCK_SEQ_EOM) {
pkt->hdr.flags &= ~cpu_to_le32(VIRTIO_VSOCK_SEQ_EOM);
restore_msg_eom_flag = true;
+
+ if (le32_to_cpu(pkt->hdr.flags & VIRTIO_VSOCK_SEQ_EOR)) {
+ pkt->hdr.flags &= ~cpu_to_le32(VIRTIO_VSOCK_SEQ_EOR);
+ restore_msg_eor_flag = true;
+ }
}
}

@@ -224,9 +230,13 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
* to send it with the next available buffer.
*/
if (pkt->off < pkt->len) {
- if (restore_msg_eom_flag)
+ if (restore_msg_eom_flag) {
pkt->hdr.flags |= cpu_to_le32(VIRTIO_VSOCK_SEQ_EOM);

+ if (restore_msg_eor_flag)
+ pkt->hdr.flags |= cpu_to_le32(VIRTIO_VSOCK_SEQ_EOR);
+ }
+
/* We are queueing the same virtio_vsock_pkt to handle
* the remaining bytes, and we want to deliver it
* to monitoring devices in the next iteration.
--
2.25.1

2021-07-26 16:45:15

by Arseny Krasnov

[permalink] [raw]
Subject: [RFC PATCH v1 7/7] vsock_test: 'SO_RCVTIMEO' test for SEQPACKET

Test for receive timeout check: connection is established,
receiver sets timeout, but sender does nothing. Receiver's
'read()' call must return EAGAIN.

Signed-off-by: Arseny Krasnov <[email protected]>
---
tools/testing/vsock/vsock_test.c | 49 ++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)

diff --git a/tools/testing/vsock/vsock_test.c b/tools/testing/vsock/vsock_test.c
index 2a3638c0a008..aa2de27d0f77 100644
--- a/tools/testing/vsock/vsock_test.c
+++ b/tools/testing/vsock/vsock_test.c
@@ -391,6 +391,50 @@ static void test_seqpacket_msg_trunc_server(const struct test_opts *opts)
close(fd);
}

+static void test_seqpacket_timeout_client(const struct test_opts *opts)
+{
+ int fd;
+ struct timeval tv;
+ char dummy;
+
+ fd = vsock_seqpacket_connect(opts->peer_cid, 1234);
+ if (fd < 0) {
+ perror("connect");
+ exit(EXIT_FAILURE);
+ }
+
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+
+ if (setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (void *)&tv, sizeof(tv)) == -1) {
+ perror("setsockopt 'SO_RCVTIMEO'");
+ exit(EXIT_FAILURE);
+ }
+
+ if ((read(fd, &dummy, sizeof(dummy)) != -1) ||
+ (errno != EAGAIN)) {
+ perror("EAGAIN expected");
+ exit(EXIT_FAILURE);
+ }
+
+ control_writeln("WAITDONE");
+ close(fd);
+}
+
+static void test_seqpacket_timeout_server(const struct test_opts *opts)
+{
+ int fd;
+
+ fd = vsock_seqpacket_accept(VMADDR_CID_ANY, 1234, NULL);
+ if (fd < 0) {
+ perror("accept");
+ exit(EXIT_FAILURE);
+ }
+
+ control_expectln("WAITDONE");
+ close(fd);
+}
+
static struct test_case test_cases[] = {
{
.name = "SOCK_STREAM connection reset",
@@ -431,6 +475,11 @@ static struct test_case test_cases[] = {
.run_client = test_seqpacket_msg_trunc_client,
.run_server = test_seqpacket_msg_trunc_server,
},
+ {
+ .name = "SOCK_SEQPACKET timeout",
+ .run_client = test_seqpacket_timeout_client,
+ .run_server = test_seqpacket_timeout_server,
+ },
{},
};

--
2.25.1

2021-07-27 08:00:55

by Stefano Garzarella

[permalink] [raw]
Subject: Re: [RFC PATCH v1 0/7] virtio/vsock: introduce MSG_EOR flag for SEQPACKET

On Mon, Jul 26, 2021 at 07:31:33PM +0300, Arseny Krasnov wrote:
> This patchset implements support of MSG_EOR bit for SEQPACKET
>AF_VSOCK sockets over virtio transport.
> Idea is to distinguish concepts of 'messages' and 'records'.
>Message is result of sending calls: 'write()', 'send()', 'sendmsg()'
>etc. It has fixed maximum length, and it bounds are visible using
>return from receive calls: 'read()', 'recv()', 'recvmsg()' etc.
>Current implementation based on message definition above.
> Record has unlimited length, it consists of multiple message,
>and bounds of record are visible via MSG_EOR flag returned from
>'recvmsg()' call. Sender passes MSG_EOR to sending system call and
>receiver will see MSG_EOR when corresponding message will be processed.
> To support MSG_EOR new bit was added along with existing
>'VIRTIO_VSOCK_SEQ_EOR': 'VIRTIO_VSOCK_SEQ_EOM'(end-of-message) - now it
>works in the same way as 'VIRTIO_VSOCK_SEQ_EOR'. But 'VIRTIO_VSOCK_SEQ_EOR'
>is used to mark 'MSG_EOR' bit passed from userspace.

At this point it's probably better to rename the old flag, so we stay
compatible.

What happens if one of the two peers does not support MSG_EOR handling,
while the other does?

I'll do a closer review in the next few days.

Thanks,
Stefano


2021-07-27 09:38:26

by Arseny Krasnov

[permalink] [raw]
Subject: Re: [MASSMAIL KLMS] Re: [RFC PATCH v1 0/7] virtio/vsock: introduce MSG_EOR flag for SEQPACKET


On 27.07.2021 10:59, Stefano Garzarella wrote:
> Caution: This is an external email. Be cautious while opening links or attachments.
>
>
>
> On Mon, Jul 26, 2021 at 07:31:33PM +0300, Arseny Krasnov wrote:
>> This patchset implements support of MSG_EOR bit for SEQPACKET
>> AF_VSOCK sockets over virtio transport.
>> Idea is to distinguish concepts of 'messages' and 'records'.
>> Message is result of sending calls: 'write()', 'send()', 'sendmsg()'
>> etc. It has fixed maximum length, and it bounds are visible using
>> return from receive calls: 'read()', 'recv()', 'recvmsg()' etc.
>> Current implementation based on message definition above.
>> Record has unlimited length, it consists of multiple message,
>> and bounds of record are visible via MSG_EOR flag returned from
>> 'recvmsg()' call. Sender passes MSG_EOR to sending system call and
>> receiver will see MSG_EOR when corresponding message will be processed.
>> To support MSG_EOR new bit was added along with existing
>> 'VIRTIO_VSOCK_SEQ_EOR': 'VIRTIO_VSOCK_SEQ_EOM'(end-of-message) - now it
>> works in the same way as 'VIRTIO_VSOCK_SEQ_EOR'. But 'VIRTIO_VSOCK_SEQ_EOR'
>> is used to mark 'MSG_EOR' bit passed from userspace.
> At this point it's probably better to rename the old flag, so we stay
> compatible.
>
> What happens if one of the two peers does not support MSG_EOR handling,
> while the other does?
>
> I'll do a closer review in the next few days.
Thank You, also i think MSG_EOR support must be described in spec
>
> Thanks,
> Stefano
>
>

2021-07-27 09:59:18

by Stefano Garzarella

[permalink] [raw]
Subject: Re: [MASSMAIL KLMS] Re: [RFC PATCH v1 0/7] virtio/vsock: introduce MSG_EOR flag for SEQPACKET

On Tue, Jul 27, 2021 at 12:34:36PM +0300, Arseny Krasnov wrote:
>
>On 27.07.2021 10:59, Stefano Garzarella wrote:
>> Caution: This is an external email. Be cautious while opening links or attachments.
>>
>>
>>
>> On Mon, Jul 26, 2021 at 07:31:33PM +0300, Arseny Krasnov wrote:
>>> This patchset implements support of MSG_EOR bit for SEQPACKET
>>> AF_VSOCK sockets over virtio transport.
>>> Idea is to distinguish concepts of 'messages' and 'records'.
>>> Message is result of sending calls: 'write()', 'send()', 'sendmsg()'
>>> etc. It has fixed maximum length, and it bounds are visible using
>>> return from receive calls: 'read()', 'recv()', 'recvmsg()' etc.
>>> Current implementation based on message definition above.
>>> Record has unlimited length, it consists of multiple message,
>>> and bounds of record are visible via MSG_EOR flag returned from
>>> 'recvmsg()' call. Sender passes MSG_EOR to sending system call and
>>> receiver will see MSG_EOR when corresponding message will be processed.
>>> To support MSG_EOR new bit was added along with existing
>>> 'VIRTIO_VSOCK_SEQ_EOR': 'VIRTIO_VSOCK_SEQ_EOM'(end-of-message) - now it
>>> works in the same way as 'VIRTIO_VSOCK_SEQ_EOR'. But 'VIRTIO_VSOCK_SEQ_EOR'
>>> is used to mark 'MSG_EOR' bit passed from userspace.
>> At this point it's probably better to rename the old flag, so we stay
>> compatible.
>>
>> What happens if one of the two peers does not support MSG_EOR handling,
>> while the other does?
>>
>> I'll do a closer review in the next few days.
>Thank You, also i think MSG_EOR support must be described in spec

Yep, sure!

What do you think about the concerns above?

Stefano


2021-07-27 12:37:40

by Arseny Krasnov

[permalink] [raw]
Subject: Re: [MASSMAIL KLMS] Re: [MASSMAIL KLMS] Re: [RFC PATCH v1 0/7] virtio/vsock: introduce MSG_EOR flag for SEQPACKET


On 27.07.2021 12:58, Stefano Garzarella wrote:
> Caution: This is an external email. Be cautious while opening links or attachments.
>
>
>
> On Tue, Jul 27, 2021 at 12:34:36PM +0300, Arseny Krasnov wrote:
>> On 27.07.2021 10:59, Stefano Garzarella wrote:
>>> Caution: This is an external email. Be cautious while opening links or attachments.
>>>
>>>
>>>
>>> On Mon, Jul 26, 2021 at 07:31:33PM +0300, Arseny Krasnov wrote:
>>>> This patchset implements support of MSG_EOR bit for SEQPACKET
>>>> AF_VSOCK sockets over virtio transport.
>>>> Idea is to distinguish concepts of 'messages' and 'records'.
>>>> Message is result of sending calls: 'write()', 'send()', 'sendmsg()'
>>>> etc. It has fixed maximum length, and it bounds are visible using
>>>> return from receive calls: 'read()', 'recv()', 'recvmsg()' etc.
>>>> Current implementation based on message definition above.
>>>> Record has unlimited length, it consists of multiple message,
>>>> and bounds of record are visible via MSG_EOR flag returned from
>>>> 'recvmsg()' call. Sender passes MSG_EOR to sending system call and
>>>> receiver will see MSG_EOR when corresponding message will be processed.
>>>> To support MSG_EOR new bit was added along with existing
>>>> 'VIRTIO_VSOCK_SEQ_EOR': 'VIRTIO_VSOCK_SEQ_EOM'(end-of-message) - now it
>>>> works in the same way as 'VIRTIO_VSOCK_SEQ_EOR'. But 'VIRTIO_VSOCK_SEQ_EOR'
>>>> is used to mark 'MSG_EOR' bit passed from userspace.
>>> At this point it's probably better to rename the old flag, so we stay
>>> compatible.
>>>
>>> What happens if one of the two peers does not support MSG_EOR handling,
>>> while the other does?
>>>
>>> I'll do a closer review in the next few days.
>> Thank You, also i think MSG_EOR support must be described in spec
> Yep, sure!
>
> What do you think about the concerns above?
I think you are right, i'll rename EOR -> EOM, and EOR will be added by patch
>
> Stefano
>
>

2021-08-04 13:30:35

by Stefano Garzarella

[permalink] [raw]
Subject: Re: [RFC PATCH v1 0/7] virtio/vsock: introduce MSG_EOR flag for SEQPACKET

Hi Arseny,

On Mon, Jul 26, 2021 at 07:31:33PM +0300, Arseny Krasnov wrote:
> This patchset implements support of MSG_EOR bit for SEQPACKET
>AF_VSOCK sockets over virtio transport.
> Idea is to distinguish concepts of 'messages' and 'records'.
>Message is result of sending calls: 'write()', 'send()', 'sendmsg()'
>etc. It has fixed maximum length, and it bounds are visible using
>return from receive calls: 'read()', 'recv()', 'recvmsg()' etc.
>Current implementation based on message definition above.

Okay, so the implementation we merged is wrong right?
Should we disable the feature bit in stable kernels that contain it? Or
maybe we can backport the fixes...

> Record has unlimited length, it consists of multiple message,
>and bounds of record are visible via MSG_EOR flag returned from
>'recvmsg()' call. Sender passes MSG_EOR to sending system call and
>receiver will see MSG_EOR when corresponding message will be processed.
> To support MSG_EOR new bit was added along with existing
>'VIRTIO_VSOCK_SEQ_EOR': 'VIRTIO_VSOCK_SEQ_EOM'(end-of-message) - now it
>works in the same way as 'VIRTIO_VSOCK_SEQ_EOR'. But 'VIRTIO_VSOCK_SEQ_EOR'
>is used to mark 'MSG_EOR' bit passed from userspace.

I understand that it makes sense to remap VIRTIO_VSOCK_SEQ_EOR to
MSG_EOR to make the user understand the boundaries, but why do we need
EOM as well?

Why do we care about the boundaries of a message within a record?
I mean, if the sender makes 3 calls:
send(A1,0)
send(A2,0)
send(A3, MSG_EOR);

IIUC it should be fine if the receiver for example receives all in one
single recv() calll with MSG_EOR set, so why do we need EOM?

Thanks,
Stefano

2021-08-05 09:10:50

by Arseny Krasnov

[permalink] [raw]
Subject: Re: [RFC PATCH v1 0/7] virtio/vsock: introduce MSG_EOR flag for SEQPACKET


On 04.08.2021 15:57, Stefano Garzarella wrote:
> Caution: This is an external email. Be cautious while opening links or attachments.
>
>
>
> Hi Arseny,
>
> On Mon, Jul 26, 2021 at 07:31:33PM +0300, Arseny Krasnov wrote:
>> This patchset implements support of MSG_EOR bit for SEQPACKET
>> AF_VSOCK sockets over virtio transport.
>> Idea is to distinguish concepts of 'messages' and 'records'.
>> Message is result of sending calls: 'write()', 'send()', 'sendmsg()'
>> etc. It has fixed maximum length, and it bounds are visible using
>> return from receive calls: 'read()', 'recv()', 'recvmsg()' etc.
>> Current implementation based on message definition above.
> Okay, so the implementation we merged is wrong right?
> Should we disable the feature bit in stable kernels that contain it? Or
> maybe we can backport the fixes...

Hi,

No, this is correct and it is message boundary based. Idea of this

patchset is to add extra boundaries marker which i think could be

useful when we want to send data in seqpacket mode which length

is bigger than maximum message length(this is limited by transport).

Of course we can fragment big piece of data too small messages, but this

requires to carry fragmentation info in data protocol. So In this case

when we want to maintain boundaries receiver calls recvmsg() until MSG_EOR found.

But when receiver knows, that data is fit in maximum datagram length,

it doesn't care about checking MSG_EOR just calling recv() or read()(e.g.

message based mode).


Thank You

>
>> Record has unlimited length, it consists of multiple message,
>> and bounds of record are visible via MSG_EOR flag returned from
>> 'recvmsg()' call. Sender passes MSG_EOR to sending system call and
>> receiver will see MSG_EOR when corresponding message will be processed.
>> To support MSG_EOR new bit was added along with existing
>> 'VIRTIO_VSOCK_SEQ_EOR': 'VIRTIO_VSOCK_SEQ_EOM'(end-of-message) - now it
>> works in the same way as 'VIRTIO_VSOCK_SEQ_EOR'. But 'VIRTIO_VSOCK_SEQ_EOR'
>> is used to mark 'MSG_EOR' bit passed from userspace.
> I understand that it makes sense to remap VIRTIO_VSOCK_SEQ_EOR to
> MSG_EOR to make the user understand the boundaries, but why do we need
> EOM as well?
>
> Why do we care about the boundaries of a message within a record?
> I mean, if the sender makes 3 calls:
> send(A1,0)
> send(A2,0)
> send(A3, MSG_EOR);
>
> IIUC it should be fine if the receiver for example receives all in one
> single recv() calll with MSG_EOR set, so why do we need EOM?
>
> Thanks,
> Stefano
>
>

2021-08-05 12:19:20

by Stefano Garzarella

[permalink] [raw]
Subject: Re: [RFC PATCH v1 0/7] virtio/vsock: introduce MSG_EOR flag for SEQPACKET

On Thu, Aug 05, 2021 at 11:33:12AM +0300, Arseny Krasnov wrote:
>
>On 04.08.2021 15:57, Stefano Garzarella wrote:
>> Caution: This is an external email. Be cautious while opening links or attachments.
>>
>>
>>
>> Hi Arseny,
>>
>> On Mon, Jul 26, 2021 at 07:31:33PM +0300, Arseny Krasnov wrote:
>>> This patchset implements support of MSG_EOR bit for SEQPACKET
>>> AF_VSOCK sockets over virtio transport.
>>> Idea is to distinguish concepts of 'messages' and 'records'.
>>> Message is result of sending calls: 'write()', 'send()', 'sendmsg()'
>>> etc. It has fixed maximum length, and it bounds are visible using
>>> return from receive calls: 'read()', 'recv()', 'recvmsg()' etc.
>>> Current implementation based on message definition above.
>> Okay, so the implementation we merged is wrong right?
>> Should we disable the feature bit in stable kernels that contain it? Or
>> maybe we can backport the fixes...
>
>Hi,
>
>No, this is correct and it is message boundary based. Idea of this
>patchset is to add extra boundaries marker which i think could be
>useful when we want to send data in seqpacket mode which length
>is bigger than maximum message length(this is limited by transport).
>Of course we can fragment big piece of data too small messages, but
>this
>requires to carry fragmentation info in data protocol. So In this case
>when we want to maintain boundaries receiver calls recvmsg() until
>MSG_EOR found.
>But when receiver knows, that data is fit in maximum datagram length,
>it doesn't care about checking MSG_EOR just calling recv() or
>read()(e.g.
>message based mode).

I'm not sure we should maintain boundaries of multiple send(), from
POSIX standard [1]:

SOCK_SEQPACKET
Provides sequenced, reliable, bidirectional, connection-mode
transmission paths for records. A record can be sent using one or
more output operations and received using one or more input
operations, but a single operation never transfers part of more than
one record. Record boundaries are visible to the receiver via the
MSG_EOR flag.

From my understanding a record could be sent with multiple send() and
received, for example, with a single recvmsg().
The only boundary should be the MSG_EOR flag set by the user on the last
send() of a record.

From send() description [2]:

MSG_EOR
Terminates a record (if supported by the protocol).

From recvmsg() description [3]:

MSG_EOR
End-of-record was received (if supported by the protocol).

Thanks,
Stefano

[1]
https://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html
[2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html
[3]
https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html

2021-08-05 12:53:22

by Arseny Krasnov

[permalink] [raw]
Subject: Re: [!!Mass Mail KSE][MASSMAIL KLMS] Re: [RFC PATCH v1 0/7] virtio/vsock: introduce MSG_EOR flag for SEQPACKET


On 05.08.2021 12:06, Stefano Garzarella wrote:
> Caution: This is an external email. Be cautious while opening links or attachments.
>
>
>
> On Thu, Aug 05, 2021 at 11:33:12AM +0300, Arseny Krasnov wrote:
>> On 04.08.2021 15:57, Stefano Garzarella wrote:
>>> Caution: This is an external email. Be cautious while opening links or attachments.
>>>
>>>
>>>
>>> Hi Arseny,
>>>
>>> On Mon, Jul 26, 2021 at 07:31:33PM +0300, Arseny Krasnov wrote:
>>>> This patchset implements support of MSG_EOR bit for SEQPACKET
>>>> AF_VSOCK sockets over virtio transport.
>>>> Idea is to distinguish concepts of 'messages' and 'records'.
>>>> Message is result of sending calls: 'write()', 'send()', 'sendmsg()'
>>>> etc. It has fixed maximum length, and it bounds are visible using
>>>> return from receive calls: 'read()', 'recv()', 'recvmsg()' etc.
>>>> Current implementation based on message definition above.
>>> Okay, so the implementation we merged is wrong right?
>>> Should we disable the feature bit in stable kernels that contain it? Or
>>> maybe we can backport the fixes...
>> Hi,
>>
>> No, this is correct and it is message boundary based. Idea of this
>> patchset is to add extra boundaries marker which i think could be
>> useful when we want to send data in seqpacket mode which length
>> is bigger than maximum message length(this is limited by transport).
>> Of course we can fragment big piece of data too small messages, but
>> this
>> requires to carry fragmentation info in data protocol. So In this case
>> when we want to maintain boundaries receiver calls recvmsg() until
>> MSG_EOR found.
>> But when receiver knows, that data is fit in maximum datagram length,
>> it doesn't care about checking MSG_EOR just calling recv() or
>> read()(e.g.
>> message based mode).
> I'm not sure we should maintain boundaries of multiple send(), from
> POSIX standard [1]:

Yes, but also from POSIX: such calls like send() and sendmsg()

operates with "message" and if we check recvmsg() we will

find the following thing:


For message-based sockets, such as SOCK_DGRAM and SOCK_SEQPACKET, the entire

message shall be read in a single operation. If a message is too long to fit in the supplied

buffers, and MSG_PEEK is not set in the flags argument, the excess bytes shall be discarded.


I understand this, that send() boundaries also must be maintained.

I've checked SEQPACKET in AF_UNIX and AX_25 - both doesn't support

MSG_EOR, so send() boundaries must be supported.

>
> SOCK_SEQPACKET
> Provides sequenced, reliable, bidirectional, connection-mode
> transmission paths for records. A record can be sent using one or
> more output operations and received using one or more input
> operations, but a single operation never transfers part of more than
> one record. Record boundaries are visible to the receiver via the
> MSG_EOR flag.
>
> From my understanding a record could be sent with multiple send() and
> received, for example, with a single recvmsg().
> The only boundary should be the MSG_EOR flag set by the user on the last
> send() of a record.
You are right, if we talking about "record".
>
> From send() description [2]:
>
> MSG_EOR
> Terminates a record (if supported by the protocol).
>
> From recvmsg() description [3]:
>
> MSG_EOR
> End-of-record was received (if supported by the protocol).
>
> Thanks,
> Stefano
>
> [1]
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html
> [2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html
> [3]
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html

P.S.: seems SEQPACKET is too exotic thing that everyone implements it in

own manner, because i've tested SCTP seqpacket implementation, and found

that:

1) It doesn't support MSG_EOR bit at send side, but uses MSG_EOR at receiver

side to mark MESSAGE boundary.

2) According POSIX any extra bytes that didn't fit in user's buffer must be dropped,

but SCTP doesn't drop it - you can read rest of datagram in next calls.

>
>

2021-08-06 08:07:06

by Stefano Garzarella

[permalink] [raw]
Subject: Re: [RFC PATCH v1 3/7] vhost/vsock: support MSG_EOR bit processing

On Mon, Jul 26, 2021 at 07:33:38PM +0300, Arseny Krasnov wrote:
>It works in the same way as 'end-of-message' bit: if packet has
>'EOM' bit, also check for 'EOR' bit.
>
>Signed-off-by: Arseny Krasnov <[email protected]>
>---
> drivers/vhost/vsock.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
>index 3b55de70ac77..3e2b150f9c6f 100644
>--- a/drivers/vhost/vsock.c
>+++ b/drivers/vhost/vsock.c
>@@ -115,6 +115,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
> size_t iov_len, payload_len;
> int head;
> bool restore_msg_eom_flag = false;
>+ bool restore_msg_eor_flag = false;

Since we now have 2 flags to potentially restore, we could use a single
variable (e.g. uint32_t flags_to_restore), initialized to 0.

We can set all the flags we need to restore and then simply put it
in or with the `pkt->hdr.flags` field.

> spin_lock_bh(&vsock->send_pkt_list_lock);
> if (list_empty(&vsock->send_pkt_list)) {
>@@ -188,6 +189,11 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
> if (le32_to_cpu(pkt->hdr.flags) & VIRTIO_VSOCK_SEQ_EOM) {
> pkt->hdr.flags &= ~cpu_to_le32(VIRTIO_VSOCK_SEQ_EOM);
> restore_msg_eom_flag = true;
>+
>+ if (le32_to_cpu(pkt->hdr.flags & VIRTIO_VSOCK_SEQ_EOR)) {
^
Here it should be `le32_to_cpu(pkt->hdr.flags) & VIRTIO_VSOCK_SEQ_EOR`

>+ pkt->hdr.flags &= ~cpu_to_le32(VIRTIO_VSOCK_SEQ_EOR);
>+ restore_msg_eor_flag = true;
>+ }
> }
> }
>
>@@ -224,9 +230,13 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
> * to send it with the next available buffer.
> */
> if (pkt->off < pkt->len) {
>- if (restore_msg_eom_flag)
>+ if (restore_msg_eom_flag) {
> pkt->hdr.flags |= cpu_to_le32(VIRTIO_VSOCK_SEQ_EOM);
>
>+ if (restore_msg_eor_flag)
>+ pkt->hdr.flags |= cpu_to_le32(VIRTIO_VSOCK_SEQ_EOR);
>+ }
>+

If we use a single variable, here we can simply do:

pkt->hdr.flags |= cpu_to_le32(flags_to_restore);

Stefano

2021-08-06 08:46:03

by Arseny Krasnov

[permalink] [raw]
Subject: Re: [RFC PATCH v1 3/7] vhost/vsock: support MSG_EOR bit processing


On 06.08.2021 10:28, Stefano Garzarella wrote:
> Caution: This is an external email. Be cautious while opening links or attachments.
>
>
>
> On Mon, Jul 26, 2021 at 07:33:38PM +0300, Arseny Krasnov wrote:
>> It works in the same way as 'end-of-message' bit: if packet has
>> 'EOM' bit, also check for 'EOR' bit.
>>
>> Signed-off-by: Arseny Krasnov <[email protected]>
>> ---
>> drivers/vhost/vsock.c | 12 +++++++++++-
>> 1 file changed, 11 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
>> index 3b55de70ac77..3e2b150f9c6f 100644
>> --- a/drivers/vhost/vsock.c
>> +++ b/drivers/vhost/vsock.c
>> @@ -115,6 +115,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
>> size_t iov_len, payload_len;
>> int head;
>> bool restore_msg_eom_flag = false;
>> + bool restore_msg_eor_flag = false;
> Since we now have 2 flags to potentially restore, we could use a single
> variable (e.g. uint32_t flags_to_restore), initialized to 0.
>
> We can set all the flags we need to restore and then simply put it
> in or with the `pkt->hdr.flags` field.
>
>> spin_lock_bh(&vsock->send_pkt_list_lock);
>> if (list_empty(&vsock->send_pkt_list)) {
>> @@ -188,6 +189,11 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
>> if (le32_to_cpu(pkt->hdr.flags) & VIRTIO_VSOCK_SEQ_EOM) {
>> pkt->hdr.flags &= ~cpu_to_le32(VIRTIO_VSOCK_SEQ_EOM);
>> restore_msg_eom_flag = true;
>> +
>> + if (le32_to_cpu(pkt->hdr.flags & VIRTIO_VSOCK_SEQ_EOR)) {
> ^
> Here it should be `le32_to_cpu(pkt->hdr.flags) & VIRTIO_VSOCK_SEQ_EOR`
>
>> + pkt->hdr.flags &= ~cpu_to_le32(VIRTIO_VSOCK_SEQ_EOR);
>> + restore_msg_eor_flag = true;
>> + }
>> }
>> }
>>
>> @@ -224,9 +230,13 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
>> * to send it with the next available buffer.
>> */
>> if (pkt->off < pkt->len) {
>> - if (restore_msg_eom_flag)
>> + if (restore_msg_eom_flag) {
>> pkt->hdr.flags |= cpu_to_le32(VIRTIO_VSOCK_SEQ_EOM);
>>
>> + if (restore_msg_eor_flag)
>> + pkt->hdr.flags |= cpu_to_le32(VIRTIO_VSOCK_SEQ_EOR);
>> + }
>> +
> If we use a single variable, here we can simply do:
>
> pkt->hdr.flags |= cpu_to_le32(flags_to_restore);
>
> Stefano

Thanks, i'll prepare v2 both with spec patch. About spec: i've already sent

patch for SEQPACKET, can i prepare spec patch updating current reviewed

SEQPACKET? E.g. i'll include both EOM and EOR in one patch.


Thank You

>

2021-08-06 12:01:15

by Stefano Garzarella

[permalink] [raw]
Subject: Re: [!!Mass Mail KSE][MASSMAIL KLMS] Re: [RFC PATCH v1 0/7] virtio/vsock: introduce MSG_EOR flag for SEQPACKET

On Thu, Aug 05, 2021 at 12:21:57PM +0300, Arseny Krasnov wrote:
>
>On 05.08.2021 12:06, Stefano Garzarella wrote:
>> Caution: This is an external email. Be cautious while opening links or attachments.
>>
>>
>>
>> On Thu, Aug 05, 2021 at 11:33:12AM +0300, Arseny Krasnov wrote:
>>> On 04.08.2021 15:57, Stefano Garzarella wrote:
>>>> Caution: This is an external email. Be cautious while opening links or attachments.
>>>>
>>>>
>>>>
>>>> Hi Arseny,
>>>>
>>>> On Mon, Jul 26, 2021 at 07:31:33PM +0300, Arseny Krasnov wrote:
>>>>> This patchset implements support of MSG_EOR bit for SEQPACKET
>>>>> AF_VSOCK sockets over virtio transport.
>>>>> Idea is to distinguish concepts of 'messages' and 'records'.
>>>>> Message is result of sending calls: 'write()', 'send()', 'sendmsg()'
>>>>> etc. It has fixed maximum length, and it bounds are visible using
>>>>> return from receive calls: 'read()', 'recv()', 'recvmsg()' etc.
>>>>> Current implementation based on message definition above.
>>>> Okay, so the implementation we merged is wrong right?
>>>> Should we disable the feature bit in stable kernels that contain it? Or
>>>> maybe we can backport the fixes...
>>> Hi,
>>>
>>> No, this is correct and it is message boundary based. Idea of this
>>> patchset is to add extra boundaries marker which i think could be
>>> useful when we want to send data in seqpacket mode which length
>>> is bigger than maximum message length(this is limited by transport).
>>> Of course we can fragment big piece of data too small messages, but
>>> this
>>> requires to carry fragmentation info in data protocol. So In this case
>>> when we want to maintain boundaries receiver calls recvmsg() until
>>> MSG_EOR found.
>>> But when receiver knows, that data is fit in maximum datagram length,
>>> it doesn't care about checking MSG_EOR just calling recv() or
>>> read()(e.g.
>>> message based mode).
>> I'm not sure we should maintain boundaries of multiple send(), from
>> POSIX standard [1]:
>
>Yes, but also from POSIX: such calls like send() and sendmsg()
>
>operates with "message" and if we check recvmsg() we will
>
>find the following thing:
>
>
>For message-based sockets, such as SOCK_DGRAM and SOCK_SEQPACKET, the entire
>
>message shall be read in a single operation. If a message is too long to fit in the supplied
>
>buffers, and MSG_PEEK is not set in the flags argument, the excess bytes shall be discarded.
>
>
>I understand this, that send() boundaries also must be maintained.
>
>I've checked SEQPACKET in AF_UNIX and AX_25 - both doesn't support
>
>MSG_EOR, so send() boundaries must be supported.
>
>>
>> SOCK_SEQPACKET
>> Provides sequenced, reliable, bidirectional, connection-mode
>> transmission paths for records. A record can be sent using one or
>> more output operations and received using one or more input
>> operations, but a single operation never transfers part of more than
>> one record. Record boundaries are visible to the receiver via the
>> MSG_EOR flag.
>>
>> From my understanding a record could be sent with multiple send()
>> and
>> received, for example, with a single recvmsg().
>> The only boundary should be the MSG_EOR flag set by the user on the
>> last
>> send() of a record.
>You are right, if we talking about "record".
>>
>> From send() description [2]:
>>
>> MSG_EOR
>> Terminates a record (if supported by the protocol).
>>
>> From recvmsg() description [3]:
>>
>> MSG_EOR
>> End-of-record was received (if supported by the protocol).
>>
>> Thanks,
>> Stefano
>>
>> [1]
>> https://pubs.opengroup.org/onlinepubs/9699919799/functions/socket.html
>> [2]
>> https://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html
>> [3]
>> https://pubs.opengroup.org/onlinepubs/9699919799/functions/recvmsg.html
>
>P.S.: seems SEQPACKET is too exotic thing that everyone implements it
>in
>
>own manner, because i've tested SCTP seqpacket implementation, and
>found
>
>that:
>
>1) It doesn't support MSG_EOR bit at send side, but uses MSG_EOR at
>receiver
>
>side to mark MESSAGE boundary.
>
>2) According POSIX any extra bytes that didn't fit in user's buffer
>must be dropped,
>
>but SCTP doesn't drop it - you can read rest of datagram in next calls.
>

Thanks for this useful information, now I see the differences and why we
should support both.

I think is better to include them in the cover letter.

I'm going to review the paches right now :-)

Stefano

2021-08-06 14:54:25

by Stefano Garzarella

[permalink] [raw]
Subject: Re: [RFC PATCH v1 3/7] vhost/vsock: support MSG_EOR bit processing

On Fri, Aug 06, 2021 at 11:40:38AM +0300, Arseny Krasnov wrote:
>
>On 06.08.2021 10:28, Stefano Garzarella wrote:
>> Caution: This is an external email. Be cautious while opening links or attachments.
>>
>>
>>
>> On Mon, Jul 26, 2021 at 07:33:38PM +0300, Arseny Krasnov wrote:
>>> It works in the same way as 'end-of-message' bit: if packet has
>>> 'EOM' bit, also check for 'EOR' bit.
>>>
>>> Signed-off-by: Arseny Krasnov <[email protected]>
>>> ---
>>> drivers/vhost/vsock.c | 12 +++++++++++-
>>> 1 file changed, 11 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/vhost/vsock.c b/drivers/vhost/vsock.c
>>> index 3b55de70ac77..3e2b150f9c6f 100644
>>> --- a/drivers/vhost/vsock.c
>>> +++ b/drivers/vhost/vsock.c
>>> @@ -115,6 +115,7 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
>>> size_t iov_len, payload_len;
>>> int head;
>>> bool restore_msg_eom_flag = false;
>>> + bool restore_msg_eor_flag = false;
>> Since we now have 2 flags to potentially restore, we could use a single
>> variable (e.g. uint32_t flags_to_restore), initialized to 0.
>>
>> We can set all the flags we need to restore and then simply put it
>> in or with the `pkt->hdr.flags` field.
>>
>>> spin_lock_bh(&vsock->send_pkt_list_lock);
>>> if (list_empty(&vsock->send_pkt_list)) {
>>> @@ -188,6 +189,11 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
>>> if (le32_to_cpu(pkt->hdr.flags) & VIRTIO_VSOCK_SEQ_EOM) {
>>> pkt->hdr.flags &= ~cpu_to_le32(VIRTIO_VSOCK_SEQ_EOM);
>>> restore_msg_eom_flag = true;
>>> +
>>> + if (le32_to_cpu(pkt->hdr.flags & VIRTIO_VSOCK_SEQ_EOR)) {
>> ^
>> Here it should be `le32_to_cpu(pkt->hdr.flags) & VIRTIO_VSOCK_SEQ_EOR`
>>
>>> + pkt->hdr.flags &= ~cpu_to_le32(VIRTIO_VSOCK_SEQ_EOR);
>>> + restore_msg_eor_flag = true;
>>> + }
>>> }
>>> }
>>>
>>> @@ -224,9 +230,13 @@ vhost_transport_do_send_pkt(struct vhost_vsock *vsock,
>>> * to send it with the next available buffer.
>>> */
>>> if (pkt->off < pkt->len) {
>>> - if (restore_msg_eom_flag)
>>> + if (restore_msg_eom_flag) {
>>> pkt->hdr.flags |= cpu_to_le32(VIRTIO_VSOCK_SEQ_EOM);
>>>
>>> + if (restore_msg_eor_flag)
>>> + pkt->hdr.flags |= cpu_to_le32(VIRTIO_VSOCK_SEQ_EOR);
>>> + }
>>> +
>> If we use a single variable, here we can simply do:
>>
>> pkt->hdr.flags |= cpu_to_le32(flags_to_restore);
>>
>> Stefano
>
>Thanks, i'll prepare v2 both with spec patch. About spec: i've already sent
>
>patch for SEQPACKET, can i prepare spec patch updating current reviewed
>
>SEQPACKET? E.g. i'll include both EOM and EOR in one patch.

Yep, since spec is not yet merged, I think make sense to have all
seqpacket stuff in a single patch.

Thanks,
Stefano