target/mips: Fix ll/sc after 7dd547e5ab6b31e7a0cfc182d3ad131dd55a948f
PATCH 1/1 target/mips: Fix ll/sc after 7dd547e5ab6b31e7a0cfc182d3ad131dd55a948f
From: Alex Richardson <[email protected]>
After 7dd547e5ab6b31e7a0cfc182d3ad131dd55a948f the env->llval value is loaded as an unsigned value (instead of sign-extended as before). Therefore, the CMPXCHG in gen_st_cond() in translate.c fails if the sign bit is set in the loaded value.
Fix this by sign-extending the llval value for the 32-bit case.
I discovered this issue because FreeBSD MIPS64 was looping forever in an atomic helper function when trying to start /sbin/init.
--- target/mips/op_helper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
target/mips/op_helper.c +4 -4
@@ -305,7 +305,7 @@ static inline hwaddr do_translate_address(CPUMIPSState *env, } } -#define HELPER_LD_ATOMIC (name, insn, almask) \ +#define HELPER_LD_ATOMIC (name, insn, almask, do_cast) \ target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, int mem_idx) \ { \ if (arg & almask) { \
@@ -316,12 +316,12 @@ target_ulong helper_##name(CPUMIPSState *env, target_ulong arg, int mem_idx) \ } \ env->CP0_LLAddr =do_translate_address (env, arg,0 ,GETPC ()); \ env->lladdr = arg; \ - env->llval = cpu_##insn##_mmuidx_ra(env, arg, mem_idx, GETPC()); \ + env->llval = do_cast cpu_##insn##_mmuidx_ra(env, arg, mem_idx, GETPC()); \ return env->llval; \ } -HELPER_LD_ATOMIC(ll, ldl, 0x3) +HELPER_LD_ATOMIC(ll, ldl, 0x3, (target_long)(int32_t))#ifdef TARGET_MIPS64 -HELPER_LD_ATOMIC(lld, ldq, 0x7) +HELPER_LD_ATOMIC(lld, ldq, 0x7, (target_ulong))#endif #undef HELPER_LD_ATOMIC#endif
--
2.20.1
Quoted 19 lines · James Clarke
From: Alex Richardson <[email protected]>
After
7dd547e5ab6b31e7a0cfc182d3ad131dd55a948ftheenv->llvalvalue is loaded as an unsigned value (instead of sign-extended as before). Therefore, the CMPXCHG ingen_st_cond()intranslate.cfails if the sign bit is set in the loaded value.
Fix this by sign-extending the llval value for the 32-bit case.I discovered this issue because FreeBSD MIPS64 was looping forever in an atomic helper function when trying to start
/sbin/init.Signed-off-by Alex Richardson <[email protected]>Fixes 7dd547e5ab6b ("target/mips: Use cpu_*_mmuidx_ra instead of MMU_MODE*_SUFFIX")Cc Aurelien Jarno <[email protected]>Cc Aleksandar Markovic <[email protected]>Cc Aleksandar Rikalo <[email protected]>Cc Richard Henderson <[email protected]>Signed-off-by James Clarke <[email protected]>
Quoted 3 lines
--- target/mips/op_helper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
My fault. Sorry about that.
r~
Philippe Mathieu-Daudé
Tested-byQuoted 8 lines · Richard Henderson
Quoted 7 lines · James Clarke
From: Alex Richardson <[email protected]>
After
7dd547e5ab6b31e7a0cfc182d3ad131dd55a948ftheenv->llvalvalue is loaded as an unsigned value (instead of sign-extended as before). Therefore, the CMPXCHG ingen_st_cond()intranslate.cfails if the sign bit is set in the loaded value.
Fix this by sign-extending the llval value for the 32-bit case.
Thanks!
This fix the problem I spent my Saturday debugging:
https://lists.gnu.org/archive/html/qemu-devel/2020-02/msg00071.html
Too bad we crossed by few hours, you'd have saved my Saturday.
Thomas, I think this also fixes the problem you reported here:
https://www.mail-archive.com/[email protected]/msg676025.html
Quoted 23 lines
Quoted 12 lines
I discovered this issue because FreeBSD MIPS64 was looping forever in an atomic helper function when trying to start
/sbin/init.Signed-off-by Alex Richardson <[email protected]>Fixes 7dd547e5ab6b ("target/mips: Use cpu_*_mmuidx_ra instead of MMU_MODE*_SUFFIX")Cc Aurelien Jarno <[email protected]>Cc Aleksandar Markovic <[email protected]>Cc Aleksandar Rikalo <[email protected]>Cc Richard Henderson <[email protected]>Signed-off-by James Clarke <[email protected]>Quoted 3 lines
--- target/mips/op_helper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)My fault. Sorry about that.
Reviewed-by Richard Henderson <[email protected]>r~
Aleksandar Markovic
AppliedQuoted 30 lines
From: Richard Henderson <[email protected]>
Sent: Monday, February 3, 2020 8:52 AM
To: James Clarke; [email protected]
Cc: Alex Richardson; Aurelien Jarno; Aleksandar Markovic; Aleksandar Rikalo
Subject: [EXTERNAL]Re: [PATCH] target/mips: Fix ll/sc after >7dd547e5ab6b31e7a0cfc182d3ad131dd55a948fQuoted 19 lines · James Clarke
From: Alex Richardson <[email protected]>
After
7dd547e5ab6b31e7a0cfc182d3ad131dd55a948ftheenv->llvalvalue is loaded as an unsigned value (instead of sign-extended as before). Therefore, the CMPXCHG ingen_st_cond()intranslate.cfails if the sign bit is set in the loaded value.
Fix this by sign-extending the llval value for the 32-bit case.I discovered this issue because FreeBSD MIPS64 was looping forever in an atomic helper function when trying to start
/sbin/init.Signed-off-by Alex Richardson <[email protected]>Fixes 7dd547e5ab6b ("target/mips: Use cpu_*_mmuidx_ra instead of MMU_MODE*_SUFFIX")Cc Aurelien Jarno <[email protected]>Cc Aleksandar Markovic <[email protected]>Cc Aleksandar Rikalo <[email protected]>Cc Richard Henderson <[email protected]>Signed-off-by James Clarke <[email protected]>Quoted 3 lines
--- target/mips/op_helper.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Quoted 4 lines
My fault. Sorry about that.
Reviewed-by Richard Henderson <[email protected]>
Applied to the next mips queue.
Thanks to everyone involved!!
Aleksandar
Quoted 1 line
r~