qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] cpus: resume hotplugged vCPU only when the guest is running
@ 2025-10-10 21:36 Dongli Zhang
  0 siblings, 0 replies; only message in thread
From: Dongli Zhang @ 2025-10-10 21:36 UTC (permalink / raw)
  To: qemu-devel; +Cc: eduardo, marcel.apfelbaum, philmd, wangyanan55, zhao1.liu

When a new vCPU is hotplugged, cpu->stopped is unconditionally set to false
by cpu_common_realizefn().

However, there are scenarios where the guest is not running, i.e., when the
guest has been stopped via the HMP 'stop' command, or when the instance is
a live migration target started with "-incoming defer". In these cases, all
existing vCPUs have (cpu->stopped == true), except for the newly hotplugged
vCPU.

Unpause the hotplugged vCPU only when the guest is running.

Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
 hw/core/cpu-common.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
index 8c306c89e4..789382cad5 100644
--- a/hw/core/cpu-common.c
+++ b/hw/core/cpu-common.c
@@ -30,6 +30,7 @@
 #include "qemu/target-info.h"
 #include "exec/log.h"
 #include "exec/gdbstub.h"
+#include "system/runstate.h"
 #include "system/tcg.h"
 #include "hw/boards.h"
 #include "hw/qdev-properties.h"
@@ -263,7 +264,10 @@ static void cpu_common_realizefn(DeviceState *dev, Error **errp)
 
     if (dev->hotplugged) {
         cpu_synchronize_post_init(cpu);
-        cpu_resume(cpu);
+
+        if (runstate_is_running()) {
+            cpu_resume(cpu);
+        }
     }
 
     /* NOTE: latest generic point where the cpu is fully realized */
-- 
2.39.3



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-10-10 21:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-10 21:36 [PATCH 1/1] cpus: resume hotplugged vCPU only when the guest is running Dongli Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).