Received: from eggs.gnu.org ([140.186.70.92]:59981) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYNsM-0000Mw-LM for qemu-devel@nongnu.org; Wed, 07 Dec 2011 15:13:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RYNsL-0002jC-7a for qemu-devel@nongnu.org; Wed, 07 Dec 2011 15:13:58 -0500 Received: from gw.ac.upc.edu ([147.83.30.3]:44727) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYNsK-0002fx-LP for qemu-devel@nongnu.org; Wed, 07 Dec 2011 15:13:57 -0500 From: =?utf-8?Q?Llu=C3=ADs_Vilanova?= References: <20111205222208.31271.65662.stgit@ginnungagap.bsc.es> <4EDE9CBE.9080707@codemonkey.ws> <87ehwgvah0.fsf@ginnungagap.bsc.es> <4EDF703E.20401@codemonkey.ws> <87obvkqucc.fsf@ginnungagap.bsc.es> <4EDF8ABB.7010208@codemonkey.ws> <87aa74gvxj.fsf@ginnungagap.bsc.es> <4EDFA6ED.20907@codemonkey.ws> <87pqg01b7w.fsf@ginnungagap.bsc.es> <4EDFB65F.902@codemonkey.ws> Date: Wed, 07 Dec 2011 21:13:44 +0100 In-Reply-To: <4EDFB65F.902@codemonkey.ws> (Anthony Liguori's message of "Wed, 07 Dec 2011 12:54:23 -0600") Message-ID: <87zkf4rvgn.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 v2 0/5] backdoor: lightweight guest-to-QEMU backdoor channel List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: Blue Swirl , Peter Maydell , Zhi Yong Wu , qemu-devel@nongnu.org Anthony Liguori writes: > On 12/07/2011 12:51 PM, Peter Maydell wrote: >> 2011/12/7 Llu=C3=ADs Vilanova: >>> Anthony Liguori writes: >>> [...] >>>> Why should this analyzer live outside of QEMU in the first place? I f= ail to see >>>> the rationale for that other than not wanting to do the work of making= it >>>> suitable for upstream consumption. >>>=20 >>> For the same reason that SystemTap lets you add user-provided code into= the >>> trace hooks, you never know what the user actually wants. The differenc= e is that >>> when dealing with traces that require a high bandwidth, different peopl= e may be >>> interested on analyzing different events and under different conditions= , and >>> having a JIT in QEMU comes in handy to optimize the traces. This includ= es the >>> generation of extra tracing code at translation time (e.g., I generate = checks in >>> TCG to establish when I want to trace a specific event, and someone els= e may >>> just want to increment a counter using TCG code). >>>=20 >>> Guest trace instrumentation turns QEMU into a highly-performant tool fo= r dynamic >>> binary instrumentation, with all the benefits that stem from QEMU (supp= ort for a >>> myriad of target architectures, as well as support for both full-system= and >>> user-level applications). >>=20 >> I think this *is* useful. However I also think that it *is* effectively >> defining an API for people writing this hook code, and as such we ought >> to do it properly if we're going to do it. (ie nail down what we are >> providing for hook authors and don't let them grub around in the interna= ls >> otherwise). > I strongly suspect that you could define interfaces in QEMU such that you= could > do most of what you want without needing to link any code against QEMU it= self. > This is probably a case where LUA integration might make a lot of sense. Sure you can provide an API for instrumentors. It's just that defining a st= able API for that would require me at least an order of magnitude more effort, a= nd this is time I don't have right now. The other problem here is that of performance. During translation, it is basically dependant on TB reusability, plus the possibility to optimize the analyzer code when it's inlined into QEMU and s= ome of its arguments are known at compile-time. I just don't have numbers on th= at. During execution it is way more sensitive, thus my approach to build the analyzer code into QEMU. Otherwise you would go through a LUA interpreter (= or anything else) or, in the best case, a conditional indirect call (dlopen). >From my experience, these are the basics I need: * Decide what to do when an event is translated (by default - no instrument= ation -, it just generates a TCG call to an execution-time tracing routine). This includes: * Deciding whether to generate the TCG call to the execution-time tracing routine. * Access to generating other arbitrary TCG code (the API is pretty stable= , but headers depend on target-specific defines). This could also include generating code like incrementing a counter (e.= g., when counting instructions), instead of calling the execution-time trac= ing routine. My library actually hides this from the user, who just provides conditi= ons to establish whether to trace the event. Then the library automatically establishes whether it's best to evaluate each condition at translation time, using TCG code or when the execution-time tracing routine is invo= ked. * [still don't have it] Access to a map between target-specific abstracti= ons (mainly register names) and TCG values (e.g., to generate code that get= s or sets the value of a well-known register). * Decide what to do when an event is executed, including calls to execution= -time event tracing routines generated by TCG code (by default, it just calls t= he tracing backend). This includes: * Arbitrary user-provided code (the analysis itself when not inlined with TCG). * [still don't have it] Access to get and set the values of target-specif= ic abstractions (mainly registers). * Add a per-vCPU opaque pointer with data private to the analyzer code. Other things might include the injection of interrupts or anything else rel= ated to the guest. 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