From: David Hildenbrand <david@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Crosthwaite <crosthwaite.peter@gmail.com>,
Cornelia Huck <cohuck@redhat.com>,
Christian Borntraeger <borntraeger@de.ibm.com>,
qemu-s390x@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [qemu-s390x] [PATCH v1] cpus: track calls to resume/pause_all_vcpus()
Date: Fri, 13 Apr 2018 12:14:25 +0200 [thread overview]
Message-ID: <39789551-e757-de4c-e901-1f4c774a8c8c@redhat.com> (raw)
In-Reply-To: <20180409130700.5692-1-david@redhat.com>
On 09.04.2018 15:07, David Hildenbrand wrote:
> If we have parallel calls to resume/pause_all_vcpus() we can get
> into trouble because the qemu mutex is temporarily dropped while
> waiting for all threads to stop. This can happen e.g. for s390x, where
> resume/pause_all_vcpus() can be triggered by a VCPU.
>
> Pause/Resume exactly once, when we leave/hit "0".
>
> Signed-off-by: David Hildenbrand <david@redhat.com>
> ---
> cpus.c | 31 ++++++++++++++++++++++++-------
> 1 file changed, 24 insertions(+), 7 deletions(-)
>
> diff --git a/cpus.c b/cpus.c
> index 2e6701795b..7c7e0245c5 100644
> --- a/cpus.c
> +++ b/cpus.c
> @@ -1778,17 +1778,26 @@ static bool all_vcpus_paused(void)
> return true;
> }
>
> +/* wait for the initial vm_start() call */
> +static int vcpus_paused = 1;
> +
> void pause_all_vcpus(void)
> {
> CPUState *cpu;
>
> - qemu_clock_enable(QEMU_CLOCK_VIRTUAL, false);
> - CPU_FOREACH(cpu) {
> - if (qemu_cpu_is_self(cpu)) {
> - qemu_cpu_stop(cpu, true);
> - } else {
> - cpu->stop = true;
> - qemu_cpu_kick(cpu);
> + assert(qemu_mutex_iothread_locked());
> + assert(vcpus_paused >= 0);
> +
> + vcpus_paused++;
> + if (vcpus_paused == 1) {
> + qemu_clock_enable(QEMU_CLOCK_VIRTUAL, false);
> + CPU_FOREACH(cpu) {
> + if (qemu_cpu_is_self(cpu)) {
> + qemu_cpu_stop(cpu, true);
> + } else {
> + cpu->stop = true;
> + qemu_cpu_kick(cpu);
> + }
> }
> }
>
> @@ -1820,6 +1829,14 @@ void resume_all_vcpus(void)
> {
> CPUState *cpu;
>
> + assert(vcpus_paused >= 0);
> + assert(qemu_mutex_iothread_locked());
> +
> + vcpus_paused--;
> + if (vcpus_paused > 0) {
> + return;
> + }
> +
> qemu_clock_enable(QEMU_CLOCK_VIRTUAL, true);
> CPU_FOREACH(cpu) {
> cpu_resume(cpu);
>
So if everything goes well, we have a replacement for s390x and this
patch should no longer be needed.
pause_all_vcpus/resume_all_vcpus should not be called from a VCPU.
.. that implies that I have to find another way to get all CPUs out KVM
for the prototype I am working on :/
--
Thanks,
David / dhildenb
prev parent reply other threads:[~2018-04-13 10:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-09 13:07 [Qemu-devel] [PATCH v1] cpus: track calls to resume/pause_all_vcpus() David Hildenbrand
2018-04-09 13:12 ` Paolo Bonzini
2018-04-09 13:28 ` David Hildenbrand
2018-04-13 10:14 ` David Hildenbrand [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=39789551-e757-de4c-e901-1f4c774a8c8c@redhat.com \
--to=david@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=crosthwaite.peter@gmail.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=rth@twiddle.net \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).