We've seen various big patches regarding portability from Christian and
Xianto, but none was merged to date. Maintaining a large patch set on
top of a quickly moving code base is painful.
I thought it might be cool to try to throw trivial patches at Avi that
obviously don't break things and push towards portability. In case this
succeeds I'll keep throwing in trivial patches until we've split
everything proper.
This patch splits kvm_dev_ioctl into architecture independent and
architecture dependent ioctls. Those that are arch independent remain in
kvm_main.c, others are implemented by kvm_arch_dev_ioctl() in kvm_x86.c.
A header file named kvm_arch.h is being introduced that contains
prototypes for funtions in kvm_x86.c.

Comments? Is this a preferable approach? What needs to be done
different?

signed-off-by: Carsten Otte <[EMAIL PROTECTED]>
---
Index: kvm/drivers/kvm/kvm_arch.h
===================================================================
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ kvm/drivers/kvm/kvm_arch.h  2007-10-09 16:42:09.000000000 +0200
@@ -0,0 +1,17 @@
+/*
+ * Kernel-based Virtual Machine driver for Linux
+ *
+ * This header defines architecture specific interfaces
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#ifndef KVM_ARCH_H
+#define KVM_ARCH_H
+long kvm_arch_dev_ioctl(struct file *,
+                       unsigned int, unsigned long);
+
+__init void kvm_arch_init(void);
+#endif
Index: kvm/drivers/kvm/kvm_main.c
===================================================================
--- kvm.orig/drivers/kvm/kvm_main.c     2007-10-09 15:39:26.000000000 +0200
+++ kvm/drivers/kvm/kvm_main.c  2007-10-09 16:41:04.000000000 +0200
@@ -16,6 +16,7 @@
  */
 
 #include "kvm.h"
+#include "kvm_arch.h"
 #include "x86_emulate.h"
 #include "segment_descriptor.h"
 #include "irq.h"
@@ -44,7 +45,6 @@
 #include <asm/processor.h>
 #include <asm/msr.h>
 #include <asm/io.h>
-#include <asm/uaccess.h>
 #include <asm/desc.h>
 
 MODULE_AUTHOR("Qumranet");
@@ -2478,43 +2478,6 @@
 EXPORT_SYMBOL_GPL(kvm_get_cs_db_l_bits);
 
 /*
- * List of msr numbers which we expose to userspace through KVM_GET_MSRS
- * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST.
- *
- * This list is modified at module load time to reflect the
- * capabilities of the host cpu.
- */
-static u32 msrs_to_save[] = {
-       MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP,
-       MSR_K6_STAR,
-#ifdef CONFIG_X86_64
-       MSR_CSTAR, MSR_KERNEL_GS_BASE, MSR_SYSCALL_MASK, MSR_LSTAR,
-#endif
-       MSR_IA32_TIME_STAMP_COUNTER,
-};
-
-static unsigned num_msrs_to_save;
-
-static u32 emulated_msrs[] = {
-       MSR_IA32_MISC_ENABLE,
-};
-
-static __init void kvm_init_msr_list(void)
-{
-       u32 dummy[2];
-       unsigned i, j;
-
-       for (i = j = 0; i < ARRAY_SIZE(msrs_to_save); i++) {
-               if (rdmsr_safe(msrs_to_save[i], &dummy[0], &dummy[1]) < 0)
-                       continue;
-               if (j < i)
-                       msrs_to_save[j] = msrs_to_save[i];
-               j++;
-       }
-       num_msrs_to_save = j;
-}
-
-/*
  * Adapt set_msr() to msr_io()'s calling convention
  */
 static int do_set_msr(struct kvm_vcpu *vcpu, unsigned index, u64 *data)
