* [PATCH 1/3] KVM: Fix GFP_KERNEL alloc in atomic section bug
2006-12-31 13:18 [PATCH 0/3] KVM: Miscellaneous stabilization fixes Avi Kivity
@ 2006-12-31 13:19 ` Avi Kivity
2006-12-31 13:20 ` [PATCH 2/3] KVM: Use raw_smp_processor_id() instead of smp_processor_id() where applicable Avi Kivity
2006-12-31 13:21 ` [PATCH 3/3] KVM: Recover after an arch module load failure Avi Kivity
2 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2006-12-31 13:19 UTC (permalink / raw)
To: kvm-devel; +Cc: linux-kernel, mingo, akpm
From: Ingo Molnar <mingo@elte.hu>
KVM does kmalloc() in an atomic section while having preemption disabled
via vcpu_load(). Fix this by moving the ->*_msr setup from the
vcpu_setup method to the vcpu_create method.
(This is also a small speedup for setting up a vcpu, which can in theory
be more frequent than the vcpu_create method).
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Avi Kivity <avi@qumranet.com>
Index: linux-2.6/drivers/kvm/vmx.c
===================================================================
--- linux-2.6.orig/drivers/kvm/vmx.c
+++ linux-2.6/drivers/kvm/vmx.c
@@ -1094,14 +1094,6 @@ static int vmx_vcpu_setup(struct kvm_vcp
rdmsrl(MSR_IA32_SYSENTER_EIP, a);
vmcs_writel(HOST_IA32_SYSENTER_EIP, a); /* 22.2.3 */
- ret = -ENOMEM;
- vcpu->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
- if (!vcpu->guest_msrs)
- goto out;
- vcpu->host_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
- if (!vcpu->host_msrs)
- goto out_free_guest_msrs;
-
for (i = 0; i < NR_VMX_MSR; ++i) {
u32 index = vmx_msr_index[i];
u32 data_low, data_high;
@@ -1155,8 +1147,6 @@ static int vmx_vcpu_setup(struct kvm_vcp
return 0;
-out_free_guest_msrs:
- kfree(vcpu->guest_msrs);
out:
return ret;
}
@@ -1906,13 +1896,33 @@ static int vmx_create_vcpu(struct kvm_vc
{
struct vmcs *vmcs;
+ vcpu->guest_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
+ if (!vcpu->guest_msrs)
+ return -ENOMEM;
+
+ vcpu->host_msrs = kmalloc(PAGE_SIZE, GFP_KERNEL);
+ if (!vcpu->host_msrs)
+ goto out_free_guest_msrs;
+
vmcs = alloc_vmcs();
if (!vmcs)
- return -ENOMEM;
+ goto out_free_msrs;
+
vmcs_clear(vmcs);
vcpu->vmcs = vmcs;
vcpu->launched = 0;
+
return 0;
+
+out_free_msrs:
+ kfree(vcpu->host_msrs);
+ vcpu->host_msrs = NULL;
+
+out_free_guest_msrs:
+ kfree(vcpu->guest_msrs);
+ vcpu->guest_msrs = NULL;
+
+ return -ENOMEM;
}
static struct kvm_arch_ops vmx_arch_ops = {
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 2/3] KVM: Use raw_smp_processor_id() instead of smp_processor_id() where applicable
2006-12-31 13:18 [PATCH 0/3] KVM: Miscellaneous stabilization fixes Avi Kivity
2006-12-31 13:19 ` [PATCH 1/3] KVM: Fix GFP_KERNEL alloc in atomic section bug Avi Kivity
@ 2006-12-31 13:20 ` Avi Kivity
2006-12-31 13:21 ` [PATCH 3/3] KVM: Recover after an arch module load failure Avi Kivity
2 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2006-12-31 13:20 UTC (permalink / raw)
To: kvm-devel; +Cc: linux-kernel, mingo, akpm
From: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Avi Kivity <avi@qumranet.com>
Index: linux-2.6/drivers/kvm/vmx.c
===================================================================
--- linux-2.6.orig/drivers/kvm/vmx.c
+++ linux-2.6/drivers/kvm/vmx.c
@@ -116,7 +116,7 @@ static void vmcs_clear(struct vmcs *vmcs
static void __vcpu_clear(void *arg)
{
struct kvm_vcpu *vcpu = arg;
- int cpu = smp_processor_id();
+ int cpu = raw_smp_processor_id();
if (vcpu->cpu == cpu)
vmcs_clear(vcpu->vmcs);
@@ -541,7 +541,7 @@ static struct vmcs *alloc_vmcs_cpu(int c
static struct vmcs *alloc_vmcs(void)
{
- return alloc_vmcs_cpu(smp_processor_id());
+ return alloc_vmcs_cpu(raw_smp_processor_id());
}
static void free_vmcs(struct vmcs *vmcs)
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 3/3] KVM: Recover after an arch module load failure
2006-12-31 13:18 [PATCH 0/3] KVM: Miscellaneous stabilization fixes Avi Kivity
2006-12-31 13:19 ` [PATCH 1/3] KVM: Fix GFP_KERNEL alloc in atomic section bug Avi Kivity
2006-12-31 13:20 ` [PATCH 2/3] KVM: Use raw_smp_processor_id() instead of smp_processor_id() where applicable Avi Kivity
@ 2006-12-31 13:21 ` Avi Kivity
2 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2006-12-31 13:21 UTC (permalink / raw)
To: kvm-devel; +Cc: linux-kernel, mingo, akpm
From: Yoshimi Ichiyanagi <ichiyanagi.yoshimi@lab.ntt.co.jp>
If we load the wrong arch module, it leaves behind kvm_arch_ops set, which
prevents loading of the correct arch module later.
Fix be not setting kvm_arch_ops until we're sure it's good.
Signed-off-by: Yoshimi Ichiyanagi <ichiyanagi.yoshimi@lab.ntt.co.jp>
Signed-off-by: Avi Kivity <avi@qumranet.com>
Index: linux-2.6/drivers/kvm/kvm_main.c
===================================================================
--- linux-2.6.orig/drivers/kvm/kvm_main.c
+++ linux-2.6/drivers/kvm/kvm_main.c
@@ -1944,17 +1944,17 @@ int kvm_init_arch(struct kvm_arch_ops *o
return -EEXIST;
}
- kvm_arch_ops = ops;
-
- if (!kvm_arch_ops->cpu_has_kvm_support()) {
+ if (!ops->cpu_has_kvm_support()) {
printk(KERN_ERR "kvm: no hardware support\n");
return -EOPNOTSUPP;
}
- if (kvm_arch_ops->disabled_by_bios()) {
+ if (ops->disabled_by_bios()) {
printk(KERN_ERR "kvm: disabled by bios\n");
return -EOPNOTSUPP;
}
+ kvm_arch_ops = ops;
+
r = kvm_arch_ops->hardware_setup();
if (r < 0)
return r;
^ permalink raw reply [flat|nested] 4+ messages in thread