From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:58838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R9kB9-0006cL-OE for qemu-devel@nongnu.org; Fri, 30 Sep 2011 16:59:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R9kB8-0003zj-9k for qemu-devel@nongnu.org; Fri, 30 Sep 2011 16:59:31 -0400 Received: from mail-qw0-f45.google.com ([209.85.216.45]:50316) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R9kB7-0003zf-Vm for qemu-devel@nongnu.org; Fri, 30 Sep 2011 16:59:30 -0400 Received: by qadb10 with SMTP id b10so849757qad.4 for ; Fri, 30 Sep 2011 13:59:29 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <87ehyx3gdh.fsf@ginnungagap.bsc.es> References: <20110929134727.19559.54734.stgit@ginnungagap.bsc.es> <20110929134749.19559.26774.stgit@ginnungagap.bsc.es> <87y5x76mtk.fsf@ginnungagap.bsc.es> <87ehyx3gdh.fsf@ginnungagap.bsc.es> From: Blue Swirl Date: Fri, 30 Sep 2011 20:59:09 +0000 Message-ID: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 4/5] backdoor: [softmmu] Add QEMU-side proxy to "libbackdoor.a" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl , qemu-devel@nongnu.org, Zhi Yong Wu 2011/9/30 Llu=C3=ADs Vilanova : > Blue Swirl writes: > >> 2011/9/29 Llu=C3=ADs Vilanova : >>> Blue Swirl writes: >>> >>>> 2011/9/29 Llu=C3=ADs Vilanova : >>>>> +static uint64_t control_io_read(void *opaque, target_phys_addr_t add= r, unsigned size) >>>>> +{ >>>>> + =C2=A0 =C2=A0State *s =3D opaque; >>>>> + >>>>> + =C2=A0 =C2=A0uint64_t res =3D ldq_p(&s->size); >>>>> + =C2=A0 =C2=A0uint8_t *resb =3D (uint8_t*)&res; >>>>> + =C2=A0 =C2=A0return resb[addr % CTRL_BYTES]; >>> >>>> I don't think these lines do what you mean, but I'm also not sure what >>>> it is supposed to mean. >>> >>> Pre: only can read on a byte-per-byte basis (as stated in control_ops.i= mpl), >>> just because the code looks less ugly, and host performance should not = be an >>> issue here. >>> >>> The device is treated as a circular buffer of length CTRL_BYTES >>> >>> Reads are only used to get the size of the data channel. >>> >>> First line should handle guest/host endianess swapping, although I'm no= t sure if >>> that's the API I'm supposed to use. >>> >>> Then return the N'th byte of the uint64_t variable holding the (endiane= ss-aware) >>> result. > >> That may be the intention, but the first line will load res from guest >> memory using an address (&s->size) in host memory. > > Ok, I think I found what I really wanted: tswap64 > > >> I think the next two lines are equal to >> return res >> (addr % CTRL_BYTES); >> but with some obfuscation. > > But I cannot assume any endianess on neither host or guest. The only thin= g I can > assume is that the generic device code handling the reads will read from = lower > to higher addresses. Since this is your device, you can specify that the device works only in little endian, like most if not all PCI devices. Then you can use le64_to_cpu(). > In any case, take me with a grain of salt, endianess often confuses me. > > >> It would be much clearer if the registers were byte arrays so you >> could read and write the data directly without pointer arithmetic. > > Is that something present on the device API? Sorry I don't know what you = mean by > byte array... for me 'resb' already is a byte array :) I meant that instead of uint64_t size; uint64_t cmd; you'd have uint8_t size[8]; uint8_t cmd[8]; >> Byte accesses will be slower than larger word size accesses, I thought >> performance was one of the goals with this? > > They will be slower on host time, but will not waste "guest time". > > BTW, will the current scheme in KVM provoke one VM exit for each byte or = only > one for the whole 64bits? > > But yes, I was just too lazy to add code for all the supported sizes from= 1 to > 8, and let the generic device code pick the best. > > > Lluis > > -- > =C2=A0"And it's much the same thing with knowledge, for whenever you lear= n > =C2=A0something new, the whole world becomes that much richer." > =C2=A0-- The Princess of Pure Reason, as told by Norton Juster in The Pha= ntom > =C2=A0Tollbooth >