Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4868677ybi; Tue, 28 May 2019 03:59:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqzA3WsYD136BVDMdUkE2b/HASrFfJIx9xtQ6tnCPxUo6DK6dAuN/zg7AUz20vV4h6JV2Usa X-Received: by 2002:aa7:8c1a:: with SMTP id c26mr142573622pfd.25.1559041166850; Tue, 28 May 2019 03:59:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559041166; cv=none; d=google.com; s=arc-20160816; b=QW/yWE4XVDDAYKSlkYgfd80Vn1zVXR4bW+vYz2oJJafrF9udYDN0ebSCLprw9t0f5R ni1oSd2zYKPP7qV14oYLXKQKjjcUOavnfMf6IgnLqv3mjuApfbfe2lozg12YnmA4HY2u uMQtJnBh2ygYGH034f6mCUeGfJ0mTxZrYCh0xHumgJuakpwxPAU5J5P17y65fytG/8tL 7Air7l7vVa21W014uhXr3liFJYVvot3Zcp6YBz9Yz9ZLOu6mMfwK2ONcjLcz9fyW9n4H QmsYdeCdZgw6gAB+MLN82AUWAY4bZNxtNWMcbVCl2z7WgiPmHYMFEZ+DZNlCTGyTxsdw 1WpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=LeMIWij/emZe6bEyHg7+7Hm/uaDzkeNXfSulw22LFVI=; b=bWfeUJHsDhXnOCKpO6jlbNFbTzSAxuNNdjOj1S2XIBSdhbZVESyKTUW437woKcGqP7 WMD7qnpbFrHu25sFzMMr26pw5pyiKexHOE/FBXCGGLI9rvuU4FlRKAJpowzBFWyGRWij ayD4zNWlYEgtBdwrB1uzpNpaBWcjBeDJpGaWOmcWuQLrKwtK9adKy/arqpuh2LI9IULS G5aqpUIK8Jfo+1MLKA8MPpU36VS0pLObsdkRO/1sG8GXARI4ChgBRiESY6Zvi/G6vt+p JAl7hYVuEDq2wG9h0xpU8Y0evVGZLm8IbCtSCuiDryG8jM+FyrrRIci5dss0WkdLYvaB AzpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p91si23529363plb.165.2019.05.28.03.59.11; Tue, 28 May 2019 03:59:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726982AbfE1K4y (ORCPT + 99 others); Tue, 28 May 2019 06:56:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55006 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726912AbfE1K4r (ORCPT ); Tue, 28 May 2019 06:56:47 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 70E1CF74CF; Tue, 28 May 2019 10:56:47 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-117-13.ams2.redhat.com [10.36.117.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F19260BE2; Tue, 28 May 2019 10:56:45 +0000 (UTC) From: Stefano Garzarella To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, kvm@vger.kernel.org, Stefan Hajnoczi , "David S. Miller" , "Michael S . Tsirkin" Subject: [PATCH 4/4] vsock/virtio: free used buffers during the .remove() Date: Tue, 28 May 2019 12:56:23 +0200 Message-Id: <20190528105623.27983-5-sgarzare@redhat.com> In-Reply-To: <20190528105623.27983-1-sgarzare@redhat.com> References: <20190528105623.27983-1-sgarzare@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 28 May 2019 10:56:47 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Before this patch, we only freed unused buffers, but there may still be used buffers to be freed. Signed-off-by: Stefano Garzarella --- net/vmw_vsock/virtio_transport.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index ad093ce96693..6a2afb989562 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -669,6 +669,18 @@ static void virtio_vsock_flush_works(struct virtio_vsock *vsock) flush_work(&vsock->send_pkt_work); } +static void virtio_vsock_free_buf(struct virtqueue *vq) +{ + struct virtio_vsock_pkt *pkt; + unsigned int len; + + while ((pkt = virtqueue_detach_unused_buf(vq))) + virtio_transport_free_pkt(pkt); + + while ((pkt = virtqueue_get_buf(vq, &len))) + virtio_transport_free_pkt(pkt); +} + static void virtio_vsock_remove(struct virtio_device *vdev) { struct virtio_vsock *vsock = vdev->priv; @@ -702,13 +714,11 @@ static void virtio_vsock_remove(struct virtio_device *vdev) vdev->config->reset(vdev); mutex_lock(&vsock->rx_lock); - while ((pkt = virtqueue_detach_unused_buf(vsock->vqs[VSOCK_VQ_RX]))) - virtio_transport_free_pkt(pkt); + virtio_vsock_free_buf(vsock->vqs[VSOCK_VQ_RX]); mutex_unlock(&vsock->rx_lock); mutex_lock(&vsock->tx_lock); - while ((pkt = virtqueue_detach_unused_buf(vsock->vqs[VSOCK_VQ_TX]))) - virtio_transport_free_pkt(pkt); + virtio_vsock_free_buf(vsock->vqs[VSOCK_VQ_TX]); mutex_unlock(&vsock->tx_lock); spin_lock_bh(&vsock->send_pkt_list_lock); -- 2.20.1