@@ -3292,7 +3255,6 @@
 static long kvm_dev_ioctl(struct file *filp,
                          unsigned int ioctl, unsigned long arg)
 {
-       void __user *argp = (void __user *)arg;
        long r = -EINVAL;
 
        switch (ioctl) {
@@ -3308,56 +3270,8 @@
                        goto out;
                r = kvm_dev_ioctl_create_vm();
                break;
-       case KVM_GET_MSR_INDEX_LIST: {
-               struct kvm_msr_list __user *user_msr_list = argp;
-               struct kvm_msr_list msr_list;
-               unsigned n;
-
-               r = -EFAULT;
-               if (copy_from_user(&msr_list, user_msr_list, sizeof msr_list))
-                       goto out;
-               n = msr_list.nmsrs;
-               msr_list.nmsrs = num_msrs_to_save + ARRAY_SIZE(emulated_msrs);
-               if (copy_to_user(user_msr_list, &msr_list, sizeof msr_list))
-                       goto out;
-               r = -E2BIG;
-               if (n < num_msrs_to_save)
-                       goto out;
-               r = -EFAULT;
-               if (copy_to_user(user_msr_list->indices, &msrs_to_save,
-                                num_msrs_to_save * sizeof(u32)))
-                       goto out;
-               if (copy_to_user(user_msr_list->indices
-                                + num_msrs_to_save * sizeof(u32),
-                                &emulated_msrs,
-                                ARRAY_SIZE(emulated_msrs) * sizeof(u32)))
-                       goto out;
-               r = 0;
-               break;
-       }
-       case KVM_CHECK_EXTENSION: {
-               int ext = (long)argp;
-
-               switch (ext) {
-               case KVM_CAP_IRQCHIP:
-               case KVM_CAP_HLT:
-               case KVM_CAP_MMU_SHADOW_CACHE_CONTROL:
-                       r = 1;
-                       break;
-               default:
-                       r = 0;
-                       break;
-               }
-               break;
-       }
-       case KVM_GET_VCPU_MMAP_SIZE:
-               r = -EINVAL;
-               if (arg)
-                       goto out;
-               r = 2 * PAGE_SIZE;
-               break;
        default:
-               ;
+               return kvm_arch_dev_ioctl(filp, ioctl, arg);
        }
 out:
        return r;
@@ -3721,7 +3635,7 @@
 
        kvm_init_debug();
 
-       kvm_init_msr_list();
+       kvm_arch_init();
 
        bad_page = alloc_page(GFP_KERNEL);
 
Index: kvm/drivers/kvm/kvm_x86.c
===================================================================
--- /dev/null   1970-01-01 00:00:00.000000000 +0000
+++ kvm/drivers/kvm/kvm_x86.c   2007-10-09 16:47:55.000000000 +0200
@@ -0,0 +1,126 @@
+/*
+ * Kernel-based Virtual Machine driver for Linux
+ *
+ * derived from drivers/kvm/kvm_main.c
+ *
+ * Copyright (C) 2006 Qumranet, Inc.
+ *
+ * Authors:
+ *   Avi Kivity   <[EMAIL PROTECTED]>
+ *   Yaniv Kamay  <[EMAIL PROTECTED]>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the COPYING file in the top-level directory.
+ *
+ */
+
+#include "kvm.h"
+#include "kvm_arch.h"
+
+#include <asm/uaccess.h>
+
+static u32 emulated_msrs[] = {
+       MSR_IA32_MISC_ENABLE,
+};
+
+static unsigned num_msrs_to_save;
+
+/*
+ * List of msr numbers which we expose to userspace through KVM_GET_MSRS
+ * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST.
+ *
+ * This list is modified at module load time to reflect the
+ * capabilities of the host cpu.
+ */
+static u32 msrs_to_save[] = {
+       MSR_IA32_SYSENTER_CS, MSR_IA32_SYSENTER_ESP, MSR_IA32_SYSENTER_EIP,
+       MSR_K6_STAR,
+#ifdef CONFIG_X86_64
+       MSR_CSTAR, MSR_KERNEL_GS_BASE, MSR_SYSCALL_MASK, MSR_LSTAR,
+#endif
+       MSR_IA32_TIME_STAMP_COUNTER,
+};
+
+
+long kvm_arch_dev_ioctl(struct file *filp,
+                       unsigned int ioctl, unsigned long arg)
+{
+       void __user *argp = (void __user *)arg;
+       long r;
+
+       switch (ioctl) {
+       case KVM_GET_MSR_INDEX_LIST: {
+               struct kvm_msr_list __user *user_msr_list = argp;
+               struct kvm_msr_list msr_list;
+               unsigned n;
+
+               r = -EFAULT;
+               if (copy_from_user(&msr_list, user_msr_list, sizeof msr_list))
+                       goto out;
+               n = msr_list.nmsrs;
+               msr_list.nmsrs = num_msrs_to_save + ARRAY_SIZE(emulated_msrs);
+               if (copy_to_user(user_msr_list, &msr_list, sizeof msr_list))
+                       goto out;
+               r = -E2BIG;
+               if (n < num_msrs_to_save)
+                       goto out;
+               r = -EFAULT;
+               if (copy_to_user(user_msr_list->indices, &msrs_to_save,
+                                num_msrs_to_save * sizeof(u32)))
+                       goto out;
+               if (copy_to_user(user_msr_list->indices
+                                + num_msrs_to_save * sizeof(u32),
+                                &emulated_msrs,
+                                ARRAY_SIZE(emulated_msrs) * sizeof(u32)))
+                       goto out;
+               r = 0;
+               break;
+       }
+       case KVM_CHECK_EXTENSION: {
+               int ext = (long)argp;
+
+               switch (ext) {
+               case KVM_CAP_IRQCHIP:
+               case KVM_CAP_HLT:
+               case KVM_CAP_MMU_SHADOW_CACHE_CONTROL:
+                       r = 1;
+                       break;
+               default:
+                       r = 0;
+                       break;
+               }
+               break;
+       }
+       case KVM_GET_VCPU_MMAP_SIZE: {
+               r = -EINVAL;
+               if (arg)
+                       goto out;
+               r = 2 * PAGE_SIZE;
+               break;
+       }
+       default:
+               r = -EINVAL;
+       }
+out:
+       return r;
+}
+
+static __init void kvm_init_msr_list(void)
+{
+       u32 dummy[2];
+       unsigned i, j;
+
+       for (i = j = 0; i < ARRAY_SIZE(msrs_to_save); i++) {
+               if (rdmsr_safe(msrs_to_save[i], &dummy[0], &dummy[1]) < 0)
+                       continue;
+               if (j < i)
+                       msrs_to_save[j] = msrs_to_save[i];
+               j++;
+       }
+       num_msrs_to_save = j;
+}
+
+__init void kvm_arch_init(void)
+{
+       kvm_init_msr_list();
+}
Index: kvm/drivers/kvm/Makefile
===================================================================
--- kvm.orig/drivers/kvm/Makefile       2007-10-09 18:17:03.000000000 +0200
+++ kvm/drivers/kvm/Makefile    2007-10-09 18:17:12.000000000 +0200
@@ -2,7 +2,7 @@
 # Makefile for Kernel-based Virtual Machine module
 #
 
-kvm-objs := kvm_main.o mmu.o x86_emulate.o i8259.o irq.o lapic.o ioapic.o
+kvm-objs := kvm_main.o kvm_x86.o mmu.o x86_emulate.o i8259.o irq.o lapic.o 
ioapic.o
 obj-$(CONFIG_KVM) += kvm.o
 kvm-intel-objs = vmx.o
 obj-$(CONFIG_KVM_INTEL) += kvm-intel.o



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
kvm-devel mailing list
kvm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/kvm-devel

Reply via email to