Hi Mohamed,

I gave this a try with the CPU hotplug reproducer from my earlier
mail: the Ubuntu 24.04 arm64 cloud image on an M2 Pro (macOS 15.7),
"-M virt -accel hvf -cpu host -smp 2", then as root:

  echo 0 > /sys/devices/system/cpu/cpu1/online
  echo 1 > /sys/devices/system/cpu/cpu1/online

On current master (e9fa1f6) the guest still panics on the second
command ("kernel BUG at arch/arm64/kernel/smp.c:388"), 3 out of 3
runs. With this patch on top, CPU1 comes back online and the guest
carries on, 3 out of 3 runs.

I can't judge Peter's question about which sync call is the right
one, but if it helps:

Tested-by: Adrien Kohlbecker <[email protected]>

I'm happy to test a v3 too.

Thanks,
Adrien

On Tue, Oct 27, 2026, at 13:01, Mohamed Mediouni wrote:
> In case of PSCI off followed by a PSCI on which
> is a scenario that happens notably during kexec,
> what happens today is that the state sync does
> not happen and the vCPU becomes in an unexpected state.
>
> Address this via marking the vCPU as dirty during a PSCI power on.
>
> Signed-off-by: Mohamed Mediouni <[email protected]>
> ---
>  target/arm/hvf/hvf.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c
> index e1ddfe14c7..7ce2e38df1 100644
> --- a/target/arm/hvf/hvf.c
> +++ b/target/arm/hvf/hvf.c
> @@ -1651,6 +1651,14 @@ static bool hvf_handle_psci_call(CPUState *cpu, 
> int *excp_ret)
>          context_id = param[3];
>          ret = arm_set_cpu_on(mpidr, entry, context_id,
>                               hvf_psci_get_target_el(), target_aarch64);
> +
> +        /*
> +         * Mark state as dirty for HVF to sync context
> +         * when the vCPU runs. arm_set_cpu_on() does not
> +         * do it by itself.
> +         */
> +        arm_get_cpu_by_id(mpidr)->vcpu_dirty = true;
> +
>          break;
>      case QEMU_PSCI_0_1_FN_CPU_OFF:
>      case QEMU_PSCI_0_2_FN_CPU_OFF:
> -- 
> 2.54.0 (Apple Git-157)

Reply via email to