From: Richard Henderson <richard.henderson@linaro.org>
To: Qi Hu <huqi@loongson.cn>, Paolo Bonzini <pbonzini@redhat.com>,
Eduardo Habkost <eduardo@habkost.net>
Cc: qemu-devel@nongnu.org, Jinyang Shen <shenjinyang@loongson.cn>,
Xuehai Chen <chenxuehai@loongson.cn>
Subject: Re: [PATCH v2] target/i386: Fix caculation of LOCK NEG eflags
Date: Sat, 22 Oct 2022 19:31:08 +1000 [thread overview]
Message-ID: <ff582518-668a-91b6-d9c9-01ba290f9f86@linaro.org> (raw)
In-Reply-To: <20221022061216.423098-1-huqi@loongson.cn>
On 10/22/22 16:12, Qi Hu wrote:
> In sequence:
> ---
> lock negl -0x14(%rbp)
> pushf
> pop %rax
> ---
>
> %rax will obtain the wrong value becasue the "lock neg" caculates the
> wrong eflags. The "s->T0" is updated by the wrong value.
>
> You can use this to do some test:
> ---
> #include <assert.h>
>
> int main()
> {
> __volatile__ unsigned test = 0x2363a;
> __volatile__ char cond = 0;
> asm(
> "lock negl %0 \n\t"
> "sets %1"
> : "=m"(test), "=r"(cond)
> :
> :);
> assert(cond & 1);
> return 0;
> }
> ---
>
> Reported-by: Jinyang Shen <shenjinyang@loongson.cn>
> Co-Developed-by: Xuehai Chen <chenxuehai@loongson.cn>
> Signed-off-by: Xuehai Chen <chenxuehai@loongson.cn>
> Signed-off-by: Qi Hu <huqi@loongson.cn>
> ---
> V1 -> V2:
> Following Richard's suggestion, just change mov to neg instead of using
> local_tmp.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
r~
> ---
> target/i386/tcg/translate.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
> index e19d5c1c64..cec2182080 100644
> --- a/target/i386/tcg/translate.c
> +++ b/target/i386/tcg/translate.c
> @@ -3299,7 +3299,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
>
> tcg_temp_free(t2);
> tcg_temp_free(a0);
> - tcg_gen_mov_tl(s->T0, t0);
> + tcg_gen_neg_tl(s->T0, t0);
> tcg_temp_free(t0);
> } else {
> tcg_gen_neg_tl(s->T0, s->T0);
next prev parent reply other threads:[~2022-10-22 9:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-22 6:12 [PATCH v2] target/i386: Fix caculation of LOCK NEG eflags Qi Hu
2022-10-22 9:31 ` Richard Henderson [this message]
2022-10-23 21:02 ` Philippe Mathieu-Daudé
2022-10-24 8:40 ` Qi Hu
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=ff582518-668a-91b6-d9c9-01ba290f9f86@linaro.org \
--to=richard.henderson@linaro.org \
--cc=chenxuehai@loongson.cn \
--cc=eduardo@habkost.net \
--cc=huqi@loongson.cn \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=shenjinyang@loongson.cn \
/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).