aboutsummaryrefslogtreecommitdiff
path: root/arch/x86/kvm/x86.c
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2009-01-05 15:21:42 +0200
committerAvi Kivity <avi@redhat.com>2009-03-24 11:03:01 +0200
commit269e05e48502f1cc06802e9fba90f5100dd6bb0d (patch)
tree9b3501dc1f5e137c2dca7eacf15c0353f627be97 /arch/x86/kvm/x86.c
parenta77ab5ead5c1fef2c6c5a9b3cf3765e52643a2aa (diff)
KVM: Properly lock PIT creation
Otherwise, two threads can create a PIT in parallel and cause a memory leak. Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r--arch/x86/kvm/x86.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index a1f14611f4b..6fbc3460337 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1837,10 +1837,16 @@ long kvm_arch_vm_ioctl(struct file *filp,
goto out;
break;
case KVM_CREATE_PIT:
+ mutex_lock(&kvm->lock);
+ r = -EEXIST;
+ if (kvm->arch.vpit)
+ goto create_pit_unlock;
r = -ENOMEM;
kvm->arch.vpit = kvm_create_pit(kvm);
if (kvm->arch.vpit)
r = 0;
+ create_pit_unlock:
+ mutex_unlock(&kvm->lock);
break;
case KVM_IRQ_LINE: {
struct kvm_irq_level irq_event;