From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH 4/6] KVM: Add kvm_get_irq_routing_entry() func Date: Thu, 18 Nov 2010 11:30:47 +0200 Message-ID: <4CE4F247.9080203@redhat.com> References: <1289812532-3227-1-git-send-email-sheng@linux.intel.com> <1289812532-3227-5-git-send-email-sheng@linux.intel.com> <4CE3E045.30500@redhat.com> <201011181022.15853.sheng@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Marcelo Tosatti , "Michael S. Tsirkin" , kvm@vger.kernel.org To: Sheng Yang Return-path: Received: from mx1.redhat.com ([209.132.183.28]:28261 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755900Ab0KRJaw (ORCPT ); Thu, 18 Nov 2010 04:30:52 -0500 In-Reply-To: <201011181022.15853.sheng@linux.intel.com> Sender: kvm-owner@vger.kernel.org List-ID: On 11/18/2010 04:22 AM, Sheng Yang wrote: > On Wednesday 17 November 2010 22:01:41 Avi Kivity wrote: > > On 11/15/2010 11:15 AM, Sheng Yang wrote: > > > We need to query the entry later. > > > > > > +int kvm_get_irq_routing_entry(struct kvm *kvm, int gsi, > > > + struct kvm_kernel_irq_routing_entry *entry) > > > +{ > > > + int count = 0; > > > + struct kvm_kernel_irq_routing_entry *ei = NULL; > > > + struct kvm_irq_routing_table *irq_rt; > > > + struct hlist_node *n; > > > + > > > + rcu_read_lock(); > > > + irq_rt = rcu_dereference(kvm->irq_routing); > > > + if (gsi< irq_rt->nr_rt_entries) > > > + hlist_for_each_entry(ei, n,&irq_rt->map[gsi], link) > > > + count++; > > > + if (count == 1) > > > + *entry = *ei; > > > + rcu_read_unlock(); > > > + > > > + return (count != 1); > > > +} > > > + > > > > Not good form to rely on ei being valid after the loop. > > > > I guess this is only useful for msi? Need to document it. > > May can be used for others later, it's somehow generic. Where should I document > it? Non-msi interrupts (wires) can be wired to more than one interrupt line (and often are - pic/ioapic). You can document it by adding _msi to the name. > > > > *entry may be stale after rcu_read_unlock(). Is this a problem? > > I suppose not. All MSI-X MMIO accessing would be executed without delay, so no re- > order issue would happen. If the guest is reading and writing the field at the same > time(from two cpus), it should got some kinds of sync method for itself - or it > may not care what's the reading result(like the one after msix_mask_irq()). I guess so. Michael/Alex? -- error compiling committee.c: too many arguments to function