From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baKOL-0007zy-2R for qemu-devel@nongnu.org; Thu, 18 Aug 2016 06:17:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1baKOG-0004gr-Fe for qemu-devel@nongnu.org; Thu, 18 Aug 2016 06:17:39 -0400 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]:34772) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1baKOG-0004gQ-5f for qemu-devel@nongnu.org; Thu, 18 Aug 2016 06:17:36 -0400 Received: by mail-wm0-x243.google.com with SMTP id q128so4708360wma.1 for ; Thu, 18 Aug 2016 03:17:36 -0700 (PDT) Date: Thu, 18 Aug 2016 11:17:32 +0100 From: Stefan Hajnoczi Message-ID: <20160818101732.GC4850@stefanha-x1.localdomain> References: <147041636348.2523.2954972609232949598.stgit@fimbulvetr.bsc.es> <147041637969.2523.4570342042982870131.stgit@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="t0UkRYy7tHLRMCai" Content-Disposition: inline In-Reply-To: <147041637969.2523.4570342042982870131.stgit@fimbulvetr.bsc.es> Subject: Re: [Qemu-devel] [PATCH 3/6] hypertrace: [*-user] Add QEMU-side proxy to "guest_hypertrace" event List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?Llu=EDs?= Vilanova Cc: qemu-devel@nongnu.org, Riku Voipio , Stefan Hajnoczi --t0UkRYy7tHLRMCai Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Aug 05, 2016 at 06:59:39PM +0200, Llu=EDs Vilanova wrote: > +static void init_channel(const char *base, const char *suffix, size_t si= ze, > + char ** path, int *fd, uint64_t **addr) > +{ > + *path =3D g_malloc(strlen(base) + strlen(suffix) + 1); > + sprintf(*path, "%s%s", base, suffix); Use g_strdup_printf() instead. > +static void swap_control(void *from, void *to) > +{ > + if (mprotect(from, getpagesize(), PROT_READ | PROT_WRITE) =3D=3D -1)= { > + error_report("error: mprotect(from): %s", strerror(errno)); > + abort(); > + } > + if (mprotect(to, getpagesize(), PROT_READ) =3D=3D -1) { > + error_report("error: mprotect(to): %s", strerror(errno)); > + abort(); > + } > +} > + > +#include "hypertrace/emit.c" > + > +static void segv_handler(int signum, siginfo_t *siginfo, void *sigctxt) > +{ > + if (qemu_control_0 <=3D siginfo->si_addr && > + siginfo->si_addr < qemu_control_1) { > + > + /* 1st fault (guest will write cmd) */ > + assert(((unsigned long)siginfo->si_addr % getpagesize()) =3D=3D = sizeof(uint64_t)); > + swap_control(qemu_control_0, qemu_control_1); > + > + } else if (qemu_control_1 <=3D siginfo->si_addr && > + siginfo->si_addr < qemu_control_1 + getpagesize()) { > + uint64_t vcontrol =3D ((uint64_t*)qemu_control_0)[2]; > + uint64_t *data_ptr =3D &qemu_data[vcontrol * CONFIG_HYPERTRACE_A= RGS * sizeof(uint64_t)]; > + > + /* 2nd fault (invoke) */ > + assert(((unsigned long)siginfo->si_addr % getpagesize()) =3D=3D = sizeof(uint64_t)); > + hypertrace_emit(current_cpu, data_ptr); > + swap_control(qemu_control_1, qemu_control_0); > + > + } else { > + /* proxy to next handler */ > + if (segv_next.sa_sigaction !=3D NULL) { > + segv_next.sa_sigaction(signum, siginfo, sigctxt); > + } else if (segv_next.sa_handler !=3D NULL) { > + segv_next.sa_handler(signum); > + } > + } > +} Can this approach be made thread-safe? If not then it would be good to consider the problem right away and switch to something that is thread-safe, even if it depends on the target architecture. --t0UkRYy7tHLRMCai Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJXtYs8AAoJEJykq7OBq3PIY8AH/2uTapuV0j5dAPYrD3p/3F2H E3qFctYqQrwIZUuqPurfr8XC7d358fEKx3j2iusYtElX3XefXUyXGJbUPwsHw+si B4hAZv7QaJRITuCyRP8rO80clxGpjFYOEDPD8yVh0tytk5xojLfY/NfVTxWr/Z69 u9qOVA9IY+OoG+QxdjanDG0YV7D43CVB38MKKoSY5if42n3DDaSpp+KFc0H4st4H IsqLRpvxa6otMRzb6NjzR/2hlqMWmeEYhh+H69UXvg5LsPyWmGkUKutKyib9qcFP uHT/6Sx/4DiKf4N51B/DfxsHYrYZerl+WSG2qwPHXqEk7ueU2abYGOQ++LirGP8= =AZJa -----END PGP SIGNATURE----- --t0UkRYy7tHLRMCai--