From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-arm@nongnu.org, qemu-devel@nongnu.org
Cc: patches@linaro.org, Richard Henderson <rth@twiddle.net>,
alarson@ddci.com, qemu-stable@nongnu.org
Subject: [Qemu-devel] [PATCH for-2.12] target/arm: Don't corrupt insn_start arguments on 32-bit hosts
Date: Mon, 9 Apr 2018 11:38:34 +0100 [thread overview]
Message-ID: <20180409103834.11285-1-peter.maydell@linaro.org> (raw)
For the Arm target, we have a 3-operand tcg_insn_start,
where the 3 arguments are the PC, condexec bits, and
a syndrome value. We set it up like this:
tcg_gen_insn_start(dc->pc,
(dc->condexec_cond << 4) | (dc->condexec_mask >> 1),
0);
dc->insn_start = tcg_last_op();
and then we patch in the 3rd operand later in disas_set_insn_syndrome():
tcg_set_insn_param(s->insn_start, 2, syn);
Unfortunately, if we're running on a setup where
TARGET_LONG_BITS > TCG_TARGET_REG_BITS (ie 64 bit guest
on 32 bit host), tcg_gen_insn_start() has under the hood
split the 3 operands we gave it into 6, and so we end
up patching a syndrome value into the condexec bits.
This means we'll end up with corrupted guest condexec
state if we have to do a cpu_restore_state(), which happens
often when using icount and occasionally for load/store
instructions that fault.
Fix the bug by using the correct operand offset for the
64-on-32 case.
Cc: qemu-stable@nongnu.org
Reported-by: alarson@ddci.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
This doesn't apply as-is to the stable branch, but the
difference is minor (insn_start was insn_start_idx, but
the 2 vs 4 for argument 2 is still the same.)
---
target/arm/translate.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/target/arm/translate.h b/target/arm/translate.h
index c47febf99d..f04ece9cfd 100644
--- a/target/arm/translate.h
+++ b/target/arm/translate.h
@@ -120,7 +120,15 @@ static inline void disas_set_insn_syndrome(DisasContext *s, uint32_t syn)
/* We check and clear insn_start_idx to catch multiple updates. */
assert(s->insn_start != NULL);
+#if TARGET_LONG_BITS <= TCG_TARGET_REG_BITS
tcg_set_insn_param(s->insn_start, 2, syn);
+#else
+ /* tcg_gen_insn_start has split every target_ulong argument to
+ * op_insn_start into two 32-bit arguments, so we want the low
+ * half of the 3rd argument, which is at index 4.
+ */
+ tcg_set_insn_param(s->insn_start, 4, syn);
+#endif
s->insn_start = NULL;
}
--
2.16.2
next reply other threads:[~2018-04-09 10:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-09 10:38 Peter Maydell [this message]
2018-04-09 22:09 ` [Qemu-devel] [PATCH for-2.12] target/arm: Don't corrupt insn_start arguments on 32-bit hosts Richard Henderson
2018-04-09 22:13 ` Peter Maydell
2018-04-09 22:20 ` 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=20180409103834.11285-1-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=alarson@ddci.com \
--cc=patches@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=rth@twiddle.net \
/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).