qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Dongli Zhang <dongli.zhang@oracle.com>
To: qemu-devel@nongnu.org
Cc: eduardo@habkost.net, marcel.apfelbaum@gmail.com,
	philmd@linaro.org, wangyanan55@huawei.com, zhao1.liu@intel.com,
	Joe Jin <joe.jin@oracle.com>
Subject: Re: [PATCH 1/1] cpus: resume hotplugged vCPU only when the guest is running
Date: Mon, 10 Nov 2025 23:42:55 -0800	[thread overview]
Message-ID: <9eee231c-4b51-49bc-a89e-f44891174eac@oracle.com> (raw)
In-Reply-To: <20251010213639.1634-1-dongli.zhang@oracle.com>

Ping?

This can prevent un-predictable symptoms during Libvirt/QEMU live migration,
especially when hotpluggable='yes' for vCPU in Libvirt XML file.

For instance, vCPU hotpluggable='yes' is equivalent to:

1. Create source QEMU with "-smp 1,maxvcpus=4". Keep QEMU in prelaunch state.

2. Cold-plug vCPUs=1,2,3 to source QEMU (prelaunch).

3. Continue source QEMU to running status.

4. Create target QEMU with "-smp 1,maxvpus=4". Target QEMU remains
prelaunch/stopped.

5. Cold plug vCPUs=1,2,3 to target QEMU. They are expected to remain in stopped
status.

Unfortunately, due to the bug, vCPUs=1,2,3 are in running status. There are
chances for them to start running in KVM guest mode before target QEMU is fully
resumed during live migration.

As a result, anything abnormal can happen.

Thank you very much!

Dongli Zhang

On 10/10/25 2:36 PM, Dongli Zhang wrote:
> 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 */



      reply	other threads:[~2025-11-11  7:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-10 21:36 [PATCH 1/1] cpus: resume hotplugged vCPU only when the guest is running Dongli Zhang
2025-11-11  7:42 ` Dongli Zhang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9eee231c-4b51-49bc-a89e-f44891174eac@oracle.com \
    --to=dongli.zhang@oracle.com \
    --cc=eduardo@habkost.net \
    --cc=joe.jin@oracle.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=wangyanan55@huawei.com \
    --cc=zhao1.liu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).