qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] dump: add kernel_gs_base to QEMU CPU state
@ 2018-07-10 15:21 Viktor Prutyanov
  2018-07-11 16:00 ` Eduardo Habkost
  0 siblings, 1 reply; 6+ messages in thread
From: Viktor Prutyanov @ 2018-07-10 15:21 UTC (permalink / raw)
  To: qemu-devel; +Cc: pbonzini, rth, ehabkost, rkagan, Viktor Prutyanov

This patch adds field with content of KERNEL_GS_BASE MSR to QEMU note in
ELF dump.

On Windows, if all vCPUs are running usermode tasks at the time the dump is
created, this can be helpful in the discovery of guest system structures
during conversion ELF dump to MEMORY.DMP dump.

Signed-off-by: Viktor Prutyanov <viktor.prutyanov@virtuozzo.com>
---
 target/i386/arch_dump.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/target/i386/arch_dump.c b/target/i386/arch_dump.c
index 35b55fc..a702138 100644
--- a/target/i386/arch_dump.c
+++ b/target/i386/arch_dump.c
@@ -237,7 +237,7 @@ int x86_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,
  * please count up QEMUCPUSTATE_VERSION if you have changed definition of
  * QEMUCPUState, and modify the tools using this information accordingly.
  */
-#define QEMUCPUSTATE_VERSION (1)
+#define QEMUCPUSTATE_VERSION (2)
 
 struct QEMUCPUSegment {
     uint32_t selector;
@@ -258,6 +258,7 @@ struct QEMUCPUState {
     QEMUCPUSegment cs, ds, es, fs, gs, ss;
     QEMUCPUSegment ldt, tr, gdt, idt;
     uint64_t cr[5];
+    uint64_t kernel_gs_base;
 };
 
 typedef struct QEMUCPUState QEMUCPUState;
@@ -315,6 +316,8 @@ static void qemu_get_cpustate(QEMUCPUState *s, CPUX86State *env)
     s->cr[2] = env->cr[2];
     s->cr[3] = env->cr[3];
     s->cr[4] = env->cr[4];
+
+    s->kernel_gs_base = env->kernelgsbase;
 }
 
 static inline int cpu_write_qemu_note(WriteCoreDumpFunction f,
-- 
2.7.4

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

* Re: [Qemu-devel] [PATCH] dump: add kernel_gs_base to QEMU CPU state
  2018-07-10 15:21 [Qemu-devel] [PATCH] dump: add kernel_gs_base to QEMU CPU state Viktor Prutyanov
@ 2018-07-11 16:00 ` Eduardo Habkost
  2018-07-11 16:19   ` Paolo Bonzini
  2018-07-11 16:26   ` Viktor Prutyanov
  0 siblings, 2 replies; 6+ messages in thread
From: Eduardo Habkost @ 2018-07-11 16:00 UTC (permalink / raw)
  To: Viktor Prutyanov; +Cc: qemu-devel, pbonzini, rth, rkagan

On Tue, Jul 10, 2018 at 06:21:09PM +0300, Viktor Prutyanov wrote:
> This patch adds field with content of KERNEL_GS_BASE MSR to QEMU note in
> ELF dump.
> 
> On Windows, if all vCPUs are running usermode tasks at the time the dump is
> created, this can be helpful in the discovery of guest system structures
> during conversion ELF dump to MEMORY.DMP dump.
> 
> Signed-off-by: Viktor Prutyanov <viktor.prutyanov@virtuozzo.com>
> ---
>  target/i386/arch_dump.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/target/i386/arch_dump.c b/target/i386/arch_dump.c
> index 35b55fc..a702138 100644
> --- a/target/i386/arch_dump.c
> +++ b/target/i386/arch_dump.c
> @@ -237,7 +237,7 @@ int x86_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,
>   * please count up QEMUCPUSTATE_VERSION if you have changed definition of
>   * QEMUCPUState, and modify the tools using this information accordingly.

Where are the tools using this information, that need to be
updated?  Won't this break existing versions of those tools?

Is the dump format and pointers to available tools documented
somewhere?


