@samitouri / QOSamiQemu / commits / edd1c8aa89

whpx: i386: don't increment eip on MSR access raising GPF

Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr> Link: https://lore.kernel.org/r/20260422214225.2242-33-mohamed@unpredictable.fr Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Mohamed Mediouni committed Apr 22, 2026 at 23:42 UTC edd1c8aa89c455cdbc8b5b435cf019fd6597cd30
1 file changed +11
target/i386/whpx/whpx-all.c
+11
@@ -2048,6 +2048,7 @@ int whpx_vcpu_run(CPUState *cpu)
2048 WHV_REGISTER_NAME reg_names[3];
2049 UINT32 reg_count;
2050 bool is_known_msr = 0;
2051 + bool raises_gpf = false;
2052 uint64_t val;
2053
2054 if (vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite) {
@@ -2086,6 +2087,7 @@ int whpx_vcpu_run(CPUState *cpu)
2087 int msr_ret = cpu_set_apic_base(X86_CPU(cpu)->apic_state, val);
2088 if (msr_ret < 0) {
2089 x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0D_GPF, 0);
2090 + raises_gpf = true;
2091 } else {
2092 whpx_set_reg(cpu, WHvX64RegisterApicBase, reg);
2093 }
@@ -2105,6 +2107,7 @@ int whpx_vcpu_run(CPUState *cpu)
2107 reg_values[1].Reg64 = val;
2108 if (msr_ret < 0) {
2109 x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0D_GPF, 0);
2110 + raises_gpf = true;
2111 }
2112 } else {
2113 bql_lock();
@@ -2112,6 +2115,7 @@ int whpx_vcpu_run(CPUState *cpu)
2115 bql_unlock();
2116 if (msr_ret < 0) {
2117 x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0D_GPF, 0);
2118 + raises_gpf = true;
2119 }
2120 }
2121 }
@@ -2135,6 +2139,13 @@ int whpx_vcpu_run(CPUState *cpu)
2139
2140 if (!is_known_msr && !whpx->ignore_unknown_msr) {
2141 x86_emul_raise_exception(&X86_CPU(cpu)->env, EXCP0D_GPF, 0);
2142 + raises_gpf = true;
2143 + }
2144 +
2145 + /* When a GPF is raised, do not change Rip. */
2146 + if (raises_gpf) {
2147 + reg_values[0].Reg64 =
2148 + vcpu->exit_ctx.VpContext.Rip;
2149 }
2150
2151 hr = whp_dispatch.WHvSetVirtualProcessorRegisters(