From: Ian Campbell Subject: Re: [PATCH v4 01/12] xen/arm: basic PSCI support, implement cpu_on and cpu_off Date: Mon, 29 Apr 2013 10:15:46 +0100 Message-ID: <1367226946.3142.233.camel@zakaz.uk.xensource.com> References: <1366990117-8689-1-git-send-email-stefano.stabellini@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1366990117-8689-1-git-send-email-stefano.stabellini@eu.citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Stefano Stabellini Cc: Julien Grall , "xen-devel@lists.xensource.com" , "Tim (Xen.org)" List-Id: xen-devel@lists.xenproject.org On Fri, 2013-04-26 at 16:28 +0100, Stefano Stabellini wrote: > +int do_psci_cpu_on(uint32_t vcpuid, register_t entry_point) > +{ > + struct vcpu *v; > + struct domain *d = current->domain; > + struct vcpu_guest_context *ctxt; > + int rc; > + > + if ( (vcpuid < 0) || (vcpuid >= MAX_VIRT_CPUS) ) > + return PSCI_EINVAL; > + > + if ( vcpuid >= d->max_vcpus || (v = d->vcpu[vcpuid]) == NULL ) > + return PSCI_EINVAL; > + > + if ( (ctxt = alloc_vcpu_guest_context()) == NULL ) > + return PSCI_DENIED; > + > + memset(ctxt, 0, sizeof(*ctxt)); > + ctxt->user_regs.pc64 = (u64) entry_point; > + ctxt->sctlr = SCTLR_BASE; > + ctxt->ttbr0 = 0; > + ctxt->ttbr1 = 0; > + ctxt->ttbcr = 0; /* Defined Reset Value */ > + ctxt->user_regs.cpsr = PSR_GUEST_INIT; > + ctxt->flags = VGCF_online; > + > + domain_lock(d); > + rc = arch_set_info_guest(v, ctxt); > + free_vcpu_guest_context(ctxt); I'm slightly concerned that there might be other state which needs clearing when we are brining up a VCPU which has subsequently been running and blocked via cpu_down. I'm thinking of the sort of things which vcpu_reset clears up. However I guess we'll find those out later. > + if ( rc < 0 ) > + { > + domain_unlock(d); > + return PSCI_DENIED; > + } > + domain_unlock(d); > + > + vcpu_wake(v); > + > + return PSCI_SUCCESS; > +} > + > +int do_psci_cpu_off(uint32_t power_state) > +{ > + struct vcpu *v = current; > + if ( !test_and_set_bit(_VPF_down, &v->pause_flags) ) > + vcpu_sleep_nosync(v); > + return PSCI_SUCCESS; We will return here but not make it back to the guest, because we will call into the scheduler (vcpu_sleep_nosync makes sure this is the case) and block. If cpu_up is subsequently called then it will overwrite the VCPU's guest state and so it will return to the newly selected address. Good! Acked-by: Ian Campbell