Commit 894a9c55 authored by Marcelo Tosatti's avatar Marcelo Tosatti Committed by Avi Kivity

KVM: x86: missing locking in PIT/IRQCHIP/SET_BSP_CPU ioctl paths

Correct missing locking in a few places in x86's vm_ioctl handling path.
Signed-off-by: default avatarMarcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent ec04b260
...@@ -345,9 +345,7 @@ static void pit_load_count(struct kvm *kvm, int channel, u32 val) ...@@ -345,9 +345,7 @@ static void pit_load_count(struct kvm *kvm, int channel, u32 val)
void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val) void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val)
{ {
mutex_lock(&kvm->arch.vpit->pit_state.lock);
pit_load_count(kvm, channel, val); pit_load_count(kvm, channel, val);
mutex_unlock(&kvm->arch.vpit->pit_state.lock);
} }
static inline struct kvm_pit *dev_to_pit(struct kvm_io_device *dev) static inline struct kvm_pit *dev_to_pit(struct kvm_io_device *dev)
......
...@@ -1987,19 +1987,25 @@ static int kvm_vm_ioctl_set_irqchip(struct kvm *kvm, struct kvm_irqchip *chip) ...@@ -1987,19 +1987,25 @@ static int kvm_vm_ioctl_set_irqchip(struct kvm *kvm, struct kvm_irqchip *chip)
r = 0; r = 0;
switch (chip->chip_id) { switch (chip->chip_id) {
case KVM_IRQCHIP_PIC_MASTER: case KVM_IRQCHIP_PIC_MASTER:
spin_lock(&pic_irqchip(kvm)->lock);
memcpy(&pic_irqchip(kvm)->pics[0], memcpy(&pic_irqchip(kvm)->pics[0],
&chip->chip.pic, &chip->chip.pic,
sizeof(struct kvm_pic_state)); sizeof(struct kvm_pic_state));
spin_unlock(&pic_irqchip(kvm)->lock);
break; break;
case KVM_IRQCHIP_PIC_SLAVE: case KVM_IRQCHIP_PIC_SLAVE:
spin_lock(&pic_irqchip(kvm)->lock);
memcpy(&pic_irqchip(kvm)->pics[1], memcpy(&pic_irqchip(kvm)->pics[1],
&chip->chip.pic, &chip->chip.pic,
sizeof(struct kvm_pic_state)); sizeof(struct kvm_pic_state));
spin_unlock(&pic_irqchip(kvm)->lock);
break; break;
case KVM_IRQCHIP_IOAPIC: case KVM_IRQCHIP_IOAPIC:
mutex_lock(&kvm->irq_lock);
memcpy(ioapic_irqchip(kvm), memcpy(ioapic_irqchip(kvm),
&chip->chip.ioapic, &chip->chip.ioapic,
sizeof(struct kvm_ioapic_state)); sizeof(struct kvm_ioapic_state));
mutex_unlock(&kvm->irq_lock);
break; break;
default: default:
r = -EINVAL; r = -EINVAL;
...@@ -2013,7 +2019,9 @@ static int kvm_vm_ioctl_get_pit(struct kvm *kvm, struct kvm_pit_state *ps) ...@@ -2013,7 +2019,9 @@ static int kvm_vm_ioctl_get_pit(struct kvm *kvm, struct kvm_pit_state *ps)
{ {
int r = 0; int r = 0;
mutex_lock(&kvm->arch.vpit->pit_state.lock);
memcpy(ps, &kvm->arch.vpit->pit_state, sizeof(struct kvm_pit_state)); memcpy(ps, &kvm->arch.vpit->pit_state, sizeof(struct kvm_pit_state));
mutex_unlock(&kvm->arch.vpit->pit_state.lock);
return r; return r;
} }
...@@ -2021,8 +2029,10 @@ static int kvm_vm_ioctl_set_pit(struct kvm *kvm, struct kvm_pit_state *ps) ...@@ -2021,8 +2029,10 @@ static int kvm_vm_ioctl_set_pit(struct kvm *kvm, struct kvm_pit_state *ps)
{ {
int r = 0; int r = 0;
mutex_lock(&kvm->arch.vpit->pit_state.lock);
memcpy(&kvm->arch.vpit->pit_state, ps, sizeof(struct kvm_pit_state)); memcpy(&kvm->arch.vpit->pit_state, ps, sizeof(struct kvm_pit_state));
kvm_pit_load_count(kvm, 0, ps->channels[0].count); kvm_pit_load_count(kvm, 0, ps->channels[0].count);
mutex_unlock(&kvm->arch.vpit->pit_state.lock);
return r; return r;
} }
...@@ -2031,7 +2041,9 @@ static int kvm_vm_ioctl_reinject(struct kvm *kvm, ...@@ -2031,7 +2041,9 @@ static int kvm_vm_ioctl_reinject(struct kvm *kvm,
{ {
if (!kvm->arch.vpit) if (!kvm->arch.vpit)
return -ENXIO; return -ENXIO;
mutex_lock(&kvm->arch.vpit->pit_state.lock);
kvm->arch.vpit->pit_state.pit_timer.reinject = control->pit_reinject; kvm->arch.vpit->pit_state.pit_timer.reinject = control->pit_reinject;
mutex_unlock(&kvm->arch.vpit->pit_state.lock);
return 0; return 0;
} }
......
...@@ -2274,10 +2274,12 @@ static long kvm_vm_ioctl(struct file *filp, ...@@ -2274,10 +2274,12 @@ static long kvm_vm_ioctl(struct file *filp,
#ifdef CONFIG_KVM_APIC_ARCHITECTURE #ifdef CONFIG_KVM_APIC_ARCHITECTURE
case KVM_SET_BOOT_CPU_ID: case KVM_SET_BOOT_CPU_ID:
r = 0; r = 0;
mutex_lock(&kvm->lock);
if (atomic_read(&kvm->online_vcpus) != 0) if (atomic_read(&kvm->online_vcpus) != 0)
r = -EBUSY; r = -EBUSY;
else else
kvm->bsp_vcpu_id = arg; kvm->bsp_vcpu_id = arg;
mutex_unlock(&kvm->lock);
break; break;
#endif #endif
default: default:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment