Re: [PATCH v2] vsock/virtio: add support for MSG_PEEK

2019-09-30 Thread Stefano Garzarella
Hi Matias,

On Fri, Sep 27, 2019 at 04:44:23PM +, Matias Ezequiel Vara Larsen wrote:
> This patch adds support for MSG_PEEK. In such a case, packets are not
> removed from the rx_queue and credit updates are not sent.
> 
> Signed-off-by: Matias Ezequiel Vara Larsen 
> ---
>  net/vmw_vsock/virtio_transport_common.c | 55 
> +++--
>  1 file changed, 52 insertions(+), 3 deletions(-)

The patch LGTM. As David pointed out, this patch should go into net-next.
Since now net-next is open, you can resend with net-next tag [1] and
with:

Reviewed-by: Stefano Garzarella 
Tested-by: Stefano Garzarella 

Thanks,
Stefano

[1] https://www.kernel.org/doc/Documentation/networking/netdev-FAQ.txt
> 
> diff --git a/net/vmw_vsock/virtio_transport_common.c 
> b/net/vmw_vsock/virtio_transport_common.c
> index 94cc0fa..cf15751 100644
> --- a/net/vmw_vsock/virtio_transport_common.c
> +++ b/net/vmw_vsock/virtio_transport_common.c
> @@ -264,6 +264,55 @@ static int virtio_transport_send_credit_update(struct 
> vsock_sock *vsk,
>  }
>  
>  static ssize_t
> +virtio_transport_stream_do_peek(struct vsock_sock *vsk,
> + struct msghdr *msg,
> + size_t len)
> +{
> + struct virtio_vsock_sock *vvs = vsk->trans;
> + struct virtio_vsock_pkt *pkt;
> + size_t bytes, total = 0, off;
> + int err = -EFAULT;
> +
> + spin_lock_bh(>rx_lock);
> +
> + list_for_each_entry(pkt, >rx_queue, list) {
> + off = pkt->off;
> +
> + if (total == len)
> + break;
> +
> + while (total < len && off < pkt->len) {
> + bytes = len - total;
> + if (bytes > pkt->len - off)
> + bytes = pkt->len - off;
> +
> + /* sk_lock is held by caller so no one else can dequeue.
> +  * Unlock rx_lock since memcpy_to_msg() may sleep.
> +  */
> + spin_unlock_bh(>rx_lock);
> +
> + err = memcpy_to_msg(msg, pkt->buf + off, bytes);
> + if (err)
> + goto out;
> +
> + spin_lock_bh(>rx_lock);
> +
> + total += bytes;
> + off += bytes;
> + }
> + }
> +
> + spin_unlock_bh(>rx_lock);
> +
> + return total;
> +
> +out:
> + if (total)
> + err = total;
> + return err;
> +}
> +
> +static ssize_t
>  virtio_transport_stream_do_dequeue(struct vsock_sock *vsk,
>  struct msghdr *msg,
>  size_t len)
> @@ -330,9 +379,9 @@ virtio_transport_stream_dequeue(struct vsock_sock *vsk,
>   size_t len, int flags)
>  {
>   if (flags & MSG_PEEK)
> - return -EOPNOTSUPP;
> -
> - return virtio_transport_stream_do_dequeue(vsk, msg, len);
> + return virtio_transport_stream_do_peek(vsk, msg, len);
> + else
> + return virtio_transport_stream_do_dequeue(vsk, msg, len);
>  }
>  EXPORT_SYMBOL_GPL(virtio_transport_stream_dequeue);
>  
> -- 
> 2.7.4
> 

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


Re: [PATCH v2] vsock/virtio: add support for MSG_PEEK

2019-09-27 Thread David Miller


This is net-next material.
___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


[PATCH v2] vsock/virtio: add support for MSG_PEEK

2019-09-27 Thread Matias Ezequiel Vara Larsen
This patch adds support for MSG_PEEK. In such a case, packets are not
removed from the rx_queue and credit updates are not sent.

Signed-off-by: Matias Ezequiel Vara Larsen 
---
 net/vmw_vsock/virtio_transport_common.c | 55 +++--
 1 file changed, 52 insertions(+), 3 deletions(-)

diff --git a/net/vmw_vsock/virtio_transport_common.c 
b/net/vmw_vsock/virtio_transport_common.c
index 94cc0fa..cf15751 100644
--- a/net/vmw_vsock/virtio_transport_common.c
+++ b/net/vmw_vsock/virtio_transport_common.c
@@ -264,6 +264,55 @@ static int virtio_transport_send_credit_update(struct 
vsock_sock *vsk,
 }
 
 static ssize_t
+virtio_transport_stream_do_peek(struct vsock_sock *vsk,
+   struct msghdr *msg,
+   size_t len)
+{
+   struct virtio_vsock_sock *vvs = vsk->trans;
+   struct virtio_vsock_pkt *pkt;
+   size_t bytes, total = 0, off;
+   int err = -EFAULT;
+
+   spin_lock_bh(>rx_lock);
+
+   list_for_each_entry(pkt, >rx_queue, list) {
+   off = pkt->off;
+
+   if (total == len)
+   break;
+
+   while (total < len && off < pkt->len) {
+   bytes = len - total;
+   if (bytes > pkt->len - off)
+   bytes = pkt->len - off;
+
+   /* sk_lock is held by caller so no one else can dequeue.
+* Unlock rx_lock since memcpy_to_msg() may sleep.
+*/
+   spin_unlock_bh(>rx_lock);
+
+   err = memcpy_to_msg(msg, pkt->buf + off, bytes);
+   if (err)
+   goto out;
+
+   spin_lock_bh(>rx_lock);
+
+   total += bytes;
+   off += bytes;
+   }
+   }
+
+   spin_unlock_bh(>rx_lock);
+
+   return total;
+
+out:
+   if (total)
+   err = total;
+   return err;
+}
+
+static ssize_t
 virtio_transport_stream_do_dequeue(struct vsock_sock *vsk,
   struct msghdr *msg,
   size_t len)
@@ -330,9 +379,9 @@ virtio_transport_stream_dequeue(struct vsock_sock *vsk,
size_t len, int flags)
 {
if (flags & MSG_PEEK)
-   return -EOPNOTSUPP;
-
-   return virtio_transport_stream_do_dequeue(vsk, msg, len);
+   return virtio_transport_stream_do_peek(vsk, msg, len);
+   else
+   return virtio_transport_stream_do_dequeue(vsk, msg, len);
 }
 EXPORT_SYMBOL_GPL(virtio_transport_stream_dequeue);
 
-- 
2.7.4

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