From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
To: Richard Henderson <richard.henderson@linaro.org>, qemu-devel@nongnu.org
Cc: philmd@linaro.org
Subject: Re: [PATCH v2 12/42] accel/tcg: Use cpu_ld*_code_mmu in translator.c
Date: Tue, 18 Mar 2025 17:23:36 -0700 [thread overview]
Message-ID: <f3b98848-70b7-4ece-8ba2-43f0e07302ac@linaro.org> (raw)
In-Reply-To: <20250318213209.2579218-13-richard.henderson@linaro.org>
On 3/18/25 14:31, Richard Henderson wrote:
> Cache the mmu index in DisasContextBase.
> Perform the read on host endianness, which lets us
> share code with the translator_ld fast path.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> include/exec/translator.h | 1 +
> accel/tcg/translator.c | 58 ++++++++++++++++++---------------------
> 2 files changed, 28 insertions(+), 31 deletions(-)
>
> diff --git a/include/exec/translator.h b/include/exec/translator.h
> index d70942a10f..205dd85bba 100644
> --- a/include/exec/translator.h
> +++ b/include/exec/translator.h
> @@ -73,6 +73,7 @@ struct DisasContextBase {
> int max_insns;
> bool plugin_enabled;
> bool fake_insn;
> + uint8_t code_mmuidx;
> struct TCGOp *insn_start;
> void *host_addr[2];
>
> diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c
> index 157be33bf6..6fd9237298 100644
> --- a/accel/tcg/translator.c
> +++ b/accel/tcg/translator.c
> @@ -11,10 +11,10 @@
> #include "qemu/log.h"
> #include "qemu/error-report.h"
> #include "exec/exec-all.h"
> +#include "exec/cpu-ldst-common.h"
> +#include "exec/cpu-mmu-index.h"
> #include "exec/translator.h"
> -#include "exec/cpu_ldst.h"
> #include "exec/plugin-gen.h"
> -#include "exec/cpu_ldst.h"
> #include "exec/tswap.h"
> #include "tcg/tcg-op-common.h"
> #include "internal-target.h"
> @@ -142,6 +142,7 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
> db->host_addr[1] = NULL;
> db->record_start = 0;
> db->record_len = 0;
> + db->code_mmuidx = cpu_mmu_index(cpu, true);
>
> ops->init_disas_context(db, cpu);
> tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */
> @@ -457,55 +458,50 @@ bool translator_st(const DisasContextBase *db, void *dest,
>
> uint8_t translator_ldub(CPUArchState *env, DisasContextBase *db, vaddr pc)
> {
> - uint8_t raw;
> + uint8_t val;
>
> - if (!translator_ld(env, db, &raw, pc, sizeof(raw))) {
> - raw = cpu_ldub_code(env, pc);
> - record_save(db, pc, &raw, sizeof(raw));
> + if (!translator_ld(env, db, &val, pc, sizeof(val))) {
> + MemOpIdx oi = make_memop_idx(MO_UB, db->code_mmuidx);
> + val = cpu_ldb_code_mmu(env, pc, oi, 0);
> + record_save(db, pc, &val, sizeof(val));
> }
> - return raw;
> + return val;
> }
>
> uint16_t translator_lduw(CPUArchState *env, DisasContextBase *db, vaddr pc)
> {
> - uint16_t raw, tgt;
> + uint16_t val;
>
> - if (translator_ld(env, db, &raw, pc, sizeof(raw))) {
> - tgt = tswap16(raw);
> - } else {
> - tgt = cpu_lduw_code(env, pc);
> - raw = tswap16(tgt);
> - record_save(db, pc, &raw, sizeof(raw));
> + if (!translator_ld(env, db, &val, pc, sizeof(val))) {
> + MemOpIdx oi = make_memop_idx(MO_UW, db->code_mmuidx);
> + val = cpu_ldw_code_mmu(env, pc, oi, 0);
> + record_save(db, pc, &val, sizeof(val));
> }
> - return tgt;
> + return tswap16(val);
> }
>
> uint32_t translator_ldl(CPUArchState *env, DisasContextBase *db, vaddr pc)
> {
> - uint32_t raw, tgt;
> + uint32_t val;
>
> - if (translator_ld(env, db, &raw, pc, sizeof(raw))) {
> - tgt = tswap32(raw);
> - } else {
> - tgt = cpu_ldl_code(env, pc);
> - raw = tswap32(tgt);
> - record_save(db, pc, &raw, sizeof(raw));
> + if (!translator_ld(env, db, &val, pc, sizeof(val))) {
> + MemOpIdx oi = make_memop_idx(MO_UL, db->code_mmuidx);
> + val = cpu_ldl_code_mmu(env, pc, oi, 0);
> + record_save(db, pc, &val, sizeof(val));
> }
> - return tgt;
> + return tswap32(val);
> }
>
> uint64_t translator_ldq(CPUArchState *env, DisasContextBase *db, vaddr pc)
> {
> - uint64_t raw, tgt;
> + uint64_t val;
>
> - if (translator_ld(env, db, &raw, pc, sizeof(raw))) {
> - tgt = tswap64(raw);
> - } else {
> - tgt = cpu_ldq_code(env, pc);
> - raw = tswap64(tgt);
> - record_save(db, pc, &raw, sizeof(raw));
> + if (!translator_ld(env, db, &val, pc, sizeof(val))) {
> + MemOpIdx oi = make_memop_idx(MO_UQ, db->code_mmuidx);
> + val = cpu_ldq_code_mmu(env, pc, oi, 0);
> + record_save(db, pc, &val, sizeof(val));
> }
> - return tgt;
> + return tswap64(val);
> }
>
> void translator_fake_ld(DisasContextBase *db, const void *data, size_t len)
If I understand correctly, cpu_ldq_code_mmu performs the tswap call we
used to before. However, we now call it again when returning the final
value, leading to tswap(tswap(val)).
Is that expected?
next prev parent reply other threads:[~2025-03-19 0:24 UTC|newest]
Thread overview: 90+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-18 21:31 [PATCH v2 00/42] accel/tcg, codebase: Build once patches Richard Henderson
2025-03-18 21:31 ` [PATCH v2 01/42] accel/tcg: Build user-exec-stub.c once Richard Henderson
2025-03-18 21:31 ` [PATCH v2 02/42] accel/tcg: Build plugin-gen.c once Richard Henderson
2025-03-18 21:31 ` [PATCH v2 03/42] accel/tcg: Fix cpu_ld*_code_mmu for user mode Richard Henderson
2025-03-18 23:52 ` Pierrick Bouvier
2025-03-19 1:05 ` Richard Henderson
2025-03-19 1:08 ` Pierrick Bouvier
2025-03-19 1:09 ` Pierrick Bouvier
2025-03-18 21:31 ` [PATCH v2 04/42] include/exec: Use vaddr for *_mmu guest memory access routines Richard Henderson
2025-03-18 21:31 ` [PATCH v2 05/42] include/exec: Split out cpu-ldst-common.h Richard Henderson
2025-03-18 21:31 ` [PATCH v2 06/42] include/exec: Split out cpu-mmu-index.h Richard Henderson
2025-03-19 0:02 ` Pierrick Bouvier
2025-03-19 1:16 ` Richard Henderson
2025-03-19 17:16 ` Pierrick Bouvier
2025-03-20 14:58 ` Richard Henderson
2025-03-20 15:13 ` Pierrick Bouvier
2025-04-02 11:26 ` Philippe Mathieu-Daudé
2025-04-02 18:33 ` Richard Henderson
2025-04-02 20:14 ` Philippe Mathieu-Daudé
2025-03-18 21:31 ` [PATCH v2 07/42] include/exec: Inline *_mmuidx_ra memory operations Richard Henderson
2025-03-18 21:31 ` [PATCH v2 08/42] include/exec: Inline *_data_ra " Richard Henderson
2025-03-18 21:31 ` [PATCH v2 09/42] include/exec: Inline *_data " Richard Henderson
2025-04-01 6:24 ` Philippe Mathieu-Daudé
2025-04-01 17:56 ` Richard Henderson
2025-03-18 21:31 ` [PATCH v2 10/42] include/exec: Inline *_code " Richard Henderson
2025-03-18 21:31 ` [PATCH v2 11/42] accel/tcg: Perform aligned atomic reads in translator_ld Richard Henderson
2025-03-19 0:05 ` Alistair Francis
2025-03-19 0:15 ` Pierrick Bouvier
2025-03-19 1:28 ` Richard Henderson
2025-03-19 17:18 ` Pierrick Bouvier
2025-03-19 17:18 ` Pierrick Bouvier
2025-04-01 6:18 ` Philippe Mathieu-Daudé
2025-03-18 21:31 ` [PATCH v2 12/42] accel/tcg: Use cpu_ld*_code_mmu in translator.c Richard Henderson
2025-03-19 0:23 ` Pierrick Bouvier [this message]
2025-03-21 0:48 ` Richard Henderson
2025-03-21 18:03 ` Pierrick Bouvier
2025-03-18 21:31 ` [PATCH v2 13/42] accel/tcg: Implement translator_ld*_end Richard Henderson
2025-03-18 21:31 ` [PATCH v2 14/42] accel/tcg: Remove mmap_lock/unlock from watchpoint.c Richard Henderson
2025-03-18 21:31 ` [PATCH v2 15/42] include/exec: Split out mmap-lock.h Richard Henderson
2025-03-31 22:05 ` Pierrick Bouvier
2025-03-31 22:07 ` Pierrick Bouvier
2025-03-18 21:31 ` [PATCH v2 16/42] include/system: Move exec/memory.h to system/memory.h Richard Henderson
2025-03-18 21:31 ` [PATCH v2 17/42] include/system: Move exec/address-spaces.h to system/address-spaces.h Richard Henderson
2025-03-18 21:31 ` [PATCH v2 18/42] include/system: Move exec/ioport.h to system/ioport.h Richard Henderson
2025-03-18 21:31 ` [PATCH v2 19/42] include/system: Move exec/ram_addr.h to system/ram_addr.h Richard Henderson
2025-03-18 21:31 ` [PATCH v2 20/42] include/system: Move exec/ramblock.h to system/ramblock.h Richard Henderson
2025-03-18 21:31 ` [PATCH v2 21/42] accel/tcg: Remove unnecesary inclusion of memory-internal.h in cputlb.c Richard Henderson
2025-03-18 21:31 ` [PATCH v2 22/42] exec: Restrict memory-internal.h to system/ Richard Henderson
2025-03-18 21:31 ` [PATCH v2 23/42] meson: Introduce top-level libuser_ss and libsystem_ss Richard Henderson
2025-03-18 21:31 ` [PATCH v2 24/42] gdbstub: Move syscalls.c out of common_ss Richard Henderson
2025-03-18 21:31 ` [PATCH v2 25/42] accel/tcg: Use libuser_ss and libsystem_ss Richard Henderson
2025-03-18 21:31 ` [PATCH v2 26/42] semihosting: Move user-only implementation out-of-line Richard Henderson
2025-03-19 0:26 ` Pierrick Bouvier
2025-03-19 7:16 ` Philippe Mathieu-Daudé
2025-03-21 0:50 ` Richard Henderson
2025-03-31 22:01 ` Pierrick Bouvier
2025-03-18 21:31 ` [PATCH v2 27/42] target/mips: Restrict semihosting tests to system mode Richard Henderson
2025-03-19 0:26 ` Pierrick Bouvier
2025-03-18 21:31 ` [PATCH v2 28/42] target/xtensa: " Richard Henderson
2025-03-19 0:27 ` Pierrick Bouvier
2025-03-18 21:31 ` [PATCH v2 29/42] include/exec: Split out watchpoint.h Richard Henderson
2025-03-19 0:30 ` Pierrick Bouvier
2025-03-19 1:33 ` Richard Henderson
2025-03-18 21:31 ` [PATCH v2 30/42] hw/core: Move unconditional files to libsystem_ss, libuser_ss Richard Henderson
2025-03-18 21:31 ` [PATCH v2 31/42] system: Move most files to libsystem_ss Richard Henderson
2025-03-19 0:32 ` Pierrick Bouvier
2025-03-19 7:18 ` Philippe Mathieu-Daudé
2025-03-18 21:31 ` [PATCH v2 32/42] plugins: Move api.c, core.c to libuser_ss, libsystem_ss Richard Henderson
2025-03-19 0:32 ` Pierrick Bouvier
2025-03-18 21:31 ` [PATCH v2 33/42] include/exec: Drop ifndef CONFIG_USER_ONLY from cpu-common.h Richard Henderson
2025-03-18 21:31 ` [PATCH v2 34/42] include/hw/core: Drop ifndef CONFIG_USER_ONLY from cpu.h Richard Henderson
2025-03-18 21:32 ` [PATCH v2 35/42] include/hw/intc: Remove ifndef CONFIG_USER_ONLY from armv7m_nvic.h Richard Henderson
2025-03-19 0:33 ` Pierrick Bouvier
2025-03-18 21:32 ` [PATCH v2 36/42] include/hw/s390x: Remove ifndef CONFIG_USER_ONLY in css.h Richard Henderson
2025-03-18 21:32 ` [PATCH v2 37/42] include/exec: Split out icount.h Richard Henderson
2025-03-19 0:33 ` Pierrick Bouvier
2025-03-19 7:21 ` Philippe Mathieu-Daudé
2025-03-21 0:56 ` Richard Henderson
2025-03-18 21:32 ` [PATCH v2 38/42] include/exec: Protect icount_enabled from poisoned symbols Richard Henderson
2025-03-19 0:42 ` Pierrick Bouvier
2025-03-19 1:41 ` Richard Henderson
2025-03-18 21:32 ` [PATCH v2 39/42] include/system: Remove ifndef CONFIG_USER_ONLY in qtest.h Richard Henderson
2025-03-19 0:43 ` Pierrick Bouvier
2025-03-19 7:26 ` Philippe Mathieu-Daudé
2025-03-19 17:25 ` Pierrick Bouvier
2025-03-18 21:32 ` [PATCH v2 40/42] include/qemu: Remove ifndef CONFIG_USER_ONLY from accel.h Richard Henderson
2025-03-18 21:32 ` [PATCH v2 41/42] target/riscv: Remove ifndef CONFIG_USER_ONLY from cpu_cfg.h Richard Henderson
2025-03-19 1:41 ` Alistair Francis
2025-03-18 21:32 ` [PATCH v2 42/42] meson: Only allow CONFIG_USER_ONLY from certain source sets Richard Henderson
2025-03-19 0:44 ` Pierrick Bouvier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f3b98848-70b7-4ece-8ba2-43f0e07302ac@linaro.org \
--to=pierrick.bouvier@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).