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

[Xen-devel] [PATCH 5/12] Add HVM support



Add HVM context suspend/resume.

Signed-off-by Ke Yu <ke.yu@xxxxxxxxx>

diff -r 9ae5e96411fb xen/arch/x86/acpi/power.c
--- a/xen/arch/x86/acpi/power.c Tue Feb 13 11:19:02 2007 +0800
+++ b/xen/arch/x86/acpi/power.c Tue Feb 13 12:59:00 2007 +0800
@@ -89,8 +89,10 @@ int enter_state(u32 state)
         return -EBUSY;
     
     for_each_domain(d)
-       if (d->domain_id != 0)
+       if (d->domain_id != 0) {
            domain_pause(d);
+           arch_domain_suspend(d);
+    }
 
     printk("PM: Preparing system for %s sleep\n", acpi_states[state]);
 
diff -r 9ae5e96411fb xen/arch/x86/domain.c
--- a/xen/arch/x86/domain.c     Tue Feb 13 11:19:02 2007 +0800
+++ b/xen/arch/x86/domain.c     Tue Feb 13 13:04:17 2007 +0800
@@ -1515,6 +1515,16 @@ void arch_dump_vcpu_info(struct vcpu *v)
     }
 }
 
+/* suspend hook called by Xen S3 code 
+   assumption: domain has already been paused*/
+int arch_domain_suspend(struct domain *d)    
+{
+    if (is_hvm_domain(d)){
+        hvm_s3_suspend(d);
+    }
+    return 0;
+}
+
 /*
  * Local variables:
  * mode: C
diff -r 9ae5e96411fb xen/arch/x86/hvm/svm/svm.c
--- a/xen/arch/x86/hvm/svm/svm.c        Tue Feb 13 11:19:02 2007 +0800
+++ b/xen/arch/x86/hvm/svm/svm.c        Tue Feb 13 13:04:17 2007 +0800
@@ -1065,6 +1065,9 @@ int start_svm(void)
 
     hvm_funcs.init_ap_context = svm_init_ap_context;
     hvm_funcs.init_hypercall_page = svm_init_hypercall_page;
+
+    hvm_funcs.s3_suspend = NULL;
+    hvm_funcs.cpu_enable = NULL;
 
     hvm_enable();
 
diff -r 9ae5e96411fb xen/arch/x86/hvm/vmx/vmcs.c
--- a/xen/arch/x86/hvm/vmx/vmcs.c       Tue Feb 13 11:19:02 2007 +0800
+++ b/xen/arch/x86/hvm/vmx/vmcs.c       Tue Feb 13 13:04:17 2007 +0800
@@ -589,6 +589,19 @@ void setup_vmcs_dump(void)
     register_keyhandler('v', vmcs_dump, "dump Intel's VMCS");
 }
 
+/* S3 hook, called when Xen do S3 sleep 
+ * Assumption: all HVM domain should already be paused
+ */
+void vmcs_s3_suspend(struct domain* d){
+
+    struct vcpu *v; 
+
+    for_each_vcpu(d, v) {
+        spin_lock(&v->arch.hvm_vmx.vmcs_lock);
+        vmx_clear_vmcs(v);
+        spin_unlock(&v->arch.hvm_vmx.vmcs_lock);
+    }
+}
 
 /*
  * Local variables:
diff -r 9ae5e96411fb xen/arch/x86/hvm/vmx/vmx.c
--- a/xen/arch/x86/hvm/vmx/vmx.c        Tue Feb 13 11:19:02 2007 +0800
+++ b/xen/arch/x86/hvm/vmx/vmx.c        Tue Feb 13 13:04:17 2007 +0800
@@ -49,8 +49,12 @@
 #include <asm/hvm/vpt.h>
 #include <public/hvm/save.h>
 
+static DEFINE_PER_CPU(struct vmcs_struct*, host_vmcs);
+
 static void vmx_ctxt_switch_from(struct vcpu *v);
 static void vmx_ctxt_switch_to(struct vcpu *v);
+
+static int vmx_cpu_enable(void);
 
 static int vmx_vcpu_initialise(struct vcpu *v)
 {
@@ -1023,6 +1027,9 @@ static void vmx_setup_hvm_funcs(void)
     hvm_funcs.init_ap_context = vmx_init_ap_context;
 
     hvm_funcs.init_hypercall_page = vmx_init_hypercall_page;
+
+    hvm_funcs.s3_suspend = vmcs_s3_suspend;
+    hvm_funcs.cpu_enable = vmx_cpu_enable;
 }
 
 int start_vmx(void)
@@ -1078,6 +1085,8 @@ int start_vmx(void)
     }
 
     printk("VMXON is done\n");
+
+    this_cpu(host_vmcs) = vmcs;
 
     vmx_save_host_msrs();
 
@@ -2781,6 +2790,25 @@ asmlinkage void vmx_trace_vmentry(void)
     TRACE_VMEXIT(4, 0);
 }
 
+/* called by Xen S3 resume path 
+ * SMP: called by every physical CPU
+ */
+static int vmx_cpu_enable(void){
+
+    struct vmcs_struct *vmcs = this_cpu(host_vmcs);
+
+    if ( __vmxon(virt_to_maddr(vmcs)) )
+    {
+        clear_in_cr4(X86_CR4_VMXE);
+        printk("VMXON failed\n");
+        vmx_free_host_vmcs(vmcs);
+        return 0;
+    }
+
+    printk("VMXON is done\n");
+    return 1;
+}
+
 /*
  * Local variables:
  * mode: C
diff -r 9ae5e96411fb xen/arch/x86/x86_32/power/cpu.c
--- a/xen/arch/x86/x86_32/power/cpu.c   Tue Feb 13 11:19:02 2007 +0800
+++ b/xen/arch/x86/x86_32/power/cpu.c   Tue Feb 13 12:58:25 2007 +0800
@@ -19,6 +19,8 @@
 #include <asm/processor.h>
 #include <asm/msr.h>
 #include <asm/flushtlb.h>
+#include <asm/hvm/hvm.h>
+#include <asm/hvm/support.h>
 
 /* image of the saved processor state */
 struct saved_context {
@@ -234,6 +236,12 @@ void __restore_processor_state(struct sa
        do_fpu_end();
        mtrr_ap_init();
        mcheck_init(&boot_cpu_data);
+
+#ifdef __XEN__
+       if (hvm_enabled){
+               hvm_cpu_enable();
+       }
+#endif
 }
 
 void restore_processor_state(void)
diff -r 9ae5e96411fb xen/include/asm-x86/hvm/hvm.h
--- a/xen/include/asm-x86/hvm/hvm.h     Tue Feb 13 11:19:02 2007 +0800
+++ b/xen/include/asm-x86/hvm/hvm.h     Tue Feb 13 13:04:17 2007 +0800
@@ -134,6 +134,12 @@ struct hvm_function_table {
                             int vcpuid, int trampoline_vector);
 
     void (*init_hypercall_page)(struct domain *d, void
*hypercall_page);
+
+    /* S3 sleep HVM specific domain suspend callback */
+    void (*s3_suspend)(struct domain *d);
+
+    /* enable HVM CPU after back from sleep */
+    int (*cpu_enable)(void);
 };
 
 extern struct hvm_function_table hvm_funcs;
