[PATCH 19/19] qemu-kvm: x86: Use kvm_arch_init

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

 



From: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>

Fold the qemu-kvm specific bits of kvm_arch_create into upstream's
kvm_arch_init and call that service directly. This nicely obsolete quite
a few more functions.

Signed-off-by: Jan Kiszka <jan.kiszka@xxxxxxxxxxx>
---
 qemu-kvm-x86.c    |  145 -----------------------------------------------------
 qemu-kvm.c        |    2 +-
 qemu-kvm.h        |   13 +----
 target-i386/kvm.c |   23 +++++++--
 4 files changed, 20 insertions(+), 163 deletions(-)

diff --git a/qemu-kvm-x86.c b/qemu-kvm-x86.c
index ece5a8e..6c3a0a9 100644
--- a/qemu-kvm-x86.c
+++ b/qemu-kvm-x86.c
@@ -23,83 +23,6 @@
 #include "kvm.h"
 #include "hw/apic.h"
 
-#define MSR_IA32_TSC            0x10
-
-extern unsigned int kvm_shadow_memory;
-
-static int kvm_set_tss_addr(kvm_context_t kvm, unsigned long addr)
-{
-    int r;
-
-    r = kvm_vm_ioctl(kvm_state, KVM_SET_TSS_ADDR, addr);
-    if (r < 0) {
-        fprintf(stderr, "kvm_set_tss_addr: %m\n");
-        return r;
-    }
-    return 0;
-}
-
-static int kvm_init_tss(kvm_context_t kvm)
-{
-    int r;
-
-    r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_SET_TSS_ADDR);
-    if (r > 0) {
-        /*
-         * this address is 3 pages before the bios, and the bios should present
-         * as unavaible memory
-         */
-        r = kvm_set_tss_addr(kvm, 0xfeffd000);
-        if (r < 0) {
-            fprintf(stderr, "kvm_init_tss: unable to set tss addr\n");
-            return r;
-        }
-    } else {
-        fprintf(stderr, "kvm does not support KVM_CAP_SET_TSS_ADDR\n");
-    }
-    return 0;
-}
-
-static int kvm_set_identity_map_addr(kvm_context_t kvm, uint64_t addr)
-{
-#ifdef KVM_CAP_SET_IDENTITY_MAP_ADDR
-    int r;
-
-    r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_SET_IDENTITY_MAP_ADDR);
-    if (r > 0) {
-        r = kvm_vm_ioctl(kvm_state, KVM_SET_IDENTITY_MAP_ADDR, &addr);
-        if (r == -1) {
-            fprintf(stderr, "kvm_set_identity_map_addr: %m\n");
-            return -errno;
-        }
-        return 0;
-    }
-#endif
-    return -ENOSYS;
-}
-
-static int kvm_init_identity_map_page(kvm_context_t kvm)
-{
-#ifdef KVM_CAP_SET_IDENTITY_MAP_ADDR
-    int r;
-
-    r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION, KVM_CAP_SET_IDENTITY_MAP_ADDR);
-    if (r > 0) {
-        /*
-         * this address is 4 pages before the bios, and the bios should present
-         * as unavaible memory
-         */
-        r = kvm_set_identity_map_addr(kvm, 0xfeffc000);
-        if (r < 0) {
-            fprintf(stderr, "kvm_init_identity_map_page: "
-                    "unable to set identity mapping addr\n");
-            return r;
-        }
-    }
-#endif
-    return 0;
-}
-
 static int kvm_create_pit(kvm_context_t kvm)
 {
 #ifdef KVM_CAP_PIT
@@ -124,55 +47,6 @@ static int kvm_create_pit(kvm_context_t kvm)
     return 0;
 }
 
-int kvm_arch_create(kvm_context_t kvm)
-{
-    struct utsname utsname;
-    int r = 0;
-
-    r = kvm_init_tss(kvm);
-    if (r < 0) {
-        return r;
-    }
-
-    r = kvm_init_identity_map_page(kvm);
-    if (r < 0) {
-        return r;
-    }
-
-    /*
-     * Tell fw_cfg to notify the BIOS to reserve the range.
-     */
-    if (e820_add_entry(0xfeffc000, 0x4000, E820_RESERVED) < 0) {
-        perror("e820_add_entry() table is full");
-        exit(1);
-    }
-
-    r = kvm_create_pit(kvm);
-    if (r < 0) {
-        return r;
-    }
-
-    uname(&utsname);
-    lm_capable_kernel = strcmp(utsname.machine, "x86_64") == 0;
-
-    if (kvm_shadow_memory) {
-        kvm_set_shadow_pages(kvm_context, kvm_shadow_memory);
-    }
-
-    /* initialize has_msr_star/has_msr_hsave_pa */
-    r = kvm_get_supported_msrs(kvm_state);
-    if (r < 0) {
-        return r;
-    }
-
-    r = kvm_set_boot_cpu_id(0);
-    if (r < 0 && r != -ENOSYS) {
-        return r;
-    }
-
-    return 0;
-}
-
 #ifdef KVM_EXIT_TPR_ACCESS
 
 static int kvm_handle_tpr_access(CPUState *env)
