plugins for TCG
v4 cover plugins for TCG
Hi,
This is the latest iteration of the plugins series. The main changes from the last version are:
- dropped passing of haddr to plugins
This makes the code for handling the plugins less invasive in the softmmu path at the cost of offloading processing to the plugin if it wants the value. We rely on the fact that the TLB is per vCPU so a helper can just trigger a re-query of the TLB to get the final address.
Part of that change involved embedding the MMU index in the meminfo field for tracing. I see there are some other patches on the list for messing with TCGMemOp so there might be a clash coming up.
- translator_ld goes direct to softmmu/user functions
I also mark the [SOFTMMU_]CODE_ACCESS helpers as deprecated. There is more work to be done to clean up all the current uses of code access helpers but ideally the only thing that should be peaking at code is the translator loop itself. However a bunch of helpers have taken to using code loading functions to peak at the instruction just executed to figure out what to do. Once those have been fixed then we can remove those helpers.
Other more minor fixes can be found documented bellow the --- in the individual patches.
This series also includes the semihosting patches as they are a pre-requisite for the translator_ld patches for ARM.
Once the tree opens up for development again I hope to get the semihosting and trivial clean-up patches merged quickly so the patch count for the plugins patches proper can be reduced a bit.
The following patches need review
patch 0004/target arm remove run time semihosting checks.patch patch 0005/includes remove stale smp max _cpus externs.patch patch 0007/trace add mmu_index to mem_info.patch
patch 0011/docs devel add plugins.rst design document.patch patch 0012/configure add enable plugins MOVE TO END.patch patch 0015/plugin add implementation of the api.patch patch 0024/plugins implement helpers for resolving hwaddr.patch patch 0047/tests tcg enable plugin testing.patch
patch 0048/tests plugin add a hotblocks plugin.patch patch 0050/tests plugin add instruction execution breakdown.patch patch 0051/tests plugin add hotpages plugin to breakdown mem.patch patch 0053/include exec wrap cpu_ldst.h in CONFIG_TCG.patch
Alex Bennée (18):
target/arm: handle M-profile semihosting at translate time target/arm: handle A-profile T32 semihosting at translate time target/arm: handle A-profile A32 semihosting at translate time target/arm: remove run time semihosting checks
includes: remove stale [smp|max]_cpus externs
trace: add mmu_index to mem_info
docs/devel: add plugins.rst design document
configure: add --enable-plugins (MOVE TO END)
plugin: add implementation of the api
plugins: implement helpers for resolving hwaddr
tests/tcg: enable plugin testing
tests/plugin: add a hotblocks plugin
plugin: add qemu_plugin_insn_disas helper
tests/plugin: add instruction execution breakdown tests/plugin: add hotpages plugin to breakdown memory access patterns accel/stubs: reduce headers from tcg-stub
include/exec: wrap cpu_ldst.h in CONFIG_TCG include/exec/cpu-defs.h: fix typo
Emilio G. Cota (34):
trace: expand mem_info:size_shift to 4 bits tcg/README: fix typo s/afterwise/afterwards/
cpu: introduce cpu_in_exclusive_context()
translate-all: use cpu_in_exclusive_work_context() in tb_flush
plugin: add user-facing API
plugin: add core code
queue: add QTAILQ_REMOVE_SEVERAL
cputlb: document get_page_addr_code
cputlb: introduce get_page_addr_code_hostp
tcg: add tcg_gen_st_ptr
plugin-gen: add module for TCG-related code
atomic_template: fix indentation in GEN_ATOMIC_HELPER
atomic_template: add inline trace/plugin helpers
tcg: let plugins instrument virtual memory accesses
translate-all: notify plugin code of tb_flush *-user: notify plugin of exit
*-user: plugin syscalls
cpu: hook plugin vcpu events
plugin-gen: add plugin_insn_append
translator: add translator_ld{ub,sw,uw,l,q} target/arm: fetch code with translator_ld target/ppc: fetch code with translator_ld target/sh4: fetch code with translator_ld target/i386: fetch code with translator_ld target/hppa: fetch code with translator_ld target/m68k: fetch code with translator_ld target/alpha: fetch code with translator_ld target/riscv: fetch code with translator_ld target/sparc: fetch code with translator_ld target/xtensa: fetch code with translator_ld target/openrisc: fetch code with translator_ld
translator: inject instrumentation from plugins
plugin: add API symbols to qemu-plugins.symbols tests/plugin: add sample plugins
Lluís Vilanova (2):
vl: support -plugin option
linux-user: support -plugin option
Makefile | 10 +- Makefile.target | 2 + accel/stubs/tcg-stub.c | 3 - accel/tcg/Makefile.objs | 1 + accel/tcg/atomic_common.inc.c | 54 ++ accel/tcg/atomic_template.h | 96 ++- accel/tcg/cpu-exec.c | 8 +- accel/tcg/cputlb.c | 69 +- accel/tcg/plugin-gen.c | 977 ++++++++++++++++++++++ accel/tcg/plugin-helpers.h | 5 + accel/tcg/translate-all.c | 15 +- accel/tcg/translator.c | 20 + accel/tcg/user-exec.c | 3 + bsd-user/syscall.c | 24 +- configure | 86 +- cpus-common.c | 4 + cpus.c | 10 + disas.c | 103 +++ docs/devel/index.rst | 1 + docs/devel/plugins.rst | 107 +++ exec.c | 2 + include/disas/disas.h | 2 + include/exec/cpu-defs.h | 3 +- include/exec/cpu_ldst.h | 11 + include/exec/cpu_ldst_template.h | 37 +- include/exec/cpu_ldst_useronly_template.h | 29 +- include/exec/exec-all.h | 81 +- include/exec/helper-gen.h | 1 + include/exec/helper-proto.h | 1 + include/exec/helper-tcg.h | 1 + include/exec/plugin-gen.h | 71 ++ include/exec/translator.h | 58 +- include/qemu/bswap.h | 5 + include/qemu/plugin.h | 261 ++++++ include/qemu/qemu-plugin.h | 360 ++++++++ include/qemu/queue.h | 10 + include/qom/cpu.h | 19 + include/sysemu/sysemu.h | 2 - include/user/syscall-trace.h | 40 + linux-user/exit.c | 1 + linux-user/main.c | 18 + linux-user/syscall.c | 7 +- plugins/.gitignore | 2 + plugins/Makefile.objs | 21 + plugins/api.c | 338 ++++++++ plugins/core.c | 499 +++++++++++ plugins/loader.c | 353 ++++++++ plugins/plugin.h | 95 +++ plugins/qemu-plugins.symbols | 39 + qemu-options.hx | 17 + qom/cpu.c | 2 + scripts/tracetool/transform.py | 1 + target/alpha/translate.c | 2 +- target/arm/arm_ldst.h | 15 +- target/arm/helper.c | 90 +- target/arm/m_helper.c | 18 +- target/arm/translate.c | 64 +- 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 | 4 +- target/sparc/translate.c | 2 +- target/xtensa/translate.c | 4 +- tcg/README | 2 +- tcg/tcg-op.c | 40 +- tcg/tcg-op.h | 16 + tcg/tcg-opc.h | 3 + tcg/tcg.c | 22 + tcg/tcg.h | 23 + tests/Makefile.include | 10 +- tests/plugin/Makefile | 31 + tests/plugin/bb.c | 65 ++ tests/plugin/empty.c | 29 + tests/plugin/hotblocks.c | 146 ++++ tests/plugin/hotpages.c | 179 ++++ tests/plugin/howvec.c | 301 +++++++ tests/plugin/insn.c | 62 ++ tests/plugin/mem.c | 96 +++ tests/tcg/Makefile | 34 + tests/tcg/arm/Makefile.softmmu-target | 1 + trace-events | 8 +- trace/mem-internal.h | 31 +- trace/mem.h | 7 +- vl.c | 11 + 87 files changed, 5067 insertions(+), 260 deletions(-) create mode 100644 accel/tcg/atomic_common.inc.c create mode 100644 accel/tcg/plugin-gen.c create mode 100644 accel/tcg/plugin-helpers.h create mode 100644 docs/devel/plugins.rst create mode 100644 include/exec/plugin-gen.h create mode 100644 include/qemu/plugin.h create mode 100644 include/qemu/qemu-plugin.h create mode 100644 include/user/syscall-trace.h create mode 100644 plugins/.gitignore create mode 100644 plugins/Makefile.objs create mode 100644 plugins/api.c create mode 100644 plugins/core.c create mode 100644 plugins/loader.c create mode 100644 plugins/plugin.h create mode 100644 plugins/qemu-plugins.symbols create mode 100644 tests/plugin/Makefile create mode 100644 tests/plugin/bb.c create mode 100644 tests/plugin/empty.c create mode 100644 tests/plugin/hotblocks.c create mode 100644 tests/plugin/hotpages.c create mode 100644 tests/plugin/howvec.c create mode 100644 tests/plugin/insn.c create mode 100644 tests/plugin/mem.c
Signature · 1 line
2.20.1
PATCH v4 1/54 target/arm: handle M-profile semihosting at translate time
We do this for other semihosting calls so we might as well do it for M-profile as well.
--- target/arm/m_helper.c | 18 ++++++------------ target/arm/translate.c | 20 +++++++++++++++++++- 2 files changed, 25 insertions(+), 13 deletions(-)
target/arm/m_helper.c +6 -12
@@ -2113,19 +2113,13 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs)break ; }break ; +case EXCP_SEMIHOST : +qemu_log_mask (CPU_LOG_INT , +"...handling as semihosting call 0x%x\n" , + env->regs[0 ]); + env->regs[0 ] =do_arm_semihosting (env); +return ;case EXCP_BKPT : -if (semihosting_enabled ()) { -int nr; - nr =arm_lduw_code (env, env->regs[15 ],arm_sctlr_b (env)) &0xff ; -if (nr ==0xab ) { - env->regs[15 ] +=2 ; -qemu_log_mask (CPU_LOG_INT , -"...handling as semihosting call 0x%x\n" , - env->regs[0 ]); - env->regs[0 ] =do_arm_semihosting (env); -return ; - } - }armv7m_nvic_set_pending (env->nvic,ARMV7M_EXCP_DEBUG , false);break ;case EXCP_IRQ :
target/arm/translate.c +19 -1
@@ -10976,6 +10976,24 @@ illegal_op: default_exception_el(s)); } +/* +* Thumb BKPT. On M-profile CPUs this may be a semihosting call which +* we can process much the same way as gen_hlt() above. +*/ +static inline void gen_thumb_bkpt (DisasContext *s,int imm8) +{ + if (arm_dc_feature(s, ARM_FEATURE_M) && + semihosting_enabled() && +#ifndef CONFIG_USER_ONLY + s->current_el != 0 && +#endif + (imm8 == 0xab)) { +gen_exception_internal_insn (s,0 ,EXCP_SEMIHOST ); +return ; + } + gen_exception_bkpt_insn(s, 2, syn_aa32_bkpt(imm8, true)); +} +static void disas_thumb_insn (DisasContext *s,uint32_t insn) {uint32_t val, op, rm, rn, rd, shift, cond;
@@ -11611,7 +11629,7 @@ static void disas_thumb_insn(DisasContext *s, uint32_t insn) {int imm8 =extract32 (insn,0 ,8 );ARCH (5 ); -gen_exception_bkpt_insn (s,2 ,syn_aa32_bkpt (imm8, true)); +gen_thumb_bkpt (s, imm8);break ; }
Signature · 1 line
2.20.1
PATCH v4 2/54 target/arm: handle A-profile T32 semihosting at translate time
In reply to Alex BennéeAs for the other semihosting calls we can resolve this at translate time.
--- target/arm/translate.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
target/arm/translate.c +20 -4
@@ -10994,6 +10994,24 @@ static inline void gen_thumb_bkpt(DisasContext *s, int imm8)gen_exception_bkpt_insn (s,2 ,syn_aa32_bkpt (imm8, true)); } +/* +* Thumb SWI. On A-profile CPUs this may be a semihosting call. +*/ +static inline void gen_thumb_swi (DisasContext *s,int imm8) +{ + if (semihosting_enabled() && +#ifndef CONFIG_USER_ONLY + s->current_el != 0 && +#endif + (imm8 == 0xab)) { +gen_exception_internal_insn (s,0 ,EXCP_SEMIHOST ); +return ; + } +gen_set_pc_im (s, s->pc); + s->svc_imm = imm8; + s->base.is_jmp = DISAS_SWI; +} +static void disas_thumb_insn (DisasContext *s,uint32_t insn) {uint32_t val, op, rm, rn, rd, shift, cond;
@@ -11758,10 +11776,8 @@ static void disas_thumb_insn(DisasContext *s, uint32_t insn) goto undef;if (cond ==0xf ) { -/* swi */ -gen_set_pc_im (s, s->pc); - s->svc_imm =extract32 (insn,0 ,8 ); - s->base.is_jmp =DISAS_SWI ; +/* swi/svc */ +gen_thumb_swi (s,extract32 (insn,0 ,8 ));break ; }/* generate a conditional jump to next instruction */
Signature · 1 line
2.20.1
PATCH v4 3/54 target/arm: handle A-profile A32 semihosting at translate time
In reply to Alex BennéeAs for the other semihosting calls we can resolve this at translate time.
--- target/arm/translate.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-)
target/arm/translate.c +17 -3
@@ -7698,6 +7698,22 @@ static void arm_skip_unless(DisasContext *s, uint32_t cond)arm_gen_test_cc (cond ^1 , s->condlabel); } +static inline void gen_arm_swi (DisasContext *s,int imm24) +{ + if (semihosting_enabled() && +#ifndef CONFIG_USER_ONLY + s->current_el != 0 && +#endif + (imm24 == 0x123456)) { +gen_exception_internal_insn (s,0 ,EXCP_SEMIHOST ); +return ; + } + +gen_set_pc_im (s, s->pc); + s->svc_imm = imm24; + s->base.is_jmp = DISAS_SWI; +} +static void disas_arm_insn (DisasContext *s,unsigned int insn) {unsigned int cond, val, op1, i, shift, rm, rs, rn, rd, sh;
@@ -9248,9 +9264,7 @@ static void disas_arm_insn(DisasContext *s, unsigned int insn)break ;case 0xf :/* swi */ -gen_set_pc_im (s, s->pc); - s->svc_imm =extract32 (insn,0 ,24 ); - s->base.is_jmp =DISAS_SWI ; +gen_arm_swi (s,extract32 (insn,0 ,24 ));break ;default : illegal_op:
Signature · 1 line
2.20.1
PATCH v4 4/54 target/arm: remove run time semihosting checks
In reply to Alex BennéeNow we do all our checking and use a common EXCP_SEMIHOST for semihosting operations we can make helper code a lot simpler.
---
v2
- fix re-base conflicts
- hoist EXCP_SEMIHOST check
- comment cleanups
--- target/arm/helper.c | 90 +++++++++------------------------------------ 1 file changed, 18 insertions(+), 72 deletions(-)
target/arm/helper.c +18 -72
@@ -8259,86 +8259,30 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs) new_el, env->pc, pstate_read(env)); } -static inline bool check_for_semihosting (CPUState *cs) +/* +* Do semihosting call and set the appropriate return value. All the +* permission and validity checks have been done at translate time. +* +* We only see semihosting exceptions in TCG only as they are not +* trapped to the hypervisor in KVM. +*/ +static void handle_semihosting (CPUState *cs) {#ifdef CONFIG_TCG -/* Check whether this exception is a semihosting call; if so -* then handle it and return true; otherwise return false. -*/ ARMCPU *cpu =ARM_CPU (cs);CPUARMState *env = &cpu->env;if (is_a64 (env)) { -if (cs->exception_index ==EXCP_SEMIHOST ) { -/* This is always the 64-bit semihosting exception. -* The "is this usermode" and "is semihosting enabled" -* checks have been done at translate time. -*/ -qemu_log_mask (CPU_LOG_INT , -"...handling as semihosting call 0x%" PRIx64"\n" , - env->xregs[0 ]); - env->xregs[0 ] =do_arm_semihosting (env); -return true; - } -return false; +qemu_log_mask (CPU_LOG_INT , +"...handling as semihosting call 0x%" PRIx64"\n" , + env->xregs[0 ]); + env->xregs[0 ] =do_arm_semihosting (env); }else { -uint32_t imm; - -/* Only intercept calls from privileged modes, to provide some -* semblance of security. -*/ -if (cs->exception_index !=EXCP_SEMIHOST && - (!semihosting_enabled () || - ((env->uncached_cpsr &CPSR_M ) ==ARM_CPU_MODE_USR ))) { -return false; - } - -switch (cs->exception_index) { -case EXCP_SEMIHOST : -/* This is always a semihosting call; the "is this usermode" -* and "is semihosting enabled" checks have been done at -* translate time. -*/ -break ; -case EXCP_SWI : -/* Check for semihosting interrupt. */ -if (env->thumb) { - imm =arm_lduw_code (env, env->regs[15 ] -2 ,arm_sctlr_b (env)) - &0xff ; -if (imm ==0xab ) { -break ; - } - }else { - imm =arm_ldl_code (env, env->regs[15 ] -4 ,arm_sctlr_b (env)) - &0xffffff ; -if (imm ==0x123456 ) { -break ; - } - } -return false; -case EXCP_BKPT : -/* See if this is a semihosting syscall. */ -if (env->thumb) { - imm =arm_lduw_code (env, env->regs[15 ],arm_sctlr_b (env)) - &0xff ; -if (imm ==0xab ) { - env->regs[15 ] +=2 ; -break ; - } - } -return false; -default : -return false; - } -qemu_log_mask (CPU_LOG_INT ,"...handling as semihosting call 0x%x\n" , env->regs[0 ]); env->regs[0 ] =do_arm_semihosting (env); -return true; } -#else -return false;#endif }
@@ -8371,11 +8315,13 @@ void arm_cpu_do_interrupt(CPUState *cs)return ; } -/* Semihosting semantics depend on the register width of the -* code that caused the exception, not the target exception level, -* so must be handled here. +/* +* Semihosting semantics depend on the register width of the code +* that caused the exception, not the target exception level, so +* must be handled here. */ -if (check_for_semihosting (cs)) { +if (cs->exception_index ==EXCP_SEMIHOST ) { +handle_semihosting (cs);return ; }
Signature · 1 line
2.20.1
Re: [PATCH v4 04/54] target/arm: remove run time semihosting checks
Quoted 124 lines · Alex Bennée
Now we do all our checking and use a common
EXCP_SEMIHOSTfor semihosting operations we can make helper code a lot simpler.Signed-off-by Alex Bennée <[email protected]>---
v2
- fix re-base conflicts
- hoistEXCP_SEMIHOSTcheck
- comment cleanups--- target/arm/helper.c | 90 +++++++++------------------------------------ 1 file changed, 18 insertions(+), 72 deletions(-)target/arm/helper.c +12
-71@@ -8259,86 +8259,30 @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs) new_el, env->pc, pstate_read(env)); } -static inline bool check_for_semihosting (CPUState *cs) +/* +* Do semihosting call and set the appropriate return value. All the +* permission and validity checks have been done at translate time. +* +* We only see semihosting exceptions in TCG only as they are not +* trapped to the hypervisor in KVM. +*/ +static void handle_semihosting (CPUState *cs) {#ifdef CONFIG_TCG -/* Check whether this exception is a semihosting call; if so -* then handle it and return true; otherwise return false. -*/ ARMCPU *cpu =ARM_CPU (cs);CPUARMState *env = &cpu->env;if (is_a64 (env)) { -if (cs->exception_index ==EXCP_SEMIHOST ) { -/* This is always the 64-bit semihosting exception. -* The "is this usermode" and "is semihosting enabled" -* checks have been done at translate time. -*/ -qemu_log_mask (CPU_LOG_INT , -"...handling as semihosting call 0x%" PRIx64"\n" , - env->xregs[0 ]); - env->xregs[0 ] =do_arm_semihosting (env); -return true; - } -return false; +qemu_log_mask (CPU_LOG_INT , +"...handling as semihosting call 0x%" PRIx64"\n" , + env->xregs[0 ]); + env->xregs[0 ] =do_arm_semihosting (env); }else { -uint32_t imm; - -/* Only intercept calls from privileged modes, to provide some -* semblance of security. -*/ -if (cs->exception_index !=EXCP_SEMIHOST && - (!semihosting_enabled () || - ((env->uncached_cpsr &CPSR_M ) ==ARM_CPU_MODE_USR ))) { -return false; - } - -switch (cs->exception_index) { -case EXCP_SEMIHOST : -/* This is always a semihosting call; the "is this usermode" -* and "is semihosting enabled" checks have been done at -* translate time. -*/ -break ; -case EXCP_SWI : -/* Check for semihosting interrupt. */ -if (env->thumb) { - imm =arm_lduw_code (env, env->regs[15 ] -2 ,arm_sctlr_b (env)) - &0xff ; -if (imm ==0xab ) { -break ; - } - }else { - imm =arm_ldl_code (env, env->regs[15 ] -4 ,arm_sctlr_b (env)) - &0xffffff ; -if (imm ==0x123456 ) { -break ; - } - } -return false; -case EXCP_BKPT : -/* See if this is a semihosting syscall. */ -if (env->thumb) { - imm =arm_lduw_code (env, env->regs[15 ],arm_sctlr_b (env)) - &0xff ; -if (imm ==0xab ) { - env->regs[15 ] +=2 ; -break ; - } - } -return false; -default : -return false; - } -qemu_log_mask (CPU_LOG_INT ,"...handling as semihosting call 0x%x\n" , env->regs[0 ]); env->regs[0 ] =do_arm_semihosting (env); -return true; } -#else -return false;#endif }@@ -8371,11 +8315,13 @@ void arm_cpu_do_interrupt(CPUState *cs)return ; } -/* Semihosting semantics depend on the register width of the -* code that caused the exception, not the target exception level, -* so must be handled here.
target/arm/helper.c void arm_cpu_do_interrupt(CPUState *cs) · line 8326
Quoted 10 lines
target/arm/helper.c +6
-1+/* +* Semihosting semantics depend on the register width of the code +* that caused the exception, not the target exception level, so +* must be handled here. */ -if (check_for_semihosting (cs)) { +if (cs->exception_index ==EXCP_SEMIHOST ) { +handle_semihosting (cs);return ; }
Previously, this code would never return here if CONFIG_TCG was not defined because check_for_semihosting() always returned false in that case. Is it now true that cs->exception_index will never hold a value of EXCP_SEMIHOST if CONFIG_TCG is not defined (or that it is otherwise correct to return here in that case where it wasn't previously)?
-Aaron
Re: [PATCH v4 04/54] target/arm: remove run time semihosting checks
Quoted 18 lines · Aaron Lindsay OS
Quoted 15 lines · Alex Bennée
target/arm/helper.c +6
-4@@ -8371,11 +8315,13 @@ void arm_cpu_do_interrupt(CPUState *cs)return ; } -/* Semihosting semantics depend on the register width of the -* code that caused the exception, not the target exception level, -* so must be handled here. +/* +* Semihosting semantics depend on the register width of the code +* that caused the exception, not the target exception level, so +* must be handled here. */ -if (check_for_semihosting (cs)) { +if (cs->exception_index ==EXCP_SEMIHOST ) { +handle_semihosting (cs);
Quoted 8 lines
Review void arm_cpu_do_interrupt(CPUState *cs) · line 8326
Quoted 2 lines
(quoted diff) +0
-0return; }Previously, this code would never return here if
CONFIG_TCGwas not defined becausecheck_for_semihosting()always returned false in that case. Is it now true thatcs->exception_indexwill never hold a value ofEXCP_SEMIHOSTifCONFIG_TCGis not defined (or that it is otherwise correct to return here in that case where it wasn't previously)?
It's always true that cs->exception_index can't be EXCP_SEMIHOST here if we're not using TCG, because the only way you can get into this function other than by using TCG is the call in kvm_arm_handle_debug(), which sets exception_index beforehand. More generally, we only call this function in non-TCG if we're trying to manually configure the CPU state to simulate a guest exception entry, and that will always be done by setting up the exception_index to the kind of exception we're simulating before the call. EXCP_SEMIHOST isn't a real exception so that should never happen (you could argue that we should assert, I suppose).
thanks
-- PMM
Re: [Qemu-devel] [PATCH v4 04/54] target/arm: remove run time semihosting checks
In reply to Alex Bennéetarget/arm/helper.c static void arm_cpu_do_interrupt_aarch64(CPUState *cs) · line 8271
Quoted 11 lines · Alex Bennée
target/arm/helper.c +8
-1-static inline bool check_for_semihosting (CPUState *cs) +/* +* Do semihosting call and set the appropriate return value. All the +* permission and validity checks have been done at translate time. +* +* We only see semihosting exceptions in TCG only as they are not +* trapped to the hypervisor in KVM. +*/ +static void handle_semihosting (CPUState *cs) {#ifdef CONFIG_TCG
Let's move the ifdef outside the function...
target/arm/helper.c void arm_cpu_do_interrupt(CPUState *cs) · line 8326
Quoted 5 lines
target/arm/helper.c +2
-1-if (check_for_semihosting (cs)) { +if (cs->exception_index ==EXCP_SEMIHOST ) { +handle_semihosting (cs);return ; }
... and put another one here.
Peter described how we can't get EXCP_SEMIHOST here from kvm, and suggested an assert. Well, the assert is already present just below:
assert(!excp_is_internal(cs->exception_index));
All we need to do is not return early beforehand.
r~
PATCH v4 5/54 includes: remove stale [smp|max]_cpus externs
In reply to Alex BennéeCommit a5e0b3311 removed these in favour of querying machine properties. Remove the extern declarations as well.
Message-Id: <[email protected]>
--- include/sysemu/sysemu.h | 2 -- 1 file changed, 2 deletions(-)
include/sysemu/sysemu.h +0 -2
@@ -103,8 +103,6 @@ extern const char *keyboard_layout;extern int win2k_install_hack;extern int alt_grab;extern int ctrl_grab; -extern int smp_cpus; -extern unsigned int max_cpus;extern int cursor_hide;extern int graphic_rotate;extern int no_quit;
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 05/54] includes: remove stale [smp|max]_cpus externs
Quoted 9 lines · Alex Bennée
Commit
a5e0b3311removed these in favour of querying machine properties. Remove the extern declarations as well.Signed-off-by Alex Bennée <[email protected]>Cc Like Xu <[email protected]>Message-Id: <[email protected]>
--- include/sysemu/sysemu.h | 2 -- 1 file changed, 2 deletions(-)
r~
PATCH v4 6/54 trace: expand mem_info:size_shift to 4 bits
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
This will allow us to trace 32k-long memory accesses (although our maximum is something like 256 bytes at the moment).
--- trace-events | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
trace-events +1 -1
@@ -149,7 +149,7 @@ vcpu guest_cpu_reset(void) # Access information can be parsed as: # # struct mem_info { -# uint8_t size_shift : 2; /* interpreted as "1 << size_shift" bytes */ +# uint8_t size_shift : 4; /* interpreted as "1 << size_shift" bytes */ # bool sign_extend: 1; /* sign-extended */ # uint8_t endianness : 1; /* 0: little, 1: big */ # bool store : 1; /* wheter it's a store operation */
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 06/54] trace: expand mem_info:size_shift to 4 bits
Quoted 19 lines · Alex Bennée
From: "Emilio G. Cota" <[email protected]>
This will allow us to trace 32k-long memory accesses (although our maximum is something like 256 bytes at the moment).
Reviewed-by Alex Bennée <[email protected]>Signed-off-by Emilio G. Cota <[email protected]>[AJB: expanded to 3->4 bits]Signed-off-by Alex Bennée <[email protected]>--- trace-events | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)trace-events +0
-0
trace-events vcpu guest_cpu_reset(void) · line 155
Quoted 8 lines
trace-events +1
-1@@ -149,7 +149,7 @@ vcpu guest_cpu_reset(void) # Access information can be parsed as: # # struct mem_info { -# uint8_t size_shift : 2; /* interpreted as "1 << size_shift" bytes */ +# uint8_t size_shift : 4; /* interpreted as "1 << size_shift" bytes */ # bool sign_extend: 1; /* sign-extended */ # uint8_t endianness : 1; /* 0: little, 1: big */ # bool store : 1; /* wheter it's a store operation */
Adjusting the comment doesn't do anything, and neither the before or the after match the actual code:
#define TRACE_MEM_SZ_SHIFT_MASK 0x7 /* size shift mask */
Is this a victim of a rebase, with the changes to trace/mem-internal.h moved to a different patch?
r~
PATCH v4 7/54 trace: add mmu_index to mem_info
In reply to Alex BennéeWe are going to re-use mem_info later for plugins and will need to track the mmu_idx for softmmu code.
[TODO: convert everything to use TCGMemOpIdx?]
--- accel/tcg/atomic_template.h | 6 ++--- accel/tcg/cputlb.c | 2 ++ accel/tcg/user-exec.c | 1 + include/exec/cpu_ldst_template.h | 15 +++++------ include/exec/cpu_ldst_useronly_template.h | 6 ++--- scripts/tracetool/transform.py | 1 + tcg/tcg-op.c | 8 +++--- trace-events | 6 +++-- trace/mem-internal.h | 31 ++++++++++++++++------- trace/mem.h | 7 ++--- 10 files changed, 50 insertions(+), 33 deletions(-)
accel/tcg/atomic_template.h +3 -3
@@ -60,7 +60,7 @@#endif #define ATOMIC_TRACE_RMW do { \ - uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); \ + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false, ATOMIC_MMU_IDX); \ \ trace_guest_mem_before_exec(env_cpu(env), addr, info); \ trace_guest_mem_before_exec(env_cpu(env), addr, \
@@ -68,13 +68,13 @@ } while (0)#define ATOMIC_TRACE_LD do { \ - uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); \ + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false, ATOMIC_MMU_IDX); \ \ trace_guest_mem_before_exec(env_cpu(env), addr, info); \ } while (0)# define ATOMIC_TRACE_ST do { \ - uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, true); \ + uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, true, ATOMIC_MMU_IDX); \ \ trace_guest_mem_before_exec(env_cpu(env), addr, info); \ } while (0)
accel/tcg/cputlb.c +2 -0
@@ -1692,6 +1692,7 @@ void helper_be_stq_mmu(CPUArchState *env, target_ulong addr, uint64_t val,memory_notdirty_write_complete (&ndi); \ } \ } while (0) +#define ATOMIC_MMU_IDX oi#define DATA_SIZE 1#include "atomic_template.h"
@@ -1734,6 +1735,7 @@ void helper_be_stq_mmu(CPUArchState *env, target_ulong addr, uint64_t val,#define DATA_SIZE 8#include "atomic_template.h" #endif +#undef ATOMIC_MMU_IDX/* Code access functions. */
accel/tcg/user-exec.c +1 -0
@@ -719,6 +719,7 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,#define ATOMIC_MMU_DECLS do {} while (0)#define ATOMIC_MMU_LOOKUP atomic_mmu_lookup(env, addr, DATA_SIZE, GETPC())#define ATOMIC_MMU_CLEANUP do { clear_helper_retaddr(); } while (0) +#define ATOMIC_MMU_IDX 0#define ATOMIC_NAME (X ) HELPER(glue(glue(atomic_ ## X, SUFFIX), END))#define EXTRA_ARGS
include/exec/cpu_ldst_template.h +6 -9
@@ -84,17 +84,16 @@ glue(glue(glue(cpu_ld, USUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,CPUTLBEntry *entry;RES_TYPE res;target_ulong addr; -int mmu_idx; +int mmu_idx =CPU_MMU_INDEX ;TCGMemOpIdx oi;#if !defined(SOFTMMU_CODE_ACCESS )trace_guest_mem_before_exec (env_cpu (env), ptr, -trace_mem_build_info (SHIFT , false,MO_TE , false)); +trace_mem_build_info (SHIFT , false,MO_TE , false, mmu_idx));#endif addr = ptr; - mmu_idx =CPU_MMU_INDEX ; entry =tlb_entry (env, mmu_idx, addr);if (unlikely (entry->ADDR_READ != (addr & (TARGET_PAGE_MASK | (DATA_SIZE -1 ))))) {
@@ -123,17 +122,16 @@ glue(glue(glue(cpu_lds, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,CPUTLBEntry *entry;int res;target_ulong addr; -int mmu_idx; +int mmu_idx =CPU_MMU_INDEX ;TCGMemOpIdx oi;#if !defined(SOFTMMU_CODE_ACCESS )trace_guest_mem_before_exec (env_cpu (env), ptr, -trace_mem_build_info (SHIFT , true,MO_TE , false)); +trace_mem_build_info (SHIFT , true,MO_TE , false, mmu_idx));#endif addr = ptr; - mmu_idx =CPU_MMU_INDEX ; entry =tlb_entry (env, mmu_idx, addr);if (unlikely (entry->ADDR_READ != (addr & (TARGET_PAGE_MASK | (DATA_SIZE -1 ))))) {
@@ -165,17 +163,16 @@ glue(glue(glue(cpu_st, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env, {CPUTLBEntry *entry;target_ulong addr; -int mmu_idx; +int mmu_idx =CPU_MMU_INDEX ;TCGMemOpIdx oi;#if !defined(SOFTMMU_CODE_ACCESS )trace_guest_mem_before_exec (env_cpu (env), ptr, -trace_mem_build_info (SHIFT , false,MO_TE , true)); +trace_mem_build_info (SHIFT , false,MO_TE , true, mmu_idx));#endif addr = ptr; - mmu_idx =CPU_MMU_INDEX ; entry =tlb_entry (env, mmu_idx, addr);if (unlikely (tlb_addr_write (entry) != (addr & (TARGET_PAGE_MASK | (DATA_SIZE -1 ))))) {
include/exec/cpu_ldst_useronly_template.h +3 -3
@@ -73,7 +73,7 @@ glue(glue(cpu_ld, USUFFIX), MEMSUFFIX)(CPUArchState *env, abi_ptr ptr)#else trace_guest_mem_before_exec (env_cpu (env), ptr, -trace_mem_build_info (SHIFT , false,MO_TE , false)); +trace_mem_build_info (SHIFT , false,MO_TE , false,0 ));return glue (glue (ld,USUFFIX ), _p)(g2h (ptr));#endif }
@@ -105,7 +105,7 @@ glue(glue(cpu_lds, SUFFIX), MEMSUFFIX)(CPUArchState *env, abi_ptr ptr)#else trace_guest_mem_before_exec (env_cpu (env), ptr, -trace_mem_build_info (SHIFT , true,MO_TE , false)); +trace_mem_build_info (SHIFT , true,MO_TE , false,0 ));return glue (glue (lds,SUFFIX ), _p)(g2h (ptr));#endif }
@@ -132,7 +132,7 @@ glue(glue(cpu_st, SUFFIX), MEMSUFFIX)(CPUArchState *env, abi_ptr ptr, {trace_guest_mem_before_exec (env_cpu (env), ptr, -trace_mem_build_info (SHIFT , false,MO_TE , true)); +trace_mem_build_info (SHIFT , false,MO_TE , true,0 ));glue (glue (st,SUFFIX ), _p)(g2h (ptr), v); }
scripts/tracetool/transform.py +1 -0
@@ -83,6 +83,7 @@ TCG_2_HOST = { HOST_2_TCG_COMPAT = { "uint8_t": "uint32_t", + "uint16_t": "uint32_t", }
tcg/tcg-op.c +4 -4
@@ -2795,7 +2795,7 @@ void tcg_gen_qemu_ld_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop)tcg_gen_req_mo (TCG_MO_LD_LD |TCG_MO_ST_LD ); memop =tcg_canonicalize_memop (memop,0 ,0 );trace_guest_mem_before_tcg (tcg_ctx->cpu, cpu_env, - addr,trace_mem_get_info (memop,0 )); + addr,trace_mem_get_info (memop, idx,0 )); orig_memop = memop;if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop &MO_BSWAP )) {
@@ -2832,7 +2832,7 @@ void tcg_gen_qemu_st_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop)tcg_gen_req_mo (TCG_MO_LD_ST |TCG_MO_ST_ST ); memop =tcg_canonicalize_memop (memop,0 ,1 );trace_guest_mem_before_tcg (tcg_ctx->cpu, cpu_env, - addr,trace_mem_get_info (memop,1 )); + addr,trace_mem_get_info (memop, idx,1 ));if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop &MO_BSWAP )) { swap =tcg_temp_new_i32 ();
@@ -2875,7 +2875,7 @@ void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop)tcg_gen_req_mo (TCG_MO_LD_LD |TCG_MO_ST_LD ); memop =tcg_canonicalize_memop (memop,1 ,0 );trace_guest_mem_before_tcg (tcg_ctx->cpu, cpu_env, - addr,trace_mem_get_info (memop,0 )); + addr,trace_mem_get_info (memop, idx,0 )); orig_memop = memop;if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop &MO_BSWAP )) {
@@ -2923,7 +2923,7 @@ void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop)tcg_gen_req_mo (TCG_MO_LD_ST |TCG_MO_ST_ST ); memop =tcg_canonicalize_memop (memop,1 ,1 );trace_guest_mem_before_tcg (tcg_ctx->cpu, cpu_env, - addr,trace_mem_get_info (memop,1 )); + addr,trace_mem_get_info (memop, idx,1 ));if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop &MO_BSWAP )) { swap =tcg_temp_new_i64 ();
trace-events +4 -2
@@ -152,12 +152,14 @@ vcpu guest_cpu_reset(void) # uint8_t size_shift : 4; /* interpreted as "1 << size_shift" bytes */ # bool sign_extend: 1; /* sign-extended */ # uint8_t endianness : 1; /* 0: little, 1: big */ -# bool store : 1; /* wheter it's a store operation */ +# bool store : 1; /* whether it is a store operation */ +# pad : 1; +# uint8_t mmuidx : 4; /* mmuidx (softmmu only) */ # }; # # Mode: user, softmmu # Targets: TCG(all) -vcpu tcg guest_mem_before(TCGv vaddr, uint8_t info) "info=%d", "vaddr=0x%016"PRIx64" info=%d" +vcpu tcg guest_mem_before(TCGv vaddr, uint16_t info) "info=%d", "vaddr=0x%016"PRIx64" info=%d" # linux-user/syscall.c # bsd-user/syscall.c
trace/mem-internal.h +22 -9
@@ -14,11 +14,13 @@#define TRACE_MEM_SE (1ULL << 3)/* sign extended (y/n) */ #define TRACE_MEM_BE (1ULL << 4)/* big endian (y/n) */ #define TRACE_MEM_ST (1ULL << 5)/* store (y/n) */ +#define TRACE_MEM_MMU_SHIFT 8/* mmu idx */ -static inline uint8_t trace_mem_build_info ( -int size_shift,bool sign_extend,TCGMemOp endianness,bool store) +static inline uint16_t trace_mem_build_info ( +int size_shift,bool sign_extend,TCGMemOp endianness, +bool store,unsigned int mmu_idx) { -uint8_t res; +uint16_t res; res = size_shift &TRACE_MEM_SZ_SHIFT_MASK ;if (sign_extend) {
@@ -30,25 +32,36 @@ static inline uint8_t trace_mem_build_info(if (store) { res |=TRACE_MEM_ST ; } +#ifdef CONFIG_SOFTMMU + res |= mmu_idx <<TRACE_MEM_MMU_SHIFT ; +#endif return res; } -static inline uint8_t trace_mem_get_info (TCGMemOp op,bool store) +static inline uint16_t trace_mem_get_info (TCGMemOp op, +unsigned int mmu_idx, +bool store) {return trace_mem_build_info (op &MO_SIZE , !!(op &MO_SIGN ), - op &MO_BSWAP , store); + op &MO_BSWAP , store, + mmu_idx); } +/* Used by the atomic helpers */ static inline -uint8_t trace_mem_build_info_no_se_be (int size_shift,bool store) +uint16_t trace_mem_build_info_no_se_be (int size_shift,bool store, +TCGMemOpIdx oi) { -return trace_mem_build_info (size_shift, false,MO_BE , store); +return trace_mem_build_info (size_shift, false,MO_BE , store, +get_mmuidx (oi)); }static inline -uint8_t trace_mem_build_info_no_se_le (int size_shift,bool store) +uint16_t trace_mem_build_info_no_se_le (int size_shift,bool store, +TCGMemOpIdx oi) { -return trace_mem_build_info (size_shift, false,MO_LE , store); +return trace_mem_build_info (size_shift, false,MO_LE , store, +get_mmuidx (oi)); }#endif /* TRACE__MEM_INTERNAL_H */
trace/mem.h +4 -3
@@ -18,15 +18,16 @@* * Return a value for the 'info' argument in guest memory access traces. */ -static uint8_t trace_mem_get_info (TCGMemOp op,bool store); +static uint16_t trace_mem_get_info (TCGMemOp op,unsigned int mmu_idx,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 (int size_shift,bool sign_extend, -TCGMemOp endianness,bool store); +static uint16_t trace_mem_build_info (int size_shift,bool sign_extend, +TCGMemOp endianness,bool store, +unsigned int mmuidx);#include "trace/mem-internal.h"
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 07/54] trace: add mmu_index to mem_info
Quoted 4 lines · Alex Bennée
We are going to re-use
mem_infolater for plugins and will need to track themmu_idxfor softmmu code.[TODO: convert everything to use TCGMemOpIdx?]
Probably easier. At the moment,
Quoted 1 line
+#define
ATOMIC_MMU_IDXoi
this is mis-named. It works because
trace/mem-internal.h static inline uint8_t trace_mem_build_info( · line 65
Quoted 9 lines
static inline
trace/mem-internal.h +4
-2-uint8_t trace_mem_build_info_no_se_le (int size_shift,bool store) +uint16_t trace_mem_build_info_no_se_le (int size_shift,bool store, +TCGMemOpIdx oi) { -return trace_mem_build_info (size_shift, false,MO_LE , store); +return trace_mem_build_info (size_shift, false,MO_LE , store, +get_mmuidx (oi)); }
you're also inconsistent about the arguments between user-only and softmmu.
Without doing everything, maybe just use
#define ATOMIC_MMU_IDX get_mmuidx(oi)
?
r~
PATCH v4 8/54 tcg/README: fix typo s/afterwise/afterwards/
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
Afterwise is "wise after the fact", as in "hindsight". Here we meant "afterwards" (as in "subsequently"). Fix it.
--- tcg/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tcg/README +1 -1
@@ -101,7 +101,7 @@ This can be overridden using the following function modifiers: canonical locations before calling the helper. - TCG_CALL_NO_WRITE_GLOBALS means that the helper does not modify any globals. They will only be saved to their canonical location before calling helpers, - but they won't be reloaded afterwise. + but they won't be reloaded afterwards. - TCG_CALL_NO_SIDE_EFFECTS means that the call to the function is removed if the return value is not used.
Signature · 1 line
2.20.1
PATCH v4 9/54 cpu: introduce cpu_in_exclusive_context()
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
---
v4
- -> cpu_in_exclusive_context
- moved inside start/end exclusive
- fixed up cpu_exec_step_atomic
--- accel/tcg/cpu-exec.c | 5 +---- cpus-common.c | 4 ++++ include/qom/cpu.h | 13 +++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-)
accel/tcg/cpu-exec.c +1 -4
@@ -239,8 +239,6 @@ void cpu_exec_step_atomic(CPUState *cpu)uint32_t flags;uint32_t cflags =1 ;uint32_t cf_mask = cflags &CF_HASH_MASK ; -/* volatile because we modify it between setjmp and longjmp */ -volatile bool in_exclusive_region = false;if (sigsetjmp (cpu->jmp_env,0 ) ==0 ) { tb =tb_lookup__cpu_state (cpu, &pc, &cs_base, &flags, cf_mask);
@@ -254,7 +252,6 @@ void cpu_exec_step_atomic(CPUState *cpu)/* Since we got here, we know that parallel_cpus must be true. */ parallel_cpus = false; - in_exclusive_region = true; cc->cpu_exec_enter (cpu);/* execute the generated code */ trace_exec_tb (tb, pc);
@@ -274,7 +271,7 @@ void cpu_exec_step_atomic(CPUState *cpu)assert_no_pages_locked (); } -if (in_exclusive_region) { +if (cpu_in_exclusive_context (cpu)) {/* We might longjump out of either the codegen or the * execution, so must make sure we only end the exclusive * region if we started it.
cpus-common.c +4 -0
@@ -208,11 +208,15 @@ void start_exclusive(void)* section until end_exclusive resets pending_cpus to 0. */ qemu_mutex_unlock (&qemu_cpu_list_lock); + + current_cpu->in_exclusive_context = true; }/* Finish an exclusive operation. */ void end_exclusive (void ) { + current_cpu->in_exclusive_context = false; +qemu_mutex_lock (&qemu_cpu_list_lock);atomic_set (&pending_cpus,0 );qemu_cond_broadcast (&exclusive_resume);
include/qom/cpu.h +13 -0
@@ -373,6 +373,7 @@ struct CPUState {bool unplug;bool crash_occurred;bool exit_request; +bool in_exclusive_context;uint32_t cflags_next_tb;/* updates protected by BQL */ uint32_t interrupt_request;
@@ -785,6 +786,18 @@ void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data)*/ void async_safe_run_on_cpu (CPUState *cpu,run_on_cpu_func func,run_on_cpu_data data); +/** +* cpu_in_exclusive_context() +* @cpu: The vCPU to check +* +* Returns true if @cpu is an exclusive context, for example running +* something which has previously been queued via async_safe_run_on_cpu(). +*/ +static inline bool cpu_in_exclusive_context (const CPUState *cpu) +{ +return cpu->in_exclusive_context; +} +/** * qemu_get_cpu: * @index: The CPUState@cpu_index value of the CPU to obtain.
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 09/54] cpu: introduce cpu_in_exclusive_context()
Quoted 13 lines · Alex Bennée
From: "Emilio G. Cota" <[email protected]>
Suggested-by Alex Bennée <[email protected]>Reviewed-by Alex Bennée <[email protected]>Signed-off-by Emilio G. Cota <[email protected]>[AJB: moved inside start/end_exclusive fns + cleanup]Signed-off-by Alex Bennée <[email protected]>---
v4
- ->cpu_in_exclusive_context
- moved inside start/end exclusive
- fixed upcpu_exec_step_atomic
Quoted 5 lines
--- accel/tcg/cpu-exec.c | 5 +---- cpus-common.c | 4 ++++ include/qom/cpu.h | 13 +++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-)
r~
PATCH v4 10/54 translate-all: use cpu_in_exclusive_work_context() in tb_flush
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
tb_flush will be called by the plugin module from a safe work environment. Prepare for that.
--- accel/tcg/translate-all.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
accel/tcg/translate-all.c +7 -2
@@ -1268,8 +1268,13 @@ void tb_flush(CPUState *cpu) {if (tcg_enabled ()) {unsigned tb_flush_count =atomic_mb_read (&tb_ctx.tb_flush_count); -async_safe_run_on_cpu (cpu, do_tb_flush, -RUN_ON_CPU_HOST_INT (tb_flush_count)); + +if (cpu_in_exclusive_context (cpu)) { +do_tb_flush (cpu,RUN_ON_CPU_HOST_INT (tb_flush_count)); + }else { +async_safe_run_on_cpu (cpu, do_tb_flush, +RUN_ON_CPU_HOST_INT (tb_flush_count)); + } } }
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 10/54] translate-all: use cpu_in_exclusive_work_context() in tb_flush
Quoted 5 lines · Alex Bennée
From: "Emilio G. Cota" <[email protected]>
tb_flushwill be called by the plugin module from a safe work environment. Prepare for that.
Quoted 7 lines
Suggested-by Alex Bennée <[email protected]>Reviewed-by Alex Bennée <[email protected]>Signed-off-by Emilio G. Cota <[email protected]>Signed-off-by Alex Bennée <[email protected]>--- accel/tcg/translate-all.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
r~
PATCH v4 11/54 docs/devel: add plugins.rst design document
In reply to Alex BennéeThis is mostly extracted from Emilio's more verbose commit comments with some additional verbiage from me.
---
v4
- some rewording and tweaks
- made non-atomicity of inline ops more explicit
- expanded description of plugin unload
--- docs/devel/index.rst | 1 + docs/devel/plugins.rst | 107 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 docs/devel/plugins.rst
docs/devel/index.rst +1 -0
@@ -22,3 +22,4 @@ Contents: decodetree secure-coding-practices tcg + plugins
docs/devel/plugins.rst new file +107 -0
107 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 11/54] docs/devel: add plugins.rst design document
Quoted 10 lines · Alex Bennée
This is mostly extracted from Emilio's more verbose commit comments with some additional verbiage from me.
Signed-off-by Alex Bennée <[email protected]>---
v4
- some rewording and tweaks
- made non-atomicity of inline ops more explicit
- expanded description of plugin unload
Quoted 5 lines
--- docs/devel/index.rst | 1 + docs/devel/plugins.rst | 107 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 docs/devel/plugins.rst
r~
PATCH v4 12/54 configure: add --enable-plugins (MOVE TO END)
In reply to Alex BennéeThis adds the basic boilerplate feature enable option for the build. We shall expand it later.
XXX: currently this patch is included at the start of development to aid with incremental building. It should be moved to the end once the plugins are feature complete.
--- configure | 13 +++++++++++++ 1 file changed, 13 insertions(+)
configure +13 -0
@@ -499,6 +499,7 @@ docker="no" debug_mutex="no" libpmem="" default_devices="yes" +plugins="no" # cross compilers defaults, can be overridden with --cross-cc-ARCH cross_cc_aarch64="aarch64-linux-gnu-gcc"
@@ -1543,6 +1544,10 @@ for opt do ;; --disable-libpmem) libpmem=no ;; + --enable-plugins) plugins="yes" + ;; + --disable-plugins) plugins="no" + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information"
@@ -1740,6 +1745,8 @@ Advanced options (experts only): --enable-profiler profiler support --enable-debug-stack-usage track the maximum stack usage of stacks created by qemu_alloc_stack + --enable-plugins + enable plugins via shared library loading Optional features, enabled with --enable-FEATURE and disabled with --disable-FEATURE, default is enabled if available:
@@ -6481,6 +6488,7 @@ echo "docker $docker" echo "libpmem support $libpmem" echo "libudev $libudev" echo "default devices $default_devices" +echo "plugin support $plugins" if test "$supported_cpu" = "no"; then echo
@@ -7307,6 +7315,11 @@ if test "$sheepdog" = "yes" ; then echo "CONFIG_SHEEPDOG=y" >> $config_host_mak fi +if test "$plugins" = "yes" ; then + echo "CONFIG_PLUGIN=y" >> $config_host_mak + LIBS="-ldl $LIBS" +fi + if test "$tcg_interpreter" = "yes"; then QEMU_INCLUDES="-iquote \$(SRC_PATH)/tcg/tci $QEMU_INCLUDES" elif test "$ARCH" = "sparc64" ; then
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 12/54] configure: add --enable-plugins (MOVE TO END)
Quoted 7 lines · Alex Bennée
This adds the basic boilerplate feature enable option for the build. We shall expand it later.
XXX: currently this patch is included at the start of development to aid with incremental building. It should be moved to the end once the plugins are feature complete.
Quoted 5 lines
[AJB: split from larger patch]Signed-off-by Alex Bennée <[email protected]>--- configure | 13 +++++++++++++ 1 file changed, 13 insertions(+)
r~
PATCH v4 13/54 plugin: add user-facing API
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
Add the API first to ease review.
---
v3
- merge in changes to plugin install/reset/uninstall
- split api file
v4
- s/is/it/
- more docstrings
- remove qemu_plugin_register_vcpu_mem_haddr_cb and related bits
- add qemu_plugin_get_hwaddr and related bits
- drop vcpu_index from tb_trans_cb_t
--- include/qemu/qemu-plugin.h | 351 +++++++++++++++++++++++++++++++++++++ 1 file changed, 351 insertions(+) create mode 100644 include/qemu/qemu-plugin.h
include/qemu/qemu-plugin.h new file +351 -0
@@ -0,0 +1,351 @@ +/* +* Copyright (C) 2017, Emilio G. Cota <[email protected]> +* Copyright (C) 2019, Linaro +* +* License: GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ +#ifndef QEMU_PLUGIN_API_H +#define QEMU_PLUGIN_API_H + +#include <inttypes.h> +#include <stdbool.h> + +/* +* For best performance, build the plugin with -fvisibility=hidden so that +* QEMU_PLUGIN_LOCAL is implicit. Then, just mark qemu_plugin_install with +* QEMU_PLUGIN_EXPORT. For more info, see +* https://gcc.gnu.org/wiki/Visibility +*/ +#if defined _WIN32 || defined __CYGWIN__ +#ifdef BUILDING_DLL +#define QEMU_PLUGIN_EXPORT __declspec(dllexport) +#else +#define QEMU_PLUGIN_EXPORT __declspec(dllimport) +#endif +#define QEMU_PLUGIN_LOCAL +#else +#if __GNUC__ >=4 +#define QEMU_PLUGIN_EXPORT __attribute__((visibility("default"))) +#define QEMU_PLUGIN_LOCAL __attribute__((visibility("hidden"))) +#else +#define QEMU_PLUGIN_EXPORT +#define QEMU_PLUGIN_LOCAL +#endif +#endif + +typedef uint64_t qemu_plugin_id_t ; + +/** +* qemu_plugin_install() - Install a plugin +* @id: this plugin's opaque ID +* @argc: number of arguments +* @argv: array of arguments (@argc elements) +* +* All plugins must export this symbol. +* +* Note: Calling qemu_plugin_uninstall() from this function is a bug. To raise +* an error during install, return !0. +* +* Note: @argv remains valid throughout the lifetime of the loaded plugin. +*/ +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc, +char **argv); + +/* +* Prototypes for the various callback styles we will be registering +* in the following functions. +*/ +typedef void (*qemu_plugin_simple_cb_t )(qemu_plugin_id_t id); + +typedef void (*qemu_plugin_udata_cb_t )(qemu_plugin_id_t id,void *userdata); + +typedef void (*qemu_plugin_vcpu_simple_cb_t )(qemu_plugin_id_t id, +unsigned int vcpu_index); + +typedef void (*qemu_plugin_vcpu_udata_cb_t )(unsigned int vcpu_index, +void *userdata); + +/** +* qemu_plugin_uninstall() - Uninstall a plugin +* @id: this plugin's opaque ID +* @cb: callback to be called once the plugin has been removed +* +* Do NOT assume that the plugin has been uninstalled once this function +* returns. Plugins are uninstalled asynchronously, and therefore the given +* plugin receives callbacks until @cb is called. +* +* Note: Calling this function from qemu_plugin_install() is a bug. +*/ +void qemu_plugin_uninstall (qemu_plugin_id_t id,qemu_plugin_simple_cb_t cb); + +/** +* qemu_plugin_reset() - Reset a plugin +* @id: this plugin's opaque ID +* @cb: callback to be called once the plugin has been reset +* +* Unregisters all callbacks for the plugin given by @id. +* +* Do NOT assume that the plugin has been reset once this function returns. +* Plugins are reset asynchronously, and therefore the given plugin receives +* callbacks until @cb is called. +*/ +void qemu_plugin_reset (qemu_plugin_id_t id,qemu_plugin_simple_cb_t cb); + +/** +* qemu_plugin_register_vcpu_init_cb() - register a vCPU initialization callback +* @id: plugin ID +* @cb: callback function +* +* The @cb function is called every time a vCPU is initialized. +* +* See also: qemu_plugin_register_vcpu_exit_cb() +*/ +void qemu_plugin_register_vcpu_init_cb (qemu_plugin_id_t id, +qemu_plugin_vcpu_simple_cb_t cb); + +/** +* qemu_plugin_register_vcpu_exit_cb() - register a vCPU exit callback +* @id: plugin ID +* @cb: callback function +* +* The @cb function is called every time a vCPU exits. +* +* See also: qemu_plugin_register_vcpu_init_cb() +*/ +void qemu_plugin_register_vcpu_exit_cb (qemu_plugin_id_t id, +qemu_plugin_vcpu_simple_cb_t cb); + +/** +* qemu_plugin_register_vcpu_idle_cb() - register a vCPU idle callback +* @id: plugin ID +* @cb: callback function +* +* The @cb function is called every time a vCPU idles. +*/ +void qemu_plugin_register_vcpu_idle_cb (qemu_plugin_id_t id, +qemu_plugin_vcpu_simple_cb_t cb); + +/** +* qemu_plugin_register_vcpu_resume_cb() - register a vCPU resume callback +* @id: plugin ID +* @cb: callback function +* +* The @cb function is called every time a vCPU resumes execution. +*/ +void qemu_plugin_register_vcpu_resume_cb (qemu_plugin_id_t id, +qemu_plugin_vcpu_simple_cb_t cb); + +/* +* Opaque types that the plugin is given during the translation and +* instrumentation phase. +*/ +struct qemu_plugin_tb ; +struct qemu_plugin_insn ; + +enum qemu_plugin_cb_flags { +QEMU_PLUGIN_CB_NO_REGS ,/* callback does not access the CPU's regs */ +QEMU_PLUGIN_CB_R_REGS ,/* callback reads the CPU's regs */ +QEMU_PLUGIN_CB_RW_REGS ,/* callback reads and writes the CPU's regs */ +}; + +enum qemu_plugin_mem_rw { +QEMU_PLUGIN_MEM_R =1 , +QEMU_PLUGIN_MEM_W , +QEMU_PLUGIN_MEM_RW , +}; + +/** +* qemu_plugin_register_vcpu_tb_trans_cb() - register a translate cb +* @id: plugin ID +* @cb: callback function +* +* The @cb function is called every time a translation occurs. The @cb +* function is passed an opaque qemu_plugin_type which it can query +* for additional information including the list of translated +* instructions. At this point the plugin can register further +* callbacks to be triggered when the block or individual instruction +* executes. +*/ +typedef void (*qemu_plugin_vcpu_tb_trans_cb_t )(qemu_plugin_id_t id, +struct qemu_plugin_tb *tb); + +void qemu_plugin_register_vcpu_tb_trans_cb (qemu_plugin_id_t id, +qemu_plugin_vcpu_tb_trans_cb_t cb); + +/** +* qemu_plugin_register_vcpu_tb_trans_exec_cb() - register execution callback +* @tb: the opaque qemu_plugin_tb handle for the translation +* @cb: callback function +* @flags: does the plugin read or write the CPU's registers? +* @userdata: any plugin data to pass to the @cb? +* +* The @cb function is called every time a translated unit executes. +*/ +void qemu_plugin_register_vcpu_tb_exec_cb (struct qemu_plugin_tb *tb, +qemu_plugin_vcpu_udata_cb_t cb, +enum qemu_plugin_cb_flags flags, +void *userdata); + +enum qemu_plugin_op { +QEMU_PLUGIN_INLINE_ADD_U64 , +}; + +/** +* qemu_plugin_register_vcpu_tb_trans_exec_inline() - execution inline op +* @tb: the opaque qemu_plugin_tb handle for the translation +* @op: the type of qemu_plugin_op (e.g. ADD_U64) +* @ptr: the target memory location for the op +* @imm: the op data (e.g. 1) +* +* Insert an inline op to every time a translated unit executes. +* Useful if you just want to increment a single counter somewhere in +* memory. +*/ +void qemu_plugin_register_vcpu_tb_exec_inline (struct qemu_plugin_tb *tb, +enum qemu_plugin_op op, +void *ptr,uint64_t imm); + +/** +* qemu_plugin_register_vcpu_insn_exec_cb() - register insn execution cb +* @insn: the opaque qemu_plugin_insn handle for an instruction +* @cb: callback function +* @flags: does the plugin read or write the CPU's registers? +* @userdata: any plugin data to pass to the @cb? +* +* The @cb function is called every time an instruction is executed +*/ +void qemu_plugin_register_vcpu_insn_exec_cb (struct qemu_plugin_insn *insn, +qemu_plugin_vcpu_udata_cb_t cb, +enum qemu_plugin_cb_flags flags, +void *userdata); + +/** +* qemu_plugin_register_vcpu_insn_exec_inline() - insn execution inline op +* @insn: the opaque qemu_plugin_insn handle for an instruction +* @cb: callback function +* @op: the type of qemu_plugin_op (e.g. ADD_U64) +* @ptr: the target memory location for the op +* @imm: the op data (e.g. 1) +* +* Insert an inline op to every time an instruction executes. Useful +* if you just want to increment a single counter somewhere in memory. +*/ +void qemu_plugin_register_vcpu_insn_exec_inline (struct qemu_plugin_insn *insn, +enum qemu_plugin_op op, +void *ptr,uint64_t imm); + +/* +* Helpers to query information about the instructions in a block +*/ +size_t qemu_plugin_tb_n_insns (const struct qemu_plugin_tb *tb); + +uint64_t qemu_plugin_tb_vaddr (const struct qemu_plugin_tb *tb); + +struct qemu_plugin_insn * +qemu_plugin_tb_get_insn (const struct qemu_plugin_tb *tb,size_t idx); + +const void *qemu_plugin_insn_data (const struct qemu_plugin_insn *insn); + +size_t qemu_plugin_insn_size (const struct qemu_plugin_insn *insn); + +uint64_t qemu_plugin_insn_vaddr (const struct qemu_plugin_insn *insn); +void *qemu_plugin_insn_haddr (const struct qemu_plugin_insn *insn); + +/* +* Memory Instrumentation +* +* The anonymous qemu_plugin_meminfo_t and qemu_plugin_hwaddr types +* can be used in queries to QEMU to get more information about a +* given memory access. +*/ +typedef uint32_t qemu_plugin_meminfo_t ; +struct qemu_plugin_hwaddr ; + +/* meminfo queries */ +unsigned int qemu_plugin_mem_size_shift (qemu_plugin_meminfo_t info); +bool qemu_plugin_mem_is_sign_extended (qemu_plugin_meminfo_t info); +bool qemu_plugin_mem_is_big_endian (qemu_plugin_meminfo_t info); +bool qemu_plugin_mem_is_store (qemu_plugin_meminfo_t info); + +/* +* qemu_plugin_get_hwaddr(): +* @vaddr: the virtual address of the memory operation +* +* For system emulation returns a qemu_plugin_hwaddr handle to query +* details about the actual physical address backing the virtual +* address. For linux-user guests it just returns NULL. +* +* This handle is *only* valid for the duration of the callback. Any +* information about the handle should be recovered before the +* callback returns. +*/ +struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr (qemu_plugin_meminfo_t info, +uint64_t vaddr); + +bool qemu_plugin_hwaddr_is_io (struct qemu_plugin_hwaddr *hwaddr); +uint64_t qemu_plugin_hwaddr_to_raddr (const struct qemu_plugin_hwaddr *haddr); + +typedef void +(*qemu_plugin_vcpu_mem_cb_t )(unsigned int vcpu_index, +qemu_plugin_meminfo_t info,uint64_t vaddr, +void *userdata); + +void qemu_plugin_register_vcpu_mem_cb (struct qemu_plugin_insn *insn, +qemu_plugin_vcpu_mem_cb_t cb, +enum qemu_plugin_cb_flags flags, +enum qemu_plugin_mem_rw rw, +void *userdata); + +void qemu_plugin_register_vcpu_mem_inline (struct qemu_plugin_insn *insn, +enum qemu_plugin_mem_rw rw, +enum qemu_plugin_op op,void *ptr, +uint64_t imm); + + + +typedef void +(*qemu_plugin_vcpu_syscall_cb_t )(qemu_plugin_id_t id,unsigned int vcpu_index, +int64_t num,uint64_t a1,uint64_t a2, +uint64_t a3,uint64_t a4,uint64_t a5, +uint64_t a6,uint64_t a7,uint64_t a8); + +void qemu_plugin_register_vcpu_syscall_cb (qemu_plugin_id_t id, +qemu_plugin_vcpu_syscall_cb_t cb); + +typedef void +(*qemu_plugin_vcpu_syscall_ret_cb_t )(qemu_plugin_id_t id,unsigned int vcpu_idx, +int64_t num,int64_t ret); + +void +qemu_plugin_register_vcpu_syscall_ret_cb (qemu_plugin_id_t id, +qemu_plugin_vcpu_syscall_ret_cb_t cb); + + +/** +* qemu_plugin_vcpu_for_each() - iterate over the existing vCPU +* @id: plugin ID +* @cb: callback function +* +* The @cb function is called once for each existing vCPU. +* +* See also: qemu_plugin_register_vcpu_init_cb() +*/ +void qemu_plugin_vcpu_for_each (qemu_plugin_id_t id, +qemu_plugin_vcpu_simple_cb_t cb); + +void qemu_plugin_register_flush_cb (qemu_plugin_id_t id, +qemu_plugin_simple_cb_t cb); + +void qemu_plugin_register_atexit_cb (qemu_plugin_id_t id, +qemu_plugin_udata_cb_t cb,void *userdata); + +/* returns -1 in user-mode */ +int qemu_plugin_n_vcpus (void ); + +/* returns -1 in user-mode */ +int qemu_plugin_n_max_vcpus (void ); + +#endif /* QEMU_PLUGIN_API_H */
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 13/54] plugin: add user-facing API
Quoted 17 lines · Alex Bennée
From: "Emilio G. Cota" <[email protected]>
Add the API first to ease review.
Signed-off-by Emilio G. Cota <[email protected]>Signed-off-by Alex Bennée <[email protected]>---
v3
- merge in changes to plugin install/reset/uninstall
- split api file
v4
- s/is/it/
- more docstrings
- removeqemu_plugin_register_vcpu_mem_haddr_cband related bits
- addqemu_plugin_get_hwaddrand related bits
- dropvcpu_indexfromtb_trans_cb_t
Quoted 4 lines
--- include/qemu/qemu-plugin.h | 351 +++++++++++++++++++++++++++++++++++++ 1 file changed, 351 insertions(+) create mode 100644 include/qemu/qemu-plugin.h
r~
Re: [Qemu-devel] [PATCH v4 13/54] plugin: add user-facing API
In reply to Alex BennéeOne thing I would find useful is the ability to access register values during an execution-time callback. I think the easiest way to do that generically would be to expose them via the gdb functionality (like Pavel's earlier patchset did [1]), though that (currently) limits you to the general-purpose registers. Ideally it would be nice be able to access other registers (i.e. floating-point, or maybe even system registers), though those are more difficult to do generically.
Perhaps if we added some sort of architectural-support checking for individual plugins like I mentioned in another response to this patchset, we could allow some limited architecture-specific functionality in this vein? I confess I haven't thought through all the ramifications of that yet, though.
-Aaron
[1] - See qemulib_read_register() at
https://patchwork.ozlabs.org/patch/925393/
Re: [Qemu-devel] [PATCH v4 13/54] plugin: add user-facing API
Quoted 7 lines · Aaron Lindsay OS
One thing I would find useful is the ability to access register values during an execution-time callback. I think the easiest way to do that generically would be to expose them via the gdb functionality (like Pavel's earlier patchset did [1]), though that (currently) limits you to the general-purpose registers. Ideally it would be nice be able to access other registers (i.e. floating-point, or maybe even system registers), though those are more difficult to do generically.
ARM already has system register support via the gdbstub XML interface so it's certainly doable. The trick is how we do that in a probable way without leaking the gdb remote protocol into plugins (which is just very ugly).
Quoted 5 lines
Perhaps if we added some sort of architectural-support checking for individual plugins like I mentioned in another response to this patchset, we could allow some limited architecture-specific functionality in this vein? I confess I haven't thought through all the ramifications of that yet, though.
I was wondering if exposing the Elf Type would be enough? It's portable enough that plugins should be able to work with it without defining our own architecture enumeration.
Quoted 5 lines
-Aaron
[1] - See
qemulib_read_register()athttps://patchwork.ozlabs.org/patch/925393/
--
Alex Bennée
Re: [Qemu-devel] [PATCH v4 13/54] plugin: add user-facing API
Quoted 10 lines · Alex Bennée
Quoted 7 lines · Aaron Lindsay OS
One thing I would find useful is the ability to access register values during an execution-time callback. I think the easiest way to do that generically would be to expose them via the gdb functionality (like Pavel's earlier patchset did [1]), though that (currently) limits you to the general-purpose registers. Ideally it would be nice be able to access other registers (i.e. floating-point, or maybe even system registers), though those are more difficult to do generically.
Quoted 4 lines
ARM already has system register support via the gdbstub XML interface so it's certainly doable. The trick is how we do that in a probable way without leaking the gdb remote protocol into plugins (which is just very ugly).
What do you mean by "in a probable way"?
I agree that simply exposing the gdb interface does not seem like a clean solution.
Quoted 9 lines
Quoted 5 lines
Perhaps if we added some sort of architectural-support checking for individual plugins like I mentioned in another response to this patchset, we could allow some limited architecture-specific functionality in this vein? I confess I haven't thought through all the ramifications of that yet, though.
I was wondering if exposing the Elf Type would be enough? It's portable enough that plugins should be able to work with it without defining our own architecture enumeration.
I can't think of a reason that wouldn't work, assuming you're referring to exposing a value corresponding to the e_machine ELF header.
-Aaron
Re: [Qemu-devel] [PATCH v4 13/54] plugin: add user-facing API
Quoted 16 lines · Aaron Lindsay OS
Quoted 10 lines · Alex Bennée
Quoted 7 lines · Aaron Lindsay OS
One thing I would find useful is the ability to access register values during an execution-time callback. I think the easiest way to do that generically would be to expose them via the gdb functionality (like Pavel's earlier patchset did [1]), though that (currently) limits you to the general-purpose registers. Ideally it would be nice be able to access other registers (i.e. floating-point, or maybe even system registers), though those are more difficult to do generically.
Quoted 4 lines
ARM already has system register support via the gdbstub XML interface so it's certainly doable. The trick is how we do that in a probable way without leaking the gdb remote protocol into plugins (which is just very ugly).
Quoted 4 lines
What do you mean by "in a probable way"?
I agree that simply exposing the gdb interface does not seem like a clean solution.
That was a typo - portable was what I was aiming for. The problem with the gdb interface is how you tie register id's to something useful rather than having to encode the arbitrary gdb register enumeration into your plugins.
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Perhaps if we added some sort of architectural-support checking for individual plugins like I mentioned in another response to this patchset, we could allow some limited architecture-specific functionality in this vein? I confess I haven't thought through all the ramifications of that yet, though.
Quoted 6 lines
Quoted 3 lines
I was wondering if exposing the Elf Type would be enough? It's portable enough that plugins should be able to work with it without defining our own architecture enumeration.
I can't think of a reason that wouldn't work, assuming you're referring to exposing a value corresponding to the
e_machineELF header.
Yes exactly that - I started but uncovered some hideousness in our current Elf support so there will be a short diversion to re-factor that into something a bit more usable across the code base.
Quoted 2 lines
-Aaron
--
Alex Bennée
PATCH v4 14/54 plugin: add core code
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
---
v3
- moved to plugins/
- merged
plugin: remove uninstall_cb_t and just use simple_cb_t
plugin: handle uninstall when !current_cpu
plugin: introduce qemu_plugin_reset
- split into core/loader
- use GArray/GByteArray/GPtrArray instead of homegrown funcs
v4
- document QEMU_PLUGIN_EV_MAX
- move qemu_plugin_ram_addr_from_host to api
- drop vcpu_index from trans cb
- s/plugin_dyn_cb_type/plugin_dyn_cb_subtype/ in qemu_plugin_dyn_cb
- remove haddr from memory hooks
- checkpatch fixes
--- Makefile | 9 +- Makefile.target | 2 + include/qemu/plugin.h | 255 +++++++++++++++++++++ include/qom/cpu.h | 6 + plugins/Makefile.objs | 6 + plugins/core.c | 499 ++++++++++++++++++++++++++++++++++++++++++ plugins/loader.c | 353 ++++++++++++++++++++++++++++++ plugins/plugin.h | 95 ++++++++ 8 files changed, 1224 insertions(+), 1 deletion(-) create mode 100644 include/qemu/plugin.h create mode 100644 plugins/Makefile.objs create mode 100644 plugins/core.c create mode 100644 plugins/loader.c create mode 100644 plugins/plugin.h
Makefile +8 -1
@@ -841,7 +841,11 @@ endif ICON_SIZES=16x16 24x24 32x32 48x48 64x64 128x128 256x256 512x512 -install: all $(if $(BUILD_DOCS),install-doc) install-datadir install-localstatedir \ +install-includedir: + $(INSTALL_DIR) "$(DESTDIR)$(includedir)" + +install: all $(if $(BUILD_DOCS),install-doc) \ + install-datadir install-localstatedir install-includedir \ $(if $(INSTALL_BLOBS),$(edk2-decompressed)) \ recurse-install ifneq ($(TOOLS),)
@@ -903,6 +907,9 @@ endif "$(DESTDIR)$(qemu_desktopdir)/qemu.desktop" ifdef CONFIG_GTK $(MAKE) -C po $@ +endif +ifeq ($(CONFIG_PLUGIN),y) + $(INSTALL_DATA) $(SRC_PATH)/include/qemu/qemu-plugin.h "$(DESTDIR)$(includedir)/qemu-plugin.h" endif $(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/keymaps" set -e; for x in $(KEYMAPS); do \
Makefile.target +2 -0
@@ -122,6 +122,8 @@ obj-y += disas.o obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o LIBS := $(libs_cpu) $(LIBS) +obj-$(CONFIG_PLUGIN) += plugins/ + ######################################################### # Linux user emulator target
include/qemu/plugin.h new file +255 -0
255 lines not on this page · raw message
include/qom/cpu.h +6 -0
@@ -29,6 +29,7 @@#include "qemu/rcu_queue.h" #include "qemu/queue.h" #include "qemu/thread.h" +#include "qemu/plugin.h" typedef int (*WriteCoreDumpFunction )(const void *buf,size_t size,void *opaque);
@@ -345,6 +346,7 @@ struct qemu_work_item;* @trace_dstate_delayed: Delayed changes to trace_dstate (includes all changes * to @trace_dstate). * @trace_dstate: Dynamic tracing state of events for this vCPU (bitmask). +* @plugin_mask: Plugin event bitmap. Modified only via async work. * @ignore_memory_transaction_failures: Cached copy of the MachineState * flag of the same name: allows the board to suppress calling of the * CPU do_transaction_failed hook function.
@@ -430,6 +432,10 @@ struct CPUState {DECLARE_BITMAP (trace_dstate_delayed,CPU_TRACE_DSTATE_MAX_EVENTS );DECLARE_BITMAP (trace_dstate,CPU_TRACE_DSTATE_MAX_EVENTS ); +DECLARE_BITMAP (plugin_mask,QEMU_PLUGIN_EV_MAX ); + +GArray *plugin_mem_cbs; +/* TODO Move common fields from CPUArchState here. */ int cpu_index;int cluster_index;
plugins/Makefile.objs new file +6 -0
@@ -0,0 +1,6 @@ +# +# Plugin Support +# + +obj-y += loader.o +obj-y += core.o
plugins/core.c new file +499 -0
499 lines not on this page · raw message
plugins/loader.c new file +353 -0
353 lines not on this page · raw message
plugins/plugin.h new file +95 -0
95 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 14/54] plugin: add core code
Quoted 42 lines · Alex Bennée
include/qemu/plugin.h new file +42
-0+static inline struct qemu_plugin_insn *qemu_plugin_insn_alloc (void ) +{ +int i, j; + struct qemu_plugin_insn *insn = g_new0(struct qemu_plugin_insn, 1); + insn->data =g_byte_array_sized_new (4 ); + +for (i =0 ; i <PLUGIN_N_CB_TYPES ; i++) { +for (j =0 ; j <PLUGIN_N_CB_SUBTYPES ; j++) { + insn->cbs[i][j] =g_array_new (false, false, +sizeof (struct qemu_plugin_dyn_cb )); + } + } +return insn; +} + +struct qemu_plugin_tb { +GPtrArray *insns; +size_t n; +uint64_t vaddr; +uint64_t vaddr2; +void *haddr1; +void *haddr2; +GArray *cbs[PLUGIN_N_CB_SUBTYPES ]; +}; + +/** +* qemu_plugin_tb_insn_get(): get next plugin record for translation. +* +*/ +static inline +struct qemu_plugin_insn *qemu_plugin_tb_insn_get (struct qemu_plugin_tb *tb) +{ +struct qemu_plugin_insn *insn; +int i, j; + +if (unlikely (tb->n == tb->insns->len)) { +struct qemu_plugin_insn *new_insn =qemu_plugin_insn_alloc (); +g_ptr_array_add (tb->insns, new_insn); + } + insn =g_ptr_array_index (tb->insns, tb->n++); +g_byte_array_set_size (insn->data,0 ); + insn->calls_helpers = false;
include/qemu/plugin.h line 183
Quoted 10 lines
include/qemu/plugin.h new file +10
-0+ insn->mem_helper = false; + +for (i =0 ; i <PLUGIN_N_CB_TYPES ; i++) { +for (j =0 ; j <PLUGIN_N_CB_SUBTYPES ; j++) { +g_array_set_size (insn->cbs[i][j],0 ); + } + } + +return insn; +}
Why are these inlines in the header?
They seem to be used only once in patch 20. It seems like these should be local to plugin-gen.c.
Otherwise,
r~
Re: [Qemu-devel] [PATCH v4 14/54] plugin: add core code
In reply to Alex BennéeQuoted 17 lines · Alex Bennée
From: "Emilio G. Cota" <[email protected]>
Signed-off-by Emilio G. Cota <[email protected]>[AJB: moved directory and merged various fixes]Signed-off-by Alex Bennée <[email protected]>plugins/loader.c new file +10
-0+static int plugin_load (struct qemu_plugin_desc *desc) +{ +qemu_plugin_install_func_t install; +struct qemu_plugin_ctx *ctx; +char *err; +int rc; + + ctx =qemu_memalign (qemu_dcache_linesize,sizeof (*ctx)); +memset (ctx,0 ,sizeof (*ctx)); + ctx->desc = desc;
plugins/loader.c line 152
Quoted 10 lines
plugins/loader.c new file +10
-0+ + ctx->handle =dlopen (desc->path,RTLD_NOW ); +if (ctx->handle ==NULL ) { +error_report ("%s: %s" , __func__,dlerror ()); + goto err_dlopen; + } + +/* clear any previous dlerror, call dlsym, then check dlerror */ +dlerror (); + install =dlsym (ctx->handle,"qemu_plugin_install" );
If you use 'GModule' instead of dlopen, then we get portability to many more platforms, including ablity to load DLLs on Windows:
https://developer.gnome.org/glib/stable/glib-Dynamic-Loading-of-Modules.html
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v4 15/54 plugin: add implementation of the api
In reply to Alex Bennée---
v4
- add qemu_plugin_ram_addr_from_host
- remove _haddr api calls
--- plugins/Makefile.objs | 1 + plugins/api.c | 299 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 300 insertions(+) create mode 100644 plugins/api.c
plugins/Makefile.objs +1 -0
@@ -4,3 +4,4 @@ obj-y += loader.o obj-y += core.o +obj-y += api.o
plugins/api.c new file +299 -0
299 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 15/54] plugin: add implementation of the api
Quoted 6 lines · Alex Bennée
plugins/api.c new file +6
-0+uint64_t qemu_plugin_hwaddr_to_raddr (const struct qemu_plugin_hwaddr *haddr) +{ +#if 0 /* XXX FIXME should be SOFTMMU */ +ram_addr_t ram_addr; + +g_assert (haddr);
plugins/api.c line 269
Quoted 10 lines
plugins/api.c new file +10
-0+ ram_addr =qemu_ram_addr_from_host (haddr); +if (ram_addr ==RAM_ADDR_INVALID ) { +error_report ("Bad ram pointer %p" , haddr); +abort (); + } +return ram_addr; +#else +return 0 ; +#endif +}
What would a plugin do with an raddr? This seems like a qemu internal thing, and not really related to anything that the plugin could match up to the hw.
Otherwise,
r~
PATCH v4 16/54 queue: add QTAILQ_REMOVE_SEVERAL
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
This is faster than removing elements one by one.
Will gain a user soon.
--- include/qemu/queue.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
include/qemu/queue.h +10 -0
@@ -422,6 +422,16 @@ union { \ (elm)->field.tqe_circ.tql_prev =NULL ; \ }while (/*CONSTCOND*/ 0 ) +/* remove @left, @right and all elements in between from @head */ +#define QTAILQ_REMOVE_SEVERAL(head, left, right, field) do { \ + if (((right)->field.tqe_next) != NULL) \ + (right)->field.tqe_next->field.tqe_circ.tql_prev = \ + (left)->field.tqe_circ.tql_prev; \ + else \ + (head)->tqh_circ.tql_prev = (left)->field.tqe_circ.tql_prev; \ + (left)->field.tqe_circ.tql_prev->tql_next = (right)->field.tqe_next; \ + } while (/*CONSTCOND*/0) +#define QTAILQ_FOREACH (var, head, field) \ for ((var) = ((head)->tqh_first); \ (var); \
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 16/54] queue: add QTAILQ_REMOVE_SEVERAL
Quoted 11 lines · Alex Bennée
From: "Emilio G. Cota" <[email protected]>
This is faster than removing elements one by one.
Will gain a user soon.
Signed-off-by Emilio G. Cota <[email protected]>Signed-off-by Alex Bennée <[email protected]>--- include/qemu/queue.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
Re: [Qemu-devel] [PATCH v4 16/54] queue: add QTAILQ_REMOVE_SEVERAL
In reply to Alex BennéeQuoted 11 lines · Alex Bennée
From: "Emilio G. Cota" <[email protected]>
This is faster than removing elements one by one.
Will gain a user soon.
Signed-off-by Emilio G. Cota <[email protected]>Signed-off-by Alex Bennée <[email protected]>--- include/qemu/queue.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
r~
PATCH v4 17/54 cputlb: document get_page_addr_code
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
--- accel/tcg/cputlb.c | 5 ----- include/exec/exec-all.h | 24 +++++++++++++++++++++--- 2 files changed, 21 insertions(+), 8 deletions(-)
accel/tcg/cputlb.c +0 -5
@@ -1015,11 +1015,6 @@ static bool victim_tlb_hit(CPUArchState *env, size_t mmu_idx, size_t index,victim_tlb_hit (env, mmu_idx, index, offsetof(CPUTLBEntry , TY), \ (ADDR) & TARGET_PAGE_MASK) -/* NOTE: this function can trigger an exception */ -/* NOTE2: the returned address is not exactly the physical address: it -* is actually a ram_addr_t (in system mode; the user mode emulation -* version of this function returns a guest virtual address). - */tb_page_addr_t get_page_addr_code (CPUArchState *env,target_ulong addr) {uintptr_t mmu_idx =cpu_mmu_index (env, true);
include/exec/exec-all.h +21 -3
@@ -480,7 +480,15 @@ void mmap_lock(void);void mmap_unlock (void );bool have_mmap_lock (void ); -static inline tb_page_addr_t get_page_addr_code (CPUArchState *env1,target_ulong addr) +/** +* get_page_addr_code() - user-mode version +* @env: CPUArchState +* @addr: guest virtual address of guest code +* +* Returns @addr. +*/ +static inline tb_page_addr_t get_page_addr_code (CPUArchState *env, +target_ulong addr) {return addr; }
@@ -488,8 +496,18 @@ static inline tb_page_addr_t get_page_addr_code(CPUArchState *env1, target_ulongstatic inline void mmap_lock (void ) {}static inline void mmap_unlock (void ) {} -/* cputlb.c */ -tb_page_addr_t get_page_addr_code (CPUArchState *env1,target_ulong addr); +/** +* get_page_addr_code() - full-system version +* @env: CPUArchState +* @addr: guest virtual address of guest code +* +* If we cannot translate and execute from the entire RAM page, or if +* the region is not backed by RAM, returns -1. Otherwise, returns the +* ram_addr_t corresponding to the guest code at @addr. +* +* Note: this function can trigger an exception. +*/ +tb_page_addr_t get_page_addr_code (CPUArchState *env,target_ulong addr);void tlb_reset_dirty (CPUState *cpu,ram_addr_t start1,ram_addr_t length);void tlb_set_dirty (CPUState *cpu,target_ulong vaddr);
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 17/54] cputlb: document get_page_addr_code
Quoted 9 lines · Alex Bennée
From: "Emilio G. Cota" <[email protected]>
Suggested-by Alex Bennée <[email protected]>Signed-off-by Emilio G. Cota <[email protected]>Signed-off-by Alex Bennée <[email protected]>--- accel/tcg/cputlb.c | 5 ----- include/exec/exec-all.h | 24 +++++++++++++++++++++--- 2 files changed, 21 insertions(+), 8 deletions(-)
r~
PATCH v4 18/54 cputlb: introduce get_page_addr_code_hostp
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
This will be used by plugins to get the host address of instructions.
--- accel/tcg/cputlb.c | 14 +++++++++++++- include/exec/exec-all.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-)
accel/tcg/cputlb.c +13 -1
@@ -1015,7 +1015,8 @@ static bool victim_tlb_hit(CPUArchState *env, size_t mmu_idx, size_t index,victim_tlb_hit (env, mmu_idx, index, offsetof(CPUTLBEntry , TY), \ (ADDR) & TARGET_PAGE_MASK) -tb_page_addr_t get_page_addr_code (CPUArchState *env,target_ulong addr) +tb_page_addr_t get_page_addr_code_hostp (CPUArchState *env,target_ulong addr, +void **hostp) {uintptr_t mmu_idx =cpu_mmu_index (env, true);uintptr_t index =tlb_index (env, mmu_idx, addr);
@@ -1040,13 +1041,24 @@ tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr)* than a target page, so we must redo the MMU check every insn * - TLB_MMIO: region is not backed by RAM */ +if (hostp) { + *hostp =NULL ; + }return -1 ; } p = (void *)((uintptr_t )addr + entry->addend); +if (hostp) { + *hostp = p; + }return qemu_ram_addr_from_host_nofail (p); } +tb_page_addr_t get_page_addr_code (CPUArchState *env,target_ulong addr) +{ +return get_page_addr_code_hostp (env, addr,NULL ); +} +/* Probe for whether the specified guest write access is permitted. * If it is not permitted then an exception will be taken in the same * way as if this were a real write access (and we will not return).
include/exec/exec-all.h +38 -0
@@ -21,6 +21,7 @@#define EXEC_ALL_H #include "exec/tb-context.h" +#include "exec/cpu_ldst.h" #include "sysemu/cpus.h" /* allow to see translation results - the slowdown should be negligible, so we leave it */
@@ -492,6 +493,26 @@ static inline tb_page_addr_t get_page_addr_code(CPUArchState *env, {return addr; } + +/** +* get_page_addr_code_hostp() - user-mode version +* @env: CPUArchState +* @addr: guest virtual address of guest code +* +* Returns @addr. +* +* If @hostp is non-NULL, sets *@hostp to the host address where @addr's content +* is kept. +*/ +static inline tb_page_addr_t get_page_addr_code_hostp (CPUArchState *env, +target_ulong addr, +void **hostp) +{ +if (hostp) { + *hostp =g2h (addr); + } +return addr; +}#else static inline void mmap_lock (void ) {}static inline void mmap_unlock (void ) {}
@@ -509,6 +530,23 @@ static inline void mmap_unlock(void) {}*/ tb_page_addr_t get_page_addr_code (CPUArchState *env,target_ulong addr); +/** +* get_page_addr_code_hostp() - full-system version +* @env: CPUArchState +* @addr: guest virtual address of guest code +* +* See get_page_addr_code() (full-system version) for documentation on the +* return value. +* +* Sets *@hostp (when @hostp is non-NULL) as follows. +* If the return value is -1, sets *@hostp to NULL. Otherwise, sets *@hostp +* to the host address where @addr's content is kept. +* +* Note: this function can trigger an exception. +*/ +tb_page_addr_t get_page_addr_code_hostp (CPUArchState *env,target_ulong addr, +void **hostp); +void tlb_reset_dirty (CPUState *cpu,ram_addr_t start1,ram_addr_t length);void tlb_set_dirty (CPUState *cpu,target_ulong vaddr);
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 18/54] cputlb: introduce get_page_addr_code_hostp
Quoted 11 lines · Alex Bennée
From: "Emilio G. Cota" <[email protected]>
This will be used by plugins to get the host address of instructions.
Signed-off-by Emilio G. Cota <[email protected]>Signed-off-by Alex Bennée <[email protected]>--- accel/tcg/cputlb.c | 14 +++++++++++++- include/exec/exec-all.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-)
r~
PATCH v4 19/54 tcg: add tcg_gen_st_ptr
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
Will gain a user soon.
--- tcg/tcg-op.h | 5 +++++ 1 file changed, 5 insertions(+)
tcg/tcg-op.h +5 -0
@@ -1249,6 +1249,11 @@ static inline void tcg_gen_ld_ptr(TCGv_ptr r, TCGv_ptr a, intptr_t o)glue (tcg_gen_ld_,PTR )((NAT )r, a, o); } +static inline void tcg_gen_st_ptr (TCGv_ptr r,TCGv_ptr a,intptr_t o) +{ +glue (tcg_gen_st_,PTR )((NAT )r, a, o); +} +static inline void tcg_gen_discard_ptr (TCGv_ptr a) {glue (tcg_gen_discard_,PTR )((NAT )a);
Signature · 1 line
2.20.1
PATCH v4 20/54 plugin-gen: add module for TCG-related code
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
We first inject empty instrumentation from translator_loop. After translation, we go through the plugins to see what they want to register for, filling in the empty instrumentation. If if turns out that some instrumentation remains unused, we remove it.
This approach supports the following features:
- Inlining TCG code for simple operations. Note that we do not export TCG ops to plugins. Instead, we give them a C API to insert inlined ops. So far we only support adding an immediate to a u64, e.g. to count events.
- "Direct" callbacks. These are callbacks that do not go via a helper. Instead, the helper is defined at run-time, so that the plugin code is directly called from TCG. This makes direct callbacks as efficient as possible; they are therefore used for very frequent events, e.g. memory callbacks.
- Passing the host address to memory callbacks. Most of this is implemented in a later patch though.
- Instrumentation of memory accesses performed from helpers. See the corresponding comment, as well as a later patch.
---
v3
- introduce alloc_tcg_plugin_context
- allocate GPtrArray for tracking insns
v4
- remove hwaddr variants of callbacks
- pass full 32bit meminfo
- remove now unused code
- move plugin_gen_from into .c file
--- accel/tcg/Makefile.objs | 1 + accel/tcg/plugin-gen.c | 977 ++++++++++++++++++++++++++++++++++++ accel/tcg/plugin-helpers.h | 5 + include/exec/helper-gen.h | 1 + include/exec/helper-proto.h | 1 + include/exec/helper-tcg.h | 1 + include/exec/plugin-gen.h | 57 +++ tcg/tcg-op.h | 11 + tcg/tcg-opc.h | 3 + tcg/tcg.c | 22 + tcg/tcg.h | 20 + 11 files changed, 1099 insertions(+) create mode 100644 accel/tcg/plugin-gen.c create mode 100644 accel/tcg/plugin-helpers.h create mode 100644 include/exec/plugin-gen.h
accel/tcg/Makefile.objs +1 -0
@@ -6,3 +6,4 @@ obj-y += translator.o obj-$(CONFIG_USER_ONLY) += user-exec.o obj-$(call lnot,$(CONFIG_SOFTMMU)) += user-exec-stub.o +obj-$(CONFIG_PLUGIN) += plugin-gen.o
accel/tcg/plugin-gen.c new file +977 -0
977 lines not on this page · raw message
accel/tcg/plugin-helpers.h new file +5 -0
@@ -0,0 +1,5 @@ +#ifdef CONFIG_PLUGIN +/* Note: no TCG flags because those are overwritten later */ +DEF_HELPER_2(plugin_vcpu_udata_cb, void, i32, ptr) +DEF_HELPER_4(plugin_vcpu_mem_cb, void, i32, i32, i64, ptr) +#endif
include/exec/helper-gen.h +1 -0
@@ -70,6 +70,7 @@ static inline void glue(gen_helper_, name)(dh_retvar_decl(ret) \#include "trace/generated-helpers.h" #include "trace/generated-helpers-wrappers.h" #include "tcg-runtime.h" +#include "plugin-helpers.h" #undef DEF_HELPER_FLAGS_0#undef DEF_HELPER_FLAGS_1
include/exec/helper-proto.h +1 -0
@@ -33,6 +33,7 @@ dh_ctype(ret) HELPER(name) (dh_ctype(t1), dh_ctype(t2), dh_ctype(t3), \#include "helper.h" #include "trace/generated-helpers.h" #include "tcg-runtime.h" +#include "plugin-helpers.h" #undef DEF_HELPER_FLAGS_0#undef DEF_HELPER_FLAGS_1
include/exec/helper-tcg.h +1 -0
@@ -55,6 +55,7 @@#include "helper.h" #include "trace/generated-helpers.h" #include "tcg-runtime.h" +#include "plugin-helpers.h" #undef str#undef DEF_HELPER_FLAGS_0
include/exec/plugin-gen.h new file +57 -0
57 lines not on this page · raw message
tcg/tcg-op.h +11 -0
@@ -833,6 +833,17 @@ void tcg_gen_goto_tb(unsigned idx);*/ void tcg_gen_lookup_and_goto_ptr (void ); +static inline void tcg_gen_plugin_cb_start (unsigned from,unsigned type, +unsigned wr) +{ +tcg_gen_op3 (INDEX_op_plugin_cb_start, from, type, wr); +} + +static inline void tcg_gen_plugin_cb_end (void ) +{ +tcg_emit_op (INDEX_op_plugin_cb_end); +} +#if TARGET_LONG_BITS ==32 #define tcg_temp_new () tcg_temp_new_i32()#define tcg_global_reg_new tcg_global_reg_new_i32
tcg/tcg-opc.h +3 -0
@@ -198,6 +198,9 @@ DEF(goto_tb, 0, 0, 1, TCG_OPF_BB_EXIT | TCG_OPF_BB_END)DEF (goto_ptr,0 ,1 ,0 , TCG_OPF_BB_EXIT | TCG_OPF_BB_END | IMPL(TCG_TARGET_HAS_goto_ptr)) +DEF(plugin_cb_start, 0, 0, 3, TCG_OPF_NOT_PRESENT) +DEF(plugin_cb_end, 0, 0, 0, TCG_OPF_NOT_PRESENT) +DEF (qemu_ld_i32,1 ,TLADDR_ARGS ,1 , TCG_OPF_CALL_CLOBBER | TCG_OPF_SIDE_EFFECTS) DEF(qemu_st_i32, 0, TLADDR_ARGS + 1, 1,
tcg/tcg.c +22 -0
@@ -737,6 +737,15 @@ void tcg_region_init(void)#endif } +static void alloc_tcg_plugin_context (TCGContext *s) +{ +#ifdef CONFIG_PLUGIN + s->plugin_tb = g_new0(struct qemu_plugin_tb, 1); + s->plugin_tb->insns = +g_ptr_array_new_with_free_func (qemu_plugin_insn_cleanup_fn); +#endif +} +/* * All TCG threads except the parent (i.e. the one that called tcg_context_init * and registered the target's TCG globals) must register with this function
@@ -781,6 +790,10 @@ void tcg_register_thread(void)g_assert (n < ms->smp.max_cpus);atomic_set (&tcg_ctxs[n], s); +if (n >0 ) { +alloc_tcg_plugin_context (s); + } + tcg_ctx = s;qemu_mutex_lock (®ion.lock); err =tcg_region_initial_alloc__locked (tcg_ctx);
@@ -977,6 +990,8 @@ void tcg_context_init(TCGContext *s) indirect_reg_alloc_order[i] = tcg_target_reg_alloc_order[i]; } +alloc_tcg_plugin_context (s); + tcg_ctx = s;/* * In user-mode we simply share the init context among threads, since we
@@ -1682,6 +1697,13 @@ void tcg_gen_callN(void *func, TCGTemp *ret, int nargs, TCGTemp **args) flags = info->flags; sizemask = info->sizemask; +#ifdef CONFIG_PLUGIN +/* detect non-plugin helpers */ +if (tcg_ctx->plugin_insn &&unlikely (strncmp (info->name,"plugin_" ,7 ))) { + tcg_ctx->plugin_insn->calls_helpers = true; + } +#endif +#if defined(__sparc__) && !defined(__arch64__) \ && !defined(CONFIG_TCG_INTERPRETER )/* We have 64-bit values in one register, but need to pass as two
tcg/tcg.h +20 -0
@@ -625,6 +625,9 @@ typedef struct TCGOp {/* Next and previous opcodes. */ QTAILQ_ENTRY (TCGOp) link; +#ifdef CONFIG_PLUGIN +QSIMPLEQ_ENTRY (TCGOp) plugin_link; +#endif /* Arguments for the opcode. */ TCGArg args[MAX_OPC_PARAM ];
@@ -726,6 +729,23 @@ struct TCGContext {TCGLabel *exitreq_label; +#ifdef CONFIG_PLUGIN +/* +* We keep one plugin_tb struct per TCGContext. Note that on every TB +* translation we clear but do not free its contents; this way we +* avoid a lot of malloc/free churn, since after a few TB's it's +* unlikely that we'll need to allocate either more instructions or more +* space for instructions (for variable-instruction-length ISAs). +*/ +struct qemu_plugin_tb *plugin_tb; + +/* descriptor of the instruction being translated */ +struct qemu_plugin_insn *plugin_insn; + +/* list to quickly access the injected ops */ + QSIMPLEQ_HEAD(, TCGOp) plugin_ops; +#endif +TCGTempSet free_temps[TCG_TYPE_COUNT *2 ];TCGTemp temps[TCG_MAX_TEMPS ];/* globals first, temps after */
Signature · 1 line
2.20.1
PATCH v4 21/54 atomic_template: fix indentation in GEN_ATOMIC_HELPER
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
--- accel/tcg/atomic_template.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
accel/tcg/atomic_template.h +1 -1
@@ -284,7 +284,7 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, target_ulong addr,#define GEN_ATOMIC_HELPER (X ) \ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr, \ - ABI_TYPE val EXTRA_ARGS) \ + ABI_TYPE val EXTRA_ARGS) \ { \ ATOMIC_MMU_DECLS; \ DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP; \
Signature · 1 line
2.20.1
PATCH v4 22/54 atomic_template: add inline trace/plugin helpers
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
In preparation for plugin support.
---
v4
- move common stuff to atomic_common.inc.c
- fix ups for widened uint16_t info
- drop haddr in helpers
- fix wide lines
--- accel/tcg/atomic_common.inc.c | 50 +++++++++++++++++++ accel/tcg/atomic_template.h | 93 +++++++++++++++++++++-------------- accel/tcg/cputlb.c | 2 + accel/tcg/user-exec.c | 2 + 4 files changed, 111 insertions(+), 36 deletions(-) create mode 100644 accel/tcg/atomic_common.inc.c
accel/tcg/atomic_common.inc.c new file +50 -0
@@ -0,0 +1,50 @@ +/* +* Common Atomic Helper Functions +* +* This file should be included before the various instantiations of +* the atomic_template.h helpers. +* +* Copyright (c) 2019 Linaro +* Written by Alex Bennée <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +static inline +void atomic_trace_rmw_pre (CPUArchState *env,target_ulong addr,uint16_t info) +{ +CPUState *cpu =env_cpu (env); + +trace_guest_mem_before_exec (cpu, addr, info); +trace_guest_mem_before_exec (cpu, addr, info |TRACE_MEM_ST ); +} + +static inline void +atomic_trace_rmw_post (CPUArchState *env,target_ulong addr,uint16_t info) +{ +} + +static inline +void atomic_trace_ld_pre (CPUArchState *env,target_ulong addr,uint16_t info) +{ +trace_guest_mem_before_exec (env_cpu (env), addr, info); +} + +static inline +void atomic_trace_ld_post (CPUArchState *env,target_ulong addr,uint16_t info) +{ +} + +static inline +void atomic_trace_st_pre (CPUArchState *env,target_ulong addr,uint16_t info) +{ +trace_guest_mem_before_exec (env_cpu (env), addr, info); +} + +static inline +void atomic_trace_st_post (CPUArchState *env,target_ulong addr,uint16_t info) +{ +}
accel/tcg/atomic_template.h +57 -36
230 lines not on this page · raw message
accel/tcg/cputlb.c +2 -0
@@ -1701,6 +1701,8 @@ void helper_be_stq_mmu(CPUArchState *env, target_ulong addr, uint64_t val, } while (0)#define ATOMIC_MMU_IDX oi +#include "atomic_common.inc.c" +#define DATA_SIZE 1#include "atomic_template.h"
accel/tcg/user-exec.c +2 -0
@@ -724,6 +724,8 @@ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,#define ATOMIC_NAME (X ) HELPER(glue(glue(atomic_ ## X, SUFFIX), END))#define EXTRA_ARGS +#include "atomic_common.inc.c" +#define DATA_SIZE 1#include "atomic_template.h"
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 22/54] atomic_template: add inline trace/plugin helpers
Quoted 13 lines · Alex Bennée
From: "Emilio G. Cota" <[email protected]>
In preparation for plugin support.
Signed-off-by Emilio G. Cota <[email protected]>Signed-off-by Alex Bennée <[email protected]>---
v4
- move common stuff toatomic_common.inc.c
- fix ups for wideneduint16_tinfo
- drop haddr in helpers
- fix wide lines
Quoted 7 lines
--- accel/tcg/atomic_common.inc.c | 50 +++++++++++++++++++ accel/tcg/atomic_template.h | 93 +++++++++++++++++++++-------------- accel/tcg/cputlb.c | 2 + accel/tcg/user-exec.c | 2 + 4 files changed, 111 insertions(+), 36 deletions(-) create mode 100644 accel/tcg/atomic_common.inc.c
r~
PATCH v4 23/54 tcg: let plugins instrument virtual memory accesses
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
To capture all memory accesses we need hook into all the various helper functions that are involved in memory operations as well as the injected inline helper calls. A later commit will allow us to resolve the actual guest HW addresses by replaying the lookup.
---
v3
- fixes for cpu_neg()
v4
- rebase fixups, moved cpu_neg() fixes down the stack
- drop haddr support - will be restored with later helper
- reword commit
--- accel/tcg/atomic_common.inc.c | 4 +++ accel/tcg/atomic_template.h | 1 + accel/tcg/cpu-exec.c | 3 ++ accel/tcg/cputlb.c | 14 ++++---- include/exec/cpu-defs.h | 1 + include/exec/cpu_ldst_template.h | 28 +++++++++------- include/exec/cpu_ldst_useronly_template.h | 29 ++++++++-------- tcg/tcg-op.c | 40 ++++++++++++++++++----- tcg/tcg.h | 1 + 9 files changed, 79 insertions(+), 42 deletions(-)
accel/tcg/atomic_common.inc.c +4 -0
@@ -25,6 +25,8 @@ void atomic_trace_rmw_pre(CPUArchState *env, target_ulong addr, uint16_t info)static inline void atomic_trace_rmw_post (CPUArchState *env,target_ulong addr,uint16_t info) { +qemu_plugin_vcpu_mem_cb (env_cpu (env), addr, info); +qemu_plugin_vcpu_mem_cb (env_cpu (env), addr, info |TRACE_MEM_ST ); } static inline
@@ -36,6 +38,7 @@ void atomic_trace_ld_pre(CPUArchState *env, target_ulong addr, uint16_t info)static inline void atomic_trace_ld_post (CPUArchState *env,target_ulong addr,uint16_t info) { +qemu_plugin_vcpu_mem_cb (env_cpu (env), addr, info); } static inline
@@ -47,4 +50,5 @@ void atomic_trace_st_pre(CPUArchState *env, target_ulong addr, uint16_t info)static inline void atomic_trace_st_post (CPUArchState *env,target_ulong addr,uint16_t info) { +qemu_plugin_vcpu_mem_cb (env_cpu (env), addr, info); }
accel/tcg/atomic_template.h +1 -0
@@ -18,6 +18,7 @@* License along with this library; if not, see <http://www.gnu.org/licenses/>. */ +#include "qemu/plugin.h" #include "trace/mem.h" #if DATA_SIZE ==16
accel/tcg/cpu-exec.c +3 -0
@@ -269,6 +269,7 @@ void cpu_exec_step_atomic(CPUState *cpu)qemu_mutex_unlock_iothread (); }assert_no_pages_locked (); +qemu_plugin_disable_mem_helpers (cpu); }if (cpu_in_exclusive_context (cpu)) {
@@ -702,6 +703,8 @@ int cpu_exec(CPUState *cpu)if (qemu_mutex_iothread_locked ()) {qemu_mutex_unlock_iothread (); } +qemu_plugin_disable_mem_helpers (cpu); +assert_no_pages_locked (); }
accel/tcg/cputlb.c +8 -6
@@ -881,7 +881,7 @@ static void tlb_fill(CPUState *cpu, target_ulong addr, int size,static uint64_t io_readx (CPUArchState *env,CPUIOTLBEntry *iotlbentry,int mmu_idx,target_ulong addr,uintptr_t retaddr, -MMUAccessType access_type,int size) +TCGMemOp mo,MMUAccessType access_type,int size) {CPUState *cpu =env_cpu (env);hwaddr mr_offset;
@@ -925,7 +925,7 @@ static uint64_t io_readx(CPUArchState *env, CPUIOTLBEntry *iotlbentry,static void io_writex (CPUArchState *env,CPUIOTLBEntry *iotlbentry,int mmu_idx,uint64_t val,target_ulong addr, -uintptr_t retaddr,int size) +uintptr_t retaddr,TCGMemOp mo,int size) {CPUState *cpu =env_cpu (env);hwaddr mr_offset;
@@ -1264,7 +1264,8 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, offsetof(CPUTLBEntry, addr_code) : offsetof(CPUTLBEntry, addr_read);const MMUAccessType access_type = code_read ?MMU_INST_FETCH :MMU_DATA_LOAD ; -unsigned a_bits =get_alignment_bits (get_memop (oi)); +TCGMemOp mo =get_memop (oi); +unsigned a_bits =get_alignment_bits (mo);void *haddr;uint64_t res;
@@ -1313,7 +1314,7 @@ load_helper(CPUArchState *env, target_ulong addr, TCGMemOpIdx oi, } res =io_readx (env, &env_tlb (env)->d[mmu_idx].iotlb[index], - mmu_idx, addr, retaddr, access_type, size); + mmu_idx, addr, retaddr, mo, access_type, size);return handle_bswap (res, size, big_endian); }
@@ -1513,7 +1514,8 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val,CPUTLBEntry *entry =tlb_entry (env, mmu_idx, addr);target_ulong tlb_addr =tlb_addr_write (entry);const size_t tlb_off = offsetof(CPUTLBEntry , addr_write); -unsigned a_bits =get_alignment_bits (get_memop (oi)); +TCGMemOp mo =get_memop (oi); +unsigned a_bits =get_alignment_bits (mo);void *haddr;/* Handle CPU specific unaligned behaviour */
@@ -1562,7 +1564,7 @@ store_helper(CPUArchState *env, target_ulong addr, uint64_t val,io_writex (env, &env_tlb (env)->d[mmu_idx].iotlb[index], mmu_idx,handle_bswap (val, size, big_endian), - addr, retaddr, size); + addr, retaddr, mo, size);return ; }
include/exec/cpu-defs.h +1 -0
@@ -215,6 +215,7 @@ typedef struct CPUTLBCommon {* Since this is placed within CPUNegativeOffsetState, the smallest * negative offsets are at the end of the struct. */ + typedef struct CPUTLB { CPUTLBCommon c; CPUTLBDesc d[NB_MMU_MODES];
include/exec/cpu_ldst_template.h +16 -12
@@ -28,6 +28,7 @@#include "trace-root.h" #endif +#include "qemu/plugin.h" #include "trace/mem.h" #if DATA_SIZE ==8
@@ -86,11 +87,9 @@ glue(glue(glue(cpu_ld, USUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,target_ulong addr;int mmu_idx =CPU_MMU_INDEX ;TCGMemOpIdx oi; -#if !defined(SOFTMMU_CODE_ACCESS ) -trace_guest_mem_before_exec ( -env_cpu (env), ptr, -trace_mem_build_info (SHIFT , false,MO_TE , false, mmu_idx)); +uint16_t meminfo =trace_mem_build_info (SHIFT , false,MO_TE , false, mmu_idx); +trace_guest_mem_before_exec (env_cpu (env), ptr, meminfo);#endif addr = ptr;
@@ -104,6 +103,9 @@ glue(glue(glue(cpu_ld, USUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,uintptr_t hostaddr = addr + entry->addend; res =glue (glue (ld,USUFFIX ), _p)((uint8_t *)hostaddr); } +#ifndef SOFTMMU_CODE_ACCESS +qemu_plugin_vcpu_mem_cb (env_cpu (env), ptr, meminfo); +#endif return res; }
@@ -124,11 +126,9 @@ glue(glue(glue(cpu_lds, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,target_ulong addr;int mmu_idx =CPU_MMU_INDEX ;TCGMemOpIdx oi; -#if !defined(SOFTMMU_CODE_ACCESS ) -trace_guest_mem_before_exec ( -env_cpu (env), ptr, -trace_mem_build_info (SHIFT , true,MO_TE , false, mmu_idx)); +uint16_t meminfo =trace_mem_build_info (SHIFT , true,MO_TE , false, mmu_idx); +trace_guest_mem_before_exec (env_cpu (env), ptr, meminfo);#endif addr = ptr;
@@ -142,6 +142,9 @@ glue(glue(glue(cpu_lds, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,uintptr_t hostaddr = addr + entry->addend; res =glue (glue (lds,SUFFIX ), _p)((uint8_t *)hostaddr); } +#ifndef SOFTMMU_CODE_ACCESS +qemu_plugin_vcpu_mem_cb (env_cpu (env), ptr, meminfo); +#endif return res; }
@@ -165,11 +168,9 @@ glue(glue(glue(cpu_st, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,target_ulong addr;int mmu_idx =CPU_MMU_INDEX ;TCGMemOpIdx oi; -#if !defined(SOFTMMU_CODE_ACCESS ) -trace_guest_mem_before_exec ( -env_cpu (env), ptr, -trace_mem_build_info (SHIFT , false,MO_TE , true, mmu_idx)); +uint16_t meminfo =trace_mem_build_info (SHIFT , false,MO_TE , true, mmu_idx); +trace_guest_mem_before_exec (env_cpu (env), ptr, meminfo);#endif addr = ptr;
@@ -183,6 +184,9 @@ glue(glue(glue(cpu_st, SUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,uintptr_t hostaddr = addr + entry->addend;glue (glue (st,SUFFIX ), _p)((uint8_t *)hostaddr, v); } +#ifndef SOFTMMU_CODE_ACCESS +qemu_plugin_vcpu_mem_cb (env_cpu (env), ptr, meminfo); +#endif } static inline void
include/exec/cpu_ldst_useronly_template.h +14 -15
@@ -64,18 +64,17 @@static inline RES_TYPE glue (glue (cpu_ld ,USUFFIX ),MEMSUFFIX )(CPUArchState *env,abi_ptr ptr) { -#ifdef CODE_ACCESS RES_TYPE ret; +#ifdef CODE_ACCESS set_helper_retaddr (1 ); ret =glue (glue (ld,USUFFIX ), _p)(g2h (ptr));clear_helper_retaddr (); -return ret;#else -trace_guest_mem_before_exec ( -env_cpu (env), ptr, -trace_mem_build_info (SHIFT , false,MO_TE , false,0 )); -return glue (glue (ld,USUFFIX ), _p)(g2h (ptr)); +uint16_t meminfo =trace_mem_build_info (SHIFT , false,MO_TE , false,0 ); +trace_guest_mem_before_exec (env_cpu (env), ptr, meminfo); + ret =glue (glue (ld,USUFFIX ), _p)(g2h (ptr));#endif +return ret; }#ifndef CODE_ACCESS
@@ -96,18 +95,18 @@ glue(glue(glue(cpu_ld, USUFFIX), MEMSUFFIX), _ra)(CPUArchState *env,static inline int glue (glue (cpu_lds ,SUFFIX ),MEMSUFFIX )(CPUArchState *env,abi_ptr ptr) { -#ifdef CODE_ACCESS int ret; +#ifdef CODE_ACCESS set_helper_retaddr (1 ); ret =glue (glue (lds,SUFFIX ), _p)(g2h (ptr));clear_helper_retaddr (); -return ret;#else -trace_guest_mem_before_exec ( -env_cpu (env), ptr, -trace_mem_build_info (SHIFT , true,MO_TE , false,0 )); -return glue (glue (lds,SUFFIX ), _p)(g2h (ptr)); +uint16_t meminfo =trace_mem_build_info (SHIFT , true,MO_TE , false,0 ); +trace_guest_mem_before_exec (env_cpu (env), ptr, meminfo); + ret =glue (glue (lds,SUFFIX ), _p)(g2h (ptr)); +qemu_plugin_vcpu_mem_cb (env_cpu (env), ptr, meminfo);#endif +return ret; }#ifndef CODE_ACCESS
@@ -130,10 +129,10 @@ static inline void glue(glue(cpu_st, SUFFIX), MEMSUFFIX)(CPUArchState *env, abi_ptr ptr, RES_TYPE v) { -trace_guest_mem_before_exec ( -env_cpu (env), ptr, -trace_mem_build_info (SHIFT , false,MO_TE , true,0 )); +uint16_t meminfo =trace_mem_build_info (SHIFT , false,MO_TE , true,0 ); +trace_guest_mem_before_exec (env_cpu (env), ptr, meminfo);glue (glue (st,SUFFIX ), _p)(g2h (ptr), v); +qemu_plugin_vcpu_mem_cb (env_cpu (env), ptr, meminfo); } static inline void
tcg/tcg-op.c +31 -9
@@ -30,6 +30,7 @@#include "tcg-mo.h" #include "trace-tcg.h" #include "trace/mem.h" +#include "exec/plugin-gen.h" /* Reduce the number of ifdefs below. This assumes that all uses of TCGV_HIGH and TCGV_LOW are properly protected by a conditional that
@@ -2684,6 +2685,7 @@ void tcg_gen_exit_tb(TranslationBlock *tb, unsigned idx)tcg_debug_assert (idx ==TB_EXIT_REQUESTED ); } +plugin_gen_disable_mem_helpers ();tcg_gen_op1i (INDEX_op_exit_tb, val); }
@@ -2696,6 +2698,7 @@ void tcg_gen_goto_tb(unsigned idx)tcg_debug_assert ((tcg_ctx->goto_tb_issue_mask & (1 << idx)) ==0 ); tcg_ctx->goto_tb_issue_mask |=1 << idx;#endif +plugin_gen_disable_mem_helpers ();/* When not chaining, we simply fall through to the "fallback" exit. */ if (!qemu_loglevel_mask (CPU_LOG_TB_NOCHAIN )) {tcg_gen_op1i (INDEX_op_goto_tb, idx);
@@ -2705,7 +2708,10 @@ void tcg_gen_goto_tb(unsigned idx)void tcg_gen_lookup_and_goto_ptr (void ) {if (TCG_TARGET_HAS_goto_ptr && !qemu_loglevel_mask (CPU_LOG_TB_NOCHAIN )) { -TCGv_ptr ptr =tcg_temp_new_ptr (); +TCGv_ptr ptr; + +plugin_gen_disable_mem_helpers (); + ptr =tcg_temp_new_ptr ();gen_helper_lookup_tb_ptr (ptr, cpu_env);tcg_gen_op1i (INDEX_op_goto_ptr,tcgv_ptr_arg (ptr));tcg_temp_free_ptr (ptr);
@@ -2788,14 +2794,24 @@ static void tcg_gen_req_mo(TCGBar type) } } +static inline void plugin_gen_mem_callbacks (TCGv vaddr,uint16_t info) +{ +#ifdef CONFIG_PLUGIN +if (tcg_ctx->plugin_insn ==NULL ) { +return ; + } +plugin_gen_empty_mem_callback (vaddr, info); +#endif +} +void tcg_gen_qemu_ld_i32 (TCGv_i32 val,TCGv addr,TCGArg idx,TCGMemOp memop) {TCGMemOp orig_memop; +uint16_t info =trace_mem_get_info (memop, idx,0 );tcg_gen_req_mo (TCG_MO_LD_LD |TCG_MO_ST_LD ); memop =tcg_canonicalize_memop (memop,0 ,0 ); -trace_guest_mem_before_tcg (tcg_ctx->cpu, cpu_env, - addr,trace_mem_get_info (memop, idx,0 )); +trace_guest_mem_before_tcg (tcg_ctx->cpu, cpu_env, addr, info); orig_memop = memop;if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop &MO_BSWAP )) {
@@ -2807,6 +2823,7 @@ void tcg_gen_qemu_ld_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop) }gen_ldst_i32 (INDEX_op_qemu_ld_i32, val, addr, memop, idx); +plugin_gen_mem_callbacks (addr, info);if ((orig_memop ^ memop) &MO_BSWAP ) {switch (orig_memop &MO_SIZE ) {
@@ -2828,11 +2845,11 @@ void tcg_gen_qemu_ld_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop)void tcg_gen_qemu_st_i32 (TCGv_i32 val,TCGv addr,TCGArg idx,TCGMemOp memop) {TCGv_i32 swap =NULL ; +uint16_t info =trace_mem_get_info (memop, idx,1 );tcg_gen_req_mo (TCG_MO_LD_ST |TCG_MO_ST_ST ); memop =tcg_canonicalize_memop (memop,0 ,1 ); -trace_guest_mem_before_tcg (tcg_ctx->cpu, cpu_env, - addr,trace_mem_get_info (memop, idx,1 )); +trace_guest_mem_before_tcg (tcg_ctx->cpu, cpu_env, addr, info);if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop &MO_BSWAP )) { swap =tcg_temp_new_i32 ();
@@ -2852,6 +2869,7 @@ void tcg_gen_qemu_st_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop) }gen_ldst_i32 (INDEX_op_qemu_st_i32, val, addr, memop, idx); +plugin_gen_mem_callbacks (addr, info);if (swap) {tcg_temp_free_i32 (swap);
@@ -2861,6 +2879,7 @@ void tcg_gen_qemu_st_i32(TCGv_i32 val, TCGv addr, TCGArg idx, TCGMemOp memop)void tcg_gen_qemu_ld_i64 (TCGv_i64 val,TCGv addr,TCGArg idx,TCGMemOp memop) {TCGMemOp orig_memop; +uint16_t info;if (TCG_TARGET_REG_BITS ==32 && (memop &MO_SIZE ) <MO_64 ) {tcg_gen_qemu_ld_i32 (TCGV_LOW (val), addr, idx, memop);
@@ -2874,8 +2893,8 @@ void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop)tcg_gen_req_mo (TCG_MO_LD_LD |TCG_MO_ST_LD ); memop =tcg_canonicalize_memop (memop,1 ,0 ); -trace_guest_mem_before_tcg (tcg_ctx->cpu, cpu_env, - addr,trace_mem_get_info (memop, idx,0 )); + info =trace_mem_get_info (memop, idx,0 ); +trace_guest_mem_before_tcg (tcg_ctx->cpu, cpu_env, addr, info); orig_memop = memop;if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop &MO_BSWAP )) {
@@ -2887,6 +2906,7 @@ void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) }gen_ldst_i64 (INDEX_op_qemu_ld_i64, val, addr, memop, idx); +plugin_gen_mem_callbacks (addr, info);if ((orig_memop ^ memop) &MO_BSWAP ) {switch (orig_memop &MO_SIZE ) {
@@ -2914,6 +2934,7 @@ void tcg_gen_qemu_ld_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop)void tcg_gen_qemu_st_i64 (TCGv_i64 val,TCGv addr,TCGArg idx,TCGMemOp memop) {TCGv_i64 swap =NULL ; +uint16_t info;if (TCG_TARGET_REG_BITS ==32 && (memop &MO_SIZE ) <MO_64 ) {tcg_gen_qemu_st_i32 (TCGV_LOW (val), addr, idx, memop);
@@ -2922,8 +2943,8 @@ void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop)tcg_gen_req_mo (TCG_MO_LD_ST |TCG_MO_ST_ST ); memop =tcg_canonicalize_memop (memop,1 ,1 ); -trace_guest_mem_before_tcg (tcg_ctx->cpu, cpu_env, - addr,trace_mem_get_info (memop, idx,1 )); + info =trace_mem_get_info (memop, idx,1 ); +trace_guest_mem_before_tcg (tcg_ctx->cpu, cpu_env, addr, info);if (!TCG_TARGET_HAS_MEMORY_BSWAP && (memop &MO_BSWAP )) { swap =tcg_temp_new_i64 ();
@@ -2947,6 +2968,7 @@ void tcg_gen_qemu_st_i64(TCGv_i64 val, TCGv addr, TCGArg idx, TCGMemOp memop) }gen_ldst_i64 (INDEX_op_qemu_st_i64, val, addr, memop, idx); +plugin_gen_mem_callbacks (addr, info);if (swap) {tcg_temp_free_i64 (swap);
tcg/tcg.h +1 -0
@@ -28,6 +28,7 @@#include "cpu.h" #include "exec/tb-context.h" #include "qemu/bitops.h" +#include "qemu/plugin.h" #include "qemu/queue.h" #include "tcg-mo.h" #include "tcg-target.h"
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 23/54] tcg: let plugins instrument virtual memory accesses
Quoted 18 lines · Alex Bennée
From: "Emilio G. Cota" <[email protected]>
To capture all memory accesses we need hook into all the various helper functions that are involved in memory operations as well as the injected inline helper calls. A later commit will allow us to resolve the actual guest HW addresses by replaying the lookup.
Signed-off-by Emilio G. Cota <[email protected]>[AJB: drop haddr handling, just deal in vaddr]Signed-off-by Alex Bennée <[email protected]>---
v3
- fixes forcpu_neg()
v4
- rebase fixups, movedcpu_neg()fixes down the stack
- drop haddr support - will be restored with later helper
- reword commit
Quoted 11 lines
--- accel/tcg/atomic_common.inc.c | 4 +++ accel/tcg/atomic_template.h | 1 + accel/tcg/cpu-exec.c | 3 ++ accel/tcg/cputlb.c | 14 ++++---- include/exec/cpu-defs.h | 1 + include/exec/cpu_ldst_template.h | 28 +++++++++------- include/exec/cpu_ldst_useronly_template.h | 29 ++++++++-------- tcg/tcg-op.c | 40 ++++++++++++++++++----- tcg/tcg.h | 1 + 9 files changed, 79 insertions(+), 42 deletions(-)
r~
PATCH v4 24/54 plugins: implement helpers for resolving hwaddr
In reply to Alex BennéeWe need to keep a local per-cpu copy of the data as other threads may be running. We use a automatically growing array and re-use the space for subsequent queries.
--- accel/tcg/cputlb.c | 32 ++++++++++++++++++++++++++ include/exec/exec-all.h | 17 ++++++++++++++ include/qemu/plugin.h | 6 +++++ plugins/api.c | 50 +++++++++++++++++++++++++++++++++-------- 4 files changed, 96 insertions(+), 9 deletions(-)
accel/tcg/cputlb.c +32 -0
@@ -1130,6 +1130,38 @@ void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr,return (void *)((uintptr_t )addr + entry->addend); } + +#ifdef CONFIG_PLUGIN +/* +* Perform a TLB lookup and populate the qemu_plugin_hwaddr structure. +* This should be a hot path as we will have just looked this path up +* in the softmmu lookup code (or helper). We don't handle re-fills or +* checking the victim table. This is purely informational. +*/ + +bool tlb_plugin_lookup (CPUState *cpu,target_ulong addr,int mmu_idx, +bool is_store,struct qemu_plugin_hwaddr *data) +{ +CPUArchState *env = cpu->env_ptr; +CPUTLBEntry *tlbe =tlb_entry (env, mmu_idx, addr); +target_ulong tlb_addr = is_store ?tlb_addr_write (tlbe) : tlbe->addr_read; + +if (tlb_hit (tlb_addr, addr)) { +if (tlb_addr &TLB_MMIO ) { + data->hostaddr =0 ; + data->is_io = true; +/* XXX: lookup device */ + }else { + data->hostaddr = addr + tlbe->addend; + data->is_io = false; + } +return true; + } +return false; +} + +#endif +/* Probe for a read-modify-write atomic operation. Do not allow unaligned * operations, or io operations to proceed. Return the host address. */ static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,
include/exec/exec-all.h +17 -0
@@ -262,6 +262,17 @@ void tlb_set_page(CPUState *cpu, target_ulong vaddr, int mmu_idx, target_ulong size);void probe_write (CPUArchState *env,target_ulong addr,int size,int mmu_idx,uintptr_t retaddr); + +/** +* tlb_plugin_lookup: query last TLB lookup +* @cpu: cpu environment +* +* This function can be used directly after a memory operation to +* query information about the access. It is used by the plugin +* infrastructure to expose more information about the address. +*/ +bool tlb_plugin_lookup (CPUState *cpu,target_ulong addr,int mmu_idx, +bool is_store,struct qemu_plugin_hwaddr *data);#else static inline void tlb_init (CPUState *cpu) {
@@ -311,6 +322,12 @@ static inline void tlb_flush_by_mmuidx_all_cpus_synced(CPUState *cpu, uint16_t idxmap) { } +static inline bool tlb_plugin_lookup (CPUState *cpu,target_ulong addr, +int mmu_idx,bool is_store, +struct qemu_plugin_hwaddr *data) +{ +return false; +}#endif #define CODE_GEN_ALIGN 16/* must be >= of the size of a icache line */
include/qemu/plugin.h +6 -0
@@ -182,6 +182,12 @@ struct qemu_plugin_insn *qemu_plugin_tb_insn_get(struct qemu_plugin_tb *tb)return insn; } +struct qemu_plugin_hwaddr { +uint64_t hostaddr; +bool is_io; +}; + +#ifdef CONFIG_PLUGIN void qemu_plugin_vcpu_init_hook (CPUState *cpu);
plugins/api.c +41 -9
73 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 24/54] plugins: implement helpers for resolving hwaddr
Quoted 3 lines · Alex Bennée
We need to keep a local per-cpu copy of the data as other threads may be running. We use a automatically growing array and re-use the space for subsequent queries.
[...]
Quoted 10 lines
accel/tcg/cputlb.c +10
-0+bool tlb_plugin_lookup (CPUState *cpu,target_ulong addr,int mmu_idx, +bool is_store,struct qemu_plugin_hwaddr *data) +{ +CPUArchState *env = cpu->env_ptr; +CPUTLBEntry *tlbe =tlb_entry (env, mmu_idx, addr); +target_ulong tlb_addr = is_store ?tlb_addr_write (tlbe) : tlbe->addr_read; + +if (tlb_hit (tlb_addr, addr)) { +if (tlb_addr &TLB_MMIO ) { + data->hostaddr =0 ;
accel/tcg/cputlb.c void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr, · line 1161
Quoted 10 lines
accel/tcg/cputlb.c +10
-0+ data->is_io = true; +/* XXX: lookup device */ + }else { + data->hostaddr = addr + tlbe->addend; + data->is_io = false; + } +return true; + } +return false; +}
In what cases do you expect tlb_hit() should not evaluate to true here? Will returns of false only be in error cases, or do you expect it can occur during normal operation? In particular, I'm interested in ensuring this is as reliable as possible, since some plugins may require physical addresses.
Quoted 5 lines
plugins/api.c +5
-0+struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr (qemu_plugin_meminfo_t info, +uint64_t vaddr) +{ +CPUState *cpu = current_cpu; +unsigned int mmu_idx = info >>TRACE_MEM_MMU_SHIFT ;
plugins/api.c bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info) · line 260
Quoted 10 lines
plugins/api.c +10
-0+struct qemu_plugin_hwaddr *hwaddr; + +/* Ensure we have memory allocated for this work */ +if (!hwaddr_refs) { + hwaddr_refs =g_array_sized_new (false, true, +sizeof (struct qemu_plugin_hwaddr ), + cpu->cpu_index +1 ); + }else if (cpu->cpu_index >= hwaddr_refs->len) { + hwaddr_refs =g_array_set_size (hwaddr_refs, cpu->cpu_index +1 ); + }
Are there one or more race conditions with the allocations here? If so, could they be solved by doing the allocations at plugin initialization and when the number of online cpu's changes, instead of lazily?
Quoted 1 line
uint64_tqemu_plugin_hwaddr_to_raddr(const struct qemu_plugin_hwaddr *haddr)
I was at first confused about the utility of this function until I (re-?)discovered you had to convert first to hwaddr and then raddr to get a "true" physical address. Perhaps that could be added to a comment here or in the API definition in the main plugin header file.
-Aaron
Re: [Qemu-devel] [PATCH v4 24/54] plugins: implement helpers for resolving hwaddr
Quoted 25 lines · Aaron Lindsay OS via Qemu-devel
Quoted 3 lines · Alex Bennée
We need to keep a local per-cpu copy of the data as other threads may be running. We use a automatically growing array and re-use the space for subsequent queries.
[...]
Quoted 18 lines
accel/tcg/cputlb.c +18
-0+bool tlb_plugin_lookup (CPUState *cpu,target_ulong addr,int mmu_idx, +bool is_store,struct qemu_plugin_hwaddr *data) +{ +CPUArchState *env = cpu->env_ptr; +CPUTLBEntry *tlbe =tlb_entry (env, mmu_idx, addr); +target_ulong tlb_addr = is_store ?tlb_addr_write (tlbe) : tlbe->addr_read; + +if (tlb_hit (tlb_addr, addr)) { +if (tlb_addr &TLB_MMIO ) { + data->hostaddr =0 ; + data->is_io = true; +/* XXX: lookup device */ + }else { + data->hostaddr = addr + tlbe->addend; + data->is_io = false; + } +return true; + }
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ return false; +}In what cases do you expect
tlb_hit()should not evaluate to true here? Will returns of false only be in error cases, or do you expect it can occur during normal operation? In particular, I'm interested in ensuring this is as reliable as possible, since some plugins may require physical addresses.
I have the same question. Given the access has just succeeded, it would seem to be that the tlb entry *must* hit. No victim tlb check or anything.
r~
Re: [PATCH v4 24/54] plugins: implement helpers for resolving hwaddr
In reply to Aaron Lindsay OS via Qemu-develQuoted 25 lines · Aaron Lindsay OS
Quoted 3 lines · Alex Bennée
We need to keep a local per-cpu copy of the data as other threads may be running. We use a automatically growing array and re-use the space for subsequent queries.
[...]
Quoted 18 lines
accel/tcg/cputlb.c +18
-0+bool tlb_plugin_lookup (CPUState *cpu,target_ulong addr,int mmu_idx, +bool is_store,struct qemu_plugin_hwaddr *data) +{ +CPUArchState *env = cpu->env_ptr; +CPUTLBEntry *tlbe =tlb_entry (env, mmu_idx, addr); +target_ulong tlb_addr = is_store ?tlb_addr_write (tlbe) : tlbe->addr_read; + +if (tlb_hit (tlb_addr, addr)) { +if (tlb_addr &TLB_MMIO ) { + data->hostaddr =0 ; + data->is_io = true; +/* XXX: lookup device */ + }else { + data->hostaddr = addr + tlbe->addend; + data->is_io = false; + } +return true; + }
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ return false; +}In what cases do you expect
tlb_hit()should not evaluate to true here? Will returns of false only be in error cases, or do you expect it can occur during normal operation? In particular, I'm interested in ensuring this is as reliable as possible, since some plugins may require physical addresses.
Only if the API is misused and a call made outside of the hooked memory operation. An assert would be too strong as the plugin could then bring down QEMU - I guess we could use some sort of error_report...
Quoted 12 lines
Quoted 12 lines
plugins/api.c +11
-0+struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr (qemu_plugin_meminfo_t info, +uint64_t vaddr) +{ +CPUState *cpu = current_cpu; +unsigned int mmu_idx = info >>TRACE_MEM_MMU_SHIFT ; +struct qemu_plugin_hwaddr *hwaddr; + +/* Ensure we have memory allocated for this work */ +if (!hwaddr_refs) { + hwaddr_refs = g_array_sized_new(false, true, + sizeof(struct qemu_plugin_hwaddr),
Quoted 8 lines
plugins/api.c bool qemu_plugin_mem_is_store(qemu_plugin_meminfo_t info) · line 260
Quoted 4 lines
plugins/api.c +4
-0+ cpu->cpu_index + 1); + }else if (cpu->cpu_index >= hwaddr_refs->len) { + hwaddr_refs =g_array_set_size (hwaddr_refs, cpu->cpu_index +1 ); + }Are there one or more race conditions with the allocations here? If so, could they be solved by doing the allocations at plugin initialization and when the number of online cpu's changes, instead of lazily?
It might be easier to just keep a __thread local array here and let TLS deal with it.
--
Alex Bennée
PATCH v4 25/54 translate-all: notify plugin code of tb_flush
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
Plugins might allocate per-TB data that then they get passed each time a TB is executed (via the *userdata pointer).
Notify plugin code every time a code cache flush occurs, so that plugins can then reclaim the memory of the per-TB data.
--- accel/tcg/translate-all.c | 6 ++++++ 1 file changed, 6 insertions(+)
accel/tcg/translate-all.c +6 -0
@@ -1231,6 +1231,8 @@ static gboolean tb_host_size_iter(gpointer key, gpointer value, gpointer data)/* flush all the translation blocks */ static void do_tb_flush (CPUState *cpu,run_on_cpu_data tb_flush_count) { +bool did_flush = false; +mmap_lock ();/* If it is already been done on request of another CPU, * just retry.
@@ -1238,6 +1240,7 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count)if (tb_ctx.tb_flush_count != tb_flush_count.host_int) { goto done; } + did_flush = true;if (DEBUG_TB_FLUSH_GATE ) {size_t nb_tbs =tcg_nb_tbs ();
@@ -1262,6 +1265,9 @@ static void do_tb_flush(CPUState *cpu, run_on_cpu_data tb_flush_count) done:mmap_unlock (); +if (did_flush) { +qemu_plugin_flush_cb (); + } }void tb_flush (CPUState *cpu)
Signature · 1 line
2.20.1
PATCH v4 26/54 *-user: notify plugin of exit
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
--- bsd-user/syscall.c | 3 +++ linux-user/exit.c | 1 + 2 files changed, 4 insertions(+)
bsd-user/syscall.c +3 -0
@@ -332,6 +332,7 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,_mcleanup ();#endif gdb_exit (cpu_env, arg1); +qemu_plugin_atexit_cb ();/* XXX: should free thread stack and CPU env */ _exit (arg1); ret =0 ;/* avoid warning */
@@ -430,6 +431,7 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,_mcleanup ();#endif gdb_exit (cpu_env, arg1); +qemu_plugin_atexit_cb ();/* XXX: should free thread stack and CPU env */ _exit (arg1); ret =0 ;/* avoid warning */
@@ -505,6 +507,7 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,_mcleanup ();#endif gdb_exit (cpu_env, arg1); +qemu_plugin_atexit_cb ();/* XXX: should free thread stack and CPU env */ _exit (arg1); ret =0 ;/* avoid warning */
linux-user/exit.c +1 -0
@@ -35,4 +35,5 @@ void preexit_cleanup(CPUArchState *env, int code)__gcov_dump ();#endif gdb_exit (env, code); +qemu_plugin_atexit_cb (); }
Signature · 1 line
2.20.1
PATCH v4 27/54 *-user: plugin syscalls
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
To avoid too much duplication add a wrapper that the existing trace and the new plugin calls can live in. We could move the -strace code here as well but that is left for a future series as the code is subtly different between the bsd and linux.
--- bsd-user/syscall.c | 21 +++++++++++++------ include/user/syscall-trace.h | 40 ++++++++++++++++++++++++++++++++++++ linux-user/syscall.c | 7 ++++--- 3 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 include/user/syscall-trace.h
bsd-user/syscall.c +15 -6
@@ -26,6 +26,7 @@#include "qemu.h" #include "qemu-common.h" +#include "user/syscall-trace.h" //#define DEBUG
@@ -322,7 +323,8 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,#ifdef DEBUG gemu_log ("freebsd syscall %d\n" , num);#endif -trace_guest_user_syscall (cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); +record_syscall_start (cpu, num, arg1, arg2, arg3, arg4, arg5, arg6,0 ,0 ); +if (do_strace)print_freebsd_syscall (num, arg1, arg2, arg3, arg4, arg5, arg6);
@@ -403,7 +405,8 @@ abi_long do_freebsd_syscall(void *cpu_env, int num, abi_long arg1,#endif if (do_strace)print_freebsd_syscall_ret (num, ret); -trace_guest_user_syscall_ret (cpu, num, ret); + +record_syscall_return (cpu, num, ret);return ret; efault: ret = -TARGET_EFAULT ;
@@ -421,7 +424,9 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,#ifdef DEBUG gemu_log ("netbsd syscall %d\n" , num);#endif -trace_guest_user_syscall (cpu, num, arg1, arg2, arg3, arg4, arg5, arg6,0 ,0 ); + +record_syscall_start (cpu, num, arg1, arg2, arg3, arg4, arg5, arg6,0 ,0 ); +if (do_strace)print_netbsd_syscall (num, arg1, arg2, arg3, arg4, arg5, arg6);
@@ -479,7 +484,8 @@ abi_long do_netbsd_syscall(void *cpu_env, int num, abi_long arg1,#endif if (do_strace)print_netbsd_syscall_ret (num, ret); -trace_guest_user_syscall_ret (cpu, num, ret); + +record_syscall_return (cpu, num, ret);return ret; efault: ret = -TARGET_EFAULT ;
@@ -497,7 +503,9 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,#ifdef DEBUG gemu_log ("openbsd syscall %d\n" , num);#endif -trace_guest_user_syscall (cpu, num, arg1, arg2, arg3, arg4, arg5, arg6,0 ,0 ); + +record_syscall_start (cpu, num, arg1, arg2, arg3, arg4, arg5, arg6,0 ,0 ); +if (do_strace)print_openbsd_syscall (num, arg1, arg2, arg3, arg4, arg5, arg6);
@@ -555,7 +563,8 @@ abi_long do_openbsd_syscall(void *cpu_env, int num, abi_long arg1,#endif if (do_strace)print_openbsd_syscall_ret (num, ret); -trace_guest_user_syscall_ret (cpu, num, ret); + +record_syscall_return (cpu, num, ret);return ret; efault: ret = -TARGET_EFAULT ;
include/user/syscall-trace.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Common System Call Tracing Wrappers for *-user +* +* Copyright (c) 2019 Linaro +* Written by Alex Bennée <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef _SYSCALL_TRACE_H_ +#define _SYSCALL_TRACE_H_ + +/* +* These helpers just provide a common place for the various +* subsystems that want to track syscalls to put their hooks in. We +* could potentially unify the -strace code here as well. +*/ + +static inline void record_syscall_start (void *cpu,int num, +abi_long arg1,abi_long arg2, +abi_long arg3,abi_long arg4, +abi_long arg5,abi_long arg6, +abi_long arg7,abi_long arg8) +{ +trace_guest_user_syscall (cpu, num, + arg1, arg2, arg3, arg4, + arg5, arg6, arg7, arg8); +qemu_plugin_vcpu_syscall (cpu, num, + arg1, arg2, arg3, arg4, + arg5, arg6, arg7, arg8); +} + +static inline void record_syscall_return (void *cpu,int num,abi_long ret) +{ +trace_guest_user_syscall_ret (cpu, num, ret); +qemu_plugin_vcpu_syscall_ret (cpu, num, ret); +} + + +#endif /* _SYSCALL_TRACE_H_ */
linux-user/syscall.c +4 -3
@@ -109,6 +109,7 @@#include "qemu.h" #include "qemu/guest-random.h" +#include "user/syscall-trace.h" #include "qapi/error.h" #include "fd-trans.h"
@@ -11968,8 +11969,8 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, }#endif -trace_guest_user_syscall (cpu, num, arg1, arg2, arg3, arg4, - arg5, arg6, arg7, arg8); +record_syscall_start (cpu, num, arg1, + arg2, arg3, arg4, arg5, arg6, arg7, arg8);if (unlikely (do_strace)) {print_syscall (num, arg1, arg2, arg3, arg4, arg5, arg6);
@@ -11981,6 +11982,6 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1, arg5, arg6, arg7, arg8); } -trace_guest_user_syscall_ret (cpu, num, ret); +record_syscall_return (cpu, num, ret);return ret; }
Signature · 1 line
2.20.1
PATCH v4 28/54 cpu: hook plugin vcpu events
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
--- cpus.c | 10 ++++++++++ exec.c | 2 ++ qom/cpu.c | 2 ++ 3 files changed, 14 insertions(+)
cpus.c +10 -0
@@ -44,6 +44,7 @@#include "exec/exec-all.h" #include "qemu/thread.h" +#include "qemu/plugin.h" #include "sysemu/cpus.h" #include "sysemu/qtest.h" #include "qemu/main-loop.h"
@@ -1241,9 +1242,18 @@ static void qemu_tcg_rr_wait_io_event(void)static void qemu_wait_io_event (CPUState *cpu) { +bool slept = false; +while (cpu_thread_is_idle (cpu)) { +if (!slept) { + slept = true; +qemu_plugin_vcpu_idle_cb (cpu); + }qemu_cond_wait (cpu->halt_cond, &qemu_global_mutex); } +if (slept) { +qemu_plugin_vcpu_resume_cb (cpu); + }#ifdef _WIN32/* Eat dummy APC queued by qemu_cpu_kick_thread. */
exec.c +2 -0
@@ -974,6 +974,8 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp) }tlb_init (cpu); +qemu_plugin_vcpu_init_hook (cpu); +#ifndef CONFIG_USER_ONLY if (qdev_get_vmsd (DEVICE (cpu)) ==NULL ) {vmstate_register (NULL , cpu->cpu_index, &vmstate_cpu_common, cpu);
qom/cpu.c +2 -0
@@ -33,6 +33,7 @@#include "hw/boards.h" #include "hw/qdev-properties.h" #include "trace-root.h" +#include "qemu/plugin.h" CPUInterruptHandler cpu_interrupt_handler;
@@ -354,6 +355,7 @@ static void cpu_common_unrealizefn(DeviceState *dev, Error **errp)CPUState *cpu =CPU (dev);/* NOTE: latest generic point before the cpu is fully unrealized */ trace_fini_vcpu (cpu); +qemu_plugin_vcpu_exit_hook (cpu);cpu_exec_unrealizefn (cpu); }
Signature · 1 line
2.20.1
PATCH v4 29/54 plugin-gen: add plugin_insn_append
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
By adding it to plugin-gen's header file, we can export is as an inline, since tcg.h is included in the header (we need tcg_ctx).
---
v3
- use g_byte_array
--- include/exec/plugin-gen.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/exec/plugin-gen.h +14 -0
@@ -27,6 +27,17 @@ void plugin_gen_insn_end(void);void plugin_gen_disable_mem_helpers (void );void plugin_gen_empty_mem_callback (TCGv addr,uint32_t info); +static inline void plugin_insn_append (const void *from,size_t size) +{ +struct qemu_plugin_insn *insn = tcg_ctx->plugin_insn; + +if (insn ==NULL ) { +return ; + } + + insn->data =g_byte_array_append (insn->data, from, size); +} +#else /* !CONFIG_PLUGIN */ static inline
@@ -51,6 +62,9 @@ static inline void plugin_gen_disable_mem_helpers(void)static inline void plugin_gen_empty_mem_callback (TCGv addr,uint32_t info) { } +static inline void plugin_insn_append (const void *from,size_t size) +{ } +#endif /* CONFIG_PLUGIN */ #endif /* QEMU_PLUGIN_GEN_H */
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 29/54] plugin-gen: add plugin_insn_append
Quoted 9 lines · Alex Bennée
From: "Emilio G. Cota" <[email protected]>
By adding it to plugin-gen's header file, we can export is as an inline, since
tcg.his included in the header (we needtcg_ctx).Signed-off-by Emilio G. Cota <[email protected]>[AJB: use g_byte_array]Signed-off-by Alex Bennée <[email protected]>
Quoted 6 lines
---
v3
- useg_byte_array--- include/exec/plugin-gen.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
r~
PATCH v4 30/54 translator: add translator_ld{ub, sw, uw, l, q}
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
---
v4
- don't use the cpu_ldst helpers, plumb directly into the lower level
- mark the CODE_ACCESS/SOFTMMU_CODE_ACCESS as deprecated
--- include/exec/cpu_ldst.h | 11 ++++++++ include/exec/translator.h | 58 ++++++++++++++++++++++++++++++++++++++- include/qemu/bswap.h | 5 ++++ tcg/tcg.h | 2 ++ 4 files changed, 75 insertions(+), 1 deletion(-)
include/exec/cpu_ldst.h +11 -0
@@ -129,6 +129,11 @@ static inline void clear_helper_retaddr(void)#include "exec/cpu_ldst_useronly_template.h" #undef MEMSUFFIX +/* +* Code access is deprecated in favour of translator_ld* functions +* (see translator.h). However there are still users that need to +* converted so for now these stay. +*/ #define MEMSUFFIX _code#define CODE_ACCESS #define DATA_SIZE 1
@@ -427,6 +432,12 @@ static inline CPUTLBEntry *tlb_entry(CPUArchState *env, uintptr_t mmu_idx,#undef CPU_MMU_INDEX#undef MEMSUFFIX +/* +* Code access is deprecated in favour of translator_ld* functions +* (see translator.h). However there are still users that need to +* converted so for now these stay. +*/ +#define CPU_MMU_INDEX (cpu_mmu_index(env, true))#define MEMSUFFIX _code#define SOFTMMU_CODE_ACCESS
include/exec/translator.h +57 -1
68 lines not on this page · raw message
include/qemu/bswap.h +5 -0
@@ -306,6 +306,11 @@ static inline int ldub_p(const void *ptr)return *(uint8_t *)ptr; } +static inline int ldb_p (const void *ptr) +{ +return ldub_p (ptr); +} +static inline int ldsb_p (const void *ptr) {return *(int8_t *)ptr;
tcg/tcg.h +2 -0
@@ -1404,6 +1404,7 @@ uint64_t helper_be_ldq_cmmu(CPUArchState *env, target_ulong addr,# define helper_ret_stl_mmu helper_be_stl_mmu# define helper_ret_stq_mmu helper_be_stq_mmu# define helper_ret_ldw_cmmu helper_be_ldw_cmmu +# define helper_ret_lduw_cmmu helper_be_ldw_cmmu# define helper_ret_ldl_cmmu helper_be_ldl_cmmu# define helper_ret_ldq_cmmu helper_be_ldq_cmmu#else
@@ -1417,6 +1418,7 @@ uint64_t helper_be_ldq_cmmu(CPUArchState *env, target_ulong addr,# define helper_ret_stl_mmu helper_le_stl_mmu# define helper_ret_stq_mmu helper_le_stq_mmu# define helper_ret_ldw_cmmu helper_le_ldw_cmmu +# define helper_ret_lduw_cmmu helper_le_ldw_cmmu# define helper_ret_ldl_cmmu helper_le_ldl_cmmu# define helper_ret_ldq_cmmu helper_le_ldq_cmmu#endif
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 30/54] translator: add translator_ld{ub, sw, uw, l, q}
include/exec/translator.h void translator_loop(const TranslatorOps *ops, DisasContextBase *db, · line 171
Quoted 13 lines · Alex Bennée
include/exec/translator.h +13
-0+#ifdef CONFIG_USER_ONLY + +#define DO_LOAD (type, name, shift) \ + set_helper_retaddr(1); \ + ret = name ## _p(g2h(pc)); \ + clear_helper_retaddr(); + +#else + +#define DO_LOAD (type, name, shift) \ + int mmu_idx = cpu_mmu_index(env, true); \ + TCGMemOpIdx oi = make_memop_idx(shift, mmu_idx); \ + ret = helper_ret_ ## name ## _cmmu(env, pc, oi, 0);
Why are you only using the out-of-line slowpath functions? Seems like the rest of the fastpath should be included too.
r~
PATCH v4 31/54 target/arm: fetch code with translator_ld
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
Now the arm_ld*_code functions are only used at translate time we can just pass down to translator_ld functions.
---
v4
- use translator_ld like the rest of them
--- target/arm/arm_ldst.h | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)
target/arm/arm_ldst.h +3 -12
@@ -20,25 +20,20 @@#ifndef ARM_LDST_H #define ARM_LDST_H -#include "exec/cpu_ldst.h" +#include "exec/translator.h" #include "qemu/bswap.h" /* Load an instruction and return it in the standard little-endian order */ static inline uint32_t arm_ldl_code (CPUARMState *env,target_ulong addr,bool sctlr_b) { -uint32_t insn =cpu_ldl_code (env, addr); -if (bswap_code (sctlr_b)) { -return bswap32 (insn); - } -return insn; +return translator_ldl_swap (env, addr,bswap_code (sctlr_b)); }/* Ditto, for a halfword (Thumb) instruction */ static inline uint16_t arm_lduw_code (CPUARMState *env,target_ulong addr,bool sctlr_b) { -uint16_t insn;#ifndef CONFIG_USER_ONLY /* In big-endian (BE32) mode, adjacent Thumb instructions have been swapped within each word. Undo that now. */
@@ -46,11 +41,7 @@ static inline uint16_t arm_lduw_code(CPUARMState *env, target_ulong addr, addr ^=2 ; }#endif - insn =cpu_lduw_code (env, addr); -if (bswap_code (sctlr_b)) { -return bswap16 (insn); - } -return insn; +return translator_lduw_swap (env, addr,bswap_code (sctlr_b)); }#endif
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 31/54] target/arm: fetch code with translator_ld
Quoted 9 lines · Alex Bennée
From: "Emilio G. Cota" <[email protected]>
Now the arm_ld*_code functions are only used at translate time we can just pass down to
translator_ldfunctions.Signed-off-by Emilio G. Cota <[email protected]>[AJB: convert from plugin_insn_append to translator_ld]Signed-off-by Alex Bennée <[email protected]>
Quoted 6 lines
---
v4
- usetranslator_ldlike the rest of them--- target/arm/arm_ldst.h | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-)
r~
PATCH v4 32/54 target/ppc: fetch code with translator_ld
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
--- target/ppc/translate.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
target/ppc/translate.c +3 -5
@@ -7864,11 +7864,9 @@ static void ppc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)LOG_DISAS ("nip=" TARGET_FMT_lx" super=%d ir=%d\n" , ctx->base.pc_next, ctx->mem_idx, (int )msr_ir); -if (unlikely (need_byteswap (ctx))) { - ctx->opcode =bswap32 (cpu_ldl_code (env, ctx->base.pc_next)); - }else { - ctx->opcode =cpu_ldl_code (env, ctx->base.pc_next); - } + ctx->opcode =translator_ldl_swap (env, ctx->base.pc_next, +need_byteswap (ctx)); + LOG_DISAS("translate opcode %08x (%02x %02x %02x %02x) (%s)\n", ctx->opcode, opc1(ctx->opcode), opc2(ctx->opcode), opc3(ctx->opcode), opc4(ctx->opcode),
Signature · 1 line
2.20.1
PATCH v4 33/54 target/sh4: fetch code with translator_ld
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
There is a small wrinkle with the gUSA instruction. The translator effectively treats a (known) gUSA sequence as a single instruction. For the purposes of the plugin we end up with a long multi-instruction qemu_plugin_insn.
If the known sequence isn't detected we shall never run this translation anyway.
--- target/sh4/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/sh4/translate.c +2 -2
@@ -1917,7 +1917,7 @@ static void decode_gusa(DisasContext *ctx, CPUSH4State *env)/* Read all of the insns for the region. */ for (i =0 ; i < max_insns; ++i) { - insns[i] =cpu_lduw_code (env, pc + i *2 ); + insns[i] =translator_lduw (env, pc + i *2 ); } ld_adr = ld_dst = ld_mop =-1 ;
@@ -2332,7 +2332,7 @@ static void sh4_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) }#endif - ctx->opcode =cpu_lduw_code (env, ctx->base.pc_next); + ctx->opcode =translator_lduw (env, ctx->base.pc_next);decode_opc (ctx); ctx->base.pc_next +=2 ; }
Signature · 1 line
2.20.1
PATCH v4 34/54 target/i386: fetch code with translator_ld
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
--- target/i386/translate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
target/i386/translate.c +5 -5
@@ -1925,28 +1925,28 @@ static uint64_t advance_pc(CPUX86State *env, DisasContext *s, int num_bytes)static inline uint8_t x86_ldub_code (CPUX86State *env,DisasContext *s) { -return cpu_ldub_code (env,advance_pc (env, s,1 )); +return translator_ldub (env,advance_pc (env, s,1 )); }static inline int16_t x86_ldsw_code (CPUX86State *env,DisasContext *s) { -return cpu_ldsw_code (env,advance_pc (env, s,2 )); +return translator_ldsw (env,advance_pc (env, s,2 )); }static inline uint16_t x86_lduw_code (CPUX86State *env,DisasContext *s) { -return cpu_lduw_code (env,advance_pc (env, s,2 )); +return translator_lduw (env,advance_pc (env, s,2 )); }static inline uint32_t x86_ldl_code (CPUX86State *env,DisasContext *s) { -return cpu_ldl_code (env,advance_pc (env, s,4 )); +return translator_ldl (env,advance_pc (env, s,4 )); }#ifdef TARGET_X86_64 static inline uint64_t x86_ldq_code (CPUX86State *env,DisasContext *s) { -return cpu_ldq_code (env,advance_pc (env, s,8 )); +return translator_ldq (env,advance_pc (env, s,8 )); }#endif
Signature · 1 line
2.20.1
PATCH v4 35/54 target/hppa: fetch code with translator_ld
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
--- target/hppa/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/hppa/translate.c +1 -1
@@ -4217,7 +4217,7 @@ static void hppa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) {/* Always fetch the insn, even if nullified, so that we check the page permissions for execute. */ -uint32_t insn =cpu_ldl_code (env, ctx->base.pc_next); +uint32_t insn =translator_ldl (env, ctx->base.pc_next);/* Set up the IA queue for the next insn. This will be overwritten by a branch. */
Signature · 1 line
2.20.1
PATCH v4 36/54 target/m68k: fetch code with translator_ld
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
--- target/m68k/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/m68k/translate.c +1 -1
@@ -384,7 +384,7 @@ static TCGv gen_ldst(DisasContext *s, int opsize, TCGv addr, TCGv val,static inline uint16_t read_im16 (CPUM68KState *env,DisasContext *s) {uint16_t im; - im =cpu_lduw_code (env, s->pc); + im =translator_lduw (env, s->pc); s->pc +=2 ;return im; }
Signature · 1 line
2.20.1
PATCH v4 37/54 target/alpha: fetch code with translator_ld
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
--- target/alpha/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/alpha/translate.c +1 -1
@@ -2989,7 +2989,7 @@ static void alpha_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) {DisasContext *ctx =container_of (dcbase, DisasContext, base);CPUAlphaState *env = cpu->env_ptr; -uint32_t insn =cpu_ldl_code (env, ctx->base.pc_next); +uint32_t insn =translator_ldl (env, ctx->base.pc_next); ctx->base.pc_next +=4 ; ctx->base.is_jmp =translate_one (ctx, insn);
Signature · 1 line
2.20.1
PATCH v4 38/54 target/riscv: fetch code with translator_ld
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
--- target/riscv/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/riscv/translate.c +1 -1
@@ -796,7 +796,7 @@ static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)DisasContext *ctx =container_of (dcbase, DisasContext, base);CPURISCVState *env = cpu->env_ptr; - ctx->opcode =cpu_ldl_code (env, ctx->base.pc_next); + ctx->opcode =translator_ldl (env, ctx->base.pc_next);decode_opc (ctx); ctx->base.pc_next = ctx->pc_succ_insn;
Signature · 1 line
2.20.1
PATCH v4 39/54 target/sparc: fetch code with translator_ld
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
--- target/sparc/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/sparc/translate.c +1 -1
@@ -5900,7 +5900,7 @@ static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)CPUSPARCState *env = cs->env_ptr;unsigned int insn; - insn =cpu_ldl_code (env, dc->pc); + insn =translator_ldl (env, dc->pc); dc->base.pc_next +=4 ;disas_sparc_insn (dc, insn);
Signature · 1 line
2.20.1
PATCH v4 40/54 target/xtensa: fetch code with translator_ld
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
--- target/xtensa/translate.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/xtensa/translate.c +2 -2
@@ -863,7 +863,7 @@ static int arg_copy_compare(const void *a, const void *b)static void disas_xtensa_insn (CPUXtensaState *env,DisasContext *dc) {xtensa_isa isa = dc->config->isa; -unsigned char b[MAX_INSN_LENGTH ] = {cpu_ldub_code (env, dc->pc)}; +unsigned char b[MAX_INSN_LENGTH ] = {translator_ldub (env, dc->pc)};unsigned len =xtensa_op0_insn_len (dc, b[0 ]);xtensa_format fmt;int slot, slots;
@@ -887,7 +887,7 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc) dc->base.pc_next = dc->pc + len;for (i =1 ; i < len; ++i) { - b[i] =cpu_ldub_code (env, dc->pc + i); + b[i] =translator_ldub (env, dc->pc + i); }xtensa_insnbuf_from_chars (isa, dc->insnbuf, b, len); fmt =xtensa_format_decode (isa, dc->insnbuf);
Signature · 1 line
2.20.1
PATCH v4 41/54 target/openrisc: fetch code with translator_ld
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
--- target/openrisc/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target/openrisc/translate.c +1 -1
@@ -1305,7 +1305,7 @@ static void openrisc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) {DisasContext *dc =container_of (dcbase, DisasContext, base);OpenRISCCPU *cpu =OPENRISC_CPU (cs); -uint32_t insn =cpu_ldl_code (&cpu->env, dc->base.pc_next); +uint32_t insn =translator_ldl (&cpu->env, dc->base.pc_next);if (!decode (dc, insn)) {gen_illegal_exception (dc);
Signature · 1 line
2.20.1
PATCH v4 42/54 translator: inject instrumentation from plugins
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
---
v4
- note we can't inject instrumentation if ! DISAS_NEXT
--- accel/tcg/translator.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
accel/tcg/translator.c +20 -0
@@ -16,6 +16,7 @@#include "exec/gen-icount.h" #include "exec/log.h" #include "exec/translator.h" +#include "exec/plugin-gen.h" /* Pairs with tcg_clear_temp_count. To be called by #TranslatorOps.{translate_insn,tb_stop} if
@@ -34,6 +35,7 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, CPUState *cpu, TranslationBlock *tb, int max_insns) {int bp_insn =0 ; +bool plugin_enabled;/* Initialize DisasContext */ db->tb = tb;
@@ -55,11 +57,17 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, ops->tb_start (db, cpu);tcg_debug_assert (db->is_jmp ==DISAS_NEXT );/* no early exit */ + plugin_enabled =plugin_gen_tb_start (cpu, tb); +while (true) { db->num_insns++; ops->insn_start (db, cpu);tcg_debug_assert (db->is_jmp ==DISAS_NEXT );/* no early exit */ +if (plugin_enabled) { +plugin_gen_insn_start (cpu, db); + } +/* Pass breakpoint hits to target for further processing */ if (!db->singlestep_enabled &&unlikely (!QTAILQ_EMPTY (&cpu->breakpoints))) {
@@ -100,6 +108,14 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db,break ; } +/* +* We can't instrument after instructions that change control +* flow although this only really affects post-load operations. +*/ +if (plugin_enabled) { +plugin_gen_insn_end (); + } +/* Stop translation if the output buffer is full, or we have executed all of the allowed instructions. */ if (tcg_op_buf_full () || db->num_insns >= db->max_insns) {
@@ -112,6 +128,10 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db, ops->tb_stop (db, cpu);gen_tb_end (db->tb, db->num_insns - bp_insn); +if (plugin_enabled) { +plugin_gen_tb_end (cpu); + } +/* The disas_log hook may use these values rather than recompute. */ db->tb->size = db->pc_next - db->pc_first; db->tb->icount = db->num_insns;
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 42/54] translator: inject instrumentation from plugins
Quoted 11 lines · Alex Bennée
From: "Emilio G. Cota" <[email protected]>
Signed-off-by Emilio G. Cota <[email protected]>Signed-off-by Alex Bennée <[email protected]>---
v4
- note we can't inject instrumentation if !DISAS_NEXT--- accel/tcg/translator.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
r~
PATCH v4 43/54 plugin: add API symbols to qemu-plugins.symbols
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
---
v3
- moved to plugins/
- include qemu_plugin_reset
--- Makefile | 1 + configure | 69 ++++++++++++++++++++++++++++++++++++ plugins/.gitignore | 2 ++ plugins/Makefile.objs | 14 ++++++++ plugins/qemu-plugins.symbols | 38 ++++++++++++++++++++ 5 files changed, 124 insertions(+) create mode 100644 plugins/.gitignore create mode 100644 plugins/qemu-plugins.symbols
Makefile +1 -0
@@ -726,6 +726,7 @@ distclean: clean rm -f qemu-doc.fn qemu-doc.fns qemu-doc.info qemu-doc.ky qemu-doc.kys rm -f qemu-doc.log qemu-doc.pdf qemu-doc.pg qemu-doc.toc qemu-doc.tp rm -f qemu-doc.vr qemu-doc.txt + rm -f qemu-plugins-ld.symbols qemu-plugins-ld64.symbols rm -f config.log rm -f linux-headers/asm rm -f docs/version.texi
configure +69 -0
87 lines not on this page · raw message
plugins/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +qemu-plugins-ld.symbols +qemu-plugins-ld64.symbols
plugins/Makefile.objs +14 -0
@@ -5,3 +5,17 @@ obj-y += loader.o obj-y += core.o obj-y += api.o + +# Abuse -libs suffix to only link with --dynamic-list/-exported_symbols_list +# when the final binary includes the plugin object. +# +# Note that simply setting LDFLAGS is not enough: we build binaries that +# never link plugin.o, and the linker might fail (at least ld64 does) +# if the symbols in the list are not in the output binary. +ifdef CONFIG_HAS_LD_DYNAMIC_LIST +api.o-libs := -Wl,--dynamic-list=$(BUILD_DIR)/qemu-plugins-ld.symbols +else +ifdef CONFIG_HAS_LD_EXPORTED_SYMBOLS_LIST +api.o-libs := -Wl,-exported_symbols_list,$(BUILD_DIR)/qemu-plugins-ld64.symbols +endif +endif
plugins/qemu-plugins.symbols new file +38 -0
@@ -0,0 +1,38 @@ +{ + qemu_plugin_uninstall; + qemu_plugin_reset; + qemu_plugin_register_vcpu_init_cb; + qemu_plugin_register_vcpu_exit_cb; + qemu_plugin_register_vcpu_idle_cb; + qemu_plugin_register_vcpu_resume_cb; + qemu_plugin_register_vcpu_insn_exec_cb; + qemu_plugin_register_vcpu_insn_exec_inline; + qemu_plugin_register_vcpu_mem_cb; + qemu_plugin_register_vcpu_mem_haddr_cb; + qemu_plugin_register_vcpu_mem_inline; + qemu_plugin_ram_addr_from_host; + qemu_plugin_register_vcpu_tb_trans_cb; + qemu_plugin_register_vcpu_tb_exec_cb; + qemu_plugin_register_vcpu_tb_exec_inline; + qemu_plugin_register_flush_cb; + qemu_plugin_register_vcpu_syscall_cb; + qemu_plugin_register_vcpu_syscall_ret_cb; + qemu_plugin_register_atexit_cb; + qemu_plugin_tb_n_insns; + qemu_plugin_tb_get_insn; + qemu_plugin_tb_vaddr; + qemu_plugin_insn_data; + qemu_plugin_insn_size; + qemu_plugin_insn_vaddr; + qemu_plugin_insn_haddr; + qemu_plugin_mem_size_shift; + qemu_plugin_mem_is_sign_extended; + qemu_plugin_mem_is_big_endian; + qemu_plugin_mem_is_store; + qemu_plugin_get_hwaddr; + qemu_plugin_hwaddr_is_io; + qemu_plugin_hwaddr_to_raddr; + qemu_plugin_vcpu_for_each; + qemu_plugin_n_vcpus; + qemu_plugin_n_max_vcpus; +};
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 43/54] plugin: add API symbols to qemu-plugins.symbols
Quoted 67 lines · Alex Bennée
configure +60
-0+######################################### +# See if --dynamic-list is supported by the linker + +cat > $TMPTXT <<EOF +{ + foo; +}; +EOF + +cat > $TMPC <<EOF +#include <stdio.h> +void foo(void); + +void foo(void) +{ + printf("foo\n"); +} + +int main(void) +{ + foo(); + return 0; +} +EOF + +ld_dynamic_list="no" +if compile_prog "" "-Wl,--dynamic-list=$TMPTXT" ; then + ld_dynamic_list="yes" +fi + +######################################### +# See if -exported_symbols_list is supported by the linker + +cat > $TMPTXT <<EOF + _foo +EOF + +ld_exported_symbols_list="no" +if compile_prog "" "-Wl,-exported_symbols_list,$TMPTXT" ; then + ld_exported_symbols_list="yes" +fi + +if test "$plugins" = "yes" && + test "$ld_dynamic_list" = "no" && + test "$ld_exported_symbols_list" = "no" ; then + error_exit \ + "Plugin support requires specifying a set of symbols that " \ + "are exported to plugins. Unfortunately your linker doesn't " \ + "support the flag (--dynamic-list or -exported_symbols_list) used " \ + "for this purpose." +fi + ######################################## # See if 16-byte vector operations are supported. # Even without a vector unit the compiler may expand these.@@ -7318,6 +7371,22 @@ fi if test "$plugins" = "yes" ; then echo "CONFIG_PLUGIN=y" >> $config_host_mak LIBS="-ldl $LIBS" + # Copy the export object list to the build dir + if test "$ld_dynamic_list" = "yes" ; then + echo "CONFIG_HAS_LD_DYNAMIC_LIST=yes" >> $config_host_mak + ld_symbols=qemu-plugins-ld.symbols + cp "$source_path/plugins/qemu-plugins.symbols" $ld_symbols + elif test "$ld_exported_symbols_list" = "yes" ; then + echo "CONFIG_HAS_LD_EXPORTED_SYMBOLS_LIST=yes" >> $config_host_mak + ld64_symbols=qemu-plugins-ld64.symbols
configure fi · line 7391
Quoted 10 lines
configure +8
-0+ echo "# Automatically generated by configure - do not modify" > $ld64_symbols + grep 'qemu_' "$source_path/plugins/qemu-plugins.symbols" | sed 's/;//g' | \ + sed -E 's/^[[:space:]]*(.*)/_\1/' >> $ld64_symbols + else + error_exit \ + "If \$plugins=yes, either \$ld_dynamic_list or " \ + "\$ld_exported_symbols_list should have been set to 'yes'." + fi fi
How much of this should be skipped if --enable-static? Or perhaps just dependent on --enable-plugins and let that switch detect the conflict?
r~
Re: [Qemu-devel] [PATCH v4 43/54] plugin: add API symbols to qemu-plugins.symbols
Quoted 74 lines · Richard Henderson
Quoted 73 lines · Alex Bennée
configure +66
-0+######################################### +# See if --dynamic-list is supported by the linker + +cat > $TMPTXT <<EOF +{ + foo; +}; +EOF + +cat > $TMPC <<EOF +#include <stdio.h> +void foo(void); + +void foo(void) +{ + printf("foo\n"); +} + +int main(void) +{ + foo(); + return 0; +} +EOF + +ld_dynamic_list="no" +if compile_prog "" "-Wl,--dynamic-list=$TMPTXT" ; then + ld_dynamic_list="yes" +fi + +######################################### +# See if -exported_symbols_list is supported by the linker + +cat > $TMPTXT <<EOF + _foo +EOF + +ld_exported_symbols_list="no" +if compile_prog "" "-Wl,-exported_symbols_list,$TMPTXT" ; then + ld_exported_symbols_list="yes" +fi + +if test "$plugins" = "yes" && + test "$ld_dynamic_list" = "no" && + test "$ld_exported_symbols_list" = "no" ; then + error_exit \ + "Plugin support requires specifying a set of symbols that " \ + "are exported to plugins. Unfortunately your linker doesn't " \ + "support the flag (--dynamic-list or -exported_symbols_list) used " \ + "for this purpose." +fi + ######################################## # See if 16-byte vector operations are supported. # Even without a vector unit the compiler may expand these.@@ -7318,6 +7371,22 @@ fi if test "$plugins" = "yes" ; then echo "CONFIG_PLUGIN=y" >> $config_host_mak LIBS="-ldl $LIBS" + # Copy the export object list to the build dir + if test "$ld_dynamic_list" = "yes" ; then + echo "CONFIG_HAS_LD_DYNAMIC_LIST=yes" >> $config_host_mak + ld_symbols=qemu-plugins-ld.symbols + cp "$source_path/plugins/qemu-plugins.symbols" $ld_symbols + elif test "$ld_exported_symbols_list" = "yes" ; then + echo "CONFIG_HAS_LD_EXPORTED_SYMBOLS_LIST=yes" >> $config_host_mak + ld64_symbols=qemu-plugins-ld64.symbols + echo "# Automatically generated by configure - do not modify" > $ld64_symbols + grep 'qemu_' "$source_path/plugins/qemu-plugins.symbols" | sed 's/;//g' | \ + sed -E 's/^[[:space:]]*(.*)/_\1/' >> $ld64_symbols + else + error_exit \ + "If \$plugins=yes, either \$ld_dynamic_list or " \
Quoted 8 lines
configure fi · line 7391
Quoted 4 lines
configure +2
-0+ "\$ld_exported_symbols_list should have been set to 'yes'." + fi fiHow much of this should be skipped if --enable-static? Or perhaps just dependent on --enable-plugins and let that switch detect the conflict?
I've gated the ld_dynamic_list checks on if test "$static" = "no" so it errors out quickly if you try and build with --static --enable-plugins.
Quoted 3 lines
r~
--
Alex Bennée
PATCH v4 44/54 vl: support -plugin option
In reply to Alex BennéeFrom: Lluís Vilanova <[email protected]>
--- qemu-options.hx | 17 +++++++++++++++++ vl.c | 11 +++++++++++ 2 files changed, 28 insertions(+)
qemu-options.hx +17 -0
@@ -4131,6 +4131,23 @@ HXCOMM HX does not support conditional compilation of text. @findex -trace @include qemu-option-trace.texi ETEXI +DEF("plugin", HAS_ARG, QEMU_OPTION_plugin, + "-plugin [file=]<file>[,arg=<string>]\n" + " load a plugin\n", + QEMU_ARCH_ALL) +STEXI +@item -plugin file=@var{file}[,arg=@var{string}] +@findex -plugin + +Load a plugin. + +@table @option +@item file=@var{file} +Load the given plugin from a shared library file. +@item arg=@var{string} +Argument string passed to the plugin. (Can be given multiple times.) +@end table +ETEXI HXCOMM Internal use DEF("qtest", HAS_ARG, QEMU_OPTION_qtest, "", QEMU_ARCH_ALL)
vl.c +11 -0
@@ -109,6 +109,7 @@ int main(int argc, char **argv)#include "trace-root.h" #include "trace/control.h" +#include "qemu/plugin.h" #include "qemu/queue.h" #include "sysemu/arch_init.h"
@@ -2889,6 +2890,7 @@ int main(int argc, char **argv, char **envp)bool list_data_dirs = false;char *dir, **dirs;BlockdevOptionsQueue bdo_queue =QSIMPLEQ_HEAD_INITIALIZER (bdo_queue); +QemuPluginList plugin_list =QTAILQ_HEAD_INITIALIZER (plugin_list);os_set_line_buffering ();
@@ -2919,6 +2921,7 @@ 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); +qemu_plugin_add_opts ();qemu_add_opts (&qemu_option_rom_opts);qemu_add_opts (&qemu_machine_opts);qemu_add_opts (&qemu_accel_opts);
@@ -3697,6 +3700,9 @@ int main(int argc, char **argv, char **envp)g_free (trace_file); trace_file =trace_opt_parse (optarg);break ; +case QEMU_OPTION_plugin: +qemu_plugin_opt_parse (optarg, &plugin_list); +break ;case QEMU_OPTION_readconfig: {int ret =qemu_read_config_file (optarg);
@@ -4010,6 +4016,11 @@ int main(int argc, char **argv, char **envp) machine_class->default_machine_opts, 0); } +/* process plugin before CPUs are created, but once -smp has been parsed */ +if (qemu_plugin_load_list (&plugin_list)) { +exit (1 ); + } +qemu_opts_foreach (qemu_find_opts ("device" ), default_driver_check,NULL ,NULL ); qemu_opts_foreach(qemu_find_opts("global"),
Signature · 1 line
2.20.1
PATCH v4 45/54 linux-user: support -plugin option
In reply to Alex BennéeFrom: Lluís Vilanova <[email protected]>
--- linux-user/main.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
linux-user/main.c +18 -0
@@ -33,6 +33,7 @@#include "qemu/error-report.h" #include "qemu/help_option.h" #include "qemu/module.h" +#include "qemu/plugin.h" #include "cpu.h" #include "exec/exec-all.h" #include "tcg.h"
@@ -392,6 +393,15 @@ static void handle_arg_trace(const char *arg) trace_file =trace_opt_parse (arg); } +static QemuPluginList plugins =QTAILQ_HEAD_INITIALIZER (plugins); + +#ifdef CONFIG_PLUGIN +static void handle_arg_plugin (const char *arg) +{ +qemu_plugin_opt_parse (arg, &plugins); +} +#endif +struct qemu_argument {const char *argv;const char *env;
@@ -443,6 +453,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>]"}, +#ifdef CONFIG_PLUGIN + {"plugin", "QEMU_PLUGIN", true, handle_arg_plugin, + "", "[file=]<file>[,arg=<string>]"}, +#endif {"version", "QEMU_VERSION", false, handle_arg_version, "", "display version information and exit"}, {NULL, NULL, false, NULL, NULL, NULL}
@@ -633,6 +647,7 @@ int main(int argc, char **argv, char **envp) cpu_model =NULL ;qemu_add_opts (&qemu_trace_opts); +qemu_plugin_add_opts (); optind =parse_args (argc, argv);
@@ -640,6 +655,9 @@ int main(int argc, char **argv, char **envp)exit (1 ); }trace_init_file (trace_file); +if (qemu_plugin_load_list (&plugins)) { +exit (1 ); + }/* Zero out regs */ memset (regs,0 ,sizeof (struct target_pt_regs ));
Signature · 1 line
2.20.1
PATCH v4 46/54 tests/plugin: add sample plugins
In reply to Alex BennéeFrom: "Emilio G. Cota" <[email protected]>
Pass arguments with -plugin=libfoo.so,arg=bar,arg=baz
---
v4
- tweaks for hwaddr API
--- configure | 4 +- tests/plugin/Makefile | 28 +++++++++++++ tests/plugin/bb.c | 65 +++++++++++++++++++++++++++++ tests/plugin/empty.c | 29 +++++++++++++ tests/plugin/insn.c | 62 ++++++++++++++++++++++++++++ tests/plugin/mem.c | 96 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 282 insertions(+), 2 deletions(-) create mode 100644 tests/plugin/Makefile create mode 100644 tests/plugin/bb.c create mode 100644 tests/plugin/empty.c create mode 100644 tests/plugin/insn.c create mode 100644 tests/plugin/mem.c
configure +2 -2
@@ -8006,14 +8006,14 @@ fi # tests might fail. Prefer to keep the relevant files in their own # directory and symlink the directory instead. DIRS="tests tests/tcg tests/tcg/cris tests/tcg/lm32 tests/libqos tests/qapi-schema tests/tcg/xtensa tests/qemu-iotests tests/vm" -DIRS="$DIRS tests/fp tests/qgraph" +DIRS="$DIRS tests/fp tests/qgraph tests/plugin" DIRS="$DIRS docs docs/interop fsdev scsi" DIRS="$DIRS pc-bios/optionrom pc-bios/spapr-rtas pc-bios/s390-ccw" DIRS="$DIRS roms/seabios roms/vgabios" LINKS="Makefile tests/tcg/Makefile" LINKS="$LINKS tests/tcg/cris/Makefile tests/tcg/cris/.gdbinit" LINKS="$LINKS tests/tcg/lm32/Makefile tests/tcg/xtensa/Makefile po/Makefile" -LINKS="$LINKS tests/fp/Makefile" +LINKS="$LINKS tests/fp/Makefile tests/plugin/Makefile" LINKS="$LINKS pc-bios/optionrom/Makefile pc-bios/keymaps" LINKS="$LINKS pc-bios/spapr-rtas/Makefile" LINKS="$LINKS pc-bios/s390-ccw/Makefile"
tests/plugin/Makefile new file +28 -0
@@ -0,0 +1,28 @@ +BUILD_DIR := $(CURDIR)/../.. + +include $(BUILD_DIR)/config-host.mak +include $(SRC_PATH)/rules.mak + +$(call set-vpath, $(SRC_PATH)/tests/plugin) + +NAMES := +NAMES += bb +NAMES += empty +NAMES += insn +NAMES += mem + +SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES))) + +QEMU_CFLAGS += -fPIC +QEMU_CFLAGS += -I$(SRC_PATH)/include/qemu + +all: $(SONAMES) + +lib%.so: %.o + $(CC) -shared -Wl,-soname,$@ -o $@ $^ $(LDLIBS) + +clean: + rm -f *.o *.so *.d + rm -Rf .libs + +.PHONY: all clean
tests/plugin/bb.c new file +65 -0
65 lines not on this page · raw message
tests/plugin/empty.c new file +29 -0
@@ -0,0 +1,29 @@ +/* +* Copyright (C) 2018, Emilio G. Cota <[email protected]> +* +* License: GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +#include <inttypes.h> +#include <assert.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <stdio.h> + +#include <qemu-plugin.h> + +/* +* Empty TB translation callback. +* This allows us to measure the overhead of injecting and then +* removing empty instrumentation. +*/ +static void vcpu_tb_trans (qemu_plugin_id_t id,struct qemu_plugin_tb *tb) +{ } + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, int argc, +char **argv) +{ +qemu_plugin_register_vcpu_tb_trans_cb (id, vcpu_tb_trans); +return 0 ; +}
tests/plugin/insn.c new file +62 -0
62 lines not on this page · raw message
tests/plugin/mem.c new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v4 47/54 tests/tcg: enable plugin testing
In reply to Alex BennéeIf CONFIG_PLUGINS is enabled then lets enable testing for all our TCG targets. This is a simple smoke test that ensure we don't crash or otherwise barf out by running each plugin against each test.
There is a minor knock on effect for additional runners which need specialised QEMU_OPTS which will also need to declare a plugin version of the runner. If this gets onerous we might need to add another helper.
Checking the results of the plugins is left for a later exercise.
--- tests/Makefile.include | 10 +++++++- tests/tcg/Makefile | 34 +++++++++++++++++++++++++++ tests/tcg/arm/Makefile.softmmu-target | 1 + 3 files changed, 44 insertions(+), 1 deletion(-)
tests/Makefile.include +9 -1
@@ -1052,6 +1052,14 @@ check-softfloat: "SKIPPED for non-TCG builds") endif +# Plugins +ifeq ($(CONFIG_PLUGIN),y) +plugins: + $(call quiet-command,\ + $(MAKE) $(SUBDIR_MAKEFLAGS) -C tests/plugin V="$(V)", \ + "BUILD", "plugins") +endif + # Per guest TCG tests BUILD_TCG_TARGET_RULES=$(patsubst %,build-tcg-tests-%, $(TARGET_DIRS))
@@ -1066,7 +1074,7 @@ $(foreach PROBE_TARGET,$(TARGET_DIRS), \ $(eval build-tcg-tests-$(PROBE_TARGET): $(DOCKER_PREREQ)))) endif -build-tcg-tests-%: +build-tcg-tests-%: $(if $(CONFIG_PLUGIN),plugins) $(call quiet-command,$(MAKE) $(SUBDIR_MAKEFLAGS) -C $* V="$(V)" \ SKIP_DOCKER_BUILD=1 TARGET_DIR="$*/" guest-tests, \ "BUILD", "TCG tests for $*")
tests/tcg/Makefile +34 -0
@@ -120,11 +120,37 @@ all: $(TESTS) # RUN_TESTS=$(patsubst %,run-%, $(TESTS)) + +# If plugins exist also include those in the tests +ifeq ($(CONFIG_PLUGIN),y) +PLUGIN_DIR=../../tests/plugin +VPATH+=$(PLUGIN_DIR) +PLUGINS=$(notdir $(wildcard $(PLUGIN_DIR)/*.so)) + +# We need to ensure expand the run-plugin-TEST-with-PLUGIN +# pre-requistes manually here as we can't use stems to handle it. We +# also add some special helpers the run-plugin- rules can use bellow. + +$(foreach p,$(PLUGINS), \ + $(foreach t,$(TESTS),\ + $(eval run-plugin-$(t)-with-$(p): $t $p) \ + $(eval RUN_TESTS+=run-plugin-$(t)-with-$(p)))) +endif + +strip-plugin = $(wordlist 1, 1, $(subst -with-, ,$1)) +extract-plugin = $(wordlist 2, 2, $(subst -with-, ,$1)) + RUN_TESTS+=$(EXTRA_RUNS) ifdef CONFIG_USER_ONLY run-%: % $(call run-test, $<, $(QEMU) $(QEMU_OPTS) $<, "$< on $(TARGET_NAME)") + +run-plugin-%: + $(call run-test, $@, $(QEMU) $(QEMU_OPTS) \ + -plugin $(PLUGIN_DIR)/$(call extract-plugin,$@) \ + $(call strip-plugin,$<), \ + "$< on $(TARGET_NAME)") else run-%: % $(call run-test, $<, \
@@ -132,6 +158,14 @@ run-%: % -chardev file$(COMMA)path=$<.out$(COMMA)id=output \ $(QEMU_OPTS) $<, \ "$< on $(TARGET_NAME)") + +run-plugin-%: + $(call run-test, $@, \ + $(QEMU) -monitor none -display none \ + -chardev file$(COMMA)[email protected]$(COMMA)id=output \ + -plugin $(PLUGIN_DIR)/$(call extract-plugin,$@) \ + $(QEMU_OPTS) $(call strip-plugin,$<), \ + "$< on $(TARGET_NAME)") endif gdb-%: %
tests/tcg/arm/Makefile.softmmu-target +1 -0
@@ -25,5 +25,6 @@ LDFLAGS+=-nostdlib -N -static test-armv6m-undef: EXTRA_CFLAGS+=-mcpu=cortex-m0 run-test-armv6m-undef: QEMU_OPTS+=-semihosting -M microbit -kernel +run-plugin-test-armv6m-undef-%: QEMU_OPTS+=-semihosting -M microbit -kernel endif
Signature · 1 line
2.20.1
PATCH v4 48/54 tests/plugin: add a hotblocks plugin
In reply to Alex BennéeThis is a simple plugin to track which translation blocks are call most often. As we don't have a view of the internals of TCG we can only work by the address of the start of the block so we also need to tracks how often the address is translated.
As there will be multiple blocks starting at the same address. We can try and work around this by futzing the value to feed to the hash with the insn count.
--- tests/plugin/Makefile | 1 + tests/plugin/hotblocks.c | 146 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 tests/plugin/hotblocks.c
tests/plugin/Makefile +1 -0
@@ -10,6 +10,7 @@ NAMES += bb NAMES += empty NAMES += insn NAMES += mem +NAMES += hotblocks SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))
tests/plugin/hotblocks.c new file +146 -0
146 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v4 49/54 plugin: add qemu_plugin_insn_disas helper
In reply to Alex BennéeGive the plugins access to the QEMU dissasembler so they don't have to re-invent the wheel.
--- disas.c | 103 +++++++++++++++++++++++++++++++++++ include/disas/disas.h | 2 + include/qemu/qemu-plugin.h | 9 +++ plugins/api.c | 7 +++ plugins/qemu-plugins.symbols | 1 + 5 files changed, 122 insertions(+)
disas.c +103 -0
@@ -475,6 +475,109 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code, } } +static GString plugin_disas_output; + +static int plugin_printf (FILE *stream,const char *fmt, ...) +{ +va_list va; +GString *s = &plugin_disas_output; +int initial_len = s->len; + +va_start (va, fmt); +g_string_append_printf (s, fmt, va); +va_end (va); + +return s->len - initial_len; +} + +static void plugin_print_address (bfd_vma addr,struct disassemble_info *info) +{ +/* does nothing */ +} + +/* Disassemble a single instruction directly into plugin output */ +static +bool plugin_cap_disas_insn (disassemble_info *info,uint64_t pc,size_t size) +{ +uint8_t cap_buf[1024 ]; +csh handle; +cs_insn *insn; +size_t csize =0 ; +int count; +GString *s = &plugin_disas_output; + +if (cap_disas_start (info, &handle) !=CS_ERR_OK ) { +return false; + } + insn = cap_insn; + +size_t tsize =MIN (sizeof (cap_buf) - csize, size); +const uint8_t *cbuf = cap_buf; +target_read_memory (pc, cap_buf, tsize, info); + + count =cs_disasm (handle, cbuf, size,0 ,1 , &insn); + +if (count) { +g_string_printf (s,"%s %s" , insn->mnemonic, insn->op_str); + }else { +g_string_printf (s,"cs_disasm failed" ); + } + +cs_close (&handle); +return true; +} + +char *plugin_disas (CPUState *cpu,uint64_t addr,size_t size) +{ +CPUClass *cc =CPU_GET_CLASS (cpu); +target_ulong pc; +int count; +CPUDebug s; +GString *ds =g_string_set_size (&plugin_disas_output,0 ); + +g_assert (ds == &plugin_disas_output); + +INIT_DISASSEMBLE_INFO (s.info,NULL , plugin_printf); + + s.cpu = cpu; + s.info.read_memory_func = target_read_memory; + s.info.buffer_vma = addr; + s.info.buffer_length = size; + s.info.print_address_func = plugin_print_address; + s.info.cap_arch =-1 ; + s.info.cap_mode =0 ; + s.info.cap_insn_unit =4 ; + s.info.cap_insn_split =4 ; + +#ifdef TARGET_WORDS_BIGENDIAN + s.info.endian =BFD_ENDIAN_BIG ; +#else + s.info.endian =BFD_ENDIAN_LITTLE ; +#endif + +if (cc->disas_set_info) { + cc->disas_set_info (cpu, &s.info); + } + +if (s.info.cap_arch >=0 &&plugin_cap_disas_insn (&s.info, addr, size)) { +return g_strdup (ds->str); + } + +if (s.info.print_insn ==NULL ) { + s.info.print_insn = print_insn_od_target; + } + +for (pc = addr; size >0 ; pc += count, size -= count) { + count = s.info.print_insn (pc, &s.info); +if (count <0 ) { +break ; + } +g_assert (size >= count); + } + +return g_strdup (ds->str); +} +/* Disassemble this for me please... (debugging). */ void disas (FILE *out,void *code,unsigned long size) {
include/disas/disas.h +2 -0
@@ -13,6 +13,8 @@ void target_disas(FILE *out, CPUState *cpu, target_ulong code,void monitor_disas (Monitor *mon,CPUState *cpu,target_ulong pc,int nb_insn,int is_physical); +char *plugin_disas (CPUState *cpu,uint64_t addr,size_t size); +/* Look up symbol for debugging purpose. Returns "" if unknown. */ const char *lookup_symbol (target_ulong orig_addr);#endif
include/qemu/qemu-plugin.h +9 -0
@@ -324,6 +324,15 @@ qemu_plugin_register_vcpu_syscall_ret_cb(qemu_plugin_id_t id, qemu_plugin_vcpu_syscall_ret_cb_t cb); +/** +* qemu_plugin_insn_disas() - return disassembly string for instruction +* @insn: instruction reference +* +* Returns an allocated string containing the disassembly +*/ + +char *qemu_plugin_insn_disas (const struct qemu_plugin_insn *insn); +/** * qemu_plugin_vcpu_for_each() - iterate over the existing vCPU * @id: plugin ID
plugins/api.c +7 -0
@@ -40,6 +40,7 @@#include "sysemu/sysemu.h" #include "tcg/tcg.h" #include "exec/exec-all.h" +#include "disas/disas.h" #include "plugin.h" #ifndef CONFIG_USER_ONLY #include "hw/boards.h"
@@ -211,6 +212,12 @@ void *qemu_plugin_insn_haddr(const struct qemu_plugin_insn *insn)return insn->haddr; } +char *qemu_plugin_insn_disas (const struct qemu_plugin_insn *insn) +{ +CPUState *cpu = current_cpu; +return plugin_disas (cpu, insn->vaddr, insn->data->len); +} +/* * The memory queries allow the plugin to query information about a * memory access.
plugins/qemu-plugins.symbols +1 -0
@@ -25,6 +25,7 @@ qemu_plugin_insn_size; qemu_plugin_insn_vaddr; qemu_plugin_insn_haddr; + qemu_plugin_insn_disas; qemu_plugin_mem_size_shift; qemu_plugin_mem_is_sign_extended; qemu_plugin_mem_is_big_endian;
Signature · 1 line
2.20.1
PATCH v4 50/54 tests/plugin: add instruction execution breakdown
In reply to Alex BennéeThis gives a break down of instruction classes and individual instruction types.
--- tests/plugin/Makefile | 1 + tests/plugin/howvec.c | 301 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 302 insertions(+) create mode 100644 tests/plugin/howvec.c
tests/plugin/Makefile +1 -0
@@ -11,6 +11,7 @@ NAMES += empty NAMES += insn NAMES += mem NAMES += hotblocks +NAMES += howvec SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))
tests/plugin/howvec.c new file +301 -0
301 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 50/54] tests/plugin: add instruction execution breakdown
Quoted 3 lines · Alex Bennée
+ * Attempt to measure the amount of vectorisation that has been done
+ * on some code by counting classes of instruction. This is very much
+ * ARM specific.
I suspect some of my plugins will also be architecture-specific. Does it make sense to have a plugin specify to QEMU which architectures or running modes (i.e. softmmu vs. linux user) it supports? Or alternatively to have QEMU expose this information to the plugin so that it can cleanly exit if its needs are not met?
-Aaron
Re: [PATCH v4 50/54] tests/plugin: add instruction execution breakdown
Quoted 10 lines · Aaron Lindsay OS
Quoted 3 lines · Alex Bennée
+ * Attempt to measure the amount of vectorisation that has been done
+ * on some code by counting classes of instruction. This is very much
+ * ARM specific.I suspect some of my plugins will also be architecture-specific. Does it make sense to have a plugin specify to QEMU which architectures or running modes (i.e. softmmu vs. linux user) it supports? Or alternatively to have QEMU expose this information to the plugin so that it can cleanly exit if its needs are not met?
I've exposed an information block with the qemu type in it as a string. This allows the plugin to take appropriate action.
Quoted 2 lines
-Aaron
--
Alex Bennée
PATCH v4 51/54 tests/plugin: add hotpages plugin to breakdown memory access patterns
In reply to Alex BennéeThis plugin gives a break down of access patterns grouped into pages.
---
v4
- tweaks for new hwaddr api
- add sorting and pagesize selection args
--- tests/plugin/Makefile | 1 + tests/plugin/hotpages.c | 179 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+) create mode 100644 tests/plugin/hotpages.c
tests/plugin/Makefile +1 -0
@@ -12,6 +12,7 @@ NAMES += insn NAMES += mem NAMES += hotblocks NAMES += howvec +NAMES += hotpages SONAMES := $(addsuffix .so,$(addprefix lib,$(NAMES)))
tests/plugin/hotpages.c new file +179 -0
179 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v4 52/54 accel/stubs: reduce headers from tcg-stub
In reply to Alex BennéeWe don't need much for these. However I do wonder why these aren't just null inlines in exec-all.h
--- accel/stubs/tcg-stub.c | 3 --- 1 file changed, 3 deletions(-)
accel/stubs/tcg-stub.c +0 -3
@@ -11,10 +11,7 @@*/ #include "qemu/osdep.h" -#include "qemu-common.h" #include "cpu.h" -#include "tcg/tcg.h" -#include "exec/cpu-common.h" #include "exec/exec-all.h" void tb_flush (CPUState *cpu)
Signature · 1 line
2.20.1
PATCH v4 53/54 include/exec: wrap cpu_ldst.h in CONFIG_TCG
In reply to Alex BennéeThis gets around a build problem with --disable-tcg.
--- include/exec/exec-all.h | 2 ++ 1 file changed, 2 insertions(+)
include/exec/exec-all.h +2 -0
@@ -21,7 +21,9 @@#define EXEC_ALL_H #include "exec/tb-context.h" +#ifdef CONFIG_TCG #include "exec/cpu_ldst.h" +#endif #include "sysemu/cpus.h" /* allow to see translation results - the slowdown should be negligible, so we leave it */
Signature · 1 line
2.20.1
Re: [Qemu-devel] [PATCH v4 53/54] include/exec: wrap cpu_ldst.h in CONFIG_TCG
Quoted 6 lines · Alex Bennée
This gets around a build problem with --disable-tcg.
Signed-off-by Alex Bennée <[email protected]>--- include/exec/exec-all.h | 2 ++ 1 file changed, 2 insertions(+)
r~
PATCH v4 54/54 include/exec/cpu-defs.h: fix typo
In reply to Alex Bennée--- include/exec/cpu-defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/exec/cpu-defs.h +1 -1
@@ -233,7 +233,7 @@ typedef struct CPUTLB { } CPUTLB;#endif /* !CONFIG_USER_ONLY && CONFIG_TCG */ /* -* This structure must be placed in ArchCPU immedately +* This structure must be placed in ArchCPU immediately * before CPUArchState, as a field named "neg". */ typedef struct CPUNegativeOffsetState {
Signature · 1 line
2.20.1
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Subject: [Qemu-devel] [PATCH v4 00/54] plugins for TCG
Message-id: [email protected]
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected] -> patchew/[email protected]
* [new tag] patchew/[email protected] -> patchew/[email protected]
Submodule 'capstone' (https://git.qemu.org/git/capstone.git) registered for path 'capstone'
Submodule 'dtc' (https://git.qemu.org/git/dtc.git) registered for path 'dtc'
Submodule 'roms/QemuMacDrivers' (https://git.qemu.org/git/QemuMacDrivers.git) registered for path 'roms/QemuMacDrivers' Submodule 'roms/SLOF' (https://git.qemu.org/git/SLOF.git) registered for path 'roms/SLOF'
Submodule 'roms/edk2' (https://git.qemu.org/git/edk2.git) registered for path 'roms/edk2'
Submodule 'roms/ipxe' (https://git.qemu.org/git/ipxe.git) registered for path 'roms/ipxe'
Submodule 'roms/openbios' (https://git.qemu.org/git/openbios.git) registered for path 'roms/openbios'
Submodule 'roms/openhackware' (https://git.qemu.org/git/openhackware.git) registered for path 'roms/openhackware'
Submodule 'roms/opensbi' (https://git.qemu.org/git/opensbi.git) registered for path 'roms/opensbi'
Submodule 'roms/qemu-palcode' (https://git.qemu.org/git/qemu-palcode.git) registered for path 'roms/qemu-palcode'
Submodule 'roms/seabios' (https://git.qemu.org/git/seabios.git/) registered for path 'roms/seabios'
Submodule 'roms/seabios-hppa' (https://git.qemu.org/git/seabios-hppa.git) registered for path 'roms/seabios-hppa'
Submodule 'roms/sgabios' (https://git.qemu.org/git/sgabios.git) registered for path 'roms/sgabios'
Submodule 'roms/skiboot' (https://git.qemu.org/git/skiboot.git) registered for path 'roms/skiboot'
Submodule 'roms/u-boot' (https://git.qemu.org/git/u-boot.git) registered for path 'roms/u-boot'
Submodule 'roms/u-boot-sam460ex' (https://git.qemu.org/git/u-boot-sam460ex.git) registered for path 'roms/u-boot-sam460ex' Submodule 'slirp' (https://git.qemu.org/git/libslirp.git) registered for path 'slirp'
Submodule 'tests/fp/berkeley-softfloat-3' (https://git.qemu.org/git/berkeley-softfloat-3.git) registered for path 'tests/fp/berkeley-softfloat-3' Submodule 'tests/fp/berkeley-testfloat-3' (https://git.qemu.org/git/berkeley-testfloat-3.git) registered for path 'tests/fp/berkeley-testfloat-3' Submodule 'ui/keycodemapdb' (https://git.qemu.org/git/keycodemapdb.git) registered for path 'ui/keycodemapdb'
Cloning into 'capstone'...
Submodule path 'capstone': checked out '22ead3e0bfdb87516656453336160e0a37b066bf'
Cloning into 'dtc'...
Submodule path 'dtc': checked out '88f18909db731a627456f26d779445f84e449536'
Cloning into 'roms/QemuMacDrivers'...
Submodule path 'roms/QemuMacDrivers': checked out '90c488d5f4a407342247b9ea869df1c2d9c8e266'
Cloning into 'roms/SLOF'...
Submodule path 'roms/SLOF': checked out 'ba1ab360eebe6338bb8d7d83a9220ccf7e213af3'
Cloning into 'roms/edk2'...
Submodule path 'roms/edk2': checked out '20d2e5a125e34fc8501026613a71549b2a1a3e54'
Submodule 'SoftFloat' (https://github.com/ucb-bar/berkeley-softfloat-3.git) registered for path 'ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3' Submodule 'CryptoPkg/Library/OpensslLib/openssl' (https://github.com/openssl/openssl) registered for path 'CryptoPkg/Library/OpensslLib/openssl' Cloning into 'ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3'...
Submodule path 'roms/edk2/ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3': checked out 'b64af41c3276f97f0e181920400ee056b9c88037' Cloning into 'CryptoPkg/Library/OpensslLib/openssl'...
Submodule path 'roms/edk2/CryptoPkg/Library/OpensslLib/openssl': checked out '50eaac9f3337667259de725451f201e784599687' Submodule 'boringssl' (https://boringssl.googlesource.com/boringssl) registered for path 'boringssl'
Submodule 'krb5' (https://github.com/krb5/krb5) registered for path 'krb5'
Submodule 'pyca.cryptography' (https://github.com/pyca/cryptography.git) registered for path 'pyca-cryptography'
Cloning into 'boringssl'...
Submodule path 'roms/edk2/CryptoPkg/Library/OpensslLib/openssl/boringssl': checked out '2070f8ad9151dc8f3a73bffaa146b5e6937a583f' Cloning into 'krb5'...
Submodule path 'roms/edk2/CryptoPkg/Library/OpensslLib/openssl/krb5': checked out 'b9ad6c49505c96a088326b62a52568e3484f2168' Cloning into 'pyca-cryptography'...
Submodule path 'roms/edk2/CryptoPkg/Library/OpensslLib/openssl/pyca-cryptography': checked out '09403100de2f6f1cdd0d484dcb8e620f1c335c8f' Cloning into 'roms/ipxe'...
Submodule path 'roms/ipxe': checked out 'de4565cbe76ea9f7913a01f331be3ee901bb6e17'
Cloning into 'roms/openbios'...
Submodule path 'roms/openbios': checked out 'c79e0ecb84f4f1ee3f73f521622e264edd1bf174'
Cloning into 'roms/openhackware'...
Submodule path 'roms/openhackware': checked out 'c559da7c8eec5e45ef1f67978827af6f0b9546f5'
Cloning into 'roms/opensbi'...
Submodule path 'roms/opensbi': checked out 'ce228ee0919deb9957192d723eecc8aaae2697c6'
Cloning into 'roms/qemu-palcode'...
Submodule path 'roms/qemu-palcode': checked out 'bf0e13698872450164fa7040da36a95d2d4b326f'
Cloning into 'roms/seabios'...
Submodule path 'roms/seabios': checked out 'a5cab58e9a3fb6e168aba919c5669bea406573b4'
Cloning into 'roms/seabios-hppa'...
Submodule path 'roms/seabios-hppa': checked out '0f4fe84658165e96ce35870fd19fc634e182e77b'
Cloning into 'roms/sgabios'...
Submodule path 'roms/sgabios': checked out 'cbaee52287e5f32373181cff50a00b6c4ac9015a'
Cloning into 'roms/skiboot'...
Submodule path 'roms/skiboot': checked out '261ca8e779e5138869a45f174caa49be6a274501'
Cloning into 'roms/u-boot'...
Submodule path 'roms/u-boot': checked out 'd3689267f92c5956e09cc7d1baa4700141662bff'
Cloning into 'roms/u-boot-sam460ex'...
Submodule path 'roms/u-boot-sam460ex': checked out '60b3916f33e617a815973c5a6df77055b2e3a588'
Cloning into 'slirp'...
Submodule path 'slirp': checked out 'f0da6726207b740f6101028b2992f918477a4b08'
Cloning into 'tests/fp/berkeley-softfloat-3'...
Submodule path 'tests/fp/berkeley-softfloat-3': checked out 'b64af41c3276f97f0e181920400ee056b9c88037'
Cloning into 'tests/fp/berkeley-testfloat-3'...
Submodule path 'tests/fp/berkeley-testfloat-3': checked out '5a59dcec19327396a011a17fd924aed4fec416b3'
Cloning into 'ui/keycodemapdb'...
Submodule path 'ui/keycodemapdb': checked out '6b3d716e2b6472eb7189d3220552280ef3d832ce'
Switched to a new branch 'test'
4618434 include/exec/cpu-defs.h: fix typo
d260302 include/exec: wrap cpu_ldst.h in CONFIG_TCG
4a08e81 accel/stubs: reduce headers from tcg-stub
dc047a8 tests/plugin: add hotpages plugin to breakdown memory access patterns
0031177 tests/plugin: add instruction execution breakdown
bd83073 plugin: add qemu_plugin_insn_disas helper
719f27a tests/plugin: add a hotblocks plugin
0c2193f tests/tcg: enable plugin testing
4fda032 tests/plugin: add sample plugins
fd7f586 linux-user: support -plugin option
b484c3f vl: support -plugin option
720fb2d plugin: add API symbols to qemu-plugins.symbols
75048c5 translator: inject instrumentation from plugins
90d92af target/openrisc: fetch code with translator_ld
bf3c443 target/xtensa: fetch code with translator_ld
1b3b92b target/sparc: fetch code with translator_ld
f41eb29 target/riscv: fetch code with translator_ld
35e338c target/alpha: fetch code with translator_ld
9014aab target/m68k: fetch code with translator_ld
604625d target/hppa: fetch code with translator_ld
f86b279 target/i386: fetch code with translator_ld
5bfcc20 target/sh4: fetch code with translator_ld
65656f9 target/ppc: fetch code with translator_ld
1338aac target/arm: fetch code with translator_ld
6ad7980 translator: add translator_ld{ub, sw, uw, l, q}
123a7b0 plugin-gen: add plugin_insn_append
2fc0fb1 cpu: hook plugin vcpu events
2ad986c *-user: plugin syscalls
12cf148 *-user: notify plugin of exit
5ef3c3d translate-all: notify plugin code of tb_flush
ceffbf5 plugins: implement helpers for resolving hwaddr
bfd0bef tcg: let plugins instrument virtual memory accesses
8c70962 atomic_template: add inline trace/plugin helpers
b6d0321 atomic_template: fix indentation in GEN_ATOMIC_HELPER
59e11a6 plugin-gen: add module for TCG-related code
b7ff8fb tcg: add tcg_gen_st_ptr
57dce44 cputlb: introduce get_page_addr_code_hostp
c21fd8d cputlb: document get_page_addr_code
0156ea7 queue: add QTAILQ_REMOVE_SEVERAL
98bb420 plugin: add implementation of the api
90dff04 plugin: add core code
dfc8157 plugin: add user-facing API
c508aec configure: add --enable-plugins (MOVE TO END)
efd9ca8 docs/devel: add plugins.rst design document
7e445c2 translate-all: use cpu_in_exclusive_work_context() in tb_flush
e3927dd cpu: introduce cpu_in_exclusive_context()
2c1c22b tcg/README: fix typo s/afterwise/afterwards/
0082b05 trace: add mmu_index to mem_info
43a9cd6 trace: expand mem_info:size_shift to 4 bits
92f8098 includes: remove stale [smp|max]_cpus externs
b12d00f target/arm: remove run time semihosting checks
3964cfe target/arm: handle A-profile A32 semihosting at translate time
354ccbf target/arm: handle A-profile T32 semihosting at translate time
c736511 target/arm: handle M-profile semihosting at translate time
=== OUTPUT BEGIN ===
1/54 Checking commit c736511afb73 (target/arm: handle M-profile semihosting at translate time) 2/54 Checking commit 354ccbf7836a (target/arm: handle A-profile T32 semihosting at translate time) 3/54 Checking commit 3964cfed151e (target/arm: handle A-profile A32 semihosting at translate time) 4/54 Checking commit b12d00f866ff (target/arm: remove run time semihosting checks) 5/54 Checking commit 92f80985c6b7 (includes: remove stale [smp|max]_cpus externs) 6/54 Checking commit 43a9cd64afe9 (trace: expand mem_info:size_shift to 4 bits) 7/54 Checking commit 0082b05e9d82 (trace: add mmu_index to mem_info)
ERROR: line over 90 characters
#24: FILE: accel/tcg/atomic_template.h:63:
+ uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false, ATOMIC_MMU_IDX); \
ERROR: line over 90 characters
#33: FILE: accel/tcg/atomic_template.h:71:
+ uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false, ATOMIC_MMU_IDX); \
ERROR: line over 90 characters
#40: FILE: accel/tcg/atomic_template.h:77:
+ uint16_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, true, ATOMIC_MMU_IDX); \
WARNING: line over 80 characters
#321: FILE: trace/mem.h:21:
+static uint16_t trace_mem_get_info(TCGMemOp op, unsigned int mmu_idx, bool store);
total: 3 errors, 1 warnings, 261 lines checked
Patch 7/54 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
8/54 Checking commit 2c1c22bc16e9 (tcg/README: fix typo s/afterwise/afterwards/) 9/54 Checking commit e3927dda7720 (cpu: introduce cpu_in_exclusive_context())
10/54 Checking commit 7e445c2738b4 (translate-all: use cpu_in_exclusive_work_context() in tb_flush) 11/54 Checking commit efd9ca87d2ad (docs/devel: add plugins.rst design document)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#24:
new file mode 100644
total: 0 errors, 1 warnings, 111 lines checked
Patch 11/54 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
12/54 Checking commit c508aec11118 (configure: add --enable-plugins (MOVE TO END)) 13/54 Checking commit dfc81576c19a (plugin: add user-facing API)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #15:
new file mode 100644
WARNING: architecture specific defines should be avoided #41: FILE: include/qemu/qemu-plugin.h:22:
+#if defined _WIN32 || defined __CYGWIN__
WARNING: architecture specific defines should be avoided #49: FILE: include/qemu/qemu-plugin.h:30:
+ #if __GNUC__ >= 4
total: 0 errors, 3 warnings, 351 lines checked
Patch 13/54 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
14/54 Checking commit 90dff041feaf (plugin: add core code)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #54:
new file mode 100644
ERROR: "foo * bar" should be "foo *bar"
#190: FILE: include/qemu/plugin.h:132:
+static inline struct qemu_plugin_insn * qemu_plugin_insn_alloc(void)
ERROR: named QLIST_HEAD should be typedefed separately #399: FILE: plugins/core.c:37:
+QLIST_HEAD(qemu_plugin_cb_head, qemu_plugin_cb);
WARNING: line over 80 characters
#618: FILE: plugins/core.c:256:
+ cbs = g_array_sized_new(false, false, sizeof(struct qemu_plugin_dyn_cb), 1);
WARNING: Block comments use a leading /* on a separate line #909: FILE: plugins/loader.c:42:
+ { /* end of list */ }
ERROR: externs should be avoided in .c files
#915: FILE: plugins/loader.c:48:
+extern struct qemu_plugin_state plugin;
total: 3 errors, 3 warnings, 1261 lines checked
Patch 14/54 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
15/54 Checking commit 98bb4205f8d1 (plugin: add implementation of the api)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #22:
new file mode 100644
ERROR: if this code is redundant consider removing it #282: FILE: plugins/api.c:256:
+#if 0 /* XXX FIXME should be SOFTMMU */
ERROR: "foo * bar" should be "foo *bar"
#303: FILE: plugins/api.c:277:
+static MachineState * get_ms(void)
total: 2 errors, 1 warnings, 303 lines checked
Patch 15/54 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
16/54 Checking commit 0156ea779e67 (queue: add QTAILQ_REMOVE_SEVERAL)
WARNING: Block comments use a leading /* on a separate line #31: FILE: include/qemu/queue.h:433:
+ } while (/*CONSTCOND*/0)
total: 0 errors, 1 warnings, 16 lines checked
Patch 16/54 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
17/54 Checking commit c21fd8dfb8e0 (cputlb: document get_page_addr_code) 18/54 Checking commit 57dce445a292 (cputlb: introduce get_page_addr_code_hostp) 19/54 Checking commit b7ff8fb737a6 (tcg: add tcg_gen_st_ptr)
20/54 Checking commit 59e11a6c6781 (plugin-gen: add module for TCG-related code)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #48:
new file mode 100644
ERROR: if this code is redundant consider removing it #420: FILE: accel/tcg/plugin-gen.c:368:
+#if 0 /* XXX: no longer needed? */
total: 1 errors, 1 warnings, 1168 lines checked
Patch 20/54 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
21/54 Checking commit b6d032138a56 (atomic_template: fix indentation in GEN_ATOMIC_HELPER) 22/54 Checking commit 8c70962547d5 (atomic_template: add inline trace/plugin helpers)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #15:
new file mode 100644
total: 0 errors, 1 warnings, 296 lines checked
Patch 22/54 has style problems, please review. If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
23/54 Checking commit bfd0bef6abd9 (tcg: let plugins instrument virtual memory accesses)
WARNING: line over 80 characters
#171: FILE: include/exec/cpu_ldst_template.h:91:
+ uint16_t meminfo = trace_mem_build_info(SHIFT, false, MO_TE, false, mmu_idx);
total: 0 errors, 1 warnings, 372 lines checked
Patch 23/54 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
24/54 Checking commit ceffbf57661b (plugins: implement helpers for resolving hwaddr) 25/54 Checking commit 5ef3c3d45dd0 (translate-all: notify plugin code of tb_flush) 26/54 Checking commit 12cf1480ae24 (*-user: notify plugin of exit) 27/54 Checking commit 2ad986cc69bd (*-user: plugin syscalls)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #93:
new file mode 100644
total: 0 errors, 1 warnings, 127 lines checked
Patch 27/54 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
28/54 Checking commit 2fc0fb11c7c5 (cpu: hook plugin vcpu events) 29/54 Checking commit 123a7b0c3078 (plugin-gen: add plugin_insn_append) 30/54 Checking commit 6ad7980f6247 (translator: add translator_ld{ub, sw, uw, l, q})
ERROR: Macros with multiple statements should be enclosed in a do - while loop #76: FILE: include/exec/translator.h:161:
+#define DO_LOAD(type, name, shift) \ + set_helper_retaddr(1); \ + ret = name ## _p(g2h(pc)); \
+ clear_helper_retaddr();
WARNING: Block comments use a leading /* on a separate line #109: FILE: include/exec/translator.h:194:
+GEN_TRANSLATOR_LD(translator_ldub, ldb, uint8_t, 1, /* no swap needed */)
total: 1 errors, 1 warnings, 116 lines checked
Patch 30/54 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
31/54 Checking commit 1338aac82722 (target/arm: fetch code with translator_ld) 32/54 Checking commit 65656f9c3eea (target/ppc: fetch code with translator_ld) 33/54 Checking commit 5bfcc20d11c6 (target/sh4: fetch code with translator_ld) 34/54 Checking commit f86b27916216 (target/i386: fetch code with translator_ld) 35/54 Checking commit 604625d4780e (target/hppa: fetch code with translator_ld) 36/54 Checking commit 9014aab24680 (target/m68k: fetch code with translator_ld) 37/54 Checking commit 35e338c60b8f (target/alpha: fetch code with translator_ld) 38/54 Checking commit f41eb298b626 (target/riscv: fetch code with translator_ld) 39/54 Checking commit 1b3b92b10053 (target/sparc: fetch code with translator_ld) 40/54 Checking commit bf3c443ec239 (target/xtensa: fetch code with translator_ld) 41/54 Checking commit 90d92af84114 (target/openrisc: fetch code with translator_ld) 42/54 Checking commit 75048c56cd83 (translator: inject instrumentation from plugins) 43/54 Checking commit 720fb2d03f34 (plugin: add API symbols to qemu-plugins.symbols)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #120:
new file mode 100644
total: 0 errors, 1 warnings, 151 lines checked
Patch 43/54 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
44/54 Checking commit b484c3fd133c (vl: support -plugin option) 45/54 Checking commit fd7f58630fad (linux-user: support -plugin option) 46/54 Checking commit 4fda03223154 (tests/plugin: add sample plugins)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #36:
new file mode 100644
total: 0 errors, 1 warnings, 296 lines checked
Patch 46/54 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
47/54 Checking commit 0c2193fd7aa2 (tests/tcg: enable plugin testing) 48/54 Checking commit 719f27a8e85d (tests/plugin: add a hotblocks plugin)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #32:
new file mode 100644
total: 0 errors, 1 warnings, 153 lines checked
Patch 48/54 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
49/54 Checking commit bd8307360460 (plugin: add qemu_plugin_insn_disas helper)
ERROR: "foo * bar" should be "foo *bar"
#74: FILE: disas.c:530:
+char * plugin_disas(CPUState *cpu, uint64_t addr, size_t size)
ERROR: "foo * bar" should be "foo *bar"
#136: FILE: include/disas/disas.h:16:
+char * plugin_disas(CPUState *cpu, uint64_t addr, size_t size);
ERROR: "foo * bar" should be "foo *bar"
#155: FILE: include/qemu/qemu-plugin.h:334:
+char * qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn);
total: 3 errors, 0 warnings, 158 lines checked
Patch 49/54 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
50/54 Checking commit 0031177b24bf (tests/plugin: add instruction execution breakdown)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #26:
new file mode 100644
ERROR: space required after that ',' (ctx:VxV)
#99: FILE: tests/plugin/howvec.c:69:
+ { " Add/Sub (imm,tags)","asit", 0x1f800000, 0x11800000, COUNT_CLASS},
^
ERROR: space required after that ',' (ctx:VxV)
#122: FILE: tests/plugin/howvec.c:92:
+ { " AdvSimd ldstmult++","advlsmp",0xbfb00000, 0x0c800000, COUNT_CLASS},
^
ERROR: space required after that ',' (ctx:VxV)
#122: FILE: tests/plugin/howvec.c:92:
+ { " AdvSimd ldstmult++","advlsmp",0xbfb00000, 0x0c800000, COUNT_CLASS},
^
ERROR: space required after that ',' (ctx:VxV)
#124: FILE: tests/plugin/howvec.c:94:
+ { " AdvSimd ldst++", "advlssp",0xbf800000, 0x0d800000, COUNT_CLASS},
^
ERROR: space required after that ',' (ctx:VxV)
#128: FILE: tests/plugin/howvec.c:98:
+ { " ldst noalloc pair", "ldstnap",0x3b800000, 0x28000000, COUNT_CLASS},
^
ERROR: space required after that ',' (ctx:VxV)
#132: FILE: tests/plugin/howvec.c:102:
+ { " ldst reg (reg off)","ldstro", 0x3b200b00, 0x38200800, COUNT_CLASS},
^
WARNING: line over 80 characters
#167: FILE: tests/plugin/howvec.c:137:
+ g_string_append_printf(report, "Class: %-24s\tcounted individually\n",
ERROR: space required after that ',' (ctx:VxV)
#183: FILE: tests/plugin/howvec.c:153:
+ g_string_append_printf(report,"Individual Instructions:\n");
^WARNING: line over 80 characters
#189: FILE: tests/plugin/howvec.c:159:
+ g_string_append_printf(report, "Instr: %-24s\t(%ld hits)\t(op=%#08x/%s)\n",
ERROR: "foo * bar" should be "foo *bar"
#214: FILE: tests/plugin/howvec.c:184:
+static uint64_t * find_counter(struct qemu_plugin_insn *insn)
WARNING: line over 80 characters
#246: FILE: tests/plugin/howvec.c:216:
+ GUINT_TO_POINTER(opcode));
total: 8 errors, 4 warnings, 308 lines checked
Patch 50/54 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
51/54 Checking commit dc047a82f004 (tests/plugin: add hotpages plugin to breakdown memory access patterns)
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#26:
new file mode 100644
total: 0 errors, 1 warnings, 186 lines checked
Patch 51/54 has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
52/54 Checking commit 4a08e81629be (accel/stubs: reduce headers from tcg-stub) 53/54 Checking commit d260302d62f5 (include/exec: wrap cpu_ldst.h in CONFIG_TCG) 54/54 Checking commit 4618434e2366 (include/exec/cpu-defs.h: fix typo) === OUTPUT END ===
Test command exited with code: 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Quoted 30 lines · Alex Bennée
Hi,
This is the latest iteration of the plugins series. The main changes from the last version are:
- dropped passing of haddr to plugins
This makes the code for handling the plugins less invasive in the softmmu path at the cost of offloading processing to the plugin if it wants the value. We rely on the fact that the TLB is per vCPU so a helper can just trigger a re-query of the TLB to get the final address.
Part of that change involved embedding the MMU index in the meminfo field for tracing. I see there are some other patches on the list for messing with TCGMemOp so there might be a clash coming up.
-
translator_ldgoes direct to softmmu/user functionsI also mark the [SOFTMMU_]CODE_ACCESS helpers as deprecated. There is more work to be done to clean up all the current uses of code access helpers but ideally the only thing that should be peaking at code is the translator loop itself. However a bunch of helpers have taken to using code loading functions to peak at the instruction just executed to figure out what to do. Once those have been fixed then we can remove those helpers.
Other more minor fixes can be found documented bellow the --- in the individual patches.
Quoted 6 lines
This series also includes the semihosting patches as they are a pre-requisite for the
translator_ldpatches for ARM.Once the tree opens up for development again I hope to get the semihosting and trivial clean-up patches merged quickly so the patch count for the plugins patches proper can be reduced a bit.
Next time, please explain briefly what TCG plugins are about right in your cover letter. I had to go hunting for this. Found "[PATCH v4 11/54] docs/devel: add plugins.rst design document".
Please advise why TCG plugins don't undermine the GPL. Any proposal to add a plugin interface needs to do that.
Quoted 35 lines · Markus Armbruster
Quoted 33 lines · Alex Bennée
Hi,
This is the latest iteration of the plugins series. The main changes from the last version are:
- dropped passing of haddr to plugins
This makes the code for handling the plugins less invasive in the softmmu path at the cost of offloading processing to the plugin if it wants the value. We rely on the fact that the TLB is per vCPU so a helper can just trigger a re-query of the TLB to get the final address.
Part of that change involved embedding the MMU index in the meminfo field for tracing. I see there are some other patches on the list for messing with TCGMemOp so there might be a clash coming up.
-
translator_ldgoes direct to softmmu/user functionsI also mark the [SOFTMMU_]CODE_ACCESS helpers as deprecated. There is more work to be done to clean up all the current uses of code access helpers but ideally the only thing that should be peaking at code is the translator loop itself. However a bunch of helpers have taken to using code loading functions to peak at the instruction just executed to figure out what to do. Once those have been fixed then we can remove those helpers.
Other more minor fixes can be found documented bellow the --- in the individual patches.
This series also includes the semihosting patches as they are a pre-requisite for the
translator_ldpatches for ARM.
Quoted 7 lines
Quoted 3 lines
Once the tree opens up for development again I hope to get the semihosting and trivial clean-up patches merged quickly so the patch count for the plugins patches proper can be reduced a bit.
Next time, please explain briefly what TCG plugins are about right in your cover letter. I had to go hunting for this. Found "[PATCH v4 11/54] docs/devel: add
plugins.rstdesign document".
I'll provide a better overview in my next cover letter.
Quoted 2 lines
Please advise why TCG plugins don't undermine the GPL. Any proposal to add a plugin interface needs to do that.
I'm not sure what we can say about this apart from "ask your lawyer". I'm certainly not proposing we add any sort of language about what should and shouldn't be allowed to use the plugin interface. I find it hard to see how anyone could argue code written to interface with the plugin API couldn't be considered a derived work.
There are two use cases I have in mind:
The first is FLOSS developers writing interesting tools that can take advantage of QEMU's control of the system to do experiments that are tricky with other setups (Valgrind is limited to same-arch, Dynamo/Pin are user-space only). I want these experiments to be easy to do without having to keep hacking and re-hacking QEMU's core code. I would hope QEMU developers would up-stream theirs into the QEMU source tree but I can imagine academics will have open source code that will only ever sit in their paper's repository.
The other is users who currently maintain hacked up internal copies of QEMU as a test bed for whatever piece of silicon they are brewing behind closed doors. This code would never be distributed (hence never be a GPL issue) and is generally kept private because it's IP sensitive (e.g: experimenting with different cache models). If we can provide an interface that allows them to keep their experiments private and separate from changes to the core code then maybe apart from making their lives a bit easier we will see some non-IP sensitive contributions come back to the upstream. I live in hope ;-)
--
Alex Bennée
Quoted 10 lines · Alex Bennée
Quoted 2 lines · Markus Armbruster
Please advise why TCG plugins don't undermine the GPL. Any proposal to add a plugin interface needs to do that.
I'm not sure what we can say about this apart from "ask your lawyer". I'm certainly not proposing we add any sort of language about what should and shouldn't be allowed to use the plugin interface. I find it hard to see how anyone could argue code written to interface with the plugin API couldn't be considered a derived work.
I am not a lawyer, but I would not have expected software merely using a well-defined API to be considered a derivative work of the software defining it. Unless, of course, it is a derivative work of another plugin using the same interface in a way that is not necessitated by the structure of the API.
What's your reasoning for why it would be a derivative work? Is your belief that the plugin API is complex enough that anything using it has to be a derivative work, or something else?
That said, I'm not sure I understand in what way adding a plugin interface would undermine the GPL, so maybe I'm missing the point.
-Aaron
Quoted 18 lines · Aaron Lindsay OS
Quoted 10 lines · Alex Bennée
Quoted 2 lines · Markus Armbruster
Please advise why TCG plugins don't undermine the GPL. Any proposal to add a plugin interface needs to do that.
I'm not sure what we can say about this apart from "ask your lawyer". I'm certainly not proposing we add any sort of language about what should and shouldn't be allowed to use the plugin interface. I find it hard to see how anyone could argue code written to interface with the plugin API couldn't be considered a derived work.
I am not a lawyer, but I would not have expected software merely using a well-defined API to be considered a derivative work of the software defining it. Unless, of course, it is a derivative work of another plugin using the same interface in a way that is not necessitated by the structure of the API.
Quoted 3 lines
What's your reasoning for why it would be a derivative work? Is your belief that the plugin API is complex enough that anything using it has to be a derivative work, or something else?
Well it's derivative if the code couldn't have been written on it's own
- so is "derived" from a design in GPL code. The endless arguments about derivation w.r.t the nvidia kernel drivers hinge on the fact the drivers are multi-OS and shimmed to into the kernel - not explicitly written for Linux. However no one really knows where the line is because it's the courts that will ultimately decide.
OTOH the kernel has explicit language about the syscall layer:
NOTE! This copyright does *not* cover user programs that use kernel
services by normal system calls - this is merely considered normal use of the kernel, and does *not* fall under the heading of "derived work".
Anyway I don't really care either way and don't intend to become an arm chair lawyer as the arguments can become rather circular and tedious. We might want to make an explicit statement in the QEMU tree about reserving the right to change the API in the future and the best way to keep plugins in sync is to have them in the upstream source tree.
Quoted 2 lines
That said, I'm not sure I understand in what way adding a plugin interface would undermine the GPL, so maybe I'm missing the point.
I suspect there is a similar concern as GCC had when they were asked to expose their IR to tools. They were explicitly concerned that people would ship proprietary compilers consisting of a GPL GCC shell with all the clever optimisations in proprietary plugins that glued the front and backends together. I don't think this is a problem for QEMU because at the moment plugins can't be used to improve code generation - just observe it. You could theoretically implement device models this way but there are definitely easier more efficient ways of doing it - as shown by other 3rd party forks of QEMU.
As I mentioned in the other message I'm sure there will be proprietary
- or rather secret behind closed doors plugins but I don't view them any differently to all the various secret and external forks of the main QEMU source.
Quoted 2 lines
-Aaron
--
Alex Bennée
Quoted 6 lines · Alex Bennée
Quoted 2 lines · Markus Armbruster
Please advise why TCG plugins don't undermine the GPL. Any proposal to add a plugin interface needs to do that.
I'm not sure what we can say about this apart from "ask your lawyer".
I suspect the underlying confusion here is "the term 'plugin' has a very wide scope and you and Markus are probably not on the same page about what this API/ABI is actually doing".
Specifically, this is not the 'plugin ABI that lets you write device models out of tree' that is sometimes mooted, and the ABI does not (unless it's changed since I last looked) expose arbitrary bits of QEMU internals to the plugin or let plugins make calls to random QEMU functions. It's a very limited scope ABI that allows QEMU users to write code that can do useful introspection on what running guest code is doing without having to modify QEMU itself in non-sustainable non-upstreamable ways.
[If it doesn't have that kind of protection against misuse then we should add it.]
More generally, your cover letter really needs to be much more descriptive about what we're trying to do here, and what the purpose, limitations, etc are here. If you say "plugins" without giving any detail then you're going to trigger a lot of (reasonable) reactions from people who associate that word with a much more generalized "provide arbitrary bits of QEMU functionality as 3rd-party blobs" concept...
thanks
-- PMM
[Qemu-devel] TCG plugins and the GPL (was: [PATCH v4 00/54] plugins for TCG)
In reply to Alex BennéeQuoted 1 line · Alex Bennée
Markus Armbruster <[email protected]> writes:
[...]
Quoted 4 lines
Quoted 2 lines
Please advise why TCG plugins don't undermine the GPL. Any proposal to add a plugin interface needs to do that.
I'm not sure what we can say about this apart from "ask your lawyer".
I'm not asking for a legal argument, I'm asking for a pragmatic one.
Quoted 4 lines
I'm certainly not proposing we add any sort of language about what should and shouldn't be allowed to use the plugin interface. I find it hard to see how anyone could argue code written to interface with the plugin API couldn't be considered a derived work.
What makes that so? Is writing a plugin without linking with QEMU code impractical?
Quoted 10 lines
There are two use cases I have in mind:
The first is FLOSS developers writing interesting tools that can take advantage of QEMU's control of the system to do experiments that are tricky with other setups (Valgrind is limited to same-arch, Dynamo/Pin are user-space only). I want these experiments to be easy to do without having to keep hacking and re-hacking QEMU's core code. I would hope QEMU developers would up-stream theirs into the QEMU source tree but I can imagine academics will have open source code that will only ever sit in their paper's repository.
GPL'ed code that's not for upstream is 100% legitimate.
Quoted 4 lines
The other is users who currently maintain hacked up internal copies of QEMU as a test bed for whatever piece of silicon they are brewing behind closed doors. This code would never be distributed (hence never be a GPL issue)
Correct. We can't force anybody to distribute, and that's only proper.
Quoted 6 lines
and is generally kept private because it's IP sensitive
(e.g: experimenting with different cache models). If we can provide an interface that allows them to keep their experiments private and separate from changes to the core code then maybe apart from making their lives a bit easier we will see some non-IP sensitive contributions come back to the upstream. I live in hope ;-)
I'm concerned about a third case: imlementing stuff as a plugin so you can distribute it with a GPL-incompatible license. Particularly pernicious when that stuff could be useful upstream.
Are there any technical difficulties that could make distributing a plugins in binary form impractical?
Re: [Qemu-devel] TCG plugins and the GPL (was: [PATCH v4 00/54] plugins for TCG)
Quoted 11 lines · Markus Armbruster
Quoted 1 line · Alex Bennée
Markus Armbruster <[email protected]> writes:
[...]
Quoted 4 lines
Quoted 2 lines
Please advise why TCG plugins don't undermine the GPL. Any proposal to add a plugin interface needs to do that.
I'm not sure what we can say about this apart from "ask your lawyer".
I'm not asking for a legal argument, I'm asking for a pragmatic one.
Quoted 7 lines
Quoted 4 lines
I'm certainly not proposing we add any sort of language about what should and shouldn't be allowed to use the plugin interface. I find it hard to see how anyone could argue code written to interface with the plugin API couldn't be considered a derived work.
What makes that so? Is writing a plugin without linking with QEMU code impractical?
The way a plugin works is by linking. The plugin itself would be useless unless combined with the QEMU code to do its thing. It is a more intimate binding than an IPC interface using some sort of protocol. The argument goes that pretty much any kernel module is derived code - but again it has never really been litigated in the courts which would be the people to set the precedent.
Quoted 28 lines
Quoted 11 lines
There are two use cases I have in mind:
The first is FLOSS developers writing interesting tools that can take advantage of QEMU's control of the system to do experiments that are tricky with other setups (Valgrind is limited to same-arch, Dynamo/Pin are user-space only). I want these experiments to be easy to do without having to keep hacking and re-hacking QEMU's core code. I would hope QEMU developers would up-stream theirs into the QEMU source tree but I can imagine academics will have open source code that will only ever sit in their paper's repository.
GPL'ed code that's not for upstream is 100% legitimate.
Quoted 4 lines
The other is users who currently maintain hacked up internal copies of QEMU as a test bed for whatever piece of silicon they are brewing behind closed doors. This code would never be distributed (hence never be a GPL issue)
Correct. We can't force anybody to distribute, and that's only proper.
Quoted 6 lines
and is generally kept private because it's IP sensitive
(e.g: experimenting with different cache models). If we can provide an interface that allows them to keep their experiments private and separate from changes to the core code then maybe apart from making their lives a bit easier we will see some non-IP sensitive contributions come back to the upstream. I live in hope ;-)
Quoted 3 lines
I'm concerned about a third case: imlementing stuff as a plugin so you can distribute it with a GPL-incompatible license. Particularly pernicious when that stuff could be useful upstream.
If someone were to do that it would depend on a copyright holder (i.e. one of us) being willing to challenge that licensing. AIUI GCC used additional language in the runtime exception clause:
https://www.gnu.org/licenses/gcc-exception-3.1.html
which only allows use of the runtime exception if the code has gone through GPL compatible code:
A Compilation Process is "Eligible" if it is done using GCC, alone or with other GPL-compatible software, or if it is done without using any work based on GCC. For example, using non-GPL-compatible Software to optimize any GCC intermediate representations would not qualify as an Eligible Compilation Process.
Quoted 2 lines
Are there any technical difficulties that could make distributing a plugins in binary form impractical?
Well the first thing will be we are not intending to offer a guaranteed ABI. While we don't want to be changing it at a whim there shouldn't be an expectation that the plugin interface will maintain backwards compatibility (unlike the command line interface ;-). There should be an expectation that plugins will likely need to be rebuilt against the current source tree from time to time.
We could implement a more technical measure analogous to the kernels module signing that would require the plugin to be rebuilt with reference to the current QEMU source tree although that will be a pain even for internally distributed blobs. I'm loathed to implement such a system from v1 though given the problem of publicly distributed binary blobs is currently only a theoretical problem.
--
Alex Bennée
Re: [Qemu-devel] TCG plugins and the GPL (was: [PATCH v4 00/54] plugins for TCG)
Quoted 7 lines · Alex Bennée
Well the first thing will be we are not intending to offer a guaranteed ABI. While we don't want to be changing it at a whim there shouldn't be an expectation that the plugin interface will maintain backwards compatibility (unlike the command line interface ;-). There should be an expectation that plugins will likely need to be rebuilt against the current source tree from time to time.
Wait, what? From my perspective the whole point of the plugin interface is that it should be stable, in that at least there's a good chance that a plugin you built will work against multiple versions of QEMU, and if it doesn't then it should fail with a reasonable error message telling you to update. I'm not sure we should be landing the plugins infrastructure if we don't have that much stability.
thanks
-- PMM
Re: [Qemu-devel] TCG plugins and the GPL (was: [PATCH v4 00/54] plugins for TCG)
Quoted 9 lines · Peter Maydell
Quoted 7 lines · Alex Bennée
Well the first thing will be we are not intending to offer a guaranteed ABI. While we don't want to be changing it at a whim there shouldn't be an expectation that the plugin interface will maintain backwards compatibility (unlike the command line interface ;-). There should be an expectation that plugins will likely need to be rebuilt against the current source tree from time to time.
Quoted 7 lines
Wait, what? From my perspective the whole point of the plugin interface is that it should be stable, in that at least there's a good chance that a plugin you built will work against multiple versions of QEMU, and if it doesn't then it should fail with a reasonable error message telling you to update. I'm not sure we should be landing the plugins infrastructure if we don't have that much stability.
There is a big fat blurry line between "set in stone" and "not requiring you to re-engineer the plugin every QEMU release". I'm saying we should reserve the right to extend and change the plugin API as required but the expectation would be the plugins will continue to work the same way but maybe with tweaks to the API hooks to support additional features.
It's also a pretty young interface so I would expect some evolution once it is released into the field.
One problem with the anti-license circumvention measures being suggested is it will mean having to recompile plugins for any given release. This isn't a problem for plugins we write but it does add an extra step for out of tree plugins. Maybe being forced to re-compile (but not change the source) is a hurdle we are willing to accept?
--
Alex Bennée
Re: [Qemu-devel] TCG plugins and the GPL (was: [PATCH v4 00/54] plugins for TCG)
Quoted 26 lines · Alex Bennée
Quoted 9 lines · Peter Maydell
Quoted 7 lines · Alex Bennée
Well the first thing will be we are not intending to offer a guaranteed ABI. While we don't want to be changing it at a whim there shouldn't be an expectation that the plugin interface will maintain backwards compatibility (unlike the command line interface ;-). There should be an expectation that plugins will likely need to be rebuilt against the current source tree from time to time.
Quoted 7 lines
Wait, what? From my perspective the whole point of the plugin interface is that it should be stable, in that at least there's a good chance that a plugin you built will work against multiple versions of QEMU, and if it doesn't then it should fail with a reasonable error message telling you to update. I'm not sure we should be landing the plugins infrastructure if we don't have that much stability.
There is a big fat blurry line between "set in stone" and "not requiring you to re-engineer the plugin every QEMU release". I'm saying we should reserve the right to extend and change the plugin API as required but the expectation would be the plugins will continue to work the same way but maybe with tweaks to the API hooks to support additional features.
Quoted 8 lines
It's also a pretty young interface so I would expect some evolution once it is released into the field.
One problem with the anti-license circumvention measures being suggested is it will mean having to recompile plugins for any given release. This isn't a problem for plugins we write but it does add an extra step for out of tree plugins. Maybe being forced to re-compile (but not change the source) is a hurdle we are willing to accept?
I can understand & totally support not wishing to break the compilation of plugins for every release, by having a reasonably stable API.
I think forcing recompile for each release is reasonable protection to make it less atttractive to create license violating closed source plugins.
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [Qemu-devel] TCG plugins and the GPL (was: [PATCH v4 00/54] plugins for TCG)
Quoted 3 lines · Daniel P. Berrangé
I think forcing recompile for each release is reasonable protection to make it less atttractive to create license violating closed source plugins.
I'm just not sure that a plugin that, for instance, does "whenever the guest makes a memory access print the address and data", is in any reasonable sense a derived work of QEMU that it makes sense to extend the GPL to. We're providing a convenient introspection interface here, similar to but different from the way gdbstub lets you introspect guest binary behaviour, not an arbitrary mechanism for extending QEMU itself.
thanks
-- PMM
Re: [Qemu-devel] TCG plugins and the GPL (was: [PATCH v4 00/54] plugins for TCG)
In reply to Alex BennéeQuoted 9 lines · Alex Bennée
Quoted 7 lines · Peter Maydell
Wait, what? From my perspective the whole point of the plugin interface is that it should be stable, in that at least there's a good chance that a plugin you built will work against multiple versions of QEMU, and if it doesn't then it should fail with a reasonable error message telling you to update. I'm not sure we should be landing the plugins infrastructure if we don't have that much stability.
Quoted 8 lines
There is a big fat blurry line between "set in stone" and "not requiring you to re-engineer the plugin every QEMU release". I'm saying we should reserve the right to extend and change the plugin API as required but the expectation would be the plugins will continue to work the same way but maybe with tweaks to the API hooks to support additional features.
It's also a pretty young interface so I would expect some evolution once it is released into the field.
Sure. But I think we should document that we at least intend to have some approximation to a compatability/deprecation policy here, and some mechanisms for versioning so you get a helpful error rather than weird misbehaviour if your plugin is too old.
Quoted 2 lines
One problem with the anti-license circumvention measures being suggested is it will mean having to recompile plugins for any given release.
Why should we do this? I think this is making life hard for our users for no good reason. We *do* have this check for modules, because a module is just a random .so that can do anything in QEMU. I thought we had the TCG-plugin interface much more locked down than that?
thanks
-- PMM
Re: [Qemu-devel] TCG plugins and the GPL (was: [PATCH v4 00/54] plugins for TCG)
Quoted 24 lines · Peter Maydell
Quoted 9 lines · Alex Bennée
Quoted 7 lines · Peter Maydell
Wait, what? From my perspective the whole point of the plugin interface is that it should be stable, in that at least there's a good chance that a plugin you built will work against multiple versions of QEMU, and if it doesn't then it should fail with a reasonable error message telling you to update. I'm not sure we should be landing the plugins infrastructure if we don't have that much stability.
Quoted 8 lines
There is a big fat blurry line between "set in stone" and "not requiring you to re-engineer the plugin every QEMU release". I'm saying we should reserve the right to extend and change the plugin API as required but the expectation would be the plugins will continue to work the same way but maybe with tweaks to the API hooks to support additional features.
It's also a pretty young interface so I would expect some evolution once it is released into the field.
Sure. But I think we should document that we at least intend to have some approximation to a compatability/deprecation policy here, and some mechanisms for versioning so you get a helpful error rather than weird misbehaviour if your plugin is too old.
Quoted 8 lines
Quoted 2 lines
One problem with the anti-license circumvention measures being suggested is it will mean having to recompile plugins for any given release.
Why should we do this? I think this is making life hard for our users for no good reason. We *do* have this check for modules, because a module is just a random .so that can do anything in QEMU. I thought we had the TCG-plugin interface much more locked down than that?
It is, there are only a few set calls the plugin can make into QEMU, mostly to register callbacks to events. Currently it can examine the state of the system (again through the API) but can't change it's behaviour (although a register access interface has been requested although I'd initially intended to make it read only).
Quoted 3 lines
thanks
-- PMM
--
Alex Bennée
Re: [Qemu-devel] TCG plugins and the GPL (was: [PATCH v4 00/54] plugins for TCG)
In reply to Alex BennéeQuoted 22 lines · Alex Bennée
Quoted 11 lines · Markus Armbruster
Quoted 1 line · Alex Bennée
Markus Armbruster <[email protected]> writes:
[...]
Quoted 4 lines
Quoted 2 lines
Please advise why TCG plugins don't undermine the GPL. Any proposal to add a plugin interface needs to do that.
I'm not sure what we can say about this apart from "ask your lawyer".
I'm not asking for a legal argument, I'm asking for a pragmatic one.
Quoted 7 lines
Quoted 4 lines
I'm certainly not proposing we add any sort of language about what should and shouldn't be allowed to use the plugin interface. I find it hard to see how anyone could argue code written to interface with the plugin API couldn't be considered a derived work.
What makes that so? Is writing a plugin without linking with QEMU code impractical?
Quoted 6 lines
The way a plugin works is by linking. The plugin itself would be useless unless combined with the QEMU code to do its thing. It is a more intimate binding than an IPC interface using some sort of protocol. The argument goes that pretty much any kernel module is derived code - but again it has never really been litigated in the courts which would be the people to set the precedent.
Part of the problem with the kernel is the historical precedent they had set. The issue of GPL compliance only become prominent much later after (closed source) loadable modules were already widely in use. They tried to lock the door after the horse had already bolted by adding EXPORT_SYMBOL_GPL.
We can avoid this trapped by clearly documenting our license expectations from the very start. ie state that we consider any plugins to be derived works and to be bound by the terms of the GPL. This doesn't mean the plugins themselves have to be GPL, but they have to be under terms that allow relicensing to the GPL, in order to be license compatible.
We could even go as far as having the plugin registration API require that the plugin explicitly declare its license and we can log this license at time of loading. If people use a non-GPL compatible license it will be clearly visible as non-compatible, or if they lie and pretend to be GPL then they would be willfully violating.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
There are two use cases I have in mind:
The first is FLOSS developers writing interesting tools that can take advantage of QEMU's control of the system to do experiments that are tricky with other setups (Valgrind is limited to same-arch, Dynamo/Pin are user-space only). I want these experiments to be easy to do without having to keep hacking and re-hacking QEMU's core code. I would hope QEMU developers would up-stream theirs into the QEMU source tree but I can imagine academics will have open source code that will only ever sit in their paper's repository.
Quoted 1 line
Quoted 1 line
GPL'ed code that's not for upstream is 100% legitimate.
Yep, the code only has to be provided to the people who receive the plugin binary. Those people can't be prevented from redistributing it further though.
Quoted 18 lines
Quoted 10 lines
Quoted 4 lines
The other is users who currently maintain hacked up internal copies of QEMU as a test bed for whatever piece of silicon they are brewing behind closed doors. This code would never be distributed (hence never be a GPL issue)
Correct. We can't force anybody to distribute, and that's only proper.
Are there any technical difficulties that could make distributing a plugins in binary form impractical?
Well the first thing will be we are not intending to offer a guaranteed ABI. While we don't want to be changing it at a whim there shouldn't be an expectation that the plugin interface will maintain backwards compatibility (unlike the command line interface ;-). There should be an expectation that plugins will likely need to be rebuilt against the current source tree from time to time.
Quoted 6 lines
We could implement a more technical measure analogous to the kernels module signing that would require the plugin to be rebuilt with reference to the current QEMU source tree although that will be a pain even for internally distributed blobs. I'm loathed to implement such a system from v1 though given the problem of publicly distributed binary blobs is currently only a theoretical problem.
The problem with waiting for a problem to arise is that you have set a precedent that its ok. We are in a stronger enforcement position if we can set expectations accurately from day one, avoiding the trap the kernel had which needed to try to enforce after the fact.
So from that POV, I'd be strongly in favour of technical measures that force the plugin to be rebuilt against each new QEMU version.
This doesn't need to be module signing - it could be as simple as requiring the plugin to export a symbol "module_version" which must exactly match the QEMU version, or refuse to load it. If we want to be even more strict we could generate a random hash in each QEMU rebuild, which is the similar level of strictness to kernel signing
Regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed the asan build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
make docker-image-fedora V=1 NETWORK=1
time make docker-test-debug@fedora TARGET_LIST=x86_64-softmmu J=14 NETWORK=1 === TEST SCRIPT END ===
CC x86_64-softmmu/cpus.o
CC x86_64-softmmu/gdbstub.o
CC x86_64-softmmu/balloon.o
/tmp/qemu-test/src/disas.c:503:5: error: use of undeclared identifier 'csh'
csh handle;
^
/tmp/qemu-test/src/disas.c:504:5: error: use of undeclared identifier 'cs_insn'
cs_insn *insn;
^
/tmp/qemu-test/src/disas.c:504:14: error: use of undeclared identifier 'insn'; did you mean 'info'?
cs_insn *insn;
^~~~
info
/tmp/qemu-test/src/disas.c:500:46: note: 'info' declared here
bool plugin_cap_disas_insn(disassemble_info *info, uint64_t pc, size_t size)
^
/tmp/qemu-test/src/disas.c:509:9: error: implicit declaration of function 'cap_disas_start' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
if (cap_disas_start(info, &handle) != CS_ERR_OK) {
^
/tmp/qemu-test/src/disas.c:509:9: error: this function declaration is not a prototype [-Werror,-Wstrict-prototypes]
/tmp/qemu-test/src/disas.c:509:32: error: use of undeclared identifier 'handle'
if (cap_disas_start(info, &handle) != CS_ERR_OK) {
^
/tmp/qemu-test/src/disas.c:509:43: error: use of undeclared identifier 'CS_ERR_OK'
if (cap_disas_start(info, &handle) != CS_ERR_OK) {
^
/tmp/qemu-test/src/disas.c:512:5: error: use of undeclared identifier 'insn'
insn = cap_insn;
^
/tmp/qemu-test/src/disas.c:512:12: error: use of undeclared identifier 'cap_insn'
insn = cap_insn;
^
/tmp/qemu-test/src/disas.c:518:13: error: implicit declaration of function 'cs_disasm' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
count = cs_disasm(handle, cbuf, size, 0, 1, &insn);
^
/tmp/qemu-test/src/disas.c:518:13: error: this function declaration is not a prototype [-Werror,-Wstrict-prototypes]
/tmp/qemu-test/src/disas.c:518:23: error: use of undeclared identifier 'handle'
count = cs_disasm(handle, cbuf, size, 0, 1, &insn);
^
/tmp/qemu-test/src/disas.c:518:50: error: use of undeclared identifier 'insn'
count = cs_disasm(handle, cbuf, size, 0, 1, &insn);
^
/tmp/qemu-test/src/disas.c:521:37: error: use of undeclared identifier 'insn'
g_string_printf(s, "%s %s", insn->mnemonic, insn->op_str);
^
/tmp/qemu-test/src/disas.c:521:53: error: use of undeclared identifier 'insn'
g_string_printf(s, "%s %s", insn->mnemonic, insn->op_str);
^
/tmp/qemu-test/src/disas.c:526:5: error: implicit declaration of function 'cs_close' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
cs_close(&handle);
^
/tmp/qemu-test/src/disas.c:526:5: error: this function declaration is not a prototype [-Werror,-Wstrict-prototypes]
/tmp/qemu-test/src/disas.c:526:15: error: use of undeclared identifier 'handle'
cs_close(&handle);
^18 errors generated.
The full log is available at
http://patchew.org/logs/[email protected]/testing.asan/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]