@@ -262,4 +268,20 @@ hvm_inject_exception(unsigned int trapnr
 
 int hvm_bringup_ap(int vcpuid, int trampoline_vector);
 
+static inline void
+hvm_s3_suspend(struct domain* d)
+{
+    if (hvm_funcs.s3_suspend)
+        hvm_funcs.s3_suspend(d);
+}
+
+static inline int
+hvm_cpu_enable(void)
+{
+    if (hvm_funcs.cpu_enable){
+        return hvm_funcs.cpu_enable();
+    }
+    return 1;
+}
+
 #endif /* __ASM_X86_HVM_HVM_H__ */
diff -r 9ae5e96411fb xen/include/asm-x86/hvm/vmx/vmcs.h
--- a/xen/include/asm-x86/hvm/vmx/vmcs.h        Tue Feb 13 11:19:02 2007
+0800
+++ b/xen/include/asm-x86/hvm/vmx/vmcs.h        Tue Feb 13 13:04:17 2007
+0800
@@ -28,6 +28,7 @@ extern void vmcs_dump_vcpu(void);
 extern void vmcs_dump_vcpu(void);
 extern void vmx_init_vmcs_config(void);
 extern void setup_vmcs_dump(void);
+extern void vmcs_s3_suspend(struct domain* d);
 
 struct vmcs_struct {
     u32 vmcs_revision_id;
diff -r 9ae5e96411fb xen/include/xen/domain.h
--- a/xen/include/xen/domain.h  Tue Feb 13 11:19:02 2007 +0800
+++ b/xen/include/xen/domain.h  Tue Feb 13 13:09:23 2007 +0800
@@ -55,4 +55,6 @@ void arch_dump_domain_info(struct domain
 
 int arch_vcpu_reset(struct vcpu *v);
 
+int arch_domain_suspend(struct domain *d);
+
 #endif /* __XEN_DOMAIN_H__ */

Attachment: hvm_context.patch
Description: hvm_context.patch

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.