target-s390x: fix CC computation for EX instruction
PATCH 1/1 target-s390x: fix CC computation for EX instruction
Commit 7a6c7067f optimized CC computation by only saving cc_op before calling helpers as they either don't touch the CC or generate a new static value. This however doesn't work for the EX instruction as the helper changes or not the CC value depending on the actual executed instruction (e.g. MVC vs CLC).
This patches force a CC computation before calling the helper. This fixes random memory corruption occuring in guests.
--- target-s390x/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
target-s390x/translate.c +1 -1
@@ -2095,7 +2095,7 @@ static ExitStatus op_ex(DisasContext *s, DisasOps *o)TCGv_i64 tmp;update_psw_addr (s); -update_cc_op (s); +gen_op_calc_cc (s); tmp =tcg_const_i64 (s->next_pc);gen_helper_ex (cc_op, cpu_env, cc_op, o->in1, o->in2, tmp);
Signature · 1 line
2.1.4
Quoted 6 lines · Aurelien Jarno
Commit
7a6c7067foptimized CC computation by only savingcc_opbefore calling helpers as they either don't touch the CC or generate a new static value. This however doesn't work for the EX instruction as the helper changes or not the CC value depending on the actual executed instruction (e.g. MVC vs CLC).
Quoted 6 lines
This patches force a CC computation before calling the helper. This fixes random memory corruption occuring in guests.
Cc Richard Henderson <[email protected]>Cc Alexander Graf <[email protected]>Signed-off-by Aurelien Jarno <[email protected]>
Sounds plausible to me, though I'm surprised I didn't run into this myself yet.
Richard?
Alex
Quoted 17 lines
--- target-s390x/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-s390x/translate.c +1
-1@@ -2095,7 +2095,7 @@ static ExitStatus op_ex(DisasContext *s, DisasOps *o)TCGv_i64 tmp;update_psw_addr (s); -update_cc_op (s); +gen_op_calc_cc (s); tmp =tcg_const_i64 (s->next_pc);gen_helper_ex (cc_op, cpu_env, cc_op, o->in1, o->in2, tmp);
Quoted 21 lines · Aurelien Jarno
Commit
7a6c7067foptimized CC computation by only savingcc_opbefore calling helpers as they either don't touch the CC or generate a new static value. This however doesn't work for the EX instruction as the helper changes or not the CC value depending on the actual executed instruction (e.g. MVC vs CLC).This patches force a CC computation before calling the helper. This fixes random memory corruption occuring in guests.
Cc Richard Henderson <[email protected]>Cc Alexander Graf <[email protected]>Signed-off-by Aurelien Jarno <[email protected]>--- target-s390x/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-s390x/translate.c +0
-0
target-s390x/translate.c static ExitStatus op_ex(DisasContext *s, DisasOps *o) · line 2101
Quoted 8 lines
target-s390x/translate.c +1
-1@@ -2095,7 +2095,7 @@ static ExitStatus op_ex(DisasContext *s, DisasOps *o)TCGv_i64 tmp;update_psw_addr (s); -update_cc_op (s); +gen_op_calc_cc (s); tmp =tcg_const_i64 (s->next_pc);gen_helper_ex (cc_op, cpu_env, cc_op, o->in1, o->in2, tmp);
I agree this is a bug, and the right fix.
You can also remove the set_cc_static at the end of op_ex, since that's done by gen_op_calc_cc.
r~
Quoted 28 lines · Richard Henderson
Quoted 27 lines · Aurelien Jarno
Commit
7a6c7067foptimized CC computation by only savingcc_opbefore calling helpers as they either don't touch the CC or generate a new static value. This however doesn't work for the EX instruction as the helper changes or not the CC value depending on the actual executed instruction (e.g. MVC vs CLC).This patches force a CC computation before calling the helper. This fixes random memory corruption occuring in guests.
Cc Richard Henderson <[email protected]>Cc Alexander Graf <[email protected]>Signed-off-by Aurelien Jarno <[email protected]>--- target-s390x/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-s390x/translate.c +1
-1@@ -2095,7 +2095,7 @@ static ExitStatus op_ex(DisasContext *s, DisasOps *o)TCGv_i64 tmp;update_psw_addr (s); -update_cc_op (s); +gen_op_calc_cc (s);
Quoted 6 lines
target-s390x/translate.c static ExitStatus op_ex(DisasContext *s, DisasOps *o) · line 2101
Quoted 2 lines
target-s390x/translate.c +0
-0tmp =tcg_const_i64 (s->next_pc);gen_helper_ex (cc_op, cpu_env, cc_op, o->in1, o->in2, tmp);I agree this is a bug, and the right fix.
You can also remove the
set_cc_staticat the end ofop_ex, since that's done bygen_op_calc_cc.
Thanks, I applied the patch and did the change to remove set_cc_static from op_ex locally.
Alex
Quoted 31 lines · Alexander Graf
Quoted 30 lines · Richard Henderson
Quoted 21 lines · Aurelien Jarno
Commit
7a6c7067foptimized CC computation by only savingcc_opbefore calling helpers as they either don't touch the CC or generate a new static value. This however doesn't work for the EX instruction as the helper changes or not the CC value depending on the actual executed instruction (e.g. MVC vs CLC).This patches force a CC computation before calling the helper. This fixes random memory corruption occuring in guests.
Cc Richard Henderson <[email protected]>Cc Alexander Graf <[email protected]>Signed-off-by Aurelien Jarno <[email protected]>--- target-s390x/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)target-s390x/translate.c +0
-0target-s390x/translate.c static ExitStatus op_ex(DisasContext *s, DisasOps *o) · line 2099
Quoted 6 lines
target-s390x/translate.c +1
-1@@ -2095,7 +2095,7 @@ static ExitStatus op_ex(DisasContext *s, DisasOps *o)TCGv_i64 tmp;update_psw_addr (s); -update_cc_op (s); +gen_op_calc_cc (s); tmp =tcg_const_i64 (s->next_pc);gen_helper_ex (cc_op, cpu_env, cc_op, o->in1, o->in2, tmp);I agree this is a bug, and the right fix.
Quoted 5 lines
Quoted 2 lines
You can also remove the
set_cc_staticat the end ofop_ex, since that's done bygen_op_calc_cc.Thanks, I applied the patch and did the change to remove
set_cc_staticfromop_exlocally.
Thanks!
Aurelien
Signature · 2 lines
Aurelien Jarno GPG: 4096R/1DDD8C9B [email protected] http://www.aurel32.net