From patchwork Thu May 19 15:33:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Damien Hedde X-Patchwork-Id: 1633338 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=greensocs.com header.i=@greensocs.com header.a=rsa-sha256 header.s=mail header.b=tePtb47u; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L3vHK2Gjkz9sPf for ; Fri, 20 May 2022 01:42:05 +1000 (AEST) Received: from localhost ([::1]:44836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nriHq-000856-QJ for incoming@patchwork.ozlabs.org; Thu, 19 May 2022 11:42:02 -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_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" phase_get() returns the current phase, we'll use it in next commit. Signed-off-by: Damien Hedde Reviewed-by: Philippe Mathieu-Daudé 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; +/* + * 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); #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) static MachineInitPhase machine_phase; +MachineInitPhase phase_get(void) +{ + return machine_phase; +} + bool phase_check(MachineInitPhase phase) { return machine_phase >= phase; From patchwork Thu May 19 15:33:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Hedde X-Patchwork-Id: 1633339 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=greensocs.com header.i=@greensocs.com header.a=rsa-sha256 header.s=mail header.b=daXCasdc; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L3vHw42BJz9sPf for ; Fri, 20 May 2022 01:42:36 +1000 (AEST) Received: from localhost ([::1]:45906 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nriIM-0000PI-Io for incoming@patchwork.ozlabs.org; Thu, 19 May 2022 11:42:34 -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_P=2E_Berrang=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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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); +/** + * @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 initialization"); return; } + phase_until(PHASE_MACHINE_READY, errp); +} +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. */ if (loadvm) { load_snapshot(loadvm, NULL, false, NULL, &error_fatal); @@ -2729,6 +2735,46 @@ void qmp_x_exit_preconfig(Error **errp) } } +bool phase_until(MachineInitPhase phase, Error **errp) +{ + ERRP_GUARD(); + if (!phase_check(PHASE_ACCEL_CREATED)) { + error_setg(errp, "Phase transition is not supported until accelerator" + " is created"); + return false; + } + + while (!phase_check(phase)) { + MachineInitPhase cur_phase = 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; From patchwork Thu May 19 15:33:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Damien Hedde X-Patchwork-Id: 1633336 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=greensocs.com header.i=@greensocs.com header.a=rsa-sha256 header.s=mail header.b=IX4lK/pt; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L3v8z307Dz9sPf for ; Fri, 20 May 2022 01:36:33 +1000 (AEST) Received: from localhost ([::1]:35698 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nriCU-0001eB-DC for incoming@patchwork.ozlabs.org; Thu, 19 May 2022 11:36:30 -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_Mathieu-Daud?= =?utf-8?q?=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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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é 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) void qmp_x_exit_preconfig(Error **errp) { - if (phase_check(PHASE_MACHINE_INITIALIZED)) { - error_setg(errp, "The command is permitted only before machine initialization"); + 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) 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 **errp) 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; From patchwork Thu May 19 15:34:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Damien Hedde X-Patchwork-Id: 1633337 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=greensocs.com header.i=@greensocs.com header.a=rsa-sha256 header.s=mail header.b=A02OLMJX; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L3v9F6T9nz9sPf for ; Fri, 20 May 2022 01:36:49 +1000 (AEST) Received: from localhost ([::1]:36800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nriCl-0002X4-W5 for incoming@patchwork.ozlabs.org; Thu, 19 May 2022 11:36:48 -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_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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é 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 *opts, char *id; DeviceState *dev = NULL; BusState *bus = NULL; + bool is_hotplug = phase_check(PHASE_MACHINE_READY); driver = qdict_get_try_str(opts, "driver"); if (!driver) { @@ -662,7 +663,7 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts, return NULL; } - if (phase_check(PHASE_MACHINE_READY) && bus && !qbus_is_hotpluggable(bus)) { + 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 *opts, dev = qdev_new(driver); /* 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; } From patchwork Thu May 19 15:34:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Hedde X-Patchwork-Id: 1633370 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=greensocs.com header.i=@greensocs.com header.a=rsa-sha256 header.s=mail header.b=Mk3KF1Ge; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L3vQJ21f3z9sPf for ; Fri, 20 May 2022 01:48:08 +1000 (AEST) Received: from localhost ([::1]:59068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nriNi-0001JC-8u for incoming@patchwork.ozlabs.org; Thu, 19 May 2022 11:48:06 -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_P=2E_Berrang=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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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" /* * Aliases were a bad idea from the start. Let's keep them @@ -673,6 +674,10 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts, return NULL; } + if (!is_hotplug) { + rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE); + } + /* create device */ dev = qdev_new(driver); @@ -714,6 +719,9 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts, if (!qdev_realize(DEVICE(dev), bus, errp)) { goto err_del_dev; } + if (!is_hotplug) { + rom_reset_order_override(); + } return dev; 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; } 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) } /* 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(); } static void qemu_machine_creation_done(void) From patchwork Thu May 19 15:34:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Hedde X-Patchwork-Id: 1633334 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=greensocs.com header.i=@greensocs.com header.a=rsa-sha256 header.s=mail header.b=tsQxZ92Q; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L3v9049Skz9tk1 for ; Fri, 20 May 2022 01:36:36 +1000 (AEST) Received: from localhost ([::1]:35810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nriCY-0001kH-9J for incoming@patchwork.ozlabs.org; Thu, 19 May 2022 11:36:34 -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_P=2E_Berrang=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 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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 } ## # @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); qmp_register_command(&qmp_commands, "device_add", - qmp_device_add, 0, 0); + qmp_device_add, QCO_ALLOW_PRECONFIG, 0); 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; + if (!phase_until(PHASE_MACHINE_INITIALIZED, errp)) { + return; + } + opts = 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 = "add device, like -device on the command line", .cmd = hmp_device_add, .command_completion = device_add_completion, + .flags = "p", }, SRST