From patchwork Mon Nov 25 15:49:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 21746 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f69.google.com (mail-pb0-f69.google.com [209.85.160.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C485723A3F for ; Mon, 25 Nov 2013 15:50:37 +0000 (UTC) Received: by mail-pb0-f69.google.com with SMTP id md12sf11207138pbc.8 for ; Mon, 25 Nov 2013 07:50:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=EMjWs41JvSfykW7quSNr2CBWR4K1IPG/QpJe51dqZw0=; b=OWoXsbD7pjk3SUFklRnV3ET8Rsy8yc8OY81Q0F5PUScGUft+diKMs6EgTGSqbg35BQ 9QLpGpxzwuDLmehb3TvdfI1c1wUn2vFyD9W6z2OcvDER2G1hiSMIWeYwDabyeNOgDp0S oYypU/BXkAWbNDPqnkBD2VkGo/cQNHSPRWD8OByEWlcGFRZYlh/2CYwgC2p4KR3WxvkY /R8zvusjyU3EDvGG27vJbFffYJ9aiPNEOy0n3RjmHgBGCPA3tgj619+4trNKgRRv2fWf y34PDebT9m//FhfEu70DdA0UP2j7CtI7coB5fmBweBPtA/cpugbYs9lya9EfbH+tHWUL AYVg== X-Gm-Message-State: ALoCoQmspvpLDflrOgPhXEQRhsmIb17ghms8O7JtXBziqb18w93jD/hGKM1rxsbC4HmXOCdPi8/Z X-Received: by 10.66.102.8 with SMTP id fk8mr258791pab.24.1385394636865; Mon, 25 Nov 2013 07:50:36 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.4.138 with SMTP id k10ls2052857qek.13.gmail; Mon, 25 Nov 2013 07:50:36 -0800 (PST) X-Received: by 10.58.11.73 with SMTP id o9mr26841476veb.8.1385394636727; Mon, 25 Nov 2013 07:50:36 -0800 (PST) Received: from mail-vb0-f42.google.com (mail-vb0-f42.google.com [209.85.212.42]) by mx.google.com with ESMTPS id v5si18047070ves.42.2013.11.25.07.50.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Nov 2013 07:50:36 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.42 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.42; Received: by mail-vb0-f42.google.com with SMTP id w18so3005734vbj.29 for ; Mon, 25 Nov 2013 07:50:36 -0800 (PST) X-Received: by 10.220.86.69 with SMTP id r5mr27018340vcl.9.1385394636616; Mon, 25 Nov 2013 07:50:36 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp142970vcz; Mon, 25 Nov 2013 07:50:36 -0800 (PST) X-Received: by 10.66.235.69 with SMTP id uk5mr1259644pac.185.1385394635601; Mon, 25 Nov 2013 07:50:35 -0800 (PST) Received: from mail-pb0-f51.google.com (mail-pb0-f51.google.com [209.85.160.51]) by mx.google.com with ESMTPS id fb6si17339641pab.66.2013.11.25.07.50.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Nov 2013 07:50:35 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.51 is neither permitted nor denied by best guess record for domain of anup.patel@linaro.org) client-ip=209.85.160.51; Received: by mail-pb0-f51.google.com with SMTP id up15so6020409pbc.10 for ; Mon, 25 Nov 2013 07:50:35 -0800 (PST) X-Received: by 10.68.190.136 with SMTP id gq8mr18635526pbc.68.1385394635194; Mon, 25 Nov 2013 07:50:35 -0800 (PST) Received: from pnqlab006.amcc.com ([182.73.239.130]) by mx.google.com with ESMTPSA id e6sm6039746pbg.4.2013.11.25.07.50.30 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Nov 2013 07:50:34 -0800 (PST) From: Anup Patel To: kvmarm@lists.cs.columbia.edu Cc: linux-arm-kernel@lists.infradead.org, patches@linaro.org, linaro-kernel@lists.linaro.org, patches@apm.com, Christoffer Dall , Marc Zyngier , Rob Herring , Pranavkumar Sawargaonkar , Anup Patel Subject: [PATCH 2/2] ARM/ARM64: KVM: Forward PSCI SYSTEM_OFF and SYSTEM_RESET to user space Date: Mon, 25 Nov 2013 21:19:59 +0530 Message-Id: <1385394599-15439-3-git-send-email-anup.patel@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1385394599-15439-1-git-send-email-anup.patel@linaro.org> References: <1385394599-15439-1-git-send-email-anup.patel@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: anup.patel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.42 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The PSCI SYSTEM_OFF and SYSTEM_RESET functions are system-level functions hence cannot be fully emulated by the in-kernel PSCI emulation code. To tackle this, we forward PSCI SYSTEM_OFF and SYSTEM_RESET function calls from guest to user space (i.e. QEMU or KVMTOOL) via KVM run structure using KVM_EXIT_SHUTDOWN and KVM_EXIT_RESET exit reasons. Signed-off-by: Anup Patel Signed-off-by: Pranavkumar Sawargaonkar --- arch/arm/include/asm/kvm_psci.h | 2 +- arch/arm/include/uapi/asm/kvm.h | 2 ++ arch/arm/kvm/handle_exit.c | 7 ++++++- arch/arm/kvm/psci.c | 38 +++++++++++++++++++++++++++++-------- arch/arm64/include/asm/kvm_psci.h | 2 +- arch/arm64/include/uapi/asm/kvm.h | 2 ++ arch/arm64/kvm/handle_exit.c | 10 ++++++---- 7 files changed, 48 insertions(+), 15 deletions(-) diff --git a/arch/arm/include/asm/kvm_psci.h b/arch/arm/include/asm/kvm_psci.h index 9a83d98..992d7f1 100644 --- a/arch/arm/include/asm/kvm_psci.h +++ b/arch/arm/include/asm/kvm_psci.h @@ -18,6 +18,6 @@ #ifndef __ARM_KVM_PSCI_H__ #define __ARM_KVM_PSCI_H__ -bool kvm_psci_call(struct kvm_vcpu *vcpu); +int kvm_psci_call(struct kvm_vcpu *vcpu); #endif /* __ARM_KVM_PSCI_H__ */ diff --git a/arch/arm/include/uapi/asm/kvm.h b/arch/arm/include/uapi/asm/kvm.h index c498b60..f4de20c 100644 --- a/arch/arm/include/uapi/asm/kvm.h +++ b/arch/arm/include/uapi/asm/kvm.h @@ -172,6 +172,8 @@ struct kvm_arch_memory_slot { #define KVM_PSCI_FN_CPU_OFF KVM_PSCI_FN(1) #define KVM_PSCI_FN_CPU_ON KVM_PSCI_FN(2) #define KVM_PSCI_FN_MIGRATE KVM_PSCI_FN(3) +#define KVM_PSCI_FN_SYSTEM_OFF KVM_PSCI_FN(4) +#define KVM_PSCI_FN_SYSTEM_RESET KVM_PSCI_FN(5) #define KVM_PSCI_RET_SUCCESS 0 #define KVM_PSCI_RET_NI ((unsigned long)-1) diff --git a/arch/arm/kvm/handle_exit.c b/arch/arm/kvm/handle_exit.c index a920790..c96c7e8 100644 --- a/arch/arm/kvm/handle_exit.c +++ b/arch/arm/kvm/handle_exit.c @@ -40,11 +40,16 @@ static int handle_svc_hyp(struct kvm_vcpu *vcpu, struct kvm_run *run) static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run) { + int ret; + trace_kvm_hvc(*vcpu_pc(vcpu), *vcpu_reg(vcpu, 0), kvm_vcpu_hvc_get_imm(vcpu)); - if (kvm_psci_call(vcpu)) + ret = kvm_psci_call(vcpu); + if (ret == 0) return 1; + else if (ret > 0) + return 0; kvm_inject_undefined(vcpu); return 1; diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c index 0881bf1..c8d3fcd 100644 --- a/arch/arm/kvm/psci.c +++ b/arch/arm/kvm/psci.c @@ -84,18 +84,31 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu) return KVM_PSCI_RET_SUCCESS; } +static void kvm_psci_system_off(struct kvm_vcpu *vcpu) +{ + vcpu->run->exit_reason = KVM_EXIT_SHUTDOWN; +} + +static void kvm_psci_system_reset(struct kvm_vcpu *vcpu) +{ + vcpu->run->exit_reason = KVM_EXIT_RESET; +} + /** * kvm_psci_call - handle PSCI call if r0 value is in range * @vcpu: Pointer to the VCPU struct * * Handle PSCI calls from guests through traps from HVC instructions. - * The calling convention is similar to SMC calls to the secure world where - * the function number is placed in r0 and this function returns true if the - * function number specified in r0 is withing the PSCI range, and false - * otherwise. + * The calling convention is similar to SMC calls to the secure world + * where the function number is placed in r0 and function number + * specified in r0 is withing the PSCI range. + * + * This function returns: 0 (success), > 0 (success but exit to user + * space), and < 0 (failure) */ -bool kvm_psci_call(struct kvm_vcpu *vcpu) +int kvm_psci_call(struct kvm_vcpu *vcpu) { + int ret = 0; unsigned long psci_fn = *vcpu_reg(vcpu, 0) & ~((u32) 0); unsigned long val; @@ -111,11 +124,20 @@ bool kvm_psci_call(struct kvm_vcpu *vcpu) case KVM_PSCI_FN_MIGRATE: val = KVM_PSCI_RET_NI; break; - + case KVM_PSCI_FN_SYSTEM_OFF: + kvm_psci_system_off(vcpu); + val = KVM_PSCI_RET_SUCCESS; + ret = 1; + break; + case KVM_PSCI_FN_SYSTEM_RESET: + kvm_psci_system_reset(vcpu); + val = KVM_PSCI_RET_SUCCESS; + ret = 1; + break; default: - return false; + return -EINVAL; } *vcpu_reg(vcpu, 0) = val; - return true; + return ret; } diff --git a/arch/arm64/include/asm/kvm_psci.h b/arch/arm64/include/asm/kvm_psci.h index e301a48..9bd0ee8 100644 --- a/arch/arm64/include/asm/kvm_psci.h +++ b/arch/arm64/include/asm/kvm_psci.h @@ -18,6 +18,6 @@ #ifndef __ARM64_KVM_PSCI_H__ #define __ARM64_KVM_PSCI_H__ -bool kvm_psci_call(struct kvm_vcpu *vcpu); +int kvm_psci_call(struct kvm_vcpu *vcpu); #endif /* __ARM64_KVM_PSCI_H__ */ diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h index d9f026b..f678902 100644 --- a/arch/arm64/include/uapi/asm/kvm.h +++ b/arch/arm64/include/uapi/asm/kvm.h @@ -158,6 +158,8 @@ struct kvm_arch_memory_slot { #define KVM_PSCI_FN_CPU_OFF KVM_PSCI_FN(1) #define KVM_PSCI_FN_CPU_ON KVM_PSCI_FN(2) #define KVM_PSCI_FN_MIGRATE KVM_PSCI_FN(3) +#define KVM_PSCI_FN_SYSTEM_OFF KVM_PSCI_FN(4) +#define KVM_PSCI_FN_SYSTEM_RESET KVM_PSCI_FN(5) #define KVM_PSCI_RET_SUCCESS 0 #define KVM_PSCI_RET_NI ((unsigned long)-1) diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index 8da5606..a5b5b6a 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -30,8 +30,13 @@ typedef int (*exit_handle_fn)(struct kvm_vcpu *, struct kvm_run *); static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run) { - if (kvm_psci_call(vcpu)) + int ret; + + ret = kvm_psci_call(vcpu); + if (ret == 0) return 1; + else if (ret > 0) + return 0; kvm_inject_undefined(vcpu); return 1; @@ -39,9 +44,6 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run) static int handle_smc(struct kvm_vcpu *vcpu, struct kvm_run *run) { - if (kvm_psci_call(vcpu)) - return 1; - kvm_inject_undefined(vcpu); return 1; }