From: Magnus Kulke <magnuskulke@linux.microsoft.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, "Wei Liu" <wei.liu@kernel.org>,
"Anirudh Rayabharam" <anirudh@anirudhrb.com>,
aastharawat@microsoft.com,
"Doru Blânzeanu" <dblanzeanu@linux.microsoft.com>,
"Aastha Rawat" <aastharawat@linux.microsoft.com>,
magnuskulke@microsoft.com, Anirudh.Rayabharam@microsoft.com,
liuwe@microsoft.com, doru.blanzeanu@microsoft.com
Subject: Re: [PATCH] accel/mshv: mitigate early boot vcpu exit race
Date: Mon, 6 Jul 2026 14:27:16 +0200 [thread overview]
Message-ID: <akufJAci7WqN4JSB@example.com> (raw)
In-Reply-To: <26d4e782-ebbf-4a4f-a5f7-6fe107cc083f@redhat.com>
On Thu, Jun 25, 2026 at 03:15:16PM +0200, Paolo Bonzini wrote:
>
> These two should not be needed. The sequence of events is:
>
> - exit from here
>
> - "while (!cpu->unplug || cpu_can_run(cpu))" is still true
>
> - qemu_process_cpu_events() runs:
> - set exit_request == false
> - cpu_thread_is_idle(cpu) is false due to cpu->stop == true
> - qemu_process_cpu_events_common() runs:
> - sets cpu->thread_kicked == false
> - qemu_cpu_stop() sets cpu->stopped == true
>
> - cpu_can_run(cpu) is now false, so mshv_cpu_exec() does not run
>
> - ... but !cpu->unplug is true -> another run around the loop
>
> - now cpu_thread_is_idle(cpu) is true, so the thread goes to sleep.
>
> > + ret = EXCP_INTERRUPT;
> > + break;
> > + }
>
>
> Also, for cleanliness I'd put the lines after the "if (cpu->accel->dirty)"
> immediately below.
>
>
> > +/*
> > + * mshv-custom kick implementation:
> > + *
> > + * We set cpu->exit_request before the SIG_IPI is delivered to the vcpu
> > + * thread (as part of cpus_kick_thread()). It is consumed in the
> > + * mshv_cpu_exec loop.
> > + */
> > +static void mshv_kick_vcpu_thread(CPUState *cpu)
> > +{
> > + qatomic_set_mb(&cpu->exit_request, true);
> > + cpus_kick_thread(cpu);
> > +}
> > +
>
> This should not be necessary, either. In recent versions of QEMU,
> cpu->exit_request is set appropriately by cpu_exit(); see commits
> ac6c8a390b4 and f8217ae54e4 and nearby.
>
> Accelerators can write cpu->exit_request, but only within the accelerator
> thread if they want to kick themselves out of cpu_exec(). For example, KVM
> does this to run kvm_arch_process_async_events(); but MSHV does not have
> anything similar.
>
> Paolo
I see, we indeed just need to honor cpu->exit_request in the loop and
break out if it is set, this only seems to be address the issue that the
patch was attempting to fix. Since we also need to it for the migration
case, I submit a revised patch as part of a migration series, so we can
abandon this one.
thanks!
magnus
prev parent reply other threads:[~2026-07-06 12:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-21 13:34 [PATCH] accel/mshv: mitigate early boot vcpu exit race Magnus Kulke
2026-05-22 13:18 ` Doru Blânzeanu
2026-06-25 13:15 ` Paolo Bonzini
2026-07-06 12:27 ` Magnus Kulke [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=akufJAci7WqN4JSB@example.com \
--to=magnuskulke@linux.microsoft.com \
--cc=Anirudh.Rayabharam@microsoft.com \
--cc=aastharawat@linux.microsoft.com \
--cc=aastharawat@microsoft.com \
--cc=anirudh@anirudhrb.com \
--cc=dblanzeanu@linux.microsoft.com \
--cc=doru.blanzeanu@microsoft.com \
--cc=liuwe@microsoft.com \
--cc=magnuskulke@microsoft.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=wei.liu@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.