[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 68/78] target/ppc: Fix mtmsr(d) L=1 variant that loses interrupts
From: |
Michael Roth |
Subject: |
[PATCH 68/78] target/ppc: Fix mtmsr(d) L=1 variant that loses interrupts |
Date: |
Tue, 16 Jun 2020 09:15:37 -0500 |
From: Nicholas Piggin <npiggin@gmail.com>
If mtmsr L=1 sets MSR[EE] while there is a maskable exception pending,
it does not cause an interrupt. This causes the test case to hang:
https://lists.gnu.org/archive/html/qemu-ppc/2019-10/msg00826.html
More recently, Linux reduced the occurance of operations (e.g., rfi)
which stop translation and allow pending interrupts to be processed.
This started causing hangs in Linux boot in long-running kernel tests,
running with '-d int' shows the decrementer stops firing despite DEC
wrapping and MSR[EE]=1.
https://lists.ozlabs.org/pipermail/linuxppc-dev/2020-April/208301.html
The cause is the broken mtmsr L=1 behaviour, which is contrary to the
architecture. From Power ISA v3.0B, p.977, Move To Machine State Register,
Programming Note states:
If MSR[EE]=0 and an External, Decrementer, or Performance Monitor
exception is pending, executing an mtmsrd instruction that sets
MSR[EE] to 1 will cause the interrupt to occur before the next
instruction is executed, if no higher priority exception exists
Fix this by handling L=1 exactly the same way as L=0, modulo the MSR
bits altered.
The confusion arises from L=0 being "context synchronizing" whereas L=1
is "execution synchronizing", which is a weaker semantic. However this
is not a relaxation of the requirement that these exceptions cause
interrupts when MSR[EE]=1 (e.g., when mtmsr executes to completion as
TCG is doing here), rather it specifies how a pipelined processor can
have multiple instructions in flight where one may influence how another
behaves.
Cc: qemu-stable@nongnu.org
Reported-by: Anton Blanchard <anton@ozlabs.org>
Reported-by: Nathan Chancellor <natechancellor@gmail.com>
Tested-by: Nathan Chancellor <natechancellor@gmail.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Message-Id: <20200414111131.465560-1-npiggin@gmail.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Tested-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
(cherry picked from commit 5ed195065cc6895f61b9d59bfa0a0536ed5ed51e)
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
target/ppc/translate.c | 46 +++++++++++++++++++++++++-----------------
1 file changed, 27 insertions(+), 19 deletions(-)
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
index f87f6eeaf7..4f5008ed6f 100644
--- a/target/ppc/translate.c
+++ b/target/ppc/translate.c
@@ -4361,30 +4361,34 @@ static void gen_mtmsrd(DisasContext *ctx)
CHK_SV;
#if !defined(CONFIG_USER_ONLY)
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
if (ctx->opcode & 0x00010000) {
- /* Special form that does not need any synchronisation */
+ /* L=1 form only updates EE and RI */
TCGv t0 = tcg_temp_new();
+ TCGv t1 = tcg_temp_new();
tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)],
(1 << MSR_RI) | (1 << MSR_EE));
- tcg_gen_andi_tl(cpu_msr, cpu_msr,
+ tcg_gen_andi_tl(t1, cpu_msr,
~(target_ulong)((1 << MSR_RI) | (1 << MSR_EE)));
- tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
+ tcg_gen_or_tl(t1, t1, t0);
+
+ gen_helper_store_msr(cpu_env, t1);
tcg_temp_free(t0);
+ tcg_temp_free(t1);
+
} else {
/*
* XXX: we need to update nip before the store if we enter
* power saving mode, we will exit the loop directly from
* ppc_store_msr
*/
- if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
- gen_io_start();
- }
gen_update_nip(ctx, ctx->base.pc_next);
gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]);
- /* Must stop the translation as machine state (may have) changed */
- /* Note that mtmsr is not always defined as context-synchronizing */
- gen_stop_exception(ctx);
}
+ /* Must stop the translation as machine state (may have) changed */
+ gen_stop_exception(ctx);
#endif /* !defined(CONFIG_USER_ONLY) */
}
#endif /* defined(TARGET_PPC64) */
@@ -4394,15 +4398,23 @@ static void gen_mtmsr(DisasContext *ctx)
CHK_SV;
#if !defined(CONFIG_USER_ONLY)
- if (ctx->opcode & 0x00010000) {
- /* Special form that does not need any synchronisation */
+ if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
+ gen_io_start();
+ }
+ if (ctx->opcode & 0x00010000) {
+ /* L=1 form only updates EE and RI */
TCGv t0 = tcg_temp_new();
+ TCGv t1 = tcg_temp_new();
tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)],
(1 << MSR_RI) | (1 << MSR_EE));
- tcg_gen_andi_tl(cpu_msr, cpu_msr,
+ tcg_gen_andi_tl(t1, cpu_msr,
~(target_ulong)((1 << MSR_RI) | (1 << MSR_EE)));
- tcg_gen_or_tl(cpu_msr, cpu_msr, t0);
+ tcg_gen_or_tl(t1, t1, t0);
+
+ gen_helper_store_msr(cpu_env, t1);
tcg_temp_free(t0);
+ tcg_temp_free(t1);
+
} else {
TCGv msr = tcg_temp_new();
@@ -4411,9 +4423,6 @@ static void gen_mtmsr(DisasContext *ctx)
* power saving mode, we will exit the loop directly from
* ppc_store_msr
*/
- if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) {
- gen_io_start();
- }
gen_update_nip(ctx, ctx->base.pc_next);
#if defined(TARGET_PPC64)
tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32);
@@ -4422,10 +4431,9 @@ static void gen_mtmsr(DisasContext *ctx)
#endif
gen_helper_store_msr(cpu_env, msr);
tcg_temp_free(msr);
- /* Must stop the translation as machine state (may have) changed */
- /* Note that mtmsr is not always defined as context-synchronizing */
- gen_stop_exception(ctx);
}
+ /* Must stop the translation as machine state (may have) changed */
+ gen_stop_exception(ctx);
#endif
}
--
2.17.1
- [PATCH 59/78] qga-win: Handle VSS_E_PROVIDER_ALREADY_REGISTERED error, (continued)
- [PATCH 59/78] qga-win: Handle VSS_E_PROVIDER_ALREADY_REGISTERED error, Michael Roth, 2020/06/16
- [PATCH 60/78] qga-win: prevent crash when executing guest-file-read with large count, Michael Roth, 2020/06/16
- [PATCH 05/78] target/arm: ensure we use current exception state after SCR update, Michael Roth, 2020/06/16
- [PATCH 61/78] qga: Fix undefined C behavior, Michael Roth, 2020/06/16
- [PATCH 62/78] qemu-ga: document vsock-listen in the man page, Michael Roth, 2020/06/16
- [PATCH 63/78] hw/i386/amd_iommu.c: Fix corruption of log events passed to guest, Michael Roth, 2020/06/16
- [PATCH 64/78] tcg/i386: Fix INDEX_op_dup2_vec, Michael Roth, 2020/06/16
- [PATCH 65/78] dump: Fix writing of ELF section, Michael Roth, 2020/06/16
- [PATCH 66/78] xen-block: Fix double qlist remove and request leak, Michael Roth, 2020/06/16
- [PATCH 67/78] vhost-user-gpu: Release memory returned by vu_queue_pop() with free(), Michael Roth, 2020/06/16
- [PATCH 68/78] target/ppc: Fix mtmsr(d) L=1 variant that loses interrupts,
Michael Roth <=
- [PATCH 69/78] hostmem: don't use mbind() if host-nodes is empty, Michael Roth, 2020/06/16
- [PATCH 70/78] target/arm: Clear tail in gvec_fmul_idx_*, gvec_fmla_idx_*, Michael Roth, 2020/06/16
- [PATCH 06/78] block: Activate recursively even for already active nodes, Michael Roth, 2020/06/16
- [PATCH 71/78] qemu-nbd: Close inherited stderr, Michael Roth, 2020/06/16
- [PATCH 72/78] 9p: Lock directory streams with a CoMutex, Michael Roth, 2020/06/16