Re: [PATCH v2 2/8] vsock/virtio: free packets during the socket release
On Thu, May 16, 2019 at 04:32:18PM +0100, Stefan Hajnoczi wrote: > On Fri, May 10, 2019 at 02:58:37PM +0200, Stefano Garzarella wrote: > > When the socket is released, we should free all packets > > queued in the per-socket list in order to avoid a memory > > leak. > > > > Signed-off-by: Stefano Garzarella > > --- > > net/vmw_vsock/virtio_transport_common.c | 8 > > 1 file changed, 8 insertions(+) > > Ouch, this would be nice as a separate patch that can be merged right > away (with s/virtio_vsock_buf/virtio_vsock_pkt/). Okay, I'll fix this patch following the David's comment and I'll send as a separate patch using the virtio_vsock_pkt. Thanks, Stefano ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH v2 2/8] vsock/virtio: free packets during the socket release
On Fri, May 10, 2019 at 02:58:37PM +0200, Stefano Garzarella wrote: > When the socket is released, we should free all packets > queued in the per-socket list in order to avoid a memory > leak. > > Signed-off-by: Stefano Garzarella > --- > net/vmw_vsock/virtio_transport_common.c | 8 > 1 file changed, 8 insertions(+) Ouch, this would be nice as a separate patch that can be merged right away (with s/virtio_vsock_buf/virtio_vsock_pkt/). signature.asc Description: PGP signature ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH v2 2/8] vsock/virtio: free packets during the socket release
On Fri, May 10, 2019 at 03:20:08PM -0700, David Miller wrote: > From: Stefano Garzarella > Date: Fri, 10 May 2019 14:58:37 +0200 > > > @@ -827,12 +827,20 @@ static bool virtio_transport_close(struct vsock_sock > > *vsk) > > > > void virtio_transport_release(struct vsock_sock *vsk) > > { > > + struct virtio_vsock_sock *vvs = vsk->trans; > > + struct virtio_vsock_buf *buf; > > struct sock *sk = >sk; > > bool remove_sock = true; > > > > lock_sock(sk); > > if (sk->sk_type == SOCK_STREAM) > > remove_sock = virtio_transport_close(vsk); > > + while (!list_empty(>rx_queue)) { > > + buf = list_first_entry(>rx_queue, > > + struct virtio_vsock_buf, list); > > Please use list_for_each_entry_safe(). Thanks for the review, I'll change it in the v3. Cheers, Stefano ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [PATCH v2 2/8] vsock/virtio: free packets during the socket release
From: Stefano Garzarella Date: Fri, 10 May 2019 14:58:37 +0200 > @@ -827,12 +827,20 @@ static bool virtio_transport_close(struct vsock_sock > *vsk) > > void virtio_transport_release(struct vsock_sock *vsk) > { > + struct virtio_vsock_sock *vvs = vsk->trans; > + struct virtio_vsock_buf *buf; > struct sock *sk = >sk; > bool remove_sock = true; > > lock_sock(sk); > if (sk->sk_type == SOCK_STREAM) > remove_sock = virtio_transport_close(vsk); > + while (!list_empty(>rx_queue)) { > + buf = list_first_entry(>rx_queue, > +struct virtio_vsock_buf, list); Please use list_for_each_entry_safe(). ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
[PATCH v2 2/8] vsock/virtio: free packets during the socket release
When the socket is released, we should free all packets queued in the per-socket list in order to avoid a memory leak. Signed-off-by: Stefano Garzarella --- net/vmw_vsock/virtio_transport_common.c | 8 1 file changed, 8 insertions(+) diff --git a/net/vmw_vsock/virtio_transport_common.c b/net/vmw_vsock/virtio_transport_common.c index 0248d6808755..65c8b4a23f2b 100644 --- a/net/vmw_vsock/virtio_transport_common.c +++ b/net/vmw_vsock/virtio_transport_common.c @@ -827,12 +827,20 @@ static bool virtio_transport_close(struct vsock_sock *vsk) void virtio_transport_release(struct vsock_sock *vsk) { + struct virtio_vsock_sock *vvs = vsk->trans; + struct virtio_vsock_buf *buf; struct sock *sk = >sk; bool remove_sock = true; lock_sock(sk); if (sk->sk_type == SOCK_STREAM) remove_sock = virtio_transport_close(vsk); + while (!list_empty(>rx_queue)) { + buf = list_first_entry(>rx_queue, + struct virtio_vsock_buf, list); + list_del(>list); + virtio_transport_free_buf(buf); + } release_sock(sk); if (remove_sock) -- 2.20.1 ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization