From nobody Tue Feb 10 00:24:45 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1652975078; cv=none; d=zohomail.com; s=zohoarc; b=hPCNsFCPmiU/fYJmPRyH2MF2TAFH7q24+Z10kWOJ6HTcKheDrM9sFAfBrhcgfrLiKNH++anqpb4yykAYnfR9RLMYOOdOSw33JUpWLxDz+QhGxS4kmDjZAIMpvt4nfxd/7zsMFDcHOVZ2Lc1Pkp8l0+JcE3XX0AX4HcTvw2jbtZY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652975078; h=Content-Type: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; bh=yn/s3Oq39rzmoejHaHV+Y/8l9ePpuMuVvPWS30BJqRc=; b=htjMLCCwO6hiPy2VAdCRJ/02vkJx76Ne9TTHxrmuEkcRgsLTnCzu1m2VBeWdZWzYAYkyOnO0iEq3Q2Mj4TQmymY93uCRYFEAq6QA7pp2GN+U/ZdQ1rfgkG5lSIDYh/b9ct9smOYbkRBp2W7sAroGsLX/PUe6O8mZlomj4xUe3Po= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1652975078540655.0162771288059; Thu, 19 May 2022 08:44:38 -0700 (PDT) Received: from localhost ([::1]:50850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nriKL-0003xd-2c for importer@patchew.org; Thu, 19 May 2022 11:44:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nriAe-0001al-4k for qemu-devel@nongnu.org; Thu, 19 May 2022 11:34:38 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:48996) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nriAY-0007oV-9m for qemu-devel@nongnu.org; Thu, 19 May 2022 11:34:33 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.10]) by beetle.greensocs.com (Postfix) with ESMTPS id B824E20896; Thu, 19 May 2022 15:34:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1652974465; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yn/s3Oq39rzmoejHaHV+Y/8l9ePpuMuVvPWS30BJqRc=; b=tePtb47uxCR+s8BRM3dV4PG45OkcPCEVKVM/+IkXy/ibaM0wtKpVX/5n/VNXniKYej4W18 Vcm5VRQ+zY2c3/BXB0ld5ZxFUu7a1qj2lAWUPcEKDqXag0lZDF236sMDxBIVCceuUEeuiU Oj9M7FmIq9SFwCbDJFZmxBeVaXLbREc= From: Damien Hedde To: qemu-devel@nongnu.org Cc: mark.burton@greensocs.com, edgari@xilinx.com, Damien Hedde , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost Subject: [PATCH v5 1/6] machine: add phase_get() and document phase_check()/advance() Date: Thu, 19 May 2022 17:33:57 +0200 Message-Id: <20220519153402.41540-2-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220519153402.41540-1-damien.hedde@greensocs.com> References: <20220519153402.41540-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @greensocs.com) X-ZM-MESSAGEID: 1652975080306100001 phase_get() returns the current phase, we'll use it in next commit. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Jim Shu --- include/hw/qdev-core.h | 19 +++++++++++++++++++ hw/core/qdev.c | 5 +++++ 2 files changed, 24 insertions(+) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 92c3d65208..e29c705b74 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -887,7 +887,26 @@ typedef enum MachineInitPhase { PHASE_MACHINE_READY, } MachineInitPhase; =20 +/* + * phase_get: + * Returns the current phase + */ +MachineInitPhase phase_get(void); + +/** + * phase_check: + * Test if current phase is at least @phase. + * + * Returns true if this is the case. + */ extern bool phase_check(MachineInitPhase phase); + +/** + * @phase_advance: + * Update the current phase to @phase. + * + * Must only be used to make a single phase step. + */ extern void phase_advance(MachineInitPhase phase); =20 #endif diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 84f3019440..632dc0a4be 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -910,6 +910,11 @@ Object *qdev_get_machine(void) =20 static MachineInitPhase machine_phase; =20 +MachineInitPhase phase_get(void) +{ + return machine_phase; +} + bool phase_check(MachineInitPhase phase) { return machine_phase >=3D phase; --=20 2.36.1 From nobody Tue Feb 10 00:24:45 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1652975096; cv=none; d=zohomail.com; s=zohoarc; b=oC31KcweIiBqJkZezpnJf+2cTQfgtxuba6j5GrI8KeHpzgmEFVyw75cAgB0qz0LxwGt+vB6ICPV4FrqZMNWeKabUA4xWsBcMWhaflNDhqWg96lKupIvMugZsETXOF0Z1L1/LPBSEsegfscUrUFkNzoc1IJ01sooZ+m6TeH2sdX8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652975096; 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; bh=PZ/khheqxpn81zoPkGuli+zXHzcGpEanrhJLq6OMKhA=; b=Id2VW2NFH/azdb1+oIRk5MwyX/RBpuU64xHgfmSBwtvmnwWxynu5Q2LDF7db8fU5DWSv+efwCSMzRYZGCdC+MCv1mksTIy4ROTAwBpPrbKLdxjwDDlL4+tHCMPlNQS1RiLa8GDK87c82CRKkiIY6yjfY7KIq/Y0aF+qeljatHDc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1652975096526318.57326936303014; Thu, 19 May 2022 08:44:56 -0700 (PDT) Received: from localhost ([::1]:51948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nriKc-0004iE-Dl for importer@patchew.org; Thu, 19 May 2022 11:44:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nriAe-0001am-58 for qemu-devel@nongnu.org; Thu, 19 May 2022 11:34:38 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:49012) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nriAY-0007oc-9p for qemu-devel@nongnu.org; Thu, 19 May 2022 11:34:34 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.10]) by beetle.greensocs.com (Postfix) with ESMTPS id 9913B21C28; Thu, 19 May 2022 15:34:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1652974466; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PZ/khheqxpn81zoPkGuli+zXHzcGpEanrhJLq6OMKhA=; b=daXCasdc4462yel6zpxEpT88oBO9c1A53/J2PU2feIkkXSH8hsYXJ/pqaK1+lqNNUd8Pqd wrRwZu1a8k90+/FPWtCk1WVOJux99FJ51I6mopyjkNP7l2dsSlWzRTrZBdY7GkAKP9ib/0 Q3Ksyz7AVMdEyX+pPazVWIvgLhAQ1lU= From: Damien Hedde To: qemu-devel@nongnu.org Cc: mark.burton@greensocs.com, edgari@xilinx.com, Damien Hedde , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost Subject: [PATCH v5 2/6] machine&vl: introduce phase_until() to handle phase transitions Date: Thu, 19 May 2022 17:33:58 +0200 Message-Id: <20220519153402.41540-3-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220519153402.41540-1-damien.hedde@greensocs.com> References: <20220519153402.41540-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @greensocs.com) X-ZM-MESSAGEID: 1652975098085100001 Content-Type: text/plain; charset="utf-8" phase_until() is implemented in vl.c and is meant to be used to make startup progress up to a specified phase being reached(). At this point, no behavior change is introduced: phase_until() only supports a single double transition corresponding to the functionality of qmp_exit_preconfig(): + accel-created -> machine-initialized -> machine-ready As a result qmp_exit_preconfig() now uses phase_until(). This commit is a preparation to support cold plugging a device using qapi command (which will be introduced in a following commit). For this we need fine grain control of the phase. Signed-off-by: Damien Hedde Tested-by: Jim Shu --- v5: + refactor to avoid indentation change --- include/hw/qdev-core.h | 14 +++++++++++++ softmmu/vl.c | 46 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index e29c705b74..5f73d06408 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -909,4 +909,18 @@ extern bool phase_check(MachineInitPhase phase); */ extern void phase_advance(MachineInitPhase phase); =20 +/** + * @phase_until: + * @phase: the target phase + * @errp: error report + * + * Make the machine init progress until the target phase is reached. + * + * Its is a no-op is the target phase is the current or an earlier + * phase. + * + * Returns true in case of success. + */ +extern bool phase_until(MachineInitPhase phase, Error **errp); + #endif diff --git a/softmmu/vl.c b/softmmu/vl.c index 84a31eba76..7f8d15b5b8 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2702,11 +2702,17 @@ void qmp_x_exit_preconfig(Error **errp) error_setg(errp, "The command is permitted only before machine ini= tialization"); return; } + phase_until(PHASE_MACHINE_READY, errp); +} =20 +static void qemu_phase_ready(Error **errp) +{ qemu_init_board(); + /* phase is now PHASE_MACHINE_INITIALIZED. */ qemu_create_cli_devices(); cxl_fixed_memory_window_link_targets(errp); qemu_machine_creation_done(); + /* Phase is now PHASE_MACHINE_READY. */ =20 if (loadvm) { load_snapshot(loadvm, NULL, false, NULL, &error_fatal); @@ -2729,6 +2735,46 @@ void qmp_x_exit_preconfig(Error **errp) } } =20 +bool phase_until(MachineInitPhase phase, Error **errp) +{ + ERRP_GUARD(); + if (!phase_check(PHASE_ACCEL_CREATED)) { + error_setg(errp, "Phase transition is not supported until accelera= tor" + " is created"); + return false; + } + + while (!phase_check(phase)) { + MachineInitPhase cur_phase =3D phase_get(); + + switch (cur_phase) { + case PHASE_ACCEL_CREATED: + qemu_phase_ready(errp); + break; + + default: + /* + * If we end up here, it is because we miss a case above. + */ + error_setg(&error_abort, "Requested phase transition is not" + " implemented"); + return false; + } + + if (*errp) { + return false; + } + + /* + * Ensure we made some progress. + * With the default case above, it should be enough to prevent + * any infinite loop. + */ + assert(cur_phase < phase_get()); + } + return true; +} + void qemu_init(int argc, char **argv, char **envp) { QemuOpts *opts; --=20 2.36.1 From nobody Tue Feb 10 00:24:45 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1652974699; cv=none; d=zohomail.com; s=zohoarc; b=fySzBEUEq48MIkGbYIuF7M0GwJ0wZrVFvekq3tilSymxx0cser8/ZPNtsaq4WQWiDRP7hJjG01jwhXfAxtWf1fELpQ+Kigkh5Tvc9WOOZwYUXwzWZvB7OQ8H6OdoyHtMExrOKIjXd0XfaCPP/FfYQdKu6VhfmRanyCvs7jm6HxY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652974699; h=Content-Type: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; bh=efJjLQhFD/JgowKYsCQ9T6+G0NfNbn6JDTD+53ql1K8=; b=KZXDyht1EuHCOkD+cVVYa0HWhCg3qP+Q9g4e7ppX4NglfRjuLVMf+yZTDVdnaOpkePQsePfoNw/jBHYxOirloDopnjrszfe7QZCP2drClSp8S5BnXCDJAgWipazeFOiVjI5stYP+ifJO0vVK4taPkRwEpSdiciqhDEXo2mJ78WI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1652974698823976.8530804843048; Thu, 19 May 2022 08:38:18 -0700 (PDT) Received: from localhost ([::1]:40164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nriEC-0004m7-Ev for importer@patchew.org; Thu, 19 May 2022 11:38:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nriAd-0001ai-V4 for qemu-devel@nongnu.org; Thu, 19 May 2022 11:34:36 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:49022) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nriAY-0007oh-9l for qemu-devel@nongnu.org; Thu, 19 May 2022 11:34:33 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.10]) by beetle.greensocs.com (Postfix) with ESMTPS id EBFA321C39; Thu, 19 May 2022 15:34:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1652974467; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=efJjLQhFD/JgowKYsCQ9T6+G0NfNbn6JDTD+53ql1K8=; b=IX4lK/ptrDpJ+TP5pHZdUkn0nal6kz/I37gJqpQ83vz/RVDXgHy4Ot+c0HpwjiJFnGvw/f OcY2l4UISj7qP7Eg46zf9wS2gMyyybtt//Y7dGMOavNfzS8DyR1C2FEWfLRx6G3hoR2gPK 544J1k1xw+MBLbKvlTOGmO49DS91rKY= From: Damien Hedde To: qemu-devel@nongnu.org Cc: mark.burton@greensocs.com, edgari@xilinx.com, Damien Hedde , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini Subject: [PATCH v5 3/6] vl: support machine-initialized target in phase_until() Date: Thu, 19 May 2022 17:33:59 +0200 Message-Id: <20220519153402.41540-4-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220519153402.41540-1-damien.hedde@greensocs.com> References: <20220519153402.41540-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @greensocs.com) X-ZM-MESSAGEID: 1652974700250100002 phase_until() now supports the following transitions: + accel-created -> machine-initialized + machine-initialized -> machine-ready As a consequence we can now support the use of qmp_exit_preconfig() from phases _accel-created_ and _machine-initialized_. This commit is a preparation to support cold plugging a device using qapi (which will be introduced in a following commit). For this we need fine grain control of the phase. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Jim Shu --- v5: update due to refactor of previous commit --- softmmu/vl.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/softmmu/vl.c b/softmmu/vl.c index 7f8d15b5b8..ea15e37973 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2698,8 +2698,9 @@ static void qemu_machine_creation_done(void) =20 void qmp_x_exit_preconfig(Error **errp) { - if (phase_check(PHASE_MACHINE_INITIALIZED)) { - error_setg(errp, "The command is permitted only before machine ini= tialization"); + if (phase_check(PHASE_MACHINE_READY)) { + error_setg(errp, "The command is permitted only before" + " machine is ready"); return; } phase_until(PHASE_MACHINE_READY, errp); @@ -2707,9 +2708,6 @@ void qmp_x_exit_preconfig(Error **errp) =20 static void qemu_phase_ready(Error **errp) { - qemu_init_board(); - /* phase is now PHASE_MACHINE_INITIALIZED. */ - qemu_create_cli_devices(); cxl_fixed_memory_window_link_targets(errp); qemu_machine_creation_done(); /* Phase is now PHASE_MACHINE_READY. */ @@ -2749,6 +2747,24 @@ bool phase_until(MachineInitPhase phase, Error **err= p) =20 switch (cur_phase) { case PHASE_ACCEL_CREATED: + qemu_init_board(); + /* Phase is now PHASE_MACHINE_INITIALIZED. */ + /* + * Handle CLI devices now in order leave this case in a state + * where we can cold plug devices with QMP. The following call + * handles the CLI options: + * + -fw_cfg (has side effects on device cold plug) + * + -device + */ + qemu_create_cli_devices(); + /* + * At this point all CLI options are handled apart: + * + -S (autostart) + * + -incoming + */ + break; + + case PHASE_MACHINE_INITIALIZED: qemu_phase_ready(errp); break; =20 --=20 2.36.1 From nobody Tue Feb 10 00:24:45 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1652974713; cv=none; d=zohomail.com; s=zohoarc; b=fvL96N7g3S/f4CHQhEPm6H7bHNLiyfmXn/PHz3ubtC41+iSVBLwyS6If4fbyN4nE/1Lp9UHE84GiTN1hmsvJuqJrLXEQNIMZ97C9CNJ6Y5eLFsrM9zK+XN2OKCVXo0TAegp/q7flms2w6dzM6Qbfc46mb7e7WVkORT3qvqc0Z9A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652974713; h=Content-Type: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; bh=Y9k8TQ1op+6ZS9NDbHvigWNpOkWXrQKCidyXBlzOtes=; b=bKR0nlaFtoCAgkgkcCsX+dgEpF0DtMfxXA8DSC1+rCwTAk7f62XSEr6pwozhVVRGhfTbEEioJ1kMgj44/wVfxsGWqV/zvy9sQbiG1Zn8lPbAKUWJgzfFoGSjls155w1cDZ6oMNdkjeHD8Qe0wpLDweRfUrk5N3kiAzupPLcv9g4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1652974713859801.4645022314268; Thu, 19 May 2022 08:38:33 -0700 (PDT) Received: from localhost ([::1]:40882 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nriES-0005HX-94 for importer@patchew.org; Thu, 19 May 2022 11:38:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nriAe-0001aj-1P for qemu-devel@nongnu.org; Thu, 19 May 2022 11:34:36 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:49042) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nriAY-0007on-9n for qemu-devel@nongnu.org; Thu, 19 May 2022 11:34:33 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.10]) by beetle.greensocs.com (Postfix) with ESMTPS id 5CC6B21CCE; Thu, 19 May 2022 15:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1652974467; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y9k8TQ1op+6ZS9NDbHvigWNpOkWXrQKCidyXBlzOtes=; b=A02OLMJXH0XO7g9V1dw5D+kfJk7yS/rXnIMgqzbeXbpn9Pjn/8n9rIlbJN87OnhMpZzIjZ dgVTPlry/aQEkq+kL1yELey8OUhHWFPvuCkzjRBIj7ZWdED3PFgs/Q7W5F5BVBt2AmOrPT mM7kg49NI2mvh/8KiUvSlWWeOi2fB3M= From: Damien Hedde To: qemu-devel@nongnu.org Cc: mark.burton@greensocs.com, edgari@xilinx.com, Damien Hedde , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost Subject: [PATCH v5 4/6] qapi/device_add: compute is_hotplug flag Date: Thu, 19 May 2022 17:34:00 +0200 Message-Id: <20220519153402.41540-5-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220519153402.41540-1-damien.hedde@greensocs.com> References: <20220519153402.41540-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @greensocs.com) X-ZM-MESSAGEID: 1652974715789100001 Instead of checking the phase everytime, just store the result in a flag. We will use more of it in the following commit. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Jim Shu --- softmmu/qdev-monitor.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 12fe60c467..d68ef883b5 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -619,6 +619,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *op= ts, char *id; DeviceState *dev =3D NULL; BusState *bus =3D NULL; + bool is_hotplug =3D phase_check(PHASE_MACHINE_READY); =20 driver =3D qdict_get_try_str(opts, "driver"); if (!driver) { @@ -662,7 +663,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *op= ts, return NULL; } =20 - if (phase_check(PHASE_MACHINE_READY) && bus && !qbus_is_hotpluggable(b= us)) { + if (is_hotplug && bus && !qbus_is_hotpluggable(bus)) { error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name); return NULL; } @@ -676,7 +677,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *op= ts, dev =3D qdev_new(driver); =20 /* Check whether the hotplug is allowed by the machine */ - if (phase_check(PHASE_MACHINE_READY)) { + if (is_hotplug) { if (!qdev_hotplug_allowed(dev, errp)) { goto err_del_dev; } --=20 2.36.1 From nobody Tue Feb 10 00:24:45 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1652975404; cv=none; d=zohomail.com; s=zohoarc; b=X5QqJ+mh8b40J+onwzVzISpC05gmPmonERQF0tFE6z559SKwUpunIxMACxqrTpnK/ZiNX0VXKcygKv4kziGbmW2KL7+0p578pBv7/GyMTzlMhs6eO7JfKPMSFtZ1cPRXYT9MnqpyLO2BjCfVloWYjREVX2Q9GpPON5jfO9+x18I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652975404; 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; bh=ZMp/HqUEwGgcbMpnHPrC2IOeZfv+if927mN1x1VBfxg=; b=bjTn9eKHpXJ8O5P1uNKO/0VSKc2xZgJJCXbdIriEQP5n8wZdYRG0djS61wc8vy10WkK5znUUAH1hCFW63gHKi3zlR1tD8yClYDP18E0wEZE3eLUd6CqBfKet01kIZi9L1u1fToO3k2IaLDz/pWkc4JNyGsHERYTxRkcIwXJLn/A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1652975404144105.08293558876676; Thu, 19 May 2022 08:50:04 -0700 (PDT) Received: from localhost ([::1]:36352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nriPa-000511-Ub for importer@patchew.org; Thu, 19 May 2022 11:50:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nriAp-0001cc-9h for qemu-devel@nongnu.org; Thu, 19 May 2022 11:34:54 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:49102) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nriAf-0007pq-3l for qemu-devel@nongnu.org; Thu, 19 May 2022 11:34:45 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.10]) by beetle.greensocs.com (Postfix) with ESMTPS id BFD9021EB6; Thu, 19 May 2022 15:34:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1652974467; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZMp/HqUEwGgcbMpnHPrC2IOeZfv+if927mN1x1VBfxg=; b=Mk3KF1Ge8bnQbwVh3ms3i7mPwyCPqsOFT0C/sBp3mvJZNgSwRTfS+7sAJH/4Vodu8q0rO/ Y+yrqnuPFDUziO0H3cZatDG395fca1r0bSyk+1ZHJayjKuFkMK+jk6KbIjRb4XJVKdCfaW mJKwhAATv8jAcQcfN27BGEk+YxI//7U= From: Damien Hedde To: qemu-devel@nongnu.org Cc: mark.burton@greensocs.com, edgari@xilinx.com, Damien Hedde , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost Subject: [PATCH v5 5/6] RFC qapi/device_add: handle the rom_order_override when cold-plugging Date: Thu, 19 May 2022 17:34:01 +0200 Message-Id: <20220519153402.41540-6-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220519153402.41540-1-damien.hedde@greensocs.com> References: <20220519153402.41540-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @greensocs.com) X-ZM-MESSAGEID: 1652975405423100001 Content-Type: text/plain; charset="utf-8" rom_set_order_override() and rom_reset_order_override() were called in qemu_create_cli_devices() to set the rom_order_override value once and for all when creating the devices added on CLI. Unfortunately this won't work with qapi commands. Move the calls inside device_add so that it will be done in every case: + CLI option: -device + QAPI command: device_add rom_[set|reset]_order_override() are implemented in hw/core/loader.c They either do nothing or call fw_cfg_[set|reset]_order_override(). The later functions are implemented in hw/nvram/fw_cfg.c and only change an integer value of a "global" variable. In consequence, there are no complex side effects involved and we can safely move them from outside the -device option loop to the inner function. Signed-off-by: Damien Hedde --- I see 2 other ways to handle this: 1. Adding a new option to device_add. We could add a new boolean (_rom_order_override_ for example) option tot he qapi command. This flag would then be forced to "true" when handling "-device" parameter from CLI. The flag default could be: - always false - false on hot-plug, true on cold-plug. 2. Adding a new qapi command We could add one or two commands to do the rom_[set|reset]_order_override() operation. --- softmmu/qdev-monitor.c | 11 +++++++++++ softmmu/vl.c | 2 -- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index d68ef883b5..7cbee2b0d8 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -43,6 +43,7 @@ #include "hw/qdev-properties.h" #include "hw/clock.h" #include "hw/boards.h" +#include "hw/loader.h" =20 /* * Aliases were a bad idea from the start. Let's keep them @@ -673,6 +674,10 @@ DeviceState *qdev_device_add_from_qdict(const QDict *o= pts, return NULL; } =20 + if (!is_hotplug) { + rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE); + } + /* create device */ dev =3D qdev_new(driver); =20 @@ -714,6 +719,9 @@ DeviceState *qdev_device_add_from_qdict(const QDict *op= ts, if (!qdev_realize(DEVICE(dev), bus, errp)) { goto err_del_dev; } + if (!is_hotplug) { + rom_reset_order_override(); + } return dev; =20 err_del_dev: @@ -721,6 +729,9 @@ err_del_dev: object_unparent(OBJECT(dev)); object_unref(OBJECT(dev)); } + if (!is_hotplug) { + rom_reset_order_override(); + } return NULL; } =20 diff --git a/softmmu/vl.c b/softmmu/vl.c index ea15e37973..5a0d54b595 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2635,7 +2635,6 @@ static void qemu_create_cli_devices(void) } =20 /* init generic devices */ - rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE); qemu_opts_foreach(qemu_find_opts("device"), device_init_func, NULL, &error_fatal); QTAILQ_FOREACH(opt, &device_opts, next) { @@ -2652,7 +2651,6 @@ static void qemu_create_cli_devices(void) object_unref(OBJECT(dev)); loc_pop(&opt->loc); } - rom_reset_order_override(); } =20 static void qemu_machine_creation_done(void) --=20 2.36.1 From nobody Tue Feb 10 00:24:45 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1652974697; cv=none; d=zohomail.com; s=zohoarc; b=GC+Y7q8kxp8VZ3zcnPEZKPw0IMJm5AZNd9aXNNXeyPugKymwQz0+lQSdhx5mwHKmyaoWt/AGj6mO3kBmzhxtJpvEfFTcVZUIbA8tYzyzg2pDDase7/O1XDhRHJGRT0n1QQYdQ9p2f2sO54pHFLY/t97uMxqVCDz74Lh+WCS7tfQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652974697; 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; bh=QeWnil44tT+hHONeKx07OOPCoTcvcDXkdkPxA/V/xiI=; b=DSYCFuGbbIBmZES0+oWcPDZb19DkiK1BxOwTf/LfjAerSG4kt0l8NIXsSLsijM8ZlYOZmZG16Xc9vIlhBidJ2k/Ni5MgoGlsAqJwl7P6NvB8gCD46DRP9E+ujOQ+mC+sbKbBds7UpxlAOVWKAmTxqpG9hs9sNAd543YmpEA0IhI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1652974697348325.75643323533336; Thu, 19 May 2022 08:38:17 -0700 (PDT) Received: from localhost ([::1]:40070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nriEA-0004iE-Gf for importer@patchew.org; Thu, 19 May 2022 11:38:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nriAn-0001cY-FX for qemu-devel@nongnu.org; Thu, 19 May 2022 11:34:53 -0400 Received: from beetle.greensocs.com ([5.135.226.135]:49104) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nriAh-0007ps-89 for qemu-devel@nongnu.org; Thu, 19 May 2022 11:34:42 -0400 Received: from crumble.bar.greensocs.com (unknown [172.17.10.10]) by beetle.greensocs.com (Postfix) with ESMTPS id 390A321EBE; Thu, 19 May 2022 15:34:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=greensocs.com; s=mail; t=1652974468; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QeWnil44tT+hHONeKx07OOPCoTcvcDXkdkPxA/V/xiI=; b=tsQxZ92QZN/KtT5ew97zFbSnmo+Vm7c+C4cjk8jU5GCoVC7amRidFG1FD0eMcDFRYsemJC 2anUHHRY8yvnQeoa2jU3xiqWQbkljvfneJcBOlqIXYErK/rtHXZGZIr2RNw6OZOQ/JDUP4 hnG6f73iHdb7r4McA20mzIr9v8kthTE= From: Damien Hedde To: qemu-devel@nongnu.org Cc: mark.burton@greensocs.com, edgari@xilinx.com, Mirela Grujic , Damien Hedde , "Dr. David Alan Gilbert" , Markus Armbruster , Eric Blake , Paolo Bonzini , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Eduardo Habkost Subject: [PATCH v5 6/6] qapi/device_add: Allow execution in machine initialized phase Date: Thu, 19 May 2022 17:34:02 +0200 Message-Id: <20220519153402.41540-7-damien.hedde@greensocs.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220519153402.41540-1-damien.hedde@greensocs.com> References: <20220519153402.41540-1-damien.hedde@greensocs.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=5.135.226.135; envelope-from=damien.hedde@greensocs.com; helo=beetle.greensocs.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @greensocs.com) X-ZM-MESSAGEID: 1652974700229100001 Content-Type: text/plain; charset="utf-8" From: Mirela Grujic This commit allows to use the QMP command to add a cold-plugged device like we can do with the CLI option -device. Note: for device_add command in qdev.json adding the 'allow-preconfig' option has no effect because the command appears to bypass QAPI (see TODO at qapi/qdev.json:61). The option is added there solely to document the intent. For the same reason, the flags have to be explicitly set in monitor_init_qmp_commands() when the device_add command is registered. Signed-off-by: Mirela Grujic Signed-off-by: Damien Hedde Tested-by: Jim Shu --- v4: + use phase_until() + add missing flag in hmp-commands.hx --- qapi/qdev.json | 3 ++- monitor/misc.c | 2 +- softmmu/qdev-monitor.c | 4 ++++ hmp-commands.hx | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/qapi/qdev.json b/qapi/qdev.json index 26cd10106b..2e2de41499 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -77,7 +77,8 @@ { 'command': 'device_add', 'data': {'driver': 'str', '*bus': 'str', '*id': 'str'}, 'gen': false, # so we can get the additional arguments - 'features': ['json-cli', 'json-cli-hotplug'] } + 'features': ['json-cli', 'json-cli-hotplug'], + 'allow-preconfig': true } =20 ## # @device_del: diff --git a/monitor/misc.c b/monitor/misc.c index 6c5bb82d3b..d3d413d70c 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -233,7 +233,7 @@ static void monitor_init_qmp_commands(void) qmp_init_marshal(&qmp_commands); =20 qmp_register_command(&qmp_commands, "device_add", - qmp_device_add, 0, 0); + qmp_device_add, QCO_ALLOW_PRECONFIG, 0); =20 QTAILQ_INIT(&qmp_cap_negotiation_commands); qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities", diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index 7cbee2b0d8..c53f62be51 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -855,6 +855,10 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, = Error **errp) QemuOpts *opts; DeviceState *dev; =20 + if (!phase_until(PHASE_MACHINE_INITIALIZED, errp)) { + return; + } + opts =3D qemu_opts_from_qdict(qemu_find_opts("device"), qdict, errp); if (!opts) { return; diff --git a/hmp-commands.hx b/hmp-commands.hx index 03e6a73d1f..0091b8e2dd 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -672,6 +672,7 @@ ERST .help =3D "add device, like -device on the command line", .cmd =3D hmp_device_add, .command_completion =3D device_add_completion, + .flags =3D "p", }, =20 SRST --=20 2.36.1