Message ID | eb7fe8ed-e885-48c0-a36f-1f700bc692bf@laaksoft.nl (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Patch: Sparc prevent segfault when dumping uninitialzed cpu state | expand |
On 2/2/25 19:14, Henk van der Laak (LaakSoft) via wrote: > Hi all, my first contribution. I checked code style, patch submission rules and did a > manual test (details on request) > > Synopsis: > It's a corner case, where a segfault occurs when logging Sparc CPU state in a partially > initialized state. > > No related bug report. > > Open to harsh criticism ;-) How do we arrive here with a partially initialized state? r~
On 2/2/25 20:03, Henk van der Laak (LaakSoft) wrote: > On 03/02/2025 04:45, Richard Henderson wrote: >> On 2/2/25 19:14, Henk van der Laak (LaakSoft) via wrote: >>> Hi all, my first contribution. I checked code style, patch submission rules and did a >>> manual test (details on request) >>> >>> Synopsis: >>> It's a corner case, where a segfault occurs when logging Sparc CPU state in a partially >>> initialized state. >>> >>> No related bug report. >>> >>> Open to harsh criticism ;-) >> >> How do we arrive here with a partially initialized state? >> >> >> r~ >> > |> qemu-sparc64 -d cpu_reset -D ./cpu_reset.log demo.sparc64.asm.elf ||The logging category 'cpu_reset' causes logging of all resets including the very first > one, where initialization by Qemu has not been completed. Like I said, it's a corner case. > Henk van der Laak | > Gotcha. I'd forgotten that -d cpu_reset exists. Of course the logging happens before the superclass reset even starts, much less finishes. I guess the logging should happen in the exit phase, not the hold phase. r~
diff --git a/target/sparc/cpu.c b/target/sparc/cpu.c index fbd38ec334..83aaa456fc 100644 --- a/target/sparc/cpu.c +++ b/target/sparc/cpu.c @@ -642,7 +642,12 @@ static void sparc_cpu_dump_state(CPUState *cs, FILE *f, int flags) x == 0 ? 'o' : (x == 1 ? 'l' : 'i'), i, i + REGS_PER_LINE - 1); } - qemu_fprintf(f, TARGET_FMT_lx " ", env->regwptr[i + x * 8]); + /* + * regwptr may not be initialized yet when logging + * e.g. cpu_reset + */ + qemu_fprintf(f, TARGET_FMT_lx " ", + env->regwptr ? env->regwptr[i + x * 8] : 0); if (i % REGS_PER_LINE == REGS_PER_LINE - 1) { qemu_fprintf(f, "\n");
Hi all, my first contribution. I checked code style, patch submission rules and did a manual test (details on request) Synopsis: It's a corner case, where a segfault occurs when logging Sparc CPU state in a partially initialized state. No related bug report. Open to harsh criticism ;-) Regards, Henk van der Laak <henk@laaksoft.nl> Patch is based off 6fccaa2fba391815308a746d68f7fa197bc93586 (origin/master) as of Sun Feb 2 11:09:10 2025 -0500 Signed-off-by: Henk van der Laak <henk@laaksoft.nl> --- target/sparc/cpu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) }