From nobody Mon Feb 9 04:09:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564052296; cv=none; d=zoho.com; s=zohoarc; b=QiZAfgzcvde+8PJkGVBjayunwVC++s6AZxIiSNKqomvwk/vsA4mxJ+w3k+f13l2WqOPBCUzqxUUKimNpRPxoHtbA+S02zmpg5n238znujuiej2PYWjctyjgmWwmDLSy+3dv+k45ASS656tcRkbveHVT1HI5e24DL32j8XM0rjaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564052296; h=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:ARC-Authentication-Results; bh=1q2UtyxXiq9nFYmP8cTR7xXRyGrXP627hnv3jFVIY28=; b=ZDpHAovhXmZrs6wo4A4mAmlJCeI4o+oo0L03c1LMe29/MF+JTc3FqDtBqIyNzA8KnubLZIfQUKFJCAN+zLbOdbx5sODvWZOHwAcuKGwzxxRcdGV3svYYFnxO93FGAQwHAYkUuxPVBrDPvMcoIgJb5RqVwkhGyAURqeqTK+vbaCE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564052296599416.0233224175606; Thu, 25 Jul 2019 03:58:16 -0700 (PDT) Received: from localhost ([::1]:58586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqbRv-0001JJ-DP for importer@patchew.org; Thu, 25 Jul 2019 06:58:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41109) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqbRG-00078E-VU for qemu-devel@nongnu.org; Thu, 25 Jul 2019 06:57:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqbRF-0006Cm-Tt for qemu-devel@nongnu.org; Thu, 25 Jul 2019 06:57:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50260) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqbRF-0006Av-Lt for qemu-devel@nongnu.org; Thu, 25 Jul 2019 06:57:33 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F3423330265; Thu, 25 Jul 2019 10:57:32 +0000 (UTC) Received: from localhost.localdomain (ovpn-117-190.ams2.redhat.com [10.36.117.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7AC5A19C7F; Thu, 25 Jul 2019 10:57:30 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Thu, 25 Jul 2019 12:57:21 +0200 Message-Id: <20190725105724.2562-2-quintela@redhat.com> In-Reply-To: <20190725105724.2562-1-quintela@redhat.com> References: <20190725105724.2562-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 25 Jul 2019 10:57:33 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 1/4] migration: fix migrate_cancel leads live_migration thread endless loop 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: Laurent Vivier , Thomas Huth , kvm@vger.kernel.org, Juan Quintela , "Dr. David Alan Gilbert" , Ivan Ren , Paolo Bonzini , Ivan Ren , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Ivan Ren When we 'migrate_cancel' a multifd migration, live_migration thread may go into endless loop in multifd_send_pages functions. Reproduce steps: (qemu) migrate_set_capability multifd on (qemu) migrate -d url (qemu) [wait a while] (qemu) migrate_cancel Then may get live_migration 100% cpu usage in following stack: pthread_mutex_lock qemu_mutex_lock_impl multifd_send_pages multifd_queue_page ram_save_multifd_page ram_save_target_page ram_save_host_page ram_find_and_save_block ram_find_and_save_block ram_save_iterate qemu_savevm_state_iterate migration_iteration_run migration_thread qemu_thread_start start_thread clone Signed-off-by: Ivan Ren Message-Id: <1561468699-9819-2-git-send-email-ivanren@tencent.com> Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 2b0774c2bf..52a2d498e4 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -920,7 +920,7 @@ struct { * false. */ =20 -static void multifd_send_pages(void) +static int multifd_send_pages(void) { int i; static int next_channel; @@ -933,6 +933,11 @@ static void multifd_send_pages(void) p =3D &multifd_send_state->params[i]; =20 qemu_mutex_lock(&p->mutex); + if (p->quit) { + error_report("%s: channel %d has already quit!", __func__, i); + qemu_mutex_unlock(&p->mutex); + return -1; + } if (!p->pending_job) { p->pending_job++; next_channel =3D (i + 1) % migrate_multifd_channels(); @@ -951,9 +956,11 @@ static void multifd_send_pages(void) ram_counters.transferred +=3D transferred;; qemu_mutex_unlock(&p->mutex); qemu_sem_post(&p->sem); + + return 1; } =20 -static void multifd_queue_page(RAMBlock *block, ram_addr_t offset) +static int multifd_queue_page(RAMBlock *block, ram_addr_t offset) { MultiFDPages_t *pages =3D multifd_send_state->pages; =20 @@ -968,15 +975,19 @@ static void multifd_queue_page(RAMBlock *block, ram_a= ddr_t offset) pages->used++; =20 if (pages->used < pages->allocated) { - return; + return 1; } } =20 - multifd_send_pages(); + if (multifd_send_pages() < 0) { + return -1; + } =20 if (pages->block !=3D block) { - multifd_queue_page(block, offset); + return multifd_queue_page(block, offset); } + + return 1; } =20 static void multifd_send_terminate_threads(Error *err) @@ -1049,7 +1060,10 @@ static void multifd_send_sync_main(void) return; } if (multifd_send_state->pages->used) { - multifd_send_pages(); + if (multifd_send_pages() < 0) { + error_report("%s: multifd_send_pages fail", __func__); + return; + } } for (i =3D 0; i < migrate_multifd_channels(); i++) { MultiFDSendParams *p =3D &multifd_send_state->params[i]; @@ -1058,6 +1072,12 @@ static void multifd_send_sync_main(void) =20 qemu_mutex_lock(&p->mutex); =20 + if (p->quit) { + error_report("%s: channel %d has already quit", __func__, i); + qemu_mutex_unlock(&p->mutex); + return; + } + p->packet_num =3D multifd_send_state->packet_num++; p->flags |=3D MULTIFD_FLAG_SYNC; p->pending_job++; @@ -2033,7 +2053,9 @@ static int ram_save_page(RAMState *rs, PageSearchStat= us *pss, bool last_stage) static int ram_save_multifd_page(RAMState *rs, RAMBlock *block, ram_addr_t offset) { - multifd_queue_page(block, offset); + if (multifd_queue_page(block, offset) < 0) { + return -1; + } ram_counters.normal++; =20 return 1; --=20 2.21.0 From nobody Mon Feb 9 04:09:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564052282; cv=none; d=zoho.com; s=zohoarc; b=igNX6nvV7/PqChwUHtVnCg6aId5pwdJSGLi9ACB4JCwegxCr2gs2/drtPzpx1gfrE/BCQMraQFljpykv900yGPBhRWSm1XyYhYwnF0ApcWUIAvsmRhLSTZ6wc2YocqZkRvtY5uo80vYfq2pqPsWSLzqdBGc1ACvU0iwkzJnqlvE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564052282; h=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:ARC-Authentication-Results; bh=4sYhpwSaxMgexbQxv+N/lyVus6F71yQl49H+G1hCiOg=; b=B91G1jPi22eGtfAW2SKzJ37wllDi1Zoy+kro3e4C1AQQFo1qJzVMu7S8S1cyr5JielgfbLxL9p+wCJidvAHWZvPtlYZ6Dn98ulvD1odntBvI83E5R6BLIzV9lTNqWR+0UjAFuZoboWNpWfGpRUMYumD6NdXAipDEvyswMMfMPtQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564052282639177.7043094433377; Thu, 25 Jul 2019 03:58:02 -0700 (PDT) Received: from localhost ([::1]:58578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqbRh-00007c-4n for importer@patchew.org; Thu, 25 Jul 2019 06:58:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41128) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqbRJ-0007Jh-Fn for qemu-devel@nongnu.org; Thu, 25 Jul 2019 06:57:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqbRI-0006Fz-H1 for qemu-devel@nongnu.org; Thu, 25 Jul 2019 06:57:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52496) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqbRI-0006E8-BS for qemu-devel@nongnu.org; Thu, 25 Jul 2019 06:57:36 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E2DE30C133C; Thu, 25 Jul 2019 10:57:35 +0000 (UTC) Received: from localhost.localdomain (ovpn-117-190.ams2.redhat.com [10.36.117.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 522C619C7F; Thu, 25 Jul 2019 10:57:33 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Thu, 25 Jul 2019 12:57:22 +0200 Message-Id: <20190725105724.2562-3-quintela@redhat.com> In-Reply-To: <20190725105724.2562-1-quintela@redhat.com> References: <20190725105724.2562-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 25 Jul 2019 10:57:35 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 2/4] migration: fix migrate_cancel leads live_migration thread hung forever 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: Laurent Vivier , Thomas Huth , kvm@vger.kernel.org, Juan Quintela , "Dr. David Alan Gilbert" , Ivan Ren , Paolo Bonzini , Ivan Ren , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Ivan Ren When we 'migrate_cancel' a multifd migration, live_migration thread may hung forever at some points, because of multifd_send_thread has already exit for socket error: 1. multifd_send_pages may hung at qemu_sem_wait(&multifd_send_state-> channels_ready) 2. multifd_send_sync_main my hung at qemu_sem_wait(&multifd_send_state-> sem_sync) Signed-off-by: Ivan Ren Message-Id: <1561468699-9819-3-git-send-email-ivanren@tencent.com> Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- Remove spurious not needed bits --- migration/ram.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/migration/ram.c b/migration/ram.c index 52a2d498e4..87bb7da8e2 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1097,7 +1097,8 @@ static void *multifd_send_thread(void *opaque) { MultiFDSendParams *p =3D opaque; Error *local_err =3D NULL; - int ret; + int ret =3D 0; + uint32_t flags =3D 0; =20 trace_multifd_send_thread_start(p->id); rcu_register_thread(); @@ -1115,7 +1116,7 @@ static void *multifd_send_thread(void *opaque) if (p->pending_job) { uint32_t used =3D p->pages->used; uint64_t packet_num =3D p->packet_num; - uint32_t flags =3D p->flags; + flags =3D p->flags; =20 p->next_packet_size =3D used * qemu_target_page_size(); multifd_send_fill_packet(p); @@ -1164,6 +1165,17 @@ out: multifd_send_terminate_threads(local_err); } =20 + /* + * Error happen, I will exit, but I can't just leave, tell + * who pay attention to me. + */ + if (ret !=3D 0) { + if (flags & MULTIFD_FLAG_SYNC) { + qemu_sem_post(&multifd_send_state->sem_sync); + } + qemu_sem_post(&multifd_send_state->channels_ready); + } + qemu_mutex_lock(&p->mutex); p->running =3D false; qemu_mutex_unlock(&p->mutex); --=20 2.21.0 From nobody Mon Feb 9 04:09:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564052309; cv=none; d=zoho.com; s=zohoarc; b=FGeX1JOVP5DgirjO9+5O94FStZwu0u+mfXyflNMZSJm0C/gstxjlGyDvxNYTZsU67DzzwVoeNKgA1ME0lLC4tovU2w6BPkWD9RWgNGH5u+tst+DNulvlLfb8AhbDaogMTtxvW4hLpapLg8VziyPK8ai05QQYFsa1UQF3J67BLgQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564052309; h=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:ARC-Authentication-Results; bh=7OOXlh4m1ntvxYgasAVLIXQR2u0OWMag+w5P8OOvSOU=; b=dnmeozaHbMYMJvIygaUGeUuylmp21t+0Nj37IBQvZJo1KOzaRqIkiCWfnCxwya+4NlWecKtj6Fgf4y6y/I9LW5+EDBFvlCbgr5Vb9+FrjMCVZceCZYmg8ff/sjWgQI9JwGZy19KF05NB0hiGIxQSACm/umL51KAyVK+tPyUgzj0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564052309003847.0196434844157; Thu, 25 Jul 2019 03:58:29 -0700 (PDT) Received: from localhost ([::1]:58596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqbS8-0002Yt-15 for importer@patchew.org; Thu, 25 Jul 2019 06:58:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41156) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqbRL-0007Tr-OA for qemu-devel@nongnu.org; Thu, 25 Jul 2019 06:57:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqbRK-0006Gq-OP for qemu-devel@nongnu.org; Thu, 25 Jul 2019 06:57:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50328) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqbRK-0006GV-Iv for qemu-devel@nongnu.org; Thu, 25 Jul 2019 06:57:38 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D5CD92D1EEF; Thu, 25 Jul 2019 10:57:37 +0000 (UTC) Received: from localhost.localdomain (ovpn-117-190.ams2.redhat.com [10.36.117.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id EAE7B19C7F; Thu, 25 Jul 2019 10:57:35 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Thu, 25 Jul 2019 12:57:23 +0200 Message-Id: <20190725105724.2562-4-quintela@redhat.com> In-Reply-To: <20190725105724.2562-1-quintela@redhat.com> References: <20190725105724.2562-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 25 Jul 2019 10:57:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 3/4] migration: Make explicit that we are quitting multifd 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: Laurent Vivier , Thomas Huth , kvm@vger.kernel.org, Juan Quintela , "Dr. David Alan Gilbert" , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" We add a bool to indicate that. Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Juan Quintela --- migration/ram.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index 87bb7da8e2..eb6716710e 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -677,6 +677,8 @@ typedef struct { QemuMutex mutex; /* is this channel thread running */ bool running; + /* should this thread finish */ + bool quit; /* array of pages to receive */ MultiFDPages_t *pages; /* packet allocated len */ @@ -1266,6 +1268,7 @@ static void multifd_recv_terminate_threads(Error *err) MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 qemu_mutex_lock(&p->mutex); + p->quit =3D true; /* We could arrive here for two reasons: - normal quit, i.e. everything went fine, just finished - error quit: We close the channels so the channel threads @@ -1288,6 +1291,7 @@ int multifd_load_cleanup(Error **errp) MultiFDRecvParams *p =3D &multifd_recv_state->params[i]; =20 if (p->running) { + p->quit =3D true; qemu_thread_join(&p->thread); } object_unref(OBJECT(p->c)); @@ -1351,6 +1355,10 @@ static void *multifd_recv_thread(void *opaque) uint32_t used; uint32_t flags; =20 + if (p->quit) { + break; + } + ret =3D qio_channel_read_all_eof(p->c, (void *)p->packet, p->packet_len, &local_err); if (ret =3D=3D 0) { /* EOF */ @@ -1422,6 +1430,7 @@ int multifd_load_setup(void) =20 qemu_mutex_init(&p->mutex); qemu_sem_init(&p->sem_sync, 0); + p->quit =3D false; p->id =3D i; p->pages =3D multifd_pages_init(page_count); p->packet_len =3D sizeof(MultiFDPacket_t) --=20 2.21.0 From nobody Mon Feb 9 04:09:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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 (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1564052288; cv=none; d=zoho.com; s=zohoarc; b=P6VeR4OKFobweY7+XQqu+FyYzbFT56p13DC4gizOpSDWKfg/ms2DMm+j5lkDk61gzMqWubuD3lFN25qhvjsv90tjb0n4z2g3TRMFBqT+cBegBPK2JV4f9HxcktHtsEYugQTsqhSdupmvgzS3CT5cvwdWgyv6ZF01BYsoZ2wAs90= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564052288; h=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:ARC-Authentication-Results; bh=mcqzk/MHUzFM9Kuicye4f08PC2rPwethXf2r+BA7V9s=; b=IiZYRyj21eYz9xJwy4M9MGMNIi3YzljpiO4N+kXCLTM7EphMf8CVkxwxi8H1WdpFwvFCD46q5tKWl3zjNqGJRT2AaGkrMwfvnxBnf+pa2yLnohwlC4IMctczx5Gm7KwTlF68PEeJH42I0BCgyro4pUNn1Kh5V0p6T/n9qpTIuiQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1564052288861250.0414686059189; Thu, 25 Jul 2019 03:58:08 -0700 (PDT) Received: from localhost ([::1]:58584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqbRn-0000dK-Ft for importer@patchew.org; Thu, 25 Jul 2019 06:58:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41181) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hqbRO-0007fe-Gn for qemu-devel@nongnu.org; Thu, 25 Jul 2019 06:57:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hqbRN-0006Ht-ES for qemu-devel@nongnu.org; Thu, 25 Jul 2019 06:57:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32894) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hqbRN-0006Hd-7U for qemu-devel@nongnu.org; Thu, 25 Jul 2019 06:57:41 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B16781DF0; Thu, 25 Jul 2019 10:57:40 +0000 (UTC) Received: from localhost.localdomain (ovpn-117-190.ams2.redhat.com [10.36.117.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id 32ACD19D70; Thu, 25 Jul 2019 10:57:38 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Date: Thu, 25 Jul 2019 12:57:24 +0200 Message-Id: <20190725105724.2562-5-quintela@redhat.com> In-Reply-To: <20190725105724.2562-1-quintela@redhat.com> References: <20190725105724.2562-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 25 Jul 2019 10:57:40 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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 4/4] migration: fix migrate_cancel multifd migration leads destination hung forever 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: Laurent Vivier , Thomas Huth , kvm@vger.kernel.org, Juan Quintela , "Dr. David Alan Gilbert" , Ivan Ren , Paolo Bonzini , Ivan Ren , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Ivan Ren When migrate_cancel a multifd migration, if run sequence like this: [source] [destination] multifd_send_sync_main[finish] multifd_recv_thread wait &p->sem_sync shutdown to_dst_file detect error from_src_file send RAM_SAVE_FLAG_EOS[fail] [no chance to run multifd_recv_sync_mai= n] multifd_load_cleanup join multifd receive thread forever will lead destination qemu hung at following stack: pthread_join qemu_thread_join multifd_load_cleanup process_incoming_migration_co coroutine_trampoline Signed-off-by: Ivan Ren Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Juan Quintela Message-Id: <1561468699-9819-4-git-send-email-ivanren@tencent.com> Signed-off-by: Juan Quintela --- migration/ram.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/migration/ram.c b/migration/ram.c index eb6716710e..889148dd84 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1292,6 +1292,11 @@ int multifd_load_cleanup(Error **errp) =20 if (p->running) { p->quit =3D true; + /* + * multifd_recv_thread may hung at MULTIFD_FLAG_SYNC handle co= de, + * however try to wakeup it without harm in cleanup phase. + */ + qemu_sem_post(&p->sem_sync); qemu_thread_join(&p->thread); } object_unref(OBJECT(p->c)); --=20 2.21.0