1 | The following changes since commit fb7e7990342e59cf67dbd895c1a1e3fb1741df7a: | 1 | The following changes since commit 79b677d658d3d35e1e776826ac4abb28cdce69b8: |
---|---|---|---|
2 | 2 | ||
3 | tests/qtest/qom-test: Do not print tested properties by default (2023-01-16 15:00:57 +0000) | 3 | Merge tag 'net-pull-request' of https://github.com/jasowang/qemu into staging (2023-02-21 11:28:31 +0000) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20230116 | 7 | https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20230221 |
8 | 8 | ||
9 | for you to fetch changes up to 61710a7e23a63546da0071ea32adb96476fa5d07: | 9 | for you to fetch changes up to dbd672c87f19949bb62bfb1fb3a97b9729fd7560: |
10 | 10 | ||
11 | accel/tcg: Split out cpu_exec_{setjmp,loop} (2023-01-16 10:14:12 -1000) | 11 | sysemu/os-win32: fix setjmp/longjmp on windows-arm64 (2023-02-21 13:45:48 -1000) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | - Reorg cpu_tb_exec around setjmp. | 14 | tcg: Allow first half of insn in ram, and second half in mmio |
15 | - Use __attribute__((target)) for buffer_is_zero. | 15 | linux-user/sparc: SIGILL for unknown trap vectors |
16 | - Add perfmap and jitdump for perf support. | 16 | linux-user/microblaze: SIGILL for privileged insns |
17 | linux-user: Fix deadlock while exiting due to signal | ||
18 | target/microblaze: Add gdbstub xml | ||
19 | util: Adjust cacheflush for windows-arm64 | ||
20 | include/sysemu/os-win32: Adjust setjmp/longjmp for windows-arm64 | ||
17 | 21 | ||
18 | ---------------------------------------------------------------- | 22 | ---------------------------------------------------------------- |
19 | Ilya Leoshkevich (3): | 23 | Ilya Leoshkevich (3): |
20 | linux-user: Clean up when exiting due to a signal | 24 | linux-user: Always exit from exclusive state in fork_end() |
21 | accel/tcg: Add debuginfo support | 25 | cpus: Make {start,end}_exclusive() recursive |
22 | tcg: add perfmap and jitdump | 26 | linux-user/microblaze: Handle privileged exception |
23 | 27 | ||
24 | Richard Henderson (2): | 28 | Pierrick Bouvier (2): |
25 | util/bufferiszero: Use __attribute__((target)) for avx2/avx512 | 29 | util/cacheflush: fix cache on windows-arm64 |
26 | accel/tcg: Split out cpu_exec_{setjmp,loop} | 30 | sysemu/os-win32: fix setjmp/longjmp on windows-arm64 |
27 | 31 | ||
28 | docs/devel/tcg.rst | 23 +++ | 32 | Richard Henderson (3): |
29 | meson.build | 16 +- | 33 | accel/tcg: Allow the second page of an instruction to be MMIO |
30 | accel/tcg/debuginfo.h | 77 ++++++++++ | 34 | linux-user/sparc: Raise SIGILL for all unhandled software traps |
31 | accel/tcg/perf.h | 49 ++++++ | 35 | target/microblaze: Add gdbstub xml |
32 | accel/tcg/cpu-exec.c | 111 +++++++------- | 36 | |
33 | accel/tcg/debuginfo.c | 96 ++++++++++++ | 37 | include/hw/core/cpu.h | 4 +- |
34 | accel/tcg/perf.c | 375 ++++++++++++++++++++++++++++++++++++++++++++++ | 38 | include/sysemu/os-win32.h | 28 ++++++++++-- |
35 | accel/tcg/translate-all.c | 7 + | 39 | target/microblaze/cpu.h | 2 + |
36 | hw/core/loader.c | 5 + | 40 | accel/tcg/translator.c | 12 +++++- |
37 | linux-user/elfload.c | 3 + | 41 | cpus-common.c | 12 +++++- |
38 | linux-user/exit.c | 2 + | 42 | linux-user/main.c | 10 +++-- |
39 | linux-user/main.c | 15 ++ | 43 | linux-user/microblaze/cpu_loop.c | 10 ++++- |
40 | linux-user/signal.c | 8 +- | 44 | linux-user/sparc/cpu_loop.c | 8 ++++ |
41 | softmmu/vl.c | 11 ++ | 45 | linux-user/syscall.c | 1 + |
42 | tcg/tcg.c | 2 + | 46 | target/microblaze/cpu.c | 7 ++- |
43 | util/bufferiszero.c | 41 +---- | 47 | target/microblaze/gdbstub.c | 51 ++++++++++++++++------ |
44 | accel/tcg/meson.build | 2 + | 48 | util/cacheflush.c | 14 ++++-- |
45 | linux-user/meson.build | 1 + | 49 | configs/targets/microblaze-linux-user.mak | 1 + |
46 | qemu-options.hx | 20 +++ | 50 | configs/targets/microblaze-softmmu.mak | 1 + |
47 | 19 files changed, 763 insertions(+), 101 deletions(-) | 51 | configs/targets/microblazeel-linux-user.mak | 1 + |
48 | create mode 100644 accel/tcg/debuginfo.h | 52 | configs/targets/microblazeel-softmmu.mak | 1 + |
49 | create mode 100644 accel/tcg/perf.h | 53 | gdb-xml/microblaze-core.xml | 67 +++++++++++++++++++++++++++++ |
50 | create mode 100644 accel/tcg/debuginfo.c | 54 | gdb-xml/microblaze-stack-protect.xml | 12 ++++++ |
51 | create mode 100644 accel/tcg/perf.c | 55 | meson.build | 21 +++++++++ |
56 | 19 files changed, 229 insertions(+), 34 deletions(-) | ||
57 | create mode 100644 gdb-xml/microblaze-core.xml | ||
58 | create mode 100644 gdb-xml/microblaze-stack-protect.xml | diff view generated by jsdifflib |
1 | Recently the g_assert(cpu == current_cpu) test has been | 1 | If an instruction straddles a page boundary, and the first page |
---|---|---|---|
2 | intermittently failing with gcc. Reorg the code around | 2 | was ram, but the second page was MMIO, we would abort. Handle |
3 | the setjmp to minimize the lifetime of the cpu variable | 3 | this as if both pages are MMIO, by setting the ram_addr_t for |
4 | affected by the setjmp. | 4 | the first page to -1. |
5 | 5 | ||
6 | This appears to fix the existing issue with clang as well. | 6 | Reported-by: Sid Manning <sidneym@quicinc.com> |
7 | 7 | Reported-by: Jørgen Hansen <Jorgen.Hansen@wdc.com> | |
8 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1147 | ||
9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
11 | --- | 10 | --- |
12 | accel/tcg/cpu-exec.c | 111 +++++++++++++++++++++---------------------- | 11 | accel/tcg/translator.c | 12 ++++++++++-- |
13 | 1 file changed, 54 insertions(+), 57 deletions(-) | 12 | 1 file changed, 10 insertions(+), 2 deletions(-) |
14 | 13 | ||
15 | diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c | 14 | diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c |
16 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/accel/tcg/cpu-exec.c | 16 | --- a/accel/tcg/translator.c |
18 | +++ b/accel/tcg/cpu-exec.c | 17 | +++ b/accel/tcg/translator.c |
19 | @@ -XXX,XX +XXX,XX @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb, | 18 | @@ -XXX,XX +XXX,XX @@ static void *translator_access(CPUArchState *env, DisasContextBase *db, |
20 | 19 | if (host == NULL) { | |
21 | /* main execution loop */ | 20 | tb_page_addr_t phys_page = |
22 | 21 | get_page_addr_code_hostp(env, base, &db->host_addr[1]); | |
23 | -int cpu_exec(CPUState *cpu) | 22 | - /* We cannot handle MMIO as second page. */ |
24 | +static int __attribute__((noinline)) | 23 | - assert(phys_page != -1); |
25 | +cpu_exec_loop(CPUState *cpu, SyncClocks *sc) | ||
26 | { | ||
27 | int ret; | ||
28 | - SyncClocks sc = { 0 }; | ||
29 | - | ||
30 | - /* replay_interrupt may need current_cpu */ | ||
31 | - current_cpu = cpu; | ||
32 | - | ||
33 | - if (cpu_handle_halt(cpu)) { | ||
34 | - return EXCP_HALTED; | ||
35 | - } | ||
36 | - | ||
37 | - rcu_read_lock(); | ||
38 | - | ||
39 | - cpu_exec_enter(cpu); | ||
40 | - | ||
41 | - /* Calculate difference between guest clock and host clock. | ||
42 | - * This delay includes the delay of the last cycle, so | ||
43 | - * what we have to do is sleep until it is 0. As for the | ||
44 | - * advance/delay we gain here, we try to fix it next time. | ||
45 | - */ | ||
46 | - init_delay_params(&sc, cpu); | ||
47 | - | ||
48 | - /* prepare setjmp context for exception handling */ | ||
49 | - if (sigsetjmp(cpu->jmp_env, 0) != 0) { | ||
50 | -#if defined(__clang__) | ||
51 | - /* | ||
52 | - * Some compilers wrongly smash all local variables after | ||
53 | - * siglongjmp (the spec requires that only non-volatile locals | ||
54 | - * which are changed between the sigsetjmp and siglongjmp are | ||
55 | - * permitted to be trashed). There were bug reports for gcc | ||
56 | - * 4.5.0 and clang. The bug is fixed in all versions of gcc | ||
57 | - * that we support, but is still unfixed in clang: | ||
58 | - * https://bugs.llvm.org/show_bug.cgi?id=21183 | ||
59 | - * | ||
60 | - * Reload an essential local variable here for those compilers. | ||
61 | - * Newer versions of gcc would complain about this code (-Wclobbered), | ||
62 | - * so we only perform the workaround for clang. | ||
63 | - */ | ||
64 | - cpu = current_cpu; | ||
65 | -#else | ||
66 | - /* Non-buggy compilers preserve this; assert the correct value. */ | ||
67 | - g_assert(cpu == current_cpu); | ||
68 | -#endif | ||
69 | - | ||
70 | -#ifndef CONFIG_SOFTMMU | ||
71 | - clear_helper_retaddr(); | ||
72 | - if (have_mmap_lock()) { | ||
73 | - mmap_unlock(); | ||
74 | - } | ||
75 | -#endif | ||
76 | - if (qemu_mutex_iothread_locked()) { | ||
77 | - qemu_mutex_unlock_iothread(); | ||
78 | - } | ||
79 | - qemu_plugin_disable_mem_helpers(cpu); | ||
80 | - | ||
81 | - assert_no_pages_locked(); | ||
82 | - } | ||
83 | |||
84 | /* if an exception is pending, we execute it here */ | ||
85 | while (!cpu_handle_exception(cpu, &ret)) { | ||
86 | @@ -XXX,XX +XXX,XX @@ int cpu_exec(CPUState *cpu) | ||
87 | |||
88 | /* Try to align the host and virtual clocks | ||
89 | if the guest is in advance */ | ||
90 | - align_clocks(&sc, cpu); | ||
91 | + align_clocks(sc, cpu); | ||
92 | } | ||
93 | } | ||
94 | + return ret; | ||
95 | +} | ||
96 | + | 24 | + |
97 | +static int cpu_exec_setjmp(CPUState *cpu, SyncClocks *sc) | 25 | + /* |
98 | +{ | 26 | + * If the second page is MMIO, treat as if the first page |
99 | + /* Prepare setjmp context for exception handling. */ | 27 | + * was MMIO as well, so that we do not cache the TB. |
100 | + if (unlikely(sigsetjmp(cpu->jmp_env, 0) != 0)) { | 28 | + */ |
101 | + /* Non-buggy compilers preserve this; assert the correct value. */ | 29 | + if (unlikely(phys_page == -1)) { |
102 | + g_assert(cpu == current_cpu); | 30 | + tb_set_page_addr0(tb, -1); |
31 | + return NULL; | ||
32 | + } | ||
103 | + | 33 | + |
104 | +#ifndef CONFIG_SOFTMMU | 34 | tb_set_page_addr1(tb, phys_page); |
105 | + clear_helper_retaddr(); | 35 | #ifdef CONFIG_USER_ONLY |
106 | + if (have_mmap_lock()) { | 36 | page_protect(end); |
107 | + mmap_unlock(); | ||
108 | + } | ||
109 | +#endif | ||
110 | + if (qemu_mutex_iothread_locked()) { | ||
111 | + qemu_mutex_unlock_iothread(); | ||
112 | + } | ||
113 | + qemu_plugin_disable_mem_helpers(cpu); | ||
114 | + | ||
115 | + assert_no_pages_locked(); | ||
116 | + } | ||
117 | + | ||
118 | + return cpu_exec_loop(cpu, sc); | ||
119 | +} | ||
120 | + | ||
121 | +int cpu_exec(CPUState *cpu) | ||
122 | +{ | ||
123 | + int ret; | ||
124 | + SyncClocks sc = { 0 }; | ||
125 | + | ||
126 | + /* replay_interrupt may need current_cpu */ | ||
127 | + current_cpu = cpu; | ||
128 | + | ||
129 | + if (cpu_handle_halt(cpu)) { | ||
130 | + return EXCP_HALTED; | ||
131 | + } | ||
132 | + | ||
133 | + rcu_read_lock(); | ||
134 | + cpu_exec_enter(cpu); | ||
135 | + | ||
136 | + /* | ||
137 | + * Calculate difference between guest clock and host clock. | ||
138 | + * This delay includes the delay of the last cycle, so | ||
139 | + * what we have to do is sleep until it is 0. As for the | ||
140 | + * advance/delay we gain here, we try to fix it next time. | ||
141 | + */ | ||
142 | + init_delay_params(&sc, cpu); | ||
143 | + | ||
144 | + ret = cpu_exec_setjmp(cpu, &sc); | ||
145 | |||
146 | cpu_exec_exit(cpu); | ||
147 | rcu_read_unlock(); | ||
148 | -- | 37 | -- |
149 | 2.34.1 | 38 | 2.34.1 |
150 | 39 | ||
151 | 40 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | The linux kernel's trap tables vector all unassigned trap | ||
2 | numbers to BAD_TRAP, which then raises SIGILL. | ||
1 | 3 | ||
4 | Tested-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
5 | Reported-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | --- | ||
8 | linux-user/sparc/cpu_loop.c | 8 ++++++++ | ||
9 | 1 file changed, 8 insertions(+) | ||
10 | |||
11 | diff --git a/linux-user/sparc/cpu_loop.c b/linux-user/sparc/cpu_loop.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/linux-user/sparc/cpu_loop.c | ||
14 | +++ b/linux-user/sparc/cpu_loop.c | ||
15 | @@ -XXX,XX +XXX,XX @@ void cpu_loop (CPUSPARCState *env) | ||
16 | cpu_exec_step_atomic(cs); | ||
17 | break; | ||
18 | default: | ||
19 | + /* | ||
20 | + * Most software trap numbers vector to BAD_TRAP. | ||
21 | + * Handle anything not explicitly matched above. | ||
22 | + */ | ||
23 | + if (trapnr >= TT_TRAP && trapnr <= TT_TRAP + 0x7f) { | ||
24 | + force_sig_fault(TARGET_SIGILL, ILL_ILLTRP, env->pc); | ||
25 | + break; | ||
26 | + } | ||
27 | fprintf(stderr, "Unhandled trap: 0x%x\n", trapnr); | ||
28 | cpu_dump_state(cs, stderr, 0); | ||
29 | exit(EXIT_FAILURE); | ||
30 | -- | ||
31 | 2.34.1 | diff view generated by jsdifflib |
1 | From: Ilya Leoshkevich <iii@linux.ibm.com> | 1 | From: Ilya Leoshkevich <iii@linux.ibm.com> |
---|---|---|---|
2 | 2 | ||
3 | When exiting due to an exit() syscall, qemu-user calls | 3 | fork()ed processes currently start with |
4 | preexit_cleanup(), but this is currently not the case when exiting due | 4 | current_cpu->in_exclusive_context set, which is, strictly speaking, not |
5 | to a signal. This leads to various buffers not being flushed (e.g., | 5 | correct, but does not cause problems (even assertion failures). |
6 | for gprof, for gcov, and for the upcoming perf support). | ||
7 | 6 | ||
8 | Add the missing call. | 7 | With one of the next patches, the code begins to rely on this value, so |
8 | fix it by always calling end_exclusive() in fork_end(). | ||
9 | 9 | ||
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
10 | Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> | 12 | Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> |
11 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 13 | Message-Id: <20230214140829.45392-2-iii@linux.ibm.com> |
12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
13 | Message-Id: <20230112152013.125680-2-iii@linux.ibm.com> | ||
14 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 14 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
15 | --- | 15 | --- |
16 | linux-user/signal.c | 8 +++++--- | 16 | linux-user/main.c | 10 ++++++---- |
17 | 1 file changed, 5 insertions(+), 3 deletions(-) | 17 | linux-user/syscall.c | 1 + |
18 | 2 files changed, 7 insertions(+), 4 deletions(-) | ||
18 | 19 | ||
19 | diff --git a/linux-user/signal.c b/linux-user/signal.c | 20 | diff --git a/linux-user/main.c b/linux-user/main.c |
20 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/linux-user/signal.c | 22 | --- a/linux-user/main.c |
22 | +++ b/linux-user/signal.c | 23 | +++ b/linux-user/main.c |
23 | @@ -XXX,XX +XXX,XX @@ void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr, | 24 | @@ -XXX,XX +XXX,XX @@ void fork_end(int child) |
24 | 25 | } | |
25 | /* abort execution with signal */ | 26 | qemu_init_cpu_list(); |
26 | static G_NORETURN | 27 | gdbserver_fork(thread_cpu); |
27 | -void dump_core_and_abort(int target_sig) | 28 | - /* qemu_init_cpu_list() takes care of reinitializing the |
28 | +void dump_core_and_abort(CPUArchState *cpu_env, int target_sig) | 29 | - * exclusive state, so we don't need to end_exclusive() here. |
29 | { | 30 | - */ |
30 | CPUState *cpu = thread_cpu; | 31 | } else { |
31 | CPUArchState *env = cpu->env_ptr; | 32 | cpu_list_unlock(); |
32 | @@ -XXX,XX +XXX,XX @@ void dump_core_and_abort(int target_sig) | 33 | - end_exclusive(); |
33 | target_sig, strsignal(host_sig), "core dumped" ); | ||
34 | } | 34 | } |
35 | 35 | + /* | |
36 | + preexit_cleanup(cpu_env, 128 + target_sig); | 36 | + * qemu_init_cpu_list() reinitialized the child exclusive state, but we |
37 | + | 37 | + * also need to keep current_cpu consistent, so call end_exclusive() for |
38 | /* The proper exit code for dying from an uncaught signal is | 38 | + * both child and parent. |
39 | * -<signal>. The kernel doesn't allow exit() or _exit() to pass | 39 | + */ |
40 | * a negative value. To get the proper exit code we need to | 40 | + end_exclusive(); |
41 | @@ -XXX,XX +XXX,XX @@ static void handle_pending_signal(CPUArchState *cpu_env, int sig, | 41 | } |
42 | sig != TARGET_SIGURG && | 42 | |
43 | sig != TARGET_SIGWINCH && | 43 | __thread CPUState *thread_cpu; |
44 | sig != TARGET_SIGCONT) { | 44 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c |
45 | - dump_core_and_abort(sig); | 45 | index XXXXXXX..XXXXXXX 100644 |
46 | + dump_core_and_abort(cpu_env, sig); | 46 | --- a/linux-user/syscall.c |
47 | +++ b/linux-user/syscall.c | ||
48 | @@ -XXX,XX +XXX,XX @@ static int do_fork(CPUArchState *env, unsigned int flags, abi_ulong newsp, | ||
49 | cpu_clone_regs_parent(env, flags); | ||
50 | fork_end(0); | ||
47 | } | 51 | } |
48 | } else if (handler == TARGET_SIG_IGN) { | 52 | + g_assert(!cpu_in_exclusive_context(cpu)); |
49 | /* ignore sig */ | 53 | } |
50 | } else if (handler == TARGET_SIG_ERR) { | 54 | return ret; |
51 | - dump_core_and_abort(sig); | 55 | } |
52 | + dump_core_and_abort(cpu_env, sig); | ||
53 | } else { | ||
54 | /* compute the blocked signals during the handler execution */ | ||
55 | sigset_t *blocked_set; | ||
56 | -- | 56 | -- |
57 | 2.34.1 | 57 | 2.34.1 |
58 | 58 | ||
59 | 59 | diff view generated by jsdifflib |
1 | From: Ilya Leoshkevich <iii@linux.ibm.com> | 1 | From: Ilya Leoshkevich <iii@linux.ibm.com> |
---|---|---|---|
2 | 2 | ||
3 | Add ability to dump /tmp/perf-<pid>.map and jit-<pid>.dump. | 3 | Currently dying to one of the core_dump_signal()s deadlocks, because |
4 | The first one allows the perf tool to map samples to each individual | 4 | dump_core_and_abort() calls start_exclusive() two times: first via |
5 | translation block. The second one adds the ability to resolve symbol | 5 | stop_all_tasks(), and then via preexit_cleanup() -> |
6 | names, line numbers and inspect JITed code. | 6 | qemu_plugin_user_exit(). |
7 | 7 | ||
8 | Example of use: | 8 | There are a number of ways to solve this: resume after dumping core; |
9 | check cpu_in_exclusive_context() in qemu_plugin_user_exit(); or make | ||
10 | {start,end}_exclusive() recursive. Pick the last option, since it's | ||
11 | the most straightforward one. | ||
9 | 12 | ||
10 | perf record qemu-x86_64 -perfmap ./a.out | 13 | Fixes: da91c1920242 ("linux-user: Clean up when exiting due to a signal") |
11 | perf report | 14 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
12 | 15 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | |
13 | or | ||
14 | |||
15 | perf record -k 1 qemu-x86_64 -jitdump ./a.out | ||
16 | DEBUGINFOD_URLS= perf inject -j -i perf.data -o perf.data.jitted | ||
17 | perf report -i perf.data.jitted | ||
18 | |||
19 | Co-developed-by: Vanderson M. do Rosario <vandersonmr2@gmail.com> | ||
20 | Co-developed-by: Alex Bennée <alex.bennee@linaro.org> | ||
21 | Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> | 16 | Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> |
22 | Message-Id: <20230112152013.125680-4-iii@linux.ibm.com> | 17 | Message-Id: <20230214140829.45392-3-iii@linux.ibm.com> |
23 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 18 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
24 | --- | 19 | --- |
25 | docs/devel/tcg.rst | 23 +++ | 20 | include/hw/core/cpu.h | 4 ++-- |
26 | accel/tcg/perf.h | 49 +++++ | 21 | cpus-common.c | 12 ++++++++++-- |
27 | accel/tcg/perf.c | 375 ++++++++++++++++++++++++++++++++++++++ | 22 | 2 files changed, 12 insertions(+), 4 deletions(-) |
28 | accel/tcg/translate-all.c | 7 + | ||
29 | linux-user/exit.c | 2 + | ||
30 | linux-user/main.c | 15 ++ | ||
31 | softmmu/vl.c | 11 ++ | ||
32 | tcg/tcg.c | 2 + | ||
33 | accel/tcg/meson.build | 1 + | ||
34 | qemu-options.hx | 20 ++ | ||
35 | 10 files changed, 505 insertions(+) | ||
36 | create mode 100644 accel/tcg/perf.h | ||
37 | create mode 100644 accel/tcg/perf.c | ||
38 | 23 | ||
39 | diff --git a/docs/devel/tcg.rst b/docs/devel/tcg.rst | 24 | diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h |
40 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
41 | --- a/docs/devel/tcg.rst | 26 | --- a/include/hw/core/cpu.h |
42 | +++ b/docs/devel/tcg.rst | 27 | +++ b/include/hw/core/cpu.h |
43 | @@ -XXX,XX +XXX,XX @@ memory areas instead calls out to C code for device emulation. | 28 | @@ -XXX,XX +XXX,XX @@ struct CPUState { |
44 | Finally, the MMU helps tracking dirty pages and pages pointed to by | 29 | bool unplug; |
45 | translation blocks. | 30 | bool crash_occurred; |
46 | 31 | bool exit_request; | |
47 | +Profiling JITted code | 32 | - bool in_exclusive_context; |
48 | +--------------------- | 33 | + int exclusive_context_count; |
49 | + | 34 | uint32_t cflags_next_tb; |
50 | +The Linux ``perf`` tool will treat all JITted code as a single block as | 35 | /* updates protected by BQL */ |
51 | +unlike the main code it can't use debug information to link individual | 36 | uint32_t interrupt_request; |
52 | +program counter samples with larger functions. To overcome this | 37 | @@ -XXX,XX +XXX,XX @@ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data |
53 | +limitation you can use the ``-perfmap`` or the ``-jitdump`` option to generate | 38 | */ |
54 | +map files. ``-perfmap`` is lightweight and produces only guest-host mappings. | 39 | static inline bool cpu_in_exclusive_context(const CPUState *cpu) |
55 | +``-jitdump`` additionally saves JITed code and guest debug information (if | 40 | { |
56 | +available); its output needs to be integrated with the ``perf.data`` file | 41 | - return cpu->in_exclusive_context; |
57 | +before the final report can be viewed. | 42 | + return cpu->exclusive_context_count; |
58 | + | 43 | } |
59 | +.. code:: | 44 | |
60 | + | 45 | /** |
61 | + perf record $QEMU -perfmap $REMAINING_ARGS | 46 | diff --git a/cpus-common.c b/cpus-common.c |
62 | + perf report | 47 | index XXXXXXX..XXXXXXX 100644 |
63 | + | 48 | --- a/cpus-common.c |
64 | + perf record -k 1 $QEMU -jitdump $REMAINING_ARGS | 49 | +++ b/cpus-common.c |
65 | + DEBUGINFOD_URLS= perf inject -j -i perf.data -o perf.data.jitted | 50 | @@ -XXX,XX +XXX,XX @@ void start_exclusive(void) |
66 | + perf report -i perf.data.jitted | 51 | CPUState *other_cpu; |
67 | + | 52 | int running_cpus; |
68 | +Note that qemu-system generates mappings only for ``-kernel`` files in ELF | 53 | |
69 | +format. | 54 | + if (current_cpu->exclusive_context_count) { |
70 | diff --git a/accel/tcg/perf.h b/accel/tcg/perf.h | 55 | + current_cpu->exclusive_context_count++; |
71 | new file mode 100644 | ||
72 | index XXXXXXX..XXXXXXX | ||
73 | --- /dev/null | ||
74 | +++ b/accel/tcg/perf.h | ||
75 | @@ -XXX,XX +XXX,XX @@ | ||
76 | +/* | ||
77 | + * Linux perf perf-<pid>.map and jit-<pid>.dump integration. | ||
78 | + * | ||
79 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
80 | + */ | ||
81 | + | ||
82 | +#ifndef ACCEL_TCG_PERF_H | ||
83 | +#define ACCEL_TCG_PERF_H | ||
84 | + | ||
85 | +#if defined(CONFIG_TCG) && defined(CONFIG_LINUX) | ||
86 | +/* Start writing perf-<pid>.map. */ | ||
87 | +void perf_enable_perfmap(void); | ||
88 | + | ||
89 | +/* Start writing jit-<pid>.dump. */ | ||
90 | +void perf_enable_jitdump(void); | ||
91 | + | ||
92 | +/* Add information about TCG prologue to profiler maps. */ | ||
93 | +void perf_report_prologue(const void *start, size_t size); | ||
94 | + | ||
95 | +/* Add information about JITted guest code to profiler maps. */ | ||
96 | +void perf_report_code(uint64_t guest_pc, TranslationBlock *tb, | ||
97 | + const void *start); | ||
98 | + | ||
99 | +/* Stop writing perf-<pid>.map and/or jit-<pid>.dump. */ | ||
100 | +void perf_exit(void); | ||
101 | +#else | ||
102 | +static inline void perf_enable_perfmap(void) | ||
103 | +{ | ||
104 | +} | ||
105 | + | ||
106 | +static inline void perf_enable_jitdump(void) | ||
107 | +{ | ||
108 | +} | ||
109 | + | ||
110 | +static inline void perf_report_prologue(const void *start, size_t size) | ||
111 | +{ | ||
112 | +} | ||
113 | + | ||
114 | +static inline void perf_report_code(uint64_t guest_pc, TranslationBlock *tb, | ||
115 | + const void *start) | ||
116 | +{ | ||
117 | +} | ||
118 | + | ||
119 | +static inline void perf_exit(void) | ||
120 | +{ | ||
121 | +} | ||
122 | +#endif | ||
123 | + | ||
124 | +#endif | ||
125 | diff --git a/accel/tcg/perf.c b/accel/tcg/perf.c | ||
126 | new file mode 100644 | ||
127 | index XXXXXXX..XXXXXXX | ||
128 | --- /dev/null | ||
129 | +++ b/accel/tcg/perf.c | ||
130 | @@ -XXX,XX +XXX,XX @@ | ||
131 | +/* | ||
132 | + * Linux perf perf-<pid>.map and jit-<pid>.dump integration. | ||
133 | + * | ||
134 | + * The jitdump spec can be found at [1]. | ||
135 | + * | ||
136 | + * [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/tools/perf/Documentation/jitdump-specification.txt | ||
137 | + * | ||
138 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
139 | + */ | ||
140 | + | ||
141 | +#include "qemu/osdep.h" | ||
142 | +#include "elf.h" | ||
143 | +#include "exec/exec-all.h" | ||
144 | +#include "qemu/timer.h" | ||
145 | +#include "tcg/tcg.h" | ||
146 | + | ||
147 | +#include "debuginfo.h" | ||
148 | +#include "perf.h" | ||
149 | + | ||
150 | +static FILE *safe_fopen_w(const char *path) | ||
151 | +{ | ||
152 | + int saved_errno; | ||
153 | + FILE *f; | ||
154 | + int fd; | ||
155 | + | ||
156 | + /* Delete the old file, if any. */ | ||
157 | + unlink(path); | ||
158 | + | ||
159 | + /* Avoid symlink attacks by using O_CREAT | O_EXCL. */ | ||
160 | + fd = open(path, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); | ||
161 | + if (fd == -1) { | ||
162 | + return NULL; | ||
163 | + } | ||
164 | + | ||
165 | + /* Convert fd to FILE*. */ | ||
166 | + f = fdopen(fd, "w"); | ||
167 | + if (f == NULL) { | ||
168 | + saved_errno = errno; | ||
169 | + close(fd); | ||
170 | + errno = saved_errno; | ||
171 | + return NULL; | ||
172 | + } | ||
173 | + | ||
174 | + return f; | ||
175 | +} | ||
176 | + | ||
177 | +static FILE *perfmap; | ||
178 | + | ||
179 | +void perf_enable_perfmap(void) | ||
180 | +{ | ||
181 | + char map_file[32]; | ||
182 | + | ||
183 | + snprintf(map_file, sizeof(map_file), "/tmp/perf-%d.map", getpid()); | ||
184 | + perfmap = safe_fopen_w(map_file); | ||
185 | + if (perfmap == NULL) { | ||
186 | + warn_report("Could not open %s: %s, proceeding without perfmap", | ||
187 | + map_file, strerror(errno)); | ||
188 | + } | ||
189 | +} | ||
190 | + | ||
191 | +/* Get PC and size of code JITed for guest instruction #INSN. */ | ||
192 | +static void get_host_pc_size(uintptr_t *host_pc, uint16_t *host_size, | ||
193 | + const void *start, size_t insn) | ||
194 | +{ | ||
195 | + uint16_t start_off = insn ? tcg_ctx->gen_insn_end_off[insn - 1] : 0; | ||
196 | + | ||
197 | + if (host_pc) { | ||
198 | + *host_pc = (uintptr_t)start + start_off; | ||
199 | + } | ||
200 | + if (host_size) { | ||
201 | + *host_size = tcg_ctx->gen_insn_end_off[insn] - start_off; | ||
202 | + } | ||
203 | +} | ||
204 | + | ||
205 | +static const char *pretty_symbol(const struct debuginfo_query *q, size_t *len) | ||
206 | +{ | ||
207 | + static __thread char buf[64]; | ||
208 | + int tmp; | ||
209 | + | ||
210 | + if (!q->symbol) { | ||
211 | + tmp = snprintf(buf, sizeof(buf), "guest-0x%"PRIx64, q->address); | ||
212 | + if (len) { | ||
213 | + *len = MIN(tmp + 1, sizeof(buf)); | ||
214 | + } | ||
215 | + return buf; | ||
216 | + } | ||
217 | + | ||
218 | + if (!q->offset) { | ||
219 | + if (len) { | ||
220 | + *len = strlen(q->symbol) + 1; | ||
221 | + } | ||
222 | + return q->symbol; | ||
223 | + } | ||
224 | + | ||
225 | + tmp = snprintf(buf, sizeof(buf), "%s+0x%"PRIx64, q->symbol, q->offset); | ||
226 | + if (len) { | ||
227 | + *len = MIN(tmp + 1, sizeof(buf)); | ||
228 | + } | ||
229 | + return buf; | ||
230 | +} | ||
231 | + | ||
232 | +static void write_perfmap_entry(const void *start, size_t insn, | ||
233 | + const struct debuginfo_query *q) | ||
234 | +{ | ||
235 | + uint16_t host_size; | ||
236 | + uintptr_t host_pc; | ||
237 | + | ||
238 | + get_host_pc_size(&host_pc, &host_size, start, insn); | ||
239 | + fprintf(perfmap, "%"PRIxPTR" %"PRIx16" %s\n", | ||
240 | + host_pc, host_size, pretty_symbol(q, NULL)); | ||
241 | +} | ||
242 | + | ||
243 | +static FILE *jitdump; | ||
244 | + | ||
245 | +#define JITHEADER_MAGIC 0x4A695444 | ||
246 | +#define JITHEADER_VERSION 1 | ||
247 | + | ||
248 | +struct jitheader { | ||
249 | + uint32_t magic; | ||
250 | + uint32_t version; | ||
251 | + uint32_t total_size; | ||
252 | + uint32_t elf_mach; | ||
253 | + uint32_t pad1; | ||
254 | + uint32_t pid; | ||
255 | + uint64_t timestamp; | ||
256 | + uint64_t flags; | ||
257 | +}; | ||
258 | + | ||
259 | +enum jit_record_type { | ||
260 | + JIT_CODE_LOAD = 0, | ||
261 | + JIT_CODE_DEBUG_INFO = 2, | ||
262 | +}; | ||
263 | + | ||
264 | +struct jr_prefix { | ||
265 | + uint32_t id; | ||
266 | + uint32_t total_size; | ||
267 | + uint64_t timestamp; | ||
268 | +}; | ||
269 | + | ||
270 | +struct jr_code_load { | ||
271 | + struct jr_prefix p; | ||
272 | + | ||
273 | + uint32_t pid; | ||
274 | + uint32_t tid; | ||
275 | + uint64_t vma; | ||
276 | + uint64_t code_addr; | ||
277 | + uint64_t code_size; | ||
278 | + uint64_t code_index; | ||
279 | +}; | ||
280 | + | ||
281 | +struct debug_entry { | ||
282 | + uint64_t addr; | ||
283 | + int lineno; | ||
284 | + int discrim; | ||
285 | + const char name[]; | ||
286 | +}; | ||
287 | + | ||
288 | +struct jr_code_debug_info { | ||
289 | + struct jr_prefix p; | ||
290 | + | ||
291 | + uint64_t code_addr; | ||
292 | + uint64_t nr_entry; | ||
293 | + struct debug_entry entries[]; | ||
294 | +}; | ||
295 | + | ||
296 | +static uint32_t get_e_machine(void) | ||
297 | +{ | ||
298 | + Elf64_Ehdr elf_header; | ||
299 | + FILE *exe; | ||
300 | + size_t n; | ||
301 | + | ||
302 | + QEMU_BUILD_BUG_ON(offsetof(Elf32_Ehdr, e_machine) != | ||
303 | + offsetof(Elf64_Ehdr, e_machine)); | ||
304 | + | ||
305 | + exe = fopen("/proc/self/exe", "r"); | ||
306 | + if (exe == NULL) { | ||
307 | + return EM_NONE; | ||
308 | + } | ||
309 | + | ||
310 | + n = fread(&elf_header, sizeof(elf_header), 1, exe); | ||
311 | + fclose(exe); | ||
312 | + if (n != 1) { | ||
313 | + return EM_NONE; | ||
314 | + } | ||
315 | + | ||
316 | + return elf_header.e_machine; | ||
317 | +} | ||
318 | + | ||
319 | +void perf_enable_jitdump(void) | ||
320 | +{ | ||
321 | + struct jitheader header; | ||
322 | + char jitdump_file[32]; | ||
323 | + void *perf_marker; | ||
324 | + | ||
325 | + if (!use_rt_clock) { | ||
326 | + warn_report("CLOCK_MONOTONIC is not available, proceeding without jitdump"); | ||
327 | + return; | 56 | + return; |
328 | + } | 57 | + } |
329 | + | 58 | + |
330 | + snprintf(jitdump_file, sizeof(jitdump_file), "jit-%d.dump", getpid()); | 59 | qemu_mutex_lock(&qemu_cpu_list_lock); |
331 | + jitdump = safe_fopen_w(jitdump_file); | 60 | exclusive_idle(); |
332 | + if (jitdump == NULL) { | 61 | |
333 | + warn_report("Could not open %s: %s, proceeding without jitdump", | 62 | @@ -XXX,XX +XXX,XX @@ void start_exclusive(void) |
334 | + jitdump_file, strerror(errno)); | 63 | */ |
64 | qemu_mutex_unlock(&qemu_cpu_list_lock); | ||
65 | |||
66 | - current_cpu->in_exclusive_context = true; | ||
67 | + current_cpu->exclusive_context_count = 1; | ||
68 | } | ||
69 | |||
70 | /* Finish an exclusive operation. */ | ||
71 | void end_exclusive(void) | ||
72 | { | ||
73 | - current_cpu->in_exclusive_context = false; | ||
74 | + current_cpu->exclusive_context_count--; | ||
75 | + if (current_cpu->exclusive_context_count) { | ||
335 | + return; | 76 | + return; |
336 | + } | 77 | + } |
337 | + | 78 | |
338 | + /* | 79 | qemu_mutex_lock(&qemu_cpu_list_lock); |
339 | + * `perf inject` will see that the mapped file name in the corresponding | 80 | qatomic_set(&pending_cpus, 0); |
340 | + * PERF_RECORD_MMAP or PERF_RECORD_MMAP2 event is of the form jit-%d.dump | ||
341 | + * and will process it as a jitdump file. | ||
342 | + */ | ||
343 | + perf_marker = mmap(NULL, qemu_real_host_page_size(), PROT_READ | PROT_EXEC, | ||
344 | + MAP_PRIVATE, fileno(jitdump), 0); | ||
345 | + if (perf_marker == MAP_FAILED) { | ||
346 | + warn_report("Could not map %s: %s, proceeding without jitdump", | ||
347 | + jitdump_file, strerror(errno)); | ||
348 | + fclose(jitdump); | ||
349 | + jitdump = NULL; | ||
350 | + return; | ||
351 | + } | ||
352 | + | ||
353 | + header.magic = JITHEADER_MAGIC; | ||
354 | + header.version = JITHEADER_VERSION; | ||
355 | + header.total_size = sizeof(header); | ||
356 | + header.elf_mach = get_e_machine(); | ||
357 | + header.pad1 = 0; | ||
358 | + header.pid = getpid(); | ||
359 | + header.timestamp = get_clock(); | ||
360 | + header.flags = 0; | ||
361 | + fwrite(&header, sizeof(header), 1, jitdump); | ||
362 | +} | ||
363 | + | ||
364 | +void perf_report_prologue(const void *start, size_t size) | ||
365 | +{ | ||
366 | + if (perfmap) { | ||
367 | + fprintf(perfmap, "%"PRIxPTR" %zx tcg-prologue-buffer\n", | ||
368 | + (uintptr_t)start, size); | ||
369 | + } | ||
370 | +} | ||
371 | + | ||
372 | +/* Write a JIT_CODE_DEBUG_INFO jitdump entry. */ | ||
373 | +static void write_jr_code_debug_info(const void *start, | ||
374 | + const struct debuginfo_query *q, | ||
375 | + size_t icount) | ||
376 | +{ | ||
377 | + struct jr_code_debug_info rec; | ||
378 | + struct debug_entry ent; | ||
379 | + uintptr_t host_pc; | ||
380 | + int insn; | ||
381 | + | ||
382 | + /* Write the header. */ | ||
383 | + rec.p.id = JIT_CODE_DEBUG_INFO; | ||
384 | + rec.p.total_size = sizeof(rec) + sizeof(ent) + 1; | ||
385 | + rec.p.timestamp = get_clock(); | ||
386 | + rec.code_addr = (uintptr_t)start; | ||
387 | + rec.nr_entry = 1; | ||
388 | + for (insn = 0; insn < icount; insn++) { | ||
389 | + if (q[insn].file) { | ||
390 | + rec.p.total_size += sizeof(ent) + strlen(q[insn].file) + 1; | ||
391 | + rec.nr_entry++; | ||
392 | + } | ||
393 | + } | ||
394 | + fwrite(&rec, sizeof(rec), 1, jitdump); | ||
395 | + | ||
396 | + /* Write the main debug entries. */ | ||
397 | + for (insn = 0; insn < icount; insn++) { | ||
398 | + if (q[insn].file) { | ||
399 | + get_host_pc_size(&host_pc, NULL, start, insn); | ||
400 | + ent.addr = host_pc; | ||
401 | + ent.lineno = q[insn].line; | ||
402 | + ent.discrim = 0; | ||
403 | + fwrite(&ent, sizeof(ent), 1, jitdump); | ||
404 | + fwrite(q[insn].file, strlen(q[insn].file) + 1, 1, jitdump); | ||
405 | + } | ||
406 | + } | ||
407 | + | ||
408 | + /* Write the trailing debug_entry. */ | ||
409 | + ent.addr = (uintptr_t)start + tcg_ctx->gen_insn_end_off[icount - 1]; | ||
410 | + ent.lineno = 0; | ||
411 | + ent.discrim = 0; | ||
412 | + fwrite(&ent, sizeof(ent), 1, jitdump); | ||
413 | + fwrite("", 1, 1, jitdump); | ||
414 | +} | ||
415 | + | ||
416 | +/* Write a JIT_CODE_LOAD jitdump entry. */ | ||
417 | +static void write_jr_code_load(const void *start, uint16_t host_size, | ||
418 | + const struct debuginfo_query *q) | ||
419 | +{ | ||
420 | + static uint64_t code_index; | ||
421 | + struct jr_code_load rec; | ||
422 | + const char *symbol; | ||
423 | + size_t symbol_size; | ||
424 | + | ||
425 | + symbol = pretty_symbol(q, &symbol_size); | ||
426 | + rec.p.id = JIT_CODE_LOAD; | ||
427 | + rec.p.total_size = sizeof(rec) + symbol_size + host_size; | ||
428 | + rec.p.timestamp = get_clock(); | ||
429 | + rec.pid = getpid(); | ||
430 | + rec.tid = qemu_get_thread_id(); | ||
431 | + rec.vma = (uintptr_t)start; | ||
432 | + rec.code_addr = (uintptr_t)start; | ||
433 | + rec.code_size = host_size; | ||
434 | + rec.code_index = code_index++; | ||
435 | + fwrite(&rec, sizeof(rec), 1, jitdump); | ||
436 | + fwrite(symbol, symbol_size, 1, jitdump); | ||
437 | + fwrite(start, host_size, 1, jitdump); | ||
438 | +} | ||
439 | + | ||
440 | +void perf_report_code(uint64_t guest_pc, TranslationBlock *tb, | ||
441 | + const void *start) | ||
442 | +{ | ||
443 | + struct debuginfo_query *q; | ||
444 | + size_t insn; | ||
445 | + | ||
446 | + if (!perfmap && !jitdump) { | ||
447 | + return; | ||
448 | + } | ||
449 | + | ||
450 | + q = g_try_malloc0_n(tb->icount, sizeof(*q)); | ||
451 | + if (!q) { | ||
452 | + return; | ||
453 | + } | ||
454 | + | ||
455 | + debuginfo_lock(); | ||
456 | + | ||
457 | + /* Query debuginfo for each guest instruction. */ | ||
458 | + for (insn = 0; insn < tb->icount; insn++) { | ||
459 | + /* FIXME: This replicates the restore_state_to_opc() logic. */ | ||
460 | + q[insn].address = tcg_ctx->gen_insn_data[insn][0]; | ||
461 | + if (TARGET_TB_PCREL) { | ||
462 | + q[insn].address |= (guest_pc & TARGET_PAGE_MASK); | ||
463 | + } else { | ||
464 | +#if defined(TARGET_I386) | ||
465 | + q[insn].address -= tb->cs_base; | ||
466 | +#endif | ||
467 | + } | ||
468 | + q[insn].flags = DEBUGINFO_SYMBOL | (jitdump ? DEBUGINFO_LINE : 0); | ||
469 | + } | ||
470 | + debuginfo_query(q, tb->icount); | ||
471 | + | ||
472 | + /* Emit perfmap entries if needed. */ | ||
473 | + if (perfmap) { | ||
474 | + flockfile(perfmap); | ||
475 | + for (insn = 0; insn < tb->icount; insn++) { | ||
476 | + write_perfmap_entry(start, insn, &q[insn]); | ||
477 | + } | ||
478 | + funlockfile(perfmap); | ||
479 | + } | ||
480 | + | ||
481 | + /* Emit jitdump entries if needed. */ | ||
482 | + if (jitdump) { | ||
483 | + flockfile(jitdump); | ||
484 | + write_jr_code_debug_info(start, q, tb->icount); | ||
485 | + write_jr_code_load(start, tcg_ctx->gen_insn_end_off[tb->icount - 1], | ||
486 | + q); | ||
487 | + funlockfile(jitdump); | ||
488 | + } | ||
489 | + | ||
490 | + debuginfo_unlock(); | ||
491 | + g_free(q); | ||
492 | +} | ||
493 | + | ||
494 | +void perf_exit(void) | ||
495 | +{ | ||
496 | + if (perfmap) { | ||
497 | + fclose(perfmap); | ||
498 | + perfmap = NULL; | ||
499 | + } | ||
500 | + | ||
501 | + if (jitdump) { | ||
502 | + fclose(jitdump); | ||
503 | + jitdump = NULL; | ||
504 | + } | ||
505 | +} | ||
506 | diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c | ||
507 | index XXXXXXX..XXXXXXX 100644 | ||
508 | --- a/accel/tcg/translate-all.c | ||
509 | +++ b/accel/tcg/translate-all.c | ||
510 | @@ -XXX,XX +XXX,XX @@ | ||
511 | #include "tb-hash.h" | ||
512 | #include "tb-context.h" | ||
513 | #include "internal.h" | ||
514 | +#include "perf.h" | ||
515 | |||
516 | /* Make sure all possible CPU event bits fit in tb->trace_vcpu_dstate */ | ||
517 | QEMU_BUILD_BUG_ON(CPU_TRACE_DSTATE_MAX_EVENTS > | ||
518 | @@ -XXX,XX +XXX,XX @@ TranslationBlock *tb_gen_code(CPUState *cpu, | ||
519 | } | ||
520 | tb->tc.size = gen_code_size; | ||
521 | |||
522 | + /* | ||
523 | + * For TARGET_TB_PCREL, attribute all executions of the generated | ||
524 | + * code to its first mapping. | ||
525 | + */ | ||
526 | + perf_report_code(pc, tb, tcg_splitwx_to_rx(gen_code_buf)); | ||
527 | + | ||
528 | #ifdef CONFIG_PROFILER | ||
529 | qatomic_set(&prof->code_time, prof->code_time + profile_getclock() - ti); | ||
530 | qatomic_set(&prof->code_in_len, prof->code_in_len + tb->size); | ||
531 | diff --git a/linux-user/exit.c b/linux-user/exit.c | ||
532 | index XXXXXXX..XXXXXXX 100644 | ||
533 | --- a/linux-user/exit.c | ||
534 | +++ b/linux-user/exit.c | ||
535 | @@ -XXX,XX +XXX,XX @@ | ||
536 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||
537 | */ | ||
538 | #include "qemu/osdep.h" | ||
539 | +#include "accel/tcg/perf.h" | ||
540 | #include "exec/gdbstub.h" | ||
541 | #include "qemu.h" | ||
542 | #include "user-internals.h" | ||
543 | @@ -XXX,XX +XXX,XX @@ void preexit_cleanup(CPUArchState *env, int code) | ||
544 | #endif | ||
545 | gdb_exit(code); | ||
546 | qemu_plugin_user_exit(); | ||
547 | + perf_exit(); | ||
548 | } | ||
549 | diff --git a/linux-user/main.c b/linux-user/main.c | ||
550 | index XXXXXXX..XXXXXXX 100644 | ||
551 | --- a/linux-user/main.c | ||
552 | +++ b/linux-user/main.c | ||
553 | @@ -XXX,XX +XXX,XX @@ | ||
554 | #include "signal-common.h" | ||
555 | #include "loader.h" | ||
556 | #include "user-mmap.h" | ||
557 | +#include "accel/tcg/perf.h" | ||
558 | |||
559 | #ifdef CONFIG_SEMIHOSTING | ||
560 | #include "semihosting/semihost.h" | ||
561 | @@ -XXX,XX +XXX,XX @@ static void handle_arg_abi_call0(const char *arg) | ||
562 | } | ||
563 | #endif | ||
564 | |||
565 | +static void handle_arg_perfmap(const char *arg) | ||
566 | +{ | ||
567 | + perf_enable_perfmap(); | ||
568 | +} | ||
569 | + | ||
570 | +static void handle_arg_jitdump(const char *arg) | ||
571 | +{ | ||
572 | + perf_enable_jitdump(); | ||
573 | +} | ||
574 | + | ||
575 | static QemuPluginList plugins = QTAILQ_HEAD_INITIALIZER(plugins); | ||
576 | |||
577 | #ifdef CONFIG_PLUGIN | ||
578 | @@ -XXX,XX +XXX,XX @@ static const struct qemu_argument arg_table[] = { | ||
579 | {"xtensa-abi-call0", "QEMU_XTENSA_ABI_CALL0", false, handle_arg_abi_call0, | ||
580 | "", "assume CALL0 Xtensa ABI"}, | ||
581 | #endif | ||
582 | + {"perfmap", "QEMU_PERFMAP", false, handle_arg_perfmap, | ||
583 | + "", "Generate a /tmp/perf-${pid}.map file for perf"}, | ||
584 | + {"jitdump", "QEMU_JITDUMP", false, handle_arg_jitdump, | ||
585 | + "", "Generate a jit-${pid}.dump file for perf"}, | ||
586 | {NULL, NULL, false, NULL, NULL, NULL} | ||
587 | }; | ||
588 | |||
589 | diff --git a/softmmu/vl.c b/softmmu/vl.c | ||
590 | index XXXXXXX..XXXXXXX 100644 | ||
591 | --- a/softmmu/vl.c | ||
592 | +++ b/softmmu/vl.c | ||
593 | @@ -XXX,XX +XXX,XX @@ | ||
594 | #include "fsdev/qemu-fsdev.h" | ||
595 | #endif | ||
596 | #include "sysemu/qtest.h" | ||
597 | +#ifdef CONFIG_TCG | ||
598 | +#include "accel/tcg/perf.h" | ||
599 | +#endif | ||
600 | |||
601 | #include "disas/disas.h" | ||
602 | |||
603 | @@ -XXX,XX +XXX,XX @@ void qemu_init(int argc, char **argv) | ||
604 | case QEMU_OPTION_DFILTER: | ||
605 | qemu_set_dfilter_ranges(optarg, &error_fatal); | ||
606 | break; | ||
607 | +#if defined(CONFIG_TCG) && defined(CONFIG_LINUX) | ||
608 | + case QEMU_OPTION_perfmap: | ||
609 | + perf_enable_perfmap(); | ||
610 | + break; | ||
611 | + case QEMU_OPTION_jitdump: | ||
612 | + perf_enable_jitdump(); | ||
613 | + break; | ||
614 | +#endif | ||
615 | case QEMU_OPTION_seed: | ||
616 | qemu_guest_random_seed_main(optarg, &error_fatal); | ||
617 | break; | ||
618 | diff --git a/tcg/tcg.c b/tcg/tcg.c | ||
619 | index XXXXXXX..XXXXXXX 100644 | ||
620 | --- a/tcg/tcg.c | ||
621 | +++ b/tcg/tcg.c | ||
622 | @@ -XXX,XX +XXX,XX @@ | ||
623 | #include "exec/log.h" | ||
624 | #include "tcg/tcg-ldst.h" | ||
625 | #include "tcg-internal.h" | ||
626 | +#include "accel/tcg/perf.h" | ||
627 | |||
628 | /* Forward declarations for functions declared in tcg-target.c.inc and | ||
629 | used here. */ | ||
630 | @@ -XXX,XX +XXX,XX @@ void tcg_prologue_init(TCGContext *s) | ||
631 | #endif | ||
632 | |||
633 | prologue_size = tcg_current_code_size(s); | ||
634 | + perf_report_prologue(s->code_gen_ptr, prologue_size); | ||
635 | |||
636 | #ifndef CONFIG_TCG_INTERPRETER | ||
637 | flush_idcache_range((uintptr_t)tcg_splitwx_to_rx(s->code_buf), | ||
638 | diff --git a/accel/tcg/meson.build b/accel/tcg/meson.build | ||
639 | index XXXXXXX..XXXXXXX 100644 | ||
640 | --- a/accel/tcg/meson.build | ||
641 | +++ b/accel/tcg/meson.build | ||
642 | @@ -XXX,XX +XXX,XX @@ tcg_ss.add(when: 'CONFIG_USER_ONLY', if_true: files('user-exec.c')) | ||
643 | tcg_ss.add(when: 'CONFIG_SOFTMMU', if_false: files('user-exec-stub.c')) | ||
644 | tcg_ss.add(when: 'CONFIG_PLUGIN', if_true: [files('plugin-gen.c')]) | ||
645 | tcg_ss.add(when: libdw, if_true: files('debuginfo.c')) | ||
646 | +tcg_ss.add(when: 'CONFIG_LINUX', if_true: files('perf.c')) | ||
647 | specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss) | ||
648 | |||
649 | specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files( | ||
650 | diff --git a/qemu-options.hx b/qemu-options.hx | ||
651 | index XXXXXXX..XXXXXXX 100644 | ||
652 | --- a/qemu-options.hx | ||
653 | +++ b/qemu-options.hx | ||
654 | @@ -XXX,XX +XXX,XX @@ SRST | ||
655 | Enable synchronization profiling. | ||
656 | ERST | ||
657 | |||
658 | +#if defined(CONFIG_TCG) && defined(CONFIG_LINUX) | ||
659 | +DEF("perfmap", 0, QEMU_OPTION_perfmap, | ||
660 | + "-perfmap generate a /tmp/perf-${pid}.map file for perf\n", | ||
661 | + QEMU_ARCH_ALL) | ||
662 | +SRST | ||
663 | +``-perfmap`` | ||
664 | + Generate a map file for Linux perf tools that will allow basic profiling | ||
665 | + information to be broken down into basic blocks. | ||
666 | +ERST | ||
667 | + | ||
668 | +DEF("jitdump", 0, QEMU_OPTION_jitdump, | ||
669 | + "-jitdump generate a jit-${pid}.dump file for perf\n", | ||
670 | + QEMU_ARCH_ALL) | ||
671 | +SRST | ||
672 | +``-jitdump`` | ||
673 | + Generate a dump file for Linux perf tools that maps basic blocks to symbol | ||
674 | + names, line numbers and JITted code. | ||
675 | +ERST | ||
676 | +#endif | ||
677 | + | ||
678 | DEFHEADING() | ||
679 | |||
680 | DEFHEADING(Generic object creation:) | ||
681 | -- | 81 | -- |
682 | 2.34.1 | 82 | 2.34.1 |
683 | 83 | ||
684 | 84 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Ilya Leoshkevich <iii@linux.ibm.com> | ||
1 | 2 | ||
3 | Follow what kernel's full_exception() is doing. | ||
4 | |||
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
7 | Message-Id: <20230214140829.45392-4-iii@linux.ibm.com> | ||
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | --- | ||
10 | linux-user/microblaze/cpu_loop.c | 10 ++++++++-- | ||
11 | 1 file changed, 8 insertions(+), 2 deletions(-) | ||
12 | |||
13 | diff --git a/linux-user/microblaze/cpu_loop.c b/linux-user/microblaze/cpu_loop.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/linux-user/microblaze/cpu_loop.c | ||
16 | +++ b/linux-user/microblaze/cpu_loop.c | ||
17 | @@ -XXX,XX +XXX,XX @@ | ||
18 | |||
19 | void cpu_loop(CPUMBState *env) | ||
20 | { | ||
21 | + int trapnr, ret, si_code, sig; | ||
22 | CPUState *cs = env_cpu(env); | ||
23 | - int trapnr, ret, si_code; | ||
24 | |||
25 | while (1) { | ||
26 | cpu_exec_start(cs); | ||
27 | @@ -XXX,XX +XXX,XX @@ void cpu_loop(CPUMBState *env) | ||
28 | env->iflags &= ~(IMM_FLAG | D_FLAG); | ||
29 | switch (env->esr & 31) { | ||
30 | case ESR_EC_DIVZERO: | ||
31 | + sig = TARGET_SIGFPE; | ||
32 | si_code = TARGET_FPE_INTDIV; | ||
33 | break; | ||
34 | case ESR_EC_FPU: | ||
35 | @@ -XXX,XX +XXX,XX @@ void cpu_loop(CPUMBState *env) | ||
36 | * if there's no recognized bit set. Possibly this | ||
37 | * implies that si_code is 0, but follow the structure. | ||
38 | */ | ||
39 | + sig = TARGET_SIGFPE; | ||
40 | si_code = env->fsr; | ||
41 | if (si_code & FSR_IO) { | ||
42 | si_code = TARGET_FPE_FLTINV; | ||
43 | @@ -XXX,XX +XXX,XX @@ void cpu_loop(CPUMBState *env) | ||
44 | si_code = TARGET_FPE_FLTRES; | ||
45 | } | ||
46 | break; | ||
47 | + case ESR_EC_PRIVINSN: | ||
48 | + sig = SIGILL; | ||
49 | + si_code = ILL_PRVOPC; | ||
50 | + break; | ||
51 | default: | ||
52 | fprintf(stderr, "Unhandled hw-exception: 0x%x\n", | ||
53 | env->esr & ESR_EC_MASK); | ||
54 | cpu_dump_state(cs, stderr, 0); | ||
55 | exit(EXIT_FAILURE); | ||
56 | } | ||
57 | - force_sig_fault(TARGET_SIGFPE, si_code, env->pc); | ||
58 | + force_sig_fault(sig, si_code, env->pc); | ||
59 | break; | ||
60 | |||
61 | case EXCP_DEBUG: | ||
62 | -- | ||
63 | 2.34.1 | diff view generated by jsdifflib |
1 | From: Ilya Leoshkevich <iii@linux.ibm.com> | 1 | Mirroring the upstream gdb xml files, the two stack boundary |
---|---|---|---|
2 | registers are separated out. | ||
2 | 3 | ||
3 | Add libdw-based functions for loading and querying debuginfo. Load | 4 | Reviewed-by: Edgar E. Iglesias <edgar@zeroasic.com> |
4 | debuginfo from the system and the linux-user loaders. | ||
5 | |||
6 | This is useful for the upcoming perf support, which can then put | ||
7 | human-readable guest symbols instead of raw guest PCs into perfmap and | ||
8 | jitdump files. | ||
9 | |||
10 | Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com> | ||
11 | Message-Id: <20230112152013.125680-3-iii@linux.ibm.com> | ||
12 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
13 | --- | 6 | --- |
14 | meson.build | 8 ++++ | 7 | target/microblaze/cpu.h | 2 + |
15 | accel/tcg/debuginfo.h | 77 +++++++++++++++++++++++++++++++++ | 8 | target/microblaze/cpu.c | 7 ++- |
16 | accel/tcg/debuginfo.c | 96 ++++++++++++++++++++++++++++++++++++++++++ | 9 | target/microblaze/gdbstub.c | 51 +++++++++++----- |
17 | hw/core/loader.c | 5 +++ | 10 | configs/targets/microblaze-linux-user.mak | 1 + |
18 | linux-user/elfload.c | 3 ++ | 11 | configs/targets/microblaze-softmmu.mak | 1 + |
19 | accel/tcg/meson.build | 1 + | 12 | configs/targets/microblazeel-linux-user.mak | 1 + |
20 | linux-user/meson.build | 1 + | 13 | configs/targets/microblazeel-softmmu.mak | 1 + |
21 | 7 files changed, 191 insertions(+) | 14 | gdb-xml/microblaze-core.xml | 67 +++++++++++++++++++++ |
22 | create mode 100644 accel/tcg/debuginfo.h | 15 | gdb-xml/microblaze-stack-protect.xml | 12 ++++ |
23 | create mode 100644 accel/tcg/debuginfo.c | 16 | 9 files changed, 128 insertions(+), 15 deletions(-) |
17 | create mode 100644 gdb-xml/microblaze-core.xml | ||
18 | create mode 100644 gdb-xml/microblaze-stack-protect.xml | ||
24 | 19 | ||
25 | diff --git a/meson.build b/meson.build | 20 | diff --git a/target/microblaze/cpu.h b/target/microblaze/cpu.h |
26 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/meson.build | 22 | --- a/target/microblaze/cpu.h |
28 | +++ b/meson.build | 23 | +++ b/target/microblaze/cpu.h |
29 | @@ -XXX,XX +XXX,XX @@ if libbpf.found() and not cc.links(''' | 24 | @@ -XXX,XX +XXX,XX @@ hwaddr mb_cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr, |
30 | endif | 25 | MemTxAttrs *attrs); |
31 | endif | 26 | int mb_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); |
32 | 27 | int mb_cpu_gdb_write_register(CPUState *cpu, uint8_t *buf, int reg); | |
33 | +# libdw | 28 | +int mb_cpu_gdb_read_stack_protect(CPUArchState *cpu, GByteArray *buf, int reg); |
34 | +libdw = dependency('libdw', | 29 | +int mb_cpu_gdb_write_stack_protect(CPUArchState *cpu, uint8_t *buf, int reg); |
35 | + method: 'pkg-config', | 30 | |
36 | + kwargs: static_kwargs, | 31 | static inline uint32_t mb_cpu_read_msr(const CPUMBState *env) |
37 | + required: false) | 32 | { |
38 | + | 33 | diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c |
39 | ################# | 34 | index XXXXXXX..XXXXXXX 100644 |
40 | # config-host.h # | 35 | --- a/target/microblaze/cpu.c |
41 | ################# | 36 | +++ b/target/microblaze/cpu.c |
42 | @@ -XXX,XX +XXX,XX @@ config_host_data.set('CONFIG_DBUS_DISPLAY', dbus_display) | 37 | @@ -XXX,XX +XXX,XX @@ |
43 | config_host_data.set('CONFIG_CFI', get_option('cfi')) | 38 | #include "qemu/module.h" |
44 | config_host_data.set('CONFIG_SELINUX', selinux.found()) | 39 | #include "hw/qdev-properties.h" |
45 | config_host_data.set('CONFIG_XEN_BACKEND', xen.found()) | 40 | #include "exec/exec-all.h" |
46 | +config_host_data.set('CONFIG_LIBDW', libdw.found()) | 41 | +#include "exec/gdbstub.h" |
47 | if xen.found() | 42 | #include "fpu/softfloat-helpers.h" |
48 | # protect from xen.version() having less than three components | 43 | |
49 | xen_version = xen.version().split('.') + ['0', '0'] | 44 | static const struct { |
50 | @@ -XXX,XX +XXX,XX @@ summary_info += {'libudev': libudev} | 45 | @@ -XXX,XX +XXX,XX @@ static void mb_cpu_initfn(Object *obj) |
51 | # Dummy dependency, keep .found() | 46 | CPUMBState *env = &cpu->env; |
52 | summary_info += {'FUSE lseek': fuse_lseek.found()} | 47 | |
53 | summary_info += {'selinux': selinux} | 48 | cpu_set_cpustate_pointers(cpu); |
54 | +summary_info += {'libdw': libdw} | 49 | + gdb_register_coprocessor(CPU(cpu), mb_cpu_gdb_read_stack_protect, |
55 | summary(summary_info, bool_yn: true, section: 'Dependencies') | 50 | + mb_cpu_gdb_write_stack_protect, 2, |
56 | 51 | + "microblaze-stack-protect.xml", 0); | |
57 | if not supported_cpus.contains(cpu) | 52 | |
58 | diff --git a/accel/tcg/debuginfo.h b/accel/tcg/debuginfo.h | 53 | set_float_rounding_mode(float_round_nearest_even, &env->fp_status); |
54 | |||
55 | @@ -XXX,XX +XXX,XX @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) | ||
56 | cc->sysemu_ops = &mb_sysemu_ops; | ||
57 | #endif | ||
58 | device_class_set_props(dc, mb_properties); | ||
59 | - cc->gdb_num_core_regs = 32 + 27; | ||
60 | + cc->gdb_num_core_regs = 32 + 25; | ||
61 | + cc->gdb_core_xml_file = "microblaze-core.xml"; | ||
62 | |||
63 | cc->disas_set_info = mb_disas_set_info; | ||
64 | cc->tcg_ops = &mb_tcg_ops; | ||
65 | diff --git a/target/microblaze/gdbstub.c b/target/microblaze/gdbstub.c | ||
66 | index XXXXXXX..XXXXXXX 100644 | ||
67 | --- a/target/microblaze/gdbstub.c | ||
68 | +++ b/target/microblaze/gdbstub.c | ||
69 | @@ -XXX,XX +XXX,XX @@ enum { | ||
70 | GDB_PVR0 = 32 + 6, | ||
71 | GDB_PVR11 = 32 + 17, | ||
72 | GDB_EDR = 32 + 18, | ||
73 | - GDB_SLR = 32 + 25, | ||
74 | - GDB_SHR = 32 + 26, | ||
75 | +}; | ||
76 | + | ||
77 | +enum { | ||
78 | + GDB_SP_SHL, | ||
79 | + GDB_SP_SHR, | ||
80 | }; | ||
81 | |||
82 | int mb_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) | ||
83 | @@ -XXX,XX +XXX,XX @@ int mb_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) | ||
84 | case GDB_EDR: | ||
85 | val = env->edr; | ||
86 | break; | ||
87 | - case GDB_SLR: | ||
88 | - val = env->slr; | ||
89 | - break; | ||
90 | - case GDB_SHR: | ||
91 | - val = env->shr; | ||
92 | - break; | ||
93 | default: | ||
94 | /* Other SRegs aren't modeled, so report a value of 0 */ | ||
95 | val = 0; | ||
96 | @@ -XXX,XX +XXX,XX @@ int mb_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n) | ||
97 | return gdb_get_reg32(mem_buf, val); | ||
98 | } | ||
99 | |||
100 | +int mb_cpu_gdb_read_stack_protect(CPUMBState *env, GByteArray *mem_buf, int n) | ||
101 | +{ | ||
102 | + uint32_t val; | ||
103 | + | ||
104 | + switch (n) { | ||
105 | + case GDB_SP_SHL: | ||
106 | + val = env->slr; | ||
107 | + break; | ||
108 | + case GDB_SP_SHR: | ||
109 | + val = env->shr; | ||
110 | + break; | ||
111 | + default: | ||
112 | + return 0; | ||
113 | + } | ||
114 | + return gdb_get_reg32(mem_buf, val); | ||
115 | +} | ||
116 | + | ||
117 | int mb_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) | ||
118 | { | ||
119 | MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs); | ||
120 | @@ -XXX,XX +XXX,XX @@ int mb_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n) | ||
121 | case GDB_EDR: | ||
122 | env->edr = tmp; | ||
123 | break; | ||
124 | - case GDB_SLR: | ||
125 | - env->slr = tmp; | ||
126 | - break; | ||
127 | - case GDB_SHR: | ||
128 | - env->shr = tmp; | ||
129 | - break; | ||
130 | + } | ||
131 | + return 4; | ||
132 | +} | ||
133 | + | ||
134 | +int mb_cpu_gdb_write_stack_protect(CPUMBState *env, uint8_t *mem_buf, int n) | ||
135 | +{ | ||
136 | + switch (n) { | ||
137 | + case GDB_SP_SHL: | ||
138 | + env->slr = ldl_p(mem_buf); | ||
139 | + break; | ||
140 | + case GDB_SP_SHR: | ||
141 | + env->shr = ldl_p(mem_buf); | ||
142 | + break; | ||
143 | + default: | ||
144 | + return 0; | ||
145 | } | ||
146 | return 4; | ||
147 | } | ||
148 | diff --git a/configs/targets/microblaze-linux-user.mak b/configs/targets/microblaze-linux-user.mak | ||
149 | index XXXXXXX..XXXXXXX 100644 | ||
150 | --- a/configs/targets/microblaze-linux-user.mak | ||
151 | +++ b/configs/targets/microblaze-linux-user.mak | ||
152 | @@ -XXX,XX +XXX,XX @@ TARGET_SYSTBL_ABI=common | ||
153 | TARGET_SYSTBL=syscall.tbl | ||
154 | TARGET_BIG_ENDIAN=y | ||
155 | TARGET_HAS_BFLT=y | ||
156 | +TARGET_XML_FILES=gdb-xml/microblaze-core.xml gdb-xml/microblaze-stack-protect.xml | ||
157 | diff --git a/configs/targets/microblaze-softmmu.mak b/configs/targets/microblaze-softmmu.mak | ||
158 | index XXXXXXX..XXXXXXX 100644 | ||
159 | --- a/configs/targets/microblaze-softmmu.mak | ||
160 | +++ b/configs/targets/microblaze-softmmu.mak | ||
161 | @@ -XXX,XX +XXX,XX @@ TARGET_ARCH=microblaze | ||
162 | TARGET_BIG_ENDIAN=y | ||
163 | TARGET_SUPPORTS_MTTCG=y | ||
164 | TARGET_NEED_FDT=y | ||
165 | +TARGET_XML_FILES=gdb-xml/microblaze-core.xml gdb-xml/microblaze-stack-protect.xml | ||
166 | diff --git a/configs/targets/microblazeel-linux-user.mak b/configs/targets/microblazeel-linux-user.mak | ||
167 | index XXXXXXX..XXXXXXX 100644 | ||
168 | --- a/configs/targets/microblazeel-linux-user.mak | ||
169 | +++ b/configs/targets/microblazeel-linux-user.mak | ||
170 | @@ -XXX,XX +XXX,XX @@ TARGET_ARCH=microblaze | ||
171 | TARGET_SYSTBL_ABI=common | ||
172 | TARGET_SYSTBL=syscall.tbl | ||
173 | TARGET_HAS_BFLT=y | ||
174 | +TARGET_XML_FILES=gdb-xml/microblaze-core.xml gdb-xml/microblaze-stack-protect.xml | ||
175 | diff --git a/configs/targets/microblazeel-softmmu.mak b/configs/targets/microblazeel-softmmu.mak | ||
176 | index XXXXXXX..XXXXXXX 100644 | ||
177 | --- a/configs/targets/microblazeel-softmmu.mak | ||
178 | +++ b/configs/targets/microblazeel-softmmu.mak | ||
179 | @@ -XXX,XX +XXX,XX @@ | ||
180 | TARGET_ARCH=microblaze | ||
181 | TARGET_SUPPORTS_MTTCG=y | ||
182 | TARGET_NEED_FDT=y | ||
183 | +TARGET_XML_FILES=gdb-xml/microblaze-core.xml gdb-xml/microblaze-stack-protect.xml | ||
184 | diff --git a/gdb-xml/microblaze-core.xml b/gdb-xml/microblaze-core.xml | ||
59 | new file mode 100644 | 185 | new file mode 100644 |
60 | index XXXXXXX..XXXXXXX | 186 | index XXXXXXX..XXXXXXX |
61 | --- /dev/null | 187 | --- /dev/null |
62 | +++ b/accel/tcg/debuginfo.h | 188 | +++ b/gdb-xml/microblaze-core.xml |
63 | @@ -XXX,XX +XXX,XX @@ | 189 | @@ -XXX,XX +XXX,XX @@ |
64 | +/* | 190 | +<?xml version="1.0"?> |
65 | + * Debug information support. | 191 | +<!-- Copyright (C) 2008 Free Software Foundation, Inc. |
66 | + * | 192 | + |
67 | + * SPDX-License-Identifier: GPL-2.0-or-later | 193 | + Copying and distribution of this file, with or without modification, |
68 | + */ | 194 | + are permitted in any medium without royalty provided the copyright |
69 | + | 195 | + notice and this notice are preserved. --> |
70 | +#ifndef ACCEL_TCG_DEBUGINFO_H | 196 | + |
71 | +#define ACCEL_TCG_DEBUGINFO_H | 197 | +<!DOCTYPE feature SYSTEM "gdb-target.dtd"> |
72 | + | 198 | +<feature name="org.gnu.gdb.microblaze.core"> |
73 | +/* | 199 | + <reg name="r0" bitsize="32" regnum="0"/> |
74 | + * Debuginfo describing a certain address. | 200 | + <reg name="r1" bitsize="32" type="data_ptr"/> |
75 | + */ | 201 | + <reg name="r2" bitsize="32"/> |
76 | +struct debuginfo_query { | 202 | + <reg name="r3" bitsize="32"/> |
77 | + uint64_t address; /* Input: address. */ | 203 | + <reg name="r4" bitsize="32"/> |
78 | + int flags; /* Input: debuginfo subset. */ | 204 | + <reg name="r5" bitsize="32"/> |
79 | + const char *symbol; /* Symbol that the address is part of. */ | 205 | + <reg name="r6" bitsize="32"/> |
80 | + uint64_t offset; /* Offset from the symbol. */ | 206 | + <reg name="r7" bitsize="32"/> |
81 | + const char *file; /* Source file associated with the address. */ | 207 | + <reg name="r8" bitsize="32"/> |
82 | + int line; /* Line number in the source file. */ | 208 | + <reg name="r9" bitsize="32"/> |
83 | +}; | 209 | + <reg name="r10" bitsize="32"/> |
84 | + | 210 | + <reg name="r11" bitsize="32"/> |
85 | +/* | 211 | + <reg name="r12" bitsize="32"/> |
86 | + * Debuginfo subsets. | 212 | + <reg name="r13" bitsize="32"/> |
87 | + */ | 213 | + <reg name="r14" bitsize="32"/> |
88 | +#define DEBUGINFO_SYMBOL BIT(1) | 214 | + <reg name="r15" bitsize="32"/> |
89 | +#define DEBUGINFO_LINE BIT(2) | 215 | + <reg name="r16" bitsize="32"/> |
90 | + | 216 | + <reg name="r17" bitsize="32"/> |
91 | +#if defined(CONFIG_TCG) && defined(CONFIG_LIBDW) | 217 | + <reg name="r18" bitsize="32"/> |
92 | +/* | 218 | + <reg name="r19" bitsize="32"/> |
93 | + * Load debuginfo for the specified guest ELF image. | 219 | + <reg name="r20" bitsize="32"/> |
94 | + * Return true on success, false on failure. | 220 | + <reg name="r21" bitsize="32"/> |
95 | + */ | 221 | + <reg name="r22" bitsize="32"/> |
96 | +void debuginfo_report_elf(const char *name, int fd, uint64_t bias); | 222 | + <reg name="r23" bitsize="32"/> |
97 | + | 223 | + <reg name="r24" bitsize="32"/> |
98 | +/* | 224 | + <reg name="r25" bitsize="32"/> |
99 | + * Take the debuginfo lock. | 225 | + <reg name="r26" bitsize="32"/> |
100 | + */ | 226 | + <reg name="r27" bitsize="32"/> |
101 | +void debuginfo_lock(void); | 227 | + <reg name="r28" bitsize="32"/> |
102 | + | 228 | + <reg name="r29" bitsize="32"/> |
103 | +/* | 229 | + <reg name="r30" bitsize="32"/> |
104 | + * Fill each on N Qs with the debuginfo about Q->ADDRESS as specified by | 230 | + <reg name="r31" bitsize="32"/> |
105 | + * Q->FLAGS: | 231 | + <reg name="rpc" bitsize="32" type="code_ptr"/> |
106 | + * | 232 | + <reg name="rmsr" bitsize="32"/> |
107 | + * - DEBUGINFO_SYMBOL: update Q->SYMBOL and Q->OFFSET. If symbol debuginfo is | 233 | + <reg name="rear" bitsize="32"/> |
108 | + * missing, then leave them as is. | 234 | + <reg name="resr" bitsize="32"/> |
109 | + * - DEBUINFO_LINE: update Q->FILE and Q->LINE. If line debuginfo is missing, | 235 | + <reg name="rfsr" bitsize="32"/> |
110 | + * then leave them as is. | 236 | + <reg name="rbtr" bitsize="32"/> |
111 | + * | 237 | + <reg name="rpvr0" bitsize="32"/> |
112 | + * This function must be called under the debuginfo lock. The results can be | 238 | + <reg name="rpvr1" bitsize="32"/> |
113 | + * accessed only until the debuginfo lock is released. | 239 | + <reg name="rpvr2" bitsize="32"/> |
114 | + */ | 240 | + <reg name="rpvr3" bitsize="32"/> |
115 | +void debuginfo_query(struct debuginfo_query *q, size_t n); | 241 | + <reg name="rpvr4" bitsize="32"/> |
116 | + | 242 | + <reg name="rpvr5" bitsize="32"/> |
117 | +/* | 243 | + <reg name="rpvr6" bitsize="32"/> |
118 | + * Release the debuginfo lock. | 244 | + <reg name="rpvr7" bitsize="32"/> |
119 | + */ | 245 | + <reg name="rpvr8" bitsize="32"/> |
120 | +void debuginfo_unlock(void); | 246 | + <reg name="rpvr9" bitsize="32"/> |
121 | +#else | 247 | + <reg name="rpvr10" bitsize="32"/> |
122 | +static inline void debuginfo_report_elf(const char *image_name, int image_fd, | 248 | + <reg name="rpvr11" bitsize="32"/> |
123 | + uint64_t load_bias) | 249 | + <reg name="redr" bitsize="32"/> |
124 | +{ | 250 | + <reg name="rpid" bitsize="32"/> |
125 | +} | 251 | + <reg name="rzpr" bitsize="32"/> |
126 | + | 252 | + <reg name="rtlbx" bitsize="32"/> |
127 | +static inline void debuginfo_lock(void) | 253 | + <reg name="rtlbsx" bitsize="32"/> |
128 | +{ | 254 | + <reg name="rtlblo" bitsize="32"/> |
129 | +} | 255 | + <reg name="rtlbhi" bitsize="32"/> |
130 | + | 256 | +</feature> |
131 | +static inline void debuginfo_query(struct debuginfo_query *q, size_t n) | 257 | diff --git a/gdb-xml/microblaze-stack-protect.xml b/gdb-xml/microblaze-stack-protect.xml |
132 | +{ | ||
133 | +} | ||
134 | + | ||
135 | +static inline void debuginfo_unlock(void) | ||
136 | +{ | ||
137 | +} | ||
138 | +#endif | ||
139 | + | ||
140 | +#endif | ||
141 | diff --git a/accel/tcg/debuginfo.c b/accel/tcg/debuginfo.c | ||
142 | new file mode 100644 | 258 | new file mode 100644 |
143 | index XXXXXXX..XXXXXXX | 259 | index XXXXXXX..XXXXXXX |
144 | --- /dev/null | 260 | --- /dev/null |
145 | +++ b/accel/tcg/debuginfo.c | 261 | +++ b/gdb-xml/microblaze-stack-protect.xml |
146 | @@ -XXX,XX +XXX,XX @@ | 262 | @@ -XXX,XX +XXX,XX @@ |
147 | +/* | 263 | +<?xml version="1.0"?> |
148 | + * Debug information support. | 264 | +<!-- Copyright (C) 2008 Free Software Foundation, Inc. |
149 | + * | 265 | + |
150 | + * SPDX-License-Identifier: GPL-2.0-or-later | 266 | + Copying and distribution of this file, with or without modification, |
151 | + */ | 267 | + are permitted in any medium without royalty provided the copyright |
152 | + | 268 | + notice and this notice are preserved. --> |
153 | +#include "qemu/osdep.h" | 269 | + |
154 | +#include "qemu/lockable.h" | 270 | +<!DOCTYPE feature SYSTEM "gdb-target.dtd"> |
155 | + | 271 | +<feature name="org.gnu.gdb.microblaze.stack-protect"> |
156 | +#include <elfutils/libdwfl.h> | 272 | + <reg name="rslr" bitsize="32"/> |
157 | + | 273 | + <reg name="rshr" bitsize="32"/> |
158 | +#include "debuginfo.h" | 274 | +</feature> |
159 | + | ||
160 | +static QemuMutex lock; | ||
161 | +static Dwfl *dwfl; | ||
162 | +static const Dwfl_Callbacks dwfl_callbacks = { | ||
163 | + .find_elf = NULL, | ||
164 | + .find_debuginfo = dwfl_standard_find_debuginfo, | ||
165 | + .section_address = NULL, | ||
166 | + .debuginfo_path = NULL, | ||
167 | +}; | ||
168 | + | ||
169 | +__attribute__((constructor)) | ||
170 | +static void debuginfo_init(void) | ||
171 | +{ | ||
172 | + qemu_mutex_init(&lock); | ||
173 | +} | ||
174 | + | ||
175 | +void debuginfo_report_elf(const char *name, int fd, uint64_t bias) | ||
176 | +{ | ||
177 | + QEMU_LOCK_GUARD(&lock); | ||
178 | + | ||
179 | + if (dwfl) { | ||
180 | + dwfl_report_begin_add(dwfl); | ||
181 | + } else { | ||
182 | + dwfl = dwfl_begin(&dwfl_callbacks); | ||
183 | + } | ||
184 | + | ||
185 | + if (dwfl) { | ||
186 | + dwfl_report_elf(dwfl, name, name, fd, bias, true); | ||
187 | + dwfl_report_end(dwfl, NULL, NULL); | ||
188 | + } | ||
189 | +} | ||
190 | + | ||
191 | +void debuginfo_lock(void) | ||
192 | +{ | ||
193 | + qemu_mutex_lock(&lock); | ||
194 | +} | ||
195 | + | ||
196 | +void debuginfo_query(struct debuginfo_query *q, size_t n) | ||
197 | +{ | ||
198 | + const char *symbol, *file; | ||
199 | + Dwfl_Module *dwfl_module; | ||
200 | + Dwfl_Line *dwfl_line; | ||
201 | + GElf_Off dwfl_offset; | ||
202 | + GElf_Sym dwfl_sym; | ||
203 | + size_t i; | ||
204 | + int line; | ||
205 | + | ||
206 | + if (!dwfl) { | ||
207 | + return; | ||
208 | + } | ||
209 | + | ||
210 | + for (i = 0; i < n; i++) { | ||
211 | + dwfl_module = dwfl_addrmodule(dwfl, q[i].address); | ||
212 | + if (!dwfl_module) { | ||
213 | + continue; | ||
214 | + } | ||
215 | + | ||
216 | + if (q[i].flags & DEBUGINFO_SYMBOL) { | ||
217 | + symbol = dwfl_module_addrinfo(dwfl_module, q[i].address, | ||
218 | + &dwfl_offset, &dwfl_sym, | ||
219 | + NULL, NULL, NULL); | ||
220 | + if (symbol) { | ||
221 | + q[i].symbol = symbol; | ||
222 | + q[i].offset = dwfl_offset; | ||
223 | + } | ||
224 | + } | ||
225 | + | ||
226 | + if (q[i].flags & DEBUGINFO_LINE) { | ||
227 | + dwfl_line = dwfl_module_getsrc(dwfl_module, q[i].address); | ||
228 | + if (dwfl_line) { | ||
229 | + file = dwfl_lineinfo(dwfl_line, NULL, &line, 0, NULL, NULL); | ||
230 | + if (file) { | ||
231 | + q[i].file = file; | ||
232 | + q[i].line = line; | ||
233 | + } | ||
234 | + } | ||
235 | + } | ||
236 | + } | ||
237 | +} | ||
238 | + | ||
239 | +void debuginfo_unlock(void) | ||
240 | +{ | ||
241 | + qemu_mutex_unlock(&lock); | ||
242 | +} | ||
243 | diff --git a/hw/core/loader.c b/hw/core/loader.c | ||
244 | index XXXXXXX..XXXXXXX 100644 | ||
245 | --- a/hw/core/loader.c | ||
246 | +++ b/hw/core/loader.c | ||
247 | @@ -XXX,XX +XXX,XX @@ | ||
248 | #include "hw/boards.h" | ||
249 | #include "qemu/cutils.h" | ||
250 | #include "sysemu/runstate.h" | ||
251 | +#include "accel/tcg/debuginfo.h" | ||
252 | |||
253 | #include <zlib.h> | ||
254 | |||
255 | @@ -XXX,XX +XXX,XX @@ ssize_t load_elf_ram_sym(const char *filename, | ||
256 | clear_lsb, data_swab, as, load_rom, sym_cb); | ||
257 | } | ||
258 | |||
259 | + if (ret != ELF_LOAD_FAILED) { | ||
260 | + debuginfo_report_elf(filename, fd, 0); | ||
261 | + } | ||
262 | + | ||
263 | fail: | ||
264 | close(fd); | ||
265 | return ret; | ||
266 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | ||
267 | index XXXXXXX..XXXXXXX 100644 | ||
268 | --- a/linux-user/elfload.c | ||
269 | +++ b/linux-user/elfload.c | ||
270 | @@ -XXX,XX +XXX,XX @@ | ||
271 | #include "qemu/selfmap.h" | ||
272 | #include "qapi/error.h" | ||
273 | #include "target_signal.h" | ||
274 | +#include "accel/tcg/debuginfo.h" | ||
275 | |||
276 | #ifdef _ARCH_PPC64 | ||
277 | #undef ARCH_DLINFO | ||
278 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
279 | load_symbols(ehdr, image_fd, load_bias); | ||
280 | } | ||
281 | |||
282 | + debuginfo_report_elf(image_name, image_fd, load_bias); | ||
283 | + | ||
284 | mmap_unlock(); | ||
285 | |||
286 | close(image_fd); | ||
287 | diff --git a/accel/tcg/meson.build b/accel/tcg/meson.build | ||
288 | index XXXXXXX..XXXXXXX 100644 | ||
289 | --- a/accel/tcg/meson.build | ||
290 | +++ b/accel/tcg/meson.build | ||
291 | @@ -XXX,XX +XXX,XX @@ tcg_ss.add(files( | ||
292 | tcg_ss.add(when: 'CONFIG_USER_ONLY', if_true: files('user-exec.c')) | ||
293 | tcg_ss.add(when: 'CONFIG_SOFTMMU', if_false: files('user-exec-stub.c')) | ||
294 | tcg_ss.add(when: 'CONFIG_PLUGIN', if_true: [files('plugin-gen.c')]) | ||
295 | +tcg_ss.add(when: libdw, if_true: files('debuginfo.c')) | ||
296 | specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss) | ||
297 | |||
298 | specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files( | ||
299 | diff --git a/linux-user/meson.build b/linux-user/meson.build | ||
300 | index XXXXXXX..XXXXXXX 100644 | ||
301 | --- a/linux-user/meson.build | ||
302 | +++ b/linux-user/meson.build | ||
303 | @@ -XXX,XX +XXX,XX @@ linux_user_ss.add(files( | ||
304 | 'uname.c', | ||
305 | )) | ||
306 | linux_user_ss.add(rt) | ||
307 | +linux_user_ss.add(libdw) | ||
308 | |||
309 | linux_user_ss.add(when: 'TARGET_HAS_BFLT', if_true: files('flatload.c')) | ||
310 | linux_user_ss.add(when: 'TARGET_I386', if_true: files('vm86.c')) | ||
311 | -- | 275 | -- |
312 | 2.34.1 | 276 | 2.34.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
1 | 2 | ||
3 | ctr_el0 access is privileged on this platform and fails as an illegal | ||
4 | instruction. | ||
5 | |||
6 | Windows does not offer a way to flush data cache from userspace, and | ||
7 | only FlushInstructionCache is available in Windows API. | ||
8 | |||
9 | The generic implementation of flush_idcache_range uses, | ||
10 | __builtin___clear_cache, which already use the FlushInstructionCache | ||
11 | function. So we rely on that. | ||
12 | |||
13 | Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
14 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
15 | Message-Id: <20230221153006.20300-2-pierrick.bouvier@linaro.org> | ||
16 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
17 | --- | ||
18 | util/cacheflush.c | 14 +++++++++++--- | ||
19 | 1 file changed, 11 insertions(+), 3 deletions(-) | ||
20 | |||
21 | diff --git a/util/cacheflush.c b/util/cacheflush.c | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/util/cacheflush.c | ||
24 | +++ b/util/cacheflush.c | ||
25 | @@ -XXX,XX +XXX,XX @@ static void sys_cache_info(int *isize, int *dsize) | ||
26 | static bool have_coherent_icache; | ||
27 | #endif | ||
28 | |||
29 | -#if defined(__aarch64__) && !defined(CONFIG_DARWIN) | ||
30 | -/* Apple does not expose CTR_EL0, so we must use system interfaces. */ | ||
31 | +#if defined(__aarch64__) && !defined(CONFIG_DARWIN) && !defined(CONFIG_WIN32) | ||
32 | +/* | ||
33 | + * Apple does not expose CTR_EL0, so we must use system interfaces. | ||
34 | + * Windows neither, but we use a generic implementation of flush_idcache_range | ||
35 | + * in this case. | ||
36 | + */ | ||
37 | static uint64_t save_ctr_el0; | ||
38 | static void arch_cache_info(int *isize, int *dsize) | ||
39 | { | ||
40 | @@ -XXX,XX +XXX,XX @@ static void __attribute__((constructor)) init_cache_info(void) | ||
41 | |||
42 | /* Caches are coherent and do not require flushing; symbol inline. */ | ||
43 | |||
44 | -#elif defined(__aarch64__) | ||
45 | +#elif defined(__aarch64__) && !defined(CONFIG_WIN32) | ||
46 | +/* | ||
47 | + * For Windows, we use generic implementation of flush_idcache_range, that | ||
48 | + * performs a call to FlushInstructionCache, through __builtin___clear_cache. | ||
49 | + */ | ||
50 | |||
51 | #ifdef CONFIG_DARWIN | ||
52 | /* Apple does not expose CTR_EL0, so we must use system interfaces. */ | ||
53 | -- | ||
54 | 2.34.1 | diff view generated by jsdifflib |
1 | Use the attribute, which is supported by clang, instead of | 1 | From: Pierrick Bouvier <pierrick.bouvier@linaro.org> |
---|---|---|---|
2 | the #pragma, which is not supported and, for some reason, | ||
3 | also not detected by the meson probe, so we fail by -Werror. | ||
4 | 2 | ||
5 | Include only <immintrin.h> as that is the outermost "official" | 3 | Windows implementation of setjmp/longjmp is done in |
6 | header for these intrinsics -- emmintrin.h and smmintrin -- are | 4 | C:/WINDOWS/system32/ucrtbase.dll. Alas, on arm64, it seems to *always* |
7 | older SSE2 and SSE4 specific headers, while the immintrin.h | 5 | perform stack unwinding, which crashes from generated code. |
8 | includes all of the Intel intrinsics. | ||
9 | 6 | ||
10 | Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> | 7 | By using alternative implementation built in mingw, we avoid doing stack |
8 | unwinding and this fixes crash when calling longjmp. | ||
9 | |||
10 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
11 | Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org> | ||
12 | Acked-by: Richard Henderson <richard.henderson@linaro.org> | ||
13 | Message-Id: <20230221153006.20300-3-pierrick.bouvier@linaro.org> | ||
11 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 14 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
12 | --- | 15 | --- |
13 | meson.build | 8 ++------ | 16 | include/sysemu/os-win32.h | 28 ++++++++++++++++++++++++---- |
14 | util/bufferiszero.c | 41 ++++++----------------------------------- | 17 | meson.build | 21 +++++++++++++++++++++ |
15 | 2 files changed, 8 insertions(+), 41 deletions(-) | 18 | 2 files changed, 45 insertions(+), 4 deletions(-) |
16 | 19 | ||
20 | diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/include/sysemu/os-win32.h | ||
23 | +++ b/include/sysemu/os-win32.h | ||
24 | @@ -XXX,XX +XXX,XX @@ typedef struct sockaddr_un { | ||
25 | extern "C" { | ||
26 | #endif | ||
27 | |||
28 | -#if defined(_WIN64) | ||
29 | -/* On w64, setjmp is implemented by _setjmp which needs a second parameter. | ||
30 | +#if defined(__aarch64__) | ||
31 | +/* | ||
32 | + * On windows-arm64, setjmp is available in only one variant, and longjmp always | ||
33 | + * does stack unwinding. This crash with generated code. | ||
34 | + * Thus, we use another implementation of setjmp (not windows one), coming from | ||
35 | + * mingw, which never performs stack unwinding. | ||
36 | + */ | ||
37 | +#undef setjmp | ||
38 | +#undef longjmp | ||
39 | +/* | ||
40 | + * These functions are not declared in setjmp.h because __aarch64__ defines | ||
41 | + * setjmp to _setjmpex instead. However, they are still defined in libmingwex.a, | ||
42 | + * which gets linked automatically. | ||
43 | + */ | ||
44 | +extern int __mingw_setjmp(jmp_buf); | ||
45 | +extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int); | ||
46 | +#define setjmp(env) __mingw_setjmp(env) | ||
47 | +#define longjmp(env, val) __mingw_longjmp(env, val) | ||
48 | +#elif defined(_WIN64) | ||
49 | +/* | ||
50 | + * On windows-x64, setjmp is implemented by _setjmp which needs a second parameter. | ||
51 | * If this parameter is NULL, longjump does no stack unwinding. | ||
52 | * That is what we need for QEMU. Passing the value of register rsp (default) | ||
53 | - * lets longjmp try a stack unwinding which will crash with generated code. */ | ||
54 | + * lets longjmp try a stack unwinding which will crash with generated code. | ||
55 | + */ | ||
56 | # undef setjmp | ||
57 | # define setjmp(env) _setjmp(env, NULL) | ||
58 | -#endif | ||
59 | +#endif /* __aarch64__ */ | ||
60 | /* QEMU uses sigsetjmp()/siglongjmp() as the portable way to specify | ||
61 | * "longjmp and don't touch the signal masks". Since we know that the | ||
62 | * savemask parameter will always be zero we can safely define these | ||
17 | diff --git a/meson.build b/meson.build | 63 | diff --git a/meson.build b/meson.build |
18 | index XXXXXXX..XXXXXXX 100644 | 64 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/meson.build | 65 | --- a/meson.build |
20 | +++ b/meson.build | 66 | +++ b/meson.build |
21 | @@ -XXX,XX +XXX,XX @@ config_host_data.set('CONFIG_CPUID_H', have_cpuid_h) | 67 | @@ -XXX,XX +XXX,XX @@ if targetos == 'windows' |
22 | config_host_data.set('CONFIG_AVX2_OPT', get_option('avx2') \ | 68 | }''', name: '_lock_file and _unlock_file')) |
23 | .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot enable AVX2') \ | 69 | endif |
24 | .require(cc.links(''' | 70 | |
25 | - #pragma GCC push_options | 71 | +if targetos == 'windows' |
26 | - #pragma GCC target("avx2") | 72 | + mingw_has_setjmp_longjmp = cc.links(''' |
27 | #include <cpuid.h> | 73 | + #include <setjmp.h> |
28 | #include <immintrin.h> | 74 | + int main(void) { |
29 | - static int bar(void *a) { | 75 | + /* |
30 | + static int __attribute__((target("avx2"))) bar(void *a) { | 76 | + * These functions are not available in setjmp header, but may be |
31 | __m256i x = *(__m256i *)a; | 77 | + * available at link time, from libmingwex.a. |
32 | return _mm256_testz_si256(x, x); | 78 | + */ |
33 | } | 79 | + extern int __mingw_setjmp(jmp_buf); |
34 | @@ -XXX,XX +XXX,XX @@ config_host_data.set('CONFIG_AVX2_OPT', get_option('avx2') \ | 80 | + extern void __attribute__((noreturn)) __mingw_longjmp(jmp_buf, int); |
35 | config_host_data.set('CONFIG_AVX512F_OPT', get_option('avx512f') \ | 81 | + jmp_buf env; |
36 | .require(have_cpuid_h, error_message: 'cpuid.h not available, cannot enable AVX512F') \ | 82 | + __mingw_setjmp(env); |
37 | .require(cc.links(''' | 83 | + __mingw_longjmp(env, 0); |
38 | - #pragma GCC push_options | 84 | + } |
39 | - #pragma GCC target("avx512f") | 85 | + ''', name: 'mingw setjmp and longjmp') |
40 | #include <cpuid.h> | 86 | + |
41 | #include <immintrin.h> | 87 | + if cpu == 'aarch64' and not mingw_has_setjmp_longjmp |
42 | - static int bar(void *a) { | 88 | + error('mingw must provide setjmp/longjmp for windows-arm64') |
43 | + static int __attribute__((target("avx512f"))) bar(void *a) { | 89 | + endif |
44 | __m512i x = *(__m512i *)a; | 90 | +endif |
45 | return _mm512_test_epi64_mask(x, x); | 91 | + |
46 | } | 92 | ######################## |
47 | diff --git a/util/bufferiszero.c b/util/bufferiszero.c | 93 | # Target configuration # |
48 | index XXXXXXX..XXXXXXX 100644 | 94 | ######################## |
49 | --- a/util/bufferiszero.c | ||
50 | +++ b/util/bufferiszero.c | ||
51 | @@ -XXX,XX +XXX,XX @@ buffer_zero_int(const void *buf, size_t len) | ||
52 | } | ||
53 | |||
54 | #if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) || defined(__SSE2__) | ||
55 | -/* Do not use push_options pragmas unnecessarily, because clang | ||
56 | - * does not support them. | ||
57 | - */ | ||
58 | -#if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) | ||
59 | -#pragma GCC push_options | ||
60 | -#pragma GCC target("sse2") | ||
61 | -#endif | ||
62 | -#include <emmintrin.h> | ||
63 | +#include <immintrin.h> | ||
64 | |||
65 | /* Note that each of these vectorized functions require len >= 64. */ | ||
66 | |||
67 | -static bool | ||
68 | +static bool __attribute__((target("sse2"))) | ||
69 | buffer_zero_sse2(const void *buf, size_t len) | ||
70 | { | ||
71 | __m128i t = _mm_loadu_si128(buf); | ||
72 | @@ -XXX,XX +XXX,XX @@ buffer_zero_sse2(const void *buf, size_t len) | ||
73 | |||
74 | return _mm_movemask_epi8(_mm_cmpeq_epi8(t, zero)) == 0xFFFF; | ||
75 | } | ||
76 | -#if defined(CONFIG_AVX512F_OPT) || defined(CONFIG_AVX2_OPT) | ||
77 | -#pragma GCC pop_options | ||
78 | -#endif | ||
79 | |||
80 | #ifdef CONFIG_AVX2_OPT | ||
81 | -/* Note that due to restrictions/bugs wrt __builtin functions in gcc <= 4.8, | ||
82 | - * the includes have to be within the corresponding push_options region, and | ||
83 | - * therefore the regions themselves have to be ordered with increasing ISA. | ||
84 | - */ | ||
85 | -#pragma GCC push_options | ||
86 | -#pragma GCC target("sse4") | ||
87 | -#include <smmintrin.h> | ||
88 | - | ||
89 | -static bool | ||
90 | +static bool __attribute__((target("sse4"))) | ||
91 | buffer_zero_sse4(const void *buf, size_t len) | ||
92 | { | ||
93 | __m128i t = _mm_loadu_si128(buf); | ||
94 | @@ -XXX,XX +XXX,XX @@ buffer_zero_sse4(const void *buf, size_t len) | ||
95 | return _mm_testz_si128(t, t); | ||
96 | } | ||
97 | |||
98 | -#pragma GCC pop_options | ||
99 | -#pragma GCC push_options | ||
100 | -#pragma GCC target("avx2") | ||
101 | -#include <immintrin.h> | ||
102 | - | ||
103 | -static bool | ||
104 | +static bool __attribute__((target("avx2"))) | ||
105 | buffer_zero_avx2(const void *buf, size_t len) | ||
106 | { | ||
107 | /* Begin with an unaligned head of 32 bytes. */ | ||
108 | @@ -XXX,XX +XXX,XX @@ buffer_zero_avx2(const void *buf, size_t len) | ||
109 | |||
110 | return _mm256_testz_si256(t, t); | ||
111 | } | ||
112 | -#pragma GCC pop_options | ||
113 | #endif /* CONFIG_AVX2_OPT */ | ||
114 | |||
115 | #ifdef CONFIG_AVX512F_OPT | ||
116 | -#pragma GCC push_options | ||
117 | -#pragma GCC target("avx512f") | ||
118 | -#include <immintrin.h> | ||
119 | - | ||
120 | -static bool | ||
121 | +static bool __attribute__((target("avx512f"))) | ||
122 | buffer_zero_avx512(const void *buf, size_t len) | ||
123 | { | ||
124 | /* Begin with an unaligned head of 64 bytes. */ | ||
125 | @@ -XXX,XX +XXX,XX @@ buffer_zero_avx512(const void *buf, size_t len) | ||
126 | return !_mm512_test_epi64_mask(t, t); | ||
127 | |||
128 | } | ||
129 | -#pragma GCC pop_options | ||
130 | -#endif | ||
131 | +#endif /* CONFIG_AVX512F_OPT */ | ||
132 | |||
133 | |||
134 | /* Note that for test_buffer_is_zero_next_accel, the most preferred | ||
135 | -- | 95 | -- |
136 | 2.34.1 | 96 | 2.34.1 |
137 | 97 | ||
138 | 98 | diff view generated by jsdifflib |