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: 9504073 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 96B2160710 for ; Mon, 9 Jan 2017 06:42:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8709A280DE for ; Mon, 9 Jan 2017 06:42:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BADC2811C; Mon, 9 Jan 2017 06:42:16 +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=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3A3AE280DE for ; Mon, 9 Jan 2017 06:42:16 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cQTep-0004km-A4; Mon, 09 Jan 2017 06:42:15 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cQTPa-0002bh-Ar for linux-arm-kernel@bombadil.infradead.org; Mon, 09 Jan 2017 06:26:30 +0000 Received: from outprodmail01.cc.columbia.edu ([128.59.72.39]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cQTPU-0005EQ-ED for linux-arm-kernel@lists.infradead.org; Mon, 09 Jan 2017 06:26:26 +0000 Received: from hazelnut (hazelnut.cc.columbia.edu [128.59.213.250]) by outprodmail01.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096PWYZ017300 for ; Mon, 9 Jan 2017 01:26:01 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id B8FAF8C 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 877AE8F for ; Mon, 9 Jan 2017 01:26:01 -0500 (EST) Received: from mail-qt0-f200.google.com (mail-qt0-f200.google.com [209.85.216.200]) by sendprodmail04.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096Q1Us004985 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:26:01 -0500 Received: by mail-qt0-f200.google.com with SMTP id l7so63076801qtd.2 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=LFd3U/7u7CUwH1gGuimIGTglgtJU+5Z+IQvAaVBynGJwHLEErxHQYhuzTh8ze0suCI g12XX+FkD5kXQBaS01T5ZjPpYltZNs6Ifpu59ZT2KcbY3jn5W4nDZPzpYEV8hsZP8afz 53rw5CPZyR1IegOlal+5rhom7iAIxzLOaOQVwpOk7t5sFLEjFjz1OL90ywn2IRtbx9WV 99fyeAA3hqjdctq2H44vfMTKmUXKeLclThmW+yZitYCTwNe4yES5RivLQVIbqgEfsOpX 505oISNI0IB7TVADHaiJiVIm9Ue/Agn6hF0By/yFROG6llYwlpCjJjI5yEJ2SIAnQPvr 2IBQ== X-Gm-Message-State: AIkVDXKtHZuQV6Zn4no51zmPlQ2wic/2PlGtZWX4iemH+eu5aIyqd81LnHPwlbznNfxP1vW1WyYj5gaRn02uBE61NdhKhNwktAWdNfGDPmYlnrVlPa8sV11fhPuj2/CrrGV1kcepW0TK6HYg505j22Ya/9yOx83/lpSjew== X-Received: by 10.55.113.130 with SMTP id m124mr85031045qkc.116.1483943161125; 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 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170109_012624_618861_88D8CEAB X-CRM114-Status: GOOD ( 16.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jintack@cs.columbia.edu MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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; } /**