@samitouri / QOSamiQemu / commits / 93f38b6e88

whpx: i386: inject back db

When we get a debug exception other than int1, inject it back to the guest. Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr> Link: https://lore.kernel.org/r/20260812082814.27217-7-mohamed@unpredictable.fr Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Mohamed Mediouni committed Aug 12, 2026 at 10:28 UTC 93f38b6e8817280e1a51102d2dfd21115b8d4e88
1 file changed +26 -5
target/i386/whpx/whpx-all.c
+26 -5
@@ -1079,6 +1079,31 @@ static void whpx_inject_back_gpf(CPUState *cpu)
1079 whpx_set_reg(cpu, WHvRegisterPendingEvent, reg);
1080 }
1081
1082 +static void whpx_inject_back_db(CPUState *cpu)
1083 +{
1084 + WHV_VP_EXCEPTION_CONTEXT *ctx = &cpu->accel->exit_ctx.VpException;
1085 + WHV_REGISTER_VALUE reg = {};
1086 +
1087 + if (ctx->ExceptionInfo.SoftwareException) {
1088 + /* TODO */
1089 + warn_report("Was asked to inject software exception.");
1090 + return;
1091 + }
1092 +
1093 + if (ctx->ExceptionType != EXCP01_DB) {
1094 + warn_report("Was asked to inject exception other than debug.");
1095 + return;
1096 + }
1097 +
1098 + reg.ExceptionEvent.EventPending = 1;
1099 + reg.ExceptionEvent.EventType = WHvX64PendingEventException;
1100 + reg.ExceptionEvent.DeliverErrorCode = ctx->ExceptionInfo.ErrorCodeValid;
1101 + reg.ExceptionEvent.Vector = ctx->ExceptionType;
1102 + reg.ExceptionEvent.ErrorCode = ctx->ErrorCode;
1103 + reg.ExceptionEvent.ExceptionParameter = ctx->ExceptionParameter;
1104 + whpx_set_reg(cpu, WHvRegisterPendingEvent, reg);
1105 +}
1106 +
1107 static void handle_io(CPUState *env, uint16_t port, void *buffer,
1108 int direction, int size, int count)
1109 {
@@ -2646,11 +2671,7 @@ int whpx_vcpu_run(CPUState *cpu)
2671 } else if ((vcpu->exit_ctx.VpException.ExceptionType ==
2672 WHvX64ExceptionTypeDebugTrapOrFault) &&
2673 !cpu_single_stepping(cpu)) {
2649 - /*
2650 - * Just finished stepping over a breakpoint, but the
2651 - * gdb does not expect us to do single-stepping.
2652 - * Don't do anything special.
2653 - */
2674 + whpx_inject_back_db(cpu);
2675 cpu->exception_index = EXCP_INTERRUPT;
2676 } else {
2677 /* Another exception or debug event. Report it to GDB. */