[PATCH 10/14] accel/mshv: implement cpu_thread_is_idle() hook

Anirudh Rayabharam (Microsoft) posted 14 patches 3 weeks, 6 days ago
Maintainers: Magnus Kulke <magnuskulke@linux.microsoft.com>, Wei Liu <wei.liu@kernel.org>, Peter Maydell <peter.maydell@linaro.org>, Anirudh Rayabharam <anirudh@anirudhrb.com>, Aastha Rawat <aastharawat@linux.microsoft.com>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
There is a newer version of this series
[PATCH 10/14] accel/mshv: implement cpu_thread_is_idle() hook
Posted by Anirudh Rayabharam 3 weeks, 6 days ago
From: Magnus Kulke <magnuskulke@linux.microsoft.com>

In MSHV the hypervisor APIC is always used, so we to implement this hook
to make sure the AP's vcpu thread is not blocked waiting for an INIT SIPI
by the BSP. Without this change soft reboots with -smp cpus>=2 will
hang.

Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com>
---
 accel/mshv/mshv-all.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c
index 563599ef6a..9a101d51ff 100644
--- a/accel/mshv/mshv-all.c
+++ b/accel/mshv/mshv-all.c
@@ -747,11 +747,23 @@ static const TypeInfo mshv_accel_type = {
     .instance_size = sizeof(MshvState),
 };
 
+/*
+ * MSHV manages the LAPIC in the hypervisor. SIPI for APs are handled
+ * internally. Halted vCPUs must still enter mshv_cpu_exec() so that
+ * MSHV_RUN_VP is called and the hypervisor will deliver SIPI to wake APs.
+ */
+
+static bool mshv_vcpu_thread_is_idle(CPUState *cpu)
+{
+    return false;
+}
+
 static void mshv_accel_ops_class_init(ObjectClass *oc, const void *data)
 {
     AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
 
     ops->create_vcpu_thread = mshv_start_vcpu_thread;
+    ops->cpu_thread_is_idle = mshv_vcpu_thread_is_idle;
     ops->synchronize_post_init = mshv_cpu_synchronize_post_init;
     ops->synchronize_post_reset = mshv_cpu_synchronize_post_reset;
     ops->synchronize_state = mshv_cpu_synchronize;

-- 
2.43.0
Re: [PATCH 10/14] accel/mshv: implement cpu_thread_is_idle() hook
Posted by Mohamed Mediouni 3 weeks, 6 days ago

> On 11. Mar 2026, at 16:15, Anirudh Rayabharam <anirudh@anirudhrb.com> wrote:
> 
> From: Magnus Kulke <magnuskulke@linux.microsoft.com>
> 
> In MSHV the hypervisor APIC is always used, so we to implement this hook
> to make sure the AP's vcpu thread is not blocked waiting for an INIT SIPI
> by the BSP. Without this change soft reboots with -smp cpus>=2 will
> hang.
> 
> Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com>
Reviewed-by: Mohamed Mediouni <mohamed@unpredictable.fr>
> ---
> accel/mshv/mshv-all.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
> 
> diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c
> index 563599ef6a..9a101d51ff 100644
> --- a/accel/mshv/mshv-all.c
> +++ b/accel/mshv/mshv-all.c
> @@ -747,11 +747,23 @@ static const TypeInfo mshv_accel_type = {
>     .instance_size = sizeof(MshvState),
> };
> 
> +/*
> + * MSHV manages the LAPIC in the hypervisor. SIPI for APs are handled
> + * internally. Halted vCPUs must still enter mshv_cpu_exec() so that
> + * MSHV_RUN_VP is called and the hypervisor will deliver SIPI to wake APs.
> + */
> +
> +static bool mshv_vcpu_thread_is_idle(CPUState *cpu)
> +{
> +    return false;
> +}
> +
> static void mshv_accel_ops_class_init(ObjectClass *oc, const void *data)
> {
>     AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
> 
>     ops->create_vcpu_thread = mshv_start_vcpu_thread;
> +    ops->cpu_thread_is_idle = mshv_vcpu_thread_is_idle;
>     ops->synchronize_post_init = mshv_cpu_synchronize_post_init;
>     ops->synchronize_post_reset = mshv_cpu_synchronize_post_reset;
>     ops->synchronize_state = mshv_cpu_synchronize;
> 
> -- 
> 2.43.0
> 
>