From nobody Sat May 18 02:36:52 2024 Delivered-To: importer@patchew.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=1608996927; cv=none; d=zohomail.com; s=zohoarc; b=gSuQ+rMj/+coiGL8jx8EI1o00JW/ndb5Az80ZJVpbCm9XbfD0BK85HOmUR0Cvns50H70cgaiDB2ZbJV2YtUMQtihIdUCymIQKynyu0c5LtfG6TAFgY5S/CZ8rkXGACizYlmNtoiNs7j/6YBAqwOZd9PpaSASJUsvcPzm4mEpLQs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608996927; h=Content-Type:Content-Transfer-Encoding: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=dUzQOh2+y2tI4zzEon+4SakuZ72949EUgq9H/s4vtxs=; b=QCCR7v5Md+EgbHnsZpmBXYC36KOMNLTRUYCuDwjiDrE7cZEm84rKYLSMv8MKGM8Swknhd3vbxkh3OI1PWnK92/TRF8uuX4uZj6KqF0gcBAXtvsTI5K9b4yIFB43/YMmdkhrIQ+U3ZOSufaVMuOB/0Y7drdw/gs0ppHgQ2iYX5QQ= 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 1608996927892493.7069550582671; Sat, 26 Dec 2020 07:35:27 -0800 (PST) Received: from localhost ([::1]:36034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ktAGp-00064f-Nm for importer@patchew.org; Sat, 26 Dec 2020 09:10:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52466) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kt6u1-0002Di-Dt; Sat, 26 Dec 2020 05:34:25 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:2628) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kt6ty-0004nK-Hy; Sat, 26 Dec 2020 05:34:24 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4D30X3040qz7GcD; Sat, 26 Dec 2020 18:33:23 +0800 (CST) Received: from DESKTOP-EDHIELA.china.huawei.com (10.174.187.50) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Sat, 26 Dec 2020 18:34:01 +0800 From: g00517791 To: , Subject: [PATCH 1/8] vmbus: Fix memory leak of vmstate_gpadl Date: Sat, 26 Dec 2020 18:33:40 +0800 Message-ID: <20201226103347.868-2-gaojinhao@huawei.com> X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: <20201226103347.868-1-gaojinhao@huawei.com> References: <20201226103347.868-1-gaojinhao@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.187.50] X-CFilter-Loop: Reflected 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; Received-SPF: pass client-ip=45.249.212.35; envelope-from=gaojinhao@huawei.com; helo=szxga07-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 26 Dec 2020 09:05:44 -0500 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: "Michael S . Tsirkin" , Jason Wang , Stefan Berger , Greg Kurz , "Dr . David Alan Gilbert" , Juan Quintela , wanghaibin.wang@huawei.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , zhukeqian1@huawei.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Jinhao Gao When VM migrate VMState of vmbus/gpadl, the field(gfns) of vmbus/ gpadl having a flag of VMS_ALLOC needs to allocate memory. If the dst doesn't free memory which has been allocated for SaveStateEntry of vmbus/gpadl before dst loads device state, it may result that the pointer of gfns is overlaid when vm loads. We add the pre_load func to free memory, which prevents memory leak. Signed-off-by: Jinhao Gao --- hw/hyperv/vmbus.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c index 896e981f85..a91623aaac 100644 --- a/hw/hyperv/vmbus.c +++ b/hw/hyperv/vmbus.c @@ -519,10 +519,21 @@ void vmbus_unmap_sgl(VMBusChanReq *req, DMADirection = dir, struct iovec *iov, } } =20 +static int vmbus_gpadl_pre_load(void *opaque) +{ + VMBusGpadl *gpadl =3D VMBusGpadl(opaque); + + g_free(gpadl->gfns); + gpadl->gfns =3D NULL; + gpadl->num_gfns =3D0; + return 0; +} + static const VMStateDescription vmstate_gpadl =3D { .name =3D "vmbus/gpadl", .version_id =3D 0, .minimum_version_id =3D 0, + .pre_load =3D vmbus_gpadl_pre_load, .fields =3D (VMStateField[]) { VMSTATE_UINT32(id, VMBusGpadl), VMSTATE_UINT32(child_relid, VMBusGpadl), --=20 2.23.0 From nobody Sat May 18 02:36:52 2024 Delivered-To: importer@patchew.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=1608994753; cv=none; d=zohomail.com; s=zohoarc; b=MHLiICRjSUl2QPmP49+Qc/urFcf3NMgyVcRcq+1yFCuz6qZk/yB0n2U2n4CmPkrh6DO6ZRl1sFy8IlInnoK2dHiS5sSeRvhx07VN4n40XBg02ws9ELUU08Ong8VaN3sOhv1fMF3CVRb83oOPULpIRQ9HAQwmwl3hJ9DeXPvU3LY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608994753; h=Content-Type:Content-Transfer-Encoding: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=jTnyFumowqbaljRB3e+wz9g72roS05MmjLf6N9755/c=; b=TR/ps+mCANr/lBNpEIUeuuGGs2jsTQwarI2u+aLpTzAMpnQk+dzzvqQe6rbxMhUXBYYiLdst5ql3kmj6ewBa24SrmvHOXmgPnteXbkuVYXHRCMnBSjMs3UuKUc+517xfeNuwSest7LLyaKX6WvDuQhGppZXR0ZFdtdym+akH0aA= 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 1608994753370440.3816903223135; Sat, 26 Dec 2020 06:59:13 -0800 (PST) Received: from localhost ([::1]:56840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ktAEm-00034I-1a for importer@patchew.org; Sat, 26 Dec 2020 09:08:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52510) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kt6u2-0002E1-Ff; Sat, 26 Dec 2020 05:34:26 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:3009) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kt6tz-0004nZ-Br; Sat, 26 Dec 2020 05:34:26 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4D30X23sWGzhslr; Sat, 26 Dec 2020 18:33:22 +0800 (CST) Received: from DESKTOP-EDHIELA.china.huawei.com (10.174.187.50) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Sat, 26 Dec 2020 18:34:02 +0800 From: g00517791 To: , Subject: [PATCH 2/8] virtio-net: Fix memory leak of vmstate_virtio_net_rss Date: Sat, 26 Dec 2020 18:33:41 +0800 Message-ID: <20201226103347.868-3-gaojinhao@huawei.com> X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: <20201226103347.868-1-gaojinhao@huawei.com> References: <20201226103347.868-1-gaojinhao@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.187.50] X-CFilter-Loop: Reflected 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; Received-SPF: pass client-ip=45.249.212.191; envelope-from=gaojinhao@huawei.com; helo=szxga05-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 26 Dec 2020 09:05:44 -0500 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: "Michael S . Tsirkin" , Jason Wang , Stefan Berger , Greg Kurz , "Dr . David Alan Gilbert" , Juan Quintela , wanghaibin.wang@huawei.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , zhukeqian1@huawei.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Jinhao Gao When VM migrate VMState of virtio-net-device/rss, the field(rss_data. indirections_table) of virtio-net-device/rss having a flag of VMS_ALLOC needs to allocate memory. If the dst doesn't free memory which has bee n allocated for SaveStateEntry of virtio-net-device/rss before dst loads device state, it may result that the pointer of rss_data.indirections_table is overlaid when vm loads. We add the pre_load func to free memory, which prevents memory leak. Signed-off-by: Jinhao Gao --- hw/net/virtio-net.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 044ac95f6f..102e51f32f 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -2957,11 +2957,22 @@ static bool virtio_net_rss_needed(void *opaque) return VIRTIO_NET(opaque)->rss_data.enabled; } =20 +static int virtio_net_rss_pre_load(void *opaque) +{ + VirtIONet *n =3D VIRTIO_NET(opaque); + + g_free(n->rss_data.indirections_table); + n->rss_data.indirections_table =3D NULL; + n->rss_data.indirections_len =3D 0; + return 0; +} + static const VMStateDescription vmstate_virtio_net_rss =3D { .name =3D "virtio-net-device/rss", .version_id =3D 1, .minimum_version_id =3D 1, .needed =3D virtio_net_rss_needed, + .pre_load =3D virtio_net_rss_pre_load, .fields =3D (VMStateField[]) { VMSTATE_BOOL(rss_data.enabled, VirtIONet), VMSTATE_BOOL(rss_data.redirect, VirtIONet), --=20 2.23.0 From nobody Sat May 18 02:36:52 2024 Delivered-To: importer@patchew.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=1608997532; cv=none; d=zohomail.com; s=zohoarc; b=NxECmS0378YJ/U7eENhPmL+s4IPQorSdUfwPpVmG140nNQZdStvVcE1uhHdnrEEluFEy8W8yTrLYRmSGV5MKsoZaFBH/MlPtnNIUy91tVqAMZ3K6hYbQwD+XifocZhk9n0EWXCI7ZUDCQqqUcyZItvaT5nW6L6070uOO8nG01V8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608997532; h=Content-Type:Content-Transfer-Encoding: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=qT7odj31M0FRxz8hoXjla2wZcLyssXGxCZjryTosdxc=; b=ESl/gbgx/HDYCFQGH7igEdKuszHSUBpiM9/FqZ46m8gGe+Zr3kZJhLi7XNPOrYMZ24BNAF1riq0OxzbryQiGYYytLO8gRrHHUgO/jcNCl0GEVRRrHXlidbQJEcWWTd/exnleGa9MNloV7f97wHGMc7hZOKorey4SQrjtxPdyVA4= 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 1608997532235251.86293666201288; Sat, 26 Dec 2020 07:45:32 -0800 (PST) Received: from localhost ([::1]:44092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ktAMT-00017W-D6 for importer@patchew.org; Sat, 26 Dec 2020 09:16:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kt6u3-0002EP-46; Sat, 26 Dec 2020 05:34:27 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:2575) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kt6tz-0004oj-DZ; Sat, 26 Dec 2020 05:34:26 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4D30XK0msFzhtvh; Sat, 26 Dec 2020 18:33:37 +0800 (CST) Received: from DESKTOP-EDHIELA.china.huawei.com (10.174.187.50) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Sat, 26 Dec 2020 18:34:03 +0800 From: g00517791 To: , Subject: [PATCH 3/8] spapr: Fix memory leak of vmstate_spapr_event_entry Date: Sat, 26 Dec 2020 18:33:42 +0800 Message-ID: <20201226103347.868-4-gaojinhao@huawei.com> X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: <20201226103347.868-1-gaojinhao@huawei.com> References: <20201226103347.868-1-gaojinhao@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.187.50] X-CFilter-Loop: Reflected 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; Received-SPF: pass client-ip=45.249.212.32; envelope-from=gaojinhao@huawei.com; helo=szxga06-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 26 Dec 2020 09:05:45 -0500 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: "Michael S . Tsirkin" , Jason Wang , Stefan Berger , Greg Kurz , "Dr . David Alan Gilbert" , Juan Quintela , wanghaibin.wang@huawei.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , zhukeqian1@huawei.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Jinhao Gao When VM migrate VMState of spapr_event_log_entry, the field(extended_log) of spapr_event_log_entry having a flag of VMS_ALLOC needs to allocate memory. If the dst doesn't free memory which has been allocated for SaveStateEntry of spapr_event_log_entry before dst loads device state, it may result that the pointer of extended_log is overlaid when vm loads. We add the pre_load func to free memory, which prevents memory leak. Signed-off-by: Jinhao Gao Acked-by: David Gibson --- hw/ppc/spapr.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 489cefcb81..ddfed1e7ca 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1799,10 +1799,22 @@ static bool spapr_pending_events_needed(void *opaqu= e) return !QTAILQ_EMPTY(&spapr->pending_events); } =20 +static int spapr_event_log_entry_pre_load(void *opaque) +{ + SpaprEventLogEntry *entry =3D opaque; + + g_free(entry->extended_log); + entry->extended_log =3D NULL; + entry->extended_length =3D 0; + + return 0; +} + static const VMStateDescription vmstate_spapr_event_entry =3D { .name =3D "spapr_event_log_entry", .version_id =3D 1, .minimum_version_id =3D 1, + .pre_load =3D spapr_event_log_entry_pre_load, .fields =3D (VMStateField[]) { VMSTATE_UINT32(summary, SpaprEventLogEntry), VMSTATE_UINT32(extended_length, SpaprEventLogEntry), --=20 2.23.0 From nobody Sat May 18 02:36:52 2024 Delivered-To: importer@patchew.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=1608997471; cv=none; d=zohomail.com; s=zohoarc; b=T+YQ5MgxtnJgn0OczTVmuYdou5ov5dhyikrq6Lao0DVM35MxIapFtpUb+zlCkgfh7e/nVVxlHijRNX1awrml73hV/iFfSvqkr9870slwcpCwGCvnzFTgffhH0UK54cA9P9lV2UExldceljVM0LxPsazT1MD0/mgPke3zLyuxGOY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608997471; h=Content-Type:Content-Transfer-Encoding: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=ZNFWq1NCPqO+TccVkrOsV6199tjVX6uwjmL6/Un1CU4=; b=UzRqbq40Q68vjsg8Z/BNxv8AcmvD6n6aQ/1e6OxBjgNKtq7FRN7Vwry6KQJZtV0pwoUZRRPgZPoNaRNyx9/Ylkvah8ujU6DkO1buM1QUCYqh4KnMG7d8U/mf84qTEqE/VSDXyax6DGkxSkd5S5FNS4XGNHbjPab17JlY1DSc7To= 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 160899747117054.47375383547228; Sat, 26 Dec 2020 07:44:31 -0800 (PST) Received: from localhost ([::1]:40834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ktAJR-0008AT-Ck for importer@patchew.org; Sat, 26 Dec 2020 09:12:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52568) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kt6uC-0002Iv-D1; Sat, 26 Dec 2020 05:34:37 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:3011) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kt6uA-0004oZ-Na; Sat, 26 Dec 2020 05:34:36 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4D30X7476mzhySd; Sat, 26 Dec 2020 18:33:27 +0800 (CST) Received: from DESKTOP-EDHIELA.china.huawei.com (10.174.187.50) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Sat, 26 Dec 2020 18:34:04 +0800 From: g00517791 To: , Subject: [PATCH 4/8] spapr_pci: Fix memory leak of vmstate_spapr_pci Date: Sat, 26 Dec 2020 18:33:43 +0800 Message-ID: <20201226103347.868-5-gaojinhao@huawei.com> X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: <20201226103347.868-1-gaojinhao@huawei.com> References: <20201226103347.868-1-gaojinhao@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.187.50] X-CFilter-Loop: Reflected 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; Received-SPF: pass client-ip=45.249.212.191; envelope-from=gaojinhao@huawei.com; helo=szxga05-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 26 Dec 2020 09:05:46 -0500 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: "Michael S . Tsirkin" , Jason Wang , Stefan Berger , Greg Kurz , "Dr . David Alan Gilbert" , Juan Quintela , wanghaibin.wang@huawei.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , zhukeqian1@huawei.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Jinhao Gao When VM migrate VMState of spapr_pci, the field(msi_devs) of spapr_pci having a flag of VMS_ALLOC need to allocate memory. If the src doesn't free memory of msi_devs in SaveStateEntry of spapr_pci after QEMUFile save VMState of spapr_pci, it may result in memory leak of msi_devs. We add the post_save func to free memory, which prevents memory leak. Signed-off-by: Jinhao Gao Acked-by: David Gibson --- hw/ppc/spapr_pci.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 76d7c91e9c..1b2b940606 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -2173,6 +2173,16 @@ static int spapr_pci_pre_save(void *opaque) return 0; } =20 +static int spapr_pci_post_save(void *opaque) +{ + SpaprPhbState *sphb =3D opaque; + + g_free(sphb->msi_devs); + sphb->msi_devs =3D NULL; + sphb->msi_devs_num =3D 0; + return 0; +} + static int spapr_pci_post_load(void *opaque, int version_id) { SpaprPhbState *sphb =3D opaque; @@ -2205,6 +2215,7 @@ static const VMStateDescription vmstate_spapr_pci =3D= { .version_id =3D 2, .minimum_version_id =3D 2, .pre_save =3D spapr_pci_pre_save, + .post_save =3D spapr_pci_post_save, .post_load =3D spapr_pci_post_load, .fields =3D (VMStateField[]) { VMSTATE_UINT64_EQUAL(buid, SpaprPhbState, NULL), --=20 2.23.0 From nobody Sat May 18 02:36:52 2024 Delivered-To: importer@patchew.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=1608996929; cv=none; d=zohomail.com; s=zohoarc; b=do6Y/iYMA3NsA2PAp8mS3aRo0w6nI3wpKkGSR7h/1d4wd+xEPf/Kz+W2JzNxD09k/MIa68vv6phXh3IdKz4pyqCzLzV1bjXPxoCagJ/rLDfavcJvMYJfg/QStebCSn70j0QeSBPeqWW6bLq80KhbH759OiL5NeaH/s7SCymyqyU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608996929; h=Content-Type:Content-Transfer-Encoding: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=8bJ6do8x2rxUfcwEtaI3U8yxFU1IkipNzl0L0h7L11I=; b=HpgVjyBM/TJSF+HQMzXDOVouefA1ImscIE/FwDfje7Nc9sE5uFg7pLGG3B1OnrepaCIrJt0km/dgv6QPzC+5n4JoQibmPT/AEuqjRsUopWNodExbIJEwbknQLrL6FFw6dwRBgozW3f0Nym2XXewSqtO8ZnIjwqH/puMrh9DnKg8= 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 1608996929920576.7707752568866; Sat, 26 Dec 2020 07:35:29 -0800 (PST) Received: from localhost ([::1]:36012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ktAGp-000642-Bd for importer@patchew.org; Sat, 26 Dec 2020 09:10:11 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kt6u2-0002E5-La; Sat, 26 Dec 2020 05:34:26 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:3013) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kt6tz-0004of-5b; Sat, 26 Dec 2020 05:34:26 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4D30X74gKZzhyTy; Sat, 26 Dec 2020 18:33:27 +0800 (CST) Received: from DESKTOP-EDHIELA.china.huawei.com (10.174.187.50) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Sat, 26 Dec 2020 18:34:04 +0800 From: g00517791 To: , Subject: [PATCH 5/8] savevm: Fix memory leak of vmstate_configuration Date: Sat, 26 Dec 2020 18:33:44 +0800 Message-ID: <20201226103347.868-6-gaojinhao@huawei.com> X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: <20201226103347.868-1-gaojinhao@huawei.com> References: <20201226103347.868-1-gaojinhao@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.187.50] X-CFilter-Loop: Reflected 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; Received-SPF: pass client-ip=45.249.212.191; envelope-from=gaojinhao@huawei.com; helo=szxga05-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 26 Dec 2020 09:05:44 -0500 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: "Michael S . Tsirkin" , Jason Wang , Stefan Berger , Greg Kurz , "Dr . David Alan Gilbert" , Juan Quintela , wanghaibin.wang@huawei.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , zhukeqian1@huawei.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Jinhao Gao When VM migrate VMState of configuration, the fields(name and capabilities) of configuration having a flag of VMS_ALLOC need to allocate memory. If the src doesn't free memory of capabilities in SaveState after save VMState of configuration, or the dst doesn't free memory of name and capabilities in p= ost load of configuration, it may result in memory leak of name and capabilitie= s. We free memory in configuration_post_save and configuration_post_load func, which prevents memory leak. Signed-off-by: Jinhao Gao --- migration/savevm.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/migration/savevm.c b/migration/savevm.c index 5f937a2762..13f1a5dab7 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -314,6 +314,16 @@ static int configuration_pre_save(void *opaque) return 0; } =20 +static int configuration_post_save(void *opaque) +{ + SaveState *state =3D opaque; + + g_free(state->capabilities); + state->capabilities =3D NULL; + state->caps_count =3D 0; + return 0; +} + static int configuration_pre_load(void *opaque) { SaveState *state =3D opaque; @@ -364,24 +374,36 @@ static int configuration_post_load(void *opaque, int = version_id) { SaveState *state =3D opaque; const char *current_name =3D MACHINE_GET_CLASS(current_machine)->name; + int ret =3D 0; =20 if (strncmp(state->name, current_name, state->len) !=3D 0) { error_report("Machine type received is '%.*s' and local is '%s'", (int) state->len, state->name, current_name); - return -EINVAL; + ret =3D -EINVAL; + goto out; } =20 if (state->target_page_bits !=3D qemu_target_page_bits()) { error_report("Received TARGET_PAGE_BITS is %d but local is %d", state->target_page_bits, qemu_target_page_bits()); - return -EINVAL; + ret =3D -EINVAL; + goto out; } =20 if (!configuration_validate_capabilities(state)) { - return -EINVAL; + ret =3D -EINVAL; + goto out; } =20 - return 0; +out: + g_free((void *)state->name); + state->name =3D NULL; + state->len =3D 0; + g_free(state->capabilities); + state->capabilities =3D NULL; + state->caps_count =3D 0; + + return ret; } =20 static int get_capability(QEMUFile *f, void *pv, size_t size, @@ -515,6 +537,7 @@ static const VMStateDescription vmstate_configuration = =3D { .pre_load =3D configuration_pre_load, .post_load =3D configuration_post_load, .pre_save =3D configuration_pre_save, + .post_save =3D configuration_post_save, .fields =3D (VMStateField[]) { VMSTATE_UINT32(len, SaveState), VMSTATE_VBUFFER_ALLOC_UINT32(name, SaveState, 0, NULL, len), --=20 2.23.0 From nobody Sat May 18 02:36:52 2024 Delivered-To: importer@patchew.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=1609000590; cv=none; d=zohomail.com; s=zohoarc; b=O0VZ5mFUIM/OTbeM4IfXy8TF4E9fr5hX5R28wPM0XKEYx8nTCAnklatX9u/O9PMODRszdNvZ722msQ1Q6a5W43MrvCFVc21c1m13cRKzY2hgv4ZjQ4TkG9HT8Y/Qgu+iU7/5AO1LhK+O7tMNNWyucZ3IE5u51xTJnxKNkGdWLtw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609000590; h=Content-Type:Content-Transfer-Encoding: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=3gT41ukWEOxom3PfcPJpiTUYuET93fVYILQz+J95bao=; b=hNKZXevTb+neYEo8qgZYYcgsHRpwsDxJ42QidQev5X+gLPwNOr+6LQTfLS34uwf48gIIqvIYFMG/TkxdxUR0aE002hq8TosL46OUfhAtIyX0WbW0VC28EGyCNYpg8z3uStJlxUTkq58fmP6SQ25oBYICcmXzu+fN2fTsB6xcxFk= 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 1609000590026346.6525438507409; Sat, 26 Dec 2020 08:36:30 -0800 (PST) Received: from localhost ([::1]:47912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ktAQP-00032a-Cd for importer@patchew.org; Sat, 26 Dec 2020 09:20:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kt6u5-0002FA-Hw; Sat, 26 Dec 2020 05:34:31 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:3014) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kt6u3-0004sn-Qe; Sat, 26 Dec 2020 05:34:29 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4D30X74xYtzhyVK; Sat, 26 Dec 2020 18:33:27 +0800 (CST) Received: from DESKTOP-EDHIELA.china.huawei.com (10.174.187.50) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Sat, 26 Dec 2020 18:34:05 +0800 From: g00517791 To: , Subject: [PATCH 6/8] vmbus: Fix memory leak of vmstate_vmbus_chan_req Date: Sat, 26 Dec 2020 18:33:45 +0800 Message-ID: <20201226103347.868-7-gaojinhao@huawei.com> X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: <20201226103347.868-1-gaojinhao@huawei.com> References: <20201226103347.868-1-gaojinhao@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.187.50] X-CFilter-Loop: Reflected 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; Received-SPF: pass client-ip=45.249.212.191; envelope-from=gaojinhao@huawei.com; helo=szxga05-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 26 Dec 2020 09:05:46 -0500 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: "Michael S . Tsirkin" , Jason Wang , Stefan Berger , Greg Kurz , "Dr . David Alan Gilbert" , Juan Quintela , wanghaibin.wang@huawei.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , zhukeqian1@huawei.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Jinhao Gao When VM migrate VMState of vmbus/vmbus_chan_req, the field(msg) of vmbus/vmbus_chan_req having a flag of VMS_ALLOC needs to allocate memory. If the dst doesn't free memory which has been allocated for SaveStateEntry of vmbus/vmbus_chan_req before dst loads device state, it may result that the pointer of msg is overlaid when vm loads. We add the pre_load func to free memory, which prevents memory leak. Signed-off-by: Jinhao Gao --- hw/hyperv/vmbus.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/hyperv/vmbus.c b/hw/hyperv/vmbus.c index a91623aaac..9eda2341f3 100644 --- a/hw/hyperv/vmbus.c +++ b/hw/hyperv/vmbus.c @@ -1303,10 +1303,21 @@ typedef struct VMBusChanReqSave { ScatterGatherEntry *sgl; } VMBusChanReqSave; =20 +static int vmbus_chan_req_pre_load(void *opaque) +{ + VMBusChanReqSave *req_save =3D VMBusChanReqSave(opaque); + + g_free(req_save.msg); + req_save.msg =3D NULL; + req_save.msglen =3D 0; + return 0; +} + static const VMStateDescription vmstate_vmbus_chan_req =3D { .name =3D "vmbus/vmbus_chan_req", .version_id =3D 0, .minimum_version_id =3D 0, + .pre_load =3D vmbus_chan_req_pre_load, .fields =3D (VMStateField[]) { VMSTATE_UINT16(chan_idx, VMBusChanReqSave), VMSTATE_UINT16(pkt_type, VMBusChanReqSave), --=20 2.23.0 From nobody Sat May 18 02:36:52 2024 Delivered-To: importer@patchew.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=1608994751; cv=none; d=zohomail.com; s=zohoarc; b=D2kEGeNE3OBhrWMtxZjURrvt05JcYSK0qeIsP6LE91uU0UzyT9W78kI+/q+PlRx88t5NcWqebYWGv6drfriVgTrNTZPrneUK1+qzMzmefBJzB/6C2jUUVAXY/WCPI0gj37x5lqjS2ZGbSbRItGV4wYsXx46Vpyvg0mahxSFGWgM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608994751; h=Content-Type:Content-Transfer-Encoding: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=Zaykg4jRmx4dx46Ur86nqHqBrCqurF9EBDRuk6ta4kA=; b=QAACvLwWajNmhVbphlqBd5svPD+IC1cef/nxzmrf6Yyq6nulcRe08wqYuss5fB2fK1CbmREi4iuQcBTKyIAe50OQ7zQyFDoyUDKDY4CRi+3ogEWueSWW2baIpimC0C3jIV7rpNf5koPCjqVUeAHqIie8yyXHs9y331YwMLTfwiw= 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 160899475131515.072740593568483; Sat, 26 Dec 2020 06:59:11 -0800 (PST) Received: from localhost ([::1]:56834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ktAEm-00034B-Az for importer@patchew.org; Sat, 26 Dec 2020 09:08:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52540) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kt6u5-0002F3-5J; Sat, 26 Dec 2020 05:34:29 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:3012) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kt6u3-0004oc-5O; Sat, 26 Dec 2020 05:34:28 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4D30X74PLtzhyV3; Sat, 26 Dec 2020 18:33:27 +0800 (CST) Received: from DESKTOP-EDHIELA.china.huawei.com (10.174.187.50) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Sat, 26 Dec 2020 18:34:06 +0800 From: g00517791 To: , Subject: [PATCH 7/8] tpm_emulator: Fix memory leak of vmstate_tpm_emulator Date: Sat, 26 Dec 2020 18:33:46 +0800 Message-ID: <20201226103347.868-8-gaojinhao@huawei.com> X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: <20201226103347.868-1-gaojinhao@huawei.com> References: <20201226103347.868-1-gaojinhao@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.187.50] X-CFilter-Loop: Reflected 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; Received-SPF: pass client-ip=45.249.212.191; envelope-from=gaojinhao@huawei.com; helo=szxga05-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 26 Dec 2020 09:05:46 -0500 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: "Michael S . Tsirkin" , Jason Wang , Stefan Berger , Greg Kurz , "Dr . David Alan Gilbert" , Juan Quintela , wanghaibin.wang@huawei.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , zhukeqian1@huawei.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Jinhao Gao When VM migrate VMState of tpm-emulator, the fields(state_blobs. permanent.buffer, state_blobs.volatil.buffer and state_blobs.savestate. buffer) of tpm-emulator having a flag of VMS_ALLOC need to allocate memory. If the dst doesn't free memory which has been allocated for SaveStateEntry of tpm-emulator before dst loads device state, it may result that the pointers of state_blobs.permanent.buffer, state_blobs. volatil.buffer and state_blobs.savestate.buffer are overlaid when vm loads. We add the pre_load func to free memory, which prevents memory leak. Signed-off-by: Jinhao Gao --- backends/tpm/tpm_emulator.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c index a012adc193..7ffa95dbce 100644 --- a/backends/tpm/tpm_emulator.c +++ b/backends/tpm/tpm_emulator.c @@ -857,6 +857,18 @@ static int tpm_emulator_pre_save(void *opaque) return tpm_emulator_get_state_blobs(tpm_emu); } =20 +static int tpm_emulator_pre_load(void *opaque) +{ + TPMBackend *tb =3D opaque; + TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); + TPMBlobBuffers *state_blobs =3D &tpm_emu->state_blobs; + + tpm_sized_buffer_reset(&state_blobs->volatil); + tpm_sized_buffer_reset(&state_blobs->permanent); + tpm_sized_buffer_reset(&state_blobs->savestate); + return 0; +} + /* * Load the TPM state blobs into the TPM. * @@ -883,6 +895,7 @@ static const VMStateDescription vmstate_tpm_emulator = =3D { .name =3D "tpm-emulator", .version_id =3D 0, .pre_save =3D tpm_emulator_pre_save, + .pre_load =3D tpm_emulator_pre_load, .post_load =3D tpm_emulator_post_load, .fields =3D (VMStateField[]) { VMSTATE_UINT32(state_blobs.permanent_flags, TPMEmulator), --=20 2.23.0 From nobody Sat May 18 02:36:52 2024 Delivered-To: importer@patchew.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=1608996977; cv=none; d=zohomail.com; s=zohoarc; b=Pt8SZQckTcQ00Q438S3YlNw3tNbcTX8yUqufL6lE620gyeSZQqWqblfFYSa0Dub+AiVRJ/xHLdwbtuknKqaif547JfsjvFKyI1uzblq/VZi3+mlWK6xDzR+LKGZX/wzIVdTfRYFRjRAjbyj4l6moujJL94puns4hFUMs5TGNBWI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608996977; h=Content-Type:Content-Transfer-Encoding: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=9fZHh9OEP5z2negB1vofma/e+JbhdcHUDRcQ95o2BHI=; b=k2BccAkAFLuD/7aOxo+7bHu7tmo6yO1F7idWxuzogxTCQMpHps1ZM9C8Svo6SeBtm17aRfjBvfmZCLvCLAPZsJJgLtDety3FwKMGc8RczhEgbqFqWJPqY8YEjIcgTzTbBZdoyLqVD6QMGWO/3YHpuct86DHkwxwgSPCFIr8zUqA= 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 1608996977397236.72769674933215; Sat, 26 Dec 2020 07:36:17 -0800 (PST) Received: from localhost ([::1]:40388 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ktAJ7-0007xQ-80 for importer@patchew.org; Sat, 26 Dec 2020 09:12:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52514) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kt6u2-0002ED-RI; Sat, 26 Dec 2020 05:34:26 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:2576) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kt6tz-0004ol-Cz; Sat, 26 Dec 2020 05:34:26 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4D30XK15ZvzhvJN; Sat, 26 Dec 2020 18:33:37 +0800 (CST) Received: from DESKTOP-EDHIELA.china.huawei.com (10.174.187.50) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Sat, 26 Dec 2020 18:34:07 +0800 From: g00517791 To: , Subject: [PATCH 8/8] dbus-vmstate: Fix memory leak of dbus_vmstate Date: Sat, 26 Dec 2020 18:33:47 +0800 Message-ID: <20201226103347.868-9-gaojinhao@huawei.com> X-Mailer: git-send-email 2.29.2.windows.2 In-Reply-To: <20201226103347.868-1-gaojinhao@huawei.com> References: <20201226103347.868-1-gaojinhao@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.174.187.50] X-CFilter-Loop: Reflected 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; Received-SPF: pass client-ip=45.249.212.32; envelope-from=gaojinhao@huawei.com; helo=szxga06-in.huawei.com X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Sat, 26 Dec 2020 09:05:44 -0500 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: "Michael S . Tsirkin" , Jason Wang , Stefan Berger , Greg Kurz , "Dr . David Alan Gilbert" , Juan Quintela , wanghaibin.wang@huawei.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , zhukeqian1@huawei.com, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Jinhao Gao When VM migrate VMState of dbus_vmstate, the field(data) of dbus_vmstate having a flag of VMS_ALLOC needs to allocate memory. If the dst doesn't free memory which has been allocated for SaveStateEntry of dbus_vmstate before dst loads device state, it may result that the pointer of data is overlaid when vm loads. We add the pre_load func to free memory, which prevents memory leak. Signed-off-by: Jinhao Gao --- backends/dbus-vmstate.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/backends/dbus-vmstate.c b/backends/dbus-vmstate.c index bd050e8e9c..c13fbee760 100644 --- a/backends/dbus-vmstate.c +++ b/backends/dbus-vmstate.c @@ -366,10 +366,21 @@ static int dbus_vmstate_pre_save(void *opaque) return 0; } =20 +static int dbus_vmstate_pre_load(void *opaque) +{ + DBusVMState *self =3D DBUS_VMSTATE(opaque); + + g_free(self->data); + self->data =3D NULL; + self->data_size =3D 0; + return 0; +} + static const VMStateDescription dbus_vmstate =3D { .name =3D TYPE_DBUS_VMSTATE, .version_id =3D 0, .pre_save =3D dbus_vmstate_pre_save, + .pre_load =3D dbus_vmstate_pre_load, .post_load =3D dbus_vmstate_post_load, .fields =3D (VMStateField[]) { VMSTATE_UINT32(data_size, DBusVMState), --=20 2.23.0