From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: edgar.iglesias@xilinx.com, Thomas Huth <thuth@redhat.com>,
f4bug@amsat.org
Subject: [PATCH v3 01/19] target/microblaze: Collected fixes for env->iflags
Date: Fri, 4 Sep 2020 12:08:24 -0700 [thread overview]
Message-ID: <20200904190842.2282109-2-richard.henderson@linaro.org> (raw)
In-Reply-To: <20200904190842.2282109-1-richard.henderson@linaro.org>
There are several problems here that can result in soft lockup,
depending on exactly where an interrupt or exception is delivered:
Include BIMM_FLAG in IFLAGS_TB_MASK, since it needs to follow D_FLAG.
Ensure that iflags is 0 when entering an interrupt/exception handler.
Add mb_cpu_synchronize_from_tb to restore iflags from tb->flags.
The change to t_sync_flags is cosmetic, but makes the code clearer.
This fixes the reported regression in acceptance/replay_kernel.py.
Fixes: 683a247ed7a4 ("target/microblaze: Store "current" iflags in insn_start")
Tested-by: Thomas Huth <thuth@redhat.com>
Reported-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
target/microblaze/cpu.h | 3 ++-
target/microblaze/cpu.c | 11 +++++++++++
target/microblaze/helper.c | 17 +++++++++++------
target/microblaze/translate.c | 4 ++--
4 files changed, 26 insertions(+), 9 deletions(-)
diff --git a/target/microblaze/cpu.h b/target/microblaze/cpu.h
index d11b6fa995..a25a2b427f 100644
--- a/target/microblaze/cpu.h
+++ b/target/microblaze/cpu.h
@@ -270,7 +270,8 @@ struct CPUMBState {
#define D_FLAG (1 << 19) /* Bit in ESR. */
/* TB dependent CPUMBState. */
-#define IFLAGS_TB_MASK (D_FLAG | IMM_FLAG | DRTI_FLAG | DRTE_FLAG | DRTB_FLAG)
+#define IFLAGS_TB_MASK (D_FLAG | BIMM_FLAG | IMM_FLAG | \
+ DRTI_FLAG | DRTE_FLAG | DRTB_FLAG)
#define MSR_TB_MASK (MSR_UM | MSR_VM | MSR_EE)
uint32_t iflags;
diff --git a/target/microblaze/cpu.c b/target/microblaze/cpu.c
index 67017ecc33..6392524135 100644
--- a/target/microblaze/cpu.c
+++ b/target/microblaze/cpu.c
@@ -80,6 +80,16 @@ static void mb_cpu_set_pc(CPUState *cs, vaddr value)
MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
cpu->env.pc = value;
+ /* Ensure D_FLAG and IMM_FLAG are clear for the new PC */
+ cpu->env.iflags = 0;
+}
+
+static void mb_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb)
+{
+ MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
+
+ cpu->env.pc = tb->pc;
+ cpu->env.iflags = tb->flags & IFLAGS_TB_MASK;
}
static bool mb_cpu_has_work(CPUState *cs)
@@ -321,6 +331,7 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data)
cc->cpu_exec_interrupt = mb_cpu_exec_interrupt;
cc->dump_state = mb_cpu_dump_state;
cc->set_pc = mb_cpu_set_pc;
+ cc->synchronize_from_tb = mb_cpu_synchronize_from_tb;
cc->gdb_read_register = mb_cpu_gdb_read_register;
cc->gdb_write_register = mb_cpu_gdb_write_register;
cc->tlb_fill = mb_cpu_tlb_fill;
diff --git a/target/microblaze/helper.c b/target/microblaze/helper.c
index 48547385b0..00090526da 100644
--- a/target/microblaze/helper.c
+++ b/target/microblaze/helper.c
@@ -113,7 +113,10 @@ void mb_cpu_do_interrupt(CPUState *cs)
uint32_t t, msr = mb_cpu_read_msr(env);
/* IMM flag cannot propagate across a branch and into the dslot. */
- assert(!((env->iflags & D_FLAG) && (env->iflags & IMM_FLAG)));
+ assert((env->iflags & (D_FLAG | IMM_FLAG)) != (D_FLAG | IMM_FLAG));
+ /* BIMM flag cannot be set without D_FLAG. */
+ assert((env->iflags & (D_FLAG | BIMM_FLAG)) != BIMM_FLAG);
+ /* RTI flags are private to translate. */
assert(!(env->iflags & (DRTI_FLAG | DRTE_FLAG | DRTB_FLAG)));
env->res_addr = RES_ADDR_NONE;
switch (cs->exception_index) {
@@ -146,7 +149,7 @@ void mb_cpu_do_interrupt(CPUState *cs)
env->pc, env->ear,
env->esr, env->iflags);
log_cpu_state_mask(CPU_LOG_INT, cs, 0);
- env->iflags &= ~(IMM_FLAG | D_FLAG);
+ env->iflags = 0;
env->pc = cpu->cfg.base_vectors + 0x20;
break;
@@ -186,14 +189,14 @@ void mb_cpu_do_interrupt(CPUState *cs)
"exception at pc=%x ear=%" PRIx64 " iflags=%x\n",
env->pc, env->ear, env->iflags);
log_cpu_state_mask(CPU_LOG_INT, cs, 0);
- env->iflags &= ~(IMM_FLAG | D_FLAG);
+ env->iflags = 0;
env->pc = cpu->cfg.base_vectors + 0x20;
break;
case EXCP_IRQ:
assert(!(msr & (MSR_EIP | MSR_BIP)));
assert(msr & MSR_IE);
- assert(!(env->iflags & D_FLAG));
+ assert(!(env->iflags & (D_FLAG | IMM_FLAG)));
t = (msr & (MSR_VM | MSR_UM)) << 1;
@@ -226,13 +229,14 @@ void mb_cpu_do_interrupt(CPUState *cs)
mb_cpu_write_msr(env, msr);
env->regs[14] = env->pc;
+ env->iflags = 0;
env->pc = cpu->cfg.base_vectors + 0x10;
//log_cpu_state_mask(CPU_LOG_INT, cs, 0);
break;
case EXCP_HW_BREAK:
- assert(!(env->iflags & IMM_FLAG));
- assert(!(env->iflags & D_FLAG));
+ assert(!(env->iflags & (D_FLAG | IMM_FLAG)));
+
t = (msr & (MSR_VM | MSR_UM)) << 1;
qemu_log_mask(CPU_LOG_INT,
"break at pc=%x msr=%x %x iflags=%x\n",
@@ -242,6 +246,7 @@ void mb_cpu_do_interrupt(CPUState *cs)
msr |= t;
msr |= MSR_BIP;
env->regs[16] = env->pc;
+ env->iflags = 0;
env->pc = cpu->cfg.base_vectors + 0x18;
mb_cpu_write_msr(env, msr);
break;
diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c
index a377818b5e..a8a3249185 100644
--- a/target/microblaze/translate.c
+++ b/target/microblaze/translate.c
@@ -91,8 +91,8 @@ static int typeb_imm(DisasContext *dc, int x)
static void t_sync_flags(DisasContext *dc)
{
/* Synch the tb dependent flags between translator and runtime. */
- if ((dc->tb_flags ^ dc->base.tb->flags) & ~MSR_TB_MASK) {
- tcg_gen_movi_i32(cpu_iflags, dc->tb_flags & ~MSR_TB_MASK);
+ if ((dc->tb_flags ^ dc->base.tb->flags) & IFLAGS_TB_MASK) {
+ tcg_gen_movi_i32(cpu_iflags, dc->tb_flags & IFLAGS_TB_MASK);
}
}
--
2.25.1
next prev parent reply other threads:[~2020-09-04 19:09 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-04 19:08 [PATCH v3 00/19] target/microblaze improvements Richard Henderson
2020-09-04 19:08 ` Richard Henderson [this message]
2020-09-04 19:08 ` [PATCH v3 02/19] target/microblaze: Renumber D_FLAG Richard Henderson
2020-09-04 19:08 ` [PATCH v3 03/19] target/microblaze: Cleanup mb_cpu_do_interrupt Richard Henderson
2020-09-04 19:08 ` [PATCH v3 04/19] target/microblaze: Rename mmu structs Richard Henderson
2020-09-04 19:08 ` [PATCH v3 05/19] target/microblaze: Rename DISAS_UPDATE to DISAS_EXIT Richard Henderson
2020-09-04 19:08 ` [PATCH v3 06/19] target/microblaze: Introduce DISAS_EXIT_NEXT, DISAS_EXIT_JUMP Richard Henderson
2020-09-04 19:08 ` [PATCH v3 07/19] target/microblaze: Replace cpustate_changed with DISAS_EXIT_NEXT Richard Henderson
2020-09-04 19:08 ` [PATCH v3 08/19] target/microblaze: Handle DISAS_EXIT_NEXT in delay slot Richard Henderson
2020-09-04 19:08 ` [PATCH v3 09/19] target/microblaze: Force rtid, rted, rtbd to exit Richard Henderson
2020-09-04 19:08 ` [PATCH v3 10/19] target/microblaze: Use tcg_gen_lookup_and_goto_ptr Richard Henderson
2020-09-04 19:08 ` [PATCH v3 11/19] target/microblaze: Diagnose invalid insns in delay slots Richard Henderson
2020-09-04 19:08 ` [PATCH v3 12/19] target/microblaze: Split out MicroBlazeCPUConfig Richard Henderson
2020-09-05 21:35 ` Philippe Mathieu-Daudé
2020-09-04 19:08 ` [PATCH v3 13/19] target/microblaze: Reorg MicroBlazeCPUConfig to minimize holes Richard Henderson
2020-09-05 21:36 ` Philippe Mathieu-Daudé
2020-09-04 19:08 ` [PATCH v3 14/19] target/microblaze: Move pvr regs to MicroBlazeCPUConfig Richard Henderson
2020-09-05 21:39 ` Philippe Mathieu-Daudé
2020-09-04 19:08 ` [PATCH v3 15/19] target/microblaze: Treat pvr_regs as constant Richard Henderson
2020-09-04 19:08 ` [PATCH v3 16/19] target/microblaze: Move mmu parameters to MicroBlazeCPUConfig Richard Henderson
2020-09-05 21:41 ` Philippe Mathieu-Daudé
2020-09-04 19:08 ` [PATCH v3 17/19] target/microblaze: Fill in VMStateDescription for cpu Richard Henderson
2020-09-04 19:08 ` [PATCH v3 18/19] target/microblaze: Put MicroBlazeCPUConfig into DisasContext Richard Henderson
2020-09-05 21:42 ` Philippe Mathieu-Daudé
2020-09-04 19:08 ` [PATCH v3 19/19] configure: Do not set TARGET_ABI32 for microblaze Richard Henderson
2020-09-07 9:20 ` [PATCH v3 00/19] target/microblaze improvements Edgar E. Iglesias
2020-09-07 17:43 ` Richard Henderson
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=20200904190842.2282109-2-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=edgar.iglesias@xilinx.com \
--cc=f4bug@amsat.org \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
/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).