@@ -319,25 +193,6 @@ static void kvm_set_cr8(CPUState *env, uint64_t cr8)
     env->kvm_run->cr8 = cr8;
 }
 
-int kvm_set_shadow_pages(kvm_context_t kvm, unsigned int nrshadow_pages)
-{
-#ifdef KVM_CAP_MMU_SHADOW_CACHE_CONTROL
-    int r;
-
-    r = kvm_ioctl(kvm_state, KVM_CHECK_EXTENSION,
-                  KVM_CAP_MMU_SHADOW_CACHE_CONTROL);
-    if (r > 0) {
-        r = kvm_vm_ioctl(kvm_state, KVM_SET_NR_MMU_PAGES, nrshadow_pages);
-        if (r < 0) {
-            fprintf(stderr, "kvm_set_shadow_pages: %m\n");
-            return r;
-        }
-        return 0;
-    }
-#endif
-    return -1;
-}
-
 #ifdef KVM_CAP_VAPIC
 static int kvm_enable_tpr_access_reporting(CPUState *env)
 {
diff --git a/qemu-kvm.c b/qemu-kvm.c
index 3001392..cf02ceb 100644
--- a/qemu-kvm.c
+++ b/qemu-kvm.c
@@ -1382,7 +1382,7 @@ static int kvm_create_context(void)
         return -1;
     }
 
-    r = kvm_arch_create(kvm_context);
+    r = kvm_arch_init(kvm_state);
     if (r < 0) {
         kvm_finalize(kvm_state);
         return r;
diff --git a/qemu-kvm.h b/qemu-kvm.h
index 1644582..8b3ce9c 100644
--- a/qemu-kvm.h
+++ b/qemu-kvm.h
@@ -64,8 +64,6 @@ typedef struct kvm_context *kvm_context_t;
 
 #include "kvm.h"
 
-int kvm_arch_create(kvm_context_t kvm);
-
 int kvm_arch_run(CPUState *env);
 
 int handle_halt(CPUState *env);
@@ -124,16 +122,6 @@ int kvm_is_ready_for_interrupt_injection(CPUState *env);
  * \return 0 on success
  */
 int kvm_inject_irq(CPUState *env, unsigned irq);
-
-
-/*!
- * \brief Setting the number of shadow pages to be allocated to the vm
- *
- * \param kvm pointer to kvm_context
- * \param nrshadow_pages number of pages to be allocated
- */
-int kvm_set_shadow_pages(kvm_context_t kvm, unsigned int nrshadow_pages);
-
 #endif
 
 int kvm_set_irq_level(kvm_context_t kvm, int irq, int level, int *status);
@@ -449,6 +437,7 @@ extern int kvm_pit;
 extern int kvm_pit_reinject;
 extern int kvm_nested;
 extern kvm_context_t kvm_context;
+extern unsigned int kvm_shadow_memory;
 
 struct ioperm_data {
     unsigned long start_port;
diff --git a/target-i386/kvm.c b/target-i386/kvm.c
index bbc324b..a8b5c6d 100644
--- a/target-i386/kvm.c
+++ b/target-i386/kvm.c
@@ -197,7 +197,6 @@ typedef struct HWPoisonPage {
 static QLIST_HEAD(, HWPoisonPage) hwpoison_page_list =
     QLIST_HEAD_INITIALIZER(hwpoison_page_list);
 
-#ifdef OBSOLETE_KVM_IMPL
 static void kvm_unpoison_all(void *param)
 {
     HWPoisonPage *page, *next_page;
@@ -208,7 +207,6 @@ static void kvm_unpoison_all(void *param)
         qemu_free(page);
     }
 }
-#endif
 
 #ifdef KVM_CAP_MCE
 static void kvm_hwpoison_page_add(ram_addr_t ram_addr)
@@ -603,7 +601,7 @@ static int kvm_get_supported_msrs(KVMState *s)
     return ret;
 }
 
-#ifdef OBSOLETE_KVM_IMPL
+static int kvm_create_pit(kvm_context_t kvm);
 
 int kvm_arch_init(KVMState *s)
 {
@@ -655,11 +653,26 @@ int kvm_arch_init(KVMState *s)
     }
     qemu_register_reset(kvm_unpoison_all, NULL);
 
+    ret = kvm_create_pit(&s->kvm_context);
+    if (ret < 0) {
+        return ret;
+    }
+
+    if (kvm_shadow_memory) {
+        ret = kvm_vm_ioctl(s, KVM_SET_NR_MMU_PAGES, kvm_shadow_memory);
+        if (ret < 0) {
+            return ret;
+        }
+    }
+
+    ret = kvm_set_boot_cpu_id(0);
+    if (ret < 0 && ret != -ENOSYS) {
+        return ret;
+    }
+
     return 0;
 }
 
-#endif
-
 static void set_v8086_seg(struct kvm_segment *lhs, const SegmentCache *rhs)
 {
     lhs->selector = rhs->selector;
-- 
1.7.1

--
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