instrument: Add basic event instrumentation
v4 cover instrument: Add basic event instrumentation
This series adds an API to add instrumentation events.
It also provides additional APIs for:
* Controlling tracing events
* Peek/poke guest memory
There's still missing APIs for (can be added in later series?):
* Provide something like tracing's per-vCPU trace states (i.e., so that each vCPU can have different instrumentation code). 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).
* Peek/poke guest registers
The instrumentation code is dynamically loaded as a library into QEMU either when it starts or later using its remote control interfaces.
---
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 (20):
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: 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 | 7 + Makefile | 8 + Makefile.objs | 4 + Makefile.target | 1 bsd-user/main.c | 15 ++ bsd-user/syscall.c | 11 ++ configure | 12 ++ cpus-common.c | 9 + docs/instrument.txt | 174 ++++++++++++++++++++++++++ hmp-commands.hx | 28 ++++ include/exec/cpu_ldst_template.h | 19 +-- include/exec/cpu_ldst_useronly_template.h | 19 +-- include/exec/helper-gen.h | 1 include/exec/helper-proto.h | 1 include/exec/helper-tcg.h | 1 instrument/Makefile.objs | 9 + instrument/cmdline.c | 124 ++++++++++++++++++ instrument/cmdline.h | 49 +++++++ instrument/control.c | 148 ++++++++++++++++++++++ instrument/control.h | 123 ++++++++++++++++++ instrument/control.inc.h | 56 ++++++++ instrument/error.h | 34 +++++ instrument/events.h | 86 +++++++++++++ instrument/events.inc.h | 108 ++++++++++++++++ instrument/helpers.h | 1 instrument/load.c | 196 +++++++++++++++++++++++++++++ instrument/load.h | 87 +++++++++++++ instrument/qemu-instr/control.h | 169 +++++++++++++++++++++++++ instrument/qemu-instr/state.h | 104 +++++++++++++++ instrument/qemu-instr/types.h | 115 +++++++++++++++++ instrument/qemu-instr/types.inc.h | 15 ++ instrument/qemu-instr/visibility.h | 58 +++++++++ instrument/qmp.c | 88 +++++++++++++ instrument/state.c | 72 +++++++++++ instrument/trace.c | 125 ++++++++++++++++++ linux-user/main.c | 19 +++ linux-user/syscall.c | 6 + monitor.c | 60 +++++++++ qapi-schema.json | 3 qapi/instrument.json | 96 ++++++++++++++ qemu-options.hx | 19 +++ qom/cpu.c | 2 stubs/Makefile.objs | 1 stubs/instrument.c | 25 ++++ 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 ++ 52 files changed, 2371 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/qemu-instr/visibility.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: [email protected]
Cc: Stefan Hajnoczi <[email protected]>
Cc: Emilio G. Cota <[email protected]>
Cc: Eric Blake <[email protected]>
PATCH v4 1/20 instrument: Add documentation
--- MAINTAINERS | 6 ++ docs/instrument.txt | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 docs/instrument.txt
MAINTAINERS +6 -0
@@ -1480,6 +1480,12 @@ F: scripts/tracetool/ F: docs/tracing.txt T: git git://github.com/stefanha/qemu.git tracing +Event instrumentation +M: Lluís Vilanova <[email protected]> +M: Stefan Hajnoczi <[email protected]> +S: Maintained +F: docs/instrument.txt + Checkpatch S: Odd Fixes F: scripts/checkpatch.pl
docs/instrument.txt new file +174 -0
174 lines not on this page · raw message
PATCH v4 2/20 instrument: Add configure-time flag
In reply to Lluís Vilanova--- configure | 9 +++++++++ 1 file changed, 9 insertions(+)
configure +9 -0
@@ -352,6 +352,7 @@ pie="" qom_cast_debug="yes" trace_backends="log" trace_file="trace" +instrument="no" spice="" rbd="" smartcard=""
@@ -891,6 +892,8 @@ for opt do ;; --with-trace-file=*) trace_file="$optarg" ;; + --enable-instrument) instrument="yes" + ;; --enable-gprof) gprof="yes" ;; --enable-gcov) gcov="yes"
@@ -1441,6 +1444,7 @@ Advanced options (experts only): Available backends: $trace_backend_list --with-trace-file=NAME Full PATH,NAME of file to store traces Default:trace-<pid> + --enable-instrument enable event instrumentation --disable-slirp disable SLIRP userspace network connectivity --enable-tcg-interpreter enable TCG with bytecode interpreter (TCI) --oss-lib path to OSS library
@@ -5371,6 +5375,7 @@ echo "Trace backends $trace_backends" if have_backend "simple"; then echo "Trace output file $trace_file-<pid>" fi +echo "instrumentation $instrument" echo "spice support $spice $(echo_version $spice $spice_protocol_version/$spice_server_version)" echo "rbd support $rbd" echo "xfsctl support $xfs"
@@ -6028,6 +6033,10 @@ if have_backend "syslog"; then fi echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak +if test "$instrument" = "yes"; then + echo "CONFIG_INSTRUMENT=y" >> $config_host_mak +fi + if test "$rdma" = "yes" ; then echo "CONFIG_RDMA=y" >> $config_host_mak fi
PATCH v4 3/20 instrument: Add generic library loader
In reply to Lluís Vilanova--- MAINTAINERS | 1 Makefile.objs | 4 + configure | 2 + instrument/Makefile.objs | 4 + instrument/cmdline.c | 124 ++++++++++++++++++++++++++++++++ instrument/cmdline.h | 49 +++++++++++++ instrument/load.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++ instrument/load.h | 83 ++++++++++++++++++++++ 8 files changed, 443 insertions(+) create mode 100644 instrument/Makefile.objs create mode 100644 instrument/cmdline.c create mode 100644 instrument/cmdline.h create mode 100644 instrument/load.c create mode 100644 instrument/load.h
MAINTAINERS +1 -0
@@ -1485,6 +1485,7 @@ M: Lluís Vilanova <[email protected]> M: Stefan Hajnoczi <[email protected]> S: Maintained F: docs/instrument.txt +F: instrument/ Checkpatch S: Odd Fixes
Makefile.objs +4 -0
@@ -97,6 +97,10 @@ version-obj-$(CONFIG_WIN32) += $(BUILD_DIR)/version.o util-obj-y += trace/ target-obj-y += trace/ +###################################################################### +# instrument +target-obj-y += instrument/ + ###################################################################### # guest agent
configure +2 -0
@@ -6034,6 +6034,8 @@ fi echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak if test "$instrument" = "yes"; then + LDFLAGS="-rdynamic $LDFLAGS" # limit symbols available to clients + LIBS="-ldl $LIBS" echo "CONFIG_INSTRUMENT=y" >> $config_host_mak fi
instrument/Makefile.objs new file +4 -0
@@ -0,0 +1,4 @@ +# -*- mode: makefile -*- + +target-obj-y += cmdline.o +target-obj-$(CONFIG_INSTRUMENT) += load.o
instrument/cmdline.c new file +124 -0
124 lines not on this page · raw message
instrument/cmdline.h new file +49 -0
49 lines not on this page · raw message
instrument/load.c new file +176 -0
176 lines not on this page · raw message
instrument/load.h new file +83 -0
83 lines not on this page · raw message
Re: [Qemu-devel] [PATCH v4 03/20] instrument: Add generic library loader
Quoted 2 lines · Lluís Vilanova
Signed-off-by Lluís Vilanova <[email protected]>---
(snip)
configure fi · line 6037
Quoted 9 lines
configure +1
-0@@ -6034,6 +6034,8 @@ fi echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak if test "$instrument" = "yes"; then + LDFLAGS="-rdynamic $LDFLAGS" # limit symbols available to clients
-rdynamic exports all objects to the instrumenters, not the other way around. You can see it with nm(1).
BTW I'm using ebf447b5b from your qemu-dbi repo. Is that the same as this patchset? It doesn't compile with --enable-instrument:
$ make CC x86_64-linux-user/instrument/trace.o /data/src/qemu2/instrument/trace.c:12:30: fatal error: qemu-instr/trace.h: No such file or directory compilation terminated. /data/src/qemu2/rules.mak:66: recipe for target 'instrument/trace.o' failed make[1]: *** [instrument/trace.o] Error 1 Makefile:326: recipe for target 'subdir-x86_64-linux-user' failed make: *** [subdir-x86_64-linux-user] Error 2
Emilio
Re: [Qemu-devel] [PATCH v4 03/20] instrument: Add generic library loader
Quoted 11 lines · Emilio G Cota
Quoted 2 lines · Lluís Vilanova
Signed-off-by Lluís Vilanova <[email protected]>---
(snip)
Quoted 7 lines
configure +0
-0@@ -6034,6 +6034,8 @@ fiecho "
CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
Quoted 5 lines
Quoted 2 lines
if test "$instrument" = "yes"; then
+ LDFLAGS="-rdynamic $LDFLAGS" # limit symbols available to clients-rdynamic exports all objects to the instrumenters, not the other way around. You can see it with nm(1).
I'll send a minor fix for this in next version.
Quoted 10 lines
BTW I'm using
ebf447b5bfrom your qemu-dbi repo. Is that the same as this patchset? It doesn't compile with --enable-instrument:$ make CC x86_64-linux-user/instrument/trace.o /data/src/qemu2/instrument/trace.c:12:30: fatal error: qemu-instr/trace.h: No such file or directory compilation terminated. /data/src/qemu2/rules.mak:66: recipe for target 'instrument/trace.o' failed make[1]: *** [instrument/trace.o] Error 1 Makefile:326: recipe for target 'subdir-x86_64-linux-user' failed make: *** [subdir-x86_64-linux-user] Error 2
No, I started using a separate branch to keep the old patches around in the meantime.
Quoted 1 line
Emilio
Lluis
PATCH v4 4/20 instrument: [linux-user] Add command line library loader
In reply to Lluís Vilanova--- linux-user/main.c | 19 +++++++++++++++++++ linux-user/syscall.c | 4 ++++ 2 files changed, 23 insertions(+)
linux-user/main.c +19 -0
@@ -36,6 +36,7 @@#include "exec/log.h" #include "trace/control.h" #include "glib-compat.h" +#include "instrument/cmdline.h" char *exec_path;
@@ -4017,6 +4018,17 @@ static void handle_arg_trace(const char *arg) trace_file =trace_opt_parse (arg); } +static char *instrument_path; +static int instrument_argc; +static const char **instrument_argv; +#if defined(CONFIG_INSTRUMENT ) +static void handle_arg_instrument (const char *arg) +{ +instr_opt_parse (arg, &instrument_path, + &instrument_argc, &instrument_argv); +} +#endif +struct qemu_argument {const char *argv;const char *env;
@@ -4066,6 +4078,10 @@ static const struct qemu_argument arg_table[] = { "", "Seed for pseudo-random number generator"}, {"trace", "QEMU_TRACE", true, handle_arg_trace, "", "[[enable=]<pattern>][,events=<file>][,file=<file>]"}, +#if defined(CONFIG_INSTRUMENT) + {"instr", "QEMU_INSTR", true, handle_arg_instrument, + "", "[file=]<file>[,arg=<string>]"}, +#endif {"version", "QEMU_VERSION", false, handle_arg_version, "", "display version information and exit"}, {NULL, NULL, false, NULL, NULL, NULL}
@@ -4257,6 +4273,7 @@ int main(int argc, char **argv, char **envp)srand (time (NULL ));qemu_add_opts (&qemu_trace_opts); +qemu_add_opts (&qemu_instr_opts); optind =parse_args (argc, argv);
@@ -4265,6 +4282,8 @@ int main(int argc, char **argv, char **envp) }trace_init_file (trace_file); +instr_init (instrument_path, instrument_argc, instrument_argv); +/* Zero out regs */ memset (regs,0 ,sizeof (struct target_pt_regs ));
linux-user/syscall.c +4 -0
@@ -115,6 +115,8 @@ int __clone2(int (*fn)(void *), void *child_stack_base,#include "uname.h" #include "qemu.h" +#include "instrument/cmdline.h" +#ifndef CLONE_IO #define CLONE_IO 0x80000000/* Clone io context */
@@ -7765,6 +7767,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,_mcleanup ();#endif gdb_exit (cpu_env, arg1); +instr_fini ();_exit (arg1); ret =0 ;/* avoid warning */ break ;
@@ -9821,6 +9824,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,_mcleanup ();#endif gdb_exit (cpu_env, arg1); +instr_fini (); ret =get_errno (exit_group (arg1));break ;#endif
PATCH v4 5/20 instrument: [bsd-user] Add command line library loader
In reply to Lluís Vilanova--- bsd-user/main.c | 15 +++++++++++++++ bsd-user/syscall.c | 5 +++++ 2 files changed, 20 insertions(+)
bsd-user/main.c +15 -0
@@ -33,6 +33,7 @@#include "exec/log.h" #include "trace/control.h" #include "glib-compat.h" +#include "instrument/cmdline.h" int singlestep;unsigned long mmap_min_addr;
@@ -667,6 +668,11 @@ static void usage(void)"-B address set guest_base address to address\n" "-bsd type select emulated BSD type FreeBSD/NetBSD/OpenBSD (default)\n" "\n" +#if defined(CONFIG_INSTRUMENT ) +"-instr [file=]<file>[,arg=<string>]\n" +" load an instrumentation library\n" + "\n" +#endif "Debug options:\n" "-d item1[,...] enable logging of specified items\n" " (use '-d help' for a list of log items)\n"
@@ -738,6 +744,9 @@ int main(int argc, char **argv)envlist_t *envlist =NULL ;char *trace_file =NULL ; bsd_type = target_openbsd; +char *instrument_path =NULL ; +int instrument_argc =0 ; +const char **instrument_argv =NULL ;if (argc <=1 )usage ();
@@ -756,6 +765,7 @@ int main(int argc, char **argv) cpu_model =NULL ;qemu_add_opts (&qemu_trace_opts); +qemu_add_opts (&qemu_instr_opts); optind =1 ;for (;;) {
@@ -843,6 +853,9 @@ int main(int argc, char **argv) }else if (!strcmp (r,"trace" )) {g_free (trace_file); trace_file =trace_opt_parse (optarg); + }else if (!strcmp (r,"instr" )) { +instr_opt_parse (optarg, &instrument_path, + &instrument_argc, &instrument_argv); }else {usage (); }
@@ -872,6 +885,8 @@ int main(int argc, char **argv) }trace_init_file (trace_file); +instr_init (instrument_path, instrument_argc, instrument_argv); +/* Zero out regs */ memset (regs,0 ,sizeof (struct target_pt_regs ));
bsd-user/syscall.c +5 -0
@@ -26,6 +26,8 @@#include "qemu.h" #include "qemu-common.h" +#include "instrument/cmdline.h" +//#define DEBUG
@@ -332,6 +334,7 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,_mcleanup ();#endif gdb_exit (cpu_env, arg1); +instr_fini ();/* XXX: should free thread stack and CPU env */ _exit (arg1); ret =0 ;/* avoid warning */
@@ -430,6 +433,7 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,_mcleanup ();#endif gdb_exit (cpu_env, arg1); +instr_fini ();/* XXX: should free thread stack and CPU env */ _exit (arg1); ret =0 ;/* avoid warning */
@@ -505,6 +509,7 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,_mcleanup ();#endif gdb_exit (cpu_env, arg1); +instr_fini ();/* XXX: should free thread stack and CPU env */ _exit (arg1); ret =0 ;/* avoid warning */
PATCH v4 6/20 instrument: [softmmu] Add command line library loader
In reply to Lluís Vilanova--- qemu-options.hx | 19 +++++++++++++++++++ vl.c | 15 +++++++++++++++ 2 files changed, 34 insertions(+)
qemu-options.hx +19 -0
@@ -4077,6 +4077,25 @@ HXCOMM HX does not support conditional compilation of text. @findex -trace @include qemu-option-trace.texi ETEXI +#if defined(CONFIG_INSTRUMENT) +DEF("instr", HAS_ARG, QEMU_OPTION_instr, + "-instr [file=]<file>[,arg=<string>]\n" + " load an instrumentation library\n", + QEMU_ARCH_ALL) +#endif +STEXI +@item -instr file=@var{file}[,arg=@var{string}] +@findex -instr + +Load a dynamic trace instrumentation library. + +@table @option +@item file=@var{file} +Load the given dynamic trace instrumentation library. +@item arg=@var{string} +String argument passed as to the library's @code{qi_init} routine (can be given multiple times). +@end table +ETEXI HXCOMM Internal use DEF("qtest", HAS_ARG, QEMU_OPTION_qtest, "", QEMU_ARCH_ALL)
vl.c +15 -0
@@ -118,6 +118,7 @@ int main(int argc, char **argv)#include "trace-root.h" #include "trace/control.h" +#include "instrument/cmdline.h" #include "qemu/queue.h" #include "sysemu/arch_init.h"
@@ -3035,6 +3036,9 @@ int main(int argc, char **argv, char **envp) } BlockdevOptions_queue; QSIMPLEQ_HEAD(, BlockdevOptions_queue) bdo_queue =QSIMPLEQ_HEAD_INITIALIZER (bdo_queue); +char *instrument_path =NULL ; +int instrument_argc =0 ; +const char **instrument_argv =NULL ;module_call_init (MODULE_INIT_TRACE );
@@ -3062,6 +3066,9 @@ int main(int argc, char **argv, char **envp)qemu_add_opts (&qemu_global_opts);qemu_add_opts (&qemu_mon_opts);qemu_add_opts (&qemu_trace_opts); +#if defined(CONFIG_INSTRUMENT ) +qemu_add_opts (&qemu_instr_opts); +#endif qemu_add_opts (&qemu_option_rom_opts);qemu_add_opts (&qemu_machine_opts);qemu_add_opts (&qemu_accel_opts);
@@ -4003,6 +4010,12 @@ int main(int argc, char **argv, char **envp)g_free (trace_file); trace_file =trace_opt_parse (optarg);break ; +#if defined(CONFIG_INSTRUMENT ) +case QEMU_OPTION_instr: +instr_opt_parse (optarg, &instrument_path, + &instrument_argc, &instrument_argv); +break ; +#endif case QEMU_OPTION_readconfig: {int ret =qemu_read_config_file (optarg);
@@ -4190,6 +4203,8 @@ int main(int argc, char **argv, char **envp) }trace_init_file (trace_file); +instr_init (instrument_path, instrument_argc, instrument_argv); +/* Open the logfile at this point and set the log mask if necessary. */ if (log_file) {
PATCH v4 7/20 instrument: [qapi] Add library loader
In reply to Lluís Vilanova--- instrument/Makefile.objs | 1 instrument/load.h | 4 ++ instrument/qmp.c | 88 ++++++++++++++++++++++++++++++++++++++++++ qapi-schema.json | 3 + qapi/instrument.json | 96 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 192 insertions(+) create mode 100644 instrument/qmp.c create mode 100644 qapi/instrument.json
instrument/Makefile.objs +1 -0
@@ -2,3 +2,4 @@ target-obj-y += cmdline.o target-obj-$(CONFIG_INSTRUMENT) += load.o +target-obj-y += qmp.o
instrument/load.h +4 -0
@@ -25,6 +25,8 @@* @INSTR_LOAD_DLERROR: Error with libdl (see dlerror). * * Error codes for instr_load(). +* +* NOTE: Keep in sync with QAPI's #InstrLoadCode. */ typedef enum { INSTR_LOAD_OK,
@@ -40,6 +42,8 @@ typedef enum {* @INSTR_UNLOAD_DLERROR: Error with libdl (see dlerror). * * Error codes for instr_unload(). +* +* NOTE: Keep in sync with QAPI's #InstrUnloadCode. */ typedef enum { INSTR_UNLOAD_OK,
instrument/qmp.c new file +88 -0
88 lines not on this page · raw message
qapi-schema.json +3 -0
@@ -90,6 +90,9 @@ # QAPI introspection { 'include': 'qapi/introspect.json' } +# Instrumentation commands +{ 'include': 'qapi/instrument.json' } + ## # = QMP commands ##
qapi/instrument.json new file +96 -0
96 lines not on this page · raw message
Re: [Qemu-devel] [PATCH v4 07/20] instrument: [qapi] Add library loader
I missed prior versions of this series. Please cc: qapi-schema maintainers on all non-trivial schema patches. scripts/get_maintainer.pl points to them for this patch.
Marc-André, semantic conflict with your QAPI conditionals series. Just a heads-up, there's nothing for you to do about it right now.
Quoted 10 lines · Lluís Vilanova
Signed-off-by Lluís Vilanova <[email protected]>--- instrument/Makefile.objs | 1 instrument/load.h | 4 ++ instrument/qmp.c | 88 ++++++++++++++++++++++++++++++++++++++++++ qapi-schema.json | 3 + qapi/instrument.json | 96 ++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 192 insertions(+) create mode 100644 instrument/qmp.c create mode 100644 qapi/instrument.json
Missing: update of MAINTAINERS for qapi/instrument.json.
Quoted 23 lines
instrument/Makefile.objs +1
-0@@ -2,3 +2,4 @@ target-obj-y += cmdline.o target-obj-$(CONFIG_INSTRUMENT) += load.o +target-obj-y += qmp.oinstrument/load.h +2
-0@@ -25,6 +25,8 @@* @INSTR_LOAD_DLERROR: Error with libdl (see dlerror). * * Error codes for instr_load(). +* +* NOTE: Keep in sync with QAPI's #InstrLoadCode. */ typedef enum { INSTR_LOAD_OK,
instrument/load.h typedef enum { · line 49
Quoted 8 lines
instrument/load.h +2
-0@@ -40,6 +42,8 @@ typedef enum {* @INSTR_UNLOAD_DLERROR: Error with libdl (see dlerror). * * Error codes for instr_unload(). +* +* NOTE: Keep in sync with QAPI's #InstrUnloadCode. */ typedef enum { INSTR_UNLOAD_OK,
Any particular reason why you can't simply use the QAPI-generated enum types?
Quoted 11 lines
instrument/qmp.c new file +5
-0@@ -0,0 +1,88 @@ +/* +* QMP interface for instrumentation control commands. +* +* Copyright (C) 2012-2017 Lluís Vilanova <[email protected]> +*
instrument/qmp.c line 15
Quoted 10 lines
instrument/qmp.c new file +10
-0+* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qapi/qmp/qerror.h" +#include "qmp-commands.h" + +#include <dlfcn.h>
System headers go right after "qemu/osdep.h".
instrument/qmp.c line 20
Quoted 5 lines
instrument/qmp.c new file +5
-0+ +#include "instrument/load.h" + + +
Fewer blank lines would do.
instrument/qmp.c line 22
Quoted 2 lines
instrument/qmp.c new file +2
-0+InstrLoadResult *qmp_instr_load(const char * path, + bool have_args, strList * args,
checkpatch ERROR: "foo * bar" should be "foo *bar"
Please feed it all your patches, and carefully consider which of its complaints you should address.
Quoted 56 lines
instrument/qmp.c new file +56
-0+ Error **errp) +{ +InstrLoadResult *res =g_malloc0 (sizeof (*res)); + +#if defined(CONFIG_INSTRUMENT ) +int argc =0 ; +const char **argv =NULL ; + +strList *entry = have_args ? args :NULL ; +while (entry !=NULL ) { + argv =realloc (argv,sizeof (*argv) * (argc +1 )); + argv[argc] = entry->value; + argc++; + entry = entry->next; + } + +InstrLoadError code =instr_load (path, argc, argv, &res->handle); +switch (code) { +case INSTR_LOAD_OK : + res->code =INSTR_LOAD_CODE_OK ; + res->has_handle = true; +break ; +case INSTR_LOAD_TOO_MANY : + res->code =INSTR_LOAD_CODE_TOO_MANY ; +break ; +case INSTR_LOAD_ERROR : + res->code =INSTR_LOAD_CODE_ERROR ; +break ; +case INSTR_LOAD_DLERROR : + res->has_msg = true; + res->msg =dlerror (); + res->code =INSTR_LOAD_CODE_DLERROR ; +break ; + } +#else + res->code =INSTR_LOAD_CODE_UNAVAILABLE ; +#endif + +return res; +} + +InstrUnloadResult *qmp_instr_unload (int64_t handle,Error **errp) +{ +InstrUnloadResult *res =g_malloc0 (sizeof (*res)); + +#if defined(CONFIG_INSTRUMENT ) +InstrUnloadError code =instr_unload (handle); +switch (code) { +case INSTR_UNLOAD_OK : + res->code =INSTR_UNLOAD_CODE_OK ; +break ; +case INSTR_UNLOAD_INVALID : + res->code =INSTR_UNLOAD_CODE_INVALID ; +break ; +case INSTR_UNLOAD_DLERROR : + res->has_msg = true;
instrument/qmp.c line 88
Quoted 10 lines
instrument/qmp.c new file +10
-0+ res->msg =dlerror (); +break ; + res->code = INSTR_UNLOAD_CODE_DLERROR; + } +#else + res->code =INSTR_UNLOAD_CODE_UNAVAILABLE ; +#endif + +return res; +}
You're inventing your own "this feature isn't compiled in" protocol. We already got too many of them. Let's stick to one of the existing ones, namely the one that's got some visibility in introspection. Bonus:
turns the semantic conflict with Marc-André's work into a textual conflict. Here's how:
* Add your commands to qmp_unregister_commands_hack() in monitor.c, roughly like this:
#ifndef CONFIG_INSTRUMENT
qmp_unregister_command(&qmp_commands, "instr-load");
qmp_unregister_command(&qmp_commands, "instr-unload");
#endif* Compile qmp.c only when CONFIG_INSTRUMENT, just like the other .c files there, except for cmdline.c. Drop the ifdeffery there.
* Add stubbed out command handlers to stubs/instrument.c, roughly like this:
InstrLoadResult *qmp_instr_load(const char *path,
bool have_args, strList *args,
Error **errp)
{
error_setg(errp, QERR_UNSUPPORTED);
return NULL;
} Same for qmp_instr_unload().
These stubs must exist for the link to succeed, but they won't be called. They'll go away when Marc-André's work lands.
* In the next patch, make the HMP command conditional on CONFIG_INSTRUMENT, just like trace-file is conditional on CONFIG_TRACE_SIMPLE.
Questions?
You're also inventing your own "command failed" protocol. I'll explain in my review of instrument.json.
Quoted 20 lines
qapi-schema.json +3
-0@@ -90,6 +90,9 @@ # QAPI introspection { 'include': 'qapi/introspect.json' } +# Instrumentation commands +{ 'include': 'qapi/instrument.json' } + ## # = QMP commands ##qapi/instrument.json new file +0
-0
qapi/instrument.json line 8
Quoted 8 lines
qapi/instrument.json new file +8
-0@@ -0,0 +1,96 @@ +# *-*- Mode: Python -*-* +# +# QAPI instrumentation control commands. +# +# Copyright (C) 2012-2017 Lluís Vilanova <[email protected]> +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory.
Make the title a doc comment, like this:
# *-*- Mode: Python -*-*
#
# Copyright (C) 2012-2017 Lluís Vilanova <[email protected]> #
# This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory.
##
# QAPI instrumentation control commands.
##
The ## around the title make it go into generated
docs/interop/qemu-qmp-ref.* documentation.
Quoted 35 lines
qapi/instrument.json new file +35
-0+ +## +# @InstrLoadCode: +# +# Result code of an 'instr-load' command. +# +# @ok: Correctly loaded. +# @too-many: Tried to load too many instrumentation libraries. +# @error: The library's main() function returned a non-zero value. +# @dlerror: Error with libdl (see 'msg'). +# @unavailable: Service not available. +# +# Since: 2.11 +## +{ 'enum': 'InstrLoadCode', + 'data': [ 'ok', 'too-many', 'error', 'dlerror', 'unavailable' ] } + +## +# @InstrLoadResult: +# +# Result of an 'instr-load' command. +# +# @code: Result code. +# @msg: Additional error message (for human consumption only; present only in +# case of error). +# @handle: Instrumentation library identifier (present only if successful). +# +# Since: 2.11 +## +{ 'struct': 'InstrLoadResult', + 'data': { 'code': 'InstrLoadCode', '*msg': 'str', '*handle': 'int' } } + +## +# @instr-load: +#
qapi/instrument.json line 53
Quoted 10 lines
qapi/instrument.json new file +10
-0+# Load an instrumentation library. +# +# @path: path to the dynamic instrumentation library +# @args: arguments to the dynamic instrumentation library +# +# Since: 2.11 +## +{ 'command': 'instr-load', + 'data': { 'path': 'str', '*args': ['str'] }, + 'returns': 'InstrLoadResult' }
No :)
If the command fails, it must send an error response instead success response. Yours always sends a success response.
As far as I can tell, instr-load returns a handle on success, always, and nothing else. Therefore:
{ 'struct': 'InstrLoadResult',
'data': { 'handle': 'int' } }On error, qmp_instr_load() should set a suitable error with error_setg() and return NULL.
QAPI enum type InstrLoadCode goes away.
On returning a handle: we commonly let the user specify an ID string instead. For instance, device_add doesn't return a handle you can pass to device_del. Instead, it takes a string-valued 'id' parameter. Other commands, such as device_del, can refer to the device by that ID. Is there any particular reason why you can't stick to this convention for instrumentation?
Quoted 33 lines
qapi/instrument.json new file +33
-0+ + +## +# @InstrUnloadCode: +# +# Result code of an 'instr-unload' command. +# +# @ok: Correctly unloaded. +# @invalid: Invalid handle. +# @dlerror: Error with libdl (see 'msg'). +# @unavailable: Service not available. +# +# Since: 2.11 +## +{ 'enum': 'InstrUnloadCode', + 'data': [ 'ok', 'invalid', 'dlerror', 'unavailable' ] } + +## +# @InstrUnloadResult: +# +# Result of an 'instr-unload' command. +# +# @code: Result code. +# @msg: Additional error message (for human consumption only; present only in +# case of error). +# +# Since: 2.11 +## +{ 'struct': 'InstrUnloadResult', + 'data': { 'code': 'InstrUnloadCode', '*msg': 'str' } } + +## +# @instr-unload:
qapi/instrument.json line 96
Quoted 10 lines
qapi/instrument.json new file +10
-0+# +# Unload an instrumentation library. +# +# @handle: Instrumentation library identifier (see #InstrLoadResult). +# +# Since: 2.11 +## +{ 'command': 'instr-unload', + 'data': { 'handle': 'int' }, + 'returns': 'InstrUnloadResult' }
Likewise. instr-unload returns nothing on success. Both QAPI types go away.
Re: [Qemu-devel] [PATCH v4 07/20] instrument: [qapi] Add library loader
Quoted 8 lines · Markus Armbruster
I missed prior versions of this series. Please cc: qapi-schema maintainers on all non-trivial schema patches.
scripts/get_maintainer.plpoints to them for this patch.Marc-André, semantic conflict with your QAPI conditionals series. Just a heads-up, there's nothing for you to do about it right now.
Lluís Vilanova <[email protected]> writes:
[...]
Quoted 17 lines
Quoted 17 lines
instrument/load.h +2
-0@@ -25,6 +25,8 @@* @INSTR_LOAD_DLERROR: Error with libdl (see dlerror). * * Error codes for instr_load(). +* +* NOTE: Keep in sync with QAPI's #InstrLoadCode. */ typedef enum { INSTR_LOAD_OK,@@ -40,6 +42,8 @@ typedef enum {* @INSTR_UNLOAD_DLERROR: Error with libdl (see dlerror). * * Error codes for instr_unload().
Quoted 8 lines
instrument/load.h typedef enum { · line 49
Quoted 5 lines
instrument/load.h +2
-0+* +* NOTE: Keep in sync with QAPI's #InstrUnloadCode. */ typedef enum { INSTR_UNLOAD_OK,Any particular reason why you can't simply use the QAPI-generated enum types?
Silly me, just missed that "optimization" :) But after reading your later comments, I'll keep these and remove the QAPI-generated enums.
[...]
Quoted 137 lines
Quoted 11 lines
instrument/qmp.c new file +5
-0@@ -0,0 +1,88 @@ +/* +* QMP interface for instrumentation control commands. +* +* Copyright (C) 2012-2017 Lluís Vilanova <[email protected]> +* instrument/qmp.c line 15
Quoted 10 lines
instrument/qmp.c new file +10
-0+* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qapi/qmp/qerror.h" +#include "qmp-commands.h" + +#include <dlfcn.h> System headers go right after "
qemu/osdep.h".instrument/qmp.c line 20
Quoted 5 lines
instrument/qmp.c new file +5
-0+ +#include "instrument/load.h" + + +Fewer blank lines would do.
instrument/qmp.c line 22
Quoted 2 lines
instrument/qmp.c new file +2
-0+InstrLoadResult *qmp_instr_load(const char * path, + bool have_args, strList * args,checkpatch ERROR: "foo * bar" should be "foo *bar"
Please feed it all your patches, and carefully consider which of its complaints you should address.
Quoted 56 lines
instrument/qmp.c new file +56
-0+ Error **errp) +{ +InstrLoadResult *res =g_malloc0 (sizeof (*res)); + +#if defined(CONFIG_INSTRUMENT ) +int argc =0 ; +const char **argv =NULL ; + +strList *entry = have_args ? args :NULL ; +while (entry !=NULL ) { + argv =realloc (argv,sizeof (*argv) * (argc +1 )); + argv[argc] = entry->value; + argc++; + entry = entry->next; + } + +InstrLoadError code =instr_load (path, argc, argv, &res->handle); +switch (code) { +case INSTR_LOAD_OK : + res->code =INSTR_LOAD_CODE_OK ; + res->has_handle = true; +break ; +case INSTR_LOAD_TOO_MANY : + res->code =INSTR_LOAD_CODE_TOO_MANY ; +break ; +case INSTR_LOAD_ERROR : + res->code =INSTR_LOAD_CODE_ERROR ; +break ; +case INSTR_LOAD_DLERROR : + res->has_msg = true; + res->msg =dlerror (); + res->code =INSTR_LOAD_CODE_DLERROR ; +break ; + } +#else + res->code =INSTR_LOAD_CODE_UNAVAILABLE ; +#endif + +return res; +} + +InstrUnloadResult *qmp_instr_unload (int64_t handle,Error **errp) +{ +InstrUnloadResult *res =g_malloc0 (sizeof (*res)); + +#if defined(CONFIG_INSTRUMENT ) +InstrUnloadError code =instr_unload (handle); +switch (code) { +case INSTR_UNLOAD_OK : + res->code =INSTR_UNLOAD_CODE_OK ; +break ; +case INSTR_UNLOAD_INVALID : + res->code =INSTR_UNLOAD_CODE_INVALID ; +break ; +case INSTR_UNLOAD_DLERROR : + res->has_msg = true;instrument/qmp.c line 88
Quoted 10 lines
instrument/qmp.c new file +10
-0+ res->msg =dlerror (); +break ; + res->code = INSTR_UNLOAD_CODE_DLERROR; + } +#else + res->code =INSTR_UNLOAD_CODE_UNAVAILABLE ; +#endif + +return res; +}You're inventing your own "this feature isn't compiled in" protocol. We already got too many of them. Let's stick to one of the existing ones, namely the one that's got some visibility in introspection. Bonus:
turns the semantic conflict with Marc-André's work into a textual conflict. Here's how:* Add your commands to
qmp_unregister_commands_hack()inmonitor.c, roughly like this:#ifndef CONFIG_INSTRUMENT qmp_unregister_command(&qmp_commands, "instr-load"); qmp_unregister_command(&qmp_commands, "instr-unload"); #endif* Compile
qmp.conly whenCONFIG_INSTRUMENT, just like the other .c files there, except forcmdline.c. Drop the ifdeffery there.* Add stubbed out command handlers to
stubs/instrument.c, roughly like this:InstrLoadResult *qmp_instr_load(const char *path, bool have_args, strList *args, Error **errp) { error_setg(errp, QERR_UNSUPPORTED); return NULL; }Same for
qmp_instr_unload().
Quoted 8 lines
These stubs must exist for the link to succeed, but they won't be called. They'll go away when Marc-André's work lands.
* In the next patch, make the HMP command conditional on
CONFIG_INSTRUMENT, just like trace-file is conditional onCONFIG_TRACE_SIMPLE.Questions?
Crystal clear, applied.
Quoted 108 lines
You're also inventing your own "command failed" protocol. I'll explain in my review of instrument.json.
Quoted 20 lines
qapi-schema.json +3
-0@@ -90,6 +90,9 @@ # QAPI introspection { 'include': 'qapi/introspect.json' } +# Instrumentation commands +{ 'include': 'qapi/instrument.json' } + ## # = QMP commands ##qapi/instrument.json new file +0
-0qapi/instrument.json line 8
Quoted 8 lines
qapi/instrument.json new file +8
-0@@ -0,0 +1,96 @@ +# *-*- Mode: Python -*-* +# +# QAPI instrumentation control commands. +# +# Copyright (C) 2012-2017 Lluís Vilanova <[email protected]> +# +# This work is licensed under the terms of the GNU GPL, version 2 or later. +# See the COPYING file in the top-level directory.Make the title a doc comment, like this:
# *-*- Mode: Python -*-* # # Copyright (C) 2012-2017 Lluís Vilanova <[email protected]> # # This work is licensed under the terms of the GNU GPL, version 2 or later. # See the COPYING file in the top-level directory. ## # QAPI instrumentation control commands. ##The ## around the title make it go into generated
docs/interop/qemu-qmp-ref.* documentation.Quoted 35 lines
qapi/instrument.json new file +35
-0+ +## +# @InstrLoadCode: +# +# Result code of an 'instr-load' command. +# +# @ok: Correctly loaded. +# @too-many: Tried to load too many instrumentation libraries. +# @error: The library's main() function returned a non-zero value. +# @dlerror: Error with libdl (see 'msg'). +# @unavailable: Service not available. +# +# Since: 2.11 +## +{ 'enum': 'InstrLoadCode', + 'data': [ 'ok', 'too-many', 'error', 'dlerror', 'unavailable' ] } + +## +# @InstrLoadResult: +# +# Result of an 'instr-load' command. +# +# @code: Result code. +# @msg: Additional error message (for human consumption only; present only in +# case of error). +# @handle: Instrumentation library identifier (present only if successful). +# +# Since: 2.11 +## +{ 'struct': 'InstrLoadResult', + 'data': { 'code': 'InstrLoadCode', '*msg': 'str', '*handle': 'int' } } + +## +# @instr-load: +#qapi/instrument.json line 53
Quoted 10 lines
qapi/instrument.json new file +10
-0+# Load an instrumentation library. +# +# @path: path to the dynamic instrumentation library +# @args: arguments to the dynamic instrumentation library +# +# Since: 2.11 +## +{ 'command': 'instr-load', + 'data': { 'path': 'str', '*args': ['str'] }, + 'returns': 'InstrLoadResult' }No :)
If the command fails, it must send an error response instead success response. Yours always sends a success response.
As far as I can tell, instr-load returns a handle on success, always, and nothing else. Therefore:
{ 'struct': 'InstrLoadResult',
'data': { 'handle': 'int' } }On error,
qmp_instr_load()should set a suitable error witherror_setg()and return NULL.
Quoted 8 lines
QAPI enum type InstrLoadCode goes away.
On returning a handle: we commonly let the user specify an ID string instead. For instance,
device_adddoesn't return a handle you can pass todevice_del. Instead, it takes a string-valued 'id' parameter. Other commands, such asdevice_del, can refer to the device by that ID. Is there any particular reason why you can't stick to this convention for instrumentation?
Done too :)
Quoted 38 lines
Quoted 38 lines
qapi/instrument.json new file +38
-0+ + +## +# @InstrUnloadCode: +# +# Result code of an 'instr-unload' command. +# +# @ok: Correctly unloaded. +# @invalid: Invalid handle. +# @dlerror: Error with libdl (see 'msg'). +# @unavailable: Service not available. +# +# Since: 2.11 +## +{ 'enum': 'InstrUnloadCode', + 'data': [ 'ok', 'invalid', 'dlerror', 'unavailable' ] } + +## +# @InstrUnloadResult: +# +# Result of an 'instr-unload' command. +# +# @code: Result code. +# @msg: Additional error message (for human consumption only; present only in +# case of error). +# +# Since: 2.11 +## +{ 'struct': 'InstrUnloadResult', + 'data': { 'code': 'InstrUnloadCode', '*msg': 'str' } } + +## +# @instr-unload: +# +# Unload an instrumentation library. +# +# @handle: Instrumentation library identifier (see #InstrLoadResult). +#
Quoted 8 lines
qapi/instrument.json line 96
Quoted 5 lines
qapi/instrument.json new file +5
-0+# Since: 2.11 +## +{ 'command': 'instr-unload', + 'data': { 'handle': 'int' }, + 'returns': 'InstrUnloadResult' }Likewise. instr-unload returns nothing on success. Both QAPI types go away.
Thanks a lot!
Lluis
PATCH v4 8/20 instrument: [hmp] Add library loader
In reply to Lluís Vilanova--- hmp-commands.hx | 28 ++++++++++++++++++++++++++ monitor.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+)
hmp-commands.hx +28 -0
@@ -1858,6 +1858,34 @@ ETEXI .sub_table = info_cmds, }, + { + .name = "instr-load", + .args_type = "path:F,args:s?", + .params = "path [arg]", + .help = "load an instrumentation library", + .cmd = hmp_instr_load, + }, + +STEXI +@item instr-load @var{path} [args=value[,...]] +@findex instr-load +Load an instrumentation library. +ETEXI + + { + .name = "instr-unload", + .args_type = "handle:i", + .params = "handle", + .help = "unload an instrumentation library", + .cmd = hmp_instr_unload, + }, + +STEXI +@item instr-unload +@findex instr-unload +Unload an instrumentation library. +ETEXI + STEXI @end table ETEXI
monitor.c +60 -0
66 lines not on this page · raw message
Re: [Qemu-devel] [PATCH v4 08/20] instrument: [hmp] Add library loader
Quoted 35 lines · Lluís Vilanova
Signed-off-by Lluís Vilanova <[email protected]>--- hmp-commands.hx | 28 ++++++++++++++++++++++++++ monitor.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+)hmp-commands.hx +21
-0@@ -1858,6 +1858,34 @@ ETEXI .sub_table = info_cmds, }, + { + .name = "instr-load", + .args_type = "path:F,args:s?", + .params = "path [arg]", + .help = "load an instrumentation library", + .cmd = hmp_instr_load, + }, + +STEXI +@item instr-load @var{path} [args=value[,...]] +@findex instr-load +Load an instrumentation library. +ETEXI + + { + .name = "instr-unload", + .args_type = "handle:i", + .params = "handle", + .help = "unload an instrumentation library", + .cmd = hmp_instr_unload, + },
hmp-commands.hx ETEXI · line 1891
Quoted 10 lines
hmp-commands.hx +7
-0+ +STEXI +@item instr-unload +@findex instr-unload +Unload an instrumentation library. +ETEXI + STEXI @end table ETEXI
Want #ifdef CONFIG_INSTRUMENT, see my review of the previous patch.
See also my remark there on returning handles vs. passing in IDs.
monitor.c int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp) · line 2326
Quoted 13 lines
monitor.c +5
-0@@ -2319,6 +2319,66 @@ int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp)return fd; } +static void hmp_instr_load (Monitor *mon,const QDict *qdict) +{ +const char *path =qdict_get_str (qdict,"path" ); +const char *str =qdict_get_try_str (qdict,"args" ); +strList args;
Blank line between last declaration and first statement, please.
monitor.c int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp) · line 2327
Quoted 1 line
monitor.c +1
-0+ args.value = (str ==NULL ) ?NULL : (char *)str;
What's wrong with
args.value = (char *)str;
?
Quoted 14 lines
monitor.c +14
-0+ args.next =NULL ; +InstrLoadResult *res =qmp_instr_load (path, args.value !=NULL , + args.value !=NULL ? &args :NULL , +NULL ); +switch (res->code) { +case INSTR_LOAD_CODE_OK : +monitor_printf (mon,"Handle: %" PRId64"\n" , res->handle); +monitor_printf (mon,"OK\n" ); +break ; +case INSTR_LOAD_CODE_TOO_MANY : +monitor_printf (mon,"Too many instrumentation libraries already loaded\n" ); +break ; +case INSTR_LOAD_CODE_ERROR : +monitor_printf (mon,"Instrumentation library returned a non-zero value during initialization" );
monitor.c int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp) · line 2351
Quoted 10 lines
monitor.c +10
-0+break ; +case INSTR_LOAD_CODE_DLERROR : +monitor_printf (mon,"Error loading library: %s\n" , res->msg); +break ; +case INSTR_LOAD_CODE_UNAVAILABLE : +monitor_printf (mon,"Service not available\n" ); +break ; +default : +fprintf (stderr,"Unknown instrumentation load code: %d" , res->code); +exit (1 );
Impossible conditions should be assertion failures, but it's a moot point because...
monitor.c int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp) · line 2355
Quoted 4 lines
monitor.c +4
-0+break ; + } +qapi_free_InstrLoadResult (res); +}
With qmp_instr_load() fixed to set an error on failure, this becomes something like
InstrLoadResult *res = qmp_instr_load(path, args.value != NULL,
args.value != NULL ? &args : NULL,
&err);
if (err) {
error_report_err(err);
} else {
monitor_printf(mon, "Handle: %"PRId64"\n", res->handle);
monitor_printf(mon, "OK\n");
}
qapi_free_InstrLoadResult(res);Quoted 19 lines
monitor.c +19
-0+ +static void hmp_instr_unload (Monitor *mon,const QDict *qdict) +{ +int64_t handle =qdict_get_int (qdict,"handle" ); +InstrUnloadResult *res =qmp_instr_unload (handle,NULL ); +switch (res->code) { +case INSTR_UNLOAD_CODE_OK : +monitor_printf (mon,"OK\n" ); +break ; +case INSTR_UNLOAD_CODE_INVALID : +monitor_printf (mon,"Invalid handle\n" ); +break ; +case INSTR_UNLOAD_CODE_DLERROR : +monitor_printf (mon,"Error unloading library: %s\n" , res->msg); +break ; +case INSTR_UNLOAD_CODE_UNAVAILABLE : +monitor_printf (mon,"Service not available\n" ); +break ; +default :
monitor.c int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp) · line 2384
Quoted 10 lines
monitor.c +7
-0+fprintf (stderr,"Unknown instrumentation unload code: %d" , res->code); +exit (1 ); +break ; + } +qapi_free_InstrUnloadResult (res); +} +/* Please update hmp-commands.hx when adding or changing commands */ static mon_cmd_t info_cmds[] = { #include "hmp-commands-info.h"
Likewise.
Re: [Qemu-devel] [PATCH v4 08/20] instrument: [hmp] Add library loader
Quoted 145 lines · Markus Armbruster
Quoted 42 lines · Lluís Vilanova
Signed-off-by Lluís Vilanova <[email protected]>---
hmp-commands.hx | 28 ++++++++++++++++++++++++++ monitor.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+)hmp-commands.hx +28
-0@@ -1858,6 +1858,34 @@ ETEXI .sub_table = info_cmds, }, + { + .name = "instr-load", + .args_type = "path:F,args:s?", + .params = "path [arg]", + .help = "load an instrumentation library", + .cmd = hmp_instr_load, + }, + +STEXI +@item instr-load @var{path} [args=value[,...]] +@findex instr-load +Load an instrumentation library. +ETEXI + + { + .name = "instr-unload", + .args_type = "handle:i", + .params = "handle", + .help = "unload an instrumentation library", + .cmd = hmp_instr_unload, + }, + +STEXI +@item instr-unload +@findex instr-unload +Unload an instrumentation library. +ETEXI +Quoted 3 lines
STEXI
@end table
ETEXIWant #ifdef
CONFIG_INSTRUMENT, see my review of the previous patch.See also my remark there on returning handles vs. passing in IDs.
monitor.c int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp) · line 2326
Quoted 13 lines
monitor.c +5
-0@@ -2319,6 +2319,66 @@ int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp)return fd; } +static void hmp_instr_load (Monitor *mon,const QDict *qdict) +{ +const char *path =qdict_get_str (qdict,"path" ); +const char *str =qdict_get_try_str (qdict,"args" ); +strList args;Blank line between last declaration and first statement, please.
monitor.c int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp) · line 2327
Quoted 1 line
monitor.c +1
-0+ args.value = (str ==NULL ) ?NULL : (char *)str;What's wrong with
args.value = (char *)str;?
Quoted 14 lines
monitor.c +14
-0+ args.next =NULL ; +InstrLoadResult *res =qmp_instr_load (path, args.value !=NULL , + args.value !=NULL ? &args :NULL , +NULL ); +switch (res->code) { +case INSTR_LOAD_CODE_OK : +monitor_printf (mon,"Handle: %" PRId64"\n" , res->handle); +monitor_printf (mon,"OK\n" ); +break ; +case INSTR_LOAD_CODE_TOO_MANY : +monitor_printf (mon,"Too many instrumentation libraries already loaded\n" ); +break ; +case INSTR_LOAD_CODE_ERROR : +monitor_printf (mon,"Instrumentation library returned a non-zero value during initialization" );monitor.c int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp) · line 2351
Quoted 10 lines
monitor.c +10
-0+break ; +case INSTR_LOAD_CODE_DLERROR : +monitor_printf (mon,"Error loading library: %s\n" , res->msg); +break ; +case INSTR_LOAD_CODE_UNAVAILABLE : +monitor_printf (mon,"Service not available\n" ); +break ; +default : +fprintf (stderr,"Unknown instrumentation load code: %d" , res->code); +exit (1 );Impossible conditions should be assertion failures, but it's a moot point because...
monitor.c int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp) · line 2355
Quoted 4 lines
monitor.c +4
-0+break ; + } +qapi_free_InstrLoadResult (res); +}With
qmp_instr_load()fixed to set an error on failure, this becomes something likeInstrLoadResult *res = qmp_instr_load(path, args.value != NULL, args.value != NULL ? &args : NULL, &err); if (err) { error_report_err(err); } else { monitor_printf(mon, "Handle: %"PRId64"\n", res->handle); monitor_printf(mon, "OK\n"); } qapi_free_InstrLoadResult(res);Quoted 23 lines
monitor.c +23
-0+ +static void hmp_instr_unload (Monitor *mon,const QDict *qdict) +{ +int64_t handle =qdict_get_int (qdict,"handle" ); +InstrUnloadResult *res =qmp_instr_unload (handle,NULL ); +switch (res->code) { +case INSTR_UNLOAD_CODE_OK : +monitor_printf (mon,"OK\n" ); +break ; +case INSTR_UNLOAD_CODE_INVALID : +monitor_printf (mon,"Invalid handle\n" ); +break ; +case INSTR_UNLOAD_CODE_DLERROR : +monitor_printf (mon,"Error unloading library: %s\n" , res->msg); +break ; +case INSTR_UNLOAD_CODE_UNAVAILABLE : +monitor_printf (mon,"Service not available\n" ); +break ; +default : +fprintf (stderr,"Unknown instrumentation unload code: %d" , res->code); +exit (1 ); +break ; + }
Quoted 8 lines
monitor.c int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp) · line 2384
Quoted 6 lines
monitor.c +3
-0+qapi_free_InstrUnloadResult (res); +} +/* Please update hmp-commands.hx when adding or changing commands */ static mon_cmd_t info_cmds[] = { #include "hmp-commands-info.h"Likewise.
Done, thanks!
Lluis
PATCH v4 9/20 instrument: Add basic control interface
In reply to Lluís Vilanova--- Makefile | 5 +++ configure | 1 + instrument/Makefile.objs | 2 + instrument/control.c | 28 +++++++++++++++++ instrument/control.h | 44 +++++++++++++++++++++++++++ instrument/control.inc.h | 25 ++++++++++++++++ instrument/error.h | 28 +++++++++++++++++ instrument/events.h | 37 +++++++++++++++++++++++ instrument/events.inc.h | 11 +++++++ instrument/load.c | 13 ++++++++ instrument/qemu-instr/control.h | 43 +++++++++++++++++++++++++++ instrument/qemu-instr/visibility.h | 58 ++++++++++++++++++++++++++++++++++++ stubs/Makefile.objs | 1 + stubs/instrument.c | 13 ++++++++ 14 files changed, 309 insertions(+) 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/qemu-instr/control.h create mode 100644 instrument/qemu-instr/visibility.h create mode 100644 stubs/instrument.c
Makefile +5 -0
@@ -589,6 +589,11 @@ ifdef CONFIG_VIRTFS $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1" $(INSTALL_DATA) fsdev/virtfs-proxy-helper.1 "$(DESTDIR)$(mandir)/man1" endif +ifdef CONFIG_INSTRUMENT + $(INSTALL_DIR) "$(DESTDIR)$(includedir)/qemu-instr/" + $(INSTALL_DATA) $(SRC_PATH)/instrument/qemu-instr/control.h "$(DESTDIR)$(includedir)/qemu-instr/" + $(INSTALL_DATA) $(SRC_PATH)/instrument/qemu-instr/visibility.h "$(DESTDIR)$(includedir)/qemu-instr/" +endif install-datadir: $(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)"
configure +1 -0
@@ -6038,6 +6038,7 @@ if test "$instrument" = "yes"; then LIBS="-ldl $LIBS" echo "CONFIG_INSTRUMENT=y" >> $config_host_mak fi +QEMU_INCLUDES="-I\$(SRC_PATH)/instrument $QEMU_INCLUDES" if test "$rdma" = "yes" ; then echo "CONFIG_RDMA=y" >> $config_host_mak
instrument/Makefile.objs +2 -0
@@ -3,3 +3,5 @@ target-obj-y += cmdline.o target-obj-$(CONFIG_INSTRUMENT) += load.o target-obj-y += qmp.o + +target-obj-$(CONFIG_INSTRUMENT) += control.o
instrument/control.c new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Control instrumentation during program (de)initialization. +* +* Copyright (C) 2012-2017 Lluís Vilanova <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "instrument/control.h" +#include "instrument/error.h" +#include "instrument/events.h" +#include "instrument/load.h" +#include "instrument/qemu-instr/control.h" +#include "instrument/qemu-instr/visibility.h" + +__threadInstrState instr_cur_state; + + +qi_fini_fn instr_event__fini_fn; +void *instr_event__fini_data; + +QI_VPUBLIC void qi_set_fini(qi_fini_fn fn, void *data) +{ +ERROR_IF (!instr_get_state (),"called outside instrumentation" ); +instr_set_event (fini_fn, fn); +instr_set_event (fini_data, data); +}
instrument/control.h new file +44 -0
44 lines not on this page · raw message
instrument/control.inc.h new file +25 -0
@@ -0,0 +1,25 @@ +/* +* Control instrumentation during program (de)initialization. +* +* Copyright (C) 2012-2017 Lluís Vilanova <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/atomic.h" +#include "qemu/compiler.h" +#include <stdbool.h> + + +extern __threadInstrState instr_cur_state; + +static inline void instr_set_state (InstrState state) +{ +atomic_store_release (&instr_cur_state, state); +} + +static inline InstrState instr_get_state (void ) +{ +return atomic_load_acquire (&instr_cur_state); +}
instrument/error.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Helpers for controlling errors in instrumentation libraries. +* +* Copyright (C) 2012-2017 Lluís Vilanova <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef INSTRUMENT_ERROR_H +#define INSTRUMENT_ERROR_H + +#include "qemu/osdep.h" +#include "qemu/error-report.h" + + +#define _ERROR(msg, args...) \ + do { \ + error_report("%s:" msg, __func__, ##args); \ + } while (0) + +#define ERROR_IF(cond, msg, args...) \ + if (unlikely(cond)) { \ + _ERROR(msg, ##args); \ + return; \ + } + +#endif /* INSTRUMENT_ERROR_H */
instrument/events.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Internal API for triggering instrumentation events. +* +* Copyright (C) 2017 Lluís Vilanova <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef INSTRUMENT__EVENTS_H +#define INSTRUMENT__EVENTS_H + +#include "instrument/qemu-instr/control.h" + +/** +* instr_get_event: +* +* Get value set by instrumentation library. +*/ +#define instr_get_event (name) \ + atomic_load_acquire(&instr_event__ ## name) + +/** +* instr_get_event: +* +* Set value from instrumentation library. +*/ +#define instr_set_event (name, fn) \ + atomic_store_release(&instr_event__ ## name, fn) + + +extern qi_fini_fn instr_event__fini_fn; +extern void *instr_event__fini_data; + +#include "instrument/events.inc.h" + +#endif /* INSTRUMENT__EVENTS_H */
instrument/events.inc.h new file +11 -0
@@ -0,0 +1,11 @@ +/* +* Internal API for triggering instrumentation events. +* +* Copyright (C) 2017 Lluís Vilanova <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + + +
instrument/load.c +13 -0
@@ -11,6 +11,8 @@#include "qemu-common.h" #include <dlfcn.h> +#include "instrument/control.h" +#include "instrument/events.h" #include "instrument/load.h" #include "qemu/config-file.h" #include "qemu/error-report.h"
@@ -105,8 +107,11 @@ InstrLoadError instr_load(const char * path, int argc, const char ** argv, res =INSTR_LOAD_DLERROR ; goto err; } +instr_set_event (fini_fn,NULL ); +instr_set_state (INSTR_STATE_ENABLE ); main_res =main_cb (argc, argv); +instr_set_state (INSTR_STATE_DISABLE );if (main_res !=0 ) { res =INSTR_LOAD_ERROR ;
@@ -136,6 +141,14 @@ InstrUnloadError instr_unload(int64_t handle_id) goto out; } +qi_fini_fn fini_fn =instr_get_event (fini_fn); +if (fini_fn) { +void *fini_data =instr_get_event (fini_data); +fini_fn (fini_data); + } + +instr_set_event (fini_fn,NULL ); +/* this should never fail */ if (dlclose (handle->dlhandle) <0 ) { res =INSTR_UNLOAD_DLERROR ;
instrument/qemu-instr/control.h new file +43 -0
43 lines not on this page · raw message
instrument/qemu-instr/visibility.h new file +58 -0
58 lines not on this page · raw message
stubs/Makefile.objs +1 -0
@@ -13,6 +13,7 @@ stub-obj-y += error-printf.o stub-obj-y += fdset.o stub-obj-y += gdbstub.o stub-obj-y += get-vm-name.o +stub-obj-y += instrument.o stub-obj-y += iothread.o stub-obj-y += iothread-lock.o stub-obj-y += is-daemonized.o
stubs/instrument.c new file +13 -0
@@ -0,0 +1,13 @@ +/* +* Instrumentation placeholders. +* +* Copyright (C) 2017 Lluís Vilanova <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "instrument/control.h" + + +__threadInstrState instr_cur_state;
Re: [Qemu-devel] [PATCH v4 09/20] instrument: Add basic control interface
Quoted 11 lines · Lluís Vilanova
Signed-off-by Lluís Vilanova <[email protected]>--- Makefile | 5 +++ configure | 1 + instrument/Makefile.objs | 2 + instrument/control.c | 28 +++++++++++++++++ instrument/control.h | 44 +++++++++++++++++++++++++++ instrument/control.inc.h | 25 ++++++++++++++++ instrument/error.h | 28 +++++++++++++++++ instrument/events.h | 37 +++++++++++++++++++++++ instrument/events.inc.h | 11 +++++++
Am I the only one who finds this control vs. events division confusing?
Also, do we need all these many files, even for the public API?
And why the .inc's?
Thanks,
E.
Re: [Qemu-devel] [PATCH v4 09/20] instrument: Add basic control interface
Quoted 13 lines · Emilio G Cota
Quoted 11 lines · Lluís Vilanova
Signed-off-by Lluís Vilanova <[email protected]>---
Makefile | 5 +++ configure | 1 + instrument/Makefile.objs | 2 + instrument/control.c | 28 +++++++++++++++++ instrument/control.h | 44 +++++++++++++++++++++++++++ instrument/control.inc.h | 25 ++++++++++++++++ instrument/error.h | 28 +++++++++++++++++ instrument/events.h | 37 +++++++++++++++++++++++ instrument/events.inc.h | 11 +++++++
Quoted 1 line
Am I the only one who finds this control vs. events division confusing?
Control is only for controlling instrumentation, and the header is used mainly inside the instrumentation directory. Wheread the events header is later going to be included in every file that needs to trigger an instrumentation event.
Quoted 1 line
Also, do we need all these many files, even for the public API?
The only other header, error.h, is later used in many other files.
Quoted 1 line
And why the .inc's?
To keep tidy headers with documentation, and the implementation details stashed away on a separate file (like in the case of trace/).
Quoted 2 lines
Thanks,
E.
Cheers,
Lluis
Re: [Qemu-devel] [PATCH v4 09/20] instrument: Add basic control interface
In reply to Lluís VilanovaQuoted 2 lines · Lluís Vilanova
Signed-off-by Lluís Vilanova <[email protected]>---
(snip)
instrument/control.c line 28
Quoted 6 lines
instrument/control.c new file +6
-0+QI_VPUBLIC void qi_set_fini(qi_fini_fn fn, void *data) +{ +ERROR_IF (!instr_get_state (),"called outside instrumentation" ); +instr_set_event (fini_fn, fn); +instr_set_event (fini_data, data); +}
Why are these QI_VPUBLIC attributes here? Those are useful for DSO's, not for executables --by using -rdynamic, all non-static symbols in the executable are already visible.
Quoted 5 lines
instrument/control.h new file +0
-0
(snip)
instrument/control.h line 25
Quoted 7 lines
+ * Instrumentation state of current host thread. Used to ensure instrumentation
+ * clients use QEMU's API only in expected points.
+ */instrument/control.h new file +4
-0+typedef enum { +INSTR_STATE_DISABLE , +INSTR_STATE_ENABLE , +}InstrState ;
I find this unnecessarily ugly for the little gain we get, i.e. asserts against calling API code from QEMU.. seems unlikely to me (although admittedly I think the qemu-internal API is unnecessarily complex/verbose, so maybe you're better off with these checks).
(snip)
Quoted 5 lines
instrument/control.h new file +5
-0+/** +* instr_get_event: +* +* Get value set by instrumentation library. +*/
instrument/control.h
Quoted 10 lines
instrument/control.h new file +10
-0+#define instr_get_event (name) \ + atomic_load_acquire(&instr_event__ ## name) + +/** +* instr_get_event: +* +* Set value from instrumentation library. +*/ +#define instr_set_event (name, fn) \ + atomic_store_release(&instr_event__ ## name, fn)
This isn't enough to decide whether to call instrumentation, especially for TCG. We need TB's to know what to call, and update that mask with async work, just like we do with tracing. Check out my alternative patchset.
Also, a single function pointer cannot work for more than one plugin. But I see you have an XXX when there's more than one plugin, so it's OK for now. I used RCU lists for this, which at least gives you a time in the future at which things become visible/invisible by other threads -- this is important when unloading an instrumenter, since you don't want to clear important stuff (e.g. dlclose) before you're sure no further callbacks to it are possible. [no, the atomic_acquire/release isn't enough!]
(snip)
Quoted 27 lines
instrument/load.c +5
-0@@ -11,6 +11,8 @@#include "qemu-common.h" #include <dlfcn.h> +#include "instrument/control.h" +#include "instrument/events.h" #include "instrument/load.h" #include "qemu/config-file.h" #include "qemu/error-report.h" @@ -105,8 +107,11 @@ InstrLoadError instr_load(const char * path, int argc, const char ** argv, res =INSTR_LOAD_DLERROR ; goto err; } +instr_set_event (fini_fn,NULL ); +instr_set_state (INSTR_STATE_ENABLE ); main_res =main_cb (argc, argv); +instr_set_state (INSTR_STATE_DISABLE );if (main_res !=0 ) { res =INSTR_LOAD_ERROR ;@@ -136,6 +141,14 @@ InstrUnloadError instr_unload(int64_t handle_id) goto out;
instrument/load.c InstrUnloadError instr_unload(int64_t handle_id) · line 151
Quoted 10 lines
instrument/load.c +8
-0} +qi_fini_fn fini_fn =instr_get_event (fini_fn); +if (fini_fn) { +void *fini_data =instr_get_event (fini_data); +fini_fn (fini_data); + } + +instr_set_event (fini_fn,NULL ); +
Is fini really that useful? Doesn't the tool just die with QEMU once QEMU exits? At the end of the day, the tool could register its own atexit hook.
E.
Re: [Qemu-devel] [PATCH v4 09/20] instrument: Add basic control interface
Quoted 4 lines · Emilio G Cota
Quoted 2 lines · Lluís Vilanova
Signed-off-by Lluís Vilanova <[email protected]>---
(snip)
Quoted 10 lines
instrument/control.c line 28
Quoted 6 lines
instrument/control.c new file +6
-0+QI_VPUBLIC void qi_set_fini(qi_fini_fn fn, void *data) +{ +ERROR_IF (!instr_get_state (),"called outside instrumentation" ); +instr_set_event (fini_fn, fn); +instr_set_event (fini_data, data); +}Why are these
QI_VPUBLICattributes here? Those are useful for DSO's, not for executables --by using -rdynamic, all non-static symbols in the executable are already visible.
That's because I'm using -rdynamic, -fvisibility=hidden and these attributes all together to limit what symbols are available to dlopen()'ed libs (new series version will have the visibility compiler flag I forgot to send).
Quoted 6 lines
Quoted 5 lines
instrument/control.h new file +0
-0(snip)
Quoted 12 lines
instrument/control.h line 25
Quoted 7 lines
+ * Instrumentation state of current host thread. Used to ensure instrumentation
+ * clients use QEMU's API only in expected points.
+ */instrument/control.h new file +4
-0+typedef enum { +INSTR_STATE_DISABLE , +INSTR_STATE_ENABLE , +}InstrState ;I find this unnecessarily ugly for the little gain we get, i.e. asserts against calling API code from QEMU.. seems unlikely to me (although admittedly I think the qemu-internal API is unnecessarily complex/verbose, so maybe you're better off with these checks).
It ensures only QEMU's threads now calling a library function are allowed to use the public API. In a later patch, it also ensures that TCG-generating functions (e.g., qi_event_gen_guest_mem_before_exec) can only be called from translation-time library functions.
Quoted 12 lines
(snip)
Quoted 11 lines
instrument/control.h new file +11
-0+/** +* instr_get_event: +* +* Get value set by instrumentation library. +*/ +#define instr_get_event (name) \ + atomic_load_acquire(&instr_event__ ## name) + +/** +* instr_get_event: +*
Quoted 8 lines
instrument/control.h
Quoted 4 lines
+ * Set value from instrumentation library.
+ */instrument/control.h new file +2
-0+#define instr_set_event (name, fn) \ + atomic_store_release(&instr_event__ ## name, fn)This isn't enough to decide whether to call instrumentation, especially for TCG. We need TB's to know what to call, and update that mask with async work, just like we do with tracing. Check out my alternative patchset.
What do you mean by TB's need to know what to call?
Quoted 7 lines
Also, a single function pointer cannot work for more than one plugin. But I see you have an XXX when there's more than one plugin, so it's OK for now. I used RCU lists for this, which at least gives you a time in the future at which things become visible/invisible by other threads -- this is important when unloading an instrumenter, since you don't want to clear important stuff (e.g. dlclose) before you're sure no further callbacks to it are possible. [no, the atomic_acquire/release isn't enough!]
In principle, this together with the API checks above and kicking all vCPUs to flush TBs before unloading a library (I'm still looking at last bit) should ensure libs can be safely unloaded. This should work for guest code events, but I still need to look at other events like vCPU hotplug (is it asynchronous?), or other events we might want triggered outside the vCPU loops.
Flushing all TBs is also on my todo to support immediate event availability when loading a library and setting a translation-time callback.
Also, I'm not sure if we should support the complexity and performance penalty of more than one library at a time. Right now, the QAPI commands expose support for more than one just for future-proofing (as suggested by Richard Henderson, if I remember correctly).
Quoted 30 lines
(snip)
Quoted 29 lines
instrument/load.c +5
-0@@ -11,6 +11,8 @@#include "qemu-common.h" #include <dlfcn.h> +#include "instrument/control.h" +#include "instrument/events.h" #include "instrument/load.h" #include "qemu/config-file.h" #include "qemu/error-report.h" @@ -105,8 +107,11 @@ InstrLoadError instr_load(const char * path, int argc, const char ** argv, res =INSTR_LOAD_DLERROR ; goto err; } +instr_set_event (fini_fn,NULL ); +instr_set_state (INSTR_STATE_ENABLE ); main_res =main_cb (argc, argv); +instr_set_state (INSTR_STATE_DISABLE );if (main_res !=0 ) { res =INSTR_LOAD_ERROR ;@@ -136,6 +141,14 @@ InstrUnloadError instr_unload(int64_t handle_id) goto out; }
Quoted 10 lines
instrument/load.c InstrUnloadError instr_unload(int64_t handle_id) · line 151
Quoted 8 lines
instrument/load.c +8
-0+qi_fini_fn fini_fn =instr_get_event (fini_fn); +if (fini_fn) { +void *fini_data =instr_get_event (fini_data); +fini_fn (fini_data); + } + +instr_set_event (fini_fn,NULL ); +Is fini really that useful? Doesn't the tool just die with QEMU once QEMU exits?
The lib can be unloaded at any time (in softmmu mode).
Quoted 1 line
At the end of the day, the tool could register its own atexit hook.
I'm aware of that, but:
* Passing a pointer when registering the callback avoids global variables.
* I thought that qi_set_fini() would be more discoverable than dlclose()+atexit().
Thanks!
Lluis
PATCH v4 10/20 instrument: Add support for tracing events
In reply to Lluís Vilanova--- .gitignore | 1 Makefile | 3 + instrument/Makefile.objs | 1 instrument/error.h | 6 ++ instrument/qemu-instr/types.h | 51 +++++++++++++++ instrument/qemu-instr/types.inc.h | 15 ++++ instrument/trace.c | 125 +++++++++++++++++++++++++++++++++++++ trace/control.h | 1 8 files changed, 203 insertions(+) create mode 100644 instrument/qemu-instr/types.h create mode 100644 instrument/qemu-instr/types.inc.h create mode 100644 instrument/trace.c
.gitignore +1 -0
@@ -134,3 +134,4 @@ trace-dtrace-root.h trace-dtrace-root.dtrace trace-ust-all.h trace-ust-all.c +!/instrument/*
Makefile +3 -0
@@ -592,6 +592,9 @@ endif ifdef CONFIG_INSTRUMENT $(INSTALL_DIR) "$(DESTDIR)$(includedir)/qemu-instr/" $(INSTALL_DATA) $(SRC_PATH)/instrument/qemu-instr/control.h "$(DESTDIR)$(includedir)/qemu-instr/" + $(INSTALL_DATA) $(SRC_PATH)/instrument/qemu-instr/trace.h "$(DESTDIR)$(includedir)/qemu-instr/" + $(INSTALL_DATA) $(SRC_PATH)/instrument/qemu-instr/types.h "$(DESTDIR)$(includedir)/qemu-instr/" + $(INSTALL_DATA) $(SRC_PATH)/instrument/qemu-instr/types.inc.h "$(DESTDIR)$(includedir)/qemu-instr/" $(INSTALL_DATA) $(SRC_PATH)/instrument/qemu-instr/visibility.h "$(DESTDIR)$(includedir)/qemu-instr/" endif
instrument/Makefile.objs +1 -0
@@ -5,3 +5,4 @@ target-obj-$(CONFIG_INSTRUMENT) += load.o target-obj-y += qmp.o target-obj-$(CONFIG_INSTRUMENT) += control.o +target-obj-$(CONFIG_INSTRUMENT) += trace.o
instrument/error.h +6 -0
@@ -25,4 +25,10 @@return ; \ } +#define ERROR_IF_RET(cond, ret, msg, args...) \ + if (unlikely(cond)) { \ + _ERROR(msg, ##args); \ + return ret; \ + } \ +#endif /* INSTRUMENT_ERROR_H */
instrument/qemu-instr/types.h new file +51 -0
51 lines not on this page · raw message
instrument/qemu-instr/types.inc.h new file +15 -0
@@ -0,0 +1,15 @@ +/* +* QEMU-specific types for instrumentation clients. +* +* Copyright (C) 2012-2017 Lluís Vilanova <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include <stdlib.h> + + +struct QITraceEventIter { +char buffer[(sizeof (size_t ) *2 ) +sizeof (char *)]; +};
instrument/trace.c new file +125 -0
125 lines not on this page · raw message
trace/control.h +1 -0
@@ -13,6 +13,7 @@#include "qemu-common.h" #include "event-internal.h" +/* NOTE: Keep in sync with size of QITraceEventIter */ typedef struct TraceEventIter { size_t event; size_t group;
PATCH v4 11/20 instrument: Track vCPUs
In reply to Lluís VilanovaKeep a translation between instrumentation's QICPU and CPUState objects to avoid exposing QEMU's internals to instrumentation clients.
--- cpus-common.c | 9 +++++++++ instrument/control.c | 22 ++++++++++++++++++++++ instrument/control.h | 32 ++++++++++++++++++++++++++++++++ instrument/control.inc.h | 23 +++++++++++++++++++++++ 4 files changed, 86 insertions(+)
cpus-common.c +9 -0
@@ -22,6 +22,9 @@#include "exec/cpu-common.h" #include "qom/cpu.h" #include "sysemu/cpus.h" +#if defined(CONFIG_INSTRUMENT ) +#include "instrument/control.h" +#endif static QemuMutex qemu_cpu_list_lock;static QemuCond exclusive_cond;
@@ -84,6 +87,9 @@ void cpu_list_add(CPUState *cpu) }else {assert (!cpu_index_auto_assigned); } +#if defined(CONFIG_INSTRUMENT ) +instr_cpu_add (cpu); +#endif QTAILQ_INSERT_TAIL (&cpus, cpu, node);qemu_mutex_unlock (&qemu_cpu_list_lock);
@@ -102,6 +108,9 @@ void cpu_list_remove(CPUState *cpu)assert (!(cpu_index_auto_assigned && cpu !=QTAILQ_LAST (&cpus, CPUTailQ)));QTAILQ_REMOVE (&cpus, cpu, node); +#if defined(CONFIG_INSTRUMENT ) +instr_cpu_remove (cpu); +#endif cpu->cpu_index =UNASSIGNED_CPU_INDEX ;qemu_mutex_unlock (&qemu_cpu_list_lock); }
instrument/control.c +22 -0
@@ -13,10 +13,32 @@#include "instrument/load.h" #include "instrument/qemu-instr/control.h" #include "instrument/qemu-instr/visibility.h" +#include "qom/cpu.h" + __threadInstrState instr_cur_state; +unsigned int instr_cpus_count; +CPUState **instr_cpus; + +void instr_cpu_add (CPUState *vcpu) +{ +unsigned int idx = vcpu->cpu_index; +if (idx >= instr_cpus_count) { + instr_cpus_count = idx +1 ; + instr_cpus =realloc (instr_cpus,sizeof (*instr_cpus) * instr_cpus_count); + } + instr_cpus[idx] = vcpu; +} + +void instr_cpu_remove (CPUState *vcpu) +{ +unsigned int idx = vcpu->cpu_index; + instr_cpus[idx] =NULL ; +} + +qi_fini_fn instr_event__fini_fn;void *instr_event__fini_data;
instrument/control.h +32 -0
@@ -10,6 +10,38 @@#ifndef INSTRUMENT__CONTROL_H #define INSTRUMENT__CONTROL_H +#include "qemu/typedefs.h" +#include "instrument/qemu-instr/types.h" + + +/** +* instr_cpu_add: +* +* Make @vcpu available to instrumentation clients. +*/ +void instr_cpu_add (CPUState *vcpu); + +/** +* instr_cpu_remove: +* +* Make @vcpu unavailable to instrumentation clients. +*/ +void instr_cpu_remove (CPUState *vcpu); + +/** +* instr_cpu_get: +* +* Get the #CPUState corresponding to the given #QICPU. +*/ +static inline CPUState *instr_cpu_get (QICPU vcpu); + +/** +* instr_cpu_set: +* +* Get the #QICPU corresponding to the given #CPUState. +*/ +static inline QICPU instr_cpu_set (CPUState *vcpu); +/** * InstrState:
instrument/control.inc.h +23 -0
@@ -7,9 +7,12 @@* See the COPYING file in the top-level directory. */ +#include "qemu/osdep.h" #include "qemu/atomic.h" #include "qemu/compiler.h" +#include "qom/cpu.h" #include <stdbool.h> +#include <stdint.h> extern __threadInstrState instr_cur_state;
@@ -23,3 +26,23 @@ static inline InstrState instr_get_state(void) {return atomic_load_acquire (&instr_cur_state); } + + +extern unsigned int instr_cpus_count; +extern CPUState **instr_cpus; + +static inline CPUState *instr_cpu_get (QICPU vcpu) +{ +unsigned int idx = (uintptr_t )vcpu; +if (idx >= instr_cpus_count) { +return NULL ; + }else { +return instr_cpus[idx]; + } +} + +static inline QICPU instr_cpu_set (CPUState *vcpu) +{ +uintptr_t idx = vcpu->cpu_index; +return (QICPU )idx; +}
Re: [Qemu-devel] [PATCH v4 11/20] instrument: Track vCPUs
Quoted 4 lines · Lluís Vilanova
Keep a translation between instrumentation's QICPU and CPUState objects to avoid exposing QEMU's internals to instrumentation clients.
Signed-off-by Lluís Vilanova <[email protected]>
(snip)
Quoted 22 lines
instrument/control.c +10
-0@@ -13,10 +13,32 @@#include "instrument/load.h" #include "instrument/qemu-instr/control.h" #include "instrument/qemu-instr/visibility.h" +#include "qom/cpu.h" + __threadInstrState instr_cur_state; +unsigned int instr_cpus_count; +CPUState **instr_cpus; + +void instr_cpu_add (CPUState *vcpu) +{ +unsigned int idx = vcpu->cpu_index; +if (idx >= instr_cpus_count) { + instr_cpus_count = idx +1 ;
instrument/control.c line 39
Quoted 10 lines
instrument/control.c +10
-0+ instr_cpus =realloc (instr_cpus,sizeof (*instr_cpus) * instr_cpus_count); + } + instr_cpus[idx] = vcpu; +} + +void instr_cpu_remove (CPUState *vcpu) +{ +unsigned int idx = vcpu->cpu_index; + instr_cpus[idx] =NULL ; +}
instr_cpus_count and instr_cpus are both modified with cpu_list_lock. However, other readers do not acquire this same lock. This gets messy when you try to implement something like "vcpu_for_each", which is very useful when you load an instrumentation tool once the program is running (otherwise the tool cannot know for sure what the vCPUs are). This vcpu_for_each would also have to take cpu_list_lock, for otherwise it'd miss new threads being added. As you can imagine this gets messy pretty quickly, given that you have your own lock here. I went with having my own hash table (a list would be fine too), protected with the same "instr_lock" you have (i.e. the recursive mutex).
An unrelated comment: your usage of get/set/put confuses me. I'd expect those to work on refcounted items; instead you use them for instance to hide a cast (cpu_set) or to create/destroy (e.g. handle_get/put).
E.
PATCH v4 12/20 instrument: Add event 'guest_cpu_enter'
In reply to Lluís Vilanova--- instrument/control.c | 9 ++++++++ instrument/events.h | 5 ++++ instrument/events.inc.h | 11 ++++++++++ instrument/load.c | 1 + instrument/qemu-instr/control.h | 44 +++++++++++++++++++++++++++++++++++++++ stubs/instrument.c | 1 + trace/control-target.c | 2 ++ 7 files changed, 73 insertions(+)
instrument/control.c +9 -0
@@ -48,3 +48,12 @@ QI_VPUBLIC void qi_set_fini(qi_fini_fn fn, void *data)instr_set_event (fini_fn, fn);instr_set_event (fini_data, data); } + + +void (*instr_event__guest_cpu_enter)(QICPU vcpu); + +QI_VPUBLIC void qi_event_set_guest_cpu_enter(void (*fn)(QICPU vcpu)) +{ +ERROR_IF (!instr_get_state (),"called outside instrumentation" ); +instr_set_event (guest_cpu_enter, fn); +}
instrument/events.h +5 -0
@@ -11,6 +11,7 @@#define INSTRUMENT__EVENTS_H #include "instrument/qemu-instr/control.h" +#include "instrument/qemu-instr/types.h" /** * instr_get_event:
@@ -32,6 +33,10 @@extern qi_fini_fn instr_event__fini_fn;extern void *instr_event__fini_data; +extern void (*instr_event__guest_cpu_enter)(QICPU vcpu); +static inline void instr_guest_cpu_enter (CPUState *vcpu); + +#include "instrument/events.inc.h" #endif /* INSTRUMENT__EVENTS_H */
instrument/events.inc.h +11 -0
@@ -7,5 +7,16 @@* See the COPYING file in the top-level directory. */ +#include "instrument/control.h" +static inline void instr_guest_cpu_enter (CPUState *vcpu) +{ +void (*cb)(QICPU vcpu) =instr_get_event (guest_cpu_enter); +if (cb) { +QICPU vcpu_ =instr_cpu_set (vcpu); +instr_set_state (INSTR_STATE_ENABLE ); + (*cb)(vcpu_); +instr_set_state (INSTR_STATE_DISABLE ); + } +}
instrument/load.c +1 -0
@@ -148,6 +148,7 @@ InstrUnloadError instr_unload(int64_t handle_id) }instr_set_event (fini_fn,NULL ); +instr_set_event (guest_cpu_enter,NULL );/* this should never fail */ if (dlclose (handle->dlhandle) <0 ) {
instrument/qemu-instr/control.h +44 -0
56 lines not on this page · raw message
stubs/instrument.c +1 -0
@@ -11,3 +11,4 @@ __threadInstrState instr_cur_state; +void (*instr_event__guest_cpu_enter)(QICPU *vcpu);
trace/control-target.c +2 -0
@@ -9,6 +9,7 @@#include "qemu/osdep.h" #include "cpu.h" +#include "instrument/events.h" #include "trace-root.h" #include "trace/control.h" #include "translate-all.h"
@@ -147,5 +148,6 @@ void trace_init_vcpu(CPUState *vcpu) } } } +instr_guest_cpu_enter (vcpu);trace_guest_cpu_enter (vcpu); }
PATCH v4 13/20 instrument: Add event 'guest_cpu_exit'
In reply to Lluís Vilanova--- instrument/control.c | 9 +++++++++ instrument/events.h | 3 +++ instrument/events.inc.h | 11 +++++++++++ instrument/load.c | 1 + instrument/qemu-instr/control.h | 9 +++++++++ stubs/instrument.c | 1 + trace/control.c | 4 +++- 7 files changed, 37 insertions(+), 1 deletion(-)
instrument/control.c +9 -0
@@ -57,3 +57,12 @@ QI_VPUBLIC void qi_event_set_guest_cpu_enter(void (*fn)(QICPU vcpu))ERROR_IF (!instr_get_state (),"called outside instrumentation" );instr_set_event (guest_cpu_enter, fn); } + + +void (*instr_event__guest_cpu_exit)(QICPU vcpu); + +QI_VPUBLIC void qi_event_set_guest_cpu_exit(void (*fn)(QICPU vcpu)) +{ +ERROR_IF (!instr_get_state (),"called outside instrumentation" ); +instr_set_event (guest_cpu_exit, fn); +}
instrument/events.h +3 -0
@@ -36,6 +36,9 @@ extern void *instr_event__fini_data;extern void (*instr_event__guest_cpu_enter)(QICPU vcpu);static inline void instr_guest_cpu_enter (CPUState *vcpu); +extern void (*instr_event__guest_cpu_exit)(QICPU vcpu); +static inline void instr_guest_cpu_exit (CPUState *vcpu); +#include "instrument/events.inc.h"
instrument/events.inc.h +11 -0
@@ -20,3 +20,14 @@ static inline void instr_guest_cpu_enter(CPUState *vcpu)instr_set_state (INSTR_STATE_DISABLE ); } } + +static inline void instr_guest_cpu_exit (CPUState *vcpu) +{ +void (*cb)(QICPU vcpu) =instr_get_event (guest_cpu_exit); +if (cb) { +QICPU vcpu_ =instr_cpu_set (vcpu); +instr_set_state (INSTR_STATE_ENABLE ); + (*cb)(vcpu_); +instr_set_state (INSTR_STATE_DISABLE ); + } +}
instrument/load.c +1 -0
@@ -149,6 +149,7 @@ InstrUnloadError instr_unload(int64_t handle_id)instr_set_event (fini_fn,NULL );instr_set_event (guest_cpu_enter,NULL ); +instr_set_event (guest_cpu_exit,NULL );/* this should never fail */ if (dlclose (handle->dlhandle) <0 ) {
instrument/qemu-instr/control.h +9 -0
@@ -80,6 +80,15 @@ void qi_set_fini(qi_fini_fn fn, void *data);*/ void qi_event_set_guest_cpu_enter (void (*fn)(QICPU vcpu)); +/* +* Hot-unplug a virtual (guest) CPU. +* +* Mode: user, softmmu +* Targets: all +* Time: exec +*/ +void qi_event_set_guest_cpu_exit (void (*fn)(QICPU vcpu)); + #ifdef __cplusplus }#endif
stubs/instrument.c +1 -0
@@ -12,3 +12,4 @@ __threadInstrState instr_cur_state;void (*instr_event__guest_cpu_enter)(QICPU *vcpu); +void (*instr_event__guest_cpu_exit)(QICPU *vcpu);
trace/control.c +3 -1
@@ -1,13 +1,14 @@/* * Interface for configuring and controlling the state of tracing events. * -* Copyright (C) 2011-2016 Lluís Vilanova <[email protected]> +* Copyright (C) 2011-2017 Lluís Vilanova <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory. */ #include "qemu/osdep.h" +#include "instrument/events.h" #include "trace/control.h" #include "qemu/help_option.h" #ifdef CONFIG_TRACE_SIMPLE
@@ -272,6 +273,7 @@ void trace_fini_vcpu(CPUState *vcpu)TraceEventIter iter;TraceEvent *ev; +instr_guest_cpu_exit (vcpu);trace_guest_cpu_exit (vcpu);trace_event_iter_init (&iter,NULL );
PATCH v4 14/20 instrument: Add event 'guest_cpu_reset'
In reply to Lluís Vilanova--- instrument/control.c | 9 +++++++++ instrument/events.h | 3 +++ instrument/events.inc.h | 11 +++++++++++ instrument/load.c | 1 + instrument/qemu-instr/control.h | 9 +++++++++ qom/cpu.c | 2 ++ stubs/instrument.c | 1 + 7 files changed, 36 insertions(+)
instrument/control.c +9 -0
@@ -66,3 +66,12 @@ QI_VPUBLIC void qi_event_set_guest_cpu_exit(void (*fn)(QICPU vcpu))ERROR_IF (!instr_get_state (),"called outside instrumentation" );instr_set_event (guest_cpu_exit, fn); } + + +void (*instr_event__guest_cpu_reset)(QICPU vcpu); + +QI_VPUBLIC void qi_event_set_guest_cpu_reset(void (*fn)(QICPU vcpu)) +{ +ERROR_IF (!instr_get_state (),"called outside instrumentation" ); +instr_set_event (guest_cpu_reset, fn); +}
instrument/events.h +3 -0
@@ -39,6 +39,9 @@ static inline void instr_guest_cpu_enter(CPUState *vcpu);extern void (*instr_event__guest_cpu_exit)(QICPU vcpu);static inline void instr_guest_cpu_exit (CPUState *vcpu); +extern void (*instr_event__guest_cpu_reset)(QICPU vcpu); +static inline void instr_guest_cpu_reset (CPUState *vcpu); +#include "instrument/events.inc.h"
instrument/events.inc.h +11 -0
@@ -31,3 +31,14 @@ static inline void instr_guest_cpu_exit(CPUState *vcpu)instr_set_state (INSTR_STATE_DISABLE ); } } + +static inline void instr_guest_cpu_reset (CPUState *vcpu) +{ +void (*cb)(QICPU vcpu) =instr_get_event (guest_cpu_reset); +if (cb) { +QICPU vcpu_ =instr_cpu_set (vcpu); +instr_set_state (INSTR_STATE_ENABLE ); + (*cb)(vcpu_); +instr_set_state (INSTR_STATE_DISABLE ); + } +}
instrument/load.c +1 -0
@@ -150,6 +150,7 @@ InstrUnloadError instr_unload(int64_t handle_id)instr_set_event (fini_fn,NULL );instr_set_event (guest_cpu_enter,NULL );instr_set_event (guest_cpu_exit,NULL ); +instr_set_event (guest_cpu_reset,NULL );/* this should never fail */ if (dlclose (handle->dlhandle) <0 ) {
instrument/qemu-instr/control.h +9 -0
@@ -89,6 +89,15 @@ void qi_event_set_guest_cpu_enter(void (*fn)(QICPU vcpu));*/ void qi_event_set_guest_cpu_exit (void (*fn)(QICPU vcpu)); +/* +* Reset the state of a virtual (guest) CPU. +* +* Mode: user, softmmu +* Targets: all +* Time: exec +*/ +void qi_event_set_guest_cpu_reset (void (*fn)(QICPU vcpu)); + #ifdef __cplusplus }#endif
qom/cpu.c +2 -0
@@ -19,6 +19,7 @@*/ #include "qemu/osdep.h" +#include "instrument/events.h" #include "qapi/error.h" #include "qemu-common.h" #include "qom/cpu.h"
@@ -271,6 +272,7 @@ void cpu_reset(CPUState *cpu) (*klass->reset)(cpu); } +instr_guest_cpu_reset (cpu);trace_guest_cpu_reset (cpu); }
stubs/instrument.c +1 -0
@@ -13,3 +13,4 @@ __threadInstrState instr_cur_state;void (*instr_event__guest_cpu_enter)(QICPU *vcpu);void (*instr_event__guest_cpu_exit)(QICPU *vcpu); +void (*instr_event__guest_cpu_reset)(QICPU *vcpu);
PATCH v4 15/20 trace: Introduce a proper structure to describe memory accesses
In reply to Lluís Vilanova--- include/exec/cpu_ldst_template.h | 15 ++++++-------- include/exec/cpu_ldst_useronly_template.h | 15 ++++++-------- tcg/tcg-op.c | 22 +++++++++++++-------- trace/mem-internal.h | 22 ++++++++++++--------- trace/mem.h | 31 +++++++++++++++++++++++++---- 5 files changed, 66 insertions(+), 39 deletions(-)
include/exec/cpu_ldst_template.h +6 -9
@@ -88,9 +88,8 @@ glue(glue(glue(cpu_ld, USUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,TCGMemOpIdx oi;#if !defined(SOFTMMU_CODE_ACCESS ) -trace_guest_mem_before_exec ( -ENV_GET_CPU (env), ptr, -trace_mem_build_info (SHIFT , false,MO_TE , false)); +TraceMemInfo meminfo =trace_mem_build_info (SHIFT , false,MO_TE , false); +trace_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo.raw);#endif addr = ptr;
@@ -126,9 +125,8 @@ glue(glue(glue(cpu_lds, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,TCGMemOpIdx oi;#if !defined(SOFTMMU_CODE_ACCESS ) -trace_guest_mem_before_exec ( -ENV_GET_CPU (env), ptr, -trace_mem_build_info (SHIFT , true,MO_TE , false)); +TraceMemInfo meminfo =trace_mem_build_info (SHIFT , true,MO_TE , false); +trace_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo.raw);#endif addr = ptr;
@@ -168,9 +166,8 @@ glue(glue(glue(cpu_st, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,TCGMemOpIdx oi;#if !defined(SOFTMMU_CODE_ACCESS ) -trace_guest_mem_before_exec ( -ENV_GET_CPU (env), ptr, -trace_mem_build_info (SHIFT , false,MO_TE , true)); +TraceMemInfo meminfo =trace_mem_build_info (SHIFT , false,MO_TE , true); +trace_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo.raw);#endif addr = ptr;
include/exec/cpu_ldst_useronly_template.h +6 -9
@@ -61,9 +61,8 @@ static inline RES_TYPE glue(glue(cpu_ld, USUFFIX), MEMSUFFIX)(CPUArchState *env, target_ulong ptr) {#if !defined(CODE_ACCESS ) -trace_guest_mem_before_exec ( -ENV_GET_CPU (env), ptr, -trace_mem_build_info (DATA_SIZE , false,MO_TE , false)); +TraceMemInfo meminfo =trace_mem_build_info (DATA_SIZE , false,MO_TE , false); +trace_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo.raw);#endif return glue (glue (ld,USUFFIX ), _p)(g2h (ptr)); }
@@ -81,9 +80,8 @@ static inline int glue(glue(cpu_lds, SUFFIX), MEMSUFFIX)(CPUArchState *env, target_ulong ptr) {#if !defined(CODE_ACCESS ) -trace_guest_mem_before_exec ( -ENV_GET_CPU (env), ptr, -trace_mem_build_info (DATA_SIZE , true,MO_TE , false)); +TraceMemInfo meminfo =trace_mem_build_info (DATA_SIZE , true,MO_TE , false); +trace_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo.raw);#endif return glue (glue (lds,SUFFIX ), _p)(g2h (ptr)); }
@@ -103,9 +101,8 @@ glue(glue(cpu_st, SUFFIX), MEMSUFFIX)(CPUArchState *env, target_ulong ptr, RES_TYPE v) {#if !defined(CODE_ACCESS ) -trace_guest_mem_before_exec ( -ENV_GET_CPU (env), ptr, -trace_mem_build_info (DATA_SIZE , false,MO_TE , true)); +TraceMemInfo meminfo =trace_mem_build_info (DATA_SIZE , false,MO_TE , true); +trace_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo.raw);#endif glue (glue (st,SUFFIX ), _p)(g2h (ptr), v); }
tcg/tcg-op.c +14 -8
@@ -2664,22 +2664,26 @@ static void gen_ldst_i64(TCGOpcode opc, TCGv_i64 val, TCGv addr,void tcg_gen_qemu_ld_i32 (TCGv_i32 val,TCGv addr,TCGArg idx,TCGMemOp memop) { +TraceMemInfo meminfo; memop =tcg_canonicalize_memop (memop,0 ,0 ); -trace_guest_mem_before_tcg (tcg_ctx.cpu, tcg_ctx.tcg_env, - addr,trace_mem_get_info (memop,0 )); + meminfo =trace_mem_get_info (memop,0 ); +trace_guest_mem_before_tcg (tcg_ctx.cpu, tcg_ctx.tcg_env, addr, meminfo.raw);gen_ldst_i32 (INDEX_op_qemu_ld_i32, val, addr, memop, idx); }void tcg_gen_qemu_st_i32 (TCGv_i32 val,TCGv addr,TCGArg idx,TCGMemOp memop) { +TraceMemInfo meminfo; memop =tcg_canonicalize_memop (memop,0 ,1 ); -trace_guest_mem_before_tcg (tcg_ctx.cpu, tcg_ctx.tcg_env, - addr,trace_mem_get_info (memop,1 )); + meminfo =trace_mem_get_info (memop,1 ); +trace_guest_mem_before_tcg (tcg_ctx.cpu, tcg_ctx.tcg_env, addr, meminfo.raw);gen_ldst_i32 (INDEX_op_qemu_st_i32, val, addr, memop, idx); }void tcg_gen_qemu_ld_i64 (TCGv_i64 val,TCGv addr,TCGArg idx,TCGMemOp memop) { +TraceMemInfo meminfo; +if (TCG_TARGET_REG_BITS ==32 && (memop &MO_SIZE ) <MO_64 ) {tcg_gen_qemu_ld_i32 (TCGV_LOW (val), addr, idx, memop);if (memop &MO_SIGN ) {
@@ -2691,21 +2695,23 @@ void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) } memop =tcg_canonicalize_memop (memop,1 ,0 ); -trace_guest_mem_before_tcg (tcg_ctx.cpu, tcg_ctx.tcg_env, - addr,trace_mem_get_info (memop,0 )); + meminfo =trace_mem_get_info (memop,0 ); +trace_guest_mem_before_tcg (tcg_ctx.cpu, tcg_ctx.tcg_env, addr, meminfo.raw);gen_ldst_i64 (INDEX_op_qemu_ld_i64, val, addr, memop, idx); }void tcg_gen_qemu_st_i64 (TCGv_i64 val,TCGv addr,TCGArg idx,TCGMemOp memop) { +TraceMemInfo meminfo; +if (TCG_TARGET_REG_BITS ==32 && (memop &MO_SIZE ) <MO_64 ) {tcg_gen_qemu_st_i32 (TCGV_LOW (val), addr, idx, memop);return ; } memop =tcg_canonicalize_memop (memop,1 ,1 ); -trace_guest_mem_before_tcg (tcg_ctx.cpu, tcg_ctx.tcg_env, - addr,trace_mem_get_info (memop,1 )); + meminfo =trace_mem_get_info (memop,1 ); +trace_guest_mem_before_tcg (tcg_ctx.cpu, tcg_ctx.tcg_env, addr, meminfo.raw);gen_ldst_i64 (INDEX_op_qemu_st_i64, val, addr, memop, idx); }
trace/mem-internal.h +13 -9
@@ -1,7 +1,7 @@/* * Helper functions for guest memory tracing * -* Copyright (C) 2016 Lluís Vilanova <[email protected]> +* Copyright (C) 2016-2017 Lluís Vilanova <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory.
@@ -10,8 +10,9 @@#ifndef TRACE__MEM_INTERNAL_H #define TRACE__MEM_INTERNAL_H -static inline uint8_t trace_mem_get_info (TCGMemOp op,bool store) +static inline TraceMemInfo trace_mem_get_info (TCGMemOp op,bool store) { +TraceMemInfo res_;uint8_t res = op;bool be = (op &MO_BSWAP ) ==MO_BE ;
@@ -27,19 +28,22 @@ static inline uint8_t trace_mem_get_info(TCGMemOp op, bool store) res |=1ULL <<4 ; } -return res; + res_.raw = res; +return res_; } -static inline uint8_t trace_mem_build_info ( +static inline TraceMemInfo trace_mem_build_info (TCGMemOp size,bool sign_extend,TCGMemOp endianness,bool store) { -uint8_t res =0 ; - res |= size; - res |= (sign_extend <<2 ); +TraceMemInfo res; + res.size_shift = size; + res.sign_extend = sign_extend;if (endianness ==MO_BE ) { - res |= (1ULL <<3 ); + res.endianness =1 ; + }else { + res.endianness =0 ; } - res |= (store <<4 ); + res.store = store;return res; }
trace/mem.h +27 -4
@@ -1,7 +1,7 @@/* * Helper functions for guest memory tracing * -* Copyright (C) 2016 Lluís Vilanova <[email protected]> +* Copyright (C) 2016-2017 Lluís Vilanova <[email protected]> * * This work is licensed under the terms of the GNU GPL, version 2 or later. * See the COPYING file in the top-level directory.
@@ -12,21 +12,44 @@#include "tcg/tcg.h" +/** +* TraceMemInfo: +* @size_shift: Memoy access size, interpreted as "1 << size_shift" bytes. +* @sign_extend: Whether the access is sign-extended. +* @endianness: Endinness type (0: little, 1: big). +* @store: Whether it's a store operation. +* +* Memory access information. +* +* NOTE: Keep in sync with QIMemInfo. +*/ +typedef struct TraceMemInfo { +union { +struct { +uint8_t size_shift :2 ; +bool sign_extend:1 ; +uint8_t endianness :1 ; +bool store :1 ; + }; +uint8_t raw; + }; +}TraceMemInfo ; +/** * trace_mem_get_info: * * Return a value for the 'info' argument in guest memory access traces. */ -static uint8_t trace_mem_get_info (TCGMemOp op,bool store); +static TraceMemInfo trace_mem_get_info (TCGMemOp op,bool store);/** * trace_mem_build_info: * * Return a value for the 'info' argument in guest memory access traces. */ -static uint8_t trace_mem_build_info (TCGMemOp size,bool sign_extend, -TCGMemOp endianness,bool store); +static TraceMemInfo trace_mem_build_info (TCGMemOp size,bool sign_extend, +TCGMemOp endianness,bool store);#include "trace/mem-internal.h"
PATCH v4 16/20 instrument: Add event 'guest_mem_before_trans'
In reply to Lluís Vilanova--- Makefile.target | 1 + instrument/control.c | 13 +++++++- instrument/control.h | 36 +++++++++++++++++++++- instrument/control.inc.h | 16 +++++++--- instrument/events.h | 21 +++++++++++++ instrument/events.inc.h | 19 ++++++++++++ instrument/load.c | 1 + instrument/qemu-instr/control.h | 15 +++++++++ instrument/qemu-instr/types.h | 64 +++++++++++++++++++++++++++++++++++++++ stubs/instrument.c | 4 ++ tcg/tcg-op.c | 5 +++ trace/control.h | 23 ++++++++++++++ trace/mem.h | 23 -------------- 13 files changed, 210 insertions(+), 31 deletions(-)
Makefile.target +1 -0
@@ -196,6 +196,7 @@ $(QEMU_PROG_BUILD): config-devices.mak COMMON_LDADDS = ../libqemuutil.a ../libqemustub.a # build either PROG or PROGW +$(QEMU_PROG_BUILD): CFLAGS += -DQEMU_TARGET_BUILD=1 $(QEMU_PROG_BUILD): $(all-obj-y) $(COMMON_LDADDS) $(call LINK, $(filter-out %.mak, $^)) ifdef CONFIG_DARWIN
instrument/control.c +12 -1
@@ -16,7 +16,7 @@#include "qom/cpu.h" -__threadInstrState instr_cur_state; +__threadInstrInfo instr_cur_info;unsigned int instr_cpus_count;
@@ -75,3 +75,14 @@ QI_VPUBLIC void qi_event_set_guest_cpu_reset(void (*fn)(QICPU vcpu))ERROR_IF (!instr_get_state (),"called outside instrumentation" );instr_set_event (guest_cpu_reset, fn); } + + +void (*instr_event__guest_mem_before_trans)( +QICPU vcpu_trans,QITCGv_cpu vcpu_exec,QITCGv vaddr,QIMemInfo info); + +QI_VPUBLIC void qi_event_set_guest_mem_before_trans( +void (*fn)(QICPU vcpu_trans,QITCGv_cpu vcpu_exec,QITCGv vaddr,QIMemInfo info)) +{ +ERROR_IF (!instr_get_state (),"called outside instrumentation" ); +instr_set_event (guest_mem_before_trans, fn); +}
instrument/control.h +34 -2
@@ -56,12 +56,21 @@ typedef enum {INSTR_STATE_ENABLE , } InstrState; +#define INSTR_MAX_TCG_REGS 16 + +typedef struct InstrInfo { +InstrState state; +unsigned int max; +void *tcg_regs[INSTR_MAX_TCG_REGS ]; +}InstrInfo ; +/** * instr_set_state: * -* Set the instrumentation state of the current host thread. +* Set the instrumentation state of the current host thread, and return its +* #InstrInfo. */ -static inline void instr_set_state (InstrState state); +static inline InstrInfo *instr_set_state (InstrState state);/** * instr_get_state:
@@ -70,6 +79,29 @@ static inline void instr_set_state(InstrState state);*/ static inline InstrState instr_get_state (void ); +/** +* instr_tcg_set: +* @info: Pointer to #InstrInfo. +* @num: Number of TCG register used by instrumentation. +* @arg: TCG register. +* +* Get a suitable QITCGv* from a TCGv* value. +*/ +#define instr_tcg_set (info, num, arg) \ + ({ \ + info->tcg_regs[num] = arg; \ + (void *)num; \ + }) + +/** +* instr_tcg_count: +* @info: Pointer to #InstrInfo. +* @count: Number of TCG registers used by instrumentation. +* +* Set the number of TCG registers used by instrumentation. +*/ +static inline void instr_tcg_count (InstrInfo *info,unsigned int count); +#include "instrument/control.inc.h"
instrument/control.inc.h +12 -4
@@ -15,16 +15,18 @@#include <stdint.h> -extern __threadInstrState instr_cur_state; +extern __threadInstrInfo instr_cur_info; -static inline void instr_set_state (InstrState state) +static inline InstrInfo *instr_set_state (InstrState state) { -atomic_store_release (&instr_cur_state, state); +InstrInfo *info = &instr_cur_info; +atomic_store_release (&info->state, state); +return info; }static inline InstrState instr_get_state (void ) { -return atomic_load_acquire (&instr_cur_state); +return atomic_load_acquire (&instr_cur_info.state); }
@@ -46,3 +48,9 @@ static inline QICPU instr_cpu_set(CPUState *vcpu)uintptr_t idx = vcpu->cpu_index;return (QICPU )idx; } + + +static inline void instr_tcg_count (InstrInfo *info,unsigned int count) +{ + info->max = count; +}
instrument/events.h +21 -0
@@ -12,6 +12,8 @@#include "instrument/qemu-instr/control.h" #include "instrument/qemu-instr/types.h" +#include "trace/control.h" +/** * instr_get_event:
@@ -30,6 +32,20 @@ atomic_store_release(&instr_event__ ## name, fn) +/* +* Re-define types used by some instrumentation events. We need some arbitrary +* definition for non-target objects. + */ +#if defined(QEMU_TARGET_BUILD ) +#include "tcg/tcg.h" +#else +typedef struct TCGv_d *TCGv ; +typedef struct TCGv_env_d *TCGv_env ; +typedef struct TCGv_i32_d *TCGv_i32 ; +typedef struct TCGv_i64_d *TCGv_i64 ; +#endif + +extern qi_fini_fn instr_event__fini_fn;extern void *instr_event__fini_data;
@@ -42,6 +58,11 @@ static inline void instr_guest_cpu_exit(CPUState *vcpu);extern void (*instr_event__guest_cpu_reset)(QICPU vcpu);static inline void instr_guest_cpu_reset (CPUState *vcpu); +extern void (*instr_event__guest_mem_before_trans)( +QICPU vcpu_trans,QITCGv_cpu vcpu_exec,QITCGv vaddr,QIMemInfo info); +static inline void instr_guest_mem_before_trans ( +CPUState *vcpu_trans,TCGv_env vcpu_exec,TCGv vaddr,TraceMemInfo info); +#include "instrument/events.inc.h"
instrument/events.inc.h +19 -0
@@ -8,6 +8,7 @@*/ #include "instrument/control.h" +#include "trace/control.h" static inline void instr_guest_cpu_enter (CPUState *vcpu)
@@ -42,3 +43,21 @@ static inline void instr_guest_cpu_reset(CPUState *vcpu)instr_set_state (INSTR_STATE_DISABLE ); } } + +static inline void instr_guest_mem_before_trans ( +CPUState *vcpu_trans,TCGv_env vcpu_exec,TCGv vaddr,TraceMemInfo info) +{ +void (*cb)(QICPU vcpu_trans,QITCGv_cpu vcpu_exec,QITCGv vaddr,QIMemInfo info) + =instr_get_event (guest_mem_before_trans); +if (cb) { +InstrInfo *iinfo =instr_set_state (INSTR_STATE_ENABLE ); +QICPU vcpu_trans_ =instr_cpu_set (vcpu_trans); +QITCGv_cpu vcpu_exec_ =instr_tcg_set (iinfo,0 , vcpu_exec); +QITCGv vaddr_ =instr_tcg_set (iinfo,1 , vaddr); +QIMemInfo info_; + info_.raw = info.raw; +instr_tcg_count (iinfo,2 ); + (*cb)(vcpu_trans_, vcpu_exec_, vaddr_, info_); +instr_set_state (INSTR_STATE_DISABLE ); + } +}
instrument/load.c +1 -0
@@ -151,6 +151,7 @@ InstrUnloadError instr_unload(int64_t handle_id)instr_set_event (guest_cpu_enter,NULL );instr_set_event (guest_cpu_exit,NULL );instr_set_event (guest_cpu_reset,NULL ); +instr_set_event (guest_mem_before_trans,NULL );/* this should never fail */ if (dlclose (handle->dlhandle) <0 ) {
instrument/qemu-instr/control.h +15 -0
@@ -98,6 +98,21 @@ void qi_event_set_guest_cpu_exit(void (*fn)(QICPU vcpu));*/ void qi_event_set_guest_cpu_reset (void (*fn)(QICPU vcpu)); +/* +* Start virtual memory access (before any potential access violation). +* +* @vaddr: Access' virtual address. +* @info : Access' information. +* +* Does not include memory accesses performed by devices. +* +* Mode: user, softmmu +* Targets: TCG(all) +* Time: trans +*/ +void qi_event_set_guest_mem_before_trans ( +void (*fn)(QICPU vcpu_trans,QITCGv_cpu vcpu_exec,QITCGv vaddr,QIMemInfo info)); + #ifdef __cplusplus }#endif
instrument/qemu-instr/types.h +64 -0
80 lines not on this page · raw message
stubs/instrument.c +3 -1
@@ -10,7 +10,9 @@#include "instrument/control.h" -__threadInstrState instr_cur_state; +__threadInstrInfo instr_cur_info;void (*instr_event__guest_cpu_enter)(QICPU *vcpu);void (*instr_event__guest_cpu_exit)(QICPU *vcpu);void (*instr_event__guest_cpu_reset)(QICPU *vcpu); +void (*instr_event__guest_mem_before_trans)( +QICPU vcpu_trans,QITCGv_cpu vcpu_exec,QITCGv vaddr,QIMemInfo info);
tcg/tcg-op.c +5 -0
@@ -26,6 +26,7 @@#include "qemu-common.h" #include "cpu.h" #include "exec/exec-all.h" +#include "instrument/events.h" #include "tcg.h" #include "tcg-op.h" #include "trace-tcg.h"
@@ -2667,6 +2668,7 @@ void tcg_gen_qemu_ld_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop)TraceMemInfo meminfo; memop =tcg_canonicalize_memop (memop,0 ,0 ); meminfo =trace_mem_get_info (memop,0 ); +instr_guest_mem_before_trans (tcg_ctx.cpu, tcg_ctx.tcg_env, addr, meminfo);trace_guest_mem_before_tcg (tcg_ctx.cpu, tcg_ctx.tcg_env, addr, meminfo.raw);gen_ldst_i32 (INDEX_op_qemu_ld_i32, val, addr, memop, idx); }
@@ -2676,6 +2678,7 @@ void tcg_gen_qemu_st_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop)TraceMemInfo meminfo; memop =tcg_canonicalize_memop (memop,0 ,1 ); meminfo =trace_mem_get_info (memop,1 ); +instr_guest_mem_before_trans (tcg_ctx.cpu, tcg_ctx.tcg_env, addr, meminfo);trace_guest_mem_before_tcg (tcg_ctx.cpu, tcg_ctx.tcg_env, addr, meminfo.raw);gen_ldst_i32 (INDEX_op_qemu_st_i32, val, addr, memop, idx); }
@@ -2696,6 +2699,7 @@ void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) memop =tcg_canonicalize_memop (memop,1 ,0 ); meminfo =trace_mem_get_info (memop,0 ); +instr_guest_mem_before_trans (tcg_ctx.cpu, tcg_ctx.tcg_env, addr, meminfo);trace_guest_mem_before_tcg (tcg_ctx.cpu, tcg_ctx.tcg_env, addr, meminfo.raw);gen_ldst_i64 (INDEX_op_qemu_ld_i64, val, addr, memop, idx); }
@@ -2711,6 +2715,7 @@ void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) memop =tcg_canonicalize_memop (memop,1 ,1 ); meminfo =trace_mem_get_info (memop,1 ); +instr_guest_mem_before_trans (tcg_ctx.cpu, tcg_ctx.tcg_env, addr, meminfo);trace_guest_mem_before_tcg (tcg_ctx.cpu, tcg_ctx.tcg_env, addr, meminfo.raw);gen_ldst_i64 (INDEX_op_qemu_st_i64, val, addr, memop, idx); }
trace/control.h +23 -0
@@ -20,6 +20,29 @@ typedef struct TraceEventIter {const char *pattern; } TraceEventIter; +/** +* TraceMemInfo: +* @size_shift: Memoy access size, interpreted as "1 << size_shift" bytes. +* @sign_extend: Whether the access is sign-extended. +* @endianness: Endinness type (0: little, 1: big). +* @store: Whether it's a store operation. +* +* Memory access information. +* +* NOTE: Keep in sync with QIMemInfo. +*/ +typedef struct TraceMemInfo { +union { +struct { +uint8_t size_shift :2 ; +bool sign_extend:1 ; +uint8_t endianness :1 ; +bool store :1 ; + }; +uint8_t raw; + }; +}TraceMemInfo ; +/** * trace_event_iter_init:
trace/mem.h +0 -23
@@ -12,29 +12,6 @@#include "tcg/tcg.h" -/** -* TraceMemInfo: -* @size_shift: Memoy access size, interpreted as "1 << size_shift" bytes. -* @sign_extend: Whether the access is sign-extended. -* @endianness: Endinness type (0: little, 1: big). -* @store: Whether it's a store operation. -* -* Memory access information. -* -* NOTE: Keep in sync with QIMemInfo. -*/ -typedef struct TraceMemInfo { -union { -struct { -uint8_t size_shift :2 ; -bool sign_extend:1 ; -uint8_t endianness :1 ; -bool store :1 ; - }; -uint8_t raw; - }; -}TraceMemInfo ; -/** * trace_mem_get_info:
PATCH v4 17/20 instrument: Add event 'guest_mem_before_exec'
In reply to Lluís Vilanova--- include/exec/cpu_ldst_template.h | 4 +++ include/exec/cpu_ldst_useronly_template.h | 4 +++ include/exec/helper-gen.h | 1 + include/exec/helper-proto.h | 1 + include/exec/helper-tcg.h | 1 + instrument/control.c | 35 +++++++++++++++++++++++++++++ instrument/control.h | 15 ++++++++++++ instrument/events.h | 5 ++++ instrument/events.inc.h | 18 ++++++++++++++- instrument/helpers.h | 1 + instrument/load.c | 1 + instrument/qemu-instr/control.h | 21 +++++++++++++++++ stubs/instrument.c | 2 ++ 13 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 instrument/helpers.h
include/exec/cpu_ldst_template.h +4 -0
@@ -28,6 +28,7 @@#include "trace-root.h" #endif +#include "instrument/events.h" #include "trace/mem.h" #if DATA_SIZE ==8
@@ -89,6 +90,7 @@ glue(glue(glue(cpu_ld, USUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,#if !defined(SOFTMMU_CODE_ACCESS )TraceMemInfo meminfo =trace_mem_build_info (SHIFT , false,MO_TE , false); +instr_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo);trace_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo.raw);#endif
@@ -126,6 +128,7 @@ glue(glue(glue(cpu_lds, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,#if !defined(SOFTMMU_CODE_ACCESS )TraceMemInfo meminfo =trace_mem_build_info (SHIFT , true,MO_TE , false); +instr_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo);trace_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo.raw);#endif
@@ -167,6 +170,7 @@ glue(glue(glue(cpu_st, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,#if !defined(SOFTMMU_CODE_ACCESS )TraceMemInfo meminfo =trace_mem_build_info (SHIFT , false,MO_TE , true); +instr_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo);trace_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo.raw);#endif
include/exec/cpu_ldst_useronly_template.h +4 -0
@@ -27,6 +27,7 @@#include "trace-root.h" #endif +#include "instrument/events.h" #include "trace/mem.h" #if DATA_SIZE ==8
@@ -62,6 +63,7 @@ glue(glue(cpu_ld, USUFFIX), MEMSUFFIX)(CPUArchState *env, target_ulong ptr) {#if !defined(CODE_ACCESS )TraceMemInfo meminfo =trace_mem_build_info (DATA_SIZE , false,MO_TE , false); +instr_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo);trace_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo.raw);#endif return glue (glue (ld,USUFFIX ), _p)(g2h (ptr));
@@ -81,6 +83,7 @@ glue(glue(cpu_lds, SUFFIX), MEMSUFFIX)(CPUArchState *env, target_ulong ptr) {#if !defined(CODE_ACCESS )TraceMemInfo meminfo =trace_mem_build_info (DATA_SIZE , true,MO_TE , false); +instr_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo);trace_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo.raw);#endif return glue (glue (lds,SUFFIX ), _p)(g2h (ptr));
@@ -102,6 +105,7 @@ glue(glue(cpu_st, SUFFIX), MEMSUFFIX)(CPUArchState *env, target_ulong ptr, {#if !defined(CODE_ACCESS )TraceMemInfo meminfo =trace_mem_build_info (DATA_SIZE , false,MO_TE , true); +instr_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo);trace_guest_mem_before_exec (ENV_GET_CPU (env), ptr, meminfo.raw);#endif glue (glue (st,SUFFIX ), _p)(g2h (ptr), v);
include/exec/helper-gen.h +1 -0
@@ -57,6 +57,7 @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \ }#include "helper.h" +#include "instrument/helpers.h" #include "trace/generated-helpers.h" #include "trace/generated-helpers-wrappers.h" #include "tcg-runtime.h"
include/exec/helper-proto.h +1 -0
@@ -27,6 +27,7 @@ dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \ dh_ctype(t4), dh_ctype(t5));#include "helper.h" +#include "instrument/helpers.h" #include "trace/generated-helpers.h" #include "tcg-runtime.h"
include/exec/helper-tcg.h +1 -0
@@ -40,6 +40,7 @@ | dh_sizemask(t5, 5) },#include "helper.h" +#include "instrument/helpers.h" #include "trace/generated-helpers.h" #include "tcg-runtime.h"
instrument/control.c +35 -0
@@ -14,6 +14,8 @@#include "instrument/qemu-instr/control.h" #include "instrument/qemu-instr/visibility.h" #include "qom/cpu.h" +#include "exec/helper-proto.h" +#include "exec/helper-gen.h" __threadInstrInfo instr_cur_info;
@@ -86,3 +88,36 @@ QI_VPUBLIC void qi_event_set_guest_mem_before_trans(ERROR_IF (!instr_get_state (),"called outside instrumentation" );instr_set_event (guest_mem_before_trans, fn); } + + +QI_VPUBLIC void qi_event_gen_guest_mem_before_exec( +QITCGv_cpu vcpu,QITCGv vaddr,QIMemInfo info) +{ +ERROR_IF (instr_get_state () !=INSTR_STATE_ENABLE_TCG , +"called outside instrumentation" ); +InstrInfo *iinfo = &instr_cur_info; +TCGv_env vcpu_ =instr_tcg_get (iinfo, vcpu); +TCGv vaddr_ =instr_tcg_get (iinfo, vaddr); +TCGv_i32 info_ =tcg_const_i32 (info.raw); +gen_helper_instr_guest_mem_before_exec (vcpu_, vaddr_, info_); +tcg_temp_free_i32 (info_); +} + +void helper_instr_guest_mem_before_exec ( +CPUArchState * vcpu,target_ulong vaddr,uint32_t info) +{ +TraceMemInfo info_; + info_.raw = info; +instr_guest_mem_before_exec (ENV_GET_CPU (vcpu), vaddr, info_); +} + + +void (*instr_event__guest_mem_before_exec)( +QICPU vcpu,uint64_t vaddr,QIMemInfo info); + +QI_VPUBLIC void qi_event_set_guest_mem_before_exec( +void (*fn)(QICPU vcpu,uint64_t vaddr,QIMemInfo info)) +{ +ERROR_IF (!instr_get_state (),"called outside instrumentation" ); +instr_set_event (guest_mem_before_exec, fn); +}
instrument/control.h +15 -0
@@ -54,6 +54,7 @@ static inline QICPU instr_cpu_set(CPUState *vcpu);typedef enum {INSTR_STATE_DISABLE ,INSTR_STATE_ENABLE , +INSTR_STATE_ENABLE_TCG , }InstrState ;#define INSTR_MAX_TCG_REGS 16
@@ -102,6 +103,20 @@ static inline InstrState instr_get_state(void);*/ static inline void instr_tcg_count (InstrInfo *info,unsigned int count); +/** +* instr_tcg_get: +* @info: Pointer to #InstrInfo. +* @arg: QITCG register. +* +* Get a suitable TCGv* from a QITCGv* value. +*/ +#define instr_tcg_get (info, arg) \ + ({ \ + unsigned int idx = (uintptr_t)arg; \ + ERROR_IF(info->max <= idx, "invalid QITCGv register"); \ + info->tcg_regs[idx]; \ + }) +#include "instrument/control.inc.h"
instrument/events.h +5 -0
@@ -63,6 +63,11 @@ extern void (*instr_event__guest_mem_before_trans)(static inline void instr_guest_mem_before_trans (CPUState *vcpu_trans,TCGv_env vcpu_exec,TCGv vaddr,TraceMemInfo info); +extern void (*instr_event__guest_mem_before_exec)( +QICPU vcpu,uint64_t vaddr,QIMemInfo info); +static inline void instr_guest_mem_before_exec ( +CPUState *vcpu,uint64_t vaddr,TraceMemInfo info); +#include "instrument/events.inc.h"
instrument/events.inc.h +17 -1
@@ -50,7 +50,7 @@ static inline void instr_guest_mem_before_trans(void (*cb)(QICPU vcpu_trans,QITCGv_cpu vcpu_exec,QITCGv vaddr,QIMemInfo info) =instr_get_event (guest_mem_before_trans);if (cb) { -InstrInfo *iinfo =instr_set_state (INSTR_STATE_ENABLE ); +InstrInfo *iinfo =instr_set_state (INSTR_STATE_ENABLE_TCG );QICPU vcpu_trans_ =instr_cpu_set (vcpu_trans);QITCGv_cpu vcpu_exec_ =instr_tcg_set (iinfo,0 , vcpu_exec);QITCGv vaddr_ =instr_tcg_set (iinfo,1 , vaddr);
@@ -61,3 +61,19 @@ static inline void instr_guest_mem_before_trans(instr_set_state (INSTR_STATE_DISABLE ); } } + +static inline void instr_guest_mem_before_exec ( +CPUState *vcpu,uint64_t vaddr,TraceMemInfo info) +{ +void (*cb)(QICPU vcpu,uint64_t vaddr,QIMemInfo info) + =instr_get_event (guest_mem_before_exec); +if (cb) { +InstrInfo *iinfo =instr_set_state (INSTR_STATE_ENABLE ); +QICPU vcpu_ =instr_cpu_set (vcpu); +QIMemInfo info_; + info_.raw = info.raw; +instr_tcg_count (iinfo,2 ); + (*cb)(vcpu_, vaddr, info_); +instr_set_state (INSTR_STATE_DISABLE ); + } +}
instrument/helpers.h new file +1 -0
@@ -0,0 +1 @@ +DEF_HELPER_FLAGS_3 (instr_guest_mem_before_exec,TCG_CALL_NO_RWG , void, env, tl, i32)
instrument/load.c +1 -0
@@ -152,6 +152,7 @@ InstrUnloadError instr_unload(int64_t handle_id)instr_set_event (guest_cpu_exit,NULL );instr_set_event (guest_cpu_reset,NULL );instr_set_event (guest_mem_before_trans,NULL ); +instr_set_event (guest_mem_before_exec,NULL );/* this should never fail */ if (dlclose (handle->dlhandle) <0 ) {
instrument/qemu-instr/control.h +21 -0
@@ -113,6 +113,27 @@ void qi_event_set_guest_cpu_reset(void (*fn)(QICPU vcpu));void qi_event_set_guest_mem_before_trans (void (*fn)(QICPU vcpu_trans,QITCGv_cpu vcpu_exec,QITCGv vaddr,QIMemInfo info)); +/* +* Generate code to trigger a 'guest_mem_before_exec' from +* 'guest_mem_before_trans'. +* +* Mode: user, softmmu +* Targets: TCG(all) +* Time: trans +*/ +void qi_event_gen_guest_mem_before_exec ( +QITCGv_cpu vcpu,QITCGv vaddr,QIMemInfo info); + +/* +* Execution-time equivalent of 'guest_mem_before_trans'. +* +* Mode: user, softmmu +* Targets: TCG(all) +* Time: exec +*/ +void qi_event_set_guest_mem_before_exec ( +void (*fn)(QICPU vcpu,uint64_t vaddr,QIMemInfo info)); + #ifdef __cplusplus }#endif
stubs/instrument.c +2 -0
@@ -16,3 +16,5 @@ void (*instr_event__guest_cpu_exit)(QICPU *vcpu);void (*instr_event__guest_cpu_reset)(QICPU *vcpu);void (*instr_event__guest_mem_before_trans)(QICPU vcpu_trans,QITCGv_cpu vcpu_exec,QITCGv vaddr,QIMemInfo info); +void (*instr_event__guest_mem_before_exec)( +QICPU vcpu_trans,QITCGv_cpu vcpu_exec,QITCGv vaddr,QIMemInfo info);
PATCH v4 18/20 instrument: Add event 'guest_user_syscall'
In reply to Lluís Vilanova--- bsd-user/syscall.c | 3 +++ instrument/control.c | 14 ++++++++++++++ instrument/events.h | 7 +++++++ instrument/events.inc.h | 16 ++++++++++++++++ instrument/load.c | 1 + instrument/qemu-instr/control.h | 15 +++++++++++++++ linux-user/syscall.c | 1 + stubs/instrument.c | 3 +++ 8 files changed, 60 insertions(+)
bsd-user/syscall.c +3 -0
@@ -324,6 +324,7 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,#ifdef DEBUG gemu_log ("freebsd syscall %d\n" , num);#endif +instr_guest_user_syscall (cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);trace_guest_user_syscall (cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);if (do_strace)print_freebsd_syscall (num, arg1, arg2, arg3, arg4, arg5, arg6);
@@ -423,6 +424,7 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,#ifdef DEBUG gemu_log ("netbsd syscall %d\n" , num);#endif +instr_guest_user_syscall (cpu, num, arg1, arg2, arg3, arg4, arg5, arg6,0 ,0 );trace_guest_user_syscall (cpu, num, arg1, arg2, arg3, arg4, arg5, arg6,0 ,0 );if (do_strace)print_netbsd_syscall (num, arg1, arg2, arg3, arg4, arg5, arg6);
@@ -499,6 +501,7 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,#ifdef DEBUG gemu_log ("openbsd syscall %d\n" , num);#endif +instr_guest_user_syscall (cpu, num, arg1, arg2, arg3, arg4, arg5, arg6,0 ,0 );trace_guest_user_syscall (cpu, num, arg1, arg2, arg3, arg4, arg5, arg6,0 ,0 );if (do_strace)print_openbsd_syscall (num, arg1, arg2, arg3, arg4, arg5, arg6);
instrument/control.c +14 -0
@@ -121,3 +121,17 @@ QI_VPUBLIC void qi_event_set_guest_mem_before_exec(ERROR_IF (!instr_get_state (),"called outside instrumentation" );instr_set_event (guest_mem_before_exec, fn); } + + +void (*instr_event__guest_user_syscall)( +QICPU vcpu,uint64_t num,uint64_t arg1,uint64_t arg2,uint64_t arg3, +uint64_t arg4,uint64_t arg5,uint64_t arg6,uint64_t arg7,uint64_t arg8); + +QI_VPUBLIC void qi_event_set_guest_user_syscall( +void (*fn)(QICPU vcpu,uint64_t num,uint64_t arg1,uint64_t arg2, +uint64_t arg3,uint64_t arg4,uint64_t arg5,uint64_t arg6, +uint64_t arg7,uint64_t arg8)) +{ +ERROR_IF (!instr_get_state (),"called outside instrumentation" ); +instr_set_event (guest_user_syscall, fn); +}
instrument/events.h +7 -0
@@ -68,6 +68,13 @@ extern void (*instr_event__guest_mem_before_exec)(static inline void instr_guest_mem_before_exec (CPUState *vcpu,uint64_t vaddr,TraceMemInfo info); +extern void (*instr_event__guest_user_syscall)( +QICPU vcpu,uint64_t num,uint64_t arg1,uint64_t arg2,uint64_t arg3, +uint64_t arg4,uint64_t arg5,uint64_t arg6,uint64_t arg7,uint64_t arg8); +static inline void instr_guest_user_syscall ( +CPUState *vcpu,uint64_t num,uint64_t arg1,uint64_t arg2,uint64_t arg3, +uint64_t arg4,uint64_t arg5,uint64_t arg6,uint64_t arg7,uint64_t arg8); +#include "instrument/events.inc.h"
instrument/events.inc.h +16 -0
@@ -77,3 +77,19 @@ static inline void instr_guest_mem_before_exec(instr_set_state (INSTR_STATE_DISABLE ); } } + +static inline void instr_guest_user_syscall ( +CPUState *vcpu,uint64_t num,uint64_t arg1,uint64_t arg2,uint64_t arg3, +uint64_t arg4,uint64_t arg5,uint64_t arg6,uint64_t arg7,uint64_t arg8) +{ +void (*cb)(QICPU vcpu,uint64_t num,uint64_t arg1,uint64_t arg2, +uint64_t arg3,uint64_t arg4,uint64_t arg5,uint64_t arg6, +uint64_t arg7,uint64_t arg8) + =instr_get_event (guest_user_syscall); +if (cb) { +instr_set_state (INSTR_STATE_ENABLE ); +QICPU vcpu_ =instr_cpu_set (vcpu); + (*cb)(vcpu_, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); +instr_set_state (INSTR_STATE_DISABLE ); + } +}
instrument/load.c +1 -0
@@ -153,6 +153,7 @@ InstrUnloadError instr_unload(int64_t handle_id)instr_set_event (guest_cpu_reset,NULL );instr_set_event (guest_mem_before_trans,NULL );instr_set_event (guest_mem_before_exec,NULL ); +instr_set_event (guest_user_syscall,NULL );/* this should never fail */ if (dlclose (handle->dlhandle) <0 ) {
instrument/qemu-instr/control.h +15 -0
@@ -134,6 +134,21 @@ void qi_event_gen_guest_mem_before_exec(void qi_event_set_guest_mem_before_exec (void (*fn)(QICPU vcpu,uint64_t vaddr,QIMemInfo info)); +/* +* Start executing a guest system call in syscall emulation mode. +* +* @num: System call number. +* @arg*: System call argument value. +* +* Mode: user +* Targets: TCG(all) +* Time: exec +*/ +void qi_event_set_guest_user_syscall ( +void (*fn)(QICPU vcpu,uint64_t num,uint64_t arg1,uint64_t arg2, +uint64_t arg3,uint64_t arg4,uint64_t arg5,uint64_t arg6, +uint64_t arg7,uint64_t arg8)); + #ifdef __cplusplus }#endif
linux-user/syscall.c +1 -0
@@ -7723,6 +7723,7 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,#ifdef DEBUG gemu_log ("syscall %d" , num);#endif +instr_guest_user_syscall (cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);trace_guest_user_syscall (cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);if (do_strace)print_syscall (num, arg1, arg2, arg3, arg4, arg5, arg6);
stubs/instrument.c +3 -0
@@ -18,3 +18,6 @@ void (*instr_event__guest_mem_before_trans)( QICPU vcpu_trans, QITCGv_cpu vcpu_exec, QITCGv vaddr, QIMemInfo info);void (*instr_event__guest_mem_before_exec)(QICPU vcpu_trans,QITCGv_cpu vcpu_exec,QITCGv vaddr,QIMemInfo info); +void (*instr_event__guest_user_syscall)( +QICPU vcpu,uint64_t num,uint64_t arg1,uint64_t arg2,uint64_t arg3, +uint64_t arg4,uint64_t arg5,uint64_t arg6,uint64_t arg7,uint64_t arg8);
PATCH v4 19/20 instrument: Add event 'guest_user_syscall_ret'
In reply to Lluís Vilanova--- bsd-user/syscall.c | 3 +++ instrument/control.c | 11 +++++++++++ instrument/events.h | 5 +++++ instrument/events.inc.h | 13 +++++++++++++ instrument/load.c | 1 + instrument/qemu-instr/control.h | 13 +++++++++++++ linux-user/syscall.c | 1 + stubs/instrument.c | 2 ++ 8 files changed, 49 insertions(+)
bsd-user/syscall.c +3 -0
@@ -406,6 +406,7 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,#endif if (do_strace)print_freebsd_syscall_ret (num, ret); +instr_guest_user_syscall_ret (cpu, num, ret);trace_guest_user_syscall_ret (cpu, num, ret);return ret; efault:
@@ -483,6 +484,7 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,#endif if (do_strace)print_netbsd_syscall_ret (num, ret); +instr_guest_user_syscall_ret (cpu, num, ret);trace_guest_user_syscall_ret (cpu, num, ret);return ret; efault:
@@ -560,6 +562,7 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,#endif if (do_strace)print_openbsd_syscall_ret (num, ret); +instr_guest_user_syscall_ret (cpu, num, ret);trace_guest_user_syscall_ret (cpu, num, ret);return ret; efault:
instrument/control.c +11 -0
@@ -135,3 +135,14 @@ QI_VPUBLIC void qi_event_set_guest_user_syscall(ERROR_IF (!instr_get_state (),"called outside instrumentation" );instr_set_event (guest_user_syscall, fn); } + + +void (*instr_event__guest_user_syscall_ret)( +QICPU vcpu,uint64_t num,uint64_t ret); + +QI_VPUBLIC void qi_event_set_guest_user_syscall_ret( +void (*fn)(QICPU vcpu,uint64_t num,uint64_t ret)) +{ +ERROR_IF (!instr_get_state (),"called outside instrumentation" ); +instr_set_event (guest_user_syscall_ret, fn); +}
instrument/events.h +5 -0
@@ -75,6 +75,11 @@ static inline void instr_guest_user_syscall( CPUState *vcpu, uint64_t num, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6, uint64_t arg7, uint64_t arg8); +extern void (*instr_event__guest_user_syscall_ret)( +QICPU vcpu,uint64_t num,uint64_t ret); +static inline void instr_guest_user_syscall_ret ( +CPUState *vcpu,uint64_t num,uint64_t ret); +#include "instrument/events.inc.h"
instrument/events.inc.h +13 -0
@@ -93,3 +93,16 @@ static inline void instr_guest_user_syscall(instr_set_state (INSTR_STATE_DISABLE ); } } + +static inline void instr_guest_user_syscall_ret ( +CPUState *vcpu,uint64_t num,uint64_t ret) +{ +void (*cb)(QICPU vcpu,uint64_t num,uint64_t ret) + =instr_get_event (guest_user_syscall_ret); +if (cb) { +instr_set_state (INSTR_STATE_ENABLE ); +QICPU vcpu_ =instr_cpu_set (vcpu); + (*cb)(vcpu_, num, ret); +instr_set_state (INSTR_STATE_DISABLE ); + } +}
instrument/load.c +1 -0
@@ -154,6 +154,7 @@ InstrUnloadError instr_unload(int64_t handle_id)instr_set_event (guest_mem_before_trans,NULL );instr_set_event (guest_mem_before_exec,NULL );instr_set_event (guest_user_syscall,NULL ); +instr_set_event (guest_user_syscall_ret,NULL );/* this should never fail */ if (dlclose (handle->dlhandle) <0 ) {
instrument/qemu-instr/control.h +13 -0
@@ -149,6 +149,19 @@ void qi_event_set_guest_user_syscall( uint64_t arg3, uint64_t arg4, uint64_t arg5, uint64_t arg6, uint64_t arg7, uint64_t arg8)); +/* +* Finish executing a guest system call in syscall emulation mode. +* +* @num: System call number. +* @ret: System call result value. +* +* Mode: user +* Targets: TCG(all) +* Time: exec +*/ +void qi_event_set_guest_user_syscall_ret ( +void (*fn)(QICPU vcpu,uint64_t num,uint64_t ret)); + #ifdef __cplusplus }#endif
linux-user/syscall.c +1 -0
@@ -12397,6 +12397,7 @@ fail:#endif if (do_strace)print_syscall_ret (num, ret); +instr_guest_user_syscall_ret (cpu, num, ret);trace_guest_user_syscall_ret (cpu, num, ret);return ret; efault:
stubs/instrument.c +2 -0
@@ -21,3 +21,5 @@ void (*instr_event__guest_mem_before_exec)(void (*instr_event__guest_user_syscall)(QICPU vcpu,uint64_t num,uint64_t arg1,uint64_t arg2,uint64_t arg3,uint64_t arg4,uint64_t arg5,uint64_t arg6,uint64_t arg7,uint64_t arg8); +void (*instr_event__guest_user_syscall_ret)( +QICPU vcpu,uint64_t num,uint64_t ret);
PATCH v4 20/20 instrument: Add API to manipulate guest memory
In reply to Lluís VilanovaIt includes access to the guest's memory and vCPU registers.
--- instrument/Makefile.objs | 1 instrument/qemu-instr/state.h | 104 +++++++++++++++++++++++++++++++++++++++++ instrument/state.c | 72 ++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 instrument/qemu-instr/state.h create mode 100644 instrument/state.c
instrument/Makefile.objs +1 -0
@@ -6,3 +6,4 @@ target-obj-y += qmp.o target-obj-$(CONFIG_INSTRUMENT) += control.o target-obj-$(CONFIG_INSTRUMENT) += trace.o +target-obj-$(CONFIG_INSTRUMENT) += state.o
instrument/qemu-instr/state.h new file +104 -0
104 lines not on this page · raw message
instrument/state.c new file +72 -0
72 lines not on this page · raw message
Quoted 4 lines · Lluís Vilanova
This series adds an API to add instrumentation events.
It also provides additional APIs for:
* Controlling tracing events
hmm didn't Stefan say that tracing should be decoupled from this?
Quoted 7 lines
* Peek/poke guest memory
There's still missing APIs for (can be added in later series?):
* Provide something like tracing's per-vCPU trace states (i.e., so that each vCPU can have different instrumentation code). 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).
As I said in the description of my alternative implementation [*], I don't see much value in having per-vCPU events, as most instrumenters just care about the guest application/system. I can only think of cases where the instrumenter is only interested in a guest process (in system-mode), but that'd be ugly anyway (would need to change both QEMU and the guest kernel to track the pid).
If the need ever arises, we could add __vcpu(cpu_index) registration functions.
[*] https://lists.gnu.org/archive/html/qemu-devel/2017-09/msg01446.html
E.
Quoted 16 lines · Emilio G Cota
Quoted 4 lines · Lluís Vilanova
This series adds an API to add instrumentation events.
It also provides additional APIs for:
* Controlling tracing eventshmm didn't Stefan say that tracing should be decoupled from this?
Quoted 7 lines
* Peek/poke guest memory
There's still missing APIs for (can be added in later series?):
* Provide something like tracing's per-vCPU trace states (i.e., so that each vCPU can have different instrumentation code). 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).
Quoted 5 lines
As I said in the description of my alternative implementation [*], I don't see much value in having per-vCPU events, as most instrumenters just care about the guest application/system. I can only think of cases where the instrumenter is only interested in a guest process (in system-mode), but that'd be ugly anyway (would need to change both QEMU and the guest kernel to track the pid).
Yes, that's exactly what I was using it for (track guest processes in softmmu mode).
Quoted 1 line
If the need ever arises, we could add
__vcpu(cpu_index)registration functions.
You still need the functionality I cited if you're using "qi_event_gen_guest_mem_before_exec" or similar.
Quoted 3 lines
[*] https://lists.gnu.org/archive/html/qemu-devel/2017-09/msg01446.html
E.
Cheers,
Lluis
Quoted 7 lines · Emilio G Cota
Quoted 4 lines · Lluís Vilanova
This series adds an API to add instrumentation events.
It also provides additional APIs for:
* Controlling tracing eventshmm didn't Stefan say that tracing should be decoupled from this?
I understood decoupling instr from the tracing infrastructure (since tracing events are defined as not stable, and instr must be stable by definition).
Quoted 14 lines
Quoted 7 lines
* Peek/poke guest memory
There's still missing APIs for (can be added in later series?):
* Provide something like tracing's per-vCPU trace states (i.e., so that each vCPU can have different instrumentation code). 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).As I said in the description of my alternative implementation [*], I don't see much value in having per-vCPU events, as most instrumenters just care about the guest application/system. I can only think of cases where the instrumenter is only interested in a guest process (in system-mode), but that'd be ugly anyway (would need to change both QEMU and the guest kernel to track the pid).
Quoted 3 lines
If the need ever arises, we could add
__vcpu(cpu_index)registration functions.[*] https://lists.gnu.org/archive/html/qemu-devel/2017-09/msg01446.html
Sorry, your series slipped my radar. I'll take a look at it.
Thanks,
Lluis
Quoted 13 lines · Lluís Vilanova
This series adds an API to add instrumentation events.
It also provides additional APIs for:
* Controlling tracing events
* Peek/poke guest memoryThere's still missing APIs for (can be added in later series?):
* Provide something like tracing's per-vCPU trace states (i.e., so that each vCPU can have different instrumentation code). 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).
* Peek/poke guest registers
Quoted 4 lines
The instrumentation code is dynamically loaded as a library into QEMU either when it starts or later using its remote control interfaces.
Signed-off-by Lluís Vilanova <[email protected]>
Doesn't apply to current master, and appears to have whitespace errors. Please rebase and use scripts/checkpatch.pl to tidy up.
Quoted 13 lines · Lluís Vilanova
This series adds an API to add instrumentation events.
It also provides additional APIs for:
* Controlling tracing events
* Peek/poke guest memoryThere's still missing APIs for (can be added in later series?):
* Provide something like tracing's per-vCPU trace states (i.e., so that each vCPU can have different instrumentation code). 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).
* Peek/poke guest registers
Quoted 4 lines
The instrumentation code is dynamically loaded as a library into QEMU either when it starts or later using its remote control interfaces.
Signed-off-by Lluís Vilanova <[email protected]>
Taking a step back.
This looks like a way to dynamically load arbitrary code. What interfaces can this code use? Your cover letter should answer this.
As long as the answer is "everything the dynamic linker is willing to resolve", this series heading nowhere. We can talk about an interface for plugins, but "anything goes" is not on the menu.
Quoted 20 lines · Markus Armbruster
Quoted 13 lines · Lluís Vilanova
This series adds an API to add instrumentation events.
It also provides additional APIs for:
* Controlling tracing events
* Peek/poke guest memoryThere's still missing APIs for (can be added in later series?):
* Provide something like tracing's per-vCPU trace states (i.e., so that each vCPU can have different instrumentation code). 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).
* Peek/poke guest registersQuoted 4 lines
The instrumentation code is dynamically loaded as a library into QEMU either when it starts or later using its remote control interfaces.
Signed-off-by Lluís Vilanova <[email protected]>
Quoted 8 lines
Taking a step back.
This looks like a way to dynamically load arbitrary code. What interfaces can this code use? Your cover letter should answer this.
As long as the answer is "everything the dynamic linker is willing to resolve", this series heading nowhere. We can talk about an interface for plugins, but "anything goes" is not on the menu.
A simple solution to this is to only export the API symbols by passing --dynamic-file to the linker -- see patch 2 of the following series for an example (ELF-only, although I'm pretty sure this can be achieved on Windows as well):
https://lists.gnu.org/archive/html/qemu-devel/2017-09/msg01446.html
Thanks,
Emilio
Quoted 30 lines · Emilio G Cota
Quoted 20 lines · Markus Armbruster
Quoted 13 lines · Lluís Vilanova
This series adds an API to add instrumentation events.
It also provides additional APIs for:
* Controlling tracing events
* Peek/poke guest memoryThere's still missing APIs for (can be added in later series?):
* Provide something like tracing's per-vCPU trace states (i.e., so that each vCPU can have different instrumentation code). 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).
* Peek/poke guest registersQuoted 4 lines
The instrumentation code is dynamically loaded as a library into QEMU either when it starts or later using its remote control interfaces.
Signed-off-by Lluís Vilanova <[email protected]>Quoted 8 lines
Taking a step back.
This looks like a way to dynamically load arbitrary code. What interfaces can this code use? Your cover letter should answer this.
As long as the answer is "everything the dynamic linker is willing to resolve", this series heading nowhere. We can talk about an interface for plugins, but "anything goes" is not on the menu.
Quoted 5 lines
A simple solution to this is to only export the API symbols by passing --dynamic-file to the linker -- see patch 2 of the following series for an example (ELF-only, although I'm pretty sure this can be achieved on Windows as well):
https://lists.gnu.org/archive/html/qemu-devel/2017-09/msg01446.html
Sorry, I adapted the instr series in a rush and missed your series. I'm now preparing a new version that fixes this without the flags you mention (missed to add a line in this series).
Thanks,
Lluis