qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* Patch: Sparc prevent segfault when dumping uninitialzed cpu state
@ 2025-02-03  3:14 Henk van der Laak (LaakSoft) via
  2025-02-03  3:45 ` Richard Henderson
  0 siblings, 1 reply; 3+ messages in thread
From: Henk van der Laak (LaakSoft) via @ 2025-02-03  3:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mark Cave-Ayland, Artyom Tarasenko

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(-)

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");
              }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: Patch: Sparc prevent segfault when dumping uninitialzed cpu state
  2025-02-03  3:14 Patch: Sparc prevent segfault when dumping uninitialzed cpu state Henk van der Laak (LaakSoft) via
@ 2025-02-03  3:45 ` Richard Henderson
       [not found]   ` <a392d217-852c-46b4-84ef-d8ea5ad296c1@laaksoft.nl>
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Henderson @ 2025-02-03  3:45 UTC (permalink / raw)
  To: qemu-devel

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~


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Patch: Sparc prevent segfault when dumping uninitialzed cpu state
       [not found]   ` <a392d217-852c-46b4-84ef-d8ea5ad296c1@laaksoft.nl>
@ 2025-02-03  4:10     ` Richard Henderson
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Henderson @ 2025-02-03  4:10 UTC (permalink / raw)
  To: Henk van der Laak (LaakSoft), qemu-devel

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~


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-02-03  4:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-03  3:14 Patch: Sparc prevent segfault when dumping uninitialzed cpu state Henk van der Laak (LaakSoft) via
2025-02-03  3:45 ` Richard Henderson
     [not found]   ` <a392d217-852c-46b4-84ef-d8ea5ad296c1@laaksoft.nl>
2025-02-03  4:10     ` Richard Henderson

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).