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 11/42] accel/tcg: Perform aligned atomic reads in translator_ld
Date: Wed, 19 Mar 2025 10:18:30 -0700 [thread overview]
Message-ID: <42b115d9-ab63-43f1-9ca8-db7c23d9fa66@linaro.org> (raw)
In-Reply-To: <20250318213209.2579218-12-richard.henderson@linaro.org>
On 3/18/25 14:31, Richard Henderson wrote:
> Perform aligned atomic reads in translator_ld, if possible.
> According to
>
> https://lore.kernel.org/qemu-devel/20240607101403.1109-1-jim.shu@sifive.com/
>
> this is required for RISC-V Ziccif.
>
> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
> ---
> accel/tcg/translator.c | 42 ++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 38 insertions(+), 4 deletions(-)
>
> diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c
> index ef1538b4fc..157be33bf6 100644
> --- a/accel/tcg/translator.c
> +++ b/accel/tcg/translator.c
> @@ -265,12 +265,14 @@ static bool translator_ld(CPUArchState *env, DisasContextBase *db,
>
> if (likely(((base ^ last) & TARGET_PAGE_MASK) == 0)) {
> /* Entire read is from the first page. */
> - memcpy(dest, host + (pc - base), len);
> - return true;
> + goto do_read;
> }
>
> if (unlikely(((base ^ pc) & TARGET_PAGE_MASK) == 0)) {
> - /* Read begins on the first page and extends to the second. */
> + /*
> + * Read begins on the first page and extends to the second.
> + * The unaligned read is never atomic.
> + */
> size_t len0 = -(pc | TARGET_PAGE_MASK);
> memcpy(dest, host + (pc - base), len0);
> pc += len0;
> @@ -329,7 +331,39 @@ static bool translator_ld(CPUArchState *env, DisasContextBase *db,
> host = db->host_addr[1];
> }
>
> - memcpy(dest, host + (pc - base), len);
> + do_read:
> + /*
> + * Assume aligned reads should be atomic, if possible.
> + * We're not in a position to jump out with EXCP_ATOMIC.
> + */
> + host += pc - base;
> + switch (len) {
> + case 2:
> + if (QEMU_IS_ALIGNED(pc, 2)) {
> + uint16_t t = qatomic_read((uint16_t *)host);
> + stw_he_p(dest, t);
> + return true;
> + }
> + break;
> + case 4:
> + if (QEMU_IS_ALIGNED(pc, 4)) {
> + uint32_t t = qatomic_read((uint32_t *)host);
> + stl_he_p(dest, t);
> + return true;
> + }
> + break;
> +#ifdef CONFIG_ATOMIC64
> + case 8:
> + if (QEMU_IS_ALIGNED(pc, 8)) {
> + uint64_t t = qatomic_read__nocheck((uint64_t *)host);
> + stq_he_p(dest, t);
> + return true;
> + }
> + break;
> +#endif
> + }
> + /* Unaligned or partial read from the second page is not atomic. */
> + memcpy(dest, host, len);
> return true;
> }
>
Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
next prev parent reply other threads:[~2025-03-19 17:19 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 [this message]
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
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=42b115d9-ab63-43f1-9ca8-db7c23d9fa66@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).