[v2] dump: add kernel_gs_base to QEMU CPU state

Message ID 1531416567-13558-1-git-send-email-viktor.prutyanov@virtuozzo.com
State New
Headers show
Series
  • [v2] dump: add kernel_gs_base to QEMU CPU state
Related show

Commit Message

Viktor Prutyanov July 12, 2018, 5:29 p.m.
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>
---
 v2: keep version 1 in QEMUCPUState and document the extension procedure

 target/i386/arch_dump.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Eduardo Habkost July 13, 2018, 8:14 p.m. | #1
On Thu, Jul 12, 2018 at 08:29:27PM +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>

Reviewed-by: Eduardo Habkost <ehabkost@redhat.com>

Queued for 3.1, thanks.
Eduardo Habkost July 13, 2018, 10:12 p.m. | #2
On Thu, Jul 12, 2018 at 08:29:27PM +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>
> ---
>  v2: keep version 1 in QEMUCPUState and document the extension procedure
> 
>  target/i386/arch_dump.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/target/i386/arch_dump.c b/target/i386/arch_dump.c
> index 35b55fc..cc8750f 100644
> --- a/target/i386/arch_dump.c
> +++ b/target/i386/arch_dump.c
> @@ -258,6 +258,12 @@ struct QEMUCPUState {
>      QEMUCPUSegment cs, ds, es, fs, gs, ss;
>      QEMUCPUSegment ldt, tr, gdt, idt;
>      uint64_t cr[5];
> +    /*
> +     * Fields below are optional and are being added at the end without
> +     * changing the version. External tools may identify their presence
> +     * by checking 'size' field.
> +     */
> +    uint64_t kernel_gs_base;
>  };
>  
>  typedef struct QEMUCPUState QEMUCPUState;
> @@ -315,6 +321,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;

This breaks i386-softmmu:

/home/travis/build/ehabkost/qemu/target/i386/arch_dump.c: In function ‘qemu_get_cpustate’:
/home/travis/build/ehabkost/qemu/target/i386/arch_dump.c:325:28: error: ‘CPUX86State’ has no member named ‘kernelgsbase’
     s->kernel_gs_base = env->kernelgsbase;
                            ^
make[1]: *** [target/i386/arch_dump.o] Error 1
make: *** [subdir-i386-softmmu] Error 2
make: *** Waiting for unfinished jobs....

Patch

diff --git a/target/i386/arch_dump.c b/target/i386/arch_dump.c
index 35b55fc..cc8750f 100644
--- a/target/i386/arch_dump.c
+++ b/target/i386/arch_dump.c
@@ -258,6 +258,12 @@  struct QEMUCPUState {
     QEMUCPUSegment cs, ds, es, fs, gs, ss;
     QEMUCPUSegment ldt, tr, gdt, idt;
     uint64_t cr[5];
+    /*
+     * Fields below are optional and are being added at the end without
+     * changing the version. External tools may identify their presence
+     * by checking 'size' field.
+     */
+    uint64_t kernel_gs_base;
 };
 
 typedef struct QEMUCPUState QEMUCPUState;
@@ -315,6 +321,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,