From c5730ff194a6dfba47a200ab8ae2a6739a4465fb Mon Sep 17 00:00:00 2001 From: KONRAD Frederic Date: Fri, 2 Mar 2018 09:17:49 -0500 Subject: [PATCH] tcg: add options for enabling MTTCG We know there will be cases where MTTCG won't work until additional work is done in the front/back ends to support. It will however be useful to be able to turn it on. As a result MTTCG will default to off unless the combination is supported. However the user can turn it on for the sake of testing. Backports commit 8d4e9146b3568022ea5730d92841345d41275d66 from qemu --- include/uc_priv.h | 3 +++ qemu/aarch64.h | 1 + qemu/aarch64eb.h | 1 + qemu/arm.h | 1 + qemu/armeb.h | 1 + qemu/cpus.c | 12 ++++++++++++ qemu/header_gen.py | 1 + qemu/include/qom/cpu.h | 8 ++++++++ qemu/include/sysemu/cpus.h | 2 ++ qemu/m68k.h | 1 + qemu/mips.h | 1 + qemu/mips64.h | 1 + qemu/mips64el.h | 1 + qemu/mipsel.h | 1 + qemu/powerpc.h | 1 + qemu/sparc.h | 1 + qemu/sparc64.h | 1 + qemu/tcg/tcg.h | 9 +++++++++ qemu/vl.c | 3 +++ qemu/x86_64.h | 1 + 20 files changed, 51 insertions(+) diff --git a/include/uc_priv.h b/include/uc_priv.h index 0ec411e5..e3a98ec2 100644 --- a/include/uc_priv.h +++ b/include/uc_priv.h @@ -175,6 +175,9 @@ struct uc_struct { uc_insn_hook_validate insn_hook_validate; + // qemu/cpus.c + bool mttcg_enabled; + // qemu/exec.c MemoryRegion *system_memory; MemoryRegion io_mem_rom; diff --git a/qemu/aarch64.h b/qemu/aarch64.h index 9fbbbc20..47a0e134 100644 --- a/qemu/aarch64.h +++ b/qemu/aarch64.h @@ -2665,6 +2665,7 @@ #define qemu_st_helpers qemu_st_helpers_aarch64 #define qemu_strnlen qemu_strnlen_aarch64 #define qemu_strsep qemu_strsep_aarch64 +#define qemu_tcg_configure qemu_tcg_configure_aarch64 #define qemu_tcg_init_vcpu qemu_tcg_init_vcpu_aarch64 #define qemu_try_memalign qemu_try_memalign_aarch64 #define qentry_destroy qentry_destroy_aarch64 diff --git a/qemu/aarch64eb.h b/qemu/aarch64eb.h index 22cef871..565c6f5f 100644 --- a/qemu/aarch64eb.h +++ b/qemu/aarch64eb.h @@ -2665,6 +2665,7 @@ #define qemu_st_helpers qemu_st_helpers_aarch64eb #define qemu_strnlen qemu_strnlen_aarch64eb #define qemu_strsep qemu_strsep_aarch64eb +#define qemu_tcg_configure qemu_tcg_configure_aarch64eb #define qemu_tcg_init_vcpu qemu_tcg_init_vcpu_aarch64eb #define qemu_try_memalign qemu_try_memalign_aarch64eb #define qentry_destroy qentry_destroy_aarch64eb diff --git a/qemu/arm.h b/qemu/arm.h index 42dd2428..bc08d698 100644 --- a/qemu/arm.h +++ b/qemu/arm.h @@ -2665,6 +2665,7 @@ #define qemu_st_helpers qemu_st_helpers_arm #define qemu_strnlen qemu_strnlen_arm #define qemu_strsep qemu_strsep_arm +#define qemu_tcg_configure qemu_tcg_configure_arm #define qemu_tcg_init_vcpu qemu_tcg_init_vcpu_arm #define qemu_try_memalign qemu_try_memalign_arm #define qentry_destroy qentry_destroy_arm diff --git a/qemu/armeb.h b/qemu/armeb.h index 1e09a52b..15c8a55e 100644 --- a/qemu/armeb.h +++ b/qemu/armeb.h @@ -2665,6 +2665,7 @@ #define qemu_st_helpers qemu_st_helpers_armeb #define qemu_strnlen qemu_strnlen_armeb #define qemu_strsep qemu_strsep_armeb +#define qemu_tcg_configure qemu_tcg_configure_armeb #define qemu_tcg_init_vcpu qemu_tcg_init_vcpu_armeb #define qemu_try_memalign qemu_try_memalign_armeb #define qentry_destroy qentry_destroy_armeb diff --git a/qemu/cpus.c b/qemu/cpus.c index c74df596..c9f2ea67 100644 --- a/qemu/cpus.c +++ b/qemu/cpus.c @@ -31,6 +31,7 @@ #include "sysemu/sysemu.h" #include "exec/exec-all.h" +#include "tcg.h" #include "qemu/thread.h" #include "sysemu/cpus.h" @@ -45,6 +46,17 @@ static bool tcg_exec_all(struct uc_struct* uc); static int qemu_tcg_init_vcpu(CPUState *cpu); static void *qemu_tcg_cpu_loop(struct uc_struct *uc); + +static bool default_mttcg_enabled(void) +{ + return false; +} + +void qemu_tcg_configure(struct uc_struct *uc) +{ + uc->mttcg_enabled = default_mttcg_enabled(); +} + int vm_start(struct uc_struct* uc) { if (resume_all_vcpus(uc)) { diff --git a/qemu/header_gen.py b/qemu/header_gen.py index be96c6fb..fdb0cec4 100644 --- a/qemu/header_gen.py +++ b/qemu/header_gen.py @@ -2671,6 +2671,7 @@ symbols = ( 'qemu_st_helpers', 'qemu_strnlen', 'qemu_strsep', + 'qemu_tcg_configure', 'qemu_tcg_init_vcpu', 'qemu_try_memalign', 'qentry_destroy', diff --git a/qemu/include/qom/cpu.h b/qemu/include/qom/cpu.h index 89c3d04a..dbb2df31 100644 --- a/qemu/include/qom/cpu.h +++ b/qemu/include/qom/cpu.h @@ -328,6 +328,14 @@ struct CPUState { struct uc_struct* uc; }; +/** + * qemu_tcg_mttcg_enabled: + * Check whether we are running MultiThread TCG or not. + * + * Returns: %true if we are in MTTCG mode %false otherwise. + */ +extern bool mttcg_enabled; +#define qemu_tcg_mttcg_enabled() (mttcg_enabled) /** * cpu_paging_enabled: diff --git a/qemu/include/sysemu/cpus.h b/qemu/include/sysemu/cpus.h index 8a55e0b9..dddcc87a 100644 --- a/qemu/include/sysemu/cpus.h +++ b/qemu/include/sysemu/cpus.h @@ -17,4 +17,6 @@ extern int smp_threads; #define smp_threads 1 #endif +void qemu_tcg_configure(struct uc_struct *uc); + #endif diff --git a/qemu/m68k.h b/qemu/m68k.h index f382ad95..4017f044 100644 --- a/qemu/m68k.h +++ b/qemu/m68k.h @@ -2665,6 +2665,7 @@ #define qemu_st_helpers qemu_st_helpers_m68k #define qemu_strnlen qemu_strnlen_m68k #define qemu_strsep qemu_strsep_m68k +#define qemu_tcg_configure qemu_tcg_configure_m68k #define qemu_tcg_init_vcpu qemu_tcg_init_vcpu_m68k #define qemu_try_memalign qemu_try_memalign_m68k #define qentry_destroy qentry_destroy_m68k diff --git a/qemu/mips.h b/qemu/mips.h index 74a56b37..f481c294 100644 --- a/qemu/mips.h +++ b/qemu/mips.h @@ -2665,6 +2665,7 @@ #define qemu_st_helpers qemu_st_helpers_mips #define qemu_strnlen qemu_strnlen_mips #define qemu_strsep qemu_strsep_mips +#define qemu_tcg_configure qemu_tcg_configure_mips #define qemu_tcg_init_vcpu qemu_tcg_init_vcpu_mips #define qemu_try_memalign qemu_try_memalign_mips #define qentry_destroy qentry_destroy_mips diff --git a/qemu/mips64.h b/qemu/mips64.h index 6c8d1dd1..295d456a 100644 --- a/qemu/mips64.h +++ b/qemu/mips64.h @@ -2665,6 +2665,7 @@ #define qemu_st_helpers qemu_st_helpers_mips64 #define qemu_strnlen qemu_strnlen_mips64 #define qemu_strsep qemu_strsep_mips64 +#define qemu_tcg_configure qemu_tcg_configure_mips64 #define qemu_tcg_init_vcpu qemu_tcg_init_vcpu_mips64 #define qemu_try_memalign qemu_try_memalign_mips64 #define qentry_destroy qentry_destroy_mips64 diff --git a/qemu/mips64el.h b/qemu/mips64el.h index c88f1a84..74b5b28b 100644 --- a/qemu/mips64el.h +++ b/qemu/mips64el.h @@ -2665,6 +2665,7 @@ #define qemu_st_helpers qemu_st_helpers_mips64el #define qemu_strnlen qemu_strnlen_mips64el #define qemu_strsep qemu_strsep_mips64el +#define qemu_tcg_configure qemu_tcg_configure_mips64el #define qemu_tcg_init_vcpu qemu_tcg_init_vcpu_mips64el #define qemu_try_memalign qemu_try_memalign_mips64el #define qentry_destroy qentry_destroy_mips64el diff --git a/qemu/mipsel.h b/qemu/mipsel.h index 8070f2bd..d898c30c 100644 --- a/qemu/mipsel.h +++ b/qemu/mipsel.h @@ -2665,6 +2665,7 @@ #define qemu_st_helpers qemu_st_helpers_mipsel #define qemu_strnlen qemu_strnlen_mipsel #define qemu_strsep qemu_strsep_mipsel +#define qemu_tcg_configure qemu_tcg_configure_mipsel #define qemu_tcg_init_vcpu qemu_tcg_init_vcpu_mipsel #define qemu_try_memalign qemu_try_memalign_mipsel #define qentry_destroy qentry_destroy_mipsel diff --git a/qemu/powerpc.h b/qemu/powerpc.h index 3b8a3c11..384ec57e 100644 --- a/qemu/powerpc.h +++ b/qemu/powerpc.h @@ -2665,6 +2665,7 @@ #define qemu_st_helpers qemu_st_helpers_powerpc #define qemu_strnlen qemu_strnlen_powerpc #define qemu_strsep qemu_strsep_powerpc +#define qemu_tcg_configure qemu_tcg_configure_powerpc #define qemu_tcg_init_vcpu qemu_tcg_init_vcpu_powerpc #define qemu_try_memalign qemu_try_memalign_powerpc #define qentry_destroy qentry_destroy_powerpc diff --git a/qemu/sparc.h b/qemu/sparc.h index b5828ae9..71efd349 100644 --- a/qemu/sparc.h +++ b/qemu/sparc.h @@ -2665,6 +2665,7 @@ #define qemu_st_helpers qemu_st_helpers_sparc #define qemu_strnlen qemu_strnlen_sparc #define qemu_strsep qemu_strsep_sparc +#define qemu_tcg_configure qemu_tcg_configure_sparc #define qemu_tcg_init_vcpu qemu_tcg_init_vcpu_sparc #define qemu_try_memalign qemu_try_memalign_sparc #define qentry_destroy qentry_destroy_sparc diff --git a/qemu/sparc64.h b/qemu/sparc64.h index 48a1cc86..a2fa93ff 100644 --- a/qemu/sparc64.h +++ b/qemu/sparc64.h @@ -2665,6 +2665,7 @@ #define qemu_st_helpers qemu_st_helpers_sparc64 #define qemu_strnlen qemu_strnlen_sparc64 #define qemu_strsep qemu_strsep_sparc64 +#define qemu_tcg_configure qemu_tcg_configure_sparc64 #define qemu_tcg_init_vcpu qemu_tcg_init_vcpu_sparc64 #define qemu_try_memalign qemu_try_memalign_sparc64 #define qentry_destroy qentry_destroy_sparc64 diff --git a/qemu/tcg/tcg.h b/qemu/tcg/tcg.h index ee18f1b7..c3b803b4 100644 --- a/qemu/tcg/tcg.h +++ b/qemu/tcg/tcg.h @@ -83,6 +83,15 @@ typedef uint64_t tcg_target_ulong; #error unsupported #endif +/* Oversized TCG guests make things like MTTCG hard + * as we can't use atomics for cputlb updates. + */ +#if TARGET_LONG_BITS > TCG_TARGET_REG_BITS +#define TCG_OVERSIZED_GUEST 1 +#else +#define TCG_OVERSIZED_GUEST 0 +#endif + #if TCG_TARGET_NB_REGS <= 32 typedef uint32_t TCGRegSet; #elif TCG_TARGET_NB_REGS <= 64 diff --git a/qemu/vl.c b/qemu/vl.c index fec0308b..9f755595 100644 --- a/qemu/vl.c +++ b/qemu/vl.c @@ -137,6 +137,9 @@ int machine_initialize(struct uc_struct *uc) uc->machine_state = current_machine; current_machine->uc = uc; + // Unicorn: FIXME: ditto with regards to below + //qemu_tcg_configure(uc); + // Unicorn: FIXME: this should be uncommented // However due to the "stellar" way unicorn // handles multiple targets (e.g. the YOLO diff --git a/qemu/x86_64.h b/qemu/x86_64.h index 5b1733db..1561e09c 100644 --- a/qemu/x86_64.h +++ b/qemu/x86_64.h @@ -2665,6 +2665,7 @@ #define qemu_st_helpers qemu_st_helpers_x86_64 #define qemu_strnlen qemu_strnlen_x86_64 #define qemu_strsep qemu_strsep_x86_64 +#define qemu_tcg_configure qemu_tcg_configure_x86_64 #define qemu_tcg_init_vcpu qemu_tcg_init_vcpu_x86_64 #define qemu_try_memalign qemu_try_memalign_x86_64 #define qentry_destroy qentry_destroy_x86_64