From: mark.rutland@arm.com (Mark Rutland)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 10/10] ARM/ARM64: KVM: Emulate PSCI v0.2 CPU_SUSPEND
Date: Mon, 17 Mar 2014 11:28:21 +0000 [thread overview]
Message-ID: <20140317112820.GF8070@e106331-lin.cambridge.arm.com> (raw)
In-Reply-To: <CAAhSdy3kbafDc=T0dYHpULKoGKxAner+zY1vdLDDyU1JrqD2tQ@mail.gmail.com>
On Mon, Mar 17, 2014 at 06:54:28AM +0000, Anup Patel wrote:
> On Mon, Mar 17, 2014 at 9:11 AM, Christoffer Dall
> <christoffer.dall@linaro.org> wrote:
> > On Thu, Feb 06, 2014 at 05:01:42PM +0530, Anup Patel wrote:
> >> This patch adds emulation of PSCI v0.2 CPU_SUSPEND function call for
> >> KVM ARM/ARM64. This is a VCPU-level function call which can suspend
> >> current VCPU or all VCPUs within current VCPU's affinity level.
> >>
> >> The CPU_SUSPEND emulation is not tested much because currently there
> >> is no CPUIDLE driver in Linux kernel that uses PSCI CPU_SUSPEND. The
> >> PSCI CPU_SUSPEND implementation in ARM64 kernel was tested using a
> >> Simple CPUIDLE driver which is not published due to unstable DT-bindings
> >> for PSCI.
> >> (For more info, http://lwn.net/Articles/574950/)
> >>
> >> Even if we had stable DT-bindings for PSCI and CPUIDLE driver that
> >> uses PSCI CPU_SUSPEND then still we need to define SUSPEND states
> >> for KVM ARM/ARM64. Due to this, the CPU_SUSPEND emulation added
> >> by this patch only pause a VCPU and to wakeup a VCPU we need to
> >> explicity call PSCI CPU_ON from Guest.
> >>
> >> Signed-off-by: Anup Patel <anup.patel@linaro.org>
> >> Signed-off-by: Pranavkumar Sawargaonkar <pranavkumar@linaro.org>
> >> ---
> >> arch/arm/include/asm/kvm_host.h | 5 +++
> >> arch/arm/include/asm/kvm_psci.h | 1 +
> >> arch/arm/kvm/psci.c | 88 +++++++++++++++++++++++++++++++++++--
> >> arch/arm/kvm/reset.c | 4 ++
> >> arch/arm64/include/asm/kvm_host.h | 5 +++
> >> arch/arm64/include/asm/kvm_psci.h | 1 +
> >> arch/arm64/kvm/reset.c | 4 ++
> >> 7 files changed, 104 insertions(+), 4 deletions(-)
[...]
> >> +static void psci_do_suspend(void *context)
> >> +{
> >> + struct psci_suspend_info *sinfo = context;
> >> +
> >> + sinfo->vcpu->arch.pause = true;
> >> + sinfo->vcpu->arch.suspend = true;
> >> + sinfo->vcpu->arch.suspend_entry = sinfo->saved_entry;
> >> + sinfo->vcpu->arch.suspend_context_id = sinfo->saved_context_id;
> >
> > I don't really understand this, why are you not just setting pause =
> > true and modifying the registers as per the reentry rules in the spec?
> >
> > Doesn't seem like this patch ever reads any of these values back?
>
> Thats because we don't have any wake-up events defined for PSCI v0.2
> emulated by KVM.
I would expect interrupts to wake secondaries (e.g. SGIs for the
broadcast timer). Do you have that at least?
[...]
> >> +
> >> + /* Ignore other bits of target affinity */
> >> + target_affinity &= target_affinity_mask;
> >> +
> >> + /* Prepare suspend info */
> >> + sinfo.vcpu = NULL;
> >> + sinfo.saved_entry = *vcpu_reg(vcpu, 2);
> >> + sinfo.saved_context_id = *vcpu_reg(vcpu, 3);
> >> +
> >> + /* Suspend all VCPUs within target affinity */
> >> + kvm_for_each_vcpu(i, tmp, kvm) {
> >> + mpidr = kvm_vcpu_get_mpidr(tmp);
> >> + if (((mpidr & target_affinity_mask) == target_affinity) &&
> >> + !tmp->arch.suspend) {
> >> + sinfo.vcpu = tmp;
> >> + smp_call_function_single(tmp->cpu,
> >> + psci_do_suspend, &sinfo, 1);
> >
> > Hmmm, are you sure this is correct? How does that correspond to the
> > PSCI docs saying
> >
> > "It is only possible to call CPU_SUSPEND from the current core. That is,
> > it is not possible to request suspension of another core."
> >
> > I would think this means, if all other cores in the specified affinity
> > level are already suspended, allow suspending the entire
> > cluster/group/..., but I may be wrong.
>
> Actually, CPU_SUSPEND is for all cores belonging to affinity
> of current core.
Per 5.4.3 in the PSCI 0.2 spec:
The power state parameter expresses a constraint:
Caller allows entry down to this state, but no deeper.
The AffinityLevel parameter is a maximum level to suspend, not a
required level to suspend. CPUs are never forcibly suspended.
There's an example table in 5.4.3 which might help to clarify.
>
> >
> > My comments above notwithstanding, this also feels racy. What happens
> > if two virtual cores within the same affinity level calls CPU_SUSPEND at
> > the same time?
>
> Yes, I know its racy. I was expecting this comment.
>
> What would be appropriate lock to protect per-VCPU suspend context?
>
> I think spinlock would be better because psci_do_suspend() is called
> using SMP IPIs.
>
> >
> > Also, there doesn't seem to be any handling of the StateType requested
> > by the caller, the reentry behavior is very different depending on the
> > state you enter, unless you always treat the request as a suspend
> > (clause 3 under Section 5.4.2 in the PSCI spec), in that case that
> > deserves a comment.
>
> The StateType is completely implementation dependent. Also, it is the
> StateType that will help determine the wake-up event.
>
> For KVM, we really don't have any StateType defined hence we don't
> have any wake-up events defined for KVM PSCI.
>
> Should we have KVM specific suspend states?
> What would KVM suspend states look like because suspend states
> are platform specific?
This is something we need to figure out how to describe to the kernel.
Cheers,
Mark.
next prev parent reply other threads:[~2014-03-17 11:28 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-06 11:31 [PATCH v4 00/10] In-kernel PSCI v0.2 emulation for KVM ARM/ARM64 Anup Patel
2014-02-06 11:31 ` [PATCH v4 01/10] KVM: Add capability to advertise PSCI v0.2 support Anup Patel
2014-03-17 3:39 ` Christoffer Dall
2014-02-06 11:31 ` [PATCH v4 02/10] ARM/ARM64: KVM: Add base for PSCI v0.2 emulation Anup Patel
2014-02-07 8:28 ` Jungseok Lee
2014-02-07 8:36 ` Anup Patel
2014-02-07 9:07 ` Jungseok Lee
2014-02-07 9:26 ` Anup Patel
2014-02-07 23:37 ` Jungseok Lee
2014-02-07 23:42 ` Jungseok Lee
2014-03-14 22:57 ` Christoffer Dall
2014-03-17 3:40 ` Christoffer Dall
2014-03-17 6:14 ` Anup Patel
2014-03-19 13:22 ` Rob Herring
2014-02-06 11:31 ` [PATCH v4 03/10] KVM: Documentation: Add info regarding KVM_ARM_VCPU_PSCI_0_2 feature Anup Patel
2014-03-17 3:40 ` Christoffer Dall
2014-02-06 11:31 ` [PATCH v4 04/10] ARM/ARM64: KVM: Make kvm_psci_call() return convention more flexible Anup Patel
2014-03-17 3:40 ` Christoffer Dall
2014-02-06 11:31 ` [PATCH v4 05/10] KVM: Add KVM_EXIT_SYSTEM_EVENT to user space API header Anup Patel
2014-03-17 3:40 ` Christoffer Dall
2014-02-06 11:31 ` [PATCH v4 06/10] ARM/ARM64: KVM: Emulate PSCI v0.2 SYSTEM_OFF and SYSTEM_RESET Anup Patel
2014-03-17 3:40 ` Christoffer Dall
2014-02-06 11:31 ` [PATCH v4 07/10] ARM/ARM64: KVM: Emulate PSCI v0.2 AFFINITY_INFO Anup Patel
2014-03-17 3:41 ` Christoffer Dall
2014-02-06 11:31 ` [PATCH v4 08/10] ARM/ARM64: KVM: Emulate PSCI v0.2 MIGRATE_INFO_TYPE and related functions Anup Patel
2014-03-17 3:41 ` Christoffer Dall
2014-03-17 6:16 ` Anup Patel
2014-02-06 11:31 ` [PATCH v4 09/10] ARM/ARM64: KVM: Fix CPU_ON emulation for PSCI v0.2 Anup Patel
2014-03-17 3:41 ` Christoffer Dall
2014-03-17 6:17 ` Anup Patel
2014-02-06 11:31 ` [PATCH v4 10/10] ARM/ARM64: KVM: Emulate PSCI v0.2 CPU_SUSPEND Anup Patel
2014-03-17 3:41 ` Christoffer Dall
2014-03-17 6:54 ` Anup Patel
2014-03-17 11:28 ` Mark Rutland [this message]
2014-03-17 17:49 ` Christoffer Dall
2014-03-17 3:39 ` [PATCH v4 00/10] In-kernel PSCI v0.2 emulation for KVM ARM/ARM64 Christoffer Dall
2014-03-17 6:11 ` Anup Patel
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=20140317112820.GF8070@e106331-lin.cambridge.arm.com \
--to=mark.rutland@arm.com \
--cc=linux-arm-kernel@lists.infradead.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 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).