From patchwork Tue Aug 11 12:31:30 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 40606 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n7BCWPvn002138 for ; Tue, 11 Aug 2009 12:32:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753741AbZHKMbh (ORCPT ); Tue, 11 Aug 2009 08:31:37 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753939AbZHKMbh (ORCPT ); Tue, 11 Aug 2009 08:31:37 -0400 Received: from mx2.redhat.com ([66.187.237.31]:58481 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751854AbZHKMbg (ORCPT ); Tue, 11 Aug 2009 08:31:36 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n7BCVbXK032107 for ; Tue, 11 Aug 2009 08:31:37 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n7BCVaIh028932; Tue, 11 Aug 2009 08:31:36 -0400 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n7BCVZSF000374; Tue, 11 Aug 2009 08:31:35 -0400 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id 4140818D466; Tue, 11 Aug 2009 15:31:35 +0300 (IDT) From: Gleb Natapov To: avi@redhat.com Cc: kvm@vger.kernel.org Subject: [PATCH 3/8 v2] Move irq routing data structure to rcu locking Date: Tue, 11 Aug 2009 15:31:30 +0300 Message-Id: <1249993895-11119-4-git-send-email-gleb@redhat.com> In-Reply-To: <1249993895-11119-1-git-send-email-gleb@redhat.com> References: <1249993895-11119-1-git-send-email-gleb@redhat.com> X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Signed-off-by: Gleb Natapov --- virt/kvm/irq_comm.c | 15 ++++++++++----- 1 files changed, 10 insertions(+), 5 deletions(-) diff --git a/virt/kvm/irq_comm.c b/virt/kvm/irq_comm.c index 42994c4..9f41dde 100644 --- a/virt/kvm/irq_comm.c +++ b/virt/kvm/irq_comm.c @@ -152,7 +152,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 * 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) hlist_for_each_entry(e, n, &irq_rt->map[irq], link) { int r = e->set(e, kvm, sig_level); @@ -161,6 +162,7 @@ int kvm_set_irq(struct kvm *kvm, int irq_source_id, u32 irq, int level) ret = r + ((ret < 0) ? 0 : ret); } + rcu_read_unlock(); return ret; } @@ -172,9 +174,11 @@ void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned 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]; if (gsi == -1) gsi = pin; + rcu_read_unlock(); hlist_for_each_entry(kian, n, &kvm->arch.irq_ack_notifier_list, link) if (kian->gsi == gsi) @@ -267,9 +271,9 @@ void kvm_fire_mask_notifiers(struct kvm *kvm, int irq, bool mask) 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); - mutex_unlock(&kvm->irq_lock); } static int setup_routing_entry(struct kvm_irq_routing_table *rt, @@ -364,8 +368,9 @@ int kvm_set_irq_routing(struct kvm *kvm, mutex_lock(&kvm->irq_lock); old = kvm->irq_routing; - kvm->irq_routing = new; + rcu_assign_pointer(kvm->irq_routing, new); mutex_unlock(&kvm->irq_lock); + synchronize_rcu(); new = old; r = 0;