* [Qemu-devel] [PATCH for-2.12] target/arm: Don't corrupt insn_start arguments on 32-bit hosts
@ 2018-04-09 10:38 Peter Maydell
2018-04-09 22:09 ` Richard Henderson
0 siblings, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2018-04-09 10:38 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: patches, Richard Henderson, alarson, qemu-stable
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH for-2.12] target/arm: Don't corrupt insn_start arguments on 32-bit hosts
2018-04-09 10:38 [Qemu-devel] [PATCH for-2.12] target/arm: Don't corrupt insn_start arguments on 32-bit hosts Peter Maydell
@ 2018-04-09 22:09 ` Richard Henderson
2018-04-09 22:13 ` Peter Maydell
0 siblings, 1 reply; 4+ messages in thread
From: Richard Henderson @ 2018-04-09 22:09 UTC (permalink / raw)
To: Peter Maydell, qemu-arm, qemu-devel; +Cc: patches, alarson, qemu-stable
On 04/09/2018 08:38 PM, Peter Maydell wrote:
> +#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
>
Ouch, good catch.
I think we should fix this in tcg_set_insn_param instead,
as several other targets are also affected by this.
r~
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH for-2.12] target/arm: Don't corrupt insn_start arguments on 32-bit hosts
2018-04-09 22:09 ` Richard Henderson
@ 2018-04-09 22:13 ` Peter Maydell
2018-04-09 22:20 ` Richard Henderson
0 siblings, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2018-04-09 22:13 UTC (permalink / raw)
To: Richard Henderson
Cc: qemu-arm, QEMU Developers, patches@linaro.org, alarson,
qemu-stable
On 9 April 2018 at 23:09, Richard Henderson <rth@twiddle.net> wrote:
> On 04/09/2018 08:38 PM, Peter Maydell wrote:
>> +#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
>>
>
> Ouch, good catch.
>
> I think we should fix this in tcg_set_insn_param instead,
> as several other targets are also affected by this.
Are they? My grep didn't find anybody else using
tcg_set_insn_param() except the gen-icount.h code,
which isn't using target_long arguments.
If we can fix it in the tcg generic code instead that
would be nicer than an ifdef here, though.
thanks
-- PMM
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH for-2.12] target/arm: Don't corrupt insn_start arguments on 32-bit hosts
2018-04-09 22:13 ` Peter Maydell
@ 2018-04-09 22:20 ` Richard Henderson
0 siblings, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2018-04-09 22:20 UTC (permalink / raw)
To: Peter Maydell
Cc: qemu-arm, QEMU Developers, patches@linaro.org, alarson,
qemu-stable
On 04/10/2018 08:13 AM, Peter Maydell wrote:
> On 9 April 2018 at 23:09, Richard Henderson <rth@twiddle.net> wrote:
>> On 04/09/2018 08:38 PM, Peter Maydell wrote:
>>> +#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
>>>
>>
>> Ouch, good catch.
>>
>> I think we should fix this in tcg_set_insn_param instead,
>> as several other targets are also affected by this.
>
> Are they? My grep didn't find anybody else using
> tcg_set_insn_param() except the gen-icount.h code,
> which isn't using target_long arguments.
Ah, the s390 code I thought I remembered is still sitting on a branch. I shall
have to revive that for the next devel cycle...
> If we can fix it in the tcg generic code instead that
> would be nicer than an ifdef here, though.
I am working on this now.
r~
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-04-09 22:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-09 10:38 [Qemu-devel] [PATCH for-2.12] target/arm: Don't corrupt insn_start arguments on 32-bit hosts Peter Maydell
2018-04-09 22:09 ` Richard Henderson
2018-04-09 22:13 ` Peter Maydell
2018-04-09 22:20 ` Richard Henderson
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).