>   */
> -#define QEMUCPUSTATE_VERSION (1)
> +#define QEMUCPUSTATE_VERSION (2)
>  
>  struct QEMUCPUSegment {
>      uint32_t selector;
> @@ -258,6 +258,7 @@ struct QEMUCPUState {
>      QEMUCPUSegment cs, ds, es, fs, gs, ss;
>      QEMUCPUSegment ldt, tr, gdt, idt;
>      uint64_t cr[5];
> +    uint64_t kernel_gs_base;
>  };
>  
>  typedef struct QEMUCPUState QEMUCPUState;
> @@ -315,6 +316,8 @@ static void qemu_get_cpustate(QEMUCPUState *s, CPUX86State *env)
>      s->cr[2] = env->cr[2];
>      s->cr[3] = env->cr[3];
>      s->cr[4] = env->cr[4];
> +
> +    s->kernel_gs_base = env->kernelgsbase;
>  }
>  
>  static inline int cpu_write_qemu_note(WriteCoreDumpFunction f,
> -- 
> 2.7.4
> 

-- 
Eduardo

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

* Re: [Qemu-devel] [PATCH] dump: add kernel_gs_base to QEMU CPU state
  2018-07-11 16:00 ` Eduardo Habkost
@ 2018-07-11 16:19   ` Paolo Bonzini
  2018-07-11 19:19     ` Eduardo Habkost
  2018-07-11 16:26   ` Viktor Prutyanov
  1 sibling, 1 reply; 6+ messages in thread
From: Paolo Bonzini @ 2018-07-11 16:19 UTC (permalink / raw)
  To: Eduardo Habkost, Viktor Prutyanov; +Cc: qemu-devel, rth, rkagan

On 11/07/2018 18:00, Eduardo Habkost wrote:
>> @@ -237,7 +237,7 @@ int x86_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,
>>   * please count up QEMUCPUSTATE_VERSION if you have changed definition of
>>   * QEMUCPUState, and modify the tools using this information accordingly.
> Where are the tools using this information, that need to be
> updated?  Won't this break existing versions of those tools?

I think it's okay to _not_ change the version, since the format is
backwards-compatible.  Each QEMUCPUState struct is in a separate ELF
note, and the presence of the new field is visible in both 1) the size
of the note 2) the size field of the struct.

Another possibility is to stash kernel_gs_base in cr[1].  This approach
doesn't scale, but the word is otherwise unused if we want to make it
super safe.  I don't recommend it.

Paolo


> Is the dump format and pointers to available tools documented
> somewhere?
> 
> 

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

* Re: [Qemu-devel] [PATCH] dump: add kernel_gs_base to QEMU CPU state
  2018-07-11 16:00 ` Eduardo Habkost
  2018-07-11 16:19   ` Paolo Bonzini
@ 2018-07-11 16:26   ` Viktor Prutyanov
  2018-07-11 16:31     ` Paolo Bonzini
  1 sibling, 1 reply; 6+ messages in thread
From: Viktor Prutyanov @ 2018-07-11 16:26 UTC (permalink / raw)
  To: Eduardo Habkost; +Cc: qemu-devel, pbonzini, rth, rkagan

On Wed, 11 Jul 2018 13:00:25 -0300
Eduardo Habkost <ehabkost@redhat.com> wrote:

> On Tue, Jul 10, 2018 at 06:21:09PM +0300, Viktor Prutyanov wrote:
> > This patch adds field with content of KERNEL_GS_BASE MSR to QEMU
> > note in ELF dump.
> > 
> > On Windows, if all vCPUs are running usermode tasks at the time the
> > dump is created, this can be helpful in the discovery of guest
> > system structures during conversion ELF dump to MEMORY.DMP dump.
> > 
> > Signed-off-by: Viktor Prutyanov <viktor.prutyanov@virtuozzo.com>
> > ---
> >  target/i386/arch_dump.c | 5 ++++-
> >  1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/target/i386/arch_dump.c b/target/i386/arch_dump.c
> > index 35b55fc..a702138 100644
> > --- a/target/i386/arch_dump.c
> > +++ b/target/i386/arch_dump.c
> > @@ -237,7 +237,7 @@ int
> > x86_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,
> >   * please count up QEMUCPUSTATE_VERSION if you have changed
> > definition of
> >   * QEMUCPUState, and modify the tools using this information
> > accordingly.  
> 
> Where are the tools using this information, that need to be
> updated?  Won't this break existing versions of those tools?
> 
> Is the dump format and pointers to available tools documented
> somewhere?

