From: Fabio Checconi Subject: In-kernel ioapic and bug #2143498 Date: Sat, 4 Oct 2008 03:35:15 +0200 Message-ID: <20081004013515.GA9920@gandalf.sssup.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii To: "kvm@vger.kernel.org" Return-path: Received: from ms01.sssup.it ([193.205.80.99]:37934 "EHLO sssup.it" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751978AbYJDC3j (ORCPT ); Fri, 3 Oct 2008 22:29:39 -0400 Received: from [193.205.82.7] (HELO gandalf.sssup.it) by sssup.it (CommuniGate Pro SMTP 4.1.8) with ESMTP-TLS id 45565559 for kvm@vger.kernel.org; Sat, 04 Oct 2008 03:29:03 +0200 Received: from smaug.retis (smaug.retis [10.30.3.72]) by gandalf.sssup.it (8.12.10/8.12.10) with ESMTP id m940JrVq003818 for ; Sat, 4 Oct 2008 02:19:53 +0200 Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: Hi all, I can reproduce bug #2143498 (FreeBSD fails to reboot), and it seems to be related to the ioapic reset; using -no-kvm-irqchip solves the problem, at least here. Looking at the code I've not found where the in-kernel ioapic is reset; the patch below reloads its state from userspace in the reset handler and seems to make things work, does it make sense? Thank you. --- diff --git a/qemu/hw/apic.c b/qemu/hw/apic.c index 62cbd98..8db8ca9 100644 --- a/qemu/hw/apic.c +++ b/qemu/hw/apic.c @@ -1271,11 +1271,18 @@ static int ioapic_load(QEMUFile *f, void *opaque, int version_id) static void ioapic_reset(void *opaque) { IOAPICState *s = opaque; - int i; + int i, id = s->id; memset(s, 0, sizeof(*s)); + s->id = id; + s->base_address = 0xfec00000; + for(i = 0; i < IOAPIC_NUM_PINS; i++) s->ioredtbl[i] = 1 << 16; /* mask LVT */ + + if (kvm_enabled() && qemu_kvm_irqchip_in_kernel()) { + kvm_kernel_ioapic_load_from_user(s); + } } static CPUReadMemoryFunc *ioapic_mem_read[3] = { @@ -1298,8 +1305,8 @@ IOAPICState *ioapic_init(void) s = qemu_mallocz(sizeof(IOAPICState)); if (!s) return NULL; - ioapic_reset(s); s->id = last_apic_id++; + ioapic_reset(s); io_memory = cpu_register_io_memory(0, ioapic_mem_read, ioapic_mem_write, s);