From nobody Mon Feb 9 12:00:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1582516746; cv=none; d=zohomail.com; s=zohoarc; b=I3zwDhA/mVTiNHpXM7j6q/sPW9lN58FLic+zZ2N0RPEWWYmhQhJwV58tKbU2FOWuaSaF4r68oRwNAII+DwpZ+7IUid2F3Ilp8yyJ/QvV3mY3V1rV6t3dKz5ON0Akubq6GCq8k47ySj7kQ2mV5HyU4LfBIvcNjTmjLxb6VzF1OkM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582516746; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1RV5Dsj2t9EvprYZTRcgXXmhaisW3tC4jEi8yIAbhVg=; b=glFki1wlIVc47voS3xUlULNtoNUPXulg2S4Bc4c2C+c0L0+Yx1eQWqNDYFTDf8OGBB/aaPe/cnbUDAEkLzvEWvFVNMxRLWnGotTQLaTctJ0TtBp3mMz5/5XUrp9lIY0iERWuqT76pFVU/ZPNoi7HbkSFGLzhv6TsqjcESyGtrk8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582516746034827.2634509883471; Sun, 23 Feb 2020 19:59:06 -0800 (PST) Received: from localhost ([::1]:59392 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j64tc-00034m-Gf for importer@patchew.org; Sun, 23 Feb 2020 22:59:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60131) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j64so-0001cV-GM for qemu-devel@nongnu.org; Sun, 23 Feb 2020 22:58:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j64sn-00065z-Du for qemu-devel@nongnu.org; Sun, 23 Feb 2020 22:58:14 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2725 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j64sk-00062g-Qu; Sun, 23 Feb 2020 22:58:11 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 68B52134498437A9FDAD; Mon, 24 Feb 2020 11:58:02 +0800 (CST) Received: from localhost.localdomain (10.175.104.216) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.439.0; Mon, 24 Feb 2020 11:57:55 +0800 From: To: , , Subject: [PATCH v2 1/2] vhost-user-blk: delete virtioqueues in unrealize to fix memleaks Date: Mon, 24 Feb 2020 12:13:35 +0800 Message-ID: <20200224041336.30790-2-pannengyuan@huawei.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200224041336.30790-1-pannengyuan@huawei.com> References: <20200224041336.30790-1-pannengyuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.216] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.190 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pan Nengyuan , qemu-devel@nongnu.org, qemu-block@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Pan Nengyuan virtio queues forgot to delete in unrealize, and aslo error path in realize, this patch fix these memleaks, the leak stack is as follow: Direct leak of 114688 byte(s) in 16 object(s) allocated from: #0 0x7f24024fdbf0 in calloc (/lib64/libasan.so.3+0xcabf0) #1 0x7f2401642015 in g_malloc0 (/lib64/libglib-2.0.so.0+0x50015) #2 0x55ad175a6447 in virtio_add_queue /mnt/sdb/qemu/hw/virtio/virtio.c:= 2327 #3 0x55ad17570cf9 in vhost_user_blk_device_realize /mnt/sdb/qemu/hw/blo= ck/vhost-user-blk.c:419 #4 0x55ad175a3707 in virtio_device_realize /mnt/sdb/qemu/hw/virtio/virt= io.c:3509 #5 0x55ad176ad0d1 in device_set_realized /mnt/sdb/qemu/hw/core/qdev.c:8= 76 #6 0x55ad1781ff9d in property_set_bool /mnt/sdb/qemu/qom/object.c:2080 #7 0x55ad178245ae in object_property_set_qobject /mnt/sdb/qemu/qom/qom-= qobject.c:26 #8 0x55ad17821eb4 in object_property_set_bool /mnt/sdb/qemu/qom/object.= c:1338 #9 0x55ad177aeed7 in virtio_pci_realize /mnt/sdb/qemu/hw/virtio/virtio-= pci.c:1801 Reported-by: Euler Robot Signed-off-by: Pan Nengyuan Reviewed-by: Stefan Hajnoczi --- v2->v1: There is no change in this patch(only change the patch2/2) --- hw/block/vhost-user-blk.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index d8c459c575..2eba8b9db0 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -460,6 +460,9 @@ reconnect: virtio_err: g_free(s->vqs); g_free(s->inflight); + for (i =3D 0; i < s->num_queues; i++) { + virtio_del_queue(vdev, i); + } virtio_cleanup(vdev); vhost_user_cleanup(&s->vhost_user); } @@ -468,6 +471,7 @@ static void vhost_user_blk_device_unrealize(DeviceState= *dev, Error **errp) { VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); VHostUserBlk *s =3D VHOST_USER_BLK(dev); + int i; =20 virtio_set_status(vdev, 0); qemu_chr_fe_set_handlers(&s->chardev, NULL, NULL, NULL, @@ -476,6 +480,10 @@ static void vhost_user_blk_device_unrealize(DeviceStat= e *dev, Error **errp) vhost_dev_free_inflight(s->inflight); g_free(s->vqs); g_free(s->inflight); + + for (i =3D 0; i < s->num_queues; i++) { + virtio_del_queue(vdev, i); + } virtio_cleanup(vdev); vhost_user_cleanup(&s->vhost_user); } --=20 2.18.2 From nobody Mon Feb 9 12:00:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1582516747; cv=none; d=zohomail.com; s=zohoarc; b=OxU9nRQjepkxoy6xGNeDeR0GLlUqdjpH+2TX9neeM5H5ce554ONdZCXzJyZ/93N2Ah/ffrw+WDzYM/UGWk1cC8Rsyq/lnI7REBoM/jnXUWRD/9tY7u2LVNbdyK6/1VmaAEDQTeLtMz+tb/nFEoYcXn9hfXDO9+gP/H9fFyl5bX4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582516747; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=l8ez7hjqb3KXnZGKWsLJ/YrOA/Xv+wCOBnaZyCoQVzM=; b=i1YO6kBYFS5TsSm7MMcgMJZnC7521TF/HnBuRvIHlip10Zvrs44w3VIZjwKvAUFKMglafpCtjKxgW3JrrWtjOgjuJWlyICoqF3agzOu5tpvVd6jlCGjYbM6CVTjYt4uDkkWWG6+j32DlcgQ9EinEmpZiEf2u2kPzadjWY+FYGtk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582516747903602.0530337419217; Sun, 23 Feb 2020 19:59:07 -0800 (PST) Received: from localhost ([::1]:59394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j64te-000398-Kp for importer@patchew.org; Sun, 23 Feb 2020 22:59:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60128) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j64so-0001cU-Ch for qemu-devel@nongnu.org; Sun, 23 Feb 2020 22:58:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j64sn-00065s-Ap for qemu-devel@nongnu.org; Sun, 23 Feb 2020 22:58:14 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:2724 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j64sk-00062i-RU; Sun, 23 Feb 2020 22:58:11 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 6E2FE300CAFF946C47B1; Mon, 24 Feb 2020 11:58:02 +0800 (CST) Received: from localhost.localdomain (10.175.104.216) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.439.0; Mon, 24 Feb 2020 11:57:56 +0800 From: To: , , Subject: [PATCH v2 2/2] vhost-use-blk: convert to new virtio_delete_queue Date: Mon, 24 Feb 2020 12:13:36 +0800 Message-ID: <20200224041336.30790-3-pannengyuan@huawei.com> X-Mailer: git-send-email 2.18.2 In-Reply-To: <20200224041336.30790-1-pannengyuan@huawei.com> References: <20200224041336.30790-1-pannengyuan@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.104.216] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.190 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pan Nengyuan , qemu-devel@nongnu.org, qemu-block@nongnu.org, zhang.zhanghailiang@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Pan Nengyuan use the new virtio_delete_queue function to cleanup. Signed-off-by: Pan Nengyuan Reviewed-by: Stefan Hajnoczi --- V2->V1: - rename vqs to vhost_vqs to avoid confusing with virtqs (suggented by Stef= an Hajnoczi) --- hw/block/vhost-user-blk.c | 19 +++++++++++-------- include/hw/virtio/vhost-user-blk.h | 3 ++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/hw/block/vhost-user-blk.c b/hw/block/vhost-user-blk.c index 2eba8b9db0..12925a47ec 100644 --- a/hw/block/vhost-user-blk.c +++ b/hw/block/vhost-user-blk.c @@ -306,7 +306,7 @@ static int vhost_user_blk_connect(DeviceState *dev) s->connected =3D true; =20 s->dev.nvqs =3D s->num_queues; - s->dev.vqs =3D s->vqs; + s->dev.vqs =3D s->vhost_vqs; s->dev.vq_index =3D 0; s->dev.backend_features =3D 0; =20 @@ -420,13 +420,14 @@ static void vhost_user_blk_device_realize(DeviceState= *dev, Error **errp) virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK, sizeof(struct virtio_blk_config)); =20 + s->virtqs =3D g_new(VirtQueue *, s->num_queues); for (i =3D 0; i < s->num_queues; i++) { - virtio_add_queue(vdev, s->queue_size, - vhost_user_blk_handle_output); + s->virtqs[i] =3D virtio_add_queue(vdev, s->queue_size, + vhost_user_blk_handle_output); } =20 s->inflight =3D g_new0(struct vhost_inflight, 1); - s->vqs =3D g_new0(struct vhost_virtqueue, s->num_queues); + s->vhost_vqs =3D g_new0(struct vhost_virtqueue, s->num_queues); s->watch =3D 0; s->connected =3D false; =20 @@ -458,11 +459,12 @@ reconnect: return; =20 virtio_err: - g_free(s->vqs); + g_free(s->vhost_vqs); g_free(s->inflight); for (i =3D 0; i < s->num_queues; i++) { - virtio_del_queue(vdev, i); + virtio_delete_queue(s->virtqs[i]); } + g_free(s->virtqs); virtio_cleanup(vdev); vhost_user_cleanup(&s->vhost_user); } @@ -478,12 +480,13 @@ static void vhost_user_blk_device_unrealize(DeviceSta= te *dev, Error **errp) NULL, NULL, NULL, false); vhost_dev_cleanup(&s->dev); vhost_dev_free_inflight(s->inflight); - g_free(s->vqs); + g_free(s->vhost_vqs); g_free(s->inflight); =20 for (i =3D 0; i < s->num_queues; i++) { - virtio_del_queue(vdev, i); + virtio_delete_queue(s->virtqs[i]); } + g_free(s->virtqs); virtio_cleanup(vdev); vhost_user_cleanup(&s->vhost_user); } diff --git a/include/hw/virtio/vhost-user-blk.h b/include/hw/virtio/vhost-u= ser-blk.h index 108bfadeeb..05ea0ad183 100644 --- a/include/hw/virtio/vhost-user-blk.h +++ b/include/hw/virtio/vhost-user-blk.h @@ -36,7 +36,8 @@ typedef struct VHostUserBlk { struct vhost_dev dev; struct vhost_inflight *inflight; VhostUserState vhost_user; - struct vhost_virtqueue *vqs; + struct vhost_virtqueue *vhost_vqs; + VirtQueue **virtqs; guint watch; bool connected; } VHostUserBlk; --=20 2.18.2