aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/x86.c
diff options
context:
space:
mode:
authorMarcelo Tosatti <mtosatti@redhat.com>2009-06-23 14:05:14 -0400
committerAvi Kivity <avi@redhat.com>2009-09-10 01:33:02 -0400
commit894a9c5543abf6f88d36dc1b9f5d90f35db09cb3 (patch)
tree3fff94c380904dfef66ec7182c4dae59d7c85763 /arch/x86/kvm/x86.c
parentec04b2604c3707a46db1d26d98f82b11d0844669 (diff)
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: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r--arch/x86/kvm/x86.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 57e76b37242f..e9b0982d2589 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1987,19 +1987,25 @@ static int kvm_vm_ioctl_set_irqchip(struct kvm *kvm, struct kvm_irqchip *chip)
1987 r = 0; 1987 r = 0;
1988 switch (chip->chip_id) { 1988 switch (chip->chip_id) {
1989 case KVM_IRQCHIP_PIC_MASTER: 1989 case KVM_IRQCHIP_PIC_MASTER:
1990 spin_lock(&pic_irqchip(kvm)->lock);
1990 memcpy(&pic_irqchip(kvm)->pics[0], 1991 memcpy(&pic_irqchip(kvm)->pics[0],
1991 &chip->chip.pic, 1992 &chip->chip.pic,
1992 sizeof(struct kvm_pic_state)); 1993 sizeof(struct kvm_pic_state));
1994 spin_unlock(&pic_irqchip(kvm)->lock);
1993 break; 1995 break;
1994 case KVM_IRQCHIP_PIC_SLAVE: 1996 case KVM_IRQCHIP_PIC_SLAVE:
1997 spin_lock(&pic_irqchip(kvm)->lock);
1995 memcpy(&pic_irqchip(kvm)->pics[1], 1998 memcpy(&pic_irqchip(kvm)->pics[1],
1996 &chip->chip.pic, 1999 &chip->chip.pic,
1997 sizeof(struct kvm_pic_state)); 2000 sizeof(struct kvm_pic_state));
2001 spin_unlock(&pic_irqchip(kvm)->lock);
1998 break; 2002 break;
1999 case KVM_IRQCHIP_IOAPIC: 2003 case KVM_IRQCHIP_IOAPIC:
2004 mutex_lock(&kvm->irq_lock);
2000 memcpy(ioapic_irqchip(kvm), 2005 memcpy(ioapic_irqchip(kvm),
2001 &chip->chip.ioapic, 2006 &chip->chip.ioapic,
2002 sizeof(struct kvm_ioapic_state)); 2007 sizeof(struct kvm_ioapic_state));
2008 mutex_unlock(&kvm->irq_lock);
2003 break; 2009 break;
2004 default: 2010 default:
2005 r = -EINVAL; 2011 r = -EINVAL;
@@ -2013,7 +2019,9 @@ static int kvm_vm_ioctl_get_pit(struct kvm *kvm, struct kvm_pit_state *ps)
2013{ 2019{
2014 int r = 0; 2020 int r = 0;
2015 2021
2022 mutex_lock(&kvm->arch.vpit->pit_state.lock);
2016 memcpy(ps, &kvm->arch.vpit->pit_state, sizeof(struct kvm_pit_state)); 2023 memcpy(ps, &kvm->arch.vpit->pit_state, sizeof(struct kvm_pit_state));
2024 mutex_unlock(&kvm->arch.vpit->pit_state.lock);
2017 return r; 2025 return r;
2018} 2026}
2019 2027
@@ -2021,8 +2029,10 @@ static int kvm_vm_ioctl_set_pit(struct kvm *kvm, struct kvm_pit_state *ps)
2021{ 2029{
2022 int r = 0; 2030 int r = 0;
2023 2031
2032 mutex_lock(&kvm->arch.vpit->pit_state.lock);
2024 memcpy(&kvm->arch.vpit->pit_state, ps, sizeof(struct kvm_pit_state)); 2033 memcpy(&kvm->arch.vpit->pit_state, ps, sizeof(struct kvm_pit_state));
2025 kvm_pit_load_count(kvm, 0, ps->channels[0].count); 2034 kvm_pit_load_count(kvm, 0, ps->channels[0].count);
2035 mutex_unlock(&kvm->arch.vpit->pit_state.lock);
2026 return r; 2036 return r;
2027} 2037}
2028 2038
@@ -2031,7 +2041,9 @@ static int kvm_vm_ioctl_reinject(struct kvm *kvm,
2031{ 2041{
2032 if (!kvm->arch.vpit) 2042 if (!kvm->arch.vpit)
2033 return -ENXIO; 2043 return -ENXIO;
2044 mutex_lock(&kvm->arch.vpit->pit_state.lock);
2034 kvm->arch.vpit->pit_state.pit_timer.reinject = control->pit_reinject; 2045 kvm->arch.vpit->pit_state.pit_timer.reinject = control->pit_reinject;
2046 mutex_unlock(&kvm->arch.vpit->pit_state.lock);
2035 return 0; 2047 return 0;
2036} 2048}
2037 2049