Commit e42bba90 authored by Gleb Natapov's avatar Gleb Natapov Committed by Avi Kivity

KVM: Move irq routing data structure to rcu locking

Signed-off-by: default avatarGleb Natapov <gleb@redhat.com>
Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
parent 3e71f88b
...@@ -159,7 +159,8 @@ int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level) ...@@ -159,7 +159,8 @@ int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level)
* IOAPIC. So set the bit in both. The guest will ignore * IOAPIC. So set the bit in both. The guest will ignore
* writes to the unused one. * writes to the unused one.
*/ */
irq_rt = kvm->irq_routing; rcu_read_lock();
irq_rt = rcu_dereference(kvm->irq_routing);
if (irq < irq_rt->nr_rt_entries) if (irq < irq_rt->nr_rt_entries)
hlist_for_each_entry(e, n, &irq_rt->map[irq], link) { hlist_for_each_entry(e, n, &irq_rt->map[irq], link) {
int r = e->set(e, kvm, irq_source_id, level); int r = e->set(e, kvm, irq_source_id, level);
...@@ -168,6 +169,7 @@ int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level) ...@@ -168,6 +169,7 @@ int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level)
ret = r + ((ret < 0) ? 0 : ret); ret = r + ((ret < 0) ? 0 : ret);
} }
rcu_read_unlock();
return ret; return ret;
} }
...@@ -179,7 +181,10 @@ void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin) ...@@ -179,7 +181,10 @@ void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin)
trace_kvm_ack_irq(irqchip, pin); trace_kvm_ack_irq(irqchip, pin);
gsi = kvm->irq_routing->chip[irqchip][pin]; rcu_read_lock();
gsi = rcu_dereference(kvm->irq_routing)->chip[irqchip][pin];
rcu_read_unlock();
if (gsi != -1) if (gsi != -1)
hlist_for_each_entry(kian, n, &kvm->arch.irq_ack_notifier_list, hlist_for_each_entry(kian, n, &kvm->arch.irq_ack_notifier_list,
link) link)
...@@ -279,9 +284,9 @@ void kvm_fire_mask_notifiers(struct kvm *kvm, int irq, bool mask) ...@@ -279,9 +284,9 @@ void kvm_fire_mask_notifiers(struct kvm *kvm, int irq, bool mask)
void kvm_free_irq_routing(struct kvm *kvm) void kvm_free_irq_routing(struct kvm *kvm)
{ {
mutex_lock(&kvm->irq_lock); /* Called only during vm destruction. Nobody can use the pointer
at this stage */
kfree(kvm->irq_routing); kfree(kvm->irq_routing);
mutex_unlock(&kvm->irq_lock);
} }
static int setup_routing_entry(struct kvm_irq_routing_table *rt, static int setup_routing_entry(struct kvm_irq_routing_table *rt,
...@@ -387,8 +392,9 @@ int kvm_set_irq_routing(struct kvm *kvm, ...@@ -387,8 +392,9 @@ int kvm_set_irq_routing(struct kvm *kvm,
mutex_lock(&kvm->irq_lock); mutex_lock(&kvm->irq_lock);
old = kvm->irq_routing; old = kvm->irq_routing;
kvm->irq_routing = new; rcu_assign_pointer(kvm->irq_routing, new);
mutex_unlock(&kvm->irq_lock); mutex_unlock(&kvm->irq_lock);
synchronize_rcu();
new = old; new = old;
r = 0; r = 0;
......
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