From patchwork Mon Jan 9 06:24:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9504029 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 09B2060757 for ; Mon, 9 Jan 2017 06:38:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EED00280DE for ; Mon, 9 Jan 2017 06:38:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E37042811C; Mon, 9 Jan 2017 06:38:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 66587280DE for ; Mon, 9 Jan 2017 06:38:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030754AbdAIGgb (ORCPT ); Mon, 9 Jan 2017 01:36:31 -0500 Received: from outprodmail02.cc.columbia.edu ([128.59.72.51]:52034 "EHLO outprodmail02.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939651AbdAIG0D (ORCPT ); Mon, 9 Jan 2017 01:26:03 -0500 Received: from hazelnut (hazelnut.cc.columbia.edu [128.59.213.250]) by outprodmail02.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096P408005194 for ; Mon, 9 Jan 2017 01:26:01 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id AF01682 for ; Mon, 9 Jan 2017 01:26:01 -0500 (EST) Received: from sendprodmail04.cc.columbia.edu (sendprodmail04.cc.columbia.edu [128.59.72.16]) by hazelnut (Postfix) with ESMTP id 7ED538A for ; Mon, 9 Jan 2017 01:26:01 -0500 (EST) Received: from mail-qt0-f198.google.com (mail-qt0-f198.google.com [209.85.216.198]) by sendprodmail04.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096Q1PE004983 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:26:01 -0500 Received: by mail-qt0-f198.google.com with SMTP id x49so82675926qtc.7 for ; Sun, 08 Jan 2017 22:26:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=t2VBBbSVqk/D9g2ATuMNFUA9JWJnkkxqBqlwmkxsqfM=; b=J/W3E8dqvtATFKPABHp6vbN1Nbs/K/2iCnScboo1ZIVgWY1S4GiUiaOILZO6frAvc0 ZpDkIsCABYr6AOYOqv+3lo3LnTLgWTJRzCXTeldisxuA6gYYm2UzQdX+wH3Rc6an2R5i grMNrGhe/WDBWZCIxcyDiP9ConhhsgMEPXrcWGObTR4l9brXCWzsX2U11xWgHepH1xy/ uK6F0FXzAY/BLgg/uta29fSOFhV0mVrnB9locnGdQtU3+mlpANm5dUTZcNGpjnGCjO02 avOR9aJ2T+AZohDxd4DtSkYdnOEHngShfoxt3HSrpNVnKby6onlGMANiSSCvSghzQuvI aRxA== X-Gm-Message-State: AIkVDXJhc2veE2qyAE2n5PAE7svEo8zIRzBotyb8yAr2ji6induHNIL2Zy5mzXWvrMPpzF3x3blxJ167sqxXsJfktRRR3R5khFBnkkfj55srAx8+lSYTSGzESnhgq0AwmcYCLG2aOOmCdks= X-Received: by 10.55.113.130 with SMTP id m124mr85031050qkc.116.1483943161126; Sun, 08 Jan 2017 22:26:01 -0800 (PST) X-Received: by 10.55.113.130 with SMTP id m124mr85031024qkc.116.1483943160979; Sun, 08 Jan 2017 22:26:00 -0800 (PST) Received: from jintack.cs.columbia.edu ([2001:18d8:ffff:16:21a:4aff:feaa:f900]) by smtp.gmail.com with ESMTPSA id h3sm8623257qtc.6.2017.01.08.22.25.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Jan 2017 22:26:00 -0800 (PST) From: Jintack Lim To: christoffer.dall@linaro.org, marc.zyngier@arm.com, pbonzini@redhat.com, rkrcmar@redhat.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, vladimir.murzin@arm.com, suzuki.poulose@arm.com, mark.rutland@arm.com, james.morse@arm.com, lorenzo.pieralisi@arm.com, kevin.brodsky@arm.com, wcohen@redhat.com, shankerd@codeaurora.org, geoff@infradead.org, andre.przywara@arm.com, eric.auger@redhat.com, anna-maria@linutronix.de, shihwei@cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jintack@cs.columbia.edu Subject: [RFC 22/55] KVM: arm64: Handle PSCI call from the guest Date: Mon, 9 Jan 2017 01:24:18 -0500 Message-Id: <1483943091-1364-23-git-send-email-jintack@cs.columbia.edu> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1483943091-1364-1-git-send-email-jintack@cs.columbia.edu> References: <1483943091-1364-1-git-send-email-jintack@cs.columbia.edu> X-No-Spam-Score: Local X-Scanned-By: MIMEDefang 2.78 on 128.59.72.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP VMs used to execute hvc #0 for the psci call. However, when we come to provide virtual EL2 to the VM, the host OS inside the VM also calls kvm_call_hyp which is also hvc #0. So, it's hard to differentiate between them from the host hypervisor's point of view. So, let the VM execute smc for the psci call. On ARMv8.3, even if EL3 is not implemented, a smc instruction executed at non-secure EL1 is trapped to EL2 if HCR_EL2.TSC==1, rather than being treated as UNDEFINED. So, the host hypervisor can handle this psci call without any confusion. Signed-off-by: Jintack Lim --- arch/arm64/kvm/handle_exit.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index 208be16..ce6d2ef 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -64,8 +64,27 @@ static int handle_hvc(struct kvm_vcpu *vcpu, struct kvm_run *run) static int handle_smc(struct kvm_vcpu *vcpu, struct kvm_run *run) { - kvm_inject_undefined(vcpu); - return 1; + int ret; + + /* If imm is non-zero, it's not defined */ + if (kvm_vcpu_hvc_get_imm(vcpu)) { + kvm_inject_undefined(vcpu); + return 1; + } + + /* + * If imm is zero, it's a psci call. + * Note that on ARMv8.3, even if EL3 is not implemented, SMC executed + * at Non-secure EL1 is trapped to EL2 if HCR_EL2.TSC==1, rather than + * being treated as UNDEFINED. + */ + ret = kvm_psci_call(vcpu); + if (ret < 0) { + kvm_inject_undefined(vcpu); + return 1; + } + + return ret; } /**