Skip to contentSkip to conversation

hw/hyperv: fix SynIC not initialized for CPUs after the first

PATCH In review Ani Sinha 2 participants 2 messages Mar 20 – Mar 23 KVM

lore
Share & tools
lore

Ani Sinha

author
#0 lore raw

PATCH v2 1/1 hw/hyperv: fix SynIC not initialized for CPUs after the first

From: Sourav Poddar <[email protected]>

hyperv_is_synic_enabled() is a global flag that returns true after the first CPU initializes SynIC. With -smp N, all subsequent CPUs skip hyperv_x86_synic_add(), leaving them without a synic object. This causes get_synic() to return NULL, making hyperv_sint_route_new() fail and triggering an assertion crash in hyperv_testdev.

Fix by introducing hyperv_is_synic_present() which checks per-CPU whether a synic object is already attached instead of using the global flag.

Fixes c4cf32fc63f1 ("kvm/hyperv: add synic feature to CPU only if its not enabled")
---
 hw/hyperv/hyperv.c         | 5 +++++
 include/hw/hyperv/hyperv.h | 1 +
 target/i386/kvm/hyperv.c   | 2 +-
 3 files changed, 7 insertions(+), 1 deletion(-)
hw/hyperv/hyperv.c +5 -0
index 27e323a819..3d6212613e 100644
@@ -60,6 +60,11 @@ static SynICState *get_synic(CPUState *cs)
     return SYNIC(object_resolve_path_component(OBJECT(cs), "synic"));
 }
 
+bool hyperv_is_synic_present(CPUState *cs)
+{
+    return get_synic(cs);
+}
+
 static void synic_update(SynICState *synic, bool sctl_enable,
                          hwaddr msg_page_addr, hwaddr event_page_addr)
 {
include/hw/hyperv/hyperv.h +1 -0
index 63a8b65278..23091301d0 100644
@@ -81,6 +81,7 @@ void hyperv_synic_reset(CPUState *cs);
 void hyperv_synic_update(CPUState *cs, bool enable,
                          hwaddr msg_page_addr, hwaddr event_page_addr);
 bool hyperv_is_synic_enabled(void);
+bool hyperv_is_synic_present(CPUState *cs);
 
 /*
  * Process HVCALL_RESET_DEBUG_SESSION hypercall.
target/i386/kvm/hyperv.c +1 -1
index bd3c26d02b..420c76b5ff 100644
@@ -27,7 +27,7 @@ int hyperv_x86_synic_add(X86CPU *cpu)
 int hyperv_enable_synic(X86CPU *cpu)
 {
     int ret = 0;
-    if (!hyperv_is_synic_enabled()) {
+    if (!hyperv_is_synic_present(CPU(cpu))) {
         ret = hyperv_x86_synic_add(cpu);
     }
     return ret;
Signature · 1 line
2.52.0
Tested-by on v2 1/1
#1 lore raw
Quoted 77 lines

-----Original Message-----
From: Ani Sinha <[email protected]>
Sent: Friday, March 20, 2026 11:48 PM
To: Paolo Bonzini <[email protected]>; Marcelo Tosatti <[email protected]>
Cc: Sourav Poddar <[email protected]>; Hao, Xudong <[email protected]>; Ani Sinha <[email protected]>; qemu- [email protected]; [email protected]
Subject: [PATCH for-11.0 v2] hw/hyperv: fix SynIC not initialized for CPUs after the first

From: Sourav Poddar <[email protected]>

hyperv_is_synic_enabled() is a global flag that returns true after the first CPU initializes SynIC. With -smp N, all subsequent CPUs skip hyperv_x86_synic_add(), leaving them without a synic object. This causes get_synic() to return NULL, making hyperv_sint_route_new() fail and triggering an assertion crash in hyperv_testdev.

Fix by introducing hyperv_is_synic_present() which checks per-CPU whether a synic object is already attached instead of using the global flag.

Fixes c4cf32fc63f1 ("kvm/hyperv: add synic feature to CPU only if its not

enabled")

---
 hw/hyperv/hyperv.c         | 5 +++++
 include/hw/hyperv/hyperv.h | 1 +
 target/i386/kvm/hyperv.c   | 2 +-
 3 files changed, 7 insertions(+), 1 deletion(-)
hw/hyperv/hyperv.c +5 -0
index 27e323a819..3d6212613e 100644
@@ -60,6 +60,11 @@ static SynICState *get_synic(CPUState *cs)
     return SYNIC(object_resolve_path_component(OBJECT(cs), "synic"));
 }
 
+bool hyperv_is_synic_present(CPUState *cs)
+{
+    return get_synic(cs);
+}
+
 static void synic_update(SynICState *synic, bool sctl_enable,
                          hwaddr msg_page_addr, hwaddr event_page_addr)
 {
include/hw/hyperv/hyperv.h +1 -0
index 63a8b65278..23091301d0 100644
@@ -81,6 +81,7 @@ void hyperv_synic_reset(CPUState *cs);
 void hyperv_synic_update(CPUState *cs, bool enable,
                          hwaddr msg_page_addr, hwaddr event_page_addr);
 bool hyperv_is_synic_enabled(void);
+bool hyperv_is_synic_present(CPUState *cs);
 
 /*
  * Process HVCALL_RESET_DEBUG_SESSION hypercall.
target/i386/kvm/hyperv.c +1 -2
index bd3c26d02b..420c76b5ff 100644
@@ -27,7 +27,7 @@ int hyperv_x86_synic_add(X86CPU *cpu)
 int hyperv_enable_synic(X86CPU *cpu)
 {
     int ret = 0;
-    if (!hyperv_is_synic_enabled()) {
+    if (!hyperv_is_synic_present(CPU(cpu))) {
         ret = hyperv_x86_synic_add(cpu);
     }
     return ret;
--
Quoted 1 line

2.52.0

Tested this patch and patch[1] together, KUT hyperv_connections and hyperv_synic test passed on Intel platforms Granite Rapids and Sierra Forest.

[1] i386/hyperv: add stubs for synic enablement https://lists.nongnu.org/archive/html/qemu-devel/2026-03/msg05955.html