From patchwork Wed Sep 13 09:53:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Llu=C3=ADs_Vilanova?= X-Patchwork-Id: 813272 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xscW0326cz9s76 for ; Wed, 13 Sep 2017 19:56:12 +1000 (AEST) Received: from localhost ([::1]:41283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ds4Ow-0006Iv-Ka for incoming@patchwork.ozlabs.org; Wed, 13 Sep 2017 05:56:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59720) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ds4Mo-0004pa-4q for qemu-devel@nongnu.org; Wed, 13 Sep 2017 05:53:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ds4Mj-0002FT-0R for qemu-devel@nongnu.org; Wed, 13 Sep 2017 05:53:58 -0400 Received: from roura.ac.upc.es ([147.83.33.10]:56147) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ds4Mi-0002F1-G0 for qemu-devel@nongnu.org; Wed, 13 Sep 2017 05:53:52 -0400 Received: from correu-1.ac.upc.es (correu-1.ac.upc.es [147.83.30.91]) by roura.ac.upc.es (8.13.8/8.13.8) with ESMTP id v8D9rnEa007565; Wed, 13 Sep 2017 11:53:49 +0200 Received: from localhost (unknown [132.68.137.204]) by correu-1.ac.upc.es (Postfix) with ESMTPSA id 4F14013E; Wed, 13 Sep 2017 11:53:44 +0200 (CEST) From: =?utf-8?b?TGx1w61z?= Vilanova To: qemu-devel@nongnu.org Date: Wed, 13 Sep 2017 12:53:43 +0300 Message-Id: <150529642278.10902.18234057937634437857.stgit@frigg.lan> X-Mailer: git-send-email 2.14.1 User-Agent: StGit/0.18 MIME-Version: 1.0 X-MIME-Autoconverted: from 8bit to quoted-printable by roura.ac.upc.es id v8D9rnEa007565 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x [fuzzy] X-Received-From: 147.83.33.10 Subject: [Qemu-devel] [PATCH v6 00/22] instrument: Add basic event instrumentation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Emilio G. Cota" , Markus Armbruster , Stefan Hajnoczi Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This series adds an API to add instrumentation events. It also provides additional APIs for: * Controlling tracing events. * Peek/poke guest memory. TODO: * Replace qi_event_gen_* with generating calls to arbitrary functions (e.g., qi_event_gen_call(num_args, va_list)). * Flush all TBs when an execution-time event is unset (to ensure it won't be called in the future). * Flush all TBs when a translation-time event is set (to ensure no future events will be lost). Undecided: * Alternatively to the two last points above, provide an API to request a TB flush (much more flexible and can be more efficient, but requires instrumentor to clearly know differences between translation and execution). * Pass a user-provided pointer to events (i.e., to avoid using global variables). * Provide something like tracing's per-vCPU trace states (i.e., so that each vCPU can have different instrumentation code). Useful mainly for sampling (enable/disable instrumentation multiple times without re-translating guest code) and more complex use cases like tracing a guest process in softmmu mode. It's still not clear to me if we should extend the per-vCPU bitmap with instrumentation events, or otherwise somehow reuse the bits in tracing events (since they're currently limited). * Allow multiple callbacks per event (both to support multiple callbacks installed by a library, and multiple libraries at the same time). * Allow instr libraries to iterate on the list of guest CPUs (info is already available through guest_cpu_enter/guest_cpu_exit, but forces libs to be prepared for hot-plugging guest CPUs). Future APIs (for later series): * Peek/poke guest registers. * Add breakpoints to trigger instrumentation functions. * Trigger instrumentation functions from guest code (former hypertrace). * Add events for guest code translation/execution (once the respective tracing events are accepted upstream). * Add events for exceptions/syscalls. * Add events for TB invalidation (necessary for libraries to deallocate any data they might have allocated for the TBs they instrumented). The instrumentation code is dynamically loaded as a library into QEMU either when it starts or later using its remote control interfaces. The loaded code only has access to function explicitly exported through the QI_VPUBLIC macro. This series is branch 'devel-instrument' in https://code.gso.ac.upc.edu/git/qemu-dbi. Signed-off-by: Lluís Vilanova --- Changes in v6 ============= * Fix a minor style warning. * Fix a minor compilation error. Changes in v5 ============= * Rebase on fcea73709b. * Minor changes to pass checkpatch. * Fix symbol availability to external libraries by adding missing default symbol visibility flag. * Use a string to identify instrumentation handles [Markus Armbruster]. * Use stubs for command line initialization. * Use stubs to signal unsupported QAPI commands [Markus Armbruster]. * Use error messages instead of codes in QAPI commands [Markus Armbruster]. * Move symbol visibility macros to internal "qemu/compiler.h" header. * Trigger event 'guest_cpu_enter' when library is loaded. * Trigger event 'guest_cpu_exit' and flush TBs when library is unloaded. * Rename instr_cpu_get/instr_cpu_set into clearer instr_cpu_to_qicpu/instr_cpu_from_qicpu. * Rename handle_get/handle_put to clearer handle_new/handle_destroy. * Ensure qi_event_set_* are called only on the proper mode and targets. Changes in v4 ============= * Add missing stub function. Changes in v3 ============= * Use a separate event set for instrumentation (i.e., do not instrument tracing events) [Stefan Hajnoczi]. * Add API for peek/poke guest memory. Changes in v2 ============= * Update QEMU version in QAPI [Eric Blake]. * Clarify 'msg' result in QAPI is for humans only. * Make 'msg' and 'handle' results optional in QAPI. * Use a list of 'str' in 'instr-load' QAPI command. * Update MAINTAINERS. * Add macros for error-reporting in API. Lluís Vilanova (22): instrument: Add documentation instrument: Add configure-time flag instrument: Add generic library loader instrument: [linux-user] Add command line library loader instrument: [bsd-user] Add command line library loader instrument: [softmmu] Add command line library loader instrument: [qapi] Add library loader instrument: [hmp] Add library loader instrument: Add basic control interface instrument: Add support for tracing events instrument: Track vCPUs instrument: Add event 'guest_cpu_enter' instrument: Support synchronous modification of vCPU state exec: Add function to synchronously flush TB on a stopped vCPU instrument: Add event 'guest_cpu_exit' instrument: Add event 'guest_cpu_reset' trace: Introduce a proper structure to describe memory accesses instrument: Add event 'guest_mem_before_trans' instrument: Add event 'guest_mem_before_exec' instrument: Add event 'guest_user_syscall' instrument: Add event 'guest_user_syscall_ret' instrument: Add API to manipulate guest memory .gitignore | 1 MAINTAINERS | 8 + Makefile | 8 + Makefile.objs | 4 + Makefile.target | 1 accel/stubs/tcg-stub.c | 3 accel/tcg/translate-all.c | 7 + bsd-user/main.c | 17 ++ bsd-user/syscall.c | 14 ++ configure | 13 ++ cpus-common.c | 9 + docs/instrument.txt | 173 ++++++++++++++++++++++ hmp-commands.hx | 32 ++++ include/exec/cpu_ldst_template.h | 19 +- include/exec/cpu_ldst_useronly_template.h | 19 +- include/exec/exec-all.h | 1 include/exec/helper-gen.h | 1 include/exec/helper-proto.h | 1 include/exec/helper-tcg.h | 1 include/qemu/compiler.h | 19 ++ instrument/Makefile.objs | 8 + instrument/cmdline.c | 128 ++++++++++++++++ instrument/cmdline.h | 51 ++++++ instrument/control.c | 228 +++++++++++++++++++++++++++++ instrument/control.h | 153 +++++++++++++++++++ instrument/control.inc.h | 67 +++++++++ instrument/error.h | 34 ++++ instrument/events.h | 86 +++++++++++ instrument/events.inc.h | 109 ++++++++++++++ instrument/helpers.h | 2 instrument/load.c | 210 +++++++++++++++++++++++++++ instrument/load.h | 88 +++++++++++ instrument/qemu-instr/control.h | 177 +++++++++++++++++++++++ instrument/qemu-instr/state.h | 104 +++++++++++++ instrument/qemu-instr/types.h | 115 +++++++++++++++ instrument/qemu-instr/types.inc.h | 15 ++ instrument/qmp.c | 82 ++++++++++ instrument/state.c | 73 +++++++++ instrument/trace.c | 125 ++++++++++++++++ linux-user/main.c | 21 +++ linux-user/syscall.c | 7 + monitor.c | 43 +++++ qapi-schema.json | 3 qapi/instrument.json | 49 ++++++ qemu-options.hx | 19 ++ qom/cpu.c | 2 stubs/Makefile.objs | 1 stubs/instrument.c | 73 +++++++++ tcg/tcg-op.c | 27 ++- trace/control-target.c | 2 trace/control.c | 4 - trace/control.h | 24 +++ trace/mem-internal.h | 22 ++- trace/mem.h | 8 + vl.c | 15 ++ 55 files changed, 2486 insertions(+), 40 deletions(-) create mode 100644 docs/instrument.txt create mode 100644 instrument/Makefile.objs create mode 100644 instrument/cmdline.c create mode 100644 instrument/cmdline.h create mode 100644 instrument/control.c create mode 100644 instrument/control.h create mode 100644 instrument/control.inc.h create mode 100644 instrument/error.h create mode 100644 instrument/events.h create mode 100644 instrument/events.inc.h create mode 100644 instrument/helpers.h create mode 100644 instrument/load.c create mode 100644 instrument/load.h create mode 100644 instrument/qemu-instr/control.h create mode 100644 instrument/qemu-instr/state.h create mode 100644 instrument/qemu-instr/types.h create mode 100644 instrument/qemu-instr/types.inc.h create mode 100644 instrument/qmp.c create mode 100644 instrument/state.c create mode 100644 instrument/trace.c create mode 100644 qapi/instrument.json create mode 100644 stubs/instrument.c To: qemu-devel@nongnu.org Cc: Stefan Hajnoczi Cc: Emilio G. Cota Cc: Eric Blake Cc: Markus Armbruster