Skip to contentSkip to conversation

whpx: Fixed reporting of the CPU context to GDB for 64-bit

PATCH In review Ivan Shcherbakov 1 participant 1 message Feb 23, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 whpx: Fixed reporting of the CPU context to GDB for 64-bit

Hi All,

We have been looking into kernel-debugging Linux VMs running on Windows with Hyper-V enabled (that forces the virtualization software to use WHPX), and it turned out, none of the major virtualization tools supports it properly. I've added the missing parts to QEMU and it looks pretty solid: setting breakpoints in the kernel, running, stepping in/over works reliably and fast.
The changes involved 3 parts:
1. Fixing the x64 register reporting to gdb (this patch)
2. Fixing synchronization of CR8 <=> APIC.TPR, that was preventing WHvSetVirtualProcessorRegisters() from working
3. Implementing software breakpoints

It would be great if the changes could be integrated into the QEMU repository, allowing other Windows users to debug their VMs. Below is the description of the first patch.

This change makes sure that stopping in the 64-bit mode will set the HF_CS64_MASK flag in env->hflags (see x86_update_hflags() in target/i386/cpu.c).
Without it, the code in gdbstub.c would only use the 32-bit register values when debugging 64-bit targets, making debugging effectively impossible.

---
 target/i386/whpx/whpx-all.c | 2 ++
 1 file changed, 2 insertions(+)
target/i386/whpx/whpx-all.c +2 -0
index ef896da0a2..edd4fafbdf 100644
@@ -604,6 +604,8 @@ static void whpx_get_registers(CPUState *cpu)
         whpx_apic_get(x86_cpu->apic_state);
     }
 
+    x86_update_hflags(env);
+
     return;
 }