From nobody Mon Feb 9 00:37:30 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1537982864591398.5984025633079; Wed, 26 Sep 2018 10:27:44 -0700 (PDT) Received: from localhost ([::1]:59934 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5DbD-0004tf-KE for importer@patchew.org; Wed, 26 Sep 2018 13:27:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g5DNY-00018o-Ns for qemu-devel@nongnu.org; Wed, 26 Sep 2018 13:13:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g5DNX-0008NR-T7 for qemu-devel@nongnu.org; Wed, 26 Sep 2018 13:13:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47590) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g5DNX-0008MR-MQ for qemu-devel@nongnu.org; Wed, 26 Sep 2018 13:13:35 -0400 Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B78A830832E6; Wed, 26 Sep 2018 17:13:34 +0000 (UTC) Received: from dgilbert-t530.redhat.com (unknown [10.36.118.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03264DB564; Wed, 26 Sep 2018 17:13:32 +0000 (UTC) From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, xiaoguangrong@tencent.com, joserz@linux.ibm.com, wei@redhat.com, thuth@redhat.com, marcandre.lureau@redhat.com, fli@suse.com Date: Wed, 26 Sep 2018 18:12:35 +0100 Message-Id: <20180926171236.45203-16-dgilbert@redhat.com> In-Reply-To: <20180926171236.45203-1-dgilbert@redhat.com> References: <20180926171236.45203-1-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 26 Sep 2018 17:13:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 15/16] 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: quintela@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Fei Li 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. One test case can reproduce this is: set the compression on and migrate to a wrong nonexistent host IP address. Our current code does not judge before handling comp_param[idx]'s quit and cond that whether they have been initialized. If not initialized, "qemu_mutex_lock_impl: Assertion `mutex->initialized' failed." will occur. Fix this by squashing the terminate_compression_threads() into compress_threads_save_cleanup() and employing the existing judgement condition. One test case can reproduce this error is: set the compression on and fail to fully setup the default eight compression thread in compress_threads_save_setup(). Signed-off-by: Fei Li Message-Id: <20180925091440.18910-1-fli@suse.com> Reviewed-by: Peter Xu Signed-off-by: Dr. David Alan Gilbert --- migration/ram.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 0fdaa8efa3..408d237700 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -431,28 +431,14 @@ static void *do_data_compress(void *opaque) return NULL; } =20 -static inline void terminate_compression_threads(void) -{ - int idx, thread_count; - - thread_count =3D migrate_compress_threads(); - - for (idx =3D 0; idx < thread_count; idx++) { - qemu_mutex_lock(&comp_param[idx].mutex); - comp_param[idx].quit =3D true; - qemu_cond_signal(&comp_param[idx].cond); - qemu_mutex_unlock(&comp_param[idx].mutex); - } -} - 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(); + thread_count =3D migrate_compress_threads(); for (i =3D 0; i < thread_count; i++) { /* @@ -462,6 +448,12 @@ static void compress_threads_save_cleanup(void) if (!comp_param[i].file) { break; } + + qemu_mutex_lock(&comp_param[i].mutex); + comp_param[i].quit =3D true; + qemu_cond_signal(&comp_param[i].cond); + qemu_mutex_unlock(&comp_param[i].mutex); + qemu_thread_join(compress_threads + i); qemu_mutex_destroy(&comp_param[i].mutex); qemu_cond_destroy(&comp_param[i].cond); --=20 2.17.1