Skip to content

Commit

Permalink
[PATCH] KVM: Fix GFP_KERNEL alloc in atomic section bug
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Ingo Molnar authored and Linus Torvalds committed Jan 6, 2007
1 parent cd36bee commit 965b58a
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions drivers/kvm/vmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1094,14 +1094,6 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)
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;
Expand Down Expand Up @@ -1155,8 +1147,6 @@ static int vmx_vcpu_setup(struct kvm_vcpu *vcpu)

return 0;

out_free_guest_msrs:
kfree(vcpu->guest_msrs);
out:
return ret;
}
Expand Down Expand Up @@ -1906,13 +1896,33 @@ static int vmx_create_vcpu(struct kvm_vcpu *vcpu)
{
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 = {
Expand Down

0 comments on commit 965b58a

Please sign in to comment.