From nobody Sun Feb 8 20:34:23 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537364396549147.57844810704069; Wed, 19 Sep 2018 06:39:56 -0700 (PDT) Received: from localhost ([::1]:45526 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2chu-0001ss-Ji for importer@patchew.org; Wed, 19 Sep 2018 09:39:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2ce9-0007vo-Ow for qemu-devel@nongnu.org; Wed, 19 Sep 2018 09:36:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2ce6-00034p-IT for qemu-devel@nongnu.org; Wed, 19 Sep 2018 09:35:59 -0400 Received: from smtp.nue.novell.com ([195.135.221.5]:39010) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2ce6-00033V-7U for qemu-devel@nongnu.org; Wed, 19 Sep 2018 09:35:58 -0400 Received: from localhost.localdomain ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (NOT encrypted); Wed, 19 Sep 2018 15:35:54 +0200 From: Fei Li To: qemu-devel@nongnu.org Date: Wed, 19 Sep 2018 21:35:20 +0800 Message-Id: <20180919133523.13351-5-fli@suse.com> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180919133523.13351-1-fli@suse.com> References: <20180919133523.13351-1-fli@suse.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.135.221.5 Subject: [Qemu-devel] [PATCH RFC v3 4/7] migration: fix the compression code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, peterx@redhat.comc, armbru@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add judgement in compress_threads_save_cleanup() to check whether the static CompressParam *comp_param has been allocated. If not, just return; or else Segmentation fault will occur when using the NULL comp_param's parameters in terminate_compression_threads(). One test case can reproduce this error is: set the compression on and migrate to a wrong nonexistent host IP address. Add judgement before handling comp_param[idx]'s quit and cond in terminate_compression_threads(), in case they are not initialized. Or else "qemu_mutex_lock_impl: Assertion `mutex->initialized' failed." will occur. One test case can reproduce this error is: set the compression on and fail to fully setup the eight compression thread in compress_threads_save_setup(). Signed-off-by: Fei Li --- migration/ram.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index 79c89425a3..522a5550b4 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -427,6 +427,9 @@ static inline void terminate_compression_threads(void) thread_count =3D migrate_compress_threads(); =20 for (idx =3D 0; idx < thread_count; idx++) { + if (!comp_param[idx].mutex.initialized) { + break; + } qemu_mutex_lock(&comp_param[idx].mutex); comp_param[idx].quit =3D true; qemu_cond_signal(&comp_param[idx].cond); @@ -438,7 +441,7 @@ static void compress_threads_save_cleanup(void) { int i, thread_count; =20 - if (!migrate_use_compression()) { + if (!migrate_use_compression() || !comp_param) { return; } terminate_compression_threads(); --=20 2.13.7