From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:35523) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCdys-0003Ox-Ue for qemu-devel@nongnu.org; Tue, 27 Mar 2012 17:31:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SCdyr-0003Zp-4t for qemu-devel@nongnu.org; Tue, 27 Mar 2012 17:31:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:61840) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SCdyq-0003Zh-ST for qemu-devel@nongnu.org; Tue, 27 Mar 2012 17:31:05 -0400 Message-ID: <1332883861.3799.13.camel@bling.home> From: Alex Williamson Date: Tue, 27 Mar 2012 15:31:01 -0600 In-Reply-To: <025b834272f9972f97873779be6523527dad42a8.1332881354.git.jbaron@redhat.com> References: <025b834272f9972f97873779be6523527dad42a8.1332881354.git.jbaron@redhat.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Mime-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 1/2] qemu kvm: Set up gsi bitmap correctly List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jason Baron Cc: aliguori@us.ibm.com, kvm@vger.kernel.org, mst@redhat.com, jan.kiszka@siemens.com, qemu-devel@nongnu.org, avi@redhat.com On Tue, 2012-03-27 at 17:00 -0400, Jason Baron wrote: > The current 'kvm_init_irq_routing()' doesn't set up the gsi bitmap > correctly, and as a consequence pins max_gsi to 32 when it really > should be 1024. I ran into this limitation while testing pci > passthrough, where I consistently would get -ENOSPACE return from > kvm_get_irq_route_gsi() in assigned_dev_update_msix_mmio(). > > Signed-off-by: Jason Baron > --- > kvm-all.c | 4 ++-- > qemu-kvm.c | 2 +- > 2 files changed, 3 insertions(+), 3 deletions(-) > > diff --git a/kvm-all.c b/kvm-all.c > index ab88c7c..7d602af 100644 > --- a/kvm-all.c > +++ b/kvm-all.c > @@ -873,9 +873,9 @@ static void kvm_init_irq_routing(KVMState *s) > unsigned int gsi_bits, i; > > /* Round up so we can search ints using ffs */ > - gsi_bits = (gsi_count + 31) / 32; > + gsi_bits = ALIGN(gsi_count, 32); > s->used_gsi_bitmap = g_malloc0(gsi_bits / 8); I think the above is all that's needed (it actually used to be this, then got broken in 84b058d). But if we do this: > - s->max_gsi = gsi_bits; > + s->max_gsi = gsi_count; Then we'll hit this assert from the code immediately below where we're marking over-allocated bits as already used if we actually did a round-up: static void set_gsi(KVMState *s, unsigned int gsi) { assert(gsi < s->max_gsi); Sorry, I had forgotten about this pre-allocation trick to avoid returning > gsi_count when we talked about this. > > /* Mark any over-allocated bits as already in use */ > for (i = gsi_count; i < gsi_bits; i++) { > diff --git a/qemu-kvm.c b/qemu-kvm.c > index 2047ebb..b17cae0 100644 > --- a/qemu-kvm.c > +++ b/qemu-kvm.c > @@ -249,7 +249,7 @@ int kvm_get_irq_route_gsi(void) > uint32_t *buf = s->used_gsi_bitmap; > > /* Return the lowest unused GSI in the bitmap */ And we get to avoid doing this ALIGN on every search. > - for (i = 0; i < s->max_gsi / 32; i++) { > + for (i = 0; i < (ALIGN(s->max_gsi, 32) / 32); i++) { > bit = ffs(~buf[i]); > if (!bit) { > continue; Thanks, Alex