From: Arseny Krasnov <arseny.krasnov@kaspersky.com>
To: Stefano Garzarella <sgarzare@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
Jorgen Hansen <jhansen@vmware.com>,
Andra Paraschiv <andraprs@amazon.com>,
Colin Ian King <colin.king@canonical.com>,
Norbert Slusarek <nslusarek@gmx.net>,
Jeff Vander Stoep <jeffv@google.com>,
Alexander Popov <alex.popov@linux.com>, kvm <kvm@vger.kernel.org>,
Linux Virtualization <virtualization@lists.linux-foundation.org>,
netdev <netdev@vger.kernel.org>,
kernel list <linux-kernel@vger.kernel.org>,
stsp <stsp2@yandex.ru>, Krasnov Arseniy <oxffffaa@gmail.com>
Subject: Re: [RFC PATCH v8 11/19] virtio/vsock: dequeue callback for SOCK_SEQPACKET
Date: Wed, 21 Apr 2021 17:49:44 +0300 [thread overview]
Message-ID: <51549e2a-f549-e860-67f4-dd06b8922c5c@kaspersky.com> (raw)
In-Reply-To: <CAGxU2F7pCfVow7B5KG4hSYjxyH2LcL3wriRvrgURTxeqzn8M9A@mail.gmail.com>
On 21.04.2021 11:56, Stefano Garzarella wrote:
> On Tue, Apr 13, 2021 at 03:44:40PM +0300, Arseny Krasnov wrote:
>> This adds transport callback and it's logic for SEQPACKET dequeue.
>> Callback fetches RW packets from rx queue of socket until whole record
>> is copied(if user's buffer is full, user is not woken up). This is done
>> to not stall sender, because if we wake up user and it leaves syscall,
>> nobody will send credit update for rest of record, and sender will wait
>> for next enter of read syscall at receiver's side. So if user buffer is
>> full, we just send credit update and drop data.
>>
>> Signed-off-by: Arseny Krasnov <arseny.krasnov@kaspersky.com>
>> ---
>> v7 -> v8:
>> - Things like SEQ_BEGIN, SEQ_END, 'msg_len' and 'msg_id' now removed.
>> This callback fetches and copies RW packets to user's buffer, until
>> last packet of message found(this packet is marked in 'flags' field
>> of header).
>>
>> include/linux/virtio_vsock.h | 5 ++
>> net/vmw_vsock/virtio_transport_common.c | 73 +++++++++++++++++++++++++
>> 2 files changed, 78 insertions(+)
>>
>> diff --git a/include/linux/virtio_vsock.h b/include/linux/virtio_vsock.h
>> index dc636b727179..02acf6e9ae04 100644
>> --- a/include/linux/virtio_vsock.h
>> +++ b/include/linux/virtio_vsock.h
>> @@ -80,6 +80,11 @@ virtio_transport_dgram_dequeue(struct vsock_sock *vsk,
>> struct msghdr *msg,
>> size_t len, int flags);
>>
>> +ssize_t
>> +virtio_transport_seqpacket_dequeue(struct vsock_sock *vsk,
>> + struct msghdr *msg,
>> + int flags,
>> + bool *msg_ready);
>> s64 virtio_transport_stream_has_data(struct vsock_sock *vsk);
>> s64 virtio_transport_stream_has_space(struct vsock_sock *vsk);
>>
>> diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
>> index 833104b71a1c..8492b8bd5df5 100644
>> --- a/net/vmw_vsock/virtio_transport_common.c
>> +++ b/net/vmw_vsock/virtio_transport_common.c
>> @@ -393,6 +393,67 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk,
>> return err;
>> }
>>
>> +static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk,
>> + struct msghdr *msg,
>> + int flags,
>> + bool *msg_ready)
>> +{
>> + struct virtio_vsock_sock *vvs = vsk->trans;
>> + struct virtio_vsock_pkt *pkt;
>> + int err = 0;
>> + size_t user_buf_len = msg->msg_iter.count;
>> +
>> + *msg_ready = false;
>> + spin_lock_bh(&vvs->rx_lock);
>> +
>> + while (!*msg_ready && !list_empty(&vvs->rx_queue) && err >= 0) {
>> + pkt = list_first_entry(&vvs->rx_queue, struct virtio_vsock_pkt, list);
>> +
>> + if (le16_to_cpu(pkt->hdr.op) == VIRTIO_VSOCK_OP_RW) {
> Is this check still necessary, should they all be RW?
Ack
>
>> + size_t bytes_to_copy;
>> + size_t pkt_len;
>> +
>> + pkt_len = (size_t)le32_to_cpu(pkt->hdr.len);
>> + bytes_to_copy = min(user_buf_len, pkt_len);
>> +
> If bytes_to_copy == 0, we can avoid the next steps (release the lock try
> to copy 0 bytes, reacquire the lock)
Ack
>
>> + /* sk_lock is held by caller so no one else can dequeue.
>> + * Unlock rx_lock since memcpy_to_msg() may sleep.
>> + */
>> + spin_unlock_bh(&vvs->rx_lock);
>> +
>> + if (memcpy_to_msg(msg, pkt->buf, bytes_to_copy)) {
>> + err = -EINVAL;
> Here we should reacquire the lock or prevent it from being released out
> of cycle.
Ack
>
>> + break;
>> + }
>> +
>> + spin_lock_bh(&vvs->rx_lock);
>> +
> As mentioned before, I think we could move this part into the core and
> here always return the real dimension.
Ack
>
>> + /* If user sets 'MSG_TRUNC' we return real
>> length
>> + * of message.
>> + */
>> + if (flags & MSG_TRUNC)
>> + err += pkt_len;
>> + else
>> + err += bytes_to_copy;
>> +
>> + user_buf_len -= bytes_to_copy;
>> +
>> + if (pkt->hdr.flags & VIRTIO_VSOCK_SEQ_EOR)
> ^
> We should use le32_to_cpu() to read the flags.
>
Ack
>> + *msg_ready = true;
>> + }
>> +
>> + virtio_transport_dec_rx_pkt(vvs, pkt);
>> + list_del(&pkt->list);
>> + virtio_transport_free_pkt(pkt);
>> + }
>> +
>> + spin_unlock_bh(&vvs->rx_lock);
>> +
>> + virtio_transport_send_credit_update(vsk);
>> +
>> + return err;
>> +}
>> +
>> ssize_t
>> virtio_transport_stream_dequeue(struct vsock_sock *vsk,
>> struct msghdr *msg,
>> @@ -405,6 +466,18 @@ virtio_transport_stream_dequeue(struct vsock_sock *vsk,
>> }
>> EXPORT_SYMBOL_GPL(virtio_transport_stream_dequeue);
>>
>> +ssize_t
>> +virtio_transport_seqpacket_dequeue(struct vsock_sock *vsk,
>> + struct msghdr *msg,
>> + int flags, bool *msg_ready)
>> +{
>> + if (flags & MSG_PEEK)
>> + return -EOPNOTSUPP;
>> +
>> + return virtio_transport_seqpacket_do_dequeue(vsk, msg, flags,
>> msg_ready);
>> +}
>> +EXPORT_SYMBOL_GPL(virtio_transport_seqpacket_dequeue);
>> +
>> int
>> virtio_transport_dgram_dequeue(struct vsock_sock *vsk,
>> struct msghdr *msg,
>> --
>> 2.25.1
>>
>
next prev parent reply other threads:[~2021-04-21 14:49 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-13 12:39 [RFC PATCH v8 00/19] virtio/vsock: introduce SOCK_SEQPACKET support Arseny Krasnov
2021-04-13 12:41 ` [RFC PATCH v8 01/19] af_vsock: update functions for connectible socket Arseny Krasnov
2021-04-13 12:42 ` [RFC PATCH v8 02/19] af_vsock: separate wait data loop Arseny Krasnov
2021-04-13 12:42 ` [RFC PATCH v8 03/19] af_vsock: separate receive " Arseny Krasnov
2021-04-13 12:42 ` [RFC PATCH v8 04/19] af_vsock: implement SEQPACKET receive loop Arseny Krasnov
2021-04-21 8:37 ` Stefano Garzarella
2021-04-21 14:47 ` Arseny Krasnov
2021-04-13 12:43 ` [RFC PATCH v8 05/19] af_vsock: implement send logic for SEQPACKET Arseny Krasnov
2021-04-13 12:43 ` [RFC PATCH v8 06/19] af_vsock: rest of SEQPACKET support Arseny Krasnov
2021-04-13 12:43 ` [RFC PATCH v8 07/19] af_vsock: update comments for stream sockets Arseny Krasnov
2021-04-13 12:43 ` [RFC PATCH v8 08/19] virtio/vsock: set packet's type in virtio_transport_send_pkt_info() Arseny Krasnov
2021-04-13 12:44 ` [RFC PATCH v8 09/19] virtio/vsock: simplify credit update function API Arseny Krasnov
2021-04-13 12:44 ` [RFC PATCH v8 10/19] virtio/vsock: defines and constants for SEQPACKET Arseny Krasnov
2021-04-13 12:44 ` [RFC PATCH v8 11/19] virtio/vsock: dequeue callback for SOCK_SEQPACKET Arseny Krasnov
2021-04-14 5:21 ` Arseny Krasnov
2021-04-21 8:56 ` Stefano Garzarella
2021-04-21 14:49 ` Arseny Krasnov [this message]
2021-04-13 12:45 ` [RFC PATCH v8 12/19] virtio/vsock: add SEQPACKET receive logic Arseny Krasnov
2021-04-13 12:45 ` [RFC PATCH v8 13/19] virtio/vsock: rest of SOCK_SEQPACKET support Arseny Krasnov
2021-04-21 9:12 ` Stefano Garzarella
2021-04-21 14:50 ` Arseny Krasnov
2021-04-13 12:45 ` [RFC PATCH v8 14/19] virtio/vsock: enable SEQPACKET for transport Arseny Krasnov
2021-04-21 9:22 ` Stefano Garzarella
2021-04-13 12:46 ` [RFC PATCH v8 15/19] vhost/vsock: " Arseny Krasnov
2021-04-21 9:31 ` Stefano Garzarella
2021-04-13 12:46 ` [RFC PATCH v8 16/19] vsock/loopback: " Arseny Krasnov
2021-04-21 9:34 ` Stefano Garzarella
2021-04-13 12:46 ` [RFC PATCH v8 17/19] vsock_test: add SOCK_SEQPACKET tests Arseny Krasnov
2021-04-21 9:35 ` Stefano Garzarella
2021-04-21 15:00 ` Arseny Krasnov
2021-04-13 12:47 ` [RFC PATCH v8 18/19] virtio/vsock: update trace event for SEQPACKET Arseny Krasnov
2021-04-13 12:47 ` [RFC PATCH v8 19/19] af_vsock: serialize writes to shared socket Arseny Krasnov
2021-04-14 10:51 ` Arseny Krasnov
2021-04-21 9:38 ` Stefano Garzarella
2021-04-21 15:02 ` Arseny Krasnov
2021-04-21 9:52 ` [RFC PATCH v8 00/19] virtio/vsock: introduce SOCK_SEQPACKET support Stefano Garzarella
2021-04-21 15:06 ` Arseny Krasnov
2021-04-22 8:46 ` Stefano Garzarella
2021-04-22 9:40 ` Arseny Krasnov
2021-04-22 10:02 ` Stefano Garzarella
2021-04-22 10:29 ` Arseny Krasnov
2021-04-22 10:48 ` Stefano Garzarella
2021-04-22 11:41 ` Arseny Krasnov
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=51549e2a-f549-e860-67f4-dd06b8922c5c@kaspersky.com \
--to=arseny.krasnov@kaspersky.com \
--cc=alex.popov@linux.com \
--cc=andraprs@amazon.com \
--cc=colin.king@canonical.com \
--cc=davem@davemloft.net \
--cc=jasowang@redhat.com \
--cc=jeffv@google.com \
--cc=jhansen@vmware.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=nslusarek@gmx.net \
--cc=oxffffaa@gmail.com \
--cc=sgarzare@redhat.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;
as well as URLs for NNTP newsgroup(s).