From patchwork Tue Jul 18 16:58:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9849077 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 3BCD2600CC for ; Tue, 18 Jul 2017 17:08:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2098623B34 for ; Tue, 18 Jul 2017 17:08:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 150A7285BA; Tue, 18 Jul 2017 17:08:19 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=unavailable 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 B9D8023B34 for ; Tue, 18 Jul 2017 17:08:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752523AbdGRRHZ (ORCPT ); Tue, 18 Jul 2017 13:07:25 -0400 Received: from mail-it0-f50.google.com ([209.85.214.50]:35794 "EHLO mail-it0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752293AbdGRRAO (ORCPT ); Tue, 18 Jul 2017 13:00:14 -0400 Received: by mail-it0-f50.google.com with SMTP id h199so12465175ith.0 for ; Tue, 18 Jul 2017 10:00:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OMMwJIP2lAvb8eM2MuQ9xHEkI/X6+vKdg6iYhUg/Upk=; b=g0tmSGMRznL6NWHk8Oiqy3dogl+T4E33annfZZrEgmN2er5nKhjiKCZD6D75oykutH cfnoDZROeuVFZLPOPNpM1pc3u5TiA5NoYeMkToj04XkItwwPFH5AKyB5I+hjTQ+0LQ6T 5ylgjzmuSqo3+RLSHY2tWZYvAOdQBATk+/39I= 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=OMMwJIP2lAvb8eM2MuQ9xHEkI/X6+vKdg6iYhUg/Upk=; b=IzIwTf/QdDKX3jhInC63rWcJstikA73QgfElervnOuux8Pml/w1QCK7/6koZ6eZYVr zAR6avyVW5J3VVQH5i58u2wxW+L4xkCps2ymMhuAXqwQ5J9WULhsaMIa36SxLh2TEqB3 THwXRlUl6QDbc7UV3jIGLV++qcs8+h8jm7sYwizXwlEP/nz+bfLkEdYcIhOWChfsO6nO 9XWjPBcFrU28j8yqjRQKf63DF5IH84J9EnIROgcCL/1B28H9Hhedtw69RiqvNi+Zn30K MenSAViKJJuI/1v5WRGIrXjc1tAVx2NnJFJM/PSN+YhVFEeAS8Tsr0/Jo+nj+YPm/VCY ONuQ== X-Gm-Message-State: AIVw111RerayOGj88z/SYEs7Oi4g8mlv7XjgSBnvaPR09jb3LjWi+6w+ AXLSjMIXS0g/+v2I X-Received: by 10.36.116.22 with SMTP id o22mr3178347itc.74.1500397212739; Tue, 18 Jul 2017 10:00:12 -0700 (PDT) Received: from node.jintackl-qv26972.kvmarm-pg0.wisc.cloudlab.us (c220g1-030822.wisc.cloudlab.us. [128.104.222.82]) by smtp.gmail.com with ESMTPSA id j96sm1413075ioo.49.2017.07.18.10.00.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 10:00:12 -0700 (PDT) From: Jintack Lim To: kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com Cc: corbet@lwn.net, pbonzini@redhat.com, rkrcmar@redhat.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, akpm@linux-foundation.org, mchehab@kernel.org, cov@codeaurora.org, daniel.lezcano@linaro.org, david.daney@cavium.com, mark.rutland@arm.com, suzuki.poulose@arm.com, stefan@hello-penguin.com, andy.gross@linaro.org, wcohen@redhat.com, ard.biesheuvel@linaro.org, shankerd@codeaurora.org, vladimir.murzin@arm.com, james.morse@arm.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jintack Lim Subject: [RFC PATCH v2 22/38] KVM: arm64: Handle PSCI call via smc from the guest Date: Tue, 18 Jul 2017 11:58:48 -0500 Message-Id: <1500397144-16232-23-git-send-email-jintack.lim@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500397144-16232-1-git-send-email-jintack.lim@linaro.org> References: <1500397144-16232-1-git-send-email-jintack.lim@linaro.org> 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 if EL3 is not implemented. However, when we come to provide the virtual EL2 mode to the VM, the host OS inside the VM 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 instruction 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 | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index d19e253..6cf6b93 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -53,8 +53,28 @@ 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; + } + kvm_skip_instr(vcpu, kvm_vcpu_trap_il_is32bit(vcpu)); + + return ret; } /*