[PATCH 3/3] KVM: Centralize irq_lock aquisition during KVM_CREATE_IRQCHIP

Takuya Yoshikawa
2010-12-15T16:45:34Z

From: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>

Move irq_lock aquisition from kvm_setup_default_irq_routing(), inside of
kvm_set_irq_routing(), to its caller.

This makes the lock management clearer, with a bit longer irq_lock section.

Signed-off-by: Takuya Yoshikawa <yoshikawa.takuya@oss.ntt.co.jp>
---
arch/ia64/kvm/kvm-ia64.c | 2 ++
arch/x86/kvm/x86.c | 4 ++--
virt/kvm/irq_comm.c | 2 --
3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/ia64/kvm/kvm-ia64.c b/arch/ia64/kvm/kvm-ia64.c
index 060c594..34a1699 100644
--- a/arch/ia64/kvm/kvm-ia64.c
+++ b/arch/ia64/kvm/kvm-ia64.c
@@ -951,7 +951,9 @@ long kvm_arch_vm_ioctl(struct file *filp,
mutex_unlock(&kvm->slots_lock);
if (r)
goto out;
+ mutex_lock(&kvm->irq_lock);
r = kvm_setup_default_irq_routing(kvm);
+ mutex_unlock(&kvm->irq_lock);
if (r) {
mutex_lock(&kvm->slots_lock);
kvm_ioapic_destroy(kvm);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 736ab93..5c70869 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3319,13 +3319,13 @@ long kvm_arch_vm_ioctl(struct file *filp,
smp_wmb();
kvm->arch.vpic = vpic;
smp_wmb();
+ mutex_lock(&kvm->irq_lock);
r = kvm_setup_default_irq_routing(kvm);
if (r) {
- mutex_lock(&kvm->irq_lock);
kvm_ioapic_destroy(kvm);
kvm_destroy_pic(kvm);
- mutex_unlock(&kvm->irq_lock);
}
+ mutex_unlock(&kvm->irq_lock);
create_irqchip_unlock:
mutex_unlock(&kvm->slots_lock);
mutex_unlock(&kvm->lock);
diff --git a/virt/kvm/irq_comm.c b/virt/kvm/irq_comm.c
index 9f614b4..265fd2f 100644
--- a/virt/kvm/irq_comm.c
+++ b/virt/kvm/irq_comm.c
@@ -407,10 +407,8 @@ int kvm_set_irq_routing(struct kvm *kvm,
++ue;
}

- mutex_lock(&kvm->irq_lock);
old = kvm->irq_routing;
kvm_irq_routing_update(kvm, new);
- mutex_unlock(&kvm->irq_lock);

synchronize_rcu();

--
1.7.1