From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50647) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCSZ4-0005I3-9k for qemu-devel@nongnu.org; Thu, 22 Aug 2013 06:56:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VCSYy-00072g-AS for qemu-devel@nongnu.org; Thu, 22 Aug 2013 06:56:30 -0400 Received: from cantor2.suse.de ([195.135.220.15]:55819 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCSYy-00072R-0r for qemu-devel@nongnu.org; Thu, 22 Aug 2013 06:56:24 -0400 Message-ID: <5215EE51.8070409@suse.de> Date: Thu, 22 Aug 2013 12:56:17 +0200 From: =?UTF-8?B?QW5kcmVhcyBGw6RyYmVy?= MIME-Version: 1.0 References: <1377012076-7035-1-git-send-email-afaerber@suse.de> <1377012076-7035-12-git-send-email-afaerber@suse.de> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 11/24] cpu/a15mpcore: Embed GICState List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Alexey Kardashevskiy , QEMU Developers , Paul Brook Am 21.08.2013 23:05, schrieb Peter Maydell: > On 20 August 2013 16:21, Andreas F=C3=A4rber wrote: >> From: Andreas F=C3=A4rber >> >> This covers both emulated and KVM GIC. >=20 >> @@ -35,40 +36,48 @@ typedef struct A15MPPrivState { >> uint32_t num_cpu; >> uint32_t num_irq; >> MemoryRegion container; >> - DeviceState *gic; >> + >> + GICState gic; >> } A15MPPrivState; >=20 >> static void a15mp_priv_initfn(Object *obj) >> { >> SysBusDevice *sbd =3D SYS_BUS_DEVICE(obj); >> A15MPPrivState *s =3D A15MPCORE_PRIV(obj); >> + DeviceState *gicdev; >> + const char *gictype =3D "arm_gic"; >> + >> + if (kvm_irqchip_in_kernel()) { >> + gictype =3D "kvm-arm-gic"; >> + } >> >> memory_region_init(&s->container, obj, "a15mp-priv-container", 0x= 8000); >> sysbus_init_mmio(sbd, &s->container); >> + >> + object_initialize(&s->gic, gictype); >> + gicdev =3D DEVICE(&s->gic); >> + qdev_set_parent_bus(gicdev, sysbus_get_default()); >> + qdev_prop_set_uint32(gicdev, "revision", 2); >=20 > So this is basically assuming that kvm-arm-gic and arm-gic > both have an instance struct of exactly the same size, > even though they're different classes (they happen to be > so at the moment, because neither adds extra state beyond > that needed by common base class). Is that really a good > idea? (If it ever becomes not true we get silent memory > corruption here...) Not sure if a union of only one member is permitted? We're not actually accessing the GICState, only void* and DEVICE()/SYS_BUS_DEVICE(), so it just needs to block the memory, hopefully without needing to distinguish between ->gic.emulated and ->gic.kvm pointers. The decision doesn't depend on any user-settable property, just on the at this point global kvm_enabled() state, so I see nowhere else to allocate it dynamically. If you change the .instance_size struct one of the GICs uses, then a number of places will need to be reviewed, including ARM_GIC_COMMON()[*], ARM_GIC() and KVM_ARM_GIC() all returning the same type. [*] When we're through with the functional changes, we should s/ARM_GIC_COMMON/COMMON_ARM_GIC/g to match the general pattern. Andreas --=20 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=C3=BCrnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imend=C3=B6rffer; HRB 16746 AG N=C3=BC= rnberg