[PATCH v3 09/10] qemu-kvm: Use upstream kvm-apic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Drop the qemu-kvm version in favor of the equivalent upstream
implementation.

Signed-off-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
---
 hw/apic.c         |  151 +---------------------------------------------------
 hw/pc.c           |    5 +--
 qemu-kvm-x86.c    |   31 -----------
 qemu-kvm.h        |   25 ---------
 target-i386/kvm.c |    8 ---
 5 files changed, 4 insertions(+), 216 deletions(-)

diff --git a/hw/apic.c b/hw/apic.c
index 4eb0019..ff9d24e 100644
--- a/hw/apic.c
+++ b/hw/apic.c
@@ -22,7 +22,6 @@
 #include "host-utils.h"
 #include "trace.h"
 #include "pc.h"
-#include "kvm.h"
 
 #define MAX_APIC_WORDS 8
 
@@ -133,35 +132,9 @@ void apic_deliver_pic_intr(DeviceState *d, int level)
     }
 }
 
-static inline uint32_t kapic_reg(struct kvm_lapic_state *kapic, int reg_id);
-
-static void kvm_irqchip_deliver_nmi(void *p)
-{
-    APICCommonState *s = p;
-    struct kvm_lapic_state klapic;
-    uint32_t lvt;
-
-    kvm_get_lapic(s->cpu_env, &klapic);
-    lvt = kapic_reg(&klapic, 0x32 + APIC_LVT_LINT1);
-
-    if (lvt & APIC_LVT_MASKED) {
-        return;
-    }
-
-    if (((lvt >> 8) & 7) != APIC_DM_NMI) {
-        return;
-    }
-
-    kvm_vcpu_ioctl(s->cpu_env, KVM_NMI);
-}
-
 static void apic_external_nmi(APICCommonState *s)
 {
-    if (kvm_irqchip_in_kernel()) {
-        run_on_cpu(s->cpu_env, kvm_irqchip_deliver_nmi, s);
-    } else {
-        apic_local_deliver(s, APIC_LVT_LINT1);
-    }
+    apic_local_deliver(s, APIC_LVT_LINT1);
 }
 
 #define foreach_apic(apic, deliver_bitmask, code) \
@@ -254,11 +227,8 @@ void apic_deliver_irq(uint8_t dest, uint8_t dest_mode, uint8_t delivery_mode,
 
 static void apic_set_base(APICCommonState *s, uint64_t val)
 {
-    if (kvm_enabled() && kvm_irqchip_in_kernel())
-        s->apicbase = val;
-    else
-        s->apicbase = (val & 0xfffff000) |
-            (s->apicbase & (MSR_IA32_APICBASE_BSP | MSR_IA32_APICBASE_ENABLE));
+    s->apicbase = (val & 0xfffff000) |
+        (s->apicbase & (MSR_IA32_APICBASE_BSP | MSR_IA32_APICBASE_ENABLE));
     /* if disabled, cannot be enabled again */
     if (!(val & MSR_IA32_APICBASE_ENABLE)) {
         s->apicbase &= ~MSR_IA32_APICBASE_ENABLE;
@@ -270,9 +240,6 @@ static void apic_set_base(APICCommonState *s, uint64_t val)
 static void apic_set_tpr(APICCommonState *s, uint8_t val)
 {
     s->tpr = (val & 0x0f) << 4;
-    if (kvm_enabled() && kvm_irqchip_in_kernel()) {
-        return;
-    }
     apic_update_irq(s);
 }
 
@@ -770,120 +737,8 @@ static void apic_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val)
     }
 }
 
