* [PATCH v2] target/i386: Fix caculation of LOCK NEG eflags
@ 2022-10-22 6:12 Qi Hu
2022-10-22 9:31 ` Richard Henderson
2022-10-23 21:02 ` Philippe Mathieu-Daudé
0 siblings, 2 replies; 4+ messages in thread
From: Qi Hu @ 2022-10-22 6:12 UTC (permalink / raw)
To: Paolo Bonzini, Richard Henderson, Eduardo Habkost
Cc: qemu-devel, Jinyang Shen, Xuehai Chen
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.
---
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);
--
2.38.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] target/i386: Fix caculation of LOCK NEG eflags
2022-10-22 6:12 [PATCH v2] target/i386: Fix caculation of LOCK NEG eflags Qi Hu
@ 2022-10-22 9:31 ` Richard Henderson
2022-10-23 21:02 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 4+ messages in thread
From: Richard Henderson @ 2022-10-22 9:31 UTC (permalink / raw)
To: Qi Hu, Paolo Bonzini, Eduardo Habkost
Cc: qemu-devel, Jinyang Shen, Xuehai Chen
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);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] target/i386: Fix caculation of LOCK NEG eflags
2022-10-22 6:12 [PATCH v2] target/i386: Fix caculation of LOCK NEG eflags Qi Hu
2022-10-22 9:31 ` Richard Henderson
@ 2022-10-23 21:02 ` Philippe Mathieu-Daudé
2022-10-24 8:40 ` Qi Hu
1 sibling, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2022-10-23 21:02 UTC (permalink / raw)
To: Qi Hu, Paolo Bonzini, Richard Henderson, Eduardo Habkost
Cc: qemu-devel, Jinyang Shen, Xuehai Chen
Typo "calculation" in subject.
On 22/10/22 08: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.
> ---
> target/i386/tcg/translate.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] target/i386: Fix caculation of LOCK NEG eflags
2022-10-23 21:02 ` Philippe Mathieu-Daudé
@ 2022-10-24 8:40 ` Qi Hu
0 siblings, 0 replies; 4+ messages in thread
From: Qi Hu @ 2022-10-24 8:40 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, Paolo Bonzini, Richard Henderson,
Eduardo Habkost
Cc: qemu-devel, Jinyang Shen, Xuehai Chen
On 2022/10/24 05:02, Philippe Mathieu-Daudé wrote:
> Typo "calculation" in subject.
Thanks for the reminder. It's my fault. I will send V3 to fix this typo.
Qi
>
> On 22/10/22 08: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.
>> ---
>> target/i386/tcg/translate.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-10-24 10:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-22 6:12 [PATCH v2] target/i386: Fix caculation of LOCK NEG eflags Qi Hu
2022-10-22 9:31 ` Richard Henderson
2022-10-23 21:02 ` Philippe Mathieu-Daudé
2022-10-24 8:40 ` Qi Hu
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).