qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Scott Wood <scottwood@freescale.com>
To: Alexander Graf <agraf@suse.de>
Cc: Jan Kiszka <jan.kiszka@siemens.com>,
	Liu Yu <yu.liu@freescale.com>,
	qemu-ppc@nongnu.org,
	qemu-devel Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [kvm-devel] [PATCH v2] kvm-ppc: halt secondary cpus when guest reset
Date: Mon, 9 Jan 2012 17:17:21 -0600	[thread overview]
Message-ID: <4F0B7581.90306@freescale.com> (raw)
In-Reply-To: <DD3D25ED-9637-4425-B284-42CEE47F7B56@suse.de>

On 01/09/2012 04:39 PM, Alexander Graf wrote:
> 
> On 09.01.2012, at 22:23, Scott Wood wrote:
> 
>> On 01/09/2012 01:41 AM, Liu Yu wrote:
>>> When guest reset, we need to halt secondary cpus until guest kick them.
>>> This already works for tcg. The patch add the support for kvm.
>>>
>>> There are two cases for kvm:
>>>
>>> 1. If not use in-kernel mpic. We return env->halted in
>>> kvm_arch_process_async_events(), in order to tell kvm common code
>>> whether we request to halt.
>>>
>>> 2. If use in-kernel mpic. Even we request to halt,
>>> the common code cpu_thread_is_idle() refuses to halt,
>>> because if vcpu halts while use in-kernel mpic, then there's
>>> no external interrupt handled in qemu to wake up the vcpu thread.
>>> In this case, we set stopped to pause the sencondaries instead,
>>> And resume secondaries when primary cpu access ppce500_spin.
>>>
>>> Signed-off-by: Liu Yu <yu.liu@freescale.com>
>>> ---
>>> v2:
>>> Add comment and modify commit log
>>>
>>> hw/ppce500_spin.c |    1 +
>>> target-ppc/kvm.c  |   15 ++++++++++++++-
>>> 2 files changed, 15 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/hw/ppce500_spin.c b/hw/ppce500_spin.c
>>> index cccd940..2b52728 100644
>>> --- a/hw/ppce500_spin.c
>>> +++ b/hw/ppce500_spin.c
>>> @@ -112,6 +112,7 @@ static void spin_kick(void *data)
>>>
>>>     env->halted = 0;
>>>     env->exception_index = -1;
>>> +    env->stopped = 0;
>>>     qemu_cpu_kick(env);
>>> }
>>>
>>> diff --git a/target-ppc/kvm.c b/target-ppc/kvm.c
>>> index 429349f..b7c70e2 100644
>>> --- a/target-ppc/kvm.c
>>> +++ b/target-ppc/kvm.c
>>> @@ -504,7 +504,20 @@ void kvm_arch_post_run(CPUState *env, struct kvm_run *run)
>>>
>>> int kvm_arch_process_async_events(CPUState *env)
>>> {
>>> -    return 0;
>>> +    if (kvm_irqchip_in_kernel()) {
>>> +        if (env->halted == 1 && env->exception_index == EXCP_HLT) {
>>> +            /* We're here because secondary vcpus are requested to halt
>>> +             * before get kicked. But it's not allowed to halt vcpu when
>>> +             * kvm_irqchip_in_kernel() is true. Instead, set stopped=1
>>> +             * so that vcpu thread can be paused until guest kick them */
>>> +            env->stopped = 1;
>>> +            return 1;
>>> +        } else {
>>> +            return 0;
>>> +        }
>>> +    }
>>> +
>>> +    return env->halted;
>>> }
>>
>> Alex, is there a better way to deal with the IRQ chip issue?
> 
> To be honest, I'm not sure what the issue really is.

If irqchip is enabled, env->halted won't result in a CPU being
considered idle -- since QEMU won't see the interrupt that wakes the
vcpu, and the idling is handled in the kernel.  In this case we're
waiting for MMIO rather than an interrupt, and it's the kernel that
doesn't know what's going on.

It seems wrong to use env->stopped, though, as a spin-table release
should not override a user's explicit request to stop a CPU.  It might
be OK (though a bit ugly) if the only usage of env->stopped is through
pause_all_vcpus(), and the boot thread is the first one to be kicked
(though in theory the boot cpu could wake another cpu, and that could
wake a cpu that comes before it, causing a race with pause_all_vcpus()).

If it is OK to use env->stopped, is there any reason not to always use
it (versus just with irqchip)?

-Scott

  reply	other threads:[~2012-01-09 23:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1326094902-24152-1-git-send-email-yu.liu@freescale.com>
     [not found] ` <4F0B5AD8.9090602@freescale.com>
2012-01-09 22:39   ` [Qemu-devel] [kvm-devel] [PATCH v2] kvm-ppc: halt secondary cpus when guest reset Alexander Graf
2012-01-09 23:17     ` Scott Wood [this message]
2012-01-10  9:38       ` Jan Kiszka
2012-01-10 17:43         ` Scott Wood
2012-01-10 17:52           ` Jan Kiszka
2012-01-10 18:19             ` Alexander Graf
2012-01-10 22:43             ` Scott Wood
2012-01-10 23:01               ` Alexander Graf

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=4F0B7581.90306@freescale.com \
    --to=scottwood@freescale.com \
    --cc=agraf@suse.de \
    --cc=jan.kiszka@siemens.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=yu.liu@freescale.com \
    /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).