From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60880) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKgDR-0006eQ-6J for qemu-devel@nongnu.org; Wed, 06 Jul 2016 02:21:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bKgDQ-0004Qz-6R for qemu-devel@nongnu.org; Wed, 06 Jul 2016 02:21:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58642) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bKgDP-0004Qm-Uv for qemu-devel@nongnu.org; Wed, 06 Jul 2016 02:21:44 -0400 From: Igor Mammedov Date: Wed, 6 Jul 2016 08:20:49 +0200 Message-Id: <1467786055-85835-14-git-send-email-imammedo@redhat.com> In-Reply-To: <1467786055-85835-1-git-send-email-imammedo@redhat.com> References: <1467786055-85835-1-git-send-email-imammedo@redhat.com> Subject: [Qemu-devel] [PATCH v3 13/19] 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: qemu-devel@nongnu.org Cc: pkrempa@redhat.com, ehabkost@redhat.com, mst@redhat.com, armbru@redhat.com, eduardo.otubo@profitbricks.com, marcel@redhat.com, pbonzini@redhat.com, rth@twiddle.net 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. Fixes error "apic initialization failed" when a CPU hotplugged and unplugged more times than there are free slots in local_apics[]. Signed-off-by: Igor Mammedov --- hw/intc/apic.c | 16 +++++++--------- include/hw/i386/apic_internal.h | 1 - 2 files changed, 7 insertions(+), 10 deletions(-) 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; if (apic && apic->id == dest) - return dest; /* shortcut in case apic->id == apic->idx */ + return dest; /* shortcut in case apic->id == local_apics[dest]->id */ for (i = 0; i < MAX_APICS; i++) { apic = local_apics[i]; @@ -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; } @@ -871,20 +871,18 @@ static const MemoryRegionOps apic_io_ops = { static void apic_realize(DeviceState *dev, Error **errp) { APICCommonState *s = APIC_COMMON(dev); - static int apic_no; - if (apic_no >= MAX_APICS) { - error_setg(errp, "%s initialization failed.", - object_get_typename(OBJECT(dev))); + if (s->id >= MAX_APICS) { + error_setg(errp, "%s initialization failed. APIC ID %d is invalid", + object_get_typename(OBJECT(dev)), s->id); return; } - s->idx = apic_no++; memory_region_init_io(&s->io_memory, OBJECT(s), &apic_io_ops, s, "apic-msi", APIC_SPACE_SIZE); s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, apic_timer, s); - local_apics[s->idx] = s; + local_apics[s->id] = s; msi_nonbroken = true; } diff --git a/include/hw/i386/apic_internal.h b/include/hw/i386/apic_internal.h index 5d3be9a..e5d1550 100644 --- a/include/hw/i386/apic_internal.h +++ b/include/hw/i386/apic_internal.h @@ -173,7 +173,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; -- 2.7.0