aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2010-01-18 10:35:36 +0000
committerKeir Fraser <keir.fraser@citrix.com>2010-01-18 10:35:36 +0000
commit458e5ec73ca367cb41a5c477639799e62ea6f102 (patch)
tree1f62111a6cc49cf7e103d3a073242f1122bbc88d
parent36197bd8473609a0a407446c3904932ddd242ca7 (diff)
downloadxen-458e5ec73ca367cb41a5c477639799e62ea6f102.tar.gz
xen-458e5ec73ca367cb41a5c477639799e62ea6f102.tar.bz2
xen-458e5ec73ca367cb41a5c477639799e62ea6f102.zip
x86 hvm: Pre-allocate per-cpu HVM memory before bringing CPUs online
after boot. Avoids doing the allocations on the CPU itself, while in a not-fully-online state and with irqs disabled. This way we avoid assertions about irqs being disabled in e.g., tlb flush logic. Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
-rw-r--r--xen/arch/x86/hvm/svm/svm.c16
-rw-r--r--xen/arch/x86/hvm/vmx/vmcs.c24
-rw-r--r--xen/arch/x86/hvm/vmx/vmx.c1
-rw-r--r--xen/arch/x86/smpboot.c6
-rw-r--r--xen/include/asm-x86/hvm/hvm.h11
-rw-r--r--xen/include/asm-x86/hvm/vmx/vmcs.h1
6 files changed, 42 insertions, 17 deletions
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index 53697b3761..8b12d515f9 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -809,6 +809,16 @@ static int svm_do_pmu_interrupt(struct cpu_user_regs *regs)
return 0;
}
+static int svm_cpu_prepare(unsigned int cpu)
+{
+ if ( ((hsa[cpu] == NULL) &&
+ ((hsa[cpu] = alloc_host_save_area()) == NULL)) ||
+ ((root_vmcb[cpu] == NULL) &&
+ ((root_vmcb[cpu] = alloc_vmcb()) == NULL)) )
+ return -ENOMEM;
+ return 0;
+}
+
static int svm_cpu_up(struct cpuinfo_x86 *c)
{
u32 eax, edx, phys_hsa_lo, phys_hsa_hi;
@@ -823,10 +833,7 @@ static int svm_cpu_up(struct cpuinfo_x86 *c)
return 0;
}
- if ( ((hsa[cpu] == NULL) &&
- ((hsa[cpu] = alloc_host_save_area()) == NULL)) ||
- ((root_vmcb[cpu] == NULL) &&
- ((root_vmcb[cpu] = alloc_vmcb()) == NULL)) )
+ if ( svm_cpu_prepare(cpu) != 0 )
return 0;
write_efer(read_efer() | EFER_SVME);
@@ -1231,6 +1238,7 @@ static void svm_invlpg_intercept(unsigned long vaddr)
static struct hvm_function_table __read_mostly svm_function_table = {
.name = "SVM",
+ .cpu_prepare = svm_cpu_prepare,
.cpu_down = svm_cpu_down,
.domain_initialise = svm_domain_initialise,
.domain_destroy = svm_domain_destroy,
diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c
index a6a2f6851c..fd16ad2248 100644
--- a/xen/arch/x86/hvm/vmx/vmcs.c
+++ b/xen/arch/x86/hvm/vmx/vmcs.c
@@ -320,6 +320,19 @@ static void vmx_load_vmcs(struct vcpu *v)
local_irq_restore(flags);
}
+int vmx_cpu_prepare(unsigned int cpu)
+{
+ if ( per_cpu(host_vmcs, cpu) != NULL )
+ return 0;
+
+ per_cpu(host_vmcs, cpu) = vmx_alloc_vmcs();
+ if ( per_cpu(host_vmcs, cpu) != NULL )
+ return 0;
+
+ printk("CPU%d: Could not allocate host VMCS\n", cpu);
+ return -ENOMEM;
+}
+
int vmx_cpu_up(void)
{
u32 eax, edx;
@@ -367,15 +380,8 @@ int vmx_cpu_up(void)
INIT_LIST_HEAD(&this_cpu(active_vmcs_list));
- if ( this_cpu(host_vmcs) == NULL )
- {
- this_cpu(host_vmcs) = vmx_alloc_vmcs();
- if ( this_cpu(host_vmcs) == NULL )
- {
- printk("CPU%d: Could not allocate host VMCS\n", cpu);
- return 0;
- }
- }
+ if ( vmx_cpu_prepare(cpu) != 0 )
+ return 0;
switch ( __vmxon(virt_to_maddr(this_cpu(host_vmcs))) )
{
diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index 48cd0d6665..8cf971a45c 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -1377,6 +1377,7 @@ static void vmx_set_info_guest(struct vcpu *v)
static struct hvm_function_table __read_mostly vmx_function_table = {
.name = "VMX",
+ .cpu_prepare = vmx_cpu_prepare,
.domain_initialise = vmx_domain_initialise,
.domain_destroy = vmx_domain_destroy,
.vcpu_initialise = vmx_vcpu_initialise,
diff --git a/xen/arch/x86/smpboot.c b/xen/arch/x86/smpboot.c
index ce18c7f0be..26eb1e97a8 100644
--- a/xen/arch/x86/smpboot.c
+++ b/xen/arch/x86/smpboot.c
@@ -1518,7 +1518,11 @@ int cpu_add(uint32_t apic_id, uint32_t acpi_id, uint32_t pxm)
int __devinit __cpu_up(unsigned int cpu)
{
- int ret = 0;
+ int ret;
+
+ ret = hvm_cpu_prepare(cpu);
+ if (ret)
+ return ret;
/*
* We do warm boot only on cpus that had booted earlier
diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h
index 1697c8b31b..0ae7e7ea0a 100644
--- a/xen/include/asm-x86/hvm/hvm.h
+++ b/xen/include/asm-x86/hvm/hvm.h
@@ -111,6 +111,7 @@ struct hvm_function_table {
int (*event_pending)(struct vcpu *v);
int (*do_pmu_interrupt)(struct cpu_user_regs *regs);
+ int (*cpu_prepare)(unsigned int cpu);
int (*cpu_up)(void);
void (*cpu_down)(void);
@@ -290,11 +291,15 @@ uint8_t hvm_combine_hw_exceptions(uint8_t vec1, uint8_t vec2);
void hvm_set_rdtsc_exiting(struct domain *d, bool_t enable);
int hvm_gtsc_need_scale(struct domain *d);
+static inline int
+hvm_cpu_prepare(unsigned int cpu)
+{
+ return (hvm_funcs.cpu_prepare ? hvm_funcs.cpu_prepare(cpu) : 0);
+}
+
static inline int hvm_cpu_up(void)
{
- if ( hvm_funcs.cpu_up )
- return hvm_funcs.cpu_up();
- return 1;
+ return (hvm_funcs.cpu_up ? hvm_funcs.cpu_up() : 1);
}
static inline void hvm_cpu_down(void)
diff --git a/xen/include/asm-x86/hvm/vmx/vmcs.h b/xen/include/asm-x86/hvm/vmx/vmcs.h
index ed77451afb..657ae96252 100644
--- a/xen/include/asm-x86/hvm/vmx/vmcs.h
+++ b/xen/include/asm-x86/hvm/vmx/vmcs.h
@@ -26,6 +26,7 @@
extern void start_vmx(void);
extern void vmcs_dump_vcpu(struct vcpu *v);
extern void setup_vmcs_dump(void);
+extern int vmx_cpu_prepare(unsigned int cpu);
extern int vmx_cpu_up(void);
extern void vmx_cpu_down(void);