From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPBs5-0003Wl-Cy for qemu-devel@nongnu.org; Mon, 18 Jul 2016 12:58:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPBs0-0003ih-7A for qemu-devel@nongnu.org; Mon, 18 Jul 2016 12:58:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47249) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPBrz-0003hc-PD for qemu-devel@nongnu.org; Mon, 18 Jul 2016 12:58:16 -0400 Date: Mon, 18 Jul 2016 18:58:11 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= Message-ID: <20160718165810.GB23807@potion> References: <1468515285-173356-1-git-send-email-imammedo@redhat.com> <1468515285-173356-10-git-send-email-imammedo@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1468515285-173356-10-git-send-email-imammedo@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v4 09/16] apic: drop APICCommonState.idx and use APIC ID as index in local_apics[] List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Igor Mammedov Cc: qemu-devel@nongnu.org, pkrempa@redhat.com, ehabkost@redhat.com, mst@redhat.com, eduardo.otubo@profitbricks.com, Bandan Das , pbonzini@redhat.com 2016-07-14 18:54+0200, Igor Mammedov: > local_apics[] is sized to contain all APIC ID supported in xAPIC mode, > so use APIC ID as index in it instead of constantly increasing counter = idx. >=20 > Fixes error "apic initialization failed" when a CPU hotplugged and > unplugged more times than there are free slots in local_apics[]. >=20 > Signed-off-by: Igor Mammedov > --- The new method handles dynamic APIC ID changes made by the guest and id is set to the initial apic_id when realize is called, so it's even better than the previous one as we have higher chance of hitting the correct apic in local_apics[]. Reviewed-by: Radim Kr=C4=8Dm=C3=A1=C5=99 > CC: Radim Kr=C4=8Dm=C3=A1=C5=99 > CC: pbonzini@redhat.com > --- > include/hw/i386/apic_internal.h | 1 - > hw/intc/apic.c | 16 +++++++--------- > 2 files changed, 7 insertions(+), 10 deletions(-) >=20 > diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_int= ernal.h > index 67348e9..8330592 100644 > --- a/include/hw/i386/apic_internal.h > +++ b/include/hw/i386/apic_internal.h > @@ -174,7 +174,6 @@ struct APICCommonState { > uint32_t initial_count; > int64_t initial_count_load_time; > int64_t next_time; > - int idx; /* not actually common, used only by 'apic' derived class= */ > QEMUTimer *timer; > int64_t timer_expiry; > int sipi_vector; > diff --git a/hw/intc/apic.c b/hw/intc/apic.c > index b0d237b..f473572 100644 > --- a/hw/intc/apic.c > +++ b/hw/intc/apic.c > @@ -421,7 +421,7 @@ static int apic_find_dest(uint8_t dest) > int i; > =20 > if (apic && apic->id =3D=3D dest) > - return dest; /* shortcut in case apic->id =3D=3D apic->idx */ > + return dest; /* shortcut in case apic->id =3D=3D local_apics[= dest]->id */ > =20 > for (i =3D 0; i < MAX_APICS; i++) { > apic =3D local_apics[i]; (We could also update local_apics[] when APIC ID changes and drop the loop, but it's safer this way.) > @@ -504,14 +504,14 @@ static void apic_deliver(DeviceState *dev, uint8_= t dest, uint8_t dest_mode, > break; > case 1: > memset(deliver_bitmask, 0x00, sizeof(deliver_bitmask)); > - apic_set_bit(deliver_bitmask, s->idx); > + apic_set_bit(deliver_bitmask, s->id); > break; > case 2: > memset(deliver_bitmask, 0xff, sizeof(deliver_bitmask)); > break; > case 3: > memset(deliver_bitmask, 0xff, sizeof(deliver_bitmask)); > - apic_reset_bit(deliver_bitmask, s->idx); > + apic_reset_bit(deliver_bitmask, s->id); > break; > } > =20 > @@ -871,20 +871,18 @@ static const MemoryRegionOps apic_io_ops =3D { > static void apic_realize(DeviceState *dev, Error **errp) > { > APICCommonState *s =3D APIC_COMMON(dev); > - static int apic_no; > =20 > - if (apic_no >=3D MAX_APICS) { > - error_setg(errp, "%s initialization failed.", > - object_get_typename(OBJECT(dev))); > + if (s->id >=3D MAX_APICS) { > + error_setg(errp, "%s initialization failed. APIC ID %d is inva= lid", > + object_get_typename(OBJECT(dev)), s->id); > return; > } > - s->idx =3D apic_no++; > =20 > memory_region_init_io(&s->io_memory, OBJECT(s), &apic_io_ops, s, "= apic-msi", > APIC_SPACE_SIZE); > =20 > s->timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, apic_timer, s); > - local_apics[s->idx] =3D s; > + local_apics[s->id] =3D s; > =20 > msi_nonbroken =3D true; > } > --=20 > 2.7.4 >=20