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>
This commit is contained in:
parent
a77ab5ead5
commit
269e05e485
|
@ -548,9 +548,7 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm)
|
||||||
if (!pit)
|
if (!pit)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
mutex_lock(&kvm->lock);
|
|
||||||
pit->irq_source_id = kvm_request_irq_source_id(kvm);
|
pit->irq_source_id = kvm_request_irq_source_id(kvm);
|
||||||
mutex_unlock(&kvm->lock);
|
|
||||||
if (pit->irq_source_id < 0) {
|
if (pit->irq_source_id < 0) {
|
||||||
kfree(pit);
|
kfree(pit);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -1837,10 +1837,16 @@ long kvm_arch_vm_ioctl(struct file *filp,
|
||||||
goto out;
|
goto out;
|
||||||
break;
|
break;
|
||||||
case KVM_CREATE_PIT:
|
case KVM_CREATE_PIT:
|
||||||
|
mutex_lock(&kvm->lock);
|
||||||
|
r = -EEXIST;
|
||||||
|
if (kvm->arch.vpit)
|
||||||
|
goto create_pit_unlock;
|
||||||
r = -ENOMEM;
|
r = -ENOMEM;
|
||||||
kvm->arch.vpit = kvm_create_pit(kvm);
|
kvm->arch.vpit = kvm_create_pit(kvm);
|
||||||
if (kvm->arch.vpit)
|
if (kvm->arch.vpit)
|
||||||
r = 0;
|
r = 0;
|
||||||
|
create_pit_unlock:
|
||||||
|
mutex_unlock(&kvm->lock);
|
||||||
break;
|
break;
|
||||||
case KVM_IRQ_LINE: {
|
case KVM_IRQ_LINE: {
|
||||||
struct kvm_irq_level irq_event;
|
struct kvm_irq_level irq_event;
|
||||||
|
|
Loading…
Reference in New Issue