I hope that someone from community knows about those tools because I
can't find such tools.

> 
> >   */
> > -#define QEMUCPUSTATE_VERSION (1)
> > +#define QEMUCPUSTATE_VERSION (2)
> >  
> >  struct QEMUCPUSegment {
> >      uint32_t selector;
> > @@ -258,6 +258,7 @@ struct QEMUCPUState {
> >      QEMUCPUSegment cs, ds, es, fs, gs, ss;
> >      QEMUCPUSegment ldt, tr, gdt, idt;
> >      uint64_t cr[5];
> > +    uint64_t kernel_gs_base;
> >  };
> >  
> >  typedef struct QEMUCPUState QEMUCPUState;
> > @@ -315,6 +316,8 @@ static void qemu_get_cpustate(QEMUCPUState *s,
> > CPUX86State *env) s->cr[2] = env->cr[2];
> >      s->cr[3] = env->cr[3];
> >      s->cr[4] = env->cr[4];
> > +
> > +    s->kernel_gs_base = env->kernelgsbase;
> >  }
> >  
> >  static inline int cpu_write_qemu_note(WriteCoreDumpFunction f,
> > -- 
> > 2.7.4
> >   
> 

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

* Re: [Qemu-devel] [PATCH] dump: add kernel_gs_base to QEMU CPU state
  2018-07-11 16:26   ` Viktor Prutyanov
@ 2018-07-11 16:31     ` Paolo Bonzini
  0 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2018-07-11 16:31 UTC (permalink / raw)
  To: Viktor Prutyanov, Eduardo Habkost; +Cc: qemu-devel, rth, rkagan

On 11/07/2018 18:26, Viktor Prutyanov wrote:
>> Where are the tools using this information, that need to be
>> updated?  Won't this break existing versions of those tools?
>>
>> Is the dump format and pointers to available tools documented
>> somewhere?
> I hope that someone from community knows about those tools because I
> can't find such tools.
> 

I checked crash, and it doesn't have any issue with QEMUCPUState that is
bigger than what is currently in QEMU.  It doesn't use anything but CR3
and IDT base.  It also doesn't at all check the version! :O

Paolo

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

* Re: [Qemu-devel] [PATCH] dump: add kernel_gs_base to QEMU CPU state
  2018-07-11 16:19   ` Paolo Bonzini
@ 2018-07-11 19:19     ` Eduardo Habkost
  0 siblings, 0 replies; 6+ messages in thread
From: Eduardo Habkost @ 2018-07-11 19:19 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: Viktor Prutyanov, qemu-devel, rth, rkagan

On Wed, Jul 11, 2018 at 06:19:33PM +0200, Paolo Bonzini wrote:
> On 11/07/2018 18:00, Eduardo Habkost wrote:
> >> @@ -237,7 +237,7 @@ int x86_cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cs,
> >>   * please count up QEMUCPUSTATE_VERSION if you have changed definition of
> >>   * QEMUCPUState, and modify the tools using this information accordingly.
> > Where are the tools using this information, that need to be
> > updated?  Won't this break existing versions of those tools?
> 
> I think it's okay to _not_ change the version, since the format is
> backwards-compatible.  Each QEMUCPUState struct is in a separate ELF
> note, and the presence of the new field is visible in both 1) the size
> of the note 2) the size field of the struct.

If we do it, can we please make the documentation (or at least
code comments, as documentation doesn't seem to exist) clearly
state that the new field is optional in version 1?

-- 
Eduardo

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

end of thread, other threads:[~2018-07-11 19:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-10 15:21 [Qemu-devel] [PATCH] dump: add kernel_gs_base to QEMU CPU state Viktor Prutyanov
2018-07-11 16:00 ` Eduardo Habkost
2018-07-11 16:19   ` Paolo Bonzini
2018-07-11 19:19     ` Eduardo Habkost
2018-07-11 16:26   ` Viktor Prutyanov
2018-07-11 16:31     ` Paolo Bonzini

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