From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:36625) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qqn1f-0000TS-1k for qemu-devel@nongnu.org; Tue, 09 Aug 2011 10:11:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qqn1Z-0007RD-Le for qemu-devel@nongnu.org; Tue, 09 Aug 2011 10:11:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8655) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qqn1Z-0007QZ-7p for qemu-devel@nongnu.org; Tue, 09 Aug 2011 10:11:17 -0400 Date: Tue, 9 Aug 2011 15:48:57 +0300 From: "Michael S. Tsirkin" Message-ID: <20110809124856.GI524@redhat.com> References: <1312808972-1718-1-git-send-email-avi@redhat.com> <1312808972-1718-27-git-send-email-avi@redhat.com> <4E40D9F3.5080309@mc.net> <4E40D921.9080700@redhat.com> <20110809124246.GF524@redhat.com> <4E412BB3.9070703@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4E412BB3.9070703@redhat.com> Subject: Re: [Qemu-devel] [PATCH v4 26/39] pcnet: convert to memory API List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Avi Kivity Cc: Blue Swirl , Bob Breuer , qemu-devel@nongnu.org, kvm@vger.kernel.org On Tue, Aug 09, 2011 at 03:44:35PM +0300, Avi Kivity wrote: > On 08/09/2011 03:42 PM, Michael S. Tsirkin wrote: > >On Tue, Aug 09, 2011 at 09:52:17AM +0300, Avi Kivity wrote: > >> On 08/09/2011 09:55 AM, Bob Breuer wrote: > >> >> static void lance_cleanup(VLANClientState *nc) > >> >> @@ -117,13 +116,11 @@ static int lance_init(SysBusDevice *dev) > >> >> SysBusPCNetState *d = FROM_SYSBUS(SysBusPCNetState, dev); > >> >> PCNetState *s =&d->state; > >> >> > >> >> - s->mmio_index = > >> >> - cpu_register_io_memory(lance_mem_read, lance_mem_write, d, > >> >> - DEVICE_NATIVE_ENDIAN); > >> >> + memory_region_init_io(&s->mmio,&lance_mem_ops, s, "lance-mmio", 4); > >> > > >> >You've switched up d and s here, so anything that tries to talk to the > >> >ethernet, such as a sparc32 guest, will now cause Qemu to segfault. > >> > > >> > > >> > >> Good catch; will post a fix. > >> > >> Maybe keeping the opaque wasn't such a good idea. > > > >Yes, we typically can get from the mmio to the device state > >using container_of. > > > > > > But in some cases, we can't, and the it's a pain having to wrap > MemoryRegion in another structure containing an opaque. I guess, even though that wrapping structure would use a proper type, not an opaque. > Maybe a good compromise is to: > > - keep MemoryRegion::opaque > - pass a MemoryRegion *mr to callbacks instead of opaque > - use container_of() when possible > - use mr->opaque otherwise Right. This even saves a memory dereference when opaque is unused. > -- > error compiling committee.c: too many arguments to function