From patchwork Sat Jun 2 10:34:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Privoznik X-Patchwork-Id: 10444709 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4149E602BD for ; Sat, 2 Jun 2018 10:36:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 271C22893E for ; Sat, 2 Jun 2018 10:36:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 193CF28A59; Sat, 2 Jun 2018 10:36:23 +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 AD2842893E for ; Sat, 2 Jun 2018 10:36:22 +0000 (UTC) Received: from localhost ([::1]:59095 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fP3tV-0003be-Lb for patchwork-qemu-devel@patchwork.kernel.org; Sat, 02 Jun 2018 06:36:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56777) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fP3sJ-0003Do-JX for qemu-devel@nongnu.org; Sat, 02 Jun 2018 06:35:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fP3sG-00074y-GB for qemu-devel@nongnu.org; Sat, 02 Jun 2018 06:35:07 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56204 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fP3sG-00072O-By for qemu-devel@nongnu.org; Sat, 02 Jun 2018 06:35:04 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B4781401EF23 for ; Sat, 2 Jun 2018 10:35:02 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-53.brq.redhat.com [10.40.204.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 555DD20292A8; Sat, 2 Jun 2018 10:35:01 +0000 (UTC) From: Michal Privoznik To: qemu-devel@nongnu.org Date: Sat, 2 Jun 2018 12:34:52 +0200 Message-Id: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 02 Jun 2018 10:35:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Sat, 02 Jun 2018 10:35:02 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mprivozn@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH] cli: Don't run early event loop if no --preconfig was specified 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: imammedo@redhat.com, ehabkost@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP After 047f7038f586d215 it is possible for event loop to run two times. First time whilst parsing command line options (the idea is to bring up monitor early so that management applications can tweak config before machine is initialized). And the second time is after everything is set up (this is the usual place). In both cases the event loop is called as main_loop_wait(nonblocking = false) which causes the event loop to block until at least one event occurred. Now, consider that somebody (i.e. libvirt) calls us with -daemonize. This operation is split in two steps. The main() calls os_daemonize() which fork()-s and then waits in read() until child notifies it via write(): /qemu.git $ ./x86_64-softmmu/qemu-system-x86_64 -S -daemonize \ -no-user-config -nodefaults -nographic main(): child: os_daemonize(): read(pipe[0]) main_loop(): main_loop_wait(false) os_setup_post(): write(pipe[1]) main_loop(): main_loop_wait(false) Here it can be clearly seen that main() does not exit until an event occurs, but at the same time nobody will touch the monitor socket until their exec("qemu-system-*") finishes. So the whole thing deadlocks. The solution is to not call main_loop() unless --preconfig was specified (in which case caller knows they must connect to the socket before exec() finishes). Signed-off-by: Michal Privoznik Reviewed-by: Igor Mammedov --- vl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vl.c b/vl.c index 70f090c823..cde2934c40 100644 --- a/vl.c +++ b/vl.c @@ -4469,8 +4469,13 @@ int main(int argc, char **argv, char **envp) } parse_numa_opts(current_machine); - /* do monitor/qmp handling at preconfig state if requested */ - main_loop(); + if (preconfig_exit_requested) { + runstate_set(RUN_STATE_PRELAUNCH); + preconfig_exit_requested = false; + } else { + /* do monitor/qmp handling at preconfig state if requested */ + main_loop(); + } /* from here on runstate is RUN_STATE_PRELAUNCH */ machine_run_board_init(current_machine);