From nobody Mon Feb 9 15:10:25 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.zoho.com; dkim=fail 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 1491248765617386.65676886915344; Mon, 3 Apr 2017 12:46:05 -0700 (PDT) Received: from localhost ([::1]:60914 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv7vQ-0006ZY-2t for importer@patchew.org; Mon, 03 Apr 2017 15:46:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cv7tm-0005Jw-EL for qemu-devel@nongnu.org; Mon, 03 Apr 2017 15:44:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cv7tl-0003Ce-5A for qemu-devel@nongnu.org; Mon, 03 Apr 2017 15:44:22 -0400 Received: from mail-wr0-x244.google.com ([2a00:1450:400c:c0c::244]:36142) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cv7tk-0003CI-U2 for qemu-devel@nongnu.org; Mon, 03 Apr 2017 15:44:21 -0400 Received: by mail-wr0-x244.google.com with SMTP id k6so35038858wre.3 for ; Mon, 03 Apr 2017 12:44:20 -0700 (PDT) Received: from donizetti.lan (94-39-184-28.adsl-ull.clienti.tiscali.it. [94.39.184.28]) by smtp.gmail.com with ESMTPSA id 18sm19436935wrt.52.2017.04.03.12.44.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Apr 2017 12:44:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=rG/k0UDpWkpw3ShFdWmJ28xR6NVjiObIg6Jkg3b/MAs=; b=M3pcvNYAP5Fe+odZTN9VOBqOP8lu/Yp6Xav7+ezvUqZ9x3B5hU8b1OdaBkrI9r1BiT G2RQ0lEYfZ7SeG/nWGVmNVyLEuhUA9HF4GTrFrZju5s9FlZBgi2oOfI9uiS893bGtV7l 2Wo+zzdzTBCf46P7NCPpZypaxPpPs0J5lIfAmbbwyyLQ7oZ7ie9iGqNduVJ+fQ27YfKc IYC/t9ELuCO4QQtsm+hw2m2ILxHD0+pUqLhRrQcxWLAF9PLnBffuNJT/kgFTRHCxVOd2 2VACMf7viUrBLNMFr5IE6Nsseypu2JWIMZVsZ7JDAh8+iis1WsCmlxVKUqZ5SRu/7D24 LX8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=rG/k0UDpWkpw3ShFdWmJ28xR6NVjiObIg6Jkg3b/MAs=; b=UorKRny3oXniyLDuuJiONzuKEkpG/ziz13DuXMnJ5FBAqOkdnxn/FTzPIb993yhd5H PloHDA/0p6IJ+CwpazyHJC2RfoXf7xR8m1rp+PxGlnBRcajCgWPhMA14uXKH+3Z5eB3E 14et3O0Mvk84Jee2Xy1GYWSC6KrjbaTIdBNXgV49d6Bi66hMoh9cQlgUhCuT1T6rLsD8 Mqz1pEkzVOpioPqk/Aa5BkgQRucFLGF5fHeIF8Wq20G2dloAN7vK2ve7r5GRfSClgMjL es5oZX6OCJtze3t+coqp8Q4cKWtn7C0PAfc2VOrnhTfh8344xrzqIq8LuEF3wd19m3NA h6lg== X-Gm-Message-State: AFeK/H13AP72+LSIilVTWh9tkXjN1J3p9b9Jw1fNAORkTpJ71fqHjn/N cBipyM8O3FuoJQ== X-Received: by 10.28.208.72 with SMTP id h69mr11184532wmg.100.1491248659866; Mon, 03 Apr 2017 12:44:19 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 3 Apr 2017 21:44:09 +0200 Message-Id: <20170403194409.21276-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170403194409.21276-1-pbonzini@redhat.com> References: <20170403194409.21276-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::244 Subject: [Qemu-devel] [PULL 6/6] main-loop: Acquire main_context lock around os_host_main_loop_wait. 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: "Richard W.M. Jones" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Richard W.M. Jones" When running virt-rescue the serial console hangs from time to time. Virt-rescue runs an ordinary Linux kernel "appliance", but there is only a single idle process running inside, so the qemu main loop is largely idle. With virt-rescue >=3D 1.37 you may be able to observe the hang by doing: $ virt-rescue -e ^] --scratch > while true; do ls -l /usr/bin; done The hang in virt-rescue can be resolved by pressing a key on the serial console. Possibly with the same root cause, we also observed hangs during very early boot of regular Linux VMs with a serial console. Those hangs are extremely rare, but you may be able to observe them by running this command on baremetal for a sufficiently long time: $ while libguestfs-test-tool -t 60 >& /tmp/log ; do echo -n . ; done (Check in /tmp/log that the failure was caused by a hang during early boot, and not some other reason) During investigation of this bug, Paolo Bonzini wrote: > glib is expecting QEMU to use g_main_context_acquire around accesses to > GMainContext. However QEMU is not doing that, instead it is taking its > own mutex. So we should add g_main_context_acquire and > g_main_context_release in the two implementations of > os_host_main_loop_wait; these should undo the effect of Frediano's > glib patch. This patch exactly implements Paolo's suggestion in that paragraph. This fixes the serial console hang in my testing, across 3 different physical machines (AMD, Intel Core i7 and Intel Xeon), over many hours of automated testing. I wasn't able to reproduce the early boot hangs (but as noted above, these are extremely rare in any case). Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=3D1435432 Reported-by: Richard W.M. Jones Tested-by: Richard W.M. Jones Signed-off-by: Richard W.M. Jones Message-Id: <20170331205133.23906-1-rjones@redhat.com> [Paolo: this is actually a glib bug: recent glib versions are also expecting g_main_context_acquire around g_poll---but that is not documented and probably not even intended]. Signed-off-by: Paolo Bonzini --- util/main-loop.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/util/main-loop.c b/util/main-loop.c index 4534c89..19cad6b 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -218,9 +218,12 @@ static void glib_pollfds_poll(void) =20 static int os_host_main_loop_wait(int64_t timeout) { + GMainContext *context =3D g_main_context_default(); int ret; static int spin_counter; =20 + g_main_context_acquire(context); + glib_pollfds_fill(&timeout); =20 /* If the I/O thread is very busy or we are incorrectly busy waiting in @@ -256,6 +259,9 @@ static int os_host_main_loop_wait(int64_t timeout) } =20 glib_pollfds_poll(); + + g_main_context_release(context); + return ret; } #else @@ -412,12 +418,15 @@ static int os_host_main_loop_wait(int64_t timeout) fd_set rfds, wfds, xfds; int nfds; =20 + g_main_context_acquire(context); + /* XXX: need to suppress polling by better using win32 events */ ret =3D 0; for (pe =3D first_polling_entry; pe !=3D NULL; pe =3D pe->next) { ret |=3D pe->func(pe->opaque); } if (ret !=3D 0) { + g_main_context_release(context); return ret; } =20 @@ -472,6 +481,8 @@ static int os_host_main_loop_wait(int64_t timeout) g_main_context_dispatch(context); } =20 + g_main_context_release(context); + return select_ret || g_poll_ret; } #endif --=20 1.8.3.1