target/i386/mshv: fix vCPU run result contract
Currently the return semantics of mshv_run_vcpu() are broken. They
return a mix of int and exit_reason, ignoring the out param *exit.
This change propagates errno's to the call site and sets the *exit value
accordingly. We also consider the case when an ioctl has return due to a
qemu-requested interruption of the call, this is a legitimate condition
that should not produce an error.
Fixes: 6dec60528c ("target/i386/mshv: Implement mshv_vcpu_run()")
Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com>
Reviewed-by: Doru Blânzeanu <dblanzeanu@linux.microsoft.com>
This commit is contained in:
1 parent
3b9e70ba6c
commit
cc47cd339a
1 file changed
+17
-11
+17
-11
@@ -2124,7 +2124,6 @@ static int arch_set_single_step(CPUState *cpu, bool enable)
|
||||
int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_message *msg, MshvVmExit *exit)
|
||||
{
|
||||
int ret;
|
||||
enum MshvVmExit exit_reason;
|
||||
int cpu_fd = mshv_vcpufd(cpu);
|
||||
bool single_step;
|
||||
|
||||
@@ -2142,7 +2141,12 @@ int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_message *msg, MshvVmExit *exit)
|
||||
|
||||
ret = ioctl(cpu_fd, MSHV_RUN_VP, msg);
|
||||
if (ret < 0) {
|
||||
return MshvVmExitShutdown;
|
||||
if (errno == EINTR) {
|
||||
*exit = MshvVmExitSpecial;
|
||||
return 0;
|
||||
}
|
||||
error_report("failed to run vCPU: %s", strerror(errno));
|
||||
return -errno;
|
||||
}
|
||||
|
||||
/* disable single stepping by flipping RFLAGS.TF */
|
||||
@@ -2154,31 +2158,33 @@ int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_message *msg, MshvVmExit *exit)
|
||||
|
||||
switch (msg->header.message_type) {
|
||||
case HVMSG_UNRECOVERABLE_EXCEPTION:
|
||||
return MshvVmExitShutdown;
|
||||
*exit = MshvVmExitShutdown;
|
||||
return 0;
|
||||
case HVMSG_UNMAPPED_GPA:
|
||||
case HVMSG_GPA_INTERCEPT:
|
||||
ret = handle_mmio(cpu, msg, &exit_reason);
|
||||
ret = handle_mmio(cpu, msg, exit);
|
||||
if (ret < 0) {
|
||||
error_report("failed to handle mmio");
|
||||
return -1;
|
||||
return ret;
|
||||
}
|
||||
return exit_reason;
|
||||
return 0;
|
||||
case HVMSG_X64_IO_PORT_INTERCEPT:
|
||||
ret = handle_pio(cpu, msg);
|
||||
if (ret < 0) {
|
||||
return MshvVmExitSpecial;
|
||||
error_report("failed to handle PIO");
|
||||
return ret;
|
||||
}
|
||||
return MshvVmExitIgnore;
|
||||
*exit = MshvVmExitIgnore;
|
||||
return 0;
|
||||
case HVMSG_X64_EXCEPTION_INTERCEPT:
|
||||
bql_lock();
|
||||
ret = handle_exception_interrupt(cpu, msg, &exit_reason);
|
||||
ret = handle_exception_interrupt(cpu, msg, exit);
|
||||
bql_unlock();
|
||||
if (ret < 0) {
|
||||
error_report("failed to handle exception intercept");
|
||||
return -1;
|
||||
}
|
||||
*exit = exit_reason;
|
||||
return exit_reason;
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user