RFC Plugin support
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v2 RFC Latest38 patches 23 repliesIn review
- v1 RFC48 patches 83 repliesSuperseded
Changes in v2 from the cover letter
- Drop the 2-pass translation. Instead, empty instrumentation is injected during translation. If it turns out that this empty instrumentation is not needed, it is removed from the output. For this, add 2 TCG ops that mark the beginning and end of this empty instrumentation.
Patches in v2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/38 | trace: expand mem_info:size_shift to 3 bitstrace-events | +1 | 1 reply | |
| 2/38 | tcg/README: fix typo s/afterwise/afterwards/tcg/ | +1 | 0 replies | |
| 3/38 | cpu: introduce cpu_in_exclusive_work_context()cpus-common.c include/ | +15 | 1 reply | |
| 4/38 | translate-all: use cpu_in_exclusive_work_context() in tb_flushaccel/ | +7 | 1 reply | |
| 5/38 | plugin: add user-facing APIinclude/ | +241 | 8 replies | |
| 6/38 | plugin: add core codeMakefile Makefile.target include/ +2 more | +1297 | 3 replies | |
| 7/38 | queue: add QTAILQ_REMOVE_SEVERALinclude/ | +10 | 2 replies | |
| 8/38 | tcg: drop nargs from tcg_op_insert_{before, after}tcg/ tcg/ tcg/ | +8 | 1 reply | |
| 9/38 | cputlb: introduce get_page_addr_code_hostpaccel/ include/ | +26 | 1 reply | |
| 10/38 | plugin-gen: add module for TCG-related codeaccel/ accel/ accel/ +8 more | +1204 | 0 replies | |
| 11/38 | tcg: add tcg_gen_st_ptrtcg/ | +5 | 1 reply | |
| 12/38 | tcg: add MO_HADDR to TCGMemOptcg/ | +7 | 0 replies | |
| 13/38 | atomic_template: fix indentation in GEN_ATOMIC_HELPERaccel/ | +1 | 0 replies | |
| 14/38 | atomic_template: add inline trace/plugin helpersaccel/ | +75 | 0 replies | |
| 15/38 | tcg: let plugins instrument memory accessesaccel/ accel/ accel/ +8 more | +169 | 2 replies | |
| 16/38 | translate-all: notify plugin code of tb_flushaccel/ | +6 | 0 replies | |
| 17/38 | *-user: notify plugin of exitbsd-user/ linux-user/ | +4 | 0 replies | |
| 18/38 | *-user: plugin syscallsbsd-user/ linux-user/ | +12 | 0 replies | |
| 19/38 | cpu: hook plugin vcpu eventscpus.c exec.c qom/ | +14 | 0 replies | |
| 20/38 | plugin-gen: add plugin_insn_appendaccel/ include/ | +27 | 0 replies | |
| 21/38 | translator: add translator_ld{ub, sw, uw, l, q}include/ | +28 | 0 replies | |
| 22/38 | target/arm: call qemu_plugin_insn_appendtarget/ target/ | +9 | 0 replies | |
| 23/38 | target/ppc: fetch code with translator_ldtarget/ | +3 | 0 replies | |
| 24/38 | target/sh4: fetch code with translator_ld (WIP)target/ | +1 | 0 replies | |
| 25/38 | target/i386: fetch code with translator_ldtarget/ | +5 | 0 replies | |
| 26/38 | target/hppa: fetch code with translator_ldtarget/ | +1 | 0 replies | |
| 27/38 | target/m68k: fetch code with translator_ldtarget/ | +1 | 0 replies | |
| 28/38 | target/alpha: fetch code with translator_ldtarget/ | +1 | 0 replies | |
| 29/38 | target/riscv: fetch code with translator_ldtarget/ | +1 | 0 replies | |
| 30/38 | target/sparc: fetch code with translator_ldtarget/ | +1 | 0 replies | |
| 31/38 | target/xtensa: fetch code with translator_ldtarget/ | +2 | 2 replies | |
| 32/38 | target/openrisc: fetch code with translator_ldtarget/ | +1 | 0 replies | |
| 33/38 | translator: inject instrumentation from pluginsaccel/ | +16 | 0 replies | |
| 34/38 | plugin: add API symbols to qemu-plugins.symbolsqemu-plugins.symbols | +34 | 0 replies | |
| 35/38 | configure: add --enable-plugins.gitignore Makefile Makefile.target +1 more | +102 | 0 replies | |
| 36/38 | vl: support -plugin optionqemu-options.hx vl.c | +28 | 0 replies | |
| 37/38 | linux-user: support -plugin optionlinux-user/ | +18 | 0 replies | |
| 38/38 | tests/plugin: add sample pluginsconfigure tests/ tests/ +3 more | +282 | 0 replies |
Reviews trailers per patch
9 of 38 patches have a Reviewed-by or Acked-by.
| Patch | Alex Bennée |
|---|---|
| 1/38 | R-b |
| 2/38 | R-b |
| 3/38 | R-b |
| 4/38 | R-b |
| 5/38 | |
| 6/38 | |
| 7/38 | |
| 8/38 | |
| 9/38 | |
| 10/38 | |
| 11/38 | R-b |
| 12/38 | |
| 13/38 | R-b |
| 14/38 | |
| 15/38 | |
| 16/38 | R-b |
| 17/38 | R-b |
| 18/38 | |
| 19/38 | |
| 20/38 | |
| 21/38 | |
| 22/38 | |
| 23/38 | |
| 24/38 | |
| 25/38 | |
| 26/38 | |
| 27/38 | |
| 28/38 | |
| 29/38 | |
| 30/38 | |
| 31/38 | |
| 32/38 | |
| 33/38 | |
| 34/38 | |
| 35/38 | R-b |
| 36/38 | |
| 37/38 | |
| 38/38 |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [Qemu-devel] [RFC v2 00/38] Plugin support
v1: https://lists.gnu.org/archive/html/qemu-devel/2018-10/msg05682.html
Changes since v1:
- Drop the 2-pass translation. Instead, empty instrumentation is injected during translation. If it turns out that this empty instrumentation is not needed, it is removed from the output. For this, add 2 TCG ops that mark the beginning and end of this empty instrumentation.
This is cleaner than 2-pass translation, although it ends up being quite a bit more code, since we have
to copy backend TCG ops, which is tedious. Performance-wise, it is at worst ~9% slower (~1.3% avg) than 2-pass for SPEC06int:
https://imgur.com/a/bUNox3H
This is for an "empty" plugin (also added to tests/plugin/empty.c). That is, it subscribes to TB translation events and does nothing with them (i.e. no execution-time subscriptions).
This means the empty instrumentation has to be injected and then removed, which is the worst-case scenario since all the injection work is wasted.
- Add QTAILQ_REMOVE_SEVERAL, which helps speed up the removal of empty instrumentation.
- Drop the "TCG runtime helper" support. We do not need it for empty instrumentation; we just replace the function pointer in the copied "call" op directly.
+ To detect when an instruction uses helpers, just strncmp the helper's name against "plugin_".
- Drop tb->plugin_mask. Instead, read cpu->plugin_mask from translator_loop.
- Drop the xxhash patches, since I submitted those as a separate series.
- Move a lot of plugin-related code from translator.c to plugin-gen.c, leaving only a few function calls in translator.c.
- Add support for only subscribing to an instruction's reads or writes. This is implemented via a flag added to the memory registration functions of the public API.
- Disentangle callbacks into separate arrays. Instead of just having 3 arrays (tb, insn and mem callbacks), have 5 arrays (tb, insn, virt. mem, hostaddr mem) of 2 arrays each (udata_cb and inline). This takes a bit more space per TB, but note that this struct is allocated only once in each TCGContext. OTOH, it makes the code much simpler. The union in struct dyn_cb remains, since for instrumenting memory accesses from helpers we still coalesce all types of memory callbacks into a single array.
- Add get_page_addr_code_hostp to get the host address of code from common code. Use this to export the host address of instructions (qemu_plugin_insn_haddr() added to the public API).
- Define TCGMemOp MO_HADDR. If set, the TCG backend copies on a TLB hit the corresponding host address to env->hostaddr. This allows us to only do this copy when needed.
- Use helpers for reading and setting env->hostaddr, so that we minimize the use of #ifdef CONFIG_PLUGIN.
- Only define env->hostaddr if CONFIG_PLUGIN.
- Drop the trailing 'S' in CONFIG_PLUGINS: it is now CONFIG_PLUGIN.
- Drop a few optional features from the RFC:
+ lockstep execution
+ plugin-chan + guest hooks
+ virtual clock control
- Define translator_ld* helpers and use them, as suggested by Alex and rth. All target ISAs that use translator_loop have been converted, except s390x and mips.
- Do not bloat TCGContext if !CONFIG_PLUGIN.
- Define TCGContext.plugin_tb as a pointer, instead of the whole struct.
- Test on 32-bit and 64-bit hosts (i386, x86_64, ppc64, aarch64).
- Add cpu_in_exclusive_work_context() and use it in tb_flush(), as suggested by Alex.
- configure fixes, including MacOSX builds thanks to Roman's help.
- Remove macros in atomic_template.h, as suggested by Alex. Turns out they aren't needed, inlines are enough.
- Fixed a bug by which cpu->plugin_mem was not being cleared if the instruction that used helpers was the last one in a TB (e.g. an exception). Fix it by adding checks (1) when returning from longjmp, and (2) when finishing a TB from tcg, so that we're sure to leave cpu->plugin_mem in a good state. (I noticed the bug by uninstalling a plugin that had registered memory callbacks, which resulted in callbacks to the uninstalled [dlclose'd] plugin.)
- Make sure tcg_ctx->plugin_mem_cb is always NULL after finishing the translation of a TB. This fixes a bug on uninstall.
- Do not abort when qemu_plugin_uninstall is called more than once. This is actually quite common, so just silently return on subsequent calls to uninstall.
- Drop the "qemu"/QEMU from some overly long function/macro names. This applies to qemu-internal files, of course.
- Keep the plugin's argument array in memory until the plugin is uninstalled, so that plugins don't have to strdup their arguments.
- Drop nargs argument from tcg_op_insert_before/after; it's unused.
- Rename plugin-api.h to qemu-plugin.h, which is the same name it gets in the final destination (after `make install').
- Add insn_inline function to the API.
- Add some sample plugins to tests/plugin.
You can fetch this series from:
https://github.com/cota/qemu/tree/plugin-v2
Thanks,
Emilio
--- .gitignore | 2 + Makefile | 8 +- Makefile.target | 18 + accel/tcg/Makefile.objs | 1 + accel/tcg/atomic_template.h | 117 +++- accel/tcg/cpu-exec.c | 2 + accel/tcg/cputlb.c | 23 +- accel/tcg/plugin-gen.c | 1085 +++++++++++++++++++++++++++++ accel/tcg/plugin-helpers.h | 6 + accel/tcg/softmmu_template.h | 43 +- accel/tcg/translate-all.c | 15 +- accel/tcg/translator.c | 16 + bsd-user/syscall.c | 12 + configure | 86 ++- cpus-common.c | 2 + cpus.c | 10 + exec.c | 2 + include/exec/cpu-defs.h | 9 + include/exec/cpu_ldst.h | 9 + include/exec/cpu_ldst_template.h | 43 +- include/exec/cpu_ldst_useronly_template.h | 42 +- include/exec/exec-all.h | 13 + include/exec/helper-gen.h | 1 + include/exec/helper-proto.h | 1 + include/exec/helper-tcg.h | 1 + include/exec/plugin-gen.h | 75 ++ include/exec/translator.h | 28 + include/qemu/plugin.h | 253 +++++++ include/qemu/qemu-plugin.h | 241 +++++++ include/qemu/queue.h | 10 + include/qom/cpu.h | 19 + linux-user/exit.c | 1 + linux-user/main.c | 18 + linux-user/syscall.c | 3 + plugin.c | 1030 +++++++++++++++++++++++++++ qemu-options.hx | 17 + qemu-plugins.symbols | 34 + qom/cpu.c | 2 + target/alpha/translate.c | 2 +- target/arm/translate-a64.c | 2 + target/arm/translate.c | 8 +- target/hppa/translate.c | 2 +- target/i386/translate.c | 10 +- target/m68k/translate.c | 2 +- target/openrisc/translate.c | 2 +- target/ppc/translate.c | 8 +- target/riscv/translate.c | 2 +- target/sh4/translate.c | 2 +- target/sparc/translate.c | 2 +- target/xtensa/translate.c | 4 +- tcg/README | 2 +- tcg/i386/tcg-target.inc.c | 7 + tcg/optimize.c | 4 +- tcg/tcg-op.c | 44 +- tcg/tcg-op.h | 16 + tcg/tcg-opc.h | 3 + tcg/tcg.c | 27 +- tcg/tcg.h | 32 +- tests/plugin/Makefile | 28 + tests/plugin/bb.c | 66 ++ tests/plugin/empty.c | 30 + tests/plugin/insn.c | 63 ++ tests/plugin/mem.c | 93 +++ trace-events | 2 +- vl.c | 11 + 65 files changed, 3653 insertions(+), 119 deletions(-)