All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH RESEND v2] hmp: fix "info cpu" segfault
@ 2017-03-29 21:04 Iwona Kotlarska
  2017-03-30  0:46 ` Eduardo Habkost
  0 siblings, 1 reply; 2+ messages in thread
From: Iwona Kotlarska @ 2017-03-29 21:04 UTC (permalink / raw)
  Cc: qemu-devel, marcel, pbonzini, rth, ehabkost, Iwona Kotlarska

Running QEMU with "qemu-system-x86_64 -M none -nographic -m 256" and executing
"dump-guest-memory /dev/null 0 8192" results in segfault.
Fix by checking if we have CPU.

Signed-off-by: Iwona Kotlarska <iwona260909@gmail.com>
---
v1 --> v2
Added brackets around if body.
Changed subject.
 target/i386/arch_dump.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/target/i386/arch_dump.c b/target/i386/arch_dump.c
index 5a2e4be5d0..43992a440c 100644
--- a/target/i386/arch_dump.c
+++ b/target/i386/arch_dump.c
@@ -390,9 +390,11 @@ int cpu_get_dump_info(ArchDumpInfo *info,
     GuestPhysBlock *block;
 
 #ifdef TARGET_X86_64
-    X86CPU *first_x86_cpu = X86_CPU(first_cpu);
-
-    lma = !!(first_x86_cpu->env.hflags & HF_LMA_MASK);
+    X86CPU *first_x86_cpu = NULL;
+    first_x86_cpu = X86_CPU(first_cpu);
+    if (first_cpu != NULL) {
+        lma = !!(first_x86_cpu->env.hflags & HF_LMA_MASK);
+    }
 #endif
 
     if (lma) {
-- 
2.12.0

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

* Re: [Qemu-devel] [PATCH RESEND v2] hmp: fix "info cpu" segfault
  2017-03-29 21:04 [Qemu-devel] [PATCH RESEND v2] hmp: fix "info cpu" segfault Iwona Kotlarska
@ 2017-03-30  0:46 ` Eduardo Habkost
  0 siblings, 0 replies; 2+ messages in thread
From: Eduardo Habkost @ 2017-03-30  0:46 UTC (permalink / raw)
  To: Iwona Kotlarska; +Cc: qemu-devel, marcel, pbonzini, rth

On Wed, Mar 29, 2017 at 11:04:39PM +0200, Iwona Kotlarska wrote:
> Running QEMU with "qemu-system-x86_64 -M none -nographic -m 256" and executing
> "dump-guest-memory /dev/null 0 8192" results in segfault.
> Fix by checking if we have CPU.
> 
> Signed-off-by: Iwona Kotlarska <iwona260909@gmail.com>
> ---
> v1 --> v2
> Added brackets around if body.
> Changed subject.
>  target/i386/arch_dump.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/target/i386/arch_dump.c b/target/i386/arch_dump.c
> index 5a2e4be5d0..43992a440c 100644
> --- a/target/i386/arch_dump.c
> +++ b/target/i386/arch_dump.c
> @@ -390,9 +390,11 @@ int cpu_get_dump_info(ArchDumpInfo *info,
>      GuestPhysBlock *block;
>  
>  #ifdef TARGET_X86_64
[Reordering the diff a little bit to make my comments clearer]
> -    X86CPU *first_x86_cpu = X86_CPU(first_cpu);
> +    X86CPU *first_x86_cpu = NULL;
> +    first_x86_cpu = X86_CPU(first_cpu);

There's no reason to replace that single line with these ones.

> -
> -    lma = !!(first_x86_cpu->env.hflags & HF_LMA_MASK);
> +    if (first_cpu != NULL) {
> +        lma = !!(first_x86_cpu->env.hflags & HF_LMA_MASK);
> +    }

This part looks OK, although personally I would prefer to write it as:
    lma = first_cpu && (first_x86_cpu->env.hflags & HF_LMA_MASK);
so this can become a single-line patch.

I also wonder if the TARGET_X86_64 #ifdef is really necessary. Is
it possible to ever have HF_LMA_MASK set if the target is not
x86_64? But that's something for a separate patch, and unrelated
to the bug you are fixing.

>  #endif
>  
>      if (lma) {
> -- 
> 2.12.0
> 

-- 
Eduardo

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

end of thread, other threads:[~2017-03-30  0:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-29 21:04 [Qemu-devel] [PATCH RESEND v2] hmp: fix "info cpu" segfault Iwona Kotlarska
2017-03-30  0:46 ` Eduardo Habkost

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.