qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] target/riscv: Exit current TB after an sfence.vma
@ 2022-03-15 19:23 Idan Horowitz
  2022-03-15 19:37 ` Richard Henderson
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Idan Horowitz @ 2022-03-15 19:23 UTC (permalink / raw)
  To: qemu-riscv
  Cc: Alistair Francis, Bin Meng, Palmer Dabbelt, qemu-devel,
	Idan Horowitz

If the pages which control the translation of the currently executing
instructions are changed, and then the TLB is flushed using sfence.vma
we have to exit the current TB early, to ensure we don't execute stale
instructions.

Signed-off-by: Idan Horowitz <idan.horowitz@gmail.com>
---
 target/riscv/insn_trans/trans_privileged.c.inc | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc
index 53613682e8..f265e8202d 100644
--- a/target/riscv/insn_trans/trans_privileged.c.inc
+++ b/target/riscv/insn_trans/trans_privileged.c.inc
@@ -114,6 +114,13 @@ static bool trans_sfence_vma(DisasContext *ctx, arg_sfence_vma *a)
 {
 #ifndef CONFIG_USER_ONLY
     gen_helper_tlb_flush(cpu_env);
+    /*
+     * The flush might have changed the backing physical memory of
+     * the instructions we're currently executing
+     */
+    gen_set_pc_imm(ctx, ctx->pc_succ_insn);
+    tcg_gen_exit_tb(NULL, 0);
+    ctx->base.is_jmp = DISAS_NORETURN;
     return true;
 #endif
     return false;
-- 
2.35.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread
[parent not found: <7f383fc2.81a2.17f93c0dad7.Coremail.phantom@zju.edu.cn>]

end of thread, other threads:[~2022-03-30  7:44 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-15 19:23 [PATCH] target/riscv: Exit current TB after an sfence.vma Idan Horowitz
2022-03-15 19:37 ` Richard Henderson
2022-03-15 22:52 ` Alistair Francis
2022-03-15 23:42 ` Alistair Francis
2022-03-30  6:09   ` Alistair Francis
     [not found] <7f383fc2.81a2.17f93c0dad7.Coremail.phantom@zju.edu.cn>
2022-03-29 23:15 ` Atish Patra
2022-03-30  6:15   ` Idan Horowitz
2022-03-30  7:28     ` Atish Patra
2022-03-30  7:35       ` Idan Horowitz

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).