If KVM provides VAPIC, don't set up kvmvapic.

Signed-off-by: Anthony Xu <anthony...@intel.com>
---
 hw/intc/apic_common.c | 5 ++++-
 include/sysemu/kvm.h  | 1 +
 kvm-all.c             | 5 +++++
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/hw/intc/apic_common.c b/hw/intc/apic_common.c
index c3829e3..bf72107 100644
--- a/hw/intc/apic_common.c
+++ b/hw/intc/apic_common.c
@@ -317,8 +317,11 @@ static void apic_common_realize(DeviceState *dev, Error 
**errp)
     info = APIC_COMMON_GET_CLASS(s);
     info->realize(dev, errp);
 
-    /* Note: We need at least 1M to map the VAPIC option ROM */
+    /* Note: We need at least 1M to map the VAPIC option ROM,
+       if it is KVM, enable kvmvapic only when KVM doesn't have
+       VAPIC capability                */
     if (!vapic && s->vapic_control & VAPIC_ENABLE_MASK &&
+        (!kvm_enabled() || (kvm_enabled() && !kvm_has_vapic())) &&
         !hax_enabled() && ram_size >= 1024 * 1024) {
         vapic = sysbus_create_simple("kvmvapic", -1, NULL);
     }
diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h
index 24281fc..43e0e4c 100644
--- a/include/sysemu/kvm.h
+++ b/include/sysemu/kvm.h
@@ -215,6 +215,7 @@ extern KVMState *kvm_state;
 
 bool kvm_has_free_slot(MachineState *ms);
 int kvm_has_sync_mmu(void);
+int kvm_has_vapic(void);
 int kvm_has_vcpu_events(void);
 int kvm_has_robust_singlestep(void);
 int kvm_has_debugregs(void);
diff --git a/kvm-all.c b/kvm-all.c
index 90b8573..c331c8c 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -2232,6 +2232,11 @@ int kvm_has_sync_mmu(void)
     return kvm_check_extension(kvm_state, KVM_CAP_SYNC_MMU);
 }
 
+int kvm_has_vapic(void)
+{
+    return !kvm_check_extension(kvm_state, KVM_CAP_VAPIC);
+}
+
 int kvm_has_vcpu_events(void)
 {
     return kvm_state->vcpu_events;
-- 
1.8.3.1


Reply via email to