From patchwork Wed Sep 19 13:35:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Li X-Patchwork-Id: 10605869 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 55D6014DA for ; Wed, 19 Sep 2018 13:39:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CAC42C151 for ; Wed, 19 Sep 2018 13:39:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 20E852C1BF; Wed, 19 Sep 2018 13:39:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AF4642C151 for ; Wed, 19 Sep 2018 13:39:34 +0000 (UTC) Received: from localhost ([::1]:45526 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2chZ-0001ss-Rw for patchwork-qemu-devel@patchwork.kernel.org; Wed, 19 Sep 2018 09:39:33 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 = migrate_compress_threads(); for (idx = 0; idx < thread_count; idx++) { + if (!comp_param[idx].mutex.initialized) { + break; + } qemu_mutex_lock(&comp_param[idx].mutex); comp_param[idx].quit = true; qemu_cond_signal(&comp_param[idx].cond); @@ -438,7 +441,7 @@ static void compress_threads_save_cleanup(void) { int i, thread_count; - if (!migrate_use_compression()) { + if (!migrate_use_compression() || !comp_param) { return; } terminate_compression_threads();