mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
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>
This commit is contained in:
1 parent
36197bd847
commit
458e5ec73c
6 files changed
+42
-17
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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))) )
|
||||
{
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||