Received: from eggs.gnu.org ([2001:4830:134:3::10]:56597) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WCqvW-0000a6-O3 for qemu-devel@nongnu.org; Mon, 10 Feb 2014 08:29:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WCqvO-0007Rw-Kv for qemu-devel@nongnu.org; Mon, 10 Feb 2014 08:29:34 -0500 Received: from roura.ac.upc.es ([147.83.33.10]:56122) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WCqvO-0007RV-8i for qemu-devel@nongnu.org; Mon, 10 Feb 2014 08:29:26 -0500 From: =?utf-8?Q?Llu=C3=ADs_Vilanova?= References: <20140131160902.32741.2680.stgit@fimbulvetr.bsc.es> <20140131161008.32741.5791.stgit@fimbulvetr.bsc.es> <52F10272.8080603@twiddle.net> <874n4ey7dj.fsf@fimbulvetr.bsc.es> <52F3B45F.1040009@twiddle.net> Date: Mon, 10 Feb 2014 14:29:22 +0100 In-Reply-To: <52F3B45F.1040009@twiddle.net> (Richard Henderson's message of "Thu, 06 Feb 2014 08:12:15 -0800") Message-ID: <87mwhz9jv1.fsf@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 12/12] trace: [all] Add "guest_vmem" event List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Richard Henderson Cc: qemu-devel@nongnu.org, Stefan Hajnoczi Richard Henderson writes: > On 02/04/2014 12:01 PM, Llu=C3=ADs Vilanova wrote: >> Richard Henderson writes: >>=20 >>> On 01/31/2014 08:10 AM, Llu=C3=ADs Vilanova wrote: >>>> +#define ldub(p) ({ trace_guest_vmem(p, 1, 0); ldub_raw(p); }) >>=20 >>> Are you sure you want to log these here? Uses of these macros are >>> not restricted to the guest. Therefore you could wind up with e.g. >>> PCI device accesses being attributed to the target cpu. >>=20 >> These defines are only enabled in user-level mode. >>=20 >> But I wrote them really long ago, and I just realized they are not >> up-to-date. The changes should also cover the 'cpu_*_data' and 'cpu_*_ke= rnel' >> variants. These macros are mostly used in helpers (e.g., helper_boundl). > Yes, I know. But they're also used in non-cpu contexts such as __get_user > (i.e. kernel accesses) or virtio.c (i.e. device accesses). The macro "__get_user" accesses memory using physical addresses, so it is not traced. Grepping at "virtio.c" shows that only "ld*_phys" and "ld*_p" are used (whi= ch are not traced). Similarly happens for stores. I looked at refereces for ld/st macros (without the "_raw" and "_p" suffixe= s), and no non-target code came up (I'm including accesses - directly or indire= ctly - initiated from helper functions as target code). Am I missing something? >>> These are going to result in double-logging the same access with >>=20 >>>> +#define tcg_gen_qemu_ld_i32(val, addr, idx, memop) \ >>>> + do { \ >>>> + uint8_t _memop_size =3D _tcg_memop_size(memop); \ >>>> + trace_guest_vmem_tcg(addr, _memop_size, 0); \ >>>> + tcg_gen_qemu_ld_i32(val, addr, idx, memop); \ >>>> + } while (0) >>=20 >>> ... these. >>=20 >> I don't see how 'tcg_gen_qemu_ld_i32' gets to call 'cpu_ldl_data' > tcg_gen_qemu_ld_i32 triggers some inline code, with an out of line fallba= ck in > softmmu-template.h. > You're logging both on the main path (before qemu_ld_i32 opcode) and in t= he > fallback path. It would be one thing if you logged something different i= n the > fallback path, but you're not. You're using the exact same logging routi= ne. Aha, but I'm only tracing functions in "softmmu_header.h" (e.g., "cpu_ldub_kernel"). I've looked at the result of preprocessing "softmmu_template.h" (from "target-i386/mem_helper.c"), and the functions t= here (e.g., "helper_ret_ldub_mmu") perform translation themselves and then access physical memory (e.g., "ldub_p"). AFAIK, I did not add any tracing to that = path. >> What do you mean by non-target accesses? Accesses not directly "encoded"= in the >> semantics of a guest instruction? If so, I did this in purpose (like the= helper >> example on the top). > No, I mean accesses initiated by a device. Such things are rare, I admit, > since most devices use physical addresses not virtual. But e.g. old Sparc > hardware used a single mmu to handle both cpu and bus accesses. Hmmm, I'll have to take a look at that. Do you have any function or file fo= r the Sparc case from the top of your head? Admittedly, the whole memory access f= low is quite convoluted in QEMU, specially due to the big number of macros involved. I guess whether something could be done to simplify all this a li= ttle bit. >> The 'trace_guest_vmem_tcg' function just calls a helper generator functi= on in >> "helper.h", which cannot be included in "tcg.c". Another possibility is = to just >> forget about using "helper.h", and instead "manually" generate the call = to the >> helper; but using macros seems to me it's easier to maintain. > You simply need to move the declarations somewhere else. See e.g. > tcg-runtime.h for a set of helpers shared across all translators. Nice. I'll move them there. Thanks, 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