target/sparc: Handle FPRS correctly on big-endian hosts
PATCH v2 1/1 target/sparc: Handle FPRS correctly on big-endian hosts
In CPUSparcState we define the fprs field as uint64_t. However we then refer to it in translate.c via a TCGv_i32 which we set up with tcg_global_mem_new_ptr(). This means that on a big-endian host when the guest does something to writo te the FPRS register this value ends up in the wrong half of the uint64_t, and the QEMU C code that refers to env->fprs sees the wrong value. The effect of this is that guest code that enables the FPU crashes with spurious FPU Disabled exceptions. In particular, this is why
tests/avocado/machine_sparc64_sun4u.py:Sun4uMachine.test_sparc64_sun4u
times out on an s390 host.
There are multiple ways we could fix this; since there are actually only three bits in the FPRS register and the code in translate.c would be a bit painful to convert to dealing with a TCGv_i64, change the type of the CPU state struct field to match what translate.c is expecting.
(None of the other fields referenced by the r32[] array in sparc_tcg_init() have the wrong type.)
---
Changes v1->v2:
* drop unnecessary change to gdbstub.c
* put the vmstate fields the correct way around
NB: I believe the vmstate changes to be correct, but sparc64 seems unable to successfully do a savevm/loadvm even before this change due to some other bug (the guest kernel panics immediately after the loadvm).
--- target/sparc/cpu.h | 2 +- target/sparc/cpu.c | 4 ++-- target/sparc/machine.c | 3 ++- target/sparc/monitor.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-)
target/sparc/cpu.h +1 -1
@@ -521,7 +521,7 @@ struct CPUArchState {uint64_t igregs[8 ];/* interrupt general registers */ uint64_t mgregs[8 ];/* mmu general registers */ uint64_t glregs[8 *MAXTL_MAX ]; -uint64_t fprs; +uint32_t fprs;uint64_t tick_cmpr, stick_cmpr;CPUTimer *tick, *stick;#define TICK_NPT_MASK 0x8000000000000000ULL
target/sparc/cpu.c +2 -2
@@ -673,8 +673,8 @@ static void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags)"cleanwin: %d cwp: %d\n" , env->cansave, env->canrestore, env->otherwin, env->wstate, env->cleanwin, env->nwindows - 1 - env->cwp); -qemu_fprintf (f,"fsr: " TARGET_FMT_lx" y: " TARGET_FMT_lx" fprs: " - TARGET_FMT_lx"\n" , env->fsr, env->y, env->fprs); +qemu_fprintf (f,"fsr: " TARGET_FMT_lx" y: " TARGET_FMT_lx" fprs: %016x\n" , + env->fsr, env->y, env->fprs);#else qemu_fprintf (f,"psr: %08x (icc: " ,cpu_get_psr (env));
target/sparc/machine.c +2 -1
@@ -168,7 +168,8 @@ const VMStateDescription vmstate_sparc_cpu = {VMSTATE_UINT64_ARRAY (env.bgregs,SPARCCPU ,8 ),VMSTATE_UINT64_ARRAY (env.igregs,SPARCCPU ,8 ),VMSTATE_UINT64_ARRAY (env.mgregs,SPARCCPU ,8 ), -VMSTATE_UINT64 (env.fprs,SPARCCPU ), +VMSTATE_UNUSED (4 ),/* was unused high half of uint64_t fprs */ +VMSTATE_UINT32 (env.fprs,SPARCCPU ),VMSTATE_UINT64 (env.tick_cmpr,SPARCCPU ),VMSTATE_UINT64 (env.stick_cmpr,SPARCCPU ), VMSTATE_CPU_TIMER(env.tick, SPARCCPU),
target/sparc/monitor.c +1 -1
@@ -154,7 +154,7 @@ const MonitorDef monitor_defs[] = { { "otherwin", offsetof(CPUSPARCState, otherwin) }, { "wstate", offsetof(CPUSPARCState, wstate) }, { "cleanwin", offsetof(CPUSPARCState, cleanwin) }, - { "fprs", offsetof(CPUSPARCState, fprs) }, + { "fprs", offsetof(CPUSPARCState, fprs), NULL, MD_I32 }, #endif { NULL }, };
Signature · 1 line
2.34.1
Quoted 30 lines · Peter Maydell
In CPUSparcState we define the fprs field as
uint64_t. However we then refer to it intranslate.cvia aTCGv_i32which we set up withtcg_global_mem_new_ptr(). This means that on a big-endian host when the guest does something to writo te the FPRS register this value ends up in the wrong half of theuint64_t, and the QEMU C code that refers toenv->fprssees the wrong value. The effect of this is that guest code that enables the FPU crashes with spurious FPU Disabled exceptions. In particular, this is why
tests/avocado/machine_sparc64_sun4u.py:Sun4uMachine.test_sparc64_sun4u
times out on an s390 host.There are multiple ways we could fix this; since there are actually only three bits in the FPRS register and the code in
translate.cwould be a bit painful to convert to dealing with aTCGv_i64, change the type of the CPU state struct field to match whattranslate.cis expecting.(None of the other fields referenced by the r32[] array in
sparc_tcg_init()have the wrong type.)Signed-off-by Peter Maydell <[email protected]>---
Changesv1->v2:
* drop unnecessary change togdbstub.c
* put the vmstate fields the correct way aroundNB: I believe the vmstate changes to be correct, but sparc64 seems unable to successfully do a savevm/loadvm even before this change due to some other bug (the guest kernel panics immediately after the loadvm).
Quoted 6 lines
--- target/sparc/cpu.h | 2 +- target/sparc/cpu.c | 4 ++-- target/sparc/machine.c | 3 ++- target/sparc/monitor.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-)
Quoted 5 lines · Philippe Mathieu-Daudé
Quoted 4 lines · Peter Maydell
In CPUSparcState we define the fprs field as uint64_t. However we then refer to it in
translate.cvia aTCGv_i32which we set up with tcg_global_mem_new_ptr(). This means that on a big-endian host when the guest does something to writo te the FPRS register this value
(typo around "write")
Quoted 35 lines
Quoted 31 lines
ends up in the wrong half of the
uint64_t, and the QEMU C code that refers toenv->fprssees the wrong value. The effect of this is that guest code that enables the FPU crashes with spurious FPU Disabled exceptions. In particular, this is why tests/avocado/machine_sparc64_sun4u.py:Sun4uMachine.test_sparc64_sun4u times out on an s390 host.There are multiple ways we could fix this; since there are actually only three bits in the FPRS register and the code in
translate.cwould be a bit painful to convert to dealing with aTCGv_i64, change the type of the CPU state struct field to match whattranslate.cis expecting.(None of the other fields referenced by the r32[] array in
sparc_tcg_init()have the wrong type.)Signed-off-by Peter Maydell <[email protected]>---
Changesv1->v2:
* drop unnecessary change togdbstub.c
* put the vmstate fields the correct way aroundNB: I believe the vmstate changes to be correct, but sparc64 seems unable to successfully do a savevm/loadvm even before this change due to some other bug (the guest kernel panics immediately after the loadvm).
---
target/sparc/cpu.h | 2 +-
target/sparc/cpu.c | 4 ++--target/sparc/machine.c| 3 ++-target/sparc/monitor.c| 2 +-Quoted 1 line
4 files changed, 6 insertions(+), 5 deletions(-)Reviewed-by Philippe Mathieu-Daudé <[email protected]>
Quoted 9 lines · Philippe Mathieu-Daudé
Quoted 5 lines · Philippe Mathieu-Daudé
Quoted 4 lines · Peter Maydell
In CPUSparcState we define the fprs field as
uint64_t. However we then refer to it intranslate.cvia aTCGv_i32which we set up withtcg_global_mem_new_ptr(). This means that on a big-endian host when the guest does something to writo te the FPRS register this value(typo around "write")
Yes, should be "write to" but somehow I managed to transpose the final letters of the two words...
-- PMM
Quoted 30 lines · Peter Maydell
In CPUSparcState we define the fprs field as
uint64_t. However we then refer to it intranslate.cvia aTCGv_i32which we set up withtcg_global_mem_new_ptr(). This means that on a big-endian host when the guest does something to writo te the FPRS register this value ends up in the wrong half of theuint64_t, and the QEMU C code that refers toenv->fprssees the wrong value. The effect of this is that guest code that enables the FPU crashes with spurious FPU Disabled exceptions. In particular, this is why
tests/avocado/machine_sparc64_sun4u.py:Sun4uMachine.test_sparc64_sun4u
times out on an s390 host.There are multiple ways we could fix this; since there are actually only three bits in the FPRS register and the code in
translate.cwould be a bit painful to convert to dealing with aTCGv_i64, change the type of the CPU state struct field to match whattranslate.cis expecting.(None of the other fields referenced by the r32[] array in
sparc_tcg_init()have the wrong type.)Signed-off-by Peter Maydell<[email protected]>---
Changesv1->v2:
* drop unnecessary change togdbstub.c
* put the vmstate fields the correct way aroundNB: I believe the vmstate changes to be correct, but sparc64 seems unable to successfully do a savevm/loadvm even before this change due to some other bug (the guest kernel panics immediately after the loadvm).
Quoted 6 lines
--- target/sparc/cpu.h | 2 +- target/sparc/cpu.c | 4 ++-- target/sparc/machine.c | 3 ++- target/sparc/monitor.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-)
r~
Quoted 84 lines · Peter Maydell
In CPUSparcState we define the fprs field as
uint64_t. However we then refer to it intranslate.cvia aTCGv_i32which we set up withtcg_global_mem_new_ptr(). This means that on a big-endian host when the guest does something to writo te the FPRS register this value ends up in the wrong half of theuint64_t, and the QEMU C code that refers toenv->fprssees the wrong value. The effect of this is that guest code that enables the FPU crashes with spurious FPU Disabled exceptions. In particular, this is why
tests/avocado/machine_sparc64_sun4u.py:Sun4uMachine.test_sparc64_sun4u
times out on an s390 host.There are multiple ways we could fix this; since there are actually only three bits in the FPRS register and the code in
translate.cwould be a bit painful to convert to dealing with aTCGv_i64, change the type of the CPU state struct field to match whattranslate.cis expecting.(None of the other fields referenced by the r32[] array in
sparc_tcg_init()have the wrong type.)Signed-off-by Peter Maydell <[email protected]>---
Changesv1->v2:
* drop unnecessary change togdbstub.c
* put the vmstate fields the correct way aroundNB: I believe the vmstate changes to be correct, but sparc64 seems unable to successfully do a savevm/loadvm even before this change due to some other bug (the guest kernel panics immediately after the loadvm).
--- target/sparc/cpu.h | 2 +- target/sparc/cpu.c | 4 ++-- target/sparc/machine.c | 3 ++- target/sparc/monitor.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-)target/sparc/cpu.h +1
-1@@ -521,7 +521,7 @@ struct CPUArchState {uint64_t igregs[8 ];/* interrupt general registers */ uint64_t mgregs[8 ];/* mmu general registers */ uint64_t glregs[8 *MAXTL_MAX ]; -uint64_t fprs; +uint32_t fprs;uint64_t tick_cmpr, stick_cmpr;CPUTimer *tick, *stick;#define TICK_NPT_MASK 0x8000000000000000ULLtarget/sparc/cpu.c +2
-2@@ -673,8 +673,8 @@ static void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags)"cleanwin: %d cwp: %d\n" , env->cansave, env->canrestore, env->otherwin, env->wstate, env->cleanwin, env->nwindows - 1 - env->cwp); -qemu_fprintf (f,"fsr: " TARGET_FMT_lx" y: " TARGET_FMT_lx" fprs: " - TARGET_FMT_lx"\n" , env->fsr, env->y, env->fprs); +qemu_fprintf (f,"fsr: " TARGET_FMT_lx" y: " TARGET_FMT_lx" fprs: %016x\n" , + env->fsr, env->y, env->fprs);#else qemu_fprintf (f,"psr: %08x (icc: " ,cpu_get_psr (env));target/sparc/machine.c +2
-1@@ -168,7 +168,8 @@ const VMStateDescription vmstate_sparc_cpu = {VMSTATE_UINT64_ARRAY (env.bgregs,SPARCCPU ,8 ),VMSTATE_UINT64_ARRAY (env.igregs,SPARCCPU ,8 ),VMSTATE_UINT64_ARRAY (env.mgregs,SPARCCPU ,8 ), -VMSTATE_UINT64 (env.fprs,SPARCCPU ), +VMSTATE_UNUSED (4 ),/* was unused high half of uint64_t fprs */ +VMSTATE_UINT32 (env.fprs,SPARCCPU ),VMSTATE_UINT64 (env.tick_cmpr,SPARCCPU ),VMSTATE_UINT64 (env.stick_cmpr,SPARCCPU ), VMSTATE_CPU_TIMER(env.tick, SPARCCPU),target/sparc/monitor.c +0
-0
target/sparc/monitor.c const MonitorDef monitor_defs[] = { · line 160
Quoted 8 lines
target/sparc/monitor.c +1
-1@@ -154,7 +154,7 @@ const MonitorDef monitor_defs[] = { { "otherwin", offsetof(CPUSPARCState, otherwin) }, { "wstate", offsetof(CPUSPARCState, wstate) }, { "cleanwin", offsetof(CPUSPARCState, cleanwin) }, - { "fprs", offsetof(CPUSPARCState, fprs) }, + { "fprs", offsetof(CPUSPARCState, fprs), NULL, MD_I32 }, #endif { NULL }, };
To the best of my knowledge there is no-one actively requesting migration compatibility for SPARC, so I'm perfectly fine if any improvements here include a migration version bump if you think it makes life easier/cleaner. Otherwise:
ATB,
Mark.