]> git.ipfire.org Git - thirdparty/qemu.git/commit
target/riscv: support atomic instruction fetch (Ziccif)
authorJim Shu <jim.shu@sifive.com>
Thu, 8 May 2025 09:48:38 +0000 (17:48 +0800)
committerAlistair Francis <alistair.francis@wdc.com>
Fri, 4 Jul 2025 11:09:48 +0000 (21:09 +1000)
commitf9eaa1542be5f7273dec1111a1e17d8ff2a5bcba
treec591eb8035aa088f4c9adc4fcb8b43fe7ef761c1
parent5ee4f21713d51fdf3d8756744ffe92365df8598b
target/riscv: support atomic instruction fetch (Ziccif)

Support 4-byte atomic instruction fetch when instruction is natural
aligned.

Current implementation is not atomic because it loads instruction twice
for first and last 2 bytes. We load 4 bytes at once to keep the
atomicity. This instruction preload method only applys when instruction
is 4-byte aligned. If instruction is unaligned, it could be across pages
so that preload will trigger additional page fault.

We encounter this issue when doing pressure test of enabling & disabling
Linux kernel ftrace. Ftrace with kernel preemption requires concurrent
modification and execution of instruction, so non-atomic instruction
fetch will cause the race condition. We may fetch the wrong instruction
which is the mixing of 2 instructions.

Also, RISC-V Profile wants to provide this feature by HW. RVA20U64
Ziccif protects the atomicity of instruction fetch when it is
natural aligned.

This commit depends on the atomic read support of translator_ld in
the commit 6a9dfe1984b0c593fb0ddb52d4e70832e6201dd6.

Signed-off-by: Jim Shu <jim.shu@sifive.com>
Reviewed-by: Frank Chang <frank.chang@sifive.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-ID: <20250508094838.19394-1-jim.shu@sifive.com>
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
target/riscv/translate.c