-#ifdef KVM_CAP_IRQCHIP
-
-static inline uint32_t kapic_reg(struct kvm_lapic_state *kapic, int reg_id)
-{
-    return *((uint32_t *) (kapic->regs + (reg_id << 4)));
-}
-
-static inline void kapic_set_reg(struct kvm_lapic_state *kapic,
-                                 int reg_id, uint32_t val)
-{
-    *((uint32_t *) (kapic->regs + (reg_id << 4))) = val;
-}
-
-static void kvm_kernel_lapic_save_to_user(APICCommonState *s)
-{
-    struct kvm_lapic_state apic;
-    struct kvm_lapic_state *kapic = &apic;
-    int i, v;
-
-    kvm_get_lapic(s->cpu_env, kapic);
-
-    s->id = kapic_reg(kapic, 0x2) >> 24;
-    s->tpr = kapic_reg(kapic, 0x8);
-    s->arb_id = kapic_reg(kapic, 0x9);
-    s->log_dest = kapic_reg(kapic, 0xd) >> 24;
-    s->dest_mode = kapic_reg(kapic, 0xe) >> 28;
-    s->spurious_vec = kapic_reg(kapic, 0xf);
-    for (i = 0; i < 8; i++) {
-        s->isr[i] = kapic_reg(kapic, 0x10 + i);
-        s->tmr[i] = kapic_reg(kapic, 0x18 + i);
-        s->irr[i] = kapic_reg(kapic, 0x20 + i);
-    }
-    s->esr = kapic_reg(kapic, 0x28);
-    s->icr[0] = kapic_reg(kapic, 0x30);
-    s->icr[1] = kapic_reg(kapic, 0x31);
-    for (i = 0; i < APIC_LVT_NB; i++)
-	s->lvt[i] = kapic_reg(kapic, 0x32 + i);
-    s->initial_count = kapic_reg(kapic, 0x38);
-    s->divide_conf = kapic_reg(kapic, 0x3e);
-
-    v = (s->divide_conf & 3) | ((s->divide_conf >> 1) & 4);
-    s->count_shift = (v + 1) & 7;
-
-    s->initial_count_load_time = qemu_get_clock_ns(vm_clock);
-    apic_next_timer(s, s->initial_count_load_time);
-}
-
-static void kvm_kernel_lapic_load_from_user(APICCommonState *s)
-{
-    struct kvm_lapic_state apic;
-    struct kvm_lapic_state *klapic = &apic;
-    int i;
-
-    memset(klapic, 0, sizeof apic);
-    kapic_set_reg(klapic, 0x2, s->id << 24);
-    kapic_set_reg(klapic, 0x8, s->tpr);
-    kapic_set_reg(klapic, 0xd, s->log_dest << 24);
-    kapic_set_reg(klapic, 0xe, s->dest_mode << 28 | 0x0fffffff);
-    kapic_set_reg(klapic, 0xf, s->spurious_vec);
-    for (i = 0; i < 8; i++) {
-        kapic_set_reg(klapic, 0x10 + i, s->isr[i]);
-        kapic_set_reg(klapic, 0x18 + i, s->tmr[i]);
-        kapic_set_reg(klapic, 0x20 + i, s->irr[i]);
-    }
-    kapic_set_reg(klapic, 0x28, s->esr);
-    kapic_set_reg(klapic, 0x30, s->icr[0]);
-    kapic_set_reg(klapic, 0x31, s->icr[1]);
-    for (i = 0; i < APIC_LVT_NB; i++)
-        kapic_set_reg(klapic, 0x32 + i, s->lvt[i]);
-    kapic_set_reg(klapic, 0x38, s->initial_count);
-    kapic_set_reg(klapic, 0x3e, s->divide_conf);
-
-    kvm_set_lapic(s->cpu_env, klapic);
-}
-
-#endif
-
-void kvm_load_lapic(CPUState *env)
-{
-#ifdef KVM_CAP_IRQCHIP
-    APICCommonState *s =
-        DO_UPCAST(APICCommonState, busdev.qdev, env->apic_state);
-
-    if (!s) {
-        return;
-    }
-
-    if (kvm_enabled() && kvm_irqchip_in_kernel()) {
-        kvm_kernel_lapic_load_from_user(s);
-    }
-#endif
-}
-
-void kvm_save_lapic(CPUState *env)
-{
-#ifdef KVM_CAP_IRQCHIP
-    APICCommonState *s =
-        DO_UPCAST(APICCommonState, busdev.qdev, env->apic_state);
-
-    if (!s) {
-        return;
-    }
-
-    if (kvm_enabled() && kvm_irqchip_in_kernel()) {
-        kvm_kernel_lapic_save_to_user(s);
-    }
-#endif
-}
-
 static void apic_post_load(APICCommonState *s)
 {
-    if (kvm_enabled() && kvm_irqchip_in_kernel()) {
-        return;
-    }
     if (s->timer_expiry != -1) {
         qemu_mod_timer(s->timer, s->timer_expiry);
     } else {
diff --git a/hw/pc.c b/hw/pc.c
index 1f0e2c4..b6fdddf 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -890,12 +890,9 @@ static DeviceState *apic_init(void *env, uint8_t apic_id)
     DeviceState *dev;
     static int apic_mapped;
 
-#ifdef UNUSED_UPSTREAM_KVM
     if (kvm_irqchip_in_kernel()) {
         dev = qdev_create(NULL, "kvm-apic");
-    } else
-#endif
-    {
+    } else {
         dev = qdev_create(NULL, "apic");
     }
     qdev_prop_set_uint8(dev, "id", apic_id);
diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index e5b94b0..2dad5af 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -64,37 +64,6 @@ int kvm_enable_vapic(CPUState *env, uint64_t vapic)
     return kvm_vcpu_ioctl(env, KVM_SET_VAPIC_ADDR, &va);
 }
 
-int kvm_get_lapic(CPUState *env, struct kvm_lapic_state *s)
-{
-    int r = 0;
-
-    if (!kvm_irqchip_in_kernel()) {
-        return r;
-    }
-
-    r = kvm_vcpu_ioctl(env, KVM_GET_LAPIC, s);
-    if (r < 0) {
-        fprintf(stderr, "KVM_GET_LAPIC failed\n");
-    }
-    return r;
-}
-
-int kvm_set_lapic(CPUState *env, struct kvm_lapic_state *s)
-{
-    int r = 0;
-
-    if (!kvm_irqchip_in_kernel()) {
-        return 0;
-    }
-
-    r = kvm_vcpu_ioctl(env, KVM_SET_LAPIC, s);
-
-    if (r < 0) {
-        fprintf(stderr, "KVM_SET_LAPIC failed\n");
-    }
-    return r;
-}
-
 int kvm_get_pit(KVMState *s, struct kvm_pit_state *pit_state)
 {
     if (!kvm_irqchip_in_kernel()) {
diff --git a/qemu-kvm.h b/qemu-kvm.h
index 433e2fe..3c4f023 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -34,28 +34,6 @@
 
 #if defined(__i386__) || defined(__x86_64__)
 /*!
- * \brief Get in kernel local APIC for vcpu
- *
- * Save the local apic state including the timer of a virtual CPU
- *
- * \param kvm Pointer to the current kvm_context
- * \param vcpu Which virtual CPU should be accessed
- * \param s Local apic state of the specific virtual CPU
- */
-int kvm_get_lapic(CPUState *env, struct kvm_lapic_state *s);
-
-/*!
- * \brief Set in kernel local APIC for vcpu
- *
- * Restore the local apic state including the timer of a virtual CPU
- *
- * \param kvm Pointer to the current kvm_context
- * \param vcpu Which virtual CPU should be accessed
- * \param s Local apic state of the specific virtual CPU
- */
-int kvm_set_lapic(CPUState *env, struct kvm_lapic_state *s);
-
-/*!
  * \brief Get in kernel PIT of the virtual domain
  *
  * Save the PIT state.
@@ -199,9 +177,6 @@ struct kvm_pit_state {
 
 #endif                          /* !CONFIG_KVM */
 
-void kvm_save_lapic(CPUState *env);
-void kvm_load_lapic(CPUState *env);
-
 void kvm_hpet_enable_kpit(void);
 void kvm_hpet_disable_kpit(void);
 
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index a7d9af9..864ed5a 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -1370,7 +1370,6 @@ static int kvm_get_mp_state(CPUState *env)
 
 static int kvm_get_apic(CPUState *env)
 {
-#ifdef UNUSED_UPSTREAM_KVM
     DeviceState *apic = env->apic_state;
     struct kvm_lapic_state kapic;
     int ret;
@@ -1383,15 +1382,11 @@ static int kvm_get_apic(CPUState *env)
 
         kvm_get_apic_state(apic, &kapic);
     }
-#else
-    kvm_save_lapic(env);
-#endif
     return 0;
 }
 
 static int kvm_put_apic(CPUState *env)
 {
-#ifdef UNUSED_UPSTREAM_KVM
     DeviceState *apic = env->apic_state;
     struct kvm_lapic_state kapic;
 
@@ -1400,9 +1395,6 @@ static int kvm_put_apic(CPUState *env)
 
         return kvm_vcpu_ioctl(env, KVM_SET_LAPIC, &kapic);
     }
-#else
-    kvm_load_lapic(env);
-#endif
     return 0;
 }
 
-- 
1.7.3.4

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux