public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Bobby Eshleman <bobbyeshleman@gmail.com>
To: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
Cc: Stefan Hajnoczi <stefanha@redhat.com>,
	Stefano Garzarella <sgarzare@redhat.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	Bobby Eshleman <bobby.eshleman@bytedance.com>,
	kvm@vger.kernel.org, virtualization@lists.linux-foundation.org,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel@sberdevices.ru, oxffffaa@gmail.com
Subject: Re: [RFC PATCH v1 1/4] virtio/vsock: rework MSG_PEEK for SOCK_STREAM
Date: Tue, 27 Jun 2023 01:32:37 +0000	[thread overview]
Message-ID: <ZJo8NTRCjBTdZyOT@bullseye> (raw)
In-Reply-To: <20230618062451.79980-2-AVKrasnov@sberdevices.ru>

On Sun, Jun 18, 2023 at 09:24:48AM +0300, Arseniy Krasnov wrote:
> This reworks current implementation of MSG_PEEK logic:
> 1) Replaces 'skb_queue_walk_safe()' with 'skb_queue_walk()'. There is
>    no need in the first one, as there are no removes of skb in loop.
> 2) Removes nested while loop - MSG_PEEK logic could be implemented
>    without it: just iterate over skbs without removing it and copy
>    data from each until destination buffer is not full.
> 
> Signed-off-by: Arseniy Krasnov <AVKrasnov@sberdevices.ru>
> ---
>  net/vmw_vsock/virtio_transport_common.c | 41 ++++++++++++-------------
>  1 file changed, 19 insertions(+), 22 deletions(-)
> 
> diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c
> index b769fc258931..2ee40574c339 100644
> --- a/net/vmw_vsock/virtio_transport_common.c
> +++ b/net/vmw_vsock/virtio_transport_common.c
> @@ -348,37 +348,34 @@ virtio_transport_stream_do_peek(struct vsock_sock *vsk,
>  				size_t len)
>  {
>  	struct virtio_vsock_sock *vvs = vsk->trans;
> -	size_t bytes, total = 0, off;
> -	struct sk_buff *skb, *tmp;
> -	int err = -EFAULT;
> +	struct sk_buff *skb;
> +	size_t total = 0;
> +	int err;
>  
>  	spin_lock_bh(&vvs->rx_lock);
>  
> -	skb_queue_walk_safe(&vvs->rx_queue, skb,  tmp) {
> -		off = 0;
> +	skb_queue_walk(&vvs->rx_queue, skb) {
> +		size_t bytes;
>  
> -		if (total == len)
> -			break;
> +		bytes = len - total;
> +		if (bytes > skb->len)
> +			bytes = skb->len;
>  
> -		while (total < len && off < skb->len) {
> -			bytes = len - total;
> -			if (bytes > skb->len - off)
> -				bytes = skb->len - off;
> +		spin_unlock_bh(&vvs->rx_lock);
>  
> -			/* 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);
> +		/* sk_lock is held by caller so no one else can dequeue.
> +		 * Unlock rx_lock since memcpy_to_msg() may sleep.
> +		 */
> +		err = memcpy_to_msg(msg, skb->data, bytes);
> +		if (err)
> +			goto out;
>  
> -			err = memcpy_to_msg(msg, skb->data + off, bytes);
> -			if (err)
> -				goto out;
> +		total += bytes;
>  
> -			spin_lock_bh(&vvs->rx_lock);
> +		spin_lock_bh(&vvs->rx_lock);
>  
> -			total += bytes;
> -			off += bytes;
> -		}
> +		if (total == len)
> +			break;
>  	}
>  
>  	spin_unlock_bh(&vvs->rx_lock);
> -- 
> 2.25.1
> 

That cleans up nicely!

LGTM.

Reviewed-by: Bobby Eshleman <bobby.eshleman@bytedance.com>

  parent reply	other threads:[~2023-06-27 17:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-18  6:24 [RFC PATCH v1 0/4] virtio/vsock: some updates for MSG_PEEK flag Arseniy Krasnov
2023-06-18  6:24 ` [RFC PATCH v1 1/4] virtio/vsock: rework MSG_PEEK for SOCK_STREAM Arseniy Krasnov
2023-06-26 16:23   ` Stefano Garzarella
2023-06-27  1:32   ` Bobby Eshleman [this message]
2023-06-18  6:24 ` [RFC PATCH v1 2/4] virtio/vsock: support MSG_PEEK for SOCK_SEQPACKET Arseniy Krasnov
2023-06-26 16:28   ` Stefano Garzarella
2023-06-27  4:34     ` Arseniy Krasnov
2023-06-27  7:48       ` Stefano Garzarella
2023-06-18  6:24 ` [RFC PATCH v1 3/4] vsock/test: rework MSG_PEEK test for SOCK_STREAM Arseniy Krasnov
2023-06-18  6:24 ` [RFC PATCH v1 4/4] vsock/test: MSG_PEEK test for SOCK_SEQPACKET Arseniy Krasnov
2023-06-26 16:30 ` [RFC PATCH v1 0/4] virtio/vsock: some updates for MSG_PEEK flag Stefano Garzarella
2023-06-27 11:58   ` Arseniy 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=ZJo8NTRCjBTdZyOT@bullseye \
    --to=bobbyeshleman@gmail.com \
    --cc=AVKrasnov@sberdevices.ru \
    --cc=bobby.eshleman@bytedance.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jasowang@redhat.com \
    --cc=kernel@sberdevices.ru \
    --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=pabeni@redhat.com \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --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