Received: from eggs.gnu.org ([140.186.70.92]:47692) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R9OUG-0005BS-II for qemu-devel@nongnu.org; Thu, 29 Sep 2011 17:49:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R9OUF-0002ze-Gn for qemu-devel@nongnu.org; Thu, 29 Sep 2011 17:49:48 -0400 Received: from gw.ac.upc.es ([147.83.30.3]:39806 helo=gw.ac.upc.edu) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R9OUF-0002yp-5q for qemu-devel@nongnu.org; Thu, 29 Sep 2011 17:49:47 -0400 From: =?utf-8?Q?Llu=C3=ADs_Vilanova?= References: <20110929134727.19559.54734.stgit@ginnungagap.bsc.es> <20110929134749.19559.26774.stgit@ginnungagap.bsc.es> Date: Thu, 29 Sep 2011 23:49:43 +0200 In-Reply-To: (Blue Swirl's message of "Thu, 29 Sep 2011 20:42:07 +0000") Message-ID: <87y5x76mtk.fsf@ginnungagap.bsc.es> MIME-Version: 1.0 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 Cc: Zhi Yong Wu , qemu-devel@nongnu.org Blue Swirl writes: > 2011/9/29 Llu=C3=ADs Vilanova : >> +static uint64_t control_io_read(void *opaque, target_phys_addr_t addr, = 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.impl), 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 not su= re if that's the API I'm supposed to use. Then return the N'th byte of the uint64_t variable holding the (endianess-a= ware) result. >> +} >> + >> +static void control_io_write(void *opaque, target_phys_addr_t addr, uin= t64_t data, unsigned size) >> +{ >> + =C2=A0 =C2=A0State *s =3D opaque; >> + >> + =C2=A0 =C2=A0uint8_t *cmdb =3D (uint8_t*)&s->cmd; >> + =C2=A0 =C2=A0cmdb[addr % CTRL_BYTES] =3D (uint8_t)data; >> + >> + =C2=A0 =C2=A0if ((addr + size) % CTRL_BYTES =3D=3D 0) { >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0qemu_backdoor(ldq_p(&s->cmd), s->data_ptr); >> + =C2=A0 =C2=A0} > Same here. Pre: same as during reads. Accumulates writes into s->cmd to build the command the guest is sending us= (in guest endianess). When CTRL_BYTES bytes have been written into the device, get the command va= lue into host endianess and invoke the user-provided backdoor callback. This assumes that when executing in KVM, the device handling infrastructure= will get a lock and only one CPU will be sending a backdoor command until comple= tion. I'll add some comments there and prefix all structs and functions with "backdoor_", as otherwise debugging could get harder if everyone started avoiding the prefixes. Lluis --=20 "And it's much the same thing with knowledge, for whenever you learn something new, the whole world becomes that much richer." -- The Princess of Pure Reason, as told by Norton Juster in The Phantom Tollbooth