From nobody Sun May 19 23:41:30 2024 Delivered-To: importer@patchew.org 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; 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=1584351485; cv=none; d=zohomail.com; s=zohoarc; b=RIQOF/+9COGjVQMRXMmh7jFhP1qdB2Ks5BAthmWyYwzrbV5Gt6zu96k7k+My2O9QTEHmhqBW6uA+2cFRQpa023Fv+mhfBWpcx4nWeYBL7viZCQExzIBfW9lF+1Q5K9banqCc+RkGUHc2u5slA0lo3+BHzJPkz3kzXrNpqkiLTik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584351485; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=38rEbEmDebesg5yUMi7K2kYkZMUhsB9SVP9bh79z0i0=; b=Zb8tb5+LHhBqETB53e/3gEA7xM42nomjwRwS2dtVHa13qRhPLrsXIeQIY4jvPTVHWWu981UX55MwnWLt1xggy3dPG0iqMabgoyk1VH/eQLiZBsZJiQOSr6bJF+WdX8kZ1I+i0BMHrQbEe5FgtpC9pRrJZ4lLyrtLWbLwJIq5bSY= 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 1584351485320168.07897821198378; Mon, 16 Mar 2020 02:38:05 -0700 (PDT) Received: from localhost ([::1]:36222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDmCB-0003eC-Qz for importer@patchew.org; Mon, 16 Mar 2020 05:38:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40639) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jDlGZ-0007Dt-Jx for qemu-devel@nongnu.org; Mon, 16 Mar 2020 04:38:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jDlGY-0003to-GC for qemu-devel@nongnu.org; Mon, 16 Mar 2020 04:38:31 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:43088 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jDlGX-0002XN-Ns for qemu-devel@nongnu.org; Mon, 16 Mar 2020 04:38:30 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 8CD24C56B6550B5CA07B; Mon, 16 Mar 2020 16:38:22 +0800 (CST) Received: from DESKTOP-27KDQMV.china.huawei.com (10.173.228.124) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Mon, 16 Mar 2020 16:38:16 +0800 From: "Longpeng(Mike)" To: Subject: [PATCH] cpus: avoid stucking in pause_all_vcpus due to race Date: Mon, 16 Mar 2020 16:37:32 +0800 Message-ID: <20200316083732.2010-1-longpeng2@huawei.com> X-Mailer: git-send-email 2.25.0.windows.1 MIME-Version: 1.0 X-Originating-IP: [10.173.228.124] X-CFilter-Loop: Reflected Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 45.249.212.32 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: "Dr . David Alan Gilbert" , arei.gonglei@huawei.com, huangzhichao@huawei.com, Paolo Bonzini , Longpeng , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Longpeng We found an issue when repeat reboot in guest during migration, it cause the migration thread never be waken up again.
| | LOCK BQL | ... | main_loop_should_exit | pause_all_vcpus | 1. set all cpus ->stop=3Dtrue | and then kick | 2. return if all cpus is paused | (by '->stopped =3D=3D true'), else| 3. qemu_cond_wait [BQL UNLOCK] | |LOCK BQL |... |do_vm_stop | pause_all_vcpus | (A)set all cpus ->stop=3Dtrue | and then kick | (B)return if all cpus is paused | (by '->stopped =3D=3D true'), else | (C)qemu_cond_wait [BQL UNLOCK] 4. be waken up and LOCK BQL | (D)be waken up BUT wait for BQL 5. goto 2. | (BQL is still LOCKed) | resume_all_vcpus | 1. set all cpus ->stop=3Dfalse | and ->stopped=3Dfalse | ... | BQL UNLOCK | (E)LOCK BQL | (F)goto B. [but stopped is false now!] |Finally, sleep at step 3 forever. As suggested by Paolo, resume_all_vcpus should notice this race, so we need to move the change of runstate before pause_all_vcpus in do_vm_stop() and ignore the resume request if runstate is not running. Cc: Paolo Bonzini Cc: Dr . David Alan Gilbert Cc: Richard Henderson Signed-off-by: Longpeng --- cpus.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cpus.c b/cpus.c index b4f8b84..ef441bd 100644 --- a/cpus.c +++ b/cpus.c @@ -1026,9 +1026,9 @@ static int do_vm_stop(RunState state, bool send_stop) int ret =3D 0; =20 if (runstate_is_running()) { + runstate_set(state); cpu_disable_ticks(); pause_all_vcpus(); - runstate_set(state); vm_state_notify(0, state); if (send_stop) { qapi_event_send_stop(); @@ -1899,6 +1899,10 @@ void resume_all_vcpus(void) { CPUState *cpu; =20 + if (!runstate_is_running()) { + return; + } + qemu_clock_enable(QEMU_CLOCK_VIRTUAL, true); CPU_FOREACH(cpu) { cpu_resume(cpu); --=20 1.8.3.1