xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Allocate vmcs pages when system booting
@ 2009-11-12 10:52 Jiang, Yunhong
  2009-11-12 11:22 ` Keir Fraser
  0 siblings, 1 reply; 16+ messages in thread
From: Jiang, Yunhong @ 2009-11-12 10:52 UTC (permalink / raw)
  To: xen-devel@lists.xensource.com, Keir Fraser

[-- Attachment #1: Type: text/plain, Size: 2620 bytes --]

Currently the VMCS page is allocated when the CPU is brought-up and identified, and then spin_debug_enable() is called.

This does not work for cpu hot-add. When hot-added CPU is brought-up and try to allocate the vmcs page, it will hit check_lock, because irq is disabled still.

This patch allocate the vmcs pages for all possible pages when system booting, so that we don't allocate vmcs anymore when secondary CPU is up.

Signed-off-by: Jiang, Yunhong <yunhong.jiang@intel.com>

diff -r 1db7034f4498 xen/arch/x86/hvm/vmx/vmcs.c
--- a/xen/arch/x86/hvm/vmx/vmcs.c	Thu Nov 12 00:05:59 2009 +0800
+++ b/xen/arch/x86/hvm/vmx/vmcs.c	Thu Nov 12 04:08:25 2009 +0800
@@ -267,6 +267,34 @@ static void vmx_free_vmcs(struct vmcs_st
 static void vmx_free_vmcs(struct vmcs_struct *vmcs)
 {
     free_xenheap_page(vmcs);
+}
+
+int vmx_allocate_vmcs_pages(void)
+{
+    int cpu, ret = 0;
+
+    for_each_possible_cpu(cpu)
+    {
+        if (per_cpu(host_vmcs, cpu) == NULL)
+        {
+            per_cpu(host_vmcs, cpu) = vmx_alloc_vmcs();
+            if (per_cpu(host_vmcs, cpu) == NULL)
+            {
+                ret = -1;
+                break;
+            }
+        }
+    }
+
+    if (ret < 0)
+    {
+        for_each_possible_cpu(cpu)
+        {
+            if (per_cpu(host_vmcs, cpu))
+                vmx_free_vmcs(per_cpu(host_vmcs, cpu));
+        }
+    }
+    return ret;
 }
 
 static void __vmx_clear_vmcs(void *info)
diff -r 1db7034f4498 xen/arch/x86/hvm/vmx/vmx.c
--- a/xen/arch/x86/hvm/vmx/vmx.c	Thu Nov 12 00:05:59 2009 +0800
+++ b/xen/arch/x86/hvm/vmx/vmx.c	Thu Nov 12 04:08:25 2009 +0800
@@ -1450,6 +1450,16 @@ void start_vmx(void)
     if ( !test_bit(X86_FEATURE_VMXE, &boot_cpu_data.x86_capability) )
         return;
 
+    /*
+     * We can't allocate VMCS pages when start_secondary for hot-added CPU
+     * because allocate page at that time will trigger check_lock error
+     */
+    if (vmx_allocate_vmcs_pages())
+    {
+        printk("VMX: failed to alloca vmcs pages\n");
+        return;
+    }
+
     set_in_cr4(X86_CR4_VMXE);
 
     if ( !vmx_cpu_up() )
diff -r 1db7034f4498 xen/include/asm-x86/hvm/vmx/vmcs.h
--- a/xen/include/asm-x86/hvm/vmx/vmcs.h	Thu Nov 12 00:05:59 2009 +0800
+++ b/xen/include/asm-x86/hvm/vmx/vmcs.h	Thu Nov 12 04:08:25 2009 +0800
@@ -28,6 +28,7 @@ extern void setup_vmcs_dump(void);
 extern void setup_vmcs_dump(void);
 extern int  vmx_cpu_up(void);
 extern void vmx_cpu_down(void);
+extern int vmx_allocate_vmcs_pages(void);
 
 struct vmcs_struct {
     u32 vmcs_revision_id;


[-- Attachment #2: vmcs_allocation.patch --]
[-- Type: application/octet-stream, Size: 2058 bytes --]

diff -r 1db7034f4498 xen/arch/x86/hvm/vmx/vmcs.c
--- a/xen/arch/x86/hvm/vmx/vmcs.c	Thu Nov 12 00:05:59 2009 +0800
+++ b/xen/arch/x86/hvm/vmx/vmcs.c	Thu Nov 12 04:08:25 2009 +0800
@@ -267,6 +267,34 @@ static void vmx_free_vmcs(struct vmcs_st
 static void vmx_free_vmcs(struct vmcs_struct *vmcs)
 {
     free_xenheap_page(vmcs);
+}
+
+int vmx_allocate_vmcs_pages(void)
+{
+    int cpu, ret = 0;
+
+    for_each_possible_cpu(cpu)
+    {
+        if (per_cpu(host_vmcs, cpu) == NULL)
+        {
+            per_cpu(host_vmcs, cpu) = vmx_alloc_vmcs();
+            if (per_cpu(host_vmcs, cpu) == NULL)
+            {
+                ret = -1;
+                break;
+            }
+        }
+    }
+
+    if (ret < 0)
+    {
+        for_each_possible_cpu(cpu)
+        {
+            if (per_cpu(host_vmcs, cpu))
+                vmx_free_vmcs(per_cpu(host_vmcs, cpu));
+        }
+    }
+    return ret;
 }
 
 static void __vmx_clear_vmcs(void *info)
diff -r 1db7034f4498 xen/arch/x86/hvm/vmx/vmx.c
--- a/xen/arch/x86/hvm/vmx/vmx.c	Thu Nov 12 00:05:59 2009 +0800
+++ b/xen/arch/x86/hvm/vmx/vmx.c	Thu Nov 12 04:08:25 2009 +0800
@@ -1450,6 +1450,16 @@ void start_vmx(void)
     if ( !test_bit(X86_FEATURE_VMXE, &boot_cpu_data.x86_capability) )
         return;
 
+    /*
+     * We can't allocate VMCS pages when start_secondary for hot-added CPU
+     * because allocate page at that time will trigger check_lock error
+     */
+    if (vmx_allocate_vmcs_pages())
+    {
+        printk("VMX: failed to alloca vmcs pages\n");
+        return;
+    }
+
     set_in_cr4(X86_CR4_VMXE);
 
     if ( !vmx_cpu_up() )
diff -r 1db7034f4498 xen/include/asm-x86/hvm/vmx/vmcs.h
--- a/xen/include/asm-x86/hvm/vmx/vmcs.h	Thu Nov 12 00:05:59 2009 +0800
+++ b/xen/include/asm-x86/hvm/vmx/vmcs.h	Thu Nov 12 04:08:25 2009 +0800
@@ -28,6 +28,7 @@ extern void setup_vmcs_dump(void);
 extern void setup_vmcs_dump(void);
 extern int  vmx_cpu_up(void);
 extern void vmx_cpu_down(void);
+extern int vmx_allocate_vmcs_pages(void);
 
 struct vmcs_struct {
     u32 vmcs_revision_id;

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2010-03-19  2:17 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-12 10:52 [PATCH] Allocate vmcs pages when system booting Jiang, Yunhong
2009-11-12 11:22 ` Keir Fraser
2009-11-12 14:58   ` Jiang, Yunhong
2009-11-12 15:04     ` Keir Fraser
2009-11-12 15:15       ` Jiang, Yunhong
2010-01-15  9:06   ` Jiang, Yunhong
2010-01-15  9:30     ` Jan Beulich
2010-01-15 10:31       ` Keir Fraser
2010-01-17  2:02         ` Jiang, Yunhong
2010-01-17 21:35           ` Keir Fraser
2010-01-18  8:11             ` Keir Fraser
2010-01-18  8:22               ` Jiang, Yunhong
2010-03-18 10:45         ` Jan Beulich
2010-03-18 10:51           ` Keir Fraser
2010-03-19  2:17           ` Jiang, Yunhong
2010-01-15 10:28     ` Keir Fraser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).