public inbox for virtualization@lists.linux-foundation.org
 help / color / mirror / Atom feed
From: Stefano Garzarella <sgarzare@redhat.com>
To: Arseny Krasnov <arseny.krasnov@kaspersky.com>
Cc: Andra Paraschiv <andraprs@amazon.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jeff Vander Stoep <jeffv@google.com>,
	"stsp2@yandex.ru" <stsp2@yandex.ru>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"virtualization@lists.linux-foundation.org"
	<virtualization@lists.linux-foundation.org>,
	"oxffffaa@gmail.com" <oxffffaa@gmail.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Colin Ian King <colin.king@canonical.com>,
	Jakub Kicinski <kuba@kernel.org>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [RFC PATCH v3 03/13] af_vsock: implement SEQPACKET rx loop
Date: Fri, 29 Jan 2021 10:21:58 +0100	[thread overview]
Message-ID: <20210129092158.tm2bdwpqufsneaxw@steredhat> (raw)
In-Reply-To: <5e000f18-1457-068d-10c5-0a349c938497@kaspersky.com>

On Fri, Jan 29, 2021 at 09:28:49AM +0300, Arseny Krasnov wrote:
>
>On 28.01.2021 19:55, Stefano Garzarella wrote:
>> On Mon, Jan 25, 2021 at 02:12:36PM +0300, Arseny Krasnov wrote:
>>> This adds receive loop for SEQPACKET. It looks like receive loop for
>>> SEQPACKET, but there is a little bit difference:
>>> 1) It doesn't call notify callbacks.
>>> 2) It doesn't care about 'SO_SNDLOWAT' and 'SO_RCVLOWAT' values, because
>>>   there is no sense for these values in SEQPACKET case.
>>> 3) It waits until whole record is received or error is found during
>>>   receiving.
>>> 4) It processes and sets 'MSG_TRUNC' flag.
>>>
>>> So to avoid extra conditions for two types of socket inside one loop, two
>>> independent functions were created.
>>>
>>> Signed-off-by: Arseny Krasnov <arseny.krasnov@kaspersky.com>
>>> ---
>>> include/net/af_vsock.h   |   5 ++
>>> net/vmw_vsock/af_vsock.c | 102 ++++++++++++++++++++++++++++++++++++++-
>>> 2 files changed, 106 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/include/net/af_vsock.h b/include/net/af_vsock.h
>>> index b1c717286993..46073842d489 100644
>>> --- a/include/net/af_vsock.h
>>> +++ b/include/net/af_vsock.h
>>> @@ -135,6 +135,11 @@ struct vsock_transport {
>>> 	bool (*stream_is_active)(struct vsock_sock *);
>>> 	bool (*stream_allow)(u32 cid, u32 port);
>>>
>>> +	/* SEQ_PACKET. */
>>> +	size_t (*seqpacket_seq_get_len)(struct vsock_sock *);
>>> +	ssize_t (*seqpacket_dequeue)(struct vsock_sock *, struct msghdr *,
>>> +				     size_t len, int flags);
>>> +
>>> 	/* Notification. */
>>> 	int (*notify_poll_in)(struct vsock_sock *, size_t, bool *);
>>> 	int (*notify_poll_out)(struct vsock_sock *, size_t, bool *);
>>> diff --git a/net/vmw_vsock/af_vsock.c b/net/vmw_vsock/af_vsock.c
>>> index 524df8fc84cd..3b266880b7c8 100644
>>> --- a/net/vmw_vsock/af_vsock.c
>>> +++ b/net/vmw_vsock/af_vsock.c
>>> @@ -2006,7 +2006,107 @@ static int __vsock_stream_recvmsg(struct sock *sk, struct msghdr *msg,
>>> static int __vsock_seqpacket_recvmsg(struct sock *sk, struct msghdr *msg,
>>> 				     size_t len, int flags)
>>> {
>>> -	return -1;
>>> +	const struct vsock_transport *transport;
>>> +	const struct iovec *orig_iov;
>>> +	unsigned long orig_nr_segs;
>>> +	ssize_t dequeued_total = 0;
>>> +	struct vsock_sock *vsk;
>>> +	size_t record_len;
>>> +	long timeout;
>>> +	int err = 0;
>>> +	DEFINE_WAIT(wait);
>>> +
>>> +	vsk = vsock_sk(sk);
>>> +	transport = vsk->transport;
>>> +
>>> +	timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
>>> +	msg->msg_flags &= ~MSG_EOR;
>> Maybe add a comment about why we need to clear MSG_EOR.
>>
>>> +	orig_nr_segs = msg->msg_iter.nr_segs;
>>> +	orig_iov = msg->msg_iter.iov;
>>> +
>>> +	while (1) {
>>> +		ssize_t dequeued;
>>> +		s64 ready;
>>> +
>>> +		prepare_to_wait(sk_sleep(sk), &wait, TASK_INTERRUPTIBLE);
>>> +		ready = vsock_stream_has_data(vsk);
>>> +
>>> +		if (ready == 0) {
>>> +			if (vsock_wait_data(sk, &wait, timeout, NULL, 0)) {
>>> +				/* In case of any loop break(timeout, signal
>>> +				 * interrupt or shutdown), we report user that
>>> +				 * nothing was copied.
>>> +				 */
>>> +				dequeued_total = 0;
>>> +				break;
>>> +			}
>>> +			continue;
>>> +		}
>>> +
>>> +		finish_wait(sk_sleep(sk), &wait);
>>> +
>>> +		if (ready < 0) {
>>> +			err = -ENOMEM;
>>> +			goto out;
>>> +		}
>>> +
>>> +		if (dequeued_total == 0) {
>>> +			record_len =
>>> +				transport->seqpacket_seq_get_len(vsk);
>>> +
>>> +			if (record_len == 0)
>>> +				continue;
>>> +		}
>>> +
>>> +		/* 'msg_iter.count' is number of unused bytes in iov.
>>> +		 * On every copy to iov iterator it is decremented at
>>> +		 * size of data.
>>> +		 */
>>> +		dequeued = transport->seqpacket_dequeue(vsk, msg,
>>> +					msg->msg_iter.count, flags);
>>                                          ^
>>                                          Is this needed or 'msg' can be
>>                                          used in the transport?
>Yes, right
>>> +
>>> +		if (dequeued < 0) {
>>> +			dequeued_total = 0;
>>> +
>>> +			if (dequeued == -EAGAIN) {
>>> +				iov_iter_init(&msg->msg_iter, READ,
>>> +					      orig_iov, orig_nr_segs,
>>> +					      len);
>>> +				msg->msg_flags &= ~MSG_EOR;
>>> +				continue;
>> Why we need to reset MSG_EOR here?
>
>Because if previous attempt to receive record was failed, but
>
>MSG_EOR was set, so we clear it for next attempt to get record

Yes, I saw later when I looked at the implementation in the transport.

Maybe better to put a comment saying that seqpacket_dequeue() can set 
that flag.

Thanks,
Stefano

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

  parent reply	other threads:[~2021-01-29  9:22 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20210125110903.597155-1-arseny.krasnov@kaspersky.com>
2021-01-26 11:23 ` [RFC PATCH v3 00/13] virtio/vsock: introduce SOCK_SEQPACKET support Stefano Garzarella
     [not found] ` <20210125111131.597930-1-arseny.krasnov@kaspersky.com>
2021-01-28 16:10   ` [RFC PATCH v3 01/13] af_vsock: prepare for " Stefano Garzarella
     [not found] ` <20210125111200.598103-1-arseny.krasnov@kaspersky.com>
2021-01-28 16:32   ` [RFC PATCH v3 02/13] af_vsock: prepare 'vsock_connectible_recvmsg()' Stefano Garzarella
     [not found] ` <20210125111239.598377-1-arseny.krasnov@kaspersky.com>
2021-01-28 16:55   ` [RFC PATCH v3 03/13] af_vsock: implement SEQPACKET rx loop Stefano Garzarella
     [not found]     ` <5e000f18-1457-068d-10c5-0a349c938497@kaspersky.com>
2021-01-29  9:21       ` Stefano Garzarella [this message]
     [not found] ` <20210125111321.598653-1-arseny.krasnov@kaspersky.com>
2021-01-28 17:04   ` [RFC PATCH v3 05/13] af_vsock: rest of SEQPACKET support Stefano Garzarella
2021-01-28 17:19 ` [RFC PATCH v3 00/13] virtio/vsock: introduce SOCK_SEQPACKET support Stefano Garzarella
     [not found]   ` <63459bb3-da22-b2a4-71ee-e67660fd2e12@kaspersky.com>
2021-01-29  9:26     ` Stefano Garzarella
     [not found]       ` <cb6d5a9c-fd49-a9dd-33b3-52027ae2f71c@kaspersky.com>
2021-02-01 11:02         ` Stefano Garzarella
     [not found]           ` <1b80eb27-4818-50d7-7454-ff6cc398422e@kaspersky.com>
2021-02-01 14:23             ` Stefano Garzarella
     [not found]               ` <a8ff5600-c166-ee75-1e62-06ae127e2352@kaspersky.com>
2021-02-01 14:34                 ` Stefano Garzarella
     [not found] ` <20210125111402.598929-1-arseny.krasnov@kaspersky.com>
2021-01-29 10:28   ` [RFC PATCH v3 07/13] virtio/vsock: dequeue callback for SOCK_SEQPACKET Stefano Garzarella
     [not found] ` <20210125111444.599211-1-arseny.krasnov@kaspersky.com>
2021-01-29 10:55   ` [RFC PATCH v3 09/13] virtio/vsock: add SEQPACKET receive logic Stefano Garzarella
     [not found] ` <20210125111529.599448-1-arseny.krasnov@kaspersky.com>
2021-01-29 11:03   ` [RFC PATCH v3 10/13] virtio/vsock: rest of SOCK_SEQPACKET support Stefano Garzarella
     [not found]     ` <83775d60-29c0-2da0-a87f-11c1f0a3102b@kaspersky.com>
2021-02-01 11:04       ` Stefano Garzarella
     [not found] ` <20210125111652.599950-1-arseny.krasnov@kaspersky.com>
2021-01-29 11:16   ` [RFC PATCH v3 13/13] vsock_test: add SOCK_SEQPACKET tests Stefano Garzarella

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210129092158.tm2bdwpqufsneaxw@steredhat \
    --to=sgarzare@redhat.com \
    --cc=andraprs@amazon.com \
    --cc=arseny.krasnov@kaspersky.com \
    --cc=colin.king@canonical.com \
    --cc=davem@davemloft.net \
    --cc=jeffv@google.com \
    --cc=kuba@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=oxffffaa@gmail.com \
    --cc=stefanha@redhat.com \
    --cc=stsp2@yandex.ru \
    --cc=virtualization@lists.linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox