1 | The following changes since commit 6587b0c1331d427b0939c37e763842550ed581db: | 1 | v2: Fix incorretly resolved rebase conflict in patch 16. |
---|---|---|---|
2 | v3: Work around clang preprocessor bug in patch 3. | ||
2 | 3 | ||
3 | Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2021-10-15' into staging (2021-10-15 14:16:28 -0700) | 4 | |
5 | r~ | ||
6 | |||
7 | |||
8 | The following changes since commit fd28528ece590dc709d1a893fce2ff2f68ddca70: | ||
9 | |||
10 | Merge tag 'pull-or1k-20220904' of https://github.com/stffrdhrn/qemu into staging (2022-09-05 18:01:02 -0400) | ||
4 | 11 | ||
5 | are available in the Git repository at: | 12 | are available in the Git repository at: |
6 | 13 | ||
7 | https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20211016 | 14 | https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20220906 |
8 | 15 | ||
9 | for you to fetch changes up to 995b87dedc78b0467f5f18bbc3546072ba97516a: | 16 | for you to fetch changes up to 00c07344fa245b22e895b363320ba4cd0ec1088a: |
10 | 17 | ||
11 | Revert "cpu: Move cpu_common_props to hw/core/cpu.c" (2021-10-15 16:39:15 -0700) | 18 | target/riscv: Make translator stop before the end of a page (2022-09-06 08:04:26 +0100) |
12 | 19 | ||
13 | ---------------------------------------------------------------- | 20 | ---------------------------------------------------------------- |
14 | Move gdb singlestep to generic code | 21 | Respect PROT_EXEC in user-only mode. |
15 | Fix cpu_common_props | 22 | Fix s390x, i386 and riscv for translations crossing a page. |
16 | 23 | ||
17 | ---------------------------------------------------------------- | 24 | ---------------------------------------------------------------- |
18 | Richard Henderson (24): | 25 | Ilya Leoshkevich (4): |
19 | accel/tcg: Handle gdb singlestep in cpu_tb_exec | 26 | linux-user: Clear translations on mprotect() |
20 | target/alpha: Drop checks for singlestep_enabled | 27 | accel/tcg: Introduce is_same_page() |
21 | target/avr: Drop checks for singlestep_enabled | 28 | target/s390x: Make translator stop before the end of a page |
22 | target/cris: Drop checks for singlestep_enabled | 29 | target/i386: Make translator stop before the end of a page |
23 | target/hexagon: Drop checks for singlestep_enabled | ||
24 | target/arm: Drop checks for singlestep_enabled | ||
25 | target/hppa: Drop checks for singlestep_enabled | ||
26 | target/i386: Check CF_NO_GOTO_TB for dc->jmp_opt | ||
27 | target/i386: Drop check for singlestep_enabled | ||
28 | target/m68k: Drop checks for singlestep_enabled | ||
29 | target/microblaze: Check CF_NO_GOTO_TB for DISAS_JUMP | ||
30 | target/microblaze: Drop checks for singlestep_enabled | ||
31 | target/mips: Fix single stepping | ||
32 | target/mips: Drop exit checks for singlestep_enabled | ||
33 | target/openrisc: Drop checks for singlestep_enabled | ||
34 | target/ppc: Drop exit checks for singlestep_enabled | ||
35 | target/riscv: Remove dead code after exception | ||
36 | target/riscv: Remove exit_tb and lookup_and_goto_ptr | ||
37 | target/rx: Drop checks for singlestep_enabled | ||
38 | target/s390x: Drop check for singlestep_enabled | ||
39 | target/sh4: Drop check for singlestep_enabled | ||
40 | target/tricore: Drop check for singlestep_enabled | ||
41 | target/xtensa: Drop check for singlestep_enabled | ||
42 | Revert "cpu: Move cpu_common_props to hw/core/cpu.c" | ||
43 | 30 | ||
44 | include/hw/core/cpu.h | 1 + | 31 | Richard Henderson (16): |
45 | target/i386/helper.h | 1 - | 32 | linux-user/arm: Mark the commpage executable |
46 | target/rx/helper.h | 1 - | 33 | linux-user/hppa: Allocate page zero as a commpage |
47 | target/sh4/helper.h | 1 - | 34 | linux-user/x86_64: Allocate vsyscall page as a commpage |
48 | target/tricore/helper.h | 1 - | 35 | linux-user: Honor PT_GNU_STACK |
49 | accel/tcg/cpu-exec.c | 11 ++++ | 36 | tests/tcg/i386: Move smc_code2 to an executable section |
50 | cpu.c | 21 ++++++++ | 37 | accel/tcg: Properly implement get_page_addr_code for user-only |
51 | hw/core/cpu-common.c | 17 +----- | 38 | accel/tcg: Unlock mmap_lock after longjmp |
52 | target/alpha/translate.c | 13 ++--- | 39 | accel/tcg: Make tb_htable_lookup static |
53 | target/arm/translate-a64.c | 10 +--- | 40 | accel/tcg: Move qemu_ram_addr_from_host_nofail to physmem.c |
54 | target/arm/translate.c | 36 +++---------- | 41 | accel/tcg: Use probe_access_internal for softmmu get_page_addr_code_hostp |
55 | target/avr/translate.c | 19 ++----- | 42 | accel/tcg: Document the faulting lookup in tb_lookup_cmp |
56 | target/cris/translate.c | 16 ------ | 43 | accel/tcg: Remove translator_ldsw |
57 | target/hexagon/translate.c | 12 +---- | 44 | accel/tcg: Add pc and host_pc params to gen_intermediate_code |
58 | target/hppa/translate.c | 17 ++---- | 45 | accel/tcg: Add fast path for translator_ld* |
59 | target/i386/tcg/misc_helper.c | 8 --- | 46 | target/riscv: Add MAX_INSN_LEN and insn_len |
60 | target/i386/tcg/translate.c | 9 ++-- | 47 | target/riscv: Make translator stop before the end of a page |
61 | target/m68k/translate.c | 44 ++++----------- | ||
62 | target/microblaze/translate.c | 18 ++----- | ||
63 | target/mips/tcg/translate.c | 75 ++++++++++++-------------- | ||
64 | target/openrisc/translate.c | 18 ++----- | ||
65 | target/ppc/translate.c | 38 +++---------- | ||
66 | target/riscv/translate.c | 27 +--------- | ||
67 | target/rx/op_helper.c | 8 --- | ||
68 | target/rx/translate.c | 12 +---- | ||
69 | target/s390x/tcg/translate.c | 8 +-- | ||
70 | target/sh4/op_helper.c | 5 -- | ||
71 | target/sh4/translate.c | 14 ++--- | ||
72 | target/tricore/op_helper.c | 7 --- | ||
73 | target/tricore/translate.c | 14 +---- | ||
74 | target/xtensa/translate.c | 25 +++------ | ||
75 | target/riscv/insn_trans/trans_privileged.c.inc | 10 ++-- | ||
76 | target/riscv/insn_trans/trans_rvi.c.inc | 8 ++- | ||
77 | target/riscv/insn_trans/trans_rvv.c.inc | 2 +- | ||
78 | 34 files changed, 141 insertions(+), 386 deletions(-) | ||
79 | 48 | ||
49 | include/elf.h | 1 + | ||
50 | include/exec/cpu-common.h | 1 + | ||
51 | include/exec/exec-all.h | 89 ++++++++---------------- | ||
52 | include/exec/translator.h | 96 ++++++++++++++++--------- | ||
53 | linux-user/arm/target_cpu.h | 4 +- | ||
54 | linux-user/qemu.h | 1 + | ||
55 | accel/tcg/cpu-exec.c | 143 ++++++++++++++++++++------------------ | ||
56 | accel/tcg/cputlb.c | 93 +++++++------------------ | ||
57 | accel/tcg/translate-all.c | 29 ++++---- | ||
58 | accel/tcg/translator.c | 135 ++++++++++++++++++++++++++--------- | ||
59 | accel/tcg/user-exec.c | 17 ++++- | ||
60 | linux-user/elfload.c | 82 ++++++++++++++++++++-- | ||
61 | linux-user/mmap.c | 6 +- | ||
62 | softmmu/physmem.c | 12 ++++ | ||
63 | target/alpha/translate.c | 5 +- | ||
64 | target/arm/translate.c | 5 +- | ||
65 | target/avr/translate.c | 5 +- | ||
66 | target/cris/translate.c | 5 +- | ||
67 | target/hexagon/translate.c | 6 +- | ||
68 | target/hppa/translate.c | 5 +- | ||
69 | target/i386/tcg/translate.c | 71 +++++++++++-------- | ||
70 | target/loongarch/translate.c | 6 +- | ||
71 | target/m68k/translate.c | 5 +- | ||
72 | target/microblaze/translate.c | 5 +- | ||
73 | target/mips/tcg/translate.c | 5 +- | ||
74 | target/nios2/translate.c | 5 +- | ||
75 | target/openrisc/translate.c | 6 +- | ||
76 | target/ppc/translate.c | 5 +- | ||
77 | target/riscv/translate.c | 32 +++++++-- | ||
78 | target/rx/translate.c | 5 +- | ||
79 | target/s390x/tcg/translate.c | 20 ++++-- | ||
80 | target/sh4/translate.c | 5 +- | ||
81 | target/sparc/translate.c | 5 +- | ||
82 | target/tricore/translate.c | 6 +- | ||
83 | target/xtensa/translate.c | 6 +- | ||
84 | tests/tcg/i386/test-i386.c | 2 +- | ||
85 | tests/tcg/riscv64/noexec.c | 79 +++++++++++++++++++++ | ||
86 | tests/tcg/s390x/noexec.c | 106 ++++++++++++++++++++++++++++ | ||
87 | tests/tcg/x86_64/noexec.c | 75 ++++++++++++++++++++ | ||
88 | tests/tcg/multiarch/noexec.c.inc | 139 ++++++++++++++++++++++++++++++++++++ | ||
89 | tests/tcg/riscv64/Makefile.target | 1 + | ||
90 | tests/tcg/s390x/Makefile.target | 1 + | ||
91 | tests/tcg/x86_64/Makefile.target | 3 +- | ||
92 | 43 files changed, 966 insertions(+), 367 deletions(-) | ||
93 | create mode 100644 tests/tcg/riscv64/noexec.c | ||
94 | create mode 100644 tests/tcg/s390x/noexec.c | ||
95 | create mode 100644 tests/tcg/x86_64/noexec.c | ||
96 | create mode 100644 tests/tcg/multiarch/noexec.c.inc | diff view generated by jsdifflib |
1 | GDB single-stepping is now handled generically. | 1 | We're about to start validating PAGE_EXEC, which means |
---|---|---|---|
2 | that we've got to mark the commpage executable. We had | ||
3 | been placing the commpage outside of reserved_va, which | ||
4 | was incorrect and lead to an abort. | ||
2 | 5 | ||
3 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 6 | Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> |
7 | Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | --- | 9 | --- |
6 | target/mips/tcg/translate.c | 50 +++++++++++++------------------------ | 10 | linux-user/arm/target_cpu.h | 4 ++-- |
7 | 1 file changed, 18 insertions(+), 32 deletions(-) | 11 | linux-user/elfload.c | 6 +++++- |
12 | 2 files changed, 7 insertions(+), 3 deletions(-) | ||
8 | 13 | ||
9 | diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c | 14 | diff --git a/linux-user/arm/target_cpu.h b/linux-user/arm/target_cpu.h |
10 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
11 | --- a/target/mips/tcg/translate.c | 16 | --- a/linux-user/arm/target_cpu.h |
12 | +++ b/target/mips/tcg/translate.c | 17 | +++ b/linux-user/arm/target_cpu.h |
13 | @@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) | 18 | @@ -XXX,XX +XXX,XX @@ static inline unsigned long arm_max_reserved_va(CPUState *cs) |
14 | tcg_gen_exit_tb(ctx->base.tb, n); | ||
15 | } else { | 19 | } else { |
16 | gen_save_pc(dest); | 20 | /* |
17 | - if (ctx->base.singlestep_enabled) { | 21 | * We need to be able to map the commpage. |
18 | - save_cpu_state(ctx, 0); | 22 | - * See validate_guest_space in linux-user/elfload.c. |
19 | - gen_helper_raise_exception_debug(cpu_env); | 23 | + * See init_guest_commpage in linux-user/elfload.c. |
20 | - } else { | 24 | */ |
21 | - tcg_gen_lookup_and_goto_ptr(); | 25 | - return 0xffff0000ul; |
22 | - } | 26 | + return 0xfffffffful; |
23 | + tcg_gen_lookup_and_goto_ptr(); | ||
24 | } | 27 | } |
25 | } | 28 | } |
26 | 29 | #define MAX_RESERVED_VA arm_max_reserved_va | |
27 | @@ -XXX,XX +XXX,XX @@ static void gen_branch(DisasContext *ctx, int insn_bytes) | 30 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
28 | } else { | 31 | index XXXXXXX..XXXXXXX 100644 |
29 | tcg_gen_mov_tl(cpu_PC, btarget); | 32 | --- a/linux-user/elfload.c |
30 | } | 33 | +++ b/linux-user/elfload.c |
31 | - if (ctx->base.singlestep_enabled) { | 34 | @@ -XXX,XX +XXX,XX @@ enum { |
32 | - save_cpu_state(ctx, 0); | 35 | |
33 | - gen_helper_raise_exception_debug(cpu_env); | 36 | static bool init_guest_commpage(void) |
34 | - } | ||
35 | tcg_gen_lookup_and_goto_ptr(); | ||
36 | break; | ||
37 | default: | ||
38 | @@ -XXX,XX +XXX,XX @@ static void mips_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) | ||
39 | { | 37 | { |
40 | DisasContext *ctx = container_of(dcbase, DisasContext, base); | 38 | - void *want = g2h_untagged(HI_COMMPAGE & -qemu_host_page_size); |
41 | 39 | + abi_ptr commpage = HI_COMMPAGE & -qemu_host_page_size; | |
42 | - if (ctx->base.singlestep_enabled && ctx->base.is_jmp != DISAS_NORETURN) { | 40 | + void *want = g2h_untagged(commpage); |
43 | - save_cpu_state(ctx, ctx->base.is_jmp != DISAS_EXIT); | 41 | void *addr = mmap(want, qemu_host_page_size, PROT_READ | PROT_WRITE, |
44 | - gen_helper_raise_exception_debug(cpu_env); | 42 | MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); |
45 | - } else { | 43 | |
46 | - switch (ctx->base.is_jmp) { | 44 | @@ -XXX,XX +XXX,XX @@ static bool init_guest_commpage(void) |
47 | - case DISAS_STOP: | 45 | perror("Protecting guest commpage"); |
48 | - gen_save_pc(ctx->base.pc_next); | 46 | exit(EXIT_FAILURE); |
49 | - tcg_gen_lookup_and_goto_ptr(); | ||
50 | - break; | ||
51 | - case DISAS_NEXT: | ||
52 | - case DISAS_TOO_MANY: | ||
53 | - save_cpu_state(ctx, 0); | ||
54 | - gen_goto_tb(ctx, 0, ctx->base.pc_next); | ||
55 | - break; | ||
56 | - case DISAS_EXIT: | ||
57 | - tcg_gen_exit_tb(NULL, 0); | ||
58 | - break; | ||
59 | - case DISAS_NORETURN: | ||
60 | - break; | ||
61 | - default: | ||
62 | - g_assert_not_reached(); | ||
63 | - } | ||
64 | + switch (ctx->base.is_jmp) { | ||
65 | + case DISAS_STOP: | ||
66 | + gen_save_pc(ctx->base.pc_next); | ||
67 | + tcg_gen_lookup_and_goto_ptr(); | ||
68 | + break; | ||
69 | + case DISAS_NEXT: | ||
70 | + case DISAS_TOO_MANY: | ||
71 | + save_cpu_state(ctx, 0); | ||
72 | + gen_goto_tb(ctx, 0, ctx->base.pc_next); | ||
73 | + break; | ||
74 | + case DISAS_EXIT: | ||
75 | + tcg_gen_exit_tb(NULL, 0); | ||
76 | + break; | ||
77 | + case DISAS_NORETURN: | ||
78 | + break; | ||
79 | + default: | ||
80 | + g_assert_not_reached(); | ||
81 | } | 47 | } |
48 | + | ||
49 | + page_set_flags(commpage, commpage + qemu_host_page_size, | ||
50 | + PAGE_READ | PAGE_EXEC | PAGE_VALID); | ||
51 | return true; | ||
82 | } | 52 | } |
83 | 53 | ||
84 | -- | 54 | -- |
85 | 2.25.1 | 55 | 2.34.1 |
86 | |||
87 | diff view generated by jsdifflib |
1 | GDB single-stepping is now handled generically. | 1 | We're about to start validating PAGE_EXEC, which means that we've |
---|---|---|---|
2 | got to mark page zero executable. We had been special casing this | ||
3 | entirely within translate. | ||
2 | 4 | ||
3 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 5 | Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> |
6 | Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | --- | 8 | --- |
6 | target/sh4/helper.h | 1 - | 9 | linux-user/elfload.c | 34 +++++++++++++++++++++++++++++++--- |
7 | target/sh4/op_helper.c | 5 ----- | 10 | 1 file changed, 31 insertions(+), 3 deletions(-) |
8 | target/sh4/translate.c | 14 +++----------- | ||
9 | 3 files changed, 3 insertions(+), 17 deletions(-) | ||
10 | 11 | ||
11 | diff --git a/target/sh4/helper.h b/target/sh4/helper.h | 12 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
12 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/sh4/helper.h | 14 | --- a/linux-user/elfload.c |
14 | +++ b/target/sh4/helper.h | 15 | +++ b/linux-user/elfload.c |
15 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_1(raise_illegal_instruction, noreturn, env) | 16 | @@ -XXX,XX +XXX,XX @@ static inline void init_thread(struct target_pt_regs *regs, |
16 | DEF_HELPER_1(raise_slot_illegal_instruction, noreturn, env) | 17 | regs->gr[31] = infop->entry; |
17 | DEF_HELPER_1(raise_fpu_disable, noreturn, env) | ||
18 | DEF_HELPER_1(raise_slot_fpu_disable, noreturn, env) | ||
19 | -DEF_HELPER_1(debug, noreturn, env) | ||
20 | DEF_HELPER_1(sleep, noreturn, env) | ||
21 | DEF_HELPER_2(trapa, noreturn, env, i32) | ||
22 | DEF_HELPER_1(exclusive, noreturn, env) | ||
23 | diff --git a/target/sh4/op_helper.c b/target/sh4/op_helper.c | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/target/sh4/op_helper.c | ||
26 | +++ b/target/sh4/op_helper.c | ||
27 | @@ -XXX,XX +XXX,XX @@ void helper_raise_slot_fpu_disable(CPUSH4State *env) | ||
28 | raise_exception(env, 0x820, 0); | ||
29 | } | 18 | } |
30 | 19 | ||
31 | -void helper_debug(CPUSH4State *env) | 20 | +#define LO_COMMPAGE 0 |
32 | -{ | 21 | + |
33 | - raise_exception(env, EXCP_DEBUG, 0); | 22 | +static bool init_guest_commpage(void) |
34 | -} | 23 | +{ |
35 | - | 24 | + void *want = g2h_untagged(LO_COMMPAGE); |
36 | void helper_sleep(CPUSH4State *env) | 25 | + void *addr = mmap(want, qemu_host_page_size, PROT_NONE, |
37 | { | 26 | + MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0); |
38 | CPUState *cs = env_cpu(env); | 27 | + |
39 | diff --git a/target/sh4/translate.c b/target/sh4/translate.c | 28 | + if (addr == MAP_FAILED) { |
40 | index XXXXXXX..XXXXXXX 100644 | 29 | + perror("Allocating guest commpage"); |
41 | --- a/target/sh4/translate.c | 30 | + exit(EXIT_FAILURE); |
42 | +++ b/target/sh4/translate.c | 31 | + } |
43 | @@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) | 32 | + if (addr != want) { |
44 | tcg_gen_exit_tb(ctx->base.tb, n); | 33 | + return false; |
45 | } else { | 34 | + } |
46 | tcg_gen_movi_i32(cpu_pc, dest); | 35 | + |
47 | - if (ctx->base.singlestep_enabled) { | 36 | + /* |
48 | - gen_helper_debug(cpu_env); | 37 | + * On Linux, page zero is normally marked execute only + gateway. |
49 | - } else if (use_exit_tb(ctx)) { | 38 | + * Normal read or write is supposed to fail (thus PROT_NONE above), |
50 | + if (use_exit_tb(ctx)) { | 39 | + * but specific offsets have kernel code mapped to raise permissions |
51 | tcg_gen_exit_tb(NULL, 0); | 40 | + * and implement syscalls. Here, simply mark the page executable. |
41 | + * Special case the entry points during translation (see do_page_zero). | ||
42 | + */ | ||
43 | + page_set_flags(LO_COMMPAGE, LO_COMMPAGE + TARGET_PAGE_SIZE, | ||
44 | + PAGE_EXEC | PAGE_VALID); | ||
45 | + return true; | ||
46 | +} | ||
47 | + | ||
48 | #endif /* TARGET_HPPA */ | ||
49 | |||
50 | #ifdef TARGET_XTENSA | ||
51 | @@ -XXX,XX +XXX,XX @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, | ||
52 | } | ||
53 | |||
54 | #if defined(HI_COMMPAGE) | ||
55 | -#define LO_COMMPAGE 0 | ||
56 | +#define LO_COMMPAGE -1 | ||
57 | #elif defined(LO_COMMPAGE) | ||
58 | #define HI_COMMPAGE 0 | ||
59 | #else | ||
60 | #define HI_COMMPAGE 0 | ||
61 | -#define LO_COMMPAGE 0 | ||
62 | +#define LO_COMMPAGE -1 | ||
63 | #define init_guest_commpage() true | ||
64 | #endif | ||
65 | |||
66 | @@ -XXX,XX +XXX,XX @@ static void pgb_static(const char *image_name, abi_ulong orig_loaddr, | ||
52 | } else { | 67 | } else { |
53 | tcg_gen_lookup_and_goto_ptr(); | 68 | offset = -(HI_COMMPAGE & -align); |
54 | @@ -XXX,XX +XXX,XX @@ static void gen_jump(DisasContext * ctx) | 69 | } |
55 | delayed jump as immediate jump are conditinal jumps */ | 70 | - } else if (LO_COMMPAGE != 0) { |
56 | tcg_gen_mov_i32(cpu_pc, cpu_delayed_pc); | 71 | + } else if (LO_COMMPAGE != -1) { |
57 | tcg_gen_discard_i32(cpu_delayed_pc); | 72 | loaddr = MIN(loaddr, LO_COMMPAGE & -align); |
58 | - if (ctx->base.singlestep_enabled) { | 73 | } |
59 | - gen_helper_debug(cpu_env); | 74 | |
60 | - } else if (use_exit_tb(ctx)) { | ||
61 | + if (use_exit_tb(ctx)) { | ||
62 | tcg_gen_exit_tb(NULL, 0); | ||
63 | } else { | ||
64 | tcg_gen_lookup_and_goto_ptr(); | ||
65 | @@ -XXX,XX +XXX,XX @@ static void sh4_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) | ||
66 | switch (ctx->base.is_jmp) { | ||
67 | case DISAS_STOP: | ||
68 | gen_save_cpu_state(ctx, true); | ||
69 | - if (ctx->base.singlestep_enabled) { | ||
70 | - gen_helper_debug(cpu_env); | ||
71 | - } else { | ||
72 | - tcg_gen_exit_tb(NULL, 0); | ||
73 | - } | ||
74 | + tcg_gen_exit_tb(NULL, 0); | ||
75 | break; | ||
76 | case DISAS_NEXT: | ||
77 | case DISAS_TOO_MANY: | ||
78 | -- | 75 | -- |
79 | 2.25.1 | 76 | 2.34.1 |
80 | |||
81 | diff view generated by jsdifflib |
1 | GDB single-stepping is now handled generically. | 1 | We're about to start validating PAGE_EXEC, which means that we've |
---|---|---|---|
2 | got to mark the vsyscall page executable. We had been special | ||
3 | casing this entirely within translate. | ||
2 | 4 | ||
3 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 5 | Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> |
6 | Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | --- | 8 | --- |
6 | target/rx/helper.h | 1 - | 9 | linux-user/elfload.c | 23 +++++++++++++++++++++++ |
7 | target/rx/op_helper.c | 8 -------- | 10 | 1 file changed, 23 insertions(+) |
8 | target/rx/translate.c | 12 ++---------- | ||
9 | 3 files changed, 2 insertions(+), 19 deletions(-) | ||
10 | 11 | ||
11 | diff --git a/target/rx/helper.h b/target/rx/helper.h | 12 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
12 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/rx/helper.h | 14 | --- a/linux-user/elfload.c |
14 | +++ b/target/rx/helper.h | 15 | +++ b/linux-user/elfload.c |
15 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_1(raise_illegal_instruction, noreturn, env) | 16 | @@ -XXX,XX +XXX,XX @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en |
16 | DEF_HELPER_1(raise_access_fault, noreturn, env) | 17 | (*regs)[26] = tswapreg(env->segs[R_GS].selector & 0xffff); |
17 | DEF_HELPER_1(raise_privilege_violation, noreturn, env) | ||
18 | DEF_HELPER_1(wait, noreturn, env) | ||
19 | -DEF_HELPER_1(debug, noreturn, env) | ||
20 | DEF_HELPER_2(rxint, noreturn, env, i32) | ||
21 | DEF_HELPER_1(rxbrk, noreturn, env) | ||
22 | DEF_HELPER_FLAGS_3(fadd, TCG_CALL_NO_WG, f32, env, f32, f32) | ||
23 | diff --git a/target/rx/op_helper.c b/target/rx/op_helper.c | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/target/rx/op_helper.c | ||
26 | +++ b/target/rx/op_helper.c | ||
27 | @@ -XXX,XX +XXX,XX @@ void QEMU_NORETURN helper_wait(CPURXState *env) | ||
28 | raise_exception(env, EXCP_HLT, 0); | ||
29 | } | 18 | } |
30 | 19 | ||
31 | -void QEMU_NORETURN helper_debug(CPURXState *env) | 20 | +#if ULONG_MAX > UINT32_MAX |
32 | -{ | 21 | +#define INIT_GUEST_COMMPAGE |
33 | - CPUState *cs = env_cpu(env); | 22 | +static bool init_guest_commpage(void) |
34 | - | 23 | +{ |
35 | - cs->exception_index = EXCP_DEBUG; | 24 | + /* |
36 | - cpu_loop_exit(cs); | 25 | + * The vsyscall page is at a high negative address aka kernel space, |
37 | -} | 26 | + * which means that we cannot actually allocate it with target_mmap. |
38 | - | 27 | + * We still should be able to use page_set_flags, unless the user |
39 | void QEMU_NORETURN helper_rxint(CPURXState *env, uint32_t vec) | 28 | + * has specified -R reserved_va, which would trigger an assert(). |
29 | + */ | ||
30 | + if (reserved_va != 0 && | ||
31 | + TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE >= reserved_va) { | ||
32 | + error_report("Cannot allocate vsyscall page"); | ||
33 | + exit(EXIT_FAILURE); | ||
34 | + } | ||
35 | + page_set_flags(TARGET_VSYSCALL_PAGE, | ||
36 | + TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE, | ||
37 | + PAGE_EXEC | PAGE_VALID); | ||
38 | + return true; | ||
39 | +} | ||
40 | +#endif | ||
41 | #else | ||
42 | |||
43 | #define ELF_START_MMAP 0x80000000 | ||
44 | @@ -XXX,XX +XXX,XX @@ static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc, | ||
45 | #else | ||
46 | #define HI_COMMPAGE 0 | ||
47 | #define LO_COMMPAGE -1 | ||
48 | +#ifndef INIT_GUEST_COMMPAGE | ||
49 | #define init_guest_commpage() true | ||
50 | #endif | ||
51 | +#endif | ||
52 | |||
53 | static void pgb_fail_in_use(const char *image_name) | ||
40 | { | 54 | { |
41 | raise_exception(env, 0x100 + vec, 0); | ||
42 | diff --git a/target/rx/translate.c b/target/rx/translate.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/target/rx/translate.c | ||
45 | +++ b/target/rx/translate.c | ||
46 | @@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *dc, int n, target_ulong dest) | ||
47 | tcg_gen_exit_tb(dc->base.tb, n); | ||
48 | } else { | ||
49 | tcg_gen_movi_i32(cpu_pc, dest); | ||
50 | - if (dc->base.singlestep_enabled) { | ||
51 | - gen_helper_debug(cpu_env); | ||
52 | - } else { | ||
53 | - tcg_gen_lookup_and_goto_ptr(); | ||
54 | - } | ||
55 | + tcg_gen_lookup_and_goto_ptr(); | ||
56 | } | ||
57 | dc->base.is_jmp = DISAS_NORETURN; | ||
58 | } | ||
59 | @@ -XXX,XX +XXX,XX @@ static void rx_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) | ||
60 | gen_goto_tb(ctx, 0, dcbase->pc_next); | ||
61 | break; | ||
62 | case DISAS_JUMP: | ||
63 | - if (ctx->base.singlestep_enabled) { | ||
64 | - gen_helper_debug(cpu_env); | ||
65 | - } else { | ||
66 | - tcg_gen_lookup_and_goto_ptr(); | ||
67 | - } | ||
68 | + tcg_gen_lookup_and_goto_ptr(); | ||
69 | break; | ||
70 | case DISAS_UPDATE: | ||
71 | tcg_gen_movi_i32(cpu_pc, ctx->base.pc_next); | ||
72 | -- | 55 | -- |
73 | 2.25.1 | 56 | 2.34.1 |
74 | |||
75 | diff view generated by jsdifflib |
1 | GDB single-stepping is now handled generically. | 1 | Map the stack executable if required by default or on demand. |
---|---|---|---|
2 | 2 | ||
3 | Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
4 | Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 6 | --- |
5 | target/cris/translate.c | 16 ---------------- | 7 | include/elf.h | 1 + |
6 | 1 file changed, 16 deletions(-) | 8 | linux-user/qemu.h | 1 + |
9 | linux-user/elfload.c | 19 ++++++++++++++++++- | ||
10 | 3 files changed, 20 insertions(+), 1 deletion(-) | ||
7 | 11 | ||
8 | diff --git a/target/cris/translate.c b/target/cris/translate.c | 12 | diff --git a/include/elf.h b/include/elf.h |
9 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/target/cris/translate.c | 14 | --- a/include/elf.h |
11 | +++ b/target/cris/translate.c | 15 | +++ b/include/elf.h |
12 | @@ -XXX,XX +XXX,XX @@ static void cris_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu) | 16 | @@ -XXX,XX +XXX,XX @@ typedef int64_t Elf64_Sxword; |
17 | #define PT_LOPROC 0x70000000 | ||
18 | #define PT_HIPROC 0x7fffffff | ||
19 | |||
20 | +#define PT_GNU_STACK (PT_LOOS + 0x474e551) | ||
21 | #define PT_GNU_PROPERTY (PT_LOOS + 0x474e553) | ||
22 | |||
23 | #define PT_MIPS_REGINFO 0x70000000 | ||
24 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/linux-user/qemu.h | ||
27 | +++ b/linux-user/qemu.h | ||
28 | @@ -XXX,XX +XXX,XX @@ struct image_info { | ||
29 | uint32_t elf_flags; | ||
30 | int personality; | ||
31 | abi_ulong alignment; | ||
32 | + bool exec_stack; | ||
33 | |||
34 | /* Generic semihosting knows about these pointers. */ | ||
35 | abi_ulong arg_strings; /* strings for argv */ | ||
36 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/linux-user/elfload.c | ||
39 | +++ b/linux-user/elfload.c | ||
40 | @@ -XXX,XX +XXX,XX @@ static bool init_guest_commpage(void) | ||
41 | #define ELF_ARCH EM_386 | ||
42 | |||
43 | #define ELF_PLATFORM get_elf_platform() | ||
44 | +#define EXSTACK_DEFAULT true | ||
45 | |||
46 | static const char *get_elf_platform(void) | ||
47 | { | ||
48 | @@ -XXX,XX +XXX,XX @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *en | ||
49 | |||
50 | #define ELF_ARCH EM_ARM | ||
51 | #define ELF_CLASS ELFCLASS32 | ||
52 | +#define EXSTACK_DEFAULT true | ||
53 | |||
54 | static inline void init_thread(struct target_pt_regs *regs, | ||
55 | struct image_info *infop) | ||
56 | @@ -XXX,XX +XXX,XX @@ static inline void init_thread(struct target_pt_regs *regs, | ||
57 | #else | ||
58 | |||
59 | #define ELF_CLASS ELFCLASS32 | ||
60 | +#define EXSTACK_DEFAULT true | ||
61 | |||
62 | #endif | ||
63 | |||
64 | @@ -XXX,XX +XXX,XX @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUPPCState *en | ||
65 | |||
66 | #define ELF_CLASS ELFCLASS64 | ||
67 | #define ELF_ARCH EM_LOONGARCH | ||
68 | +#define EXSTACK_DEFAULT true | ||
69 | |||
70 | #define elf_check_arch(x) ((x) == EM_LOONGARCH) | ||
71 | |||
72 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void) | ||
73 | #define ELF_CLASS ELFCLASS32 | ||
74 | #endif | ||
75 | #define ELF_ARCH EM_MIPS | ||
76 | +#define EXSTACK_DEFAULT true | ||
77 | |||
78 | #ifdef TARGET_ABI_MIPSN32 | ||
79 | #define elf_check_abi(x) ((x) & EF_MIPS_ABI2) | ||
80 | @@ -XXX,XX +XXX,XX @@ static inline void init_thread(struct target_pt_regs *regs, | ||
81 | #define bswaptls(ptr) bswap32s(ptr) | ||
82 | #endif | ||
83 | |||
84 | +#ifndef EXSTACK_DEFAULT | ||
85 | +#define EXSTACK_DEFAULT false | ||
86 | +#endif | ||
87 | + | ||
88 | #include "elf.h" | ||
89 | |||
90 | /* We must delay the following stanzas until after "elf.h". */ | ||
91 | @@ -XXX,XX +XXX,XX @@ static abi_ulong setup_arg_pages(struct linux_binprm *bprm, | ||
92 | struct image_info *info) | ||
93 | { | ||
94 | abi_ulong size, error, guard; | ||
95 | + int prot; | ||
96 | |||
97 | size = guest_stack_size; | ||
98 | if (size < STACK_LOWER_LIMIT) { | ||
99 | @@ -XXX,XX +XXX,XX @@ static abi_ulong setup_arg_pages(struct linux_binprm *bprm, | ||
100 | guard = qemu_real_host_page_size(); | ||
101 | } | ||
102 | |||
103 | - error = target_mmap(0, size + guard, PROT_READ | PROT_WRITE, | ||
104 | + prot = PROT_READ | PROT_WRITE; | ||
105 | + if (info->exec_stack) { | ||
106 | + prot |= PROT_EXEC; | ||
107 | + } | ||
108 | + error = target_mmap(0, size + guard, prot, | ||
109 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | ||
110 | if (error == -1) { | ||
111 | perror("mmap stack"); | ||
112 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
113 | */ | ||
114 | loaddr = -1, hiaddr = 0; | ||
115 | info->alignment = 0; | ||
116 | + info->exec_stack = EXSTACK_DEFAULT; | ||
117 | for (i = 0; i < ehdr->e_phnum; ++i) { | ||
118 | struct elf_phdr *eppnt = phdr + i; | ||
119 | if (eppnt->p_type == PT_LOAD) { | ||
120 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
121 | if (!parse_elf_properties(image_fd, info, eppnt, bprm_buf, &err)) { | ||
122 | goto exit_errmsg; | ||
123 | } | ||
124 | + } else if (eppnt->p_type == PT_GNU_STACK) { | ||
125 | + info->exec_stack = eppnt->p_flags & PF_X; | ||
13 | } | 126 | } |
14 | } | 127 | } |
15 | 128 | ||
16 | - if (unlikely(dc->base.singlestep_enabled)) { | ||
17 | - switch (is_jmp) { | ||
18 | - case DISAS_TOO_MANY: | ||
19 | - case DISAS_UPDATE_NEXT: | ||
20 | - tcg_gen_movi_tl(env_pc, npc); | ||
21 | - /* fall through */ | ||
22 | - case DISAS_JUMP: | ||
23 | - case DISAS_UPDATE: | ||
24 | - t_gen_raise_exception(EXCP_DEBUG); | ||
25 | - return; | ||
26 | - default: | ||
27 | - break; | ||
28 | - } | ||
29 | - g_assert_not_reached(); | ||
30 | - } | ||
31 | - | ||
32 | switch (is_jmp) { | ||
33 | case DISAS_TOO_MANY: | ||
34 | gen_goto_tb(dc, 0, npc); | ||
35 | -- | 129 | -- |
36 | 2.25.1 | 130 | 2.34.1 |
37 | |||
38 | diff view generated by jsdifflib |
1 | As per an ancient comment in mips_tr_translate_insn about the | 1 | From: Ilya Leoshkevich <iii@linux.ibm.com> |
---|---|---|---|
2 | expectations of gdb, when restarting the insn in a delay slot | ||
3 | we also re-execute the branch. Which means that we are | ||
4 | expected to execute two insns in this case. | ||
5 | 2 | ||
6 | This has been broken since 8b86d6d2580, where we forced max_insns | 3 | Currently it's possible to execute pages that do not have PAGE_EXEC |
7 | to 1 while single-stepping. This resulted in an exit from the | 4 | if there is an existing translation block. Fix by invalidating TBs |
8 | translator loop after the branch but before the delay slot is | 5 | that touch the affected pages. |
9 | translated. | ||
10 | 6 | ||
11 | Increase the max_insns to 2 for this case. In addition, bypass | 7 | Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> |
12 | the end-of-page check, for when the branch itself ends the page. | 8 | Message-Id: <20220817150506.592862-2-iii@linux.ibm.com> |
13 | |||
14 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
15 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
16 | --- | 10 | --- |
17 | target/mips/tcg/translate.c | 25 ++++++++++++++++--------- | 11 | linux-user/mmap.c | 6 ++++-- |
18 | 1 file changed, 16 insertions(+), 9 deletions(-) | 12 | 1 file changed, 4 insertions(+), 2 deletions(-) |
19 | 13 | ||
20 | diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c | 14 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c |
21 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/mips/tcg/translate.c | 16 | --- a/linux-user/mmap.c |
23 | +++ b/target/mips/tcg/translate.c | 17 | +++ b/linux-user/mmap.c |
24 | @@ -XXX,XX +XXX,XX @@ static void mips_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | 18 | @@ -XXX,XX +XXX,XX @@ int target_mprotect(abi_ulong start, abi_ulong len, int target_prot) |
25 | ctx->default_tcg_memop_mask = (ctx->insn_flags & (ISA_MIPS_R6 | | 19 | goto error; |
26 | INSN_LOONGSON3A)) ? MO_UNALN : MO_ALIGN; | 20 | } |
27 | |||
28 | + /* | ||
29 | + * Execute a branch and its delay slot as a single instruction. | ||
30 | + * This is what GDB expects and is consistent with what the | ||
31 | + * hardware does (e.g. if a delay slot instruction faults, the | ||
32 | + * reported PC is the PC of the branch). | ||
33 | + */ | ||
34 | + if (ctx->base.singlestep_enabled && (ctx->hflags & MIPS_HFLAG_BMASK)) { | ||
35 | + ctx->base.max_insns = 2; | ||
36 | + } | ||
37 | + | ||
38 | LOG_DISAS("\ntb %p idx %d hflags %04x\n", ctx->base.tb, ctx->mem_idx, | ||
39 | ctx->hflags); | ||
40 | } | ||
41 | @@ -XXX,XX +XXX,XX @@ static void mips_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) | ||
42 | if (ctx->base.is_jmp != DISAS_NEXT) { | ||
43 | return; | ||
44 | } | 21 | } |
45 | + | 22 | + |
46 | /* | 23 | page_set_flags(start, start + len, page_flags); |
47 | - * Execute a branch and its delay slot as a single instruction. | 24 | - mmap_unlock(); |
48 | - * This is what GDB expects and is consistent with what the | 25 | - return 0; |
49 | - * hardware does (e.g. if a delay slot instruction faults, the | 26 | + tb_invalidate_phys_range(start, start + len); |
50 | - * reported PC is the PC of the branch). | 27 | + ret = 0; |
51 | + * End the TB on (most) page crossings. | 28 | + |
52 | + * See mips_tr_init_disas_context about single-stepping a branch | 29 | error: |
53 | + * together with its delay slot. | 30 | mmap_unlock(); |
54 | */ | 31 | return ret; |
55 | - if (ctx->base.singlestep_enabled && | ||
56 | - (ctx->hflags & MIPS_HFLAG_BMASK) == 0) { | ||
57 | - ctx->base.is_jmp = DISAS_TOO_MANY; | ||
58 | - } | ||
59 | - if (ctx->base.pc_next - ctx->page_start >= TARGET_PAGE_SIZE) { | ||
60 | + if (ctx->base.pc_next - ctx->page_start >= TARGET_PAGE_SIZE | ||
61 | + && !ctx->base.singlestep_enabled) { | ||
62 | ctx->base.is_jmp = DISAS_TOO_MANY; | ||
63 | } | ||
64 | } | ||
65 | -- | 32 | -- |
66 | 2.25.1 | 33 | 2.34.1 |
67 | |||
68 | diff view generated by jsdifflib |
1 | GDB single-stepping is now handled generically. | 1 | We're about to start validating PAGE_EXEC, which means |
---|---|---|---|
2 | that we've got to put this code into a section that is | ||
3 | both writable and executable. | ||
2 | 4 | ||
5 | Note that this test did not run on hardware beforehand either. | ||
6 | |||
7 | Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
8 | Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 10 | --- |
5 | target/xtensa/translate.c | 25 ++++++++----------------- | 11 | tests/tcg/i386/test-i386.c | 2 +- |
6 | 1 file changed, 8 insertions(+), 17 deletions(-) | 12 | 1 file changed, 1 insertion(+), 1 deletion(-) |
7 | 13 | ||
8 | diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c | 14 | diff --git a/tests/tcg/i386/test-i386.c b/tests/tcg/i386/test-i386.c |
9 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/target/xtensa/translate.c | 16 | --- a/tests/tcg/i386/test-i386.c |
11 | +++ b/target/xtensa/translate.c | 17 | +++ b/tests/tcg/i386/test-i386.c |
12 | @@ -XXX,XX +XXX,XX @@ static void gen_jump_slot(DisasContext *dc, TCGv dest, int slot) | 18 | @@ -XXX,XX +XXX,XX @@ uint8_t code[] = { |
13 | if (dc->icount) { | 19 | 0xc3, /* ret */ |
14 | tcg_gen_mov_i32(cpu_SR[ICOUNT], dc->next_icount); | 20 | }; |
15 | } | 21 | |
16 | - if (dc->base.singlestep_enabled) { | 22 | -asm(".section \".data\"\n" |
17 | - gen_exception(dc, EXCP_DEBUG); | 23 | +asm(".section \".data_x\",\"awx\"\n" |
18 | + if (dc->op_flags & XTENSA_OP_POSTPROCESS) { | 24 | "smc_code2:\n" |
19 | + slot = gen_postprocess(dc, slot); | 25 | "movl 4(%esp), %eax\n" |
20 | + } | 26 | "movl %eax, smc_patch_addr2 + 1\n" |
21 | + if (slot >= 0) { | ||
22 | + tcg_gen_goto_tb(slot); | ||
23 | + tcg_gen_exit_tb(dc->base.tb, slot); | ||
24 | } else { | ||
25 | - if (dc->op_flags & XTENSA_OP_POSTPROCESS) { | ||
26 | - slot = gen_postprocess(dc, slot); | ||
27 | - } | ||
28 | - if (slot >= 0) { | ||
29 | - tcg_gen_goto_tb(slot); | ||
30 | - tcg_gen_exit_tb(dc->base.tb, slot); | ||
31 | - } else { | ||
32 | - tcg_gen_exit_tb(NULL, 0); | ||
33 | - } | ||
34 | + tcg_gen_exit_tb(NULL, 0); | ||
35 | } | ||
36 | dc->base.is_jmp = DISAS_NORETURN; | ||
37 | } | ||
38 | @@ -XXX,XX +XXX,XX @@ static void xtensa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu) | ||
39 | case DISAS_NORETURN: | ||
40 | break; | ||
41 | case DISAS_TOO_MANY: | ||
42 | - if (dc->base.singlestep_enabled) { | ||
43 | - tcg_gen_movi_i32(cpu_pc, dc->pc); | ||
44 | - gen_exception(dc, EXCP_DEBUG); | ||
45 | - } else { | ||
46 | - gen_jumpi(dc, dc->pc, 0); | ||
47 | - } | ||
48 | + gen_jumpi(dc, dc->pc, 0); | ||
49 | break; | ||
50 | default: | ||
51 | g_assert_not_reached(); | ||
52 | -- | 27 | -- |
53 | 2.25.1 | 28 | 2.34.1 |
54 | |||
55 | diff view generated by jsdifflib |
1 | GDB single-stepping is now handled generically. | 1 | From: Ilya Leoshkevich <iii@linux.ibm.com> |
---|---|---|---|
2 | 2 | ||
3 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 3 | Introduce a function that checks whether a given address is on the same |
4 | page as where disassembly started. Having it improves readability of | ||
5 | the following patches. | ||
6 | |||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
9 | Message-Id: <20220811095534.241224-3-iii@linux.ibm.com> | ||
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | [rth: Make the DisasContextBase parameter const.] | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 12 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | --- | 13 | --- |
6 | target/openrisc/translate.c | 18 +++--------------- | 14 | include/exec/translator.h | 10 ++++++++++ |
7 | 1 file changed, 3 insertions(+), 15 deletions(-) | 15 | 1 file changed, 10 insertions(+) |
8 | 16 | ||
9 | diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c | 17 | diff --git a/include/exec/translator.h b/include/exec/translator.h |
10 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
11 | --- a/target/openrisc/translate.c | 19 | --- a/include/exec/translator.h |
12 | +++ b/target/openrisc/translate.c | 20 | +++ b/include/exec/translator.h |
13 | @@ -XXX,XX +XXX,XX @@ static void openrisc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) | 21 | @@ -XXX,XX +XXX,XX @@ FOR_EACH_TRANSLATOR_LD(GEN_TRANSLATOR_LD) |
14 | /* The jump destination is indirect/computed; use jmp_pc. */ | 22 | |
15 | tcg_gen_mov_tl(cpu_pc, jmp_pc); | 23 | #undef GEN_TRANSLATOR_LD |
16 | tcg_gen_discard_tl(jmp_pc); | 24 | |
17 | - if (unlikely(dc->base.singlestep_enabled)) { | 25 | +/* |
18 | - gen_exception(dc, EXCP_DEBUG); | 26 | + * Return whether addr is on the same page as where disassembly started. |
19 | - } else { | 27 | + * Translators can use this to enforce the rule that only single-insn |
20 | - tcg_gen_lookup_and_goto_ptr(); | 28 | + * translation blocks are allowed to cross page boundaries. |
21 | - } | 29 | + */ |
22 | + tcg_gen_lookup_and_goto_ptr(); | 30 | +static inline bool is_same_page(const DisasContextBase *db, target_ulong addr) |
23 | break; | 31 | +{ |
24 | } | 32 | + return ((addr ^ db->pc_first) & TARGET_PAGE_MASK) == 0; |
25 | /* The jump destination is direct; use jmp_pc_imm. | 33 | +} |
26 | @@ -XXX,XX +XXX,XX @@ static void openrisc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) | 34 | + |
27 | break; | 35 | #endif /* EXEC__TRANSLATOR_H */ |
28 | } | ||
29 | tcg_gen_movi_tl(cpu_pc, jmp_dest); | ||
30 | - if (unlikely(dc->base.singlestep_enabled)) { | ||
31 | - gen_exception(dc, EXCP_DEBUG); | ||
32 | - } else { | ||
33 | - tcg_gen_lookup_and_goto_ptr(); | ||
34 | - } | ||
35 | + tcg_gen_lookup_and_goto_ptr(); | ||
36 | break; | ||
37 | |||
38 | case DISAS_EXIT: | ||
39 | - if (unlikely(dc->base.singlestep_enabled)) { | ||
40 | - gen_exception(dc, EXCP_DEBUG); | ||
41 | - } else { | ||
42 | - tcg_gen_exit_tb(NULL, 0); | ||
43 | - } | ||
44 | + tcg_gen_exit_tb(NULL, 0); | ||
45 | break; | ||
46 | default: | ||
47 | g_assert_not_reached(); | ||
48 | -- | 36 | -- |
49 | 2.25.1 | 37 | 2.34.1 |
50 | |||
51 | diff view generated by jsdifflib |
1 | GDB single-stepping is now handled generically. | 1 | The current implementation is a no-op, simply returning addr. |
---|---|---|---|
2 | This is incorrect, because we ought to be checking the page | ||
3 | permissions for execution. | ||
2 | 4 | ||
3 | Acked-by: Laurent Vivier <laurent@vivier.eu> | 5 | Make get_page_addr_code inline for both implementations. |
6 | |||
7 | Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
8 | Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
9 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | --- | 11 | --- |
6 | target/m68k/translate.c | 44 +++++++++-------------------------------- | 12 | include/exec/exec-all.h | 85 ++++++++++++++--------------------------- |
7 | 1 file changed, 9 insertions(+), 35 deletions(-) | 13 | accel/tcg/cputlb.c | 5 --- |
14 | accel/tcg/user-exec.c | 14 +++++++ | ||
15 | 3 files changed, 42 insertions(+), 62 deletions(-) | ||
8 | 16 | ||
9 | diff --git a/target/m68k/translate.c b/target/m68k/translate.c | 17 | diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h |
10 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
11 | --- a/target/m68k/translate.c | 19 | --- a/include/exec/exec-all.h |
12 | +++ b/target/m68k/translate.c | 20 | +++ b/include/exec/exec-all.h |
13 | @@ -XXX,XX +XXX,XX @@ static void do_writebacks(DisasContext *s) | 21 | @@ -XXX,XX +XXX,XX @@ struct MemoryRegionSection *iotlb_to_section(CPUState *cpu, |
14 | } | 22 | hwaddr index, MemTxAttrs attrs); |
23 | #endif | ||
24 | |||
25 | -#if defined(CONFIG_USER_ONLY) | ||
26 | -void mmap_lock(void); | ||
27 | -void mmap_unlock(void); | ||
28 | -bool have_mmap_lock(void); | ||
29 | - | ||
30 | /** | ||
31 | - * get_page_addr_code() - user-mode version | ||
32 | + * get_page_addr_code_hostp() | ||
33 | * @env: CPUArchState | ||
34 | * @addr: guest virtual address of guest code | ||
35 | * | ||
36 | - * Returns @addr. | ||
37 | + * See get_page_addr_code() (full-system version) for documentation on the | ||
38 | + * return value. | ||
39 | + * | ||
40 | + * Sets *@hostp (when @hostp is non-NULL) as follows. | ||
41 | + * If the return value is -1, sets *@hostp to NULL. Otherwise, sets *@hostp | ||
42 | + * to the host address where @addr's content is kept. | ||
43 | + * | ||
44 | + * Note: this function can trigger an exception. | ||
45 | + */ | ||
46 | +tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, | ||
47 | + void **hostp); | ||
48 | + | ||
49 | +/** | ||
50 | + * get_page_addr_code() | ||
51 | + * @env: CPUArchState | ||
52 | + * @addr: guest virtual address of guest code | ||
53 | + * | ||
54 | + * If we cannot translate and execute from the entire RAM page, or if | ||
55 | + * the region is not backed by RAM, returns -1. Otherwise, returns the | ||
56 | + * ram_addr_t corresponding to the guest code at @addr. | ||
57 | + * | ||
58 | + * Note: this function can trigger an exception. | ||
59 | */ | ||
60 | static inline tb_page_addr_t get_page_addr_code(CPUArchState *env, | ||
61 | target_ulong addr) | ||
62 | { | ||
63 | - return addr; | ||
64 | + return get_page_addr_code_hostp(env, addr, NULL); | ||
15 | } | 65 | } |
16 | 66 | ||
17 | -static bool is_singlestepping(DisasContext *s) | 67 | -/** |
68 | - * get_page_addr_code_hostp() - user-mode version | ||
69 | - * @env: CPUArchState | ||
70 | - * @addr: guest virtual address of guest code | ||
71 | - * | ||
72 | - * Returns @addr. | ||
73 | - * | ||
74 | - * If @hostp is non-NULL, sets *@hostp to the host address where @addr's content | ||
75 | - * is kept. | ||
76 | - */ | ||
77 | -static inline tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, | ||
78 | - target_ulong addr, | ||
79 | - void **hostp) | ||
18 | -{ | 80 | -{ |
19 | - /* | 81 | - if (hostp) { |
20 | - * Return true if we are singlestepping either because of | 82 | - *hostp = g2h_untagged(addr); |
21 | - * architectural singlestep or QEMU gdbstub singlestep. This does | 83 | - } |
22 | - * not include the command line '-singlestep' mode which is rather | 84 | - return addr; |
23 | - * misnamed as it only means "one instruction per TB" and doesn't | 85 | -} |
24 | - * affect the code we generate. | 86 | +#if defined(CONFIG_USER_ONLY) |
25 | - */ | 87 | +void mmap_lock(void); |
26 | - return s->base.singlestep_enabled || s->ss_active; | 88 | +void mmap_unlock(void); |
89 | +bool have_mmap_lock(void); | ||
90 | |||
91 | /** | ||
92 | * adjust_signal_pc: | ||
93 | @@ -XXX,XX +XXX,XX @@ G_NORETURN void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr, | ||
94 | static inline void mmap_lock(void) {} | ||
95 | static inline void mmap_unlock(void) {} | ||
96 | |||
97 | -/** | ||
98 | - * get_page_addr_code() - full-system version | ||
99 | - * @env: CPUArchState | ||
100 | - * @addr: guest virtual address of guest code | ||
101 | - * | ||
102 | - * If we cannot translate and execute from the entire RAM page, or if | ||
103 | - * the region is not backed by RAM, returns -1. Otherwise, returns the | ||
104 | - * ram_addr_t corresponding to the guest code at @addr. | ||
105 | - * | ||
106 | - * Note: this function can trigger an exception. | ||
107 | - */ | ||
108 | -tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr); | ||
109 | - | ||
110 | -/** | ||
111 | - * get_page_addr_code_hostp() - full-system version | ||
112 | - * @env: CPUArchState | ||
113 | - * @addr: guest virtual address of guest code | ||
114 | - * | ||
115 | - * See get_page_addr_code() (full-system version) for documentation on the | ||
116 | - * return value. | ||
117 | - * | ||
118 | - * Sets *@hostp (when @hostp is non-NULL) as follows. | ||
119 | - * If the return value is -1, sets *@hostp to NULL. Otherwise, sets *@hostp | ||
120 | - * to the host address where @addr's content is kept. | ||
121 | - * | ||
122 | - * Note: this function can trigger an exception. | ||
123 | - */ | ||
124 | -tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, | ||
125 | - void **hostp); | ||
126 | - | ||
127 | void tlb_reset_dirty(CPUState *cpu, ram_addr_t start1, ram_addr_t length); | ||
128 | void tlb_set_dirty(CPUState *cpu, target_ulong vaddr); | ||
129 | |||
130 | diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c | ||
131 | index XXXXXXX..XXXXXXX 100644 | ||
132 | --- a/accel/tcg/cputlb.c | ||
133 | +++ b/accel/tcg/cputlb.c | ||
134 | @@ -XXX,XX +XXX,XX @@ tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, | ||
135 | return qemu_ram_addr_from_host_nofail(p); | ||
136 | } | ||
137 | |||
138 | -tb_page_addr_t get_page_addr_code(CPUArchState *env, target_ulong addr) | ||
139 | -{ | ||
140 | - return get_page_addr_code_hostp(env, addr, NULL); | ||
27 | -} | 141 | -} |
28 | - | 142 | - |
29 | /* is_jmp field values */ | 143 | static void notdirty_write(CPUState *cpu, vaddr mem_vaddr, unsigned size, |
30 | #define DISAS_JUMP DISAS_TARGET_0 /* only pc was modified dynamically */ | 144 | CPUIOTLBEntry *iotlbentry, uintptr_t retaddr) |
31 | #define DISAS_EXIT DISAS_TARGET_1 /* cpu state was modified dynamically */ | 145 | { |
32 | @@ -XXX,XX +XXX,XX @@ static void gen_exception(DisasContext *s, uint32_t dest, int nr) | 146 | diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c |
33 | s->base.is_jmp = DISAS_NORETURN; | 147 | index XXXXXXX..XXXXXXX 100644 |
148 | --- a/accel/tcg/user-exec.c | ||
149 | +++ b/accel/tcg/user-exec.c | ||
150 | @@ -XXX,XX +XXX,XX @@ void *probe_access(CPUArchState *env, target_ulong addr, int size, | ||
151 | return size ? g2h(env_cpu(env), addr) : NULL; | ||
34 | } | 152 | } |
35 | 153 | ||
36 | -static void gen_singlestep_exception(DisasContext *s) | 154 | +tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, |
37 | -{ | 155 | + void **hostp) |
38 | - /* | 156 | +{ |
39 | - * Generate the right kind of exception for singlestep, which is | 157 | + int flags; |
40 | - * either the architectural singlestep or EXCP_DEBUG for QEMU's | 158 | + |
41 | - * gdb singlestepping. | 159 | + flags = probe_access_internal(env, addr, 1, MMU_INST_FETCH, false, 0); |
42 | - */ | 160 | + g_assert(flags == 0); |
43 | - if (s->ss_active) { | 161 | + |
44 | - gen_raise_exception(EXCP_TRACE); | 162 | + if (hostp) { |
45 | - } else { | 163 | + *hostp = g2h_untagged(addr); |
46 | - gen_raise_exception(EXCP_DEBUG); | 164 | + } |
47 | - } | 165 | + return addr; |
48 | -} | 166 | +} |
49 | - | 167 | + |
50 | static inline void gen_addr_fault(DisasContext *s) | 168 | /* The softmmu versions of these helpers are in cputlb.c. */ |
51 | { | 169 | |
52 | gen_exception(s, s->base.pc_next, EXCP_ADDRESS); | 170 | /* |
53 | @@ -XXX,XX +XXX,XX @@ static void gen_exit_tb(DisasContext *s) | ||
54 | /* Generate a jump to an immediate address. */ | ||
55 | static void gen_jmp_tb(DisasContext *s, int n, uint32_t dest) | ||
56 | { | ||
57 | - if (unlikely(is_singlestepping(s))) { | ||
58 | + if (unlikely(s->ss_active)) { | ||
59 | update_cc_op(s); | ||
60 | tcg_gen_movi_i32(QREG_PC, dest); | ||
61 | - gen_singlestep_exception(s); | ||
62 | + gen_raise_exception(EXCP_TRACE); | ||
63 | } else if (translator_use_goto_tb(&s->base, dest)) { | ||
64 | tcg_gen_goto_tb(n); | ||
65 | tcg_gen_movi_i32(QREG_PC, dest); | ||
66 | @@ -XXX,XX +XXX,XX @@ static void m68k_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu) | ||
67 | |||
68 | dc->ss_active = (M68K_SR_TRACE(env->sr) == M68K_SR_TRACE_ANY_INS); | ||
69 | /* If architectural single step active, limit to 1 */ | ||
70 | - if (is_singlestepping(dc)) { | ||
71 | + if (dc->ss_active) { | ||
72 | dc->base.max_insns = 1; | ||
73 | } | ||
74 | } | ||
75 | @@ -XXX,XX +XXX,XX @@ static void m68k_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu) | ||
76 | break; | ||
77 | case DISAS_TOO_MANY: | ||
78 | update_cc_op(dc); | ||
79 | - if (is_singlestepping(dc)) { | ||
80 | + if (dc->ss_active) { | ||
81 | tcg_gen_movi_i32(QREG_PC, dc->pc); | ||
82 | - gen_singlestep_exception(dc); | ||
83 | + gen_raise_exception(EXCP_TRACE); | ||
84 | } else { | ||
85 | gen_jmp_tb(dc, 0, dc->pc); | ||
86 | } | ||
87 | break; | ||
88 | case DISAS_JUMP: | ||
89 | /* We updated CC_OP and PC in gen_jmp/gen_jmp_im. */ | ||
90 | - if (is_singlestepping(dc)) { | ||
91 | - gen_singlestep_exception(dc); | ||
92 | + if (dc->ss_active) { | ||
93 | + gen_raise_exception(EXCP_TRACE); | ||
94 | } else { | ||
95 | tcg_gen_lookup_and_goto_ptr(); | ||
96 | } | ||
97 | @@ -XXX,XX +XXX,XX @@ static void m68k_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu) | ||
98 | * We updated CC_OP and PC in gen_exit_tb, but also modified | ||
99 | * other state that may require returning to the main loop. | ||
100 | */ | ||
101 | - if (is_singlestepping(dc)) { | ||
102 | - gen_singlestep_exception(dc); | ||
103 | + if (dc->ss_active) { | ||
104 | + gen_raise_exception(EXCP_TRACE); | ||
105 | } else { | ||
106 | tcg_gen_exit_tb(NULL, 0); | ||
107 | } | ||
108 | -- | 171 | -- |
109 | 2.25.1 | 172 | 2.34.1 |
110 | |||
111 | diff view generated by jsdifflib |
1 | GDB single-stepping is now handled generically. | 1 | The mmap_lock is held around tb_gen_code. While the comment |
---|---|---|---|
2 | is correct that the lock is dropped when tb_gen_code runs out | ||
3 | of memory, the lock is *not* dropped when an exception is | ||
4 | raised reading code for translation. | ||
2 | 5 | ||
6 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
8 | Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 10 | --- |
5 | target/microblaze/translate.c | 14 ++------------ | 11 | accel/tcg/cpu-exec.c | 12 ++++++------ |
6 | 1 file changed, 2 insertions(+), 12 deletions(-) | 12 | accel/tcg/user-exec.c | 3 --- |
13 | 2 files changed, 6 insertions(+), 9 deletions(-) | ||
7 | 14 | ||
8 | diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c | 15 | diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c |
9 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/target/microblaze/translate.c | 17 | --- a/accel/tcg/cpu-exec.c |
11 | +++ b/target/microblaze/translate.c | 18 | +++ b/accel/tcg/cpu-exec.c |
12 | @@ -XXX,XX +XXX,XX @@ static void gen_raise_hw_excp(DisasContext *dc, uint32_t esr_ec) | 19 | @@ -XXX,XX +XXX,XX @@ void cpu_exec_step_atomic(CPUState *cpu) |
13 | 20 | cpu_tb_exec(cpu, tb, &tb_exit); | |
14 | static void gen_goto_tb(DisasContext *dc, int n, target_ulong dest) | 21 | cpu_exec_exit(cpu); |
15 | { | 22 | } else { |
16 | - if (dc->base.singlestep_enabled) { | 23 | - /* |
17 | - TCGv_i32 tmp = tcg_const_i32(EXCP_DEBUG); | 24 | - * The mmap_lock is dropped by tb_gen_code if it runs out of |
18 | - tcg_gen_movi_i32(cpu_pc, dest); | 25 | - * memory. |
19 | - gen_helper_raise_exception(cpu_env, tmp); | 26 | - */ |
20 | - tcg_temp_free_i32(tmp); | 27 | #ifndef CONFIG_SOFTMMU |
21 | - } else if (translator_use_goto_tb(&dc->base, dest)) { | 28 | clear_helper_retaddr(); |
22 | + if (translator_use_goto_tb(&dc->base, dest)) { | 29 | - tcg_debug_assert(!have_mmap_lock()); |
23 | tcg_gen_goto_tb(n); | 30 | + if (have_mmap_lock()) { |
24 | tcg_gen_movi_i32(cpu_pc, dest); | 31 | + mmap_unlock(); |
25 | tcg_gen_exit_tb(dc->base.tb, n); | 32 | + } |
26 | @@ -XXX,XX +XXX,XX @@ static void mb_tr_tb_stop(DisasContextBase *dcb, CPUState *cs) | 33 | #endif |
27 | /* Indirect jump (or direct jump w/ goto_tb disabled) */ | 34 | if (qemu_mutex_iothread_locked()) { |
28 | tcg_gen_mov_i32(cpu_pc, cpu_btarget); | 35 | qemu_mutex_unlock_iothread(); |
29 | tcg_gen_discard_i32(cpu_btarget); | 36 | @@ -XXX,XX +XXX,XX @@ int cpu_exec(CPUState *cpu) |
30 | - | 37 | |
31 | - if (unlikely(cs->singlestep_enabled)) { | 38 | #ifndef CONFIG_SOFTMMU |
32 | - gen_raise_exception(dc, EXCP_DEBUG); | 39 | clear_helper_retaddr(); |
33 | - } else { | 40 | - tcg_debug_assert(!have_mmap_lock()); |
34 | - tcg_gen_lookup_and_goto_ptr(); | 41 | + if (have_mmap_lock()) { |
35 | - } | 42 | + mmap_unlock(); |
36 | + tcg_gen_lookup_and_goto_ptr(); | 43 | + } |
37 | return; | 44 | #endif |
38 | 45 | if (qemu_mutex_iothread_locked()) { | |
39 | default: | 46 | qemu_mutex_unlock_iothread(); |
47 | diff --git a/accel/tcg/user-exec.c b/accel/tcg/user-exec.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/accel/tcg/user-exec.c | ||
50 | +++ b/accel/tcg/user-exec.c | ||
51 | @@ -XXX,XX +XXX,XX @@ MMUAccessType adjust_signal_pc(uintptr_t *pc, bool is_write) | ||
52 | * (and if the translator doesn't handle page boundaries correctly | ||
53 | * there's little we can do about that here). Therefore, do not | ||
54 | * trigger the unwinder. | ||
55 | - * | ||
56 | - * Like tb_gen_code, release the memory lock before cpu_loop_exit. | ||
57 | */ | ||
58 | - mmap_unlock(); | ||
59 | *pc = 0; | ||
60 | return MMU_INST_FETCH; | ||
61 | } | ||
40 | -- | 62 | -- |
41 | 2.25.1 | 63 | 2.34.1 |
42 | |||
43 | diff view generated by jsdifflib |
1 | This reverts commit 1b36e4f5a5de585210ea95f2257839c2312be28f. | 1 | The function is not used outside of cpu-exec.c. Move it and |
---|---|---|---|
2 | its subroutines up in the file, before the first use. | ||
2 | 3 | ||
3 | Despite a comment saying why cpu_common_props cannot be placed in | 4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
4 | a file that is compiled once, it was moved anyway. Revert that. | 5 | Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> |
5 | 6 | Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> | |
6 | Since then, Property is not defined in hw/core/cpu.h, so it is now | ||
7 | easier to declare a function to install the properties rather than | ||
8 | the Property array itself. | ||
9 | |||
10 | Cc: Eduardo Habkost <ehabkost@redhat.com> | ||
11 | Suggested-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
13 | --- | 8 | --- |
14 | include/hw/core/cpu.h | 1 + | 9 | include/exec/exec-all.h | 3 - |
15 | cpu.c | 21 +++++++++++++++++++++ | 10 | accel/tcg/cpu-exec.c | 122 ++++++++++++++++++++-------------------- |
16 | hw/core/cpu-common.c | 17 +---------------- | 11 | 2 files changed, 61 insertions(+), 64 deletions(-) |
17 | 3 files changed, 23 insertions(+), 16 deletions(-) | ||
18 | 12 | ||
19 | diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h | 13 | diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h |
20 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/include/hw/core/cpu.h | 15 | --- a/include/exec/exec-all.h |
22 | +++ b/include/hw/core/cpu.h | 16 | +++ b/include/exec/exec-all.h |
23 | @@ -XXX,XX +XXX,XX @@ void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...) | 17 | @@ -XXX,XX +XXX,XX @@ void tb_invalidate_phys_addr(AddressSpace *as, hwaddr addr, MemTxAttrs attrs); |
24 | GCC_FMT_ATTR(2, 3); | 18 | #endif |
25 | 19 | void tb_flush(CPUState *cpu); | |
26 | /* $(top_srcdir)/cpu.c */ | 20 | void tb_phys_invalidate(TranslationBlock *tb, tb_page_addr_t page_addr); |
27 | +void cpu_class_init_props(DeviceClass *dc); | 21 | -TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc, |
28 | void cpu_exec_initfn(CPUState *cpu); | 22 | - target_ulong cs_base, uint32_t flags, |
29 | void cpu_exec_realizefn(CPUState *cpu, Error **errp); | 23 | - uint32_t cflags); |
30 | void cpu_exec_unrealizefn(CPUState *cpu); | 24 | void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr); |
31 | diff --git a/cpu.c b/cpu.c | 25 | |
26 | /* GETPC is the true target of the return instruction that we'll execute. */ | ||
27 | diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/cpu.c | 29 | --- a/accel/tcg/cpu-exec.c |
34 | +++ b/cpu.c | 30 | +++ b/accel/tcg/cpu-exec.c |
35 | @@ -XXX,XX +XXX,XX @@ void cpu_exec_unrealizefn(CPUState *cpu) | 31 | @@ -XXX,XX +XXX,XX @@ uint32_t curr_cflags(CPUState *cpu) |
36 | cpu_list_remove(cpu); | 32 | return cflags; |
37 | } | 33 | } |
38 | 34 | ||
39 | +static Property cpu_common_props[] = { | 35 | +struct tb_desc { |
40 | +#ifndef CONFIG_USER_ONLY | 36 | + target_ulong pc; |
41 | + /* | 37 | + target_ulong cs_base; |
42 | + * Create a memory property for softmmu CPU object, | 38 | + CPUArchState *env; |
43 | + * so users can wire up its memory. (This can't go in hw/core/cpu.c | 39 | + tb_page_addr_t phys_page1; |
44 | + * because that file is compiled only once for both user-mode | 40 | + uint32_t flags; |
45 | + * and system builds.) The default if no link is set up is to use | 41 | + uint32_t cflags; |
46 | + * the system address space. | 42 | + uint32_t trace_vcpu_dstate; |
47 | + */ | ||
48 | + DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION, | ||
49 | + MemoryRegion *), | ||
50 | +#endif | ||
51 | + DEFINE_PROP_BOOL("start-powered-off", CPUState, start_powered_off, false), | ||
52 | + DEFINE_PROP_END_OF_LIST(), | ||
53 | +}; | 43 | +}; |
54 | + | 44 | + |
55 | +void cpu_class_init_props(DeviceClass *dc) | 45 | +static bool tb_lookup_cmp(const void *p, const void *d) |
56 | +{ | 46 | +{ |
57 | + device_class_set_props(dc, cpu_common_props); | 47 | + const TranslationBlock *tb = p; |
48 | + const struct tb_desc *desc = d; | ||
49 | + | ||
50 | + if (tb->pc == desc->pc && | ||
51 | + tb->page_addr[0] == desc->phys_page1 && | ||
52 | + tb->cs_base == desc->cs_base && | ||
53 | + tb->flags == desc->flags && | ||
54 | + tb->trace_vcpu_dstate == desc->trace_vcpu_dstate && | ||
55 | + tb_cflags(tb) == desc->cflags) { | ||
56 | + /* check next page if needed */ | ||
57 | + if (tb->page_addr[1] == -1) { | ||
58 | + return true; | ||
59 | + } else { | ||
60 | + tb_page_addr_t phys_page2; | ||
61 | + target_ulong virt_page2; | ||
62 | + | ||
63 | + virt_page2 = (desc->pc & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; | ||
64 | + phys_page2 = get_page_addr_code(desc->env, virt_page2); | ||
65 | + if (tb->page_addr[1] == phys_page2) { | ||
66 | + return true; | ||
67 | + } | ||
68 | + } | ||
69 | + } | ||
70 | + return false; | ||
58 | +} | 71 | +} |
59 | + | 72 | + |
60 | void cpu_exec_initfn(CPUState *cpu) | 73 | +static TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc, |
61 | { | 74 | + target_ulong cs_base, uint32_t flags, |
62 | cpu->as = NULL; | 75 | + uint32_t cflags) |
63 | diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c | 76 | +{ |
64 | index XXXXXXX..XXXXXXX 100644 | 77 | + tb_page_addr_t phys_pc; |
65 | --- a/hw/core/cpu-common.c | 78 | + struct tb_desc desc; |
66 | +++ b/hw/core/cpu-common.c | 79 | + uint32_t h; |
67 | @@ -XXX,XX +XXX,XX @@ static int64_t cpu_common_get_arch_id(CPUState *cpu) | 80 | + |
68 | return cpu->cpu_index; | 81 | + desc.env = cpu->env_ptr; |
82 | + desc.cs_base = cs_base; | ||
83 | + desc.flags = flags; | ||
84 | + desc.cflags = cflags; | ||
85 | + desc.trace_vcpu_dstate = *cpu->trace_dstate; | ||
86 | + desc.pc = pc; | ||
87 | + phys_pc = get_page_addr_code(desc.env, pc); | ||
88 | + if (phys_pc == -1) { | ||
89 | + return NULL; | ||
90 | + } | ||
91 | + desc.phys_page1 = phys_pc & TARGET_PAGE_MASK; | ||
92 | + h = tb_hash_func(phys_pc, pc, flags, cflags, *cpu->trace_dstate); | ||
93 | + return qht_lookup_custom(&tb_ctx.htable, &desc, h, tb_lookup_cmp); | ||
94 | +} | ||
95 | + | ||
96 | /* Might cause an exception, so have a longjmp destination ready */ | ||
97 | static inline TranslationBlock *tb_lookup(CPUState *cpu, target_ulong pc, | ||
98 | target_ulong cs_base, | ||
99 | @@ -XXX,XX +XXX,XX @@ void cpu_exec_step_atomic(CPUState *cpu) | ||
100 | end_exclusive(); | ||
69 | } | 101 | } |
70 | 102 | ||
71 | -static Property cpu_common_props[] = { | 103 | -struct tb_desc { |
72 | -#ifndef CONFIG_USER_ONLY | 104 | - target_ulong pc; |
73 | - /* Create a memory property for softmmu CPU object, | 105 | - target_ulong cs_base; |
74 | - * so users can wire up its memory. (This can't go in hw/core/cpu.c | 106 | - CPUArchState *env; |
75 | - * because that file is compiled only once for both user-mode | 107 | - tb_page_addr_t phys_page1; |
76 | - * and system builds.) The default if no link is set up is to use | 108 | - uint32_t flags; |
77 | - * the system address space. | 109 | - uint32_t cflags; |
78 | - */ | 110 | - uint32_t trace_vcpu_dstate; |
79 | - DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION, | ||
80 | - MemoryRegion *), | ||
81 | -#endif | ||
82 | - DEFINE_PROP_BOOL("start-powered-off", CPUState, start_powered_off, false), | ||
83 | - DEFINE_PROP_END_OF_LIST(), | ||
84 | -}; | 111 | -}; |
85 | - | 112 | - |
86 | static void cpu_class_init(ObjectClass *klass, void *data) | 113 | -static bool tb_lookup_cmp(const void *p, const void *d) |
114 | -{ | ||
115 | - const TranslationBlock *tb = p; | ||
116 | - const struct tb_desc *desc = d; | ||
117 | - | ||
118 | - if (tb->pc == desc->pc && | ||
119 | - tb->page_addr[0] == desc->phys_page1 && | ||
120 | - tb->cs_base == desc->cs_base && | ||
121 | - tb->flags == desc->flags && | ||
122 | - tb->trace_vcpu_dstate == desc->trace_vcpu_dstate && | ||
123 | - tb_cflags(tb) == desc->cflags) { | ||
124 | - /* check next page if needed */ | ||
125 | - if (tb->page_addr[1] == -1) { | ||
126 | - return true; | ||
127 | - } else { | ||
128 | - tb_page_addr_t phys_page2; | ||
129 | - target_ulong virt_page2; | ||
130 | - | ||
131 | - virt_page2 = (desc->pc & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; | ||
132 | - phys_page2 = get_page_addr_code(desc->env, virt_page2); | ||
133 | - if (tb->page_addr[1] == phys_page2) { | ||
134 | - return true; | ||
135 | - } | ||
136 | - } | ||
137 | - } | ||
138 | - return false; | ||
139 | -} | ||
140 | - | ||
141 | -TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc, | ||
142 | - target_ulong cs_base, uint32_t flags, | ||
143 | - uint32_t cflags) | ||
144 | -{ | ||
145 | - tb_page_addr_t phys_pc; | ||
146 | - struct tb_desc desc; | ||
147 | - uint32_t h; | ||
148 | - | ||
149 | - desc.env = cpu->env_ptr; | ||
150 | - desc.cs_base = cs_base; | ||
151 | - desc.flags = flags; | ||
152 | - desc.cflags = cflags; | ||
153 | - desc.trace_vcpu_dstate = *cpu->trace_dstate; | ||
154 | - desc.pc = pc; | ||
155 | - phys_pc = get_page_addr_code(desc.env, pc); | ||
156 | - if (phys_pc == -1) { | ||
157 | - return NULL; | ||
158 | - } | ||
159 | - desc.phys_page1 = phys_pc & TARGET_PAGE_MASK; | ||
160 | - h = tb_hash_func(phys_pc, pc, flags, cflags, *cpu->trace_dstate); | ||
161 | - return qht_lookup_custom(&tb_ctx.htable, &desc, h, tb_lookup_cmp); | ||
162 | -} | ||
163 | - | ||
164 | void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr) | ||
87 | { | 165 | { |
88 | DeviceClass *dc = DEVICE_CLASS(klass); | 166 | if (TCG_TARGET_HAS_direct_jump) { |
89 | @@ -XXX,XX +XXX,XX @@ static void cpu_class_init(ObjectClass *klass, void *data) | ||
90 | dc->realize = cpu_common_realizefn; | ||
91 | dc->unrealize = cpu_common_unrealizefn; | ||
92 | dc->reset = cpu_common_reset; | ||
93 | - device_class_set_props(dc, cpu_common_props); | ||
94 | + cpu_class_init_props(dc); | ||
95 | /* | ||
96 | * Reason: CPUs still need special care by board code: wiring up | ||
97 | * IRQs, adding reset handlers, halting non-first CPUs, ... | ||
98 | -- | 167 | -- |
99 | 2.25.1 | 168 | 2.34.1 |
100 | |||
101 | diff view generated by jsdifflib |
1 | We have already set DISAS_NORETURN in generate_exception, | 1 | The base qemu_ram_addr_from_host function is already in |
---|---|---|---|
2 | which makes the exit_tb unreachable. | 2 | softmmu/physmem.c; move the nofail version to be adjacent. |
3 | 3 | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
5 | Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
6 | Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | --- | 8 | --- |
7 | target/riscv/insn_trans/trans_privileged.c.inc | 6 +----- | 9 | include/exec/cpu-common.h | 1 + |
8 | 1 file changed, 1 insertion(+), 5 deletions(-) | 10 | accel/tcg/cputlb.c | 12 ------------ |
11 | softmmu/physmem.c | 12 ++++++++++++ | ||
12 | 3 files changed, 13 insertions(+), 12 deletions(-) | ||
9 | 13 | ||
10 | diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc | 14 | diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h |
11 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/target/riscv/insn_trans/trans_privileged.c.inc | 16 | --- a/include/exec/cpu-common.h |
13 | +++ b/target/riscv/insn_trans/trans_privileged.c.inc | 17 | +++ b/include/exec/cpu-common.h |
14 | @@ -XXX,XX +XXX,XX @@ static bool trans_ecall(DisasContext *ctx, arg_ecall *a) | 18 | @@ -XXX,XX +XXX,XX @@ typedef uintptr_t ram_addr_t; |
15 | { | 19 | void qemu_ram_remap(ram_addr_t addr, ram_addr_t length); |
16 | /* always generates U-level ECALL, fixed in do_interrupt handler */ | 20 | /* This should not be used by devices. */ |
17 | generate_exception(ctx, RISCV_EXCP_U_ECALL); | 21 | ram_addr_t qemu_ram_addr_from_host(void *ptr); |
18 | - exit_tb(ctx); /* no chaining */ | 22 | +ram_addr_t qemu_ram_addr_from_host_nofail(void *ptr); |
19 | - ctx->base.is_jmp = DISAS_NORETURN; | 23 | RAMBlock *qemu_ram_block_by_name(const char *name); |
20 | return true; | 24 | RAMBlock *qemu_ram_block_from_host(void *ptr, bool round_offset, |
25 | ram_addr_t *offset); | ||
26 | diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/accel/tcg/cputlb.c | ||
29 | +++ b/accel/tcg/cputlb.c | ||
30 | @@ -XXX,XX +XXX,XX @@ void tlb_set_page(CPUState *cpu, target_ulong vaddr, | ||
31 | prot, mmu_idx, size); | ||
21 | } | 32 | } |
22 | 33 | ||
23 | @@ -XXX,XX +XXX,XX @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a) | 34 | -static inline ram_addr_t qemu_ram_addr_from_host_nofail(void *ptr) |
24 | post = opcode_at(&ctx->base, post_addr); | 35 | -{ |
25 | } | 36 | - ram_addr_t ram_addr; |
26 | 37 | - | |
27 | - if (pre == 0x01f01013 && ebreak == 0x00100073 && post == 0x40705013) { | 38 | - ram_addr = qemu_ram_addr_from_host(ptr); |
28 | + if (pre == 0x01f01013 && ebreak == 0x00100073 && post == 0x40705013) { | 39 | - if (ram_addr == RAM_ADDR_INVALID) { |
29 | generate_exception(ctx, RISCV_EXCP_SEMIHOST); | 40 | - error_report("Bad ram pointer %p", ptr); |
30 | } else { | 41 | - abort(); |
31 | generate_exception(ctx, RISCV_EXCP_BREAKPOINT); | 42 | - } |
32 | } | 43 | - return ram_addr; |
33 | - exit_tb(ctx); /* no chaining */ | 44 | -} |
34 | - ctx->base.is_jmp = DISAS_NORETURN; | 45 | - |
35 | return true; | 46 | /* |
47 | * Note: tlb_fill() can trigger a resize of the TLB. This means that all of the | ||
48 | * caller's prior references to the TLB table (e.g. CPUTLBEntry pointers) must | ||
49 | diff --git a/softmmu/physmem.c b/softmmu/physmem.c | ||
50 | index XXXXXXX..XXXXXXX 100644 | ||
51 | --- a/softmmu/physmem.c | ||
52 | +++ b/softmmu/physmem.c | ||
53 | @@ -XXX,XX +XXX,XX @@ ram_addr_t qemu_ram_addr_from_host(void *ptr) | ||
54 | return block->offset + offset; | ||
36 | } | 55 | } |
37 | 56 | ||
57 | +ram_addr_t qemu_ram_addr_from_host_nofail(void *ptr) | ||
58 | +{ | ||
59 | + ram_addr_t ram_addr; | ||
60 | + | ||
61 | + ram_addr = qemu_ram_addr_from_host(ptr); | ||
62 | + if (ram_addr == RAM_ADDR_INVALID) { | ||
63 | + error_report("Bad ram pointer %p", ptr); | ||
64 | + abort(); | ||
65 | + } | ||
66 | + return ram_addr; | ||
67 | +} | ||
68 | + | ||
69 | static MemTxResult flatview_read(FlatView *fv, hwaddr addr, | ||
70 | MemTxAttrs attrs, void *buf, hwaddr len); | ||
71 | static MemTxResult flatview_write(FlatView *fv, hwaddr addr, MemTxAttrs attrs, | ||
38 | -- | 72 | -- |
39 | 2.25.1 | 73 | 2.34.1 |
40 | |||
41 | diff view generated by jsdifflib |
1 | GDB single-stepping is now handled generically. | 1 | Simplify the implementation of get_page_addr_code_hostp |
---|---|---|---|
2 | Reuse gen_debug_exception to handle architectural debug exceptions. | 2 | by reusing the existing probe_access infrastructure. |
3 | 3 | ||
4 | Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
5 | Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | --- | 7 | --- |
6 | target/ppc/translate.c | 38 ++++++++------------------------------ | 8 | accel/tcg/cputlb.c | 76 ++++++++++++++++------------------------------ |
7 | 1 file changed, 8 insertions(+), 30 deletions(-) | 9 | 1 file changed, 26 insertions(+), 50 deletions(-) |
8 | 10 | ||
9 | diff --git a/target/ppc/translate.c b/target/ppc/translate.c | 11 | diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c |
10 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
11 | --- a/target/ppc/translate.c | 13 | --- a/accel/tcg/cputlb.c |
12 | +++ b/target/ppc/translate.c | 14 | +++ b/accel/tcg/cputlb.c |
13 | @@ -XXX,XX +XXX,XX @@ | 15 | @@ -XXX,XX +XXX,XX @@ static bool victim_tlb_hit(CPUArchState *env, size_t mmu_idx, size_t index, |
14 | 16 | victim_tlb_hit(env, mmu_idx, index, offsetof(CPUTLBEntry, TY), \ | |
15 | #define CPU_SINGLE_STEP 0x1 | 17 | (ADDR) & TARGET_PAGE_MASK) |
16 | #define CPU_BRANCH_STEP 0x2 | 18 | |
17 | -#define GDBSTUB_SINGLE_STEP 0x4 | 19 | -/* |
18 | 20 | - * Return a ram_addr_t for the virtual address for execution. | |
19 | /* Include definitions for instructions classes and implementations flags */ | 21 | - * |
20 | /* #define PPC_DEBUG_DISAS */ | 22 | - * Return -1 if we can't translate and execute from an entire page |
21 | @@ -XXX,XX +XXX,XX @@ static uint32_t gen_prep_dbgex(DisasContext *ctx) | 23 | - * of RAM. This will force us to execute by loading and translating |
22 | 24 | - * one insn at a time, without caching. | |
23 | static void gen_debug_exception(DisasContext *ctx) | 25 | - * |
24 | { | 26 | - * NOTE: This function will trigger an exception if the page is |
25 | - gen_helper_raise_exception(cpu_env, tcg_constant_i32(EXCP_DEBUG)); | 27 | - * not executable. |
26 | + gen_helper_raise_exception(cpu_env, tcg_constant_i32(gen_prep_dbgex(ctx))); | 28 | - */ |
27 | ctx->base.is_jmp = DISAS_NORETURN; | 29 | -tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, |
28 | } | 30 | - void **hostp) |
29 | 31 | -{ | |
30 | @@ -XXX,XX +XXX,XX @@ static inline bool use_goto_tb(DisasContext *ctx, target_ulong dest) | 32 | - uintptr_t mmu_idx = cpu_mmu_index(env, true); |
31 | 33 | - uintptr_t index = tlb_index(env, mmu_idx, addr); | |
32 | static void gen_lookup_and_goto_ptr(DisasContext *ctx) | 34 | - CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr); |
33 | { | 35 | - void *p; |
34 | - int sse = ctx->singlestep_enabled; | 36 | - |
35 | - if (unlikely(sse)) { | 37 | - if (unlikely(!tlb_hit(entry->addr_code, addr))) { |
36 | - if (sse & GDBSTUB_SINGLE_STEP) { | 38 | - if (!VICTIM_TLB_HIT(addr_code, addr)) { |
37 | - gen_debug_exception(ctx); | 39 | - tlb_fill(env_cpu(env), addr, 0, MMU_INST_FETCH, mmu_idx, 0); |
38 | - } else if (sse & (CPU_SINGLE_STEP | CPU_BRANCH_STEP)) { | 40 | - index = tlb_index(env, mmu_idx, addr); |
39 | - gen_helper_raise_exception(cpu_env, tcg_constant_i32(gen_prep_dbgex(ctx))); | 41 | - entry = tlb_entry(env, mmu_idx, addr); |
40 | - } else { | 42 | - |
41 | - tcg_gen_exit_tb(NULL, 0); | 43 | - if (unlikely(entry->addr_code & TLB_INVALID_MASK)) { |
44 | - /* | ||
45 | - * The MMU protection covers a smaller range than a target | ||
46 | - * page, so we must redo the MMU check for every insn. | ||
47 | - */ | ||
48 | - return -1; | ||
49 | - } | ||
42 | - } | 50 | - } |
43 | + if (unlikely(ctx->singlestep_enabled)) { | 51 | - assert(tlb_hit(entry->addr_code, addr)); |
44 | + gen_debug_exception(ctx); | ||
45 | } else { | ||
46 | tcg_gen_lookup_and_goto_ptr(); | ||
47 | } | ||
48 | @@ -XXX,XX +XXX,XX @@ static void ppc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | ||
49 | ctx->singlestep_enabled = 0; | ||
50 | if ((hflags >> HFLAGS_SE) & 1) { | ||
51 | ctx->singlestep_enabled |= CPU_SINGLE_STEP; | ||
52 | + ctx->base.max_insns = 1; | ||
53 | } | ||
54 | if ((hflags >> HFLAGS_BE) & 1) { | ||
55 | ctx->singlestep_enabled |= CPU_BRANCH_STEP; | ||
56 | } | ||
57 | - if (unlikely(ctx->base.singlestep_enabled)) { | ||
58 | - ctx->singlestep_enabled |= GDBSTUB_SINGLE_STEP; | ||
59 | - } | 52 | - } |
60 | - | 53 | - |
61 | - if (ctx->singlestep_enabled & (CPU_SINGLE_STEP | GDBSTUB_SINGLE_STEP)) { | 54 | - if (unlikely(entry->addr_code & TLB_MMIO)) { |
62 | - ctx->base.max_insns = 1; | 55 | - /* The region is not backed by RAM. */ |
56 | - if (hostp) { | ||
57 | - *hostp = NULL; | ||
58 | - } | ||
59 | - return -1; | ||
63 | - } | 60 | - } |
61 | - | ||
62 | - p = (void *)((uintptr_t)addr + entry->addend); | ||
63 | - if (hostp) { | ||
64 | - *hostp = p; | ||
65 | - } | ||
66 | - return qemu_ram_addr_from_host_nofail(p); | ||
67 | -} | ||
68 | - | ||
69 | static void notdirty_write(CPUState *cpu, vaddr mem_vaddr, unsigned size, | ||
70 | CPUIOTLBEntry *iotlbentry, uintptr_t retaddr) | ||
71 | { | ||
72 | @@ -XXX,XX +XXX,XX @@ void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr addr, | ||
73 | return flags ? NULL : host; | ||
64 | } | 74 | } |
65 | 75 | ||
66 | static void ppc_tr_tb_start(DisasContextBase *db, CPUState *cs) | 76 | +/* |
67 | @@ -XXX,XX +XXX,XX @@ static void ppc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) | 77 | + * Return a ram_addr_t for the virtual address for execution. |
68 | DisasContext *ctx = container_of(dcbase, DisasContext, base); | 78 | + * |
69 | DisasJumpType is_jmp = ctx->base.is_jmp; | 79 | + * Return -1 if we can't translate and execute from an entire page |
70 | target_ulong nip = ctx->base.pc_next; | 80 | + * of RAM. This will force us to execute by loading and translating |
71 | - int sse; | 81 | + * one insn at a time, without caching. |
72 | 82 | + * | |
73 | if (is_jmp == DISAS_NORETURN) { | 83 | + * NOTE: This function will trigger an exception if the page is |
74 | /* We have already exited the TB. */ | 84 | + * not executable. |
75 | @@ -XXX,XX +XXX,XX @@ static void ppc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) | 85 | + */ |
76 | } | 86 | +tb_page_addr_t get_page_addr_code_hostp(CPUArchState *env, target_ulong addr, |
77 | 87 | + void **hostp) | |
78 | /* Honor single stepping. */ | 88 | +{ |
79 | - sse = ctx->singlestep_enabled & (CPU_SINGLE_STEP | GDBSTUB_SINGLE_STEP); | 89 | + void *p; |
80 | - if (unlikely(sse)) { | 90 | + |
81 | + if (unlikely(ctx->singlestep_enabled & CPU_SINGLE_STEP) | 91 | + (void)probe_access_internal(env, addr, 1, MMU_INST_FETCH, |
82 | + && (nip <= 0x100 || nip > 0xf00)) { | 92 | + cpu_mmu_index(env, true), false, &p, 0); |
83 | switch (is_jmp) { | 93 | + if (p == NULL) { |
84 | case DISAS_TOO_MANY: | 94 | + return -1; |
85 | case DISAS_EXIT_UPDATE: | 95 | + } |
86 | @@ -XXX,XX +XXX,XX @@ static void ppc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) | 96 | + if (hostp) { |
87 | g_assert_not_reached(); | 97 | + *hostp = p; |
88 | } | 98 | + } |
89 | 99 | + return qemu_ram_addr_from_host_nofail(p); | |
90 | - if (sse & GDBSTUB_SINGLE_STEP) { | 100 | +} |
91 | - gen_debug_exception(ctx); | 101 | + |
92 | - return; | 102 | #ifdef CONFIG_PLUGIN |
93 | - } | 103 | /* |
94 | - /* else CPU_SINGLE_STEP... */ | 104 | * Perform a TLB lookup and populate the qemu_plugin_hwaddr structure. |
95 | - if (nip <= 0x100 || nip > 0xf00) { | ||
96 | - gen_helper_raise_exception(cpu_env, tcg_constant_i32(gen_prep_dbgex(ctx))); | ||
97 | - return; | ||
98 | - } | ||
99 | + gen_debug_exception(ctx); | ||
100 | + return; | ||
101 | } | ||
102 | |||
103 | switch (is_jmp) { | ||
104 | -- | 105 | -- |
105 | 2.25.1 | 106 | 2.34.1 |
106 | |||
107 | diff view generated by jsdifflib |
1 | Currently the change in cpu_tb_exec is masked by the debug exception | 1 | It was non-obvious to me why we can raise an exception in |
---|---|---|---|
2 | being raised by the translators. But this allows us to remove that code. | 2 | the middle of a comparison function, but it works. |
3 | While nearby, use TARGET_PAGE_ALIGN instead of open-coding. | ||
3 | 4 | ||
5 | Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | --- | 7 | --- |
6 | accel/tcg/cpu-exec.c | 11 +++++++++++ | 8 | accel/tcg/cpu-exec.c | 11 ++++++++++- |
7 | 1 file changed, 11 insertions(+) | 9 | 1 file changed, 10 insertions(+), 1 deletion(-) |
8 | 10 | ||
9 | diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c | 11 | diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c |
10 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
11 | --- a/accel/tcg/cpu-exec.c | 13 | --- a/accel/tcg/cpu-exec.c |
12 | +++ b/accel/tcg/cpu-exec.c | 14 | +++ b/accel/tcg/cpu-exec.c |
13 | @@ -XXX,XX +XXX,XX @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit) | 15 | @@ -XXX,XX +XXX,XX @@ static bool tb_lookup_cmp(const void *p, const void *d) |
14 | cc->set_pc(cpu, last_tb->pc); | 16 | tb_page_addr_t phys_page2; |
15 | } | 17 | target_ulong virt_page2; |
16 | } | 18 | |
17 | + | 19 | - virt_page2 = (desc->pc & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; |
18 | + /* | 20 | + /* |
19 | + * If gdb single-step, and we haven't raised another exception, | 21 | + * We know that the first page matched, and an otherwise valid TB |
20 | + * raise a debug exception. Single-step with another exception | 22 | + * encountered an incomplete instruction at the end of that page, |
21 | + * is handled in cpu_handle_exception. | 23 | + * therefore we know that generating a new TB from the current PC |
22 | + */ | 24 | + * must also require reading from the next page -- even if the |
23 | + if (unlikely(cpu->singlestep_enabled) && cpu->exception_index == -1) { | 25 | + * second pages do not match, and therefore the resulting insn |
24 | + cpu->exception_index = EXCP_DEBUG; | 26 | + * is different for the new TB. Therefore any exception raised |
25 | + cpu_loop_exit(cpu); | 27 | + * here by the faulting lookup is not premature. |
26 | + } | 28 | + */ |
27 | + | 29 | + virt_page2 = TARGET_PAGE_ALIGN(desc->pc); |
28 | return last_tb; | 30 | phys_page2 = get_page_addr_code(desc->env, virt_page2); |
29 | } | 31 | if (tb->page_addr[1] == phys_page2) { |
30 | 32 | return true; | |
31 | -- | 33 | -- |
32 | 2.25.1 | 34 | 2.34.1 |
33 | |||
34 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | GDB single-stepping is now handled generically. | ||
2 | 1 | ||
3 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | target/alpha/translate.c | 13 +++---------- | ||
7 | 1 file changed, 3 insertions(+), 10 deletions(-) | ||
8 | |||
9 | diff --git a/target/alpha/translate.c b/target/alpha/translate.c | ||
10 | index XXXXXXX..XXXXXXX 100644 | ||
11 | --- a/target/alpha/translate.c | ||
12 | +++ b/target/alpha/translate.c | ||
13 | @@ -XXX,XX +XXX,XX @@ static void alpha_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu) | ||
14 | tcg_gen_movi_i64(cpu_pc, ctx->base.pc_next); | ||
15 | /* FALLTHRU */ | ||
16 | case DISAS_PC_UPDATED: | ||
17 | - if (!ctx->base.singlestep_enabled) { | ||
18 | - tcg_gen_lookup_and_goto_ptr(); | ||
19 | - break; | ||
20 | - } | ||
21 | - /* FALLTHRU */ | ||
22 | + tcg_gen_lookup_and_goto_ptr(); | ||
23 | + break; | ||
24 | case DISAS_PC_UPDATED_NOCHAIN: | ||
25 | - if (ctx->base.singlestep_enabled) { | ||
26 | - gen_excp_1(EXCP_DEBUG, 0); | ||
27 | - } else { | ||
28 | - tcg_gen_exit_tb(NULL, 0); | ||
29 | - } | ||
30 | + tcg_gen_exit_tb(NULL, 0); | ||
31 | break; | ||
32 | default: | ||
33 | g_assert_not_reached(); | ||
34 | -- | ||
35 | 2.25.1 | ||
36 | |||
37 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | GDB single-stepping is now handled generically. | ||
2 | 1 | ||
3 | Tested-by: Michael Rolnik <mrolnik@gmail.com> | ||
4 | Reviewed-by: Michael Rolnik <mrolnik@gmail.com> | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | --- | ||
8 | target/avr/translate.c | 19 ++++--------------- | ||
9 | 1 file changed, 4 insertions(+), 15 deletions(-) | ||
10 | |||
11 | diff --git a/target/avr/translate.c b/target/avr/translate.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/target/avr/translate.c | ||
14 | +++ b/target/avr/translate.c | ||
15 | @@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) | ||
16 | tcg_gen_exit_tb(tb, n); | ||
17 | } else { | ||
18 | tcg_gen_movi_i32(cpu_pc, dest); | ||
19 | - if (ctx->base.singlestep_enabled) { | ||
20 | - gen_helper_debug(cpu_env); | ||
21 | - } else { | ||
22 | - tcg_gen_lookup_and_goto_ptr(); | ||
23 | - } | ||
24 | + tcg_gen_lookup_and_goto_ptr(); | ||
25 | } | ||
26 | ctx->base.is_jmp = DISAS_NORETURN; | ||
27 | } | ||
28 | @@ -XXX,XX +XXX,XX @@ static void avr_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) | ||
29 | tcg_gen_movi_tl(cpu_pc, ctx->npc); | ||
30 | /* fall through */ | ||
31 | case DISAS_LOOKUP: | ||
32 | - if (!ctx->base.singlestep_enabled) { | ||
33 | - tcg_gen_lookup_and_goto_ptr(); | ||
34 | - break; | ||
35 | - } | ||
36 | - /* fall through */ | ||
37 | + tcg_gen_lookup_and_goto_ptr(); | ||
38 | + break; | ||
39 | case DISAS_EXIT: | ||
40 | - if (ctx->base.singlestep_enabled) { | ||
41 | - gen_helper_debug(cpu_env); | ||
42 | - } else { | ||
43 | - tcg_gen_exit_tb(NULL, 0); | ||
44 | - } | ||
45 | + tcg_gen_exit_tb(NULL, 0); | ||
46 | break; | ||
47 | default: | ||
48 | g_assert_not_reached(); | ||
49 | -- | ||
50 | 2.25.1 | ||
51 | |||
52 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | GDB single-stepping is now handled generically. | ||
2 | 1 | ||
3 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | target/hexagon/translate.c | 12 ++---------- | ||
7 | 1 file changed, 2 insertions(+), 10 deletions(-) | ||
8 | |||
9 | diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c | ||
10 | index XXXXXXX..XXXXXXX 100644 | ||
11 | --- a/target/hexagon/translate.c | ||
12 | +++ b/target/hexagon/translate.c | ||
13 | @@ -XXX,XX +XXX,XX @@ static void gen_end_tb(DisasContext *ctx) | ||
14 | { | ||
15 | gen_exec_counters(ctx); | ||
16 | tcg_gen_mov_tl(hex_gpr[HEX_REG_PC], hex_next_PC); | ||
17 | - if (ctx->base.singlestep_enabled) { | ||
18 | - gen_exception_raw(EXCP_DEBUG); | ||
19 | - } else { | ||
20 | - tcg_gen_exit_tb(NULL, 0); | ||
21 | - } | ||
22 | + tcg_gen_exit_tb(NULL, 0); | ||
23 | ctx->base.is_jmp = DISAS_NORETURN; | ||
24 | } | ||
25 | |||
26 | @@ -XXX,XX +XXX,XX @@ static void hexagon_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu) | ||
27 | case DISAS_TOO_MANY: | ||
28 | gen_exec_counters(ctx); | ||
29 | tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], ctx->base.pc_next); | ||
30 | - if (ctx->base.singlestep_enabled) { | ||
31 | - gen_exception_raw(EXCP_DEBUG); | ||
32 | - } else { | ||
33 | - tcg_gen_exit_tb(NULL, 0); | ||
34 | - } | ||
35 | + tcg_gen_exit_tb(NULL, 0); | ||
36 | break; | ||
37 | case DISAS_NORETURN: | ||
38 | break; | ||
39 | -- | ||
40 | 2.25.1 | ||
41 | |||
42 | diff view generated by jsdifflib |
1 | GDB single-stepping is now handled generically. | 1 | The only user can easily use translator_lduw and |
---|---|---|---|
2 | adjust the type to signed during the return. | ||
2 | 3 | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
5 | Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
6 | Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 8 | --- |
5 | target/i386/helper.h | 1 - | 9 | include/exec/translator.h | 1 - |
6 | target/i386/tcg/misc_helper.c | 8 -------- | 10 | target/i386/tcg/translate.c | 2 +- |
7 | target/i386/tcg/translate.c | 4 +--- | 11 | 2 files changed, 1 insertion(+), 2 deletions(-) |
8 | 3 files changed, 1 insertion(+), 12 deletions(-) | ||
9 | 12 | ||
10 | diff --git a/target/i386/helper.h b/target/i386/helper.h | 13 | diff --git a/include/exec/translator.h b/include/exec/translator.h |
11 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
12 | --- a/target/i386/helper.h | 15 | --- a/include/exec/translator.h |
13 | +++ b/target/i386/helper.h | 16 | +++ b/include/exec/translator.h |
14 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(syscall, void, env, int) | 17 | @@ -XXX,XX +XXX,XX @@ bool translator_use_goto_tb(DisasContextBase *db, target_ulong dest); |
15 | DEF_HELPER_2(sysret, void, env, int) | 18 | |
16 | #endif | 19 | #define FOR_EACH_TRANSLATOR_LD(F) \ |
17 | DEF_HELPER_FLAGS_2(pause, TCG_CALL_NO_WG, noreturn, env, int) | 20 | F(translator_ldub, uint8_t, cpu_ldub_code, /* no swap */) \ |
18 | -DEF_HELPER_FLAGS_1(debug, TCG_CALL_NO_WG, noreturn, env) | 21 | - F(translator_ldsw, int16_t, cpu_ldsw_code, bswap16) \ |
19 | DEF_HELPER_1(reset_rf, void, env) | 22 | F(translator_lduw, uint16_t, cpu_lduw_code, bswap16) \ |
20 | DEF_HELPER_FLAGS_3(raise_interrupt, TCG_CALL_NO_WG, noreturn, env, int, int) | 23 | F(translator_ldl, uint32_t, cpu_ldl_code, bswap32) \ |
21 | DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, int) | 24 | F(translator_ldq, uint64_t, cpu_ldq_code, bswap64) |
22 | diff --git a/target/i386/tcg/misc_helper.c b/target/i386/tcg/misc_helper.c | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/target/i386/tcg/misc_helper.c | ||
25 | +++ b/target/i386/tcg/misc_helper.c | ||
26 | @@ -XXX,XX +XXX,XX @@ void QEMU_NORETURN helper_pause(CPUX86State *env, int next_eip_addend) | ||
27 | do_pause(env); | ||
28 | } | ||
29 | |||
30 | -void QEMU_NORETURN helper_debug(CPUX86State *env) | ||
31 | -{ | ||
32 | - CPUState *cs = env_cpu(env); | ||
33 | - | ||
34 | - cs->exception_index = EXCP_DEBUG; | ||
35 | - cpu_loop_exit(cs); | ||
36 | -} | ||
37 | - | ||
38 | uint64_t helper_rdpkru(CPUX86State *env, uint32_t ecx) | ||
39 | { | ||
40 | if ((env->cr[4] & CR4_PKE_MASK) == 0) { | ||
41 | diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c | 25 | diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c |
42 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
43 | --- a/target/i386/tcg/translate.c | 27 | --- a/target/i386/tcg/translate.c |
44 | +++ b/target/i386/tcg/translate.c | 28 | +++ b/target/i386/tcg/translate.c |
45 | @@ -XXX,XX +XXX,XX @@ do_gen_eob_worker(DisasContext *s, bool inhibit, bool recheck_tf, bool jr) | 29 | @@ -XXX,XX +XXX,XX @@ static inline uint8_t x86_ldub_code(CPUX86State *env, DisasContext *s) |
46 | if (s->base.tb->flags & HF_RF_MASK) { | 30 | |
47 | gen_helper_reset_rf(cpu_env); | 31 | static inline int16_t x86_ldsw_code(CPUX86State *env, DisasContext *s) |
48 | } | 32 | { |
49 | - if (s->base.singlestep_enabled) { | 33 | - return translator_ldsw(env, &s->base, advance_pc(env, s, 2)); |
50 | - gen_helper_debug(cpu_env); | 34 | + return translator_lduw(env, &s->base, advance_pc(env, s, 2)); |
51 | - } else if (recheck_tf) { | 35 | } |
52 | + if (recheck_tf) { | 36 | |
53 | gen_helper_rechecking_single_step(cpu_env); | 37 | static inline uint16_t x86_lduw_code(CPUX86State *env, DisasContext *s) |
54 | tcg_gen_exit_tb(NULL, 0); | ||
55 | } else if (s->flags & HF_TF_MASK) { | ||
56 | -- | 38 | -- |
57 | 2.25.1 | 39 | 2.34.1 |
58 | |||
59 | diff view generated by jsdifflib |
1 | GDB single-stepping is now handled generically. | 1 | Pass these along to translator_loop -- pc may be used instead |
---|---|---|---|
2 | of tb->pc, and host_pc is currently unused. Adjust all targets | ||
3 | at one time. | ||
2 | 4 | ||
3 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 5 | Acked-by: Alistair Francis <alistair.francis@wdc.com> |
6 | Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
7 | Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | --- | 9 | --- |
6 | target/hppa/translate.c | 17 ++++------------- | 10 | include/exec/exec-all.h | 1 - |
7 | 1 file changed, 4 insertions(+), 13 deletions(-) | 11 | include/exec/translator.h | 24 ++++++++++++++++++++---- |
12 | accel/tcg/translate-all.c | 6 ++++-- | ||
13 | accel/tcg/translator.c | 9 +++++---- | ||
14 | target/alpha/translate.c | 5 +++-- | ||
15 | target/arm/translate.c | 5 +++-- | ||
16 | target/avr/translate.c | 5 +++-- | ||
17 | target/cris/translate.c | 5 +++-- | ||
18 | target/hexagon/translate.c | 6 ++++-- | ||
19 | target/hppa/translate.c | 5 +++-- | ||
20 | target/i386/tcg/translate.c | 5 +++-- | ||
21 | target/loongarch/translate.c | 6 ++++-- | ||
22 | target/m68k/translate.c | 5 +++-- | ||
23 | target/microblaze/translate.c | 5 +++-- | ||
24 | target/mips/tcg/translate.c | 5 +++-- | ||
25 | target/nios2/translate.c | 5 +++-- | ||
26 | target/openrisc/translate.c | 6 ++++-- | ||
27 | target/ppc/translate.c | 5 +++-- | ||
28 | target/riscv/translate.c | 5 +++-- | ||
29 | target/rx/translate.c | 5 +++-- | ||
30 | target/s390x/tcg/translate.c | 5 +++-- | ||
31 | target/sh4/translate.c | 5 +++-- | ||
32 | target/sparc/translate.c | 5 +++-- | ||
33 | target/tricore/translate.c | 6 ++++-- | ||
34 | target/xtensa/translate.c | 6 ++++-- | ||
35 | 25 files changed, 97 insertions(+), 53 deletions(-) | ||
8 | 36 | ||
37 | diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/include/exec/exec-all.h | ||
40 | +++ b/include/exec/exec-all.h | ||
41 | @@ -XXX,XX +XXX,XX @@ typedef ram_addr_t tb_page_addr_t; | ||
42 | #define TB_PAGE_ADDR_FMT RAM_ADDR_FMT | ||
43 | #endif | ||
44 | |||
45 | -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns); | ||
46 | void restore_state_to_opc(CPUArchState *env, TranslationBlock *tb, | ||
47 | target_ulong *data); | ||
48 | |||
49 | diff --git a/include/exec/translator.h b/include/exec/translator.h | ||
50 | index XXXXXXX..XXXXXXX 100644 | ||
51 | --- a/include/exec/translator.h | ||
52 | +++ b/include/exec/translator.h | ||
53 | @@ -XXX,XX +XXX,XX @@ | ||
54 | #include "exec/translate-all.h" | ||
55 | #include "tcg/tcg.h" | ||
56 | |||
57 | +/** | ||
58 | + * gen_intermediate_code | ||
59 | + * @cpu: cpu context | ||
60 | + * @tb: translation block | ||
61 | + * @max_insns: max number of instructions to translate | ||
62 | + * @pc: guest virtual program counter address | ||
63 | + * @host_pc: host physical program counter address | ||
64 | + * | ||
65 | + * This function must be provided by the target, which should create | ||
66 | + * the target-specific DisasContext, and then invoke translator_loop. | ||
67 | + */ | ||
68 | +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, | ||
69 | + target_ulong pc, void *host_pc); | ||
70 | |||
71 | /** | ||
72 | * DisasJumpType: | ||
73 | @@ -XXX,XX +XXX,XX @@ typedef struct TranslatorOps { | ||
74 | |||
75 | /** | ||
76 | * translator_loop: | ||
77 | - * @ops: Target-specific operations. | ||
78 | - * @db: Disassembly context. | ||
79 | * @cpu: Target vCPU. | ||
80 | * @tb: Translation block. | ||
81 | * @max_insns: Maximum number of insns to translate. | ||
82 | + * @pc: guest virtual program counter address | ||
83 | + * @host_pc: host physical program counter address | ||
84 | + * @ops: Target-specific operations. | ||
85 | + * @db: Disassembly context. | ||
86 | * | ||
87 | * Generic translator loop. | ||
88 | * | ||
89 | @@ -XXX,XX +XXX,XX @@ typedef struct TranslatorOps { | ||
90 | * - When single-stepping is enabled (system-wide or on the current vCPU). | ||
91 | * - When too many instructions have been translated. | ||
92 | */ | ||
93 | -void translator_loop(const TranslatorOps *ops, DisasContextBase *db, | ||
94 | - CPUState *cpu, TranslationBlock *tb, int max_insns); | ||
95 | +void translator_loop(CPUState *cpu, TranslationBlock *tb, int max_insns, | ||
96 | + target_ulong pc, void *host_pc, | ||
97 | + const TranslatorOps *ops, DisasContextBase *db); | ||
98 | |||
99 | void translator_loop_temp_check(DisasContextBase *db); | ||
100 | |||
101 | diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c | ||
102 | index XXXXXXX..XXXXXXX 100644 | ||
103 | --- a/accel/tcg/translate-all.c | ||
104 | +++ b/accel/tcg/translate-all.c | ||
105 | @@ -XXX,XX +XXX,XX @@ | ||
106 | |||
107 | #include "exec/cputlb.h" | ||
108 | #include "exec/translate-all.h" | ||
109 | +#include "exec/translator.h" | ||
110 | #include "qemu/bitmap.h" | ||
111 | #include "qemu/qemu-print.h" | ||
112 | #include "qemu/timer.h" | ||
113 | @@ -XXX,XX +XXX,XX @@ TranslationBlock *tb_gen_code(CPUState *cpu, | ||
114 | TCGProfile *prof = &tcg_ctx->prof; | ||
115 | int64_t ti; | ||
116 | #endif | ||
117 | + void *host_pc; | ||
118 | |||
119 | assert_memory_lock(); | ||
120 | qemu_thread_jit_write(); | ||
121 | |||
122 | - phys_pc = get_page_addr_code(env, pc); | ||
123 | + phys_pc = get_page_addr_code_hostp(env, pc, &host_pc); | ||
124 | |||
125 | if (phys_pc == -1) { | ||
126 | /* Generate a one-shot TB with 1 insn in it */ | ||
127 | @@ -XXX,XX +XXX,XX @@ TranslationBlock *tb_gen_code(CPUState *cpu, | ||
128 | tcg_func_start(tcg_ctx); | ||
129 | |||
130 | tcg_ctx->cpu = env_cpu(env); | ||
131 | - gen_intermediate_code(cpu, tb, max_insns); | ||
132 | + gen_intermediate_code(cpu, tb, max_insns, pc, host_pc); | ||
133 | assert(tb->size != 0); | ||
134 | tcg_ctx->cpu = NULL; | ||
135 | max_insns = tb->icount; | ||
136 | diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c | ||
137 | index XXXXXXX..XXXXXXX 100644 | ||
138 | --- a/accel/tcg/translator.c | ||
139 | +++ b/accel/tcg/translator.c | ||
140 | @@ -XXX,XX +XXX,XX @@ static inline void translator_page_protect(DisasContextBase *dcbase, | ||
141 | #endif | ||
142 | } | ||
143 | |||
144 | -void translator_loop(const TranslatorOps *ops, DisasContextBase *db, | ||
145 | - CPUState *cpu, TranslationBlock *tb, int max_insns) | ||
146 | +void translator_loop(CPUState *cpu, TranslationBlock *tb, int max_insns, | ||
147 | + target_ulong pc, void *host_pc, | ||
148 | + const TranslatorOps *ops, DisasContextBase *db) | ||
149 | { | ||
150 | uint32_t cflags = tb_cflags(tb); | ||
151 | bool plugin_enabled; | ||
152 | |||
153 | /* Initialize DisasContext */ | ||
154 | db->tb = tb; | ||
155 | - db->pc_first = tb->pc; | ||
156 | - db->pc_next = db->pc_first; | ||
157 | + db->pc_first = pc; | ||
158 | + db->pc_next = pc; | ||
159 | db->is_jmp = DISAS_NEXT; | ||
160 | db->num_insns = 0; | ||
161 | db->max_insns = max_insns; | ||
162 | diff --git a/target/alpha/translate.c b/target/alpha/translate.c | ||
163 | index XXXXXXX..XXXXXXX 100644 | ||
164 | --- a/target/alpha/translate.c | ||
165 | +++ b/target/alpha/translate.c | ||
166 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps alpha_tr_ops = { | ||
167 | .disas_log = alpha_tr_disas_log, | ||
168 | }; | ||
169 | |||
170 | -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) | ||
171 | +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, | ||
172 | + target_ulong pc, void *host_pc) | ||
173 | { | ||
174 | DisasContext dc; | ||
175 | - translator_loop(&alpha_tr_ops, &dc.base, cpu, tb, max_insns); | ||
176 | + translator_loop(cpu, tb, max_insns, pc, host_pc, &alpha_tr_ops, &dc.base); | ||
177 | } | ||
178 | |||
179 | void restore_state_to_opc(CPUAlphaState *env, TranslationBlock *tb, | ||
180 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
181 | index XXXXXXX..XXXXXXX 100644 | ||
182 | --- a/target/arm/translate.c | ||
183 | +++ b/target/arm/translate.c | ||
184 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps thumb_translator_ops = { | ||
185 | }; | ||
186 | |||
187 | /* generate intermediate code for basic block 'tb'. */ | ||
188 | -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) | ||
189 | +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, | ||
190 | + target_ulong pc, void *host_pc) | ||
191 | { | ||
192 | DisasContext dc = { }; | ||
193 | const TranslatorOps *ops = &arm_translator_ops; | ||
194 | @@ -XXX,XX +XXX,XX @@ void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) | ||
195 | } | ||
196 | #endif | ||
197 | |||
198 | - translator_loop(ops, &dc.base, cpu, tb, max_insns); | ||
199 | + translator_loop(cpu, tb, max_insns, pc, host_pc, ops, &dc.base); | ||
200 | } | ||
201 | |||
202 | void restore_state_to_opc(CPUARMState *env, TranslationBlock *tb, | ||
203 | diff --git a/target/avr/translate.c b/target/avr/translate.c | ||
204 | index XXXXXXX..XXXXXXX 100644 | ||
205 | --- a/target/avr/translate.c | ||
206 | +++ b/target/avr/translate.c | ||
207 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps avr_tr_ops = { | ||
208 | .disas_log = avr_tr_disas_log, | ||
209 | }; | ||
210 | |||
211 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) | ||
212 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
213 | + target_ulong pc, void *host_pc) | ||
214 | { | ||
215 | DisasContext dc = { }; | ||
216 | - translator_loop(&avr_tr_ops, &dc.base, cs, tb, max_insns); | ||
217 | + translator_loop(cs, tb, max_insns, pc, host_pc, &avr_tr_ops, &dc.base); | ||
218 | } | ||
219 | |||
220 | void restore_state_to_opc(CPUAVRState *env, TranslationBlock *tb, | ||
221 | diff --git a/target/cris/translate.c b/target/cris/translate.c | ||
222 | index XXXXXXX..XXXXXXX 100644 | ||
223 | --- a/target/cris/translate.c | ||
224 | +++ b/target/cris/translate.c | ||
225 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps cris_tr_ops = { | ||
226 | .disas_log = cris_tr_disas_log, | ||
227 | }; | ||
228 | |||
229 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) | ||
230 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
231 | + target_ulong pc, void *host_pc) | ||
232 | { | ||
233 | DisasContext dc; | ||
234 | - translator_loop(&cris_tr_ops, &dc.base, cs, tb, max_insns); | ||
235 | + translator_loop(cs, tb, max_insns, pc, host_pc, &cris_tr_ops, &dc.base); | ||
236 | } | ||
237 | |||
238 | void cris_cpu_dump_state(CPUState *cs, FILE *f, int flags) | ||
239 | diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c | ||
240 | index XXXXXXX..XXXXXXX 100644 | ||
241 | --- a/target/hexagon/translate.c | ||
242 | +++ b/target/hexagon/translate.c | ||
243 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps hexagon_tr_ops = { | ||
244 | .disas_log = hexagon_tr_disas_log, | ||
245 | }; | ||
246 | |||
247 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) | ||
248 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
249 | + target_ulong pc, void *host_pc) | ||
250 | { | ||
251 | DisasContext ctx; | ||
252 | |||
253 | - translator_loop(&hexagon_tr_ops, &ctx.base, cs, tb, max_insns); | ||
254 | + translator_loop(cs, tb, max_insns, pc, host_pc, | ||
255 | + &hexagon_tr_ops, &ctx.base); | ||
256 | } | ||
257 | |||
258 | #define NAME_LEN 64 | ||
9 | diff --git a/target/hppa/translate.c b/target/hppa/translate.c | 259 | diff --git a/target/hppa/translate.c b/target/hppa/translate.c |
10 | index XXXXXXX..XXXXXXX 100644 | 260 | index XXXXXXX..XXXXXXX 100644 |
11 | --- a/target/hppa/translate.c | 261 | --- a/target/hppa/translate.c |
12 | +++ b/target/hppa/translate.c | 262 | +++ b/target/hppa/translate.c |
13 | @@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *ctx, int which, | 263 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps hppa_tr_ops = { |
14 | } else { | 264 | .disas_log = hppa_tr_disas_log, |
15 | copy_iaoq_entry(cpu_iaoq_f, f, cpu_iaoq_b); | 265 | }; |
16 | copy_iaoq_entry(cpu_iaoq_b, b, ctx->iaoq_n_var); | 266 | |
17 | - if (ctx->base.singlestep_enabled) { | 267 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) |
18 | - gen_excp_1(EXCP_DEBUG); | 268 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, |
19 | - } else { | 269 | + target_ulong pc, void *host_pc) |
20 | - tcg_gen_lookup_and_goto_ptr(); | 270 | { |
21 | - } | 271 | DisasContext ctx; |
22 | + tcg_gen_lookup_and_goto_ptr(); | 272 | - translator_loop(&hppa_tr_ops, &ctx.base, cs, tb, max_insns); |
23 | } | 273 | + translator_loop(cs, tb, max_insns, pc, host_pc, &hppa_tr_ops, &ctx.base); |
24 | } | 274 | } |
25 | 275 | ||
26 | @@ -XXX,XX +XXX,XX @@ static bool do_rfi(DisasContext *ctx, bool rfi_r) | 276 | void restore_state_to_opc(CPUHPPAState *env, TranslationBlock *tb, |
27 | gen_helper_rfi(cpu_env); | 277 | diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c |
28 | } | 278 | index XXXXXXX..XXXXXXX 100644 |
29 | /* Exit the TB to recognize new interrupts. */ | 279 | --- a/target/i386/tcg/translate.c |
30 | - if (ctx->base.singlestep_enabled) { | 280 | +++ b/target/i386/tcg/translate.c |
31 | - gen_excp_1(EXCP_DEBUG); | 281 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps i386_tr_ops = { |
32 | - } else { | 282 | }; |
33 | - tcg_gen_exit_tb(NULL, 0); | 283 | |
34 | - } | 284 | /* generate intermediate code for basic block 'tb'. */ |
35 | + tcg_gen_exit_tb(NULL, 0); | 285 | -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) |
36 | ctx->base.is_jmp = DISAS_NORETURN; | 286 | +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, |
37 | 287 | + target_ulong pc, void *host_pc) | |
38 | return nullify_end(ctx); | 288 | { |
39 | @@ -XXX,XX +XXX,XX @@ static void hppa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) | 289 | DisasContext dc; |
40 | nullify_save(ctx); | 290 | |
41 | /* FALLTHRU */ | 291 | - translator_loop(&i386_tr_ops, &dc.base, cpu, tb, max_insns); |
42 | case DISAS_IAQ_N_UPDATED: | 292 | + translator_loop(cpu, tb, max_insns, pc, host_pc, &i386_tr_ops, &dc.base); |
43 | - if (ctx->base.singlestep_enabled) { | 293 | } |
44 | - gen_excp_1(EXCP_DEBUG); | 294 | |
45 | - } else if (is_jmp != DISAS_IAQ_N_STALE_EXIT) { | 295 | void restore_state_to_opc(CPUX86State *env, TranslationBlock *tb, |
46 | + if (is_jmp != DISAS_IAQ_N_STALE_EXIT) { | 296 | diff --git a/target/loongarch/translate.c b/target/loongarch/translate.c |
47 | tcg_gen_lookup_and_goto_ptr(); | 297 | index XXXXXXX..XXXXXXX 100644 |
48 | + break; | 298 | --- a/target/loongarch/translate.c |
49 | } | 299 | +++ b/target/loongarch/translate.c |
50 | /* FALLTHRU */ | 300 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps loongarch_tr_ops = { |
51 | case DISAS_EXIT: | 301 | .disas_log = loongarch_tr_disas_log, |
302 | }; | ||
303 | |||
304 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) | ||
305 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
306 | + target_ulong pc, void *host_pc) | ||
307 | { | ||
308 | DisasContext ctx; | ||
309 | |||
310 | - translator_loop(&loongarch_tr_ops, &ctx.base, cs, tb, max_insns); | ||
311 | + translator_loop(cs, tb, max_insns, pc, host_pc, | ||
312 | + &loongarch_tr_ops, &ctx.base); | ||
313 | } | ||
314 | |||
315 | void loongarch_translate_init(void) | ||
316 | diff --git a/target/m68k/translate.c b/target/m68k/translate.c | ||
317 | index XXXXXXX..XXXXXXX 100644 | ||
318 | --- a/target/m68k/translate.c | ||
319 | +++ b/target/m68k/translate.c | ||
320 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps m68k_tr_ops = { | ||
321 | .disas_log = m68k_tr_disas_log, | ||
322 | }; | ||
323 | |||
324 | -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) | ||
325 | +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, | ||
326 | + target_ulong pc, void *host_pc) | ||
327 | { | ||
328 | DisasContext dc; | ||
329 | - translator_loop(&m68k_tr_ops, &dc.base, cpu, tb, max_insns); | ||
330 | + translator_loop(cpu, tb, max_insns, pc, host_pc, &m68k_tr_ops, &dc.base); | ||
331 | } | ||
332 | |||
333 | static double floatx80_to_double(CPUM68KState *env, uint16_t high, uint64_t low) | ||
334 | diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c | ||
335 | index XXXXXXX..XXXXXXX 100644 | ||
336 | --- a/target/microblaze/translate.c | ||
337 | +++ b/target/microblaze/translate.c | ||
338 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps mb_tr_ops = { | ||
339 | .disas_log = mb_tr_disas_log, | ||
340 | }; | ||
341 | |||
342 | -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) | ||
343 | +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, | ||
344 | + target_ulong pc, void *host_pc) | ||
345 | { | ||
346 | DisasContext dc; | ||
347 | - translator_loop(&mb_tr_ops, &dc.base, cpu, tb, max_insns); | ||
348 | + translator_loop(cpu, tb, max_insns, pc, host_pc, &mb_tr_ops, &dc.base); | ||
349 | } | ||
350 | |||
351 | void mb_cpu_dump_state(CPUState *cs, FILE *f, int flags) | ||
352 | diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c | ||
353 | index XXXXXXX..XXXXXXX 100644 | ||
354 | --- a/target/mips/tcg/translate.c | ||
355 | +++ b/target/mips/tcg/translate.c | ||
356 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps mips_tr_ops = { | ||
357 | .disas_log = mips_tr_disas_log, | ||
358 | }; | ||
359 | |||
360 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) | ||
361 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
362 | + target_ulong pc, void *host_pc) | ||
363 | { | ||
364 | DisasContext ctx; | ||
365 | |||
366 | - translator_loop(&mips_tr_ops, &ctx.base, cs, tb, max_insns); | ||
367 | + translator_loop(cs, tb, max_insns, pc, host_pc, &mips_tr_ops, &ctx.base); | ||
368 | } | ||
369 | |||
370 | void mips_tcg_init(void) | ||
371 | diff --git a/target/nios2/translate.c b/target/nios2/translate.c | ||
372 | index XXXXXXX..XXXXXXX 100644 | ||
373 | --- a/target/nios2/translate.c | ||
374 | +++ b/target/nios2/translate.c | ||
375 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps nios2_tr_ops = { | ||
376 | .disas_log = nios2_tr_disas_log, | ||
377 | }; | ||
378 | |||
379 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) | ||
380 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
381 | + target_ulong pc, void *host_pc) | ||
382 | { | ||
383 | DisasContext dc; | ||
384 | - translator_loop(&nios2_tr_ops, &dc.base, cs, tb, max_insns); | ||
385 | + translator_loop(cs, tb, max_insns, pc, host_pc, &nios2_tr_ops, &dc.base); | ||
386 | } | ||
387 | |||
388 | void nios2_cpu_dump_state(CPUState *cs, FILE *f, int flags) | ||
389 | diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c | ||
390 | index XXXXXXX..XXXXXXX 100644 | ||
391 | --- a/target/openrisc/translate.c | ||
392 | +++ b/target/openrisc/translate.c | ||
393 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps openrisc_tr_ops = { | ||
394 | .disas_log = openrisc_tr_disas_log, | ||
395 | }; | ||
396 | |||
397 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) | ||
398 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
399 | + target_ulong pc, void *host_pc) | ||
400 | { | ||
401 | DisasContext ctx; | ||
402 | |||
403 | - translator_loop(&openrisc_tr_ops, &ctx.base, cs, tb, max_insns); | ||
404 | + translator_loop(cs, tb, max_insns, pc, host_pc, | ||
405 | + &openrisc_tr_ops, &ctx.base); | ||
406 | } | ||
407 | |||
408 | void openrisc_cpu_dump_state(CPUState *cs, FILE *f, int flags) | ||
409 | diff --git a/target/ppc/translate.c b/target/ppc/translate.c | ||
410 | index XXXXXXX..XXXXXXX 100644 | ||
411 | --- a/target/ppc/translate.c | ||
412 | +++ b/target/ppc/translate.c | ||
413 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps ppc_tr_ops = { | ||
414 | .disas_log = ppc_tr_disas_log, | ||
415 | }; | ||
416 | |||
417 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) | ||
418 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
419 | + target_ulong pc, void *host_pc) | ||
420 | { | ||
421 | DisasContext ctx; | ||
422 | |||
423 | - translator_loop(&ppc_tr_ops, &ctx.base, cs, tb, max_insns); | ||
424 | + translator_loop(cs, tb, max_insns, pc, host_pc, &ppc_tr_ops, &ctx.base); | ||
425 | } | ||
426 | |||
427 | void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, | ||
428 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | ||
429 | index XXXXXXX..XXXXXXX 100644 | ||
430 | --- a/target/riscv/translate.c | ||
431 | +++ b/target/riscv/translate.c | ||
432 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps riscv_tr_ops = { | ||
433 | .disas_log = riscv_tr_disas_log, | ||
434 | }; | ||
435 | |||
436 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) | ||
437 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
438 | + target_ulong pc, void *host_pc) | ||
439 | { | ||
440 | DisasContext ctx; | ||
441 | |||
442 | - translator_loop(&riscv_tr_ops, &ctx.base, cs, tb, max_insns); | ||
443 | + translator_loop(cs, tb, max_insns, pc, host_pc, &riscv_tr_ops, &ctx.base); | ||
444 | } | ||
445 | |||
446 | void riscv_translate_init(void) | ||
447 | diff --git a/target/rx/translate.c b/target/rx/translate.c | ||
448 | index XXXXXXX..XXXXXXX 100644 | ||
449 | --- a/target/rx/translate.c | ||
450 | +++ b/target/rx/translate.c | ||
451 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps rx_tr_ops = { | ||
452 | .disas_log = rx_tr_disas_log, | ||
453 | }; | ||
454 | |||
455 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) | ||
456 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
457 | + target_ulong pc, void *host_pc) | ||
458 | { | ||
459 | DisasContext dc; | ||
460 | |||
461 | - translator_loop(&rx_tr_ops, &dc.base, cs, tb, max_insns); | ||
462 | + translator_loop(cs, tb, max_insns, pc, host_pc, &rx_tr_ops, &dc.base); | ||
463 | } | ||
464 | |||
465 | void restore_state_to_opc(CPURXState *env, TranslationBlock *tb, | ||
466 | diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c | ||
467 | index XXXXXXX..XXXXXXX 100644 | ||
468 | --- a/target/s390x/tcg/translate.c | ||
469 | +++ b/target/s390x/tcg/translate.c | ||
470 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps s390x_tr_ops = { | ||
471 | .disas_log = s390x_tr_disas_log, | ||
472 | }; | ||
473 | |||
474 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) | ||
475 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
476 | + target_ulong pc, void *host_pc) | ||
477 | { | ||
478 | DisasContext dc; | ||
479 | |||
480 | - translator_loop(&s390x_tr_ops, &dc.base, cs, tb, max_insns); | ||
481 | + translator_loop(cs, tb, max_insns, pc, host_pc, &s390x_tr_ops, &dc.base); | ||
482 | } | ||
483 | |||
484 | void restore_state_to_opc(CPUS390XState *env, TranslationBlock *tb, | ||
485 | diff --git a/target/sh4/translate.c b/target/sh4/translate.c | ||
486 | index XXXXXXX..XXXXXXX 100644 | ||
487 | --- a/target/sh4/translate.c | ||
488 | +++ b/target/sh4/translate.c | ||
489 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps sh4_tr_ops = { | ||
490 | .disas_log = sh4_tr_disas_log, | ||
491 | }; | ||
492 | |||
493 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) | ||
494 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
495 | + target_ulong pc, void *host_pc) | ||
496 | { | ||
497 | DisasContext ctx; | ||
498 | |||
499 | - translator_loop(&sh4_tr_ops, &ctx.base, cs, tb, max_insns); | ||
500 | + translator_loop(cs, tb, max_insns, pc, host_pc, &sh4_tr_ops, &ctx.base); | ||
501 | } | ||
502 | |||
503 | void restore_state_to_opc(CPUSH4State *env, TranslationBlock *tb, | ||
504 | diff --git a/target/sparc/translate.c b/target/sparc/translate.c | ||
505 | index XXXXXXX..XXXXXXX 100644 | ||
506 | --- a/target/sparc/translate.c | ||
507 | +++ b/target/sparc/translate.c | ||
508 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps sparc_tr_ops = { | ||
509 | .disas_log = sparc_tr_disas_log, | ||
510 | }; | ||
511 | |||
512 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) | ||
513 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
514 | + target_ulong pc, void *host_pc) | ||
515 | { | ||
516 | DisasContext dc = {}; | ||
517 | |||
518 | - translator_loop(&sparc_tr_ops, &dc.base, cs, tb, max_insns); | ||
519 | + translator_loop(cs, tb, max_insns, pc, host_pc, &sparc_tr_ops, &dc.base); | ||
520 | } | ||
521 | |||
522 | void sparc_tcg_init(void) | ||
523 | diff --git a/target/tricore/translate.c b/target/tricore/translate.c | ||
524 | index XXXXXXX..XXXXXXX 100644 | ||
525 | --- a/target/tricore/translate.c | ||
526 | +++ b/target/tricore/translate.c | ||
527 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps tricore_tr_ops = { | ||
528 | }; | ||
529 | |||
530 | |||
531 | -void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns) | ||
532 | +void gen_intermediate_code(CPUState *cs, TranslationBlock *tb, int max_insns, | ||
533 | + target_ulong pc, void *host_pc) | ||
534 | { | ||
535 | DisasContext ctx; | ||
536 | - translator_loop(&tricore_tr_ops, &ctx.base, cs, tb, max_insns); | ||
537 | + translator_loop(cs, tb, max_insns, pc, host_pc, | ||
538 | + &tricore_tr_ops, &ctx.base); | ||
539 | } | ||
540 | |||
541 | void | ||
542 | diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c | ||
543 | index XXXXXXX..XXXXXXX 100644 | ||
544 | --- a/target/xtensa/translate.c | ||
545 | +++ b/target/xtensa/translate.c | ||
546 | @@ -XXX,XX +XXX,XX @@ static const TranslatorOps xtensa_translator_ops = { | ||
547 | .disas_log = xtensa_tr_disas_log, | ||
548 | }; | ||
549 | |||
550 | -void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) | ||
551 | +void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns, | ||
552 | + target_ulong pc, void *host_pc) | ||
553 | { | ||
554 | DisasContext dc = {}; | ||
555 | - translator_loop(&xtensa_translator_ops, &dc.base, cpu, tb, max_insns); | ||
556 | + translator_loop(cpu, tb, max_insns, pc, host_pc, | ||
557 | + &xtensa_translator_ops, &dc.base); | ||
558 | } | ||
559 | |||
560 | void xtensa_cpu_dump_state(CPUState *cs, FILE *f, int flags) | ||
52 | -- | 561 | -- |
53 | 2.25.1 | 562 | 2.34.1 |
54 | |||
55 | diff view generated by jsdifflib |
1 | GDB single-stepping is now handled generically. | 1 | Cache the translation from guest to host address, so we may |
---|---|---|---|
2 | use direct loads when we hit on the primary translation page. | ||
2 | 3 | ||
3 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 4 | Look up the second translation page only once, during translation. |
5 | This obviates another lookup of the second page within tb_gen_code | ||
6 | after translation. | ||
7 | |||
8 | Fixes a bug in that plugin_insn_append should be passed the bytes | ||
9 | in the original memory order, not bswapped by pieces. | ||
10 | |||
11 | Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
12 | Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 13 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | --- | 14 | --- |
6 | target/tricore/helper.h | 1 - | 15 | include/exec/translator.h | 63 +++++++++++-------- |
7 | target/tricore/op_helper.c | 7 ------- | 16 | accel/tcg/translate-all.c | 23 +++---- |
8 | target/tricore/translate.c | 14 +------------- | 17 | accel/tcg/translator.c | 126 +++++++++++++++++++++++++++++--------- |
9 | 3 files changed, 1 insertion(+), 21 deletions(-) | 18 | 3 files changed, 141 insertions(+), 71 deletions(-) |
10 | 19 | ||
11 | diff --git a/target/tricore/helper.h b/target/tricore/helper.h | 20 | diff --git a/include/exec/translator.h b/include/exec/translator.h |
12 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/tricore/helper.h | 22 | --- a/include/exec/translator.h |
14 | +++ b/target/tricore/helper.h | 23 | +++ b/include/exec/translator.h |
15 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(psw_write, void, env, i32) | 24 | @@ -XXX,XX +XXX,XX @@ typedef enum DisasJumpType { |
16 | DEF_HELPER_1(psw_read, i32, env) | 25 | * Architecture-agnostic disassembly context. |
17 | /* Exceptions */ | 26 | */ |
18 | DEF_HELPER_3(raise_exception_sync, noreturn, env, i32, i32) | 27 | typedef struct DisasContextBase { |
19 | -DEF_HELPER_2(qemu_excp, noreturn, env, i32) | 28 | - const TranslationBlock *tb; |
20 | diff --git a/target/tricore/op_helper.c b/target/tricore/op_helper.c | 29 | + TranslationBlock *tb; |
30 | target_ulong pc_first; | ||
31 | target_ulong pc_next; | ||
32 | DisasJumpType is_jmp; | ||
33 | int num_insns; | ||
34 | int max_insns; | ||
35 | bool singlestep_enabled; | ||
36 | -#ifdef CONFIG_USER_ONLY | ||
37 | - /* | ||
38 | - * Guest address of the last byte of the last protected page. | ||
39 | - * | ||
40 | - * Pages containing the translated instructions are made non-writable in | ||
41 | - * order to achieve consistency in case another thread is modifying the | ||
42 | - * code while translate_insn() fetches the instruction bytes piecemeal. | ||
43 | - * Such writer threads are blocked on mmap_lock() in page_unprotect(). | ||
44 | - */ | ||
45 | - target_ulong page_protect_end; | ||
46 | -#endif | ||
47 | + void *host_addr[2]; | ||
48 | } DisasContextBase; | ||
49 | |||
50 | /** | ||
51 | @@ -XXX,XX +XXX,XX @@ bool translator_use_goto_tb(DisasContextBase *db, target_ulong dest); | ||
52 | * the relevant information at translation time. | ||
53 | */ | ||
54 | |||
55 | -#define GEN_TRANSLATOR_LD(fullname, type, load_fn, swap_fn) \ | ||
56 | - type fullname ## _swap(CPUArchState *env, DisasContextBase *dcbase, \ | ||
57 | - abi_ptr pc, bool do_swap); \ | ||
58 | - static inline type fullname(CPUArchState *env, \ | ||
59 | - DisasContextBase *dcbase, abi_ptr pc) \ | ||
60 | - { \ | ||
61 | - return fullname ## _swap(env, dcbase, pc, false); \ | ||
62 | +uint8_t translator_ldub(CPUArchState *env, DisasContextBase *db, abi_ptr pc); | ||
63 | +uint16_t translator_lduw(CPUArchState *env, DisasContextBase *db, abi_ptr pc); | ||
64 | +uint32_t translator_ldl(CPUArchState *env, DisasContextBase *db, abi_ptr pc); | ||
65 | +uint64_t translator_ldq(CPUArchState *env, DisasContextBase *db, abi_ptr pc); | ||
66 | + | ||
67 | +static inline uint16_t | ||
68 | +translator_lduw_swap(CPUArchState *env, DisasContextBase *db, | ||
69 | + abi_ptr pc, bool do_swap) | ||
70 | +{ | ||
71 | + uint16_t ret = translator_lduw(env, db, pc); | ||
72 | + if (do_swap) { | ||
73 | + ret = bswap16(ret); | ||
74 | } | ||
75 | + return ret; | ||
76 | +} | ||
77 | |||
78 | -#define FOR_EACH_TRANSLATOR_LD(F) \ | ||
79 | - F(translator_ldub, uint8_t, cpu_ldub_code, /* no swap */) \ | ||
80 | - F(translator_lduw, uint16_t, cpu_lduw_code, bswap16) \ | ||
81 | - F(translator_ldl, uint32_t, cpu_ldl_code, bswap32) \ | ||
82 | - F(translator_ldq, uint64_t, cpu_ldq_code, bswap64) | ||
83 | +static inline uint32_t | ||
84 | +translator_ldl_swap(CPUArchState *env, DisasContextBase *db, | ||
85 | + abi_ptr pc, bool do_swap) | ||
86 | +{ | ||
87 | + uint32_t ret = translator_ldl(env, db, pc); | ||
88 | + if (do_swap) { | ||
89 | + ret = bswap32(ret); | ||
90 | + } | ||
91 | + return ret; | ||
92 | +} | ||
93 | |||
94 | -FOR_EACH_TRANSLATOR_LD(GEN_TRANSLATOR_LD) | ||
95 | - | ||
96 | -#undef GEN_TRANSLATOR_LD | ||
97 | +static inline uint64_t | ||
98 | +translator_ldq_swap(CPUArchState *env, DisasContextBase *db, | ||
99 | + abi_ptr pc, bool do_swap) | ||
100 | +{ | ||
101 | + uint64_t ret = translator_ldq(env, db, pc); | ||
102 | + if (do_swap) { | ||
103 | + ret = bswap64(ret); | ||
104 | + } | ||
105 | + return ret; | ||
106 | +} | ||
107 | |||
108 | /* | ||
109 | * Return whether addr is on the same page as where disassembly started. | ||
110 | diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | 111 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/tricore/op_helper.c | 112 | --- a/accel/tcg/translate-all.c |
23 | +++ b/target/tricore/op_helper.c | 113 | +++ b/accel/tcg/translate-all.c |
24 | @@ -XXX,XX +XXX,XX @@ static void raise_exception_sync_helper(CPUTriCoreState *env, uint32_t class, | 114 | @@ -XXX,XX +XXX,XX @@ TranslationBlock *tb_gen_code(CPUState *cpu, |
25 | raise_exception_sync_internal(env, class, tin, pc, 0); | 115 | { |
116 | CPUArchState *env = cpu->env_ptr; | ||
117 | TranslationBlock *tb, *existing_tb; | ||
118 | - tb_page_addr_t phys_pc, phys_page2; | ||
119 | - target_ulong virt_page2; | ||
120 | + tb_page_addr_t phys_pc; | ||
121 | tcg_insn_unit *gen_code_buf; | ||
122 | int gen_code_size, search_size, max_insns; | ||
123 | #ifdef CONFIG_PROFILER | ||
124 | @@ -XXX,XX +XXX,XX @@ TranslationBlock *tb_gen_code(CPUState *cpu, | ||
125 | tb->flags = flags; | ||
126 | tb->cflags = cflags; | ||
127 | tb->trace_vcpu_dstate = *cpu->trace_dstate; | ||
128 | + tb->page_addr[0] = phys_pc; | ||
129 | + tb->page_addr[1] = -1; | ||
130 | tcg_ctx->tb_cflags = cflags; | ||
131 | tb_overflow: | ||
132 | |||
133 | @@ -XXX,XX +XXX,XX @@ TranslationBlock *tb_gen_code(CPUState *cpu, | ||
134 | } | ||
135 | |||
136 | /* | ||
137 | - * If the TB is not associated with a physical RAM page then | ||
138 | - * it must be a temporary one-insn TB, and we have nothing to do | ||
139 | - * except fill in the page_addr[] fields. Return early before | ||
140 | - * attempting to link to other TBs or add to the lookup table. | ||
141 | + * If the TB is not associated with a physical RAM page then it must be | ||
142 | + * a temporary one-insn TB, and we have nothing left to do. Return early | ||
143 | + * before attempting to link to other TBs or add to the lookup table. | ||
144 | */ | ||
145 | - if (phys_pc == -1) { | ||
146 | - tb->page_addr[0] = tb->page_addr[1] = -1; | ||
147 | + if (tb->page_addr[0] == -1) { | ||
148 | return tb; | ||
149 | } | ||
150 | |||
151 | @@ -XXX,XX +XXX,XX @@ TranslationBlock *tb_gen_code(CPUState *cpu, | ||
152 | */ | ||
153 | tcg_tb_insert(tb); | ||
154 | |||
155 | - /* check next page if needed */ | ||
156 | - virt_page2 = (pc + tb->size - 1) & TARGET_PAGE_MASK; | ||
157 | - phys_page2 = -1; | ||
158 | - if ((pc & TARGET_PAGE_MASK) != virt_page2) { | ||
159 | - phys_page2 = get_page_addr_code(env, virt_page2); | ||
160 | - } | ||
161 | /* | ||
162 | * No explicit memory barrier is required -- tb_link_page() makes the | ||
163 | * TB visible in a consistent state. | ||
164 | */ | ||
165 | - existing_tb = tb_link_page(tb, phys_pc, phys_page2); | ||
166 | + existing_tb = tb_link_page(tb, tb->page_addr[0], tb->page_addr[1]); | ||
167 | /* if the TB already exists, discard what we just translated */ | ||
168 | if (unlikely(existing_tb != tb)) { | ||
169 | uintptr_t orig_aligned = (uintptr_t)gen_code_buf; | ||
170 | diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c | ||
171 | index XXXXXXX..XXXXXXX 100644 | ||
172 | --- a/accel/tcg/translator.c | ||
173 | +++ b/accel/tcg/translator.c | ||
174 | @@ -XXX,XX +XXX,XX @@ bool translator_use_goto_tb(DisasContextBase *db, target_ulong dest) | ||
175 | return ((db->pc_first ^ dest) & TARGET_PAGE_MASK) == 0; | ||
26 | } | 176 | } |
27 | 177 | ||
28 | -void helper_qemu_excp(CPUTriCoreState *env, uint32_t excp) | 178 | -static inline void translator_page_protect(DisasContextBase *dcbase, |
179 | - target_ulong pc) | ||
29 | -{ | 180 | -{ |
30 | - CPUState *cs = env_cpu(env); | 181 | -#ifdef CONFIG_USER_ONLY |
31 | - cs->exception_index = excp; | 182 | - dcbase->page_protect_end = pc | ~TARGET_PAGE_MASK; |
32 | - cpu_loop_exit(cs); | 183 | - page_protect(pc); |
184 | -#endif | ||
33 | -} | 185 | -} |
34 | - | 186 | - |
35 | /* Addressing mode helper */ | 187 | void translator_loop(CPUState *cpu, TranslationBlock *tb, int max_insns, |
36 | 188 | target_ulong pc, void *host_pc, | |
37 | static uint16_t reverse16(uint16_t val) | 189 | const TranslatorOps *ops, DisasContextBase *db) |
38 | diff --git a/target/tricore/translate.c b/target/tricore/translate.c | 190 | @@ -XXX,XX +XXX,XX @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int max_insns, |
39 | index XXXXXXX..XXXXXXX 100644 | 191 | db->num_insns = 0; |
40 | --- a/target/tricore/translate.c | 192 | db->max_insns = max_insns; |
41 | +++ b/target/tricore/translate.c | 193 | db->singlestep_enabled = cflags & CF_SINGLE_STEP; |
42 | @@ -XXX,XX +XXX,XX @@ static inline void gen_save_pc(target_ulong pc) | 194 | - translator_page_protect(db, db->pc_next); |
43 | tcg_gen_movi_tl(cpu_PC, pc); | 195 | + db->host_addr[0] = host_pc; |
196 | + db->host_addr[1] = NULL; | ||
197 | + | ||
198 | +#ifdef CONFIG_USER_ONLY | ||
199 | + page_protect(pc); | ||
200 | +#endif | ||
201 | |||
202 | ops->init_disas_context(db, cpu); | ||
203 | tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */ | ||
204 | @@ -XXX,XX +XXX,XX @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int max_insns, | ||
205 | #endif | ||
44 | } | 206 | } |
45 | 207 | ||
46 | -static void generate_qemu_excp(DisasContext *ctx, int excp) | 208 | -static inline void translator_maybe_page_protect(DisasContextBase *dcbase, |
47 | -{ | 209 | - target_ulong pc, size_t len) |
48 | - TCGv_i32 tmp = tcg_const_i32(excp); | 210 | +static void *translator_access(CPUArchState *env, DisasContextBase *db, |
49 | - gen_helper_qemu_excp(cpu_env, tmp); | 211 | + target_ulong pc, size_t len) |
50 | - ctx->base.is_jmp = DISAS_NORETURN; | ||
51 | - tcg_temp_free(tmp); | ||
52 | -} | ||
53 | - | ||
54 | static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) | ||
55 | { | 212 | { |
56 | if (translator_use_goto_tb(&ctx->base, dest)) { | 213 | -#ifdef CONFIG_USER_ONLY |
57 | @@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) | 214 | - target_ulong end = pc + len - 1; |
58 | tcg_gen_exit_tb(ctx->base.tb, n); | 215 | + void *host; |
59 | } else { | 216 | + target_ulong base, end; |
60 | gen_save_pc(dest); | 217 | + TranslationBlock *tb; |
61 | - if (ctx->base.singlestep_enabled) { | 218 | |
62 | - generate_qemu_excp(ctx, EXCP_DEBUG); | 219 | - if (end > dcbase->page_protect_end) { |
63 | - } else { | 220 | - translator_page_protect(dcbase, end); |
64 | - tcg_gen_lookup_and_goto_ptr(); | 221 | + tb = db->tb; |
65 | - } | 222 | + |
66 | + tcg_gen_lookup_and_goto_ptr(); | 223 | + /* Use slow path if first page is MMIO. */ |
67 | } | 224 | + if (unlikely(tb->page_addr[0] == -1)) { |
225 | + return NULL; | ||
226 | } | ||
227 | + | ||
228 | + end = pc + len - 1; | ||
229 | + if (likely(is_same_page(db, end))) { | ||
230 | + host = db->host_addr[0]; | ||
231 | + base = db->pc_first; | ||
232 | + } else { | ||
233 | + host = db->host_addr[1]; | ||
234 | + base = TARGET_PAGE_ALIGN(db->pc_first); | ||
235 | + if (host == NULL) { | ||
236 | + tb->page_addr[1] = | ||
237 | + get_page_addr_code_hostp(env, base, &db->host_addr[1]); | ||
238 | +#ifdef CONFIG_USER_ONLY | ||
239 | + page_protect(end); | ||
240 | #endif | ||
241 | + /* We cannot handle MMIO as second page. */ | ||
242 | + assert(tb->page_addr[1] != -1); | ||
243 | + host = db->host_addr[1]; | ||
244 | + } | ||
245 | + | ||
246 | + /* Use slow path when crossing pages. */ | ||
247 | + if (is_same_page(db, pc)) { | ||
248 | + return NULL; | ||
249 | + } | ||
250 | + } | ||
251 | + | ||
252 | + tcg_debug_assert(pc >= base); | ||
253 | + return host + (pc - base); | ||
68 | } | 254 | } |
69 | 255 | ||
256 | -#define GEN_TRANSLATOR_LD(fullname, type, load_fn, swap_fn) \ | ||
257 | - type fullname ## _swap(CPUArchState *env, DisasContextBase *dcbase, \ | ||
258 | - abi_ptr pc, bool do_swap) \ | ||
259 | - { \ | ||
260 | - translator_maybe_page_protect(dcbase, pc, sizeof(type)); \ | ||
261 | - type ret = load_fn(env, pc); \ | ||
262 | - if (do_swap) { \ | ||
263 | - ret = swap_fn(ret); \ | ||
264 | - } \ | ||
265 | - plugin_insn_append(pc, &ret, sizeof(ret)); \ | ||
266 | - return ret; \ | ||
267 | +uint8_t translator_ldub(CPUArchState *env, DisasContextBase *db, abi_ptr pc) | ||
268 | +{ | ||
269 | + uint8_t ret; | ||
270 | + void *p = translator_access(env, db, pc, sizeof(ret)); | ||
271 | + | ||
272 | + if (p) { | ||
273 | + plugin_insn_append(pc, p, sizeof(ret)); | ||
274 | + return ldub_p(p); | ||
275 | } | ||
276 | + ret = cpu_ldub_code(env, pc); | ||
277 | + plugin_insn_append(pc, &ret, sizeof(ret)); | ||
278 | + return ret; | ||
279 | +} | ||
280 | |||
281 | -FOR_EACH_TRANSLATOR_LD(GEN_TRANSLATOR_LD) | ||
282 | +uint16_t translator_lduw(CPUArchState *env, DisasContextBase *db, abi_ptr pc) | ||
283 | +{ | ||
284 | + uint16_t ret, plug; | ||
285 | + void *p = translator_access(env, db, pc, sizeof(ret)); | ||
286 | |||
287 | -#undef GEN_TRANSLATOR_LD | ||
288 | + if (p) { | ||
289 | + plugin_insn_append(pc, p, sizeof(ret)); | ||
290 | + return lduw_p(p); | ||
291 | + } | ||
292 | + ret = cpu_lduw_code(env, pc); | ||
293 | + plug = tswap16(ret); | ||
294 | + plugin_insn_append(pc, &plug, sizeof(ret)); | ||
295 | + return ret; | ||
296 | +} | ||
297 | + | ||
298 | +uint32_t translator_ldl(CPUArchState *env, DisasContextBase *db, abi_ptr pc) | ||
299 | +{ | ||
300 | + uint32_t ret, plug; | ||
301 | + void *p = translator_access(env, db, pc, sizeof(ret)); | ||
302 | + | ||
303 | + if (p) { | ||
304 | + plugin_insn_append(pc, p, sizeof(ret)); | ||
305 | + return ldl_p(p); | ||
306 | + } | ||
307 | + ret = cpu_ldl_code(env, pc); | ||
308 | + plug = tswap32(ret); | ||
309 | + plugin_insn_append(pc, &plug, sizeof(ret)); | ||
310 | + return ret; | ||
311 | +} | ||
312 | + | ||
313 | +uint64_t translator_ldq(CPUArchState *env, DisasContextBase *db, abi_ptr pc) | ||
314 | +{ | ||
315 | + uint64_t ret, plug; | ||
316 | + void *p = translator_access(env, db, pc, sizeof(ret)); | ||
317 | + | ||
318 | + if (p) { | ||
319 | + plugin_insn_append(pc, p, sizeof(ret)); | ||
320 | + return ldq_p(p); | ||
321 | + } | ||
322 | + ret = cpu_ldq_code(env, pc); | ||
323 | + plug = tswap64(ret); | ||
324 | + plugin_insn_append(pc, &plug, sizeof(ret)); | ||
325 | + return ret; | ||
326 | +} | ||
70 | -- | 327 | -- |
71 | 2.25.1 | 328 | 2.34.1 |
72 | |||
73 | diff view generated by jsdifflib |
1 | GDB single-stepping is now handled generically. | 1 | From: Ilya Leoshkevich <iii@linux.ibm.com> |
---|---|---|---|
2 | 2 | ||
3 | Right now translator stops right *after* the end of a page, which | ||
4 | breaks reporting of fault locations when the last instruction of a | ||
5 | multi-insn translation block crosses a page boundary. | ||
6 | |||
7 | Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-Id: <20220817150506.592862-3-iii@linux.ibm.com> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 11 | --- |
5 | target/s390x/tcg/translate.c | 8 ++------ | 12 | target/s390x/tcg/translate.c | 15 +++- |
6 | 1 file changed, 2 insertions(+), 6 deletions(-) | 13 | tests/tcg/s390x/noexec.c | 106 +++++++++++++++++++++++ |
14 | tests/tcg/multiarch/noexec.c.inc | 139 +++++++++++++++++++++++++++++++ | ||
15 | tests/tcg/s390x/Makefile.target | 1 + | ||
16 | 4 files changed, 257 insertions(+), 4 deletions(-) | ||
17 | create mode 100644 tests/tcg/s390x/noexec.c | ||
18 | create mode 100644 tests/tcg/multiarch/noexec.c.inc | ||
7 | 19 | ||
8 | diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c | 20 | diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c |
9 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
10 | --- a/target/s390x/tcg/translate.c | 22 | --- a/target/s390x/tcg/translate.c |
11 | +++ b/target/s390x/tcg/translate.c | 23 | +++ b/target/s390x/tcg/translate.c |
12 | @@ -XXX,XX +XXX,XX @@ struct DisasContext { | 24 | @@ -XXX,XX +XXX,XX @@ static void s390x_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) |
13 | uint64_t pc_tmp; | 25 | dc->insn_start = tcg_last_op(); |
14 | uint32_t ilen; | ||
15 | enum cc_op cc_op; | ||
16 | - bool do_debug; | ||
17 | }; | ||
18 | |||
19 | /* Information carried about a condition to be evaluated. */ | ||
20 | @@ -XXX,XX +XXX,XX @@ static void s390x_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | ||
21 | |||
22 | dc->cc_op = CC_OP_DYNAMIC; | ||
23 | dc->ex_value = dc->base.tb->cs_base; | ||
24 | - dc->do_debug = dc->base.singlestep_enabled; | ||
25 | } | 26 | } |
26 | 27 | ||
27 | static void s390x_tr_tb_start(DisasContextBase *db, CPUState *cs) | 28 | +static target_ulong get_next_pc(CPUS390XState *env, DisasContext *s, |
28 | @@ -XXX,XX +XXX,XX @@ static void s390x_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) | 29 | + uint64_t pc) |
29 | /* FALLTHRU */ | 30 | +{ |
30 | case DISAS_PC_CC_UPDATED: | 31 | + uint64_t insn = ld_code2(env, s, pc); |
31 | /* Exit the TB, either by raising a debug exception or by return. */ | 32 | + |
32 | - if (dc->do_debug) { | 33 | + return pc + get_ilen((insn >> 8) & 0xff); |
33 | - gen_exception(EXCP_DEBUG); | 34 | +} |
34 | - } else if ((dc->base.tb->flags & FLAG_MASK_PER) || | 35 | + |
35 | - dc->base.is_jmp == DISAS_PC_STALE_NOCHAIN) { | 36 | static void s390x_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) |
36 | + if ((dc->base.tb->flags & FLAG_MASK_PER) || | 37 | { |
37 | + dc->base.is_jmp == DISAS_PC_STALE_NOCHAIN) { | 38 | CPUS390XState *env = cs->env_ptr; |
38 | tcg_gen_exit_tb(NULL, 0); | 39 | @@ -XXX,XX +XXX,XX @@ static void s390x_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) |
39 | } else { | 40 | |
40 | tcg_gen_lookup_and_goto_ptr(); | 41 | dc->base.is_jmp = translate_one(env, dc); |
42 | if (dc->base.is_jmp == DISAS_NEXT) { | ||
43 | - uint64_t page_start; | ||
44 | - | ||
45 | - page_start = dc->base.pc_first & TARGET_PAGE_MASK; | ||
46 | - if (dc->base.pc_next - page_start >= TARGET_PAGE_SIZE || dc->ex_value) { | ||
47 | + if (!is_same_page(dcbase, dc->base.pc_next) || | ||
48 | + !is_same_page(dcbase, get_next_pc(env, dc, dc->base.pc_next)) || | ||
49 | + dc->ex_value) { | ||
50 | dc->base.is_jmp = DISAS_TOO_MANY; | ||
51 | } | ||
52 | } | ||
53 | diff --git a/tests/tcg/s390x/noexec.c b/tests/tcg/s390x/noexec.c | ||
54 | new file mode 100644 | ||
55 | index XXXXXXX..XXXXXXX | ||
56 | --- /dev/null | ||
57 | +++ b/tests/tcg/s390x/noexec.c | ||
58 | @@ -XXX,XX +XXX,XX @@ | ||
59 | +#include "../multiarch/noexec.c.inc" | ||
60 | + | ||
61 | +static void *arch_mcontext_pc(const mcontext_t *ctx) | ||
62 | +{ | ||
63 | + return (void *)ctx->psw.addr; | ||
64 | +} | ||
65 | + | ||
66 | +static int arch_mcontext_arg(const mcontext_t *ctx) | ||
67 | +{ | ||
68 | + return ctx->gregs[2]; | ||
69 | +} | ||
70 | + | ||
71 | +static void arch_flush(void *p, int len) | ||
72 | +{ | ||
73 | +} | ||
74 | + | ||
75 | +extern char noexec_1[]; | ||
76 | +extern char noexec_2[]; | ||
77 | +extern char noexec_end[]; | ||
78 | + | ||
79 | +asm("noexec_1:\n" | ||
80 | + " lgfi %r2,1\n" /* %r2 is 0 on entry, set 1. */ | ||
81 | + "noexec_2:\n" | ||
82 | + " lgfi %r2,2\n" /* %r2 is 0/1; set 2. */ | ||
83 | + " br %r14\n" /* return */ | ||
84 | + "noexec_end:"); | ||
85 | + | ||
86 | +extern char exrl_1[]; | ||
87 | +extern char exrl_2[]; | ||
88 | +extern char exrl_end[]; | ||
89 | + | ||
90 | +asm("exrl_1:\n" | ||
91 | + " exrl %r0, exrl_2\n" | ||
92 | + " br %r14\n" | ||
93 | + "exrl_2:\n" | ||
94 | + " lgfi %r2,2\n" | ||
95 | + "exrl_end:"); | ||
96 | + | ||
97 | +int main(void) | ||
98 | +{ | ||
99 | + struct noexec_test noexec_tests[] = { | ||
100 | + { | ||
101 | + .name = "fallthrough", | ||
102 | + .test_code = noexec_1, | ||
103 | + .test_len = noexec_end - noexec_1, | ||
104 | + .page_ofs = noexec_1 - noexec_2, | ||
105 | + .entry_ofs = noexec_1 - noexec_2, | ||
106 | + .expected_si_ofs = 0, | ||
107 | + .expected_pc_ofs = 0, | ||
108 | + .expected_arg = 1, | ||
109 | + }, | ||
110 | + { | ||
111 | + .name = "jump", | ||
112 | + .test_code = noexec_1, | ||
113 | + .test_len = noexec_end - noexec_1, | ||
114 | + .page_ofs = noexec_1 - noexec_2, | ||
115 | + .entry_ofs = 0, | ||
116 | + .expected_si_ofs = 0, | ||
117 | + .expected_pc_ofs = 0, | ||
118 | + .expected_arg = 0, | ||
119 | + }, | ||
120 | + { | ||
121 | + .name = "exrl", | ||
122 | + .test_code = exrl_1, | ||
123 | + .test_len = exrl_end - exrl_1, | ||
124 | + .page_ofs = exrl_1 - exrl_2, | ||
125 | + .entry_ofs = exrl_1 - exrl_2, | ||
126 | + .expected_si_ofs = 0, | ||
127 | + .expected_pc_ofs = exrl_1 - exrl_2, | ||
128 | + .expected_arg = 0, | ||
129 | + }, | ||
130 | + { | ||
131 | + .name = "fallthrough [cross]", | ||
132 | + .test_code = noexec_1, | ||
133 | + .test_len = noexec_end - noexec_1, | ||
134 | + .page_ofs = noexec_1 - noexec_2 - 2, | ||
135 | + .entry_ofs = noexec_1 - noexec_2 - 2, | ||
136 | + .expected_si_ofs = 0, | ||
137 | + .expected_pc_ofs = -2, | ||
138 | + .expected_arg = 1, | ||
139 | + }, | ||
140 | + { | ||
141 | + .name = "jump [cross]", | ||
142 | + .test_code = noexec_1, | ||
143 | + .test_len = noexec_end - noexec_1, | ||
144 | + .page_ofs = noexec_1 - noexec_2 - 2, | ||
145 | + .entry_ofs = -2, | ||
146 | + .expected_si_ofs = 0, | ||
147 | + .expected_pc_ofs = -2, | ||
148 | + .expected_arg = 0, | ||
149 | + }, | ||
150 | + { | ||
151 | + .name = "exrl [cross]", | ||
152 | + .test_code = exrl_1, | ||
153 | + .test_len = exrl_end - exrl_1, | ||
154 | + .page_ofs = exrl_1 - exrl_2 - 2, | ||
155 | + .entry_ofs = exrl_1 - exrl_2 - 2, | ||
156 | + .expected_si_ofs = 0, | ||
157 | + .expected_pc_ofs = exrl_1 - exrl_2 - 2, | ||
158 | + .expected_arg = 0, | ||
159 | + }, | ||
160 | + }; | ||
161 | + | ||
162 | + return test_noexec(noexec_tests, | ||
163 | + sizeof(noexec_tests) / sizeof(noexec_tests[0])); | ||
164 | +} | ||
165 | diff --git a/tests/tcg/multiarch/noexec.c.inc b/tests/tcg/multiarch/noexec.c.inc | ||
166 | new file mode 100644 | ||
167 | index XXXXXXX..XXXXXXX | ||
168 | --- /dev/null | ||
169 | +++ b/tests/tcg/multiarch/noexec.c.inc | ||
170 | @@ -XXX,XX +XXX,XX @@ | ||
171 | +/* | ||
172 | + * Common code for arch-specific MMU_INST_FETCH fault testing. | ||
173 | + */ | ||
174 | + | ||
175 | +#define _GNU_SOURCE | ||
176 | + | ||
177 | +#include <assert.h> | ||
178 | +#include <signal.h> | ||
179 | +#include <stdio.h> | ||
180 | +#include <stdlib.h> | ||
181 | +#include <string.h> | ||
182 | +#include <errno.h> | ||
183 | +#include <unistd.h> | ||
184 | +#include <sys/mman.h> | ||
185 | +#include <sys/ucontext.h> | ||
186 | + | ||
187 | +/* Forward declarations. */ | ||
188 | + | ||
189 | +static void *arch_mcontext_pc(const mcontext_t *ctx); | ||
190 | +static int arch_mcontext_arg(const mcontext_t *ctx); | ||
191 | +static void arch_flush(void *p, int len); | ||
192 | + | ||
193 | +/* Testing infrastructure. */ | ||
194 | + | ||
195 | +struct noexec_test { | ||
196 | + const char *name; | ||
197 | + const char *test_code; | ||
198 | + int test_len; | ||
199 | + int page_ofs; | ||
200 | + int entry_ofs; | ||
201 | + int expected_si_ofs; | ||
202 | + int expected_pc_ofs; | ||
203 | + int expected_arg; | ||
204 | +}; | ||
205 | + | ||
206 | +static void *page_base; | ||
207 | +static int page_size; | ||
208 | +static const struct noexec_test *current_noexec_test; | ||
209 | + | ||
210 | +static void handle_err(const char *syscall) | ||
211 | +{ | ||
212 | + printf("[ FAILED ] %s: %s\n", syscall, strerror(errno)); | ||
213 | + exit(EXIT_FAILURE); | ||
214 | +} | ||
215 | + | ||
216 | +static void handle_segv(int sig, siginfo_t *info, void *ucontext) | ||
217 | +{ | ||
218 | + const struct noexec_test *test = current_noexec_test; | ||
219 | + const mcontext_t *mc = &((ucontext_t *)ucontext)->uc_mcontext; | ||
220 | + void *expected_si; | ||
221 | + void *expected_pc; | ||
222 | + void *pc; | ||
223 | + int arg; | ||
224 | + | ||
225 | + if (test == NULL) { | ||
226 | + printf("[ FAILED ] unexpected SEGV\n"); | ||
227 | + exit(EXIT_FAILURE); | ||
228 | + } | ||
229 | + current_noexec_test = NULL; | ||
230 | + | ||
231 | + expected_si = page_base + test->expected_si_ofs; | ||
232 | + if (info->si_addr != expected_si) { | ||
233 | + printf("[ FAILED ] wrong si_addr (%p != %p)\n", | ||
234 | + info->si_addr, expected_si); | ||
235 | + exit(EXIT_FAILURE); | ||
236 | + } | ||
237 | + | ||
238 | + pc = arch_mcontext_pc(mc); | ||
239 | + expected_pc = page_base + test->expected_pc_ofs; | ||
240 | + if (pc != expected_pc) { | ||
241 | + printf("[ FAILED ] wrong pc (%p != %p)\n", pc, expected_pc); | ||
242 | + exit(EXIT_FAILURE); | ||
243 | + } | ||
244 | + | ||
245 | + arg = arch_mcontext_arg(mc); | ||
246 | + if (arg != test->expected_arg) { | ||
247 | + printf("[ FAILED ] wrong arg (%d != %d)\n", arg, test->expected_arg); | ||
248 | + exit(EXIT_FAILURE); | ||
249 | + } | ||
250 | + | ||
251 | + if (mprotect(page_base, page_size, | ||
252 | + PROT_READ | PROT_WRITE | PROT_EXEC) < 0) { | ||
253 | + handle_err("mprotect"); | ||
254 | + } | ||
255 | +} | ||
256 | + | ||
257 | +static void test_noexec_1(const struct noexec_test *test) | ||
258 | +{ | ||
259 | + void *start = page_base + test->page_ofs; | ||
260 | + void (*fn)(int arg) = page_base + test->entry_ofs; | ||
261 | + | ||
262 | + memcpy(start, test->test_code, test->test_len); | ||
263 | + arch_flush(start, test->test_len); | ||
264 | + | ||
265 | + /* Trigger TB creation in order to test invalidation. */ | ||
266 | + fn(0); | ||
267 | + | ||
268 | + if (mprotect(page_base, page_size, PROT_NONE) < 0) { | ||
269 | + handle_err("mprotect"); | ||
270 | + } | ||
271 | + | ||
272 | + /* Trigger SEGV and check that handle_segv() ran. */ | ||
273 | + current_noexec_test = test; | ||
274 | + fn(0); | ||
275 | + assert(current_noexec_test == NULL); | ||
276 | +} | ||
277 | + | ||
278 | +static int test_noexec(struct noexec_test *tests, size_t n_tests) | ||
279 | +{ | ||
280 | + struct sigaction act; | ||
281 | + size_t i; | ||
282 | + | ||
283 | + memset(&act, 0, sizeof(act)); | ||
284 | + act.sa_sigaction = handle_segv; | ||
285 | + act.sa_flags = SA_SIGINFO; | ||
286 | + if (sigaction(SIGSEGV, &act, NULL) < 0) { | ||
287 | + handle_err("sigaction"); | ||
288 | + } | ||
289 | + | ||
290 | + page_size = getpagesize(); | ||
291 | + page_base = mmap(NULL, 2 * page_size, | ||
292 | + PROT_READ | PROT_WRITE | PROT_EXEC, | ||
293 | + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); | ||
294 | + if (page_base == MAP_FAILED) { | ||
295 | + handle_err("mmap"); | ||
296 | + } | ||
297 | + page_base += page_size; | ||
298 | + | ||
299 | + for (i = 0; i < n_tests; i++) { | ||
300 | + struct noexec_test *test = &tests[i]; | ||
301 | + | ||
302 | + printf("[ RUN ] %s\n", test->name); | ||
303 | + test_noexec_1(test); | ||
304 | + printf("[ OK ]\n"); | ||
305 | + } | ||
306 | + | ||
307 | + printf("[ PASSED ]\n"); | ||
308 | + return EXIT_SUCCESS; | ||
309 | +} | ||
310 | diff --git a/tests/tcg/s390x/Makefile.target b/tests/tcg/s390x/Makefile.target | ||
311 | index XXXXXXX..XXXXXXX 100644 | ||
312 | --- a/tests/tcg/s390x/Makefile.target | ||
313 | +++ b/tests/tcg/s390x/Makefile.target | ||
314 | @@ -XXX,XX +XXX,XX @@ TESTS+=shift | ||
315 | TESTS+=trap | ||
316 | TESTS+=signals-s390x | ||
317 | TESTS+=branch-relative-long | ||
318 | +TESTS+=noexec | ||
319 | |||
320 | Z14_TESTS=vfminmax | ||
321 | vfminmax: LDFLAGS+=-lm | ||
41 | -- | 322 | -- |
42 | 2.25.1 | 323 | 2.34.1 |
43 | |||
44 | diff view generated by jsdifflib |
1 | We were using singlestep_enabled as a proxy for whether | 1 | From: Ilya Leoshkevich <iii@linux.ibm.com> |
---|---|---|---|
2 | translator_use_goto_tb would always return false. | 2 | |
3 | 3 | Right now translator stops right *after* the end of a page, which | |
4 | breaks reporting of fault locations when the last instruction of a | ||
5 | multi-insn translation block crosses a page boundary. | ||
6 | |||
7 | An implementation, like the one arm and s390x have, would require an | ||
8 | i386 length disassembler, which is burdensome to maintain. Another | ||
9 | alternative would be to single-step at the end of a guest page, but | ||
10 | this may come with a performance impact. | ||
11 | |||
12 | Fix by snapshotting disassembly state and restoring it after we figure | ||
13 | out we crossed a page boundary. This includes rolling back cc_op | ||
14 | updates and emitted ops. | ||
15 | |||
16 | Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
17 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
18 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1143 | ||
19 | Message-Id: <20220817150506.592862-4-iii@linux.ibm.com> | ||
20 | [rth: Simplify end-of-insn cross-page checks.] | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 21 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | --- | 22 | --- |
6 | target/i386/tcg/translate.c | 5 +++-- | 23 | target/i386/tcg/translate.c | 64 ++++++++++++++++----------- |
7 | 1 file changed, 3 insertions(+), 2 deletions(-) | 24 | tests/tcg/x86_64/noexec.c | 75 ++++++++++++++++++++++++++++++++ |
25 | tests/tcg/x86_64/Makefile.target | 3 +- | ||
26 | 3 files changed, 116 insertions(+), 26 deletions(-) | ||
27 | create mode 100644 tests/tcg/x86_64/noexec.c | ||
8 | 28 | ||
9 | diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c | 29 | diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c |
10 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
11 | --- a/target/i386/tcg/translate.c | 31 | --- a/target/i386/tcg/translate.c |
12 | +++ b/target/i386/tcg/translate.c | 32 | +++ b/target/i386/tcg/translate.c |
13 | @@ -XXX,XX +XXX,XX @@ static void i386_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu) | 33 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { |
34 | TCGv_i64 tmp1_i64; | ||
35 | |||
36 | sigjmp_buf jmpbuf; | ||
37 | + TCGOp *prev_insn_end; | ||
38 | } DisasContext; | ||
39 | |||
40 | /* The environment in which user-only runs is constrained. */ | ||
41 | @@ -XXX,XX +XXX,XX @@ static uint64_t advance_pc(CPUX86State *env, DisasContext *s, int num_bytes) | ||
42 | { | ||
43 | uint64_t pc = s->pc; | ||
44 | |||
45 | + /* This is a subsequent insn that crosses a page boundary. */ | ||
46 | + if (s->base.num_insns > 1 && | ||
47 | + !is_same_page(&s->base, s->pc + num_bytes - 1)) { | ||
48 | + siglongjmp(s->jmpbuf, 2); | ||
49 | + } | ||
50 | + | ||
51 | s->pc += num_bytes; | ||
52 | if (unlikely(s->pc - s->pc_start > X86_MAX_INSN_LENGTH)) { | ||
53 | /* If the instruction's 16th byte is on a different page than the 1st, a | ||
54 | @@ -XXX,XX +XXX,XX @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) | ||
55 | int modrm, reg, rm, mod, op, opreg, val; | ||
56 | target_ulong next_eip, tval; | ||
57 | target_ulong pc_start = s->base.pc_next; | ||
58 | + bool orig_cc_op_dirty = s->cc_op_dirty; | ||
59 | + CCOp orig_cc_op = s->cc_op; | ||
60 | |||
61 | s->pc_start = s->pc = pc_start; | ||
62 | s->override = -1; | ||
63 | @@ -XXX,XX +XXX,XX @@ static target_ulong disas_insn(DisasContext *s, CPUState *cpu) | ||
64 | s->rip_offset = 0; /* for relative ip address */ | ||
65 | s->vex_l = 0; | ||
66 | s->vex_v = 0; | ||
67 | - if (sigsetjmp(s->jmpbuf, 0) != 0) { | ||
68 | + switch (sigsetjmp(s->jmpbuf, 0)) { | ||
69 | + case 0: | ||
70 | + break; | ||
71 | + case 1: | ||
72 | gen_exception_gpf(s); | ||
73 | return s->pc; | ||
74 | + case 2: | ||
75 | + /* Restore state that may affect the next instruction. */ | ||
76 | + s->cc_op_dirty = orig_cc_op_dirty; | ||
77 | + s->cc_op = orig_cc_op; | ||
78 | + s->base.num_insns--; | ||
79 | + tcg_remove_ops_after(s->prev_insn_end); | ||
80 | + s->base.is_jmp = DISAS_TOO_MANY; | ||
81 | + return pc_start; | ||
82 | + default: | ||
83 | + g_assert_not_reached(); | ||
84 | } | ||
85 | |||
86 | prefixes = 0; | ||
87 | @@ -XXX,XX +XXX,XX @@ static void i386_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu) | ||
88 | { | ||
14 | DisasContext *dc = container_of(dcbase, DisasContext, base); | 89 | DisasContext *dc = container_of(dcbase, DisasContext, base); |
15 | CPUX86State *env = cpu->env_ptr; | 90 | |
16 | uint32_t flags = dc->base.tb->flags; | 91 | + dc->prev_insn_end = tcg_last_op(); |
17 | + uint32_t cflags = tb_cflags(dc->base.tb); | 92 | tcg_gen_insn_start(dc->base.pc_next, dc->cc_op); |
18 | int cpl = (flags >> HF_CPL_SHIFT) & 3; | 93 | } |
19 | int iopl = (flags >> IOPL_SHIFT) & 3; | 94 | |
20 | 95 | @@ -XXX,XX +XXX,XX @@ static void i386_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) | |
21 | @@ -XXX,XX +XXX,XX @@ static void i386_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu) | 96 | #endif |
22 | dc->cpuid_ext3_features = env->features[FEAT_8000_0001_ECX]; | 97 | |
23 | dc->cpuid_7_0_ebx_features = env->features[FEAT_7_0_EBX]; | 98 | pc_next = disas_insn(dc, cpu); |
24 | dc->cpuid_xsave_features = env->features[FEAT_XSAVE]; | 99 | - |
25 | - dc->jmp_opt = !(dc->base.singlestep_enabled || | 100 | - if (dc->flags & (HF_TF_MASK | HF_INHIBIT_IRQ_MASK)) { |
26 | + dc->jmp_opt = !((cflags & CF_NO_GOTO_TB) || | 101 | - /* if single step mode, we generate only one instruction and |
27 | (flags & (HF_TF_MASK | HF_INHIBIT_IRQ_MASK))); | 102 | - generate an exception */ |
28 | /* | 103 | - /* if irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear |
29 | * If jmp_opt, we want to handle each string instruction individually. | 104 | - the flag and abort the translation to give the irqs a |
30 | * For icount also disable repz optimization so that each iteration | 105 | - chance to happen */ |
31 | * is accounted separately. | 106 | - dc->base.is_jmp = DISAS_TOO_MANY; |
32 | */ | 107 | - } else if ((tb_cflags(dc->base.tb) & CF_USE_ICOUNT) |
33 | - dc->repz_opt = !dc->jmp_opt && !(tb_cflags(dc->base.tb) & CF_USE_ICOUNT); | 108 | - && ((pc_next & TARGET_PAGE_MASK) |
34 | + dc->repz_opt = !dc->jmp_opt && !(cflags & CF_USE_ICOUNT); | 109 | - != ((pc_next + TARGET_MAX_INSN_SIZE - 1) |
35 | 110 | - & TARGET_PAGE_MASK) | |
36 | dc->T0 = tcg_temp_new(); | 111 | - || (pc_next & ~TARGET_PAGE_MASK) == 0)) { |
37 | dc->T1 = tcg_temp_new(); | 112 | - /* Do not cross the boundary of the pages in icount mode, |
113 | - it can cause an exception. Do it only when boundary is | ||
114 | - crossed by the first instruction in the block. | ||
115 | - If current instruction already crossed the bound - it's ok, | ||
116 | - because an exception hasn't stopped this code. | ||
117 | - */ | ||
118 | - dc->base.is_jmp = DISAS_TOO_MANY; | ||
119 | - } else if ((pc_next - dc->base.pc_first) >= (TARGET_PAGE_SIZE - 32)) { | ||
120 | - dc->base.is_jmp = DISAS_TOO_MANY; | ||
121 | - } | ||
122 | - | ||
123 | dc->base.pc_next = pc_next; | ||
124 | + | ||
125 | + if (dc->base.is_jmp == DISAS_NEXT) { | ||
126 | + if (dc->flags & (HF_TF_MASK | HF_INHIBIT_IRQ_MASK)) { | ||
127 | + /* | ||
128 | + * If single step mode, we generate only one instruction and | ||
129 | + * generate an exception. | ||
130 | + * If irq were inhibited with HF_INHIBIT_IRQ_MASK, we clear | ||
131 | + * the flag and abort the translation to give the irqs a | ||
132 | + * chance to happen. | ||
133 | + */ | ||
134 | + dc->base.is_jmp = DISAS_TOO_MANY; | ||
135 | + } else if (!is_same_page(&dc->base, pc_next)) { | ||
136 | + dc->base.is_jmp = DISAS_TOO_MANY; | ||
137 | + } | ||
138 | + } | ||
139 | } | ||
140 | |||
141 | static void i386_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu) | ||
142 | diff --git a/tests/tcg/x86_64/noexec.c b/tests/tcg/x86_64/noexec.c | ||
143 | new file mode 100644 | ||
144 | index XXXXXXX..XXXXXXX | ||
145 | --- /dev/null | ||
146 | +++ b/tests/tcg/x86_64/noexec.c | ||
147 | @@ -XXX,XX +XXX,XX @@ | ||
148 | +#include "../multiarch/noexec.c.inc" | ||
149 | + | ||
150 | +static void *arch_mcontext_pc(const mcontext_t *ctx) | ||
151 | +{ | ||
152 | + return (void *)ctx->gregs[REG_RIP]; | ||
153 | +} | ||
154 | + | ||
155 | +int arch_mcontext_arg(const mcontext_t *ctx) | ||
156 | +{ | ||
157 | + return ctx->gregs[REG_RDI]; | ||
158 | +} | ||
159 | + | ||
160 | +static void arch_flush(void *p, int len) | ||
161 | +{ | ||
162 | +} | ||
163 | + | ||
164 | +extern char noexec_1[]; | ||
165 | +extern char noexec_2[]; | ||
166 | +extern char noexec_end[]; | ||
167 | + | ||
168 | +asm("noexec_1:\n" | ||
169 | + " movq $1,%rdi\n" /* %rdi is 0 on entry, set 1. */ | ||
170 | + "noexec_2:\n" | ||
171 | + " movq $2,%rdi\n" /* %rdi is 0/1; set 2. */ | ||
172 | + " ret\n" | ||
173 | + "noexec_end:"); | ||
174 | + | ||
175 | +int main(void) | ||
176 | +{ | ||
177 | + struct noexec_test noexec_tests[] = { | ||
178 | + { | ||
179 | + .name = "fallthrough", | ||
180 | + .test_code = noexec_1, | ||
181 | + .test_len = noexec_end - noexec_1, | ||
182 | + .page_ofs = noexec_1 - noexec_2, | ||
183 | + .entry_ofs = noexec_1 - noexec_2, | ||
184 | + .expected_si_ofs = 0, | ||
185 | + .expected_pc_ofs = 0, | ||
186 | + .expected_arg = 1, | ||
187 | + }, | ||
188 | + { | ||
189 | + .name = "jump", | ||
190 | + .test_code = noexec_1, | ||
191 | + .test_len = noexec_end - noexec_1, | ||
192 | + .page_ofs = noexec_1 - noexec_2, | ||
193 | + .entry_ofs = 0, | ||
194 | + .expected_si_ofs = 0, | ||
195 | + .expected_pc_ofs = 0, | ||
196 | + .expected_arg = 0, | ||
197 | + }, | ||
198 | + { | ||
199 | + .name = "fallthrough [cross]", | ||
200 | + .test_code = noexec_1, | ||
201 | + .test_len = noexec_end - noexec_1, | ||
202 | + .page_ofs = noexec_1 - noexec_2 - 2, | ||
203 | + .entry_ofs = noexec_1 - noexec_2 - 2, | ||
204 | + .expected_si_ofs = 0, | ||
205 | + .expected_pc_ofs = -2, | ||
206 | + .expected_arg = 1, | ||
207 | + }, | ||
208 | + { | ||
209 | + .name = "jump [cross]", | ||
210 | + .test_code = noexec_1, | ||
211 | + .test_len = noexec_end - noexec_1, | ||
212 | + .page_ofs = noexec_1 - noexec_2 - 2, | ||
213 | + .entry_ofs = -2, | ||
214 | + .expected_si_ofs = 0, | ||
215 | + .expected_pc_ofs = -2, | ||
216 | + .expected_arg = 0, | ||
217 | + }, | ||
218 | + }; | ||
219 | + | ||
220 | + return test_noexec(noexec_tests, | ||
221 | + sizeof(noexec_tests) / sizeof(noexec_tests[0])); | ||
222 | +} | ||
223 | diff --git a/tests/tcg/x86_64/Makefile.target b/tests/tcg/x86_64/Makefile.target | ||
224 | index XXXXXXX..XXXXXXX 100644 | ||
225 | --- a/tests/tcg/x86_64/Makefile.target | ||
226 | +++ b/tests/tcg/x86_64/Makefile.target | ||
227 | @@ -XXX,XX +XXX,XX @@ include $(SRC_PATH)/tests/tcg/i386/Makefile.target | ||
228 | |||
229 | ifeq ($(filter %-linux-user, $(TARGET)),$(TARGET)) | ||
230 | X86_64_TESTS += vsyscall | ||
231 | +X86_64_TESTS += noexec | ||
232 | TESTS=$(MULTIARCH_TESTS) $(X86_64_TESTS) test-x86_64 | ||
233 | else | ||
234 | TESTS=$(MULTIARCH_TESTS) | ||
235 | @@ -XXX,XX +XXX,XX @@ test-x86_64: LDFLAGS+=-lm -lc | ||
236 | test-x86_64: test-i386.c test-i386.h test-i386-shift.h test-i386-muldiv.h | ||
237 | $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) | ||
238 | |||
239 | -vsyscall: $(SRC_PATH)/tests/tcg/x86_64/vsyscall.c | ||
240 | +%: $(SRC_PATH)/tests/tcg/x86_64/%.c | ||
241 | $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) | ||
38 | -- | 242 | -- |
39 | 2.25.1 | 243 | 2.34.1 |
40 | |||
41 | diff view generated by jsdifflib |
1 | GDB single-stepping is now handled generically. | 1 | These will be useful in properly ending the TB. |
---|---|---|---|
2 | 2 | ||
3 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
4 | Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
5 | Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | --- | 7 | --- |
5 | target/arm/translate-a64.c | 10 ++-------- | 8 | target/riscv/translate.c | 10 +++++++++- |
6 | target/arm/translate.c | 36 ++++++------------------------------ | 9 | 1 file changed, 9 insertions(+), 1 deletion(-) |
7 | 2 files changed, 8 insertions(+), 38 deletions(-) | ||
8 | 10 | ||
9 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 11 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c |
10 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
11 | --- a/target/arm/translate-a64.c | 13 | --- a/target/riscv/translate.c |
12 | +++ b/target/arm/translate-a64.c | 14 | +++ b/target/riscv/translate.c |
13 | @@ -XXX,XX +XXX,XX @@ static inline void gen_goto_tb(DisasContext *s, int n, uint64_t dest) | 15 | @@ -XXX,XX +XXX,XX @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc) |
14 | gen_a64_set_pc_im(dest); | 16 | /* Include decoders for factored-out extensions */ |
15 | if (s->ss_active) { | 17 | #include "decode-XVentanaCondOps.c.inc" |
16 | gen_step_complete_exception(s); | 18 | |
17 | - } else if (s->base.singlestep_enabled) { | 19 | +/* The specification allows for longer insns, but not supported by qemu. */ |
18 | - gen_exception_internal(EXCP_DEBUG); | 20 | +#define MAX_INSN_LEN 4 |
19 | } else { | 21 | + |
20 | tcg_gen_lookup_and_goto_ptr(); | 22 | +static inline int insn_len(uint16_t first_word) |
21 | s->base.is_jmp = DISAS_NORETURN; | 23 | +{ |
22 | @@ -XXX,XX +XXX,XX @@ static void aarch64_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu) | 24 | + return (first_word & 3) == 3 ? 4 : 2; |
23 | { | 25 | +} |
24 | DisasContext *dc = container_of(dcbase, DisasContext, base); | 26 | + |
25 | 27 | static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) | |
26 | - if (unlikely(dc->base.singlestep_enabled || dc->ss_active)) { | ||
27 | + if (unlikely(dc->ss_active)) { | ||
28 | /* Note that this means single stepping WFI doesn't halt the CPU. | ||
29 | * For conditional branch insns this is harmless unreachable code as | ||
30 | * gen_goto_tb() has already handled emitting the debug exception | ||
31 | @@ -XXX,XX +XXX,XX @@ static void aarch64_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu) | ||
32 | /* fall through */ | ||
33 | case DISAS_EXIT: | ||
34 | case DISAS_JUMP: | ||
35 | - if (dc->base.singlestep_enabled) { | ||
36 | - gen_exception_internal(EXCP_DEBUG); | ||
37 | - } else { | ||
38 | - gen_step_complete_exception(dc); | ||
39 | - } | ||
40 | + gen_step_complete_exception(dc); | ||
41 | break; | ||
42 | case DISAS_NORETURN: | ||
43 | break; | ||
44 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/target/arm/translate.c | ||
47 | +++ b/target/arm/translate.c | ||
48 | @@ -XXX,XX +XXX,XX @@ static void gen_exception_internal(int excp) | ||
49 | tcg_temp_free_i32(tcg_excp); | ||
50 | } | ||
51 | |||
52 | -static void gen_step_complete_exception(DisasContext *s) | ||
53 | +static void gen_singlestep_exception(DisasContext *s) | ||
54 | { | ||
55 | /* We just completed step of an insn. Move from Active-not-pending | ||
56 | * to Active-pending, and then also take the swstep exception. | ||
57 | @@ -XXX,XX +XXX,XX @@ static void gen_step_complete_exception(DisasContext *s) | ||
58 | s->base.is_jmp = DISAS_NORETURN; | ||
59 | } | ||
60 | |||
61 | -static void gen_singlestep_exception(DisasContext *s) | ||
62 | -{ | ||
63 | - /* Generate the right kind of exception for singlestep, which is | ||
64 | - * either the architectural singlestep or EXCP_DEBUG for QEMU's | ||
65 | - * gdb singlestepping. | ||
66 | - */ | ||
67 | - if (s->ss_active) { | ||
68 | - gen_step_complete_exception(s); | ||
69 | - } else { | ||
70 | - gen_exception_internal(EXCP_DEBUG); | ||
71 | - } | ||
72 | -} | ||
73 | - | ||
74 | -static inline bool is_singlestepping(DisasContext *s) | ||
75 | -{ | ||
76 | - /* Return true if we are singlestepping either because of | ||
77 | - * architectural singlestep or QEMU gdbstub singlestep. This does | ||
78 | - * not include the command line '-singlestep' mode which is rather | ||
79 | - * misnamed as it only means "one instruction per TB" and doesn't | ||
80 | - * affect the code we generate. | ||
81 | - */ | ||
82 | - return s->base.singlestep_enabled || s->ss_active; | ||
83 | -} | ||
84 | - | ||
85 | void clear_eci_state(DisasContext *s) | ||
86 | { | 28 | { |
87 | /* | 29 | /* |
88 | @@ -XXX,XX +XXX,XX @@ static inline void gen_bx_excret_final_code(DisasContext *s) | 30 | @@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) |
89 | /* Is the new PC value in the magic range indicating exception return? */ | 31 | }; |
90 | tcg_gen_brcondi_i32(TCG_COND_GEU, cpu_R[15], min_magic, excret_label); | 32 | |
91 | /* No: end the TB as we would for a DISAS_JMP */ | 33 | /* Check for compressed insn */ |
92 | - if (is_singlestepping(s)) { | 34 | - if (extract16(opcode, 0, 2) != 3) { |
93 | + if (s->ss_active) { | 35 | + if (insn_len(opcode) == 2) { |
94 | gen_singlestep_exception(s); | 36 | if (!has_ext(ctx, RVC)) { |
95 | } else { | 37 | gen_exception_illegal(ctx); |
96 | tcg_gen_exit_tb(NULL, 0); | ||
97 | @@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *s, int n, target_ulong dest) | ||
98 | /* Jump, specifying which TB number to use if we gen_goto_tb() */ | ||
99 | static inline void gen_jmp_tb(DisasContext *s, uint32_t dest, int tbno) | ||
100 | { | ||
101 | - if (unlikely(is_singlestepping(s))) { | ||
102 | + if (unlikely(s->ss_active)) { | ||
103 | /* An indirect jump so that we still trigger the debug exception. */ | ||
104 | gen_set_pc_im(s, dest); | ||
105 | s->base.is_jmp = DISAS_JUMP; | ||
106 | @@ -XXX,XX +XXX,XX @@ static void arm_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | ||
107 | dc->page_start = dc->base.pc_first & TARGET_PAGE_MASK; | ||
108 | |||
109 | /* If architectural single step active, limit to 1. */ | ||
110 | - if (is_singlestepping(dc)) { | ||
111 | + if (dc->ss_active) { | ||
112 | dc->base.max_insns = 1; | ||
113 | } | ||
114 | |||
115 | @@ -XXX,XX +XXX,XX @@ static void arm_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu) | ||
116 | * insn codepath itself. | ||
117 | */ | ||
118 | gen_bx_excret_final_code(dc); | ||
119 | - } else if (unlikely(is_singlestepping(dc))) { | ||
120 | + } else if (unlikely(dc->ss_active)) { | ||
121 | /* Unconditional and "condition passed" instruction codepath. */ | ||
122 | switch (dc->base.is_jmp) { | ||
123 | case DISAS_SWI: | ||
124 | @@ -XXX,XX +XXX,XX @@ static void arm_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu) | ||
125 | /* "Condition failed" instruction codepath for the branch/trap insn */ | ||
126 | gen_set_label(dc->condlabel); | ||
127 | gen_set_condexec(dc); | ||
128 | - if (unlikely(is_singlestepping(dc))) { | ||
129 | + if (unlikely(dc->ss_active)) { | ||
130 | gen_set_pc_im(dc, dc->base.pc_next); | ||
131 | gen_singlestep_exception(dc); | ||
132 | } else { | 38 | } else { |
133 | -- | 39 | -- |
134 | 2.25.1 | 40 | 2.34.1 |
135 | |||
136 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | We were using singlestep_enabled as a proxy for whether | ||
2 | translator_use_goto_tb would always return false. | ||
3 | 1 | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | target/microblaze/translate.c | 4 ++-- | ||
7 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
8 | |||
9 | diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c | ||
10 | index XXXXXXX..XXXXXXX 100644 | ||
11 | --- a/target/microblaze/translate.c | ||
12 | +++ b/target/microblaze/translate.c | ||
13 | @@ -XXX,XX +XXX,XX @@ static void mb_tr_tb_stop(DisasContextBase *dcb, CPUState *cs) | ||
14 | break; | ||
15 | |||
16 | case DISAS_JUMP: | ||
17 | - if (dc->jmp_dest != -1 && !cs->singlestep_enabled) { | ||
18 | + if (dc->jmp_dest != -1 && !(tb_cflags(dc->base.tb) & CF_NO_GOTO_TB)) { | ||
19 | /* Direct jump. */ | ||
20 | tcg_gen_discard_i32(cpu_btarget); | ||
21 | |||
22 | @@ -XXX,XX +XXX,XX @@ static void mb_tr_tb_stop(DisasContextBase *dcb, CPUState *cs) | ||
23 | return; | ||
24 | } | ||
25 | |||
26 | - /* Indirect jump (or direct jump w/ singlestep) */ | ||
27 | + /* Indirect jump (or direct jump w/ goto_tb disabled) */ | ||
28 | tcg_gen_mov_i32(cpu_pc, cpu_btarget); | ||
29 | tcg_gen_discard_i32(cpu_btarget); | ||
30 | |||
31 | -- | ||
32 | 2.25.1 | ||
33 | |||
34 | diff view generated by jsdifflib |
1 | GDB single-stepping is now handled generically, which means | 1 | Right now the translator stops right *after* the end of a page, which |
---|---|---|---|
2 | we don't need to do anything in the wrappers. | 2 | breaks reporting of fault locations when the last instruction of a |
3 | multi-insn translation block crosses a page boundary. | ||
3 | 4 | ||
5 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1155 | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
7 | Acked-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
8 | Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | --- | 10 | --- |
7 | target/riscv/translate.c | 27 +------------------ | 11 | target/riscv/translate.c | 17 +++++-- |
8 | .../riscv/insn_trans/trans_privileged.c.inc | 4 +-- | 12 | tests/tcg/riscv64/noexec.c | 79 +++++++++++++++++++++++++++++++ |
9 | target/riscv/insn_trans/trans_rvi.c.inc | 8 +++--- | 13 | tests/tcg/riscv64/Makefile.target | 1 + |
10 | target/riscv/insn_trans/trans_rvv.c.inc | 2 +- | 14 | 3 files changed, 93 insertions(+), 4 deletions(-) |
11 | 4 files changed, 7 insertions(+), 34 deletions(-) | 15 | create mode 100644 tests/tcg/riscv64/noexec.c |
12 | 16 | ||
13 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | 17 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c |
14 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/riscv/translate.c | 19 | --- a/target/riscv/translate.c |
16 | +++ b/target/riscv/translate.c | 20 | +++ b/target/riscv/translate.c |
17 | @@ -XXX,XX +XXX,XX @@ static void generate_exception_mtval(DisasContext *ctx, int excp) | 21 | @@ -XXX,XX +XXX,XX @@ static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) |
18 | ctx->base.is_jmp = DISAS_NORETURN; | 22 | } |
19 | } | 23 | ctx->nftemp = 0; |
20 | 24 | ||
21 | -static void gen_exception_debug(void) | 25 | + /* Only the first insn within a TB is allowed to cross a page boundary. */ |
22 | -{ | 26 | if (ctx->base.is_jmp == DISAS_NEXT) { |
23 | - gen_helper_raise_exception(cpu_env, tcg_constant_i32(EXCP_DEBUG)); | 27 | - target_ulong page_start; |
24 | -} | ||
25 | - | 28 | - |
26 | -/* Wrapper around tcg_gen_exit_tb that handles single stepping */ | 29 | - page_start = ctx->base.pc_first & TARGET_PAGE_MASK; |
27 | -static void exit_tb(DisasContext *ctx) | 30 | - if (ctx->base.pc_next - page_start >= TARGET_PAGE_SIZE) { |
28 | -{ | 31 | + if (!is_same_page(&ctx->base, ctx->base.pc_next)) { |
29 | - if (ctx->base.singlestep_enabled) { | 32 | ctx->base.is_jmp = DISAS_TOO_MANY; |
30 | - gen_exception_debug(); | 33 | + } else { |
31 | - } else { | 34 | + unsigned page_ofs = ctx->base.pc_next & ~TARGET_PAGE_MASK; |
32 | - tcg_gen_exit_tb(NULL, 0); | 35 | + |
33 | - } | 36 | + if (page_ofs > TARGET_PAGE_SIZE - MAX_INSN_LEN) { |
34 | -} | 37 | + uint16_t next_insn = cpu_lduw_code(env, ctx->base.pc_next); |
35 | - | 38 | + int len = insn_len(next_insn); |
36 | -/* Wrapper around tcg_gen_lookup_and_goto_ptr that handles single stepping */ | 39 | + |
37 | -static void lookup_and_goto_ptr(DisasContext *ctx) | 40 | + if (!is_same_page(&ctx->base, ctx->base.pc_next + len)) { |
38 | -{ | 41 | + ctx->base.is_jmp = DISAS_TOO_MANY; |
39 | - if (ctx->base.singlestep_enabled) { | 42 | + } |
40 | - gen_exception_debug(); | 43 | + } |
41 | - } else { | 44 | } |
42 | - tcg_gen_lookup_and_goto_ptr(); | ||
43 | - } | ||
44 | -} | ||
45 | - | ||
46 | static void gen_exception_illegal(DisasContext *ctx) | ||
47 | { | ||
48 | generate_exception(ctx, RISCV_EXCP_ILLEGAL_INST); | ||
49 | @@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) | ||
50 | tcg_gen_exit_tb(ctx->base.tb, n); | ||
51 | } else { | ||
52 | tcg_gen_movi_tl(cpu_pc, dest); | ||
53 | - lookup_and_goto_ptr(ctx); | ||
54 | + tcg_gen_lookup_and_goto_ptr(); | ||
55 | } | 45 | } |
56 | } | 46 | } |
57 | 47 | diff --git a/tests/tcg/riscv64/noexec.c b/tests/tcg/riscv64/noexec.c | |
58 | diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc | 48 | new file mode 100644 |
49 | index XXXXXXX..XXXXXXX | ||
50 | --- /dev/null | ||
51 | +++ b/tests/tcg/riscv64/noexec.c | ||
52 | @@ -XXX,XX +XXX,XX @@ | ||
53 | +#include "../multiarch/noexec.c.inc" | ||
54 | + | ||
55 | +static void *arch_mcontext_pc(const mcontext_t *ctx) | ||
56 | +{ | ||
57 | + return (void *)ctx->__gregs[REG_PC]; | ||
58 | +} | ||
59 | + | ||
60 | +static int arch_mcontext_arg(const mcontext_t *ctx) | ||
61 | +{ | ||
62 | + return ctx->__gregs[REG_A0]; | ||
63 | +} | ||
64 | + | ||
65 | +static void arch_flush(void *p, int len) | ||
66 | +{ | ||
67 | + __builtin___clear_cache(p, p + len); | ||
68 | +} | ||
69 | + | ||
70 | +extern char noexec_1[]; | ||
71 | +extern char noexec_2[]; | ||
72 | +extern char noexec_end[]; | ||
73 | + | ||
74 | +asm(".option push\n" | ||
75 | + ".option norvc\n" | ||
76 | + "noexec_1:\n" | ||
77 | + " li a0,1\n" /* a0 is 0 on entry, set 1. */ | ||
78 | + "noexec_2:\n" | ||
79 | + " li a0,2\n" /* a0 is 0/1; set 2. */ | ||
80 | + " ret\n" | ||
81 | + "noexec_end:\n" | ||
82 | + ".option pop"); | ||
83 | + | ||
84 | +int main(void) | ||
85 | +{ | ||
86 | + struct noexec_test noexec_tests[] = { | ||
87 | + { | ||
88 | + .name = "fallthrough", | ||
89 | + .test_code = noexec_1, | ||
90 | + .test_len = noexec_end - noexec_1, | ||
91 | + .page_ofs = noexec_1 - noexec_2, | ||
92 | + .entry_ofs = noexec_1 - noexec_2, | ||
93 | + .expected_si_ofs = 0, | ||
94 | + .expected_pc_ofs = 0, | ||
95 | + .expected_arg = 1, | ||
96 | + }, | ||
97 | + { | ||
98 | + .name = "jump", | ||
99 | + .test_code = noexec_1, | ||
100 | + .test_len = noexec_end - noexec_1, | ||
101 | + .page_ofs = noexec_1 - noexec_2, | ||
102 | + .entry_ofs = 0, | ||
103 | + .expected_si_ofs = 0, | ||
104 | + .expected_pc_ofs = 0, | ||
105 | + .expected_arg = 0, | ||
106 | + }, | ||
107 | + { | ||
108 | + .name = "fallthrough [cross]", | ||
109 | + .test_code = noexec_1, | ||
110 | + .test_len = noexec_end - noexec_1, | ||
111 | + .page_ofs = noexec_1 - noexec_2 - 2, | ||
112 | + .entry_ofs = noexec_1 - noexec_2 - 2, | ||
113 | + .expected_si_ofs = 0, | ||
114 | + .expected_pc_ofs = -2, | ||
115 | + .expected_arg = 1, | ||
116 | + }, | ||
117 | + { | ||
118 | + .name = "jump [cross]", | ||
119 | + .test_code = noexec_1, | ||
120 | + .test_len = noexec_end - noexec_1, | ||
121 | + .page_ofs = noexec_1 - noexec_2 - 2, | ||
122 | + .entry_ofs = -2, | ||
123 | + .expected_si_ofs = 0, | ||
124 | + .expected_pc_ofs = -2, | ||
125 | + .expected_arg = 0, | ||
126 | + }, | ||
127 | + }; | ||
128 | + | ||
129 | + return test_noexec(noexec_tests, | ||
130 | + sizeof(noexec_tests) / sizeof(noexec_tests[0])); | ||
131 | +} | ||
132 | diff --git a/tests/tcg/riscv64/Makefile.target b/tests/tcg/riscv64/Makefile.target | ||
59 | index XXXXXXX..XXXXXXX 100644 | 133 | index XXXXXXX..XXXXXXX 100644 |
60 | --- a/target/riscv/insn_trans/trans_privileged.c.inc | 134 | --- a/tests/tcg/riscv64/Makefile.target |
61 | +++ b/target/riscv/insn_trans/trans_privileged.c.inc | 135 | +++ b/tests/tcg/riscv64/Makefile.target |
62 | @@ -XXX,XX +XXX,XX @@ static bool trans_sret(DisasContext *ctx, arg_sret *a) | 136 | @@ -XXX,XX +XXX,XX @@ |
63 | 137 | ||
64 | if (has_ext(ctx, RVS)) { | 138 | VPATH += $(SRC_PATH)/tests/tcg/riscv64 |
65 | gen_helper_sret(cpu_pc, cpu_env, cpu_pc); | 139 | TESTS += test-div |
66 | - exit_tb(ctx); /* no chaining */ | 140 | +TESTS += noexec |
67 | + tcg_gen_exit_tb(NULL, 0); /* no chaining */ | ||
68 | ctx->base.is_jmp = DISAS_NORETURN; | ||
69 | } else { | ||
70 | return false; | ||
71 | @@ -XXX,XX +XXX,XX @@ static bool trans_mret(DisasContext *ctx, arg_mret *a) | ||
72 | #ifndef CONFIG_USER_ONLY | ||
73 | tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next); | ||
74 | gen_helper_mret(cpu_pc, cpu_env, cpu_pc); | ||
75 | - exit_tb(ctx); /* no chaining */ | ||
76 | + tcg_gen_exit_tb(NULL, 0); /* no chaining */ | ||
77 | ctx->base.is_jmp = DISAS_NORETURN; | ||
78 | return true; | ||
79 | #else | ||
80 | diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc | ||
81 | index XXXXXXX..XXXXXXX 100644 | ||
82 | --- a/target/riscv/insn_trans/trans_rvi.c.inc | ||
83 | +++ b/target/riscv/insn_trans/trans_rvi.c.inc | ||
84 | @@ -XXX,XX +XXX,XX @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a) | ||
85 | if (a->rd != 0) { | ||
86 | tcg_gen_movi_tl(cpu_gpr[a->rd], ctx->pc_succ_insn); | ||
87 | } | ||
88 | - | ||
89 | - /* No chaining with JALR. */ | ||
90 | - lookup_and_goto_ptr(ctx); | ||
91 | + tcg_gen_lookup_and_goto_ptr(); | ||
92 | |||
93 | if (misaligned) { | ||
94 | gen_set_label(misaligned); | ||
95 | @@ -XXX,XX +XXX,XX @@ static bool trans_fence_i(DisasContext *ctx, arg_fence_i *a) | ||
96 | * however we need to end the translation block | ||
97 | */ | ||
98 | tcg_gen_movi_tl(cpu_pc, ctx->pc_succ_insn); | ||
99 | - exit_tb(ctx); | ||
100 | + tcg_gen_exit_tb(NULL, 0); | ||
101 | ctx->base.is_jmp = DISAS_NORETURN; | ||
102 | return true; | ||
103 | } | ||
104 | @@ -XXX,XX +XXX,XX @@ static bool do_csr_post(DisasContext *ctx) | ||
105 | { | ||
106 | /* We may have changed important cpu state -- exit to main loop. */ | ||
107 | tcg_gen_movi_tl(cpu_pc, ctx->pc_succ_insn); | ||
108 | - exit_tb(ctx); | ||
109 | + tcg_gen_exit_tb(NULL, 0); | ||
110 | ctx->base.is_jmp = DISAS_NORETURN; | ||
111 | return true; | ||
112 | } | ||
113 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
114 | index XXXXXXX..XXXXXXX 100644 | ||
115 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
116 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
117 | @@ -XXX,XX +XXX,XX @@ static bool trans_vsetvl(DisasContext *ctx, arg_vsetvl *a) | ||
118 | gen_set_gpr(ctx, a->rd, dst); | ||
119 | |||
120 | tcg_gen_movi_tl(cpu_pc, ctx->pc_succ_insn); | ||
121 | - lookup_and_goto_ptr(ctx); | ||
122 | + tcg_gen_lookup_and_goto_ptr(); | ||
123 | ctx->base.is_jmp = DISAS_NORETURN; | ||
124 | return true; | ||
125 | } | ||
126 | -- | 141 | -- |
127 | 2.25.1 | 142 | 2.34.1 |
128 | |||
129 | diff view generated by jsdifflib |