* [PATCH] target/i386/mshv: fix vCPU run result contract
@ 2026-10-15 12:19 Magnus Kulke
2026-11-11 11:48 ` Doru Blânzeanu
0 siblings, 1 reply; 3+ messages in thread
From: Magnus Kulke @ 2026-10-15 12:19 UTC (permalink / raw)
To: qemu-devel
Cc: Magnus Kulke, Magnus Kulke, Wei Liu, Doru Blânzeanu,
Doru Blânzeanu
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: 6dec60528c4 (target/i386/mshv: Implement mshv_vcpu_run())
Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com>
---
target/i386/mshv/mshv-cpu.c | 28 +++++++++++++++++-----------
1 file changed, 17 insertions(+), 11 deletions(-)
diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c
index 4df73bb497..e3c155da2e 100644
--- a/target/i386/mshv/mshv-cpu.c
+++ b/target/i386/mshv/mshv-cpu.c
@@ -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;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] target/i386/mshv: fix vCPU run result contract
2026-10-15 12:19 [PATCH] target/i386/mshv: fix vCPU run result contract Magnus Kulke
@ 2026-11-11 11:48 ` Doru Blânzeanu
2026-11-11 19:24 ` Magnus Kulke
0 siblings, 1 reply; 3+ messages in thread
From: Doru Blânzeanu @ 2026-11-11 11:48 UTC (permalink / raw)
To: Magnus Kulke; +Cc: qemu-devel, Magnus Kulke, Wei Liu, Doru Blânzeanu
On Thu, Oct 15, 2026 at 02:19:11PM +0200, Magnus Kulke wrote:
> 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: 6dec60528c4 (target/i386/mshv: Implement mshv_vcpu_run())
> Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com>
> ---
> target/i386/mshv/mshv-cpu.c | 28 +++++++++++++++++-----------
> 1 file changed, 17 insertions(+), 11 deletions(-)
>
> diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c
> index 4df73bb497..e3c155da2e 100644
> --- a/target/i386/mshv/mshv-cpu.c
> +++ b/target/i386/mshv/mshv-cpu.c
> @@ -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;
> }
> --
> 2.34.1
Reviewed-by: Doru Blânzeanu <dblanzeanu@linux.microsoft.com>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] target/i386/mshv: fix vCPU run result contract
2026-11-11 11:48 ` Doru Blânzeanu
@ 2026-11-11 19:24 ` Magnus Kulke
0 siblings, 0 replies; 3+ messages in thread
From: Magnus Kulke @ 2026-11-11 19:24 UTC (permalink / raw)
To: Doru Blânzeanu
Cc: qemu-devel, Magnus Kulke, Wei Liu, Doru Blânzeanu
On Wed, Nov 11, 2026 at 01:48:48PM +0200, Doru Blânzeanu wrote:
> On Thu, Oct 15, 2026 at 02:19:11PM +0200, Magnus Kulke wrote:
> > 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: 6dec60528c4 (target/i386/mshv: Implement mshv_vcpu_run())
> > Signed-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com>
> > ---
> > target/i386/mshv/mshv-cpu.c | 28 +++++++++++++++++-----------
> > 1 file changed, 17 insertions(+), 11 deletions(-)
> >
> > diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c
> > index 4df73bb497..e3c155da2e 100644
> > --- a/target/i386/mshv/mshv-cpu.c
> > +++ b/target/i386/mshv/mshv-cpu.c
> > @@ -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;
> > }
> > --
> > 2.34.1
>
> Reviewed-by: Doru Blânzeanu <dblanzeanu@linux.microsoft.com>
queued in pull-20261111
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-11 19:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-15 12:19 [PATCH] target/i386/mshv: fix vCPU run result contract Magnus Kulke
2026-11-11 11:48 ` Doru Blânzeanu
2026-11-11 19:24 ` Magnus Kulke
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.