From patchwork Tue Jul 19 17:22:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 9237999 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 441A7602F0 for ; Tue, 19 Jul 2016 18:02:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3BF9B26A4D for ; Tue, 19 Jul 2016 18:02:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30CC026E64; Tue, 19 Jul 2016 18:02:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CEDCD26A4D for ; Tue, 19 Jul 2016 18:02:27 +0000 (UTC) Received: from localhost ([::1]:57687 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPZLe-0001rT-Un for patchwork-qemu-devel@patchwork.kernel.org; Tue, 19 Jul 2016 14:02:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54973) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPYkY-0002NF-MX for qemu-devel@nongnu.org; Tue, 19 Jul 2016 13:24:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPYkW-0002kP-EK for qemu-devel@nongnu.org; Tue, 19 Jul 2016 13:24:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38291) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPYkW-0002kI-5u for qemu-devel@nongnu.org; Tue, 19 Jul 2016 13:24:04 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A5B867F082; Tue, 19 Jul 2016 17:24:03 +0000 (UTC) Received: from localhost (vpn1-5-81.gru2.redhat.com [10.97.5.81]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u6JHO1kf022096; Tue, 19 Jul 2016 13:24:02 -0400 From: Eduardo Habkost To: Peter Maydell Date: Tue, 19 Jul 2016 14:22:51 -0300 Message-Id: <1468948976-30660-24-git-send-email-ehabkost@redhat.com> In-Reply-To: <1468948976-30660-1-git-send-email-ehabkost@redhat.com> References: <1468948976-30660-1-git-send-email-ehabkost@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 19 Jul 2016 17:24:03 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 23/28] apic: Drop APICCommonState.idx and use APIC ID as index in local_apics[] X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Igor Mammedov , qemu-devel@nongnu.org, Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: 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. 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 Reviewed-by: Radim Krčmář Reviewed-by: Michael S. Tsirkin Signed-off-by: Eduardo Habkost --- 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 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;