Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MsOdh-0001c6-CZ for qemu-devel@nongnu.org; Mon, 28 Sep 2009 18:24:13 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MsOdb-0001bF-LK for qemu-devel@nongnu.org; Mon, 28 Sep 2009 18:24:12 -0400 Received: from [199.232.76.173] (port=40028 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MsOdb-0001bC-IK for qemu-devel@nongnu.org; Mon, 28 Sep 2009 18:24:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:26236) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MsOdb-0004wn-2y for qemu-devel@nongnu.org; Mon, 28 Sep 2009 18:24:07 -0400 Date: Mon, 28 Sep 2009 19:24:03 -0300 From: Glauber Costa Message-ID: <20090928222403.GQ29735@mothafucka.localdomain> References: <1254172517-28216-1-git-send-email-glommer@redhat.com> <1254172517-28216-2-git-send-email-glommer@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: [Qemu-devel] Re: [PATCH 1/6] provide in-kernel ioapic List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Juan Quintela Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org On Mon, Sep 28, 2009 at 11:50:46PM +0200, Juan Quintela wrote: > Glauber Costa wrote: > > This patch provides kvm with an in-kernel ioapic. We are currently not enabling it. > > The code is heavily based on what's in qemu-kvm.git. > > > > Signed-off-by: Glauber Costa > > > base_address IOAPICState field missing. > > > +#if defined(KVM_CAP_IRQCHIP) && defined(TARGET_I386) > > +static void kvm_kernel_ioapic_load_from_user(IOAPICState *s) > > +{ > > + struct kvm_irqchip chip; > > + struct kvm_ioapic_state *kioapic; > > + int i; > > + > > if (!kvm_enabled() || !kvm_irqchip_in_kernel()) { > return; No need. if this function is ever called and this is not true, this is a bug. > > > + chip.chip_id = KVM_IRQCHIP_IOAPIC; > > + kioapic = &chip.chip.ioapic; > > + > > + kioapic->id = s->id; > > + kioapic->ioregsel = s->ioregsel; > > + kioapic->base_address = IOAPIC_DEFAULT_BASE_ADDRESS; > > + kioapic->irr = s->irr; > > + for (i = 0; i < IOAPIC_NUM_PINS; i++) { > > + kioapic->redirtbl[i].bits = s->ioredtbl[i]; > > + } > > + > > + kvm_set_irqchip(&chip); > > +} > > + > > +static void kvm_kernel_ioapic_save_to_user(IOAPICState *s) > > +{ > > + struct kvm_irqchip chip; > > + struct kvm_ioapic_state *kioapic; > > + int i; > > if (!kvm_enabled() || !kvm_irqchip_in_kernel()) { > return; ditto. > > > + chip.chip_id = KVM_IRQCHIP_IOAPIC; > > + kvm_get_irqchip(&chip); > > + kioapic = &chip.chip.ioapic; > > + > > + s->id = kioapic->id; > > + s->ioregsel = kioapic->ioregsel; > > + s->irr = kioapic->irr; > > + for (i = 0; i < IOAPIC_NUM_PINS; i++) { > > + s->ioredtbl[i] = kioapic->redirtbl[i].bits; > > + } > > +} > > +#endif > > + > > +static void ioapic_pre_save(const void *opaque) > > +{ > > +#if defined(KVM_CAP_IRQCHIP) && defined(TARGET_I386) > > + IOAPICState *s = (void *)opaque; > > + > > + if (kvm_enabled() && kvm_irqchip_in_kernel()) { > > Can we put this test inside the functions? Yes, I know that qemu-kvm > uses always this syntax, but it just makes the API simpler to use. I am not sure if we are aiming for a simpler api here. Those functions should never be called if we're not using in-kernel irqchip, and it is probably better to have callers to enforce it. > > > + kvm_kernel_ioapic_save_to_user(s); > > + } > > +#endif > > +} > > + > > +static int ioapic_pre_load(void *opaque) > > +{ > > + IOAPICState *s = opaque; > > + > > + /* in case we are doing version 1, we just set these to sane > > values */ > > You forgot to update vmstate_ioapic to version 2. ok. > > > + s->irr = 0; > > + return 0; > > +} > > + > > +static int ioapic_post_load(void *opaque) > > +{ > > +#if defined(KVM_CAP_IRQCHIP) && defined(TARGET_I386) > > + IOAPICState *s = opaque; > > + > > + if (kvm_enabled() && kvm_irqchip_in_kernel()) { > > + kvm_kernel_ioapic_load_from_user(s); > > + } > > +#endif > > + return 0; > > +} > > + > > + > > static const VMStateDescription vmstate_ioapic = { > > .name = "ioapic", > > .version_id = 1, > > @@ -201,7 +276,10 @@ static const VMStateDescription vmstate_ioapic = { > > VMSTATE_UINT8(ioregsel, IOAPICState), > > VMSTATE_UINT64_ARRAY(ioredtbl, IOAPICState, IOAPIC_NUM_PINS), > > VMSTATE_END_OF_LIST() > > - } > > + }, > > + .pre_load = ioapic_pre_load, > > + .post_load = ioapic_post_load, > > + .pre_save = ioapic_pre_save, > > }; >