From patchwork Tue Jul 18 16:58:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 108156 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp6151977obm; Tue, 18 Jul 2017 10:02:48 -0700 (PDT) X-Received: by 10.98.245.22 with SMTP id n22mr2736047pfh.96.1500397368675; Tue, 18 Jul 2017 10:02:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500397368; cv=none; d=google.com; s=arc-20160816; b=e3gOqiH59tJNEj5yWl25yAhq74LK+q11GQQQV/LnD93fITx5T7iq4XSf9l3uWXyEbN 79/2jo9D9hzbkBtxwPXgMRMLH3PCnOS7jzPpAPrytbN8hhuPShJUrtcwJlVNxg2DeSBF t20uPpoA1fn0+A50S/yOFL4d658mqGQYY4LIe2GV9LJp4n4UDbDlmlDnReDYfruHVlC+ ng6lYKtg4UarA7GKJ3r45q5TqdT8YgL2pcvgW08yLXoas4tNIW/Py9JikqJMSIArqv1H np3XTGeLtwEWutpbeLazIh3Y14lQEZWxbsrCOMQZdTsan3L2iOQ7Hs1f4sALotRRWvDW 0eFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=vCn4E12DxjufvUUEMdlXA9xSO+EswdhWxIbmGzcWGgk=; b=eFxwLtgHAAfbG33Ug+lulmbeqq/SpQhWJdochzVGQGebcHWACTe4jqw+eDV7lSkgxy SS10ZYDjBytNHzdlqINUXUpDq7y15f1SYbyimr5NIiCI36vUU+A7UyTpAax1qLHDZ3IT YkeOWD3uGLHrjv0zgT/KzvAJbSDxxwFXTiKc2dHmCHRoftsIY/VtJbHy0ywiE+bKlx9q +ei2sd9oV2w11XGp1JPDKG7g6neadelNkT6qX7YQ2higN/H+iUJPXFG4jvv7DYLo5WMD +S8VoqNrDjHeGGzbpFvI5p1DYV4xjVlKrR3uXgfdc5aGq2SWDexx0gp3rzndpCyeQW/Y YBSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=d9LQlklf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r7si2083799pli.606.2017.07.18.10.02.48; Tue, 18 Jul 2017 10:02:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=d9LQlklf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752477AbdGRRAd (ORCPT + 25 others); Tue, 18 Jul 2017 13:00:33 -0400 Received: from mail-io0-f173.google.com ([209.85.223.173]:35624 "EHLO mail-io0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752410AbdGRRA1 (ORCPT ); Tue, 18 Jul 2017 13:00:27 -0400 Received: by mail-io0-f173.google.com with SMTP id k71so16788294iod.2 for ; Tue, 18 Jul 2017 10:00:27 -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=vCn4E12DxjufvUUEMdlXA9xSO+EswdhWxIbmGzcWGgk=; b=d9LQlklfakVOKbk0nYnEeNE4nQrmbW5DBHlPFKaplpd38BAKSIrLbnSh/E5OQ+eR9A m3Najim4F+QTd0dkedpGvpHUxNJQhEBiVZoqqig3YCnJ7RsrAE7PfLmp7kxOKFDTAElO XIzzVHGa7Nv0m7p53UNNZz/xtAOu9X3MSDEVE= 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=vCn4E12DxjufvUUEMdlXA9xSO+EswdhWxIbmGzcWGgk=; b=BmX8JeWP81IHEF4gKVP+GbspbFM5Cp5R2kp+SqMcNmp10PTjx3Lkbuleqe50Zr6KqA 1efsAyNWJZN2Pcp8HYTFlNqFDih0yO5pK7Ug79Oha+9urUmLyMhezx4J9JkaoGlJ0A73 BQ6KX0XpE5oI2YKApaeRuHjDNyBkZZYedFGjjbbt6F6wr023IfTv8+n5bX3YssOFZkTL Y3IY7sWBiZ0OMVP4c4ZtV1LMfGJ2ZugYpQODThloYj4fIEZk0El5aGsHPqonSdoBq3rf Z6/HTiI0GHfoaJ9GHshcoo0X/U65F2nOmEhjCpITsbgu6ut967gC0wWFM/pqqOonjaJn b5Ww== X-Gm-Message-State: AIVw112XWn++7jB9C/0QDt6PpKuU99T6WUIFkYivmlnMJsOqwPv6hOQm OxKh8a3c2pZZySwc X-Received: by 10.107.10.205 with SMTP id 74mr2538292iok.80.1500397225801; Tue, 18 Jul 2017 10:00:25 -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.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 10:00:24 -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 29/38] KVM: arm64: Support a VM with VHE considering EL0 of the VHE host Date: Tue, 18 Jul 2017 11:58:55 -0500 Message-Id: <1500397144-16232-30-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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On VHE systems, EL0 of the host kernel is considered as a part of 'VHE host'; The execution of EL0 is affected by system registers set by the VHE kernel including the hypervisor. To emulate this for a VM, we use the same set of system registers (i.e. shadow registers) for the virtual EL2 and EL0 execution. Note that the assumption so far is that a hypervisor in a VM always runs in the virtual EL2, and the exception level change from/to the virtual EL2 always goes through the host hypervisor. With VHE support for a VM, however, the exception level can be changed from EL0 to virtual EL2 without trapping to the host hypervisor. So, when returning from the VHE host mode, set the vcpu mode depending on the physical exception level. Signed-off-by: Jintack Lim --- arch/arm64/kvm/context.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) -- 1.9.1 diff --git a/arch/arm64/kvm/context.c b/arch/arm64/kvm/context.c index f3d3398..39bd92d 100644 --- a/arch/arm64/kvm/context.c +++ b/arch/arm64/kvm/context.c @@ -150,16 +150,18 @@ static void flush_shadow_special_regs(struct kvm_vcpu *vcpu) struct kvm_cpu_context *ctxt = &vcpu->arch.ctxt; ctxt->hw_pstate = *vcpu_cpsr(vcpu) & ~PSR_MODE_MASK; - /* - * We can emulate the guest's configuration of which - * stack pointer to use when executing in virtual EL2 by - * using the equivalent feature in EL1 to point to - * either the EL1 or EL0 stack pointer. - */ - if ((*vcpu_cpsr(vcpu) & PSR_MODE_MASK) == PSR_MODE_EL2h) - ctxt->hw_pstate |= PSR_MODE_EL1h; - else - ctxt->hw_pstate |= PSR_MODE_EL1t; + if (vcpu_mode_el2(vcpu)) { + /* + * We can emulate the guest's configuration of which + * stack pointer to use when executing in virtual EL2 by + * using the equivalent feature in EL1 to point to + * either the EL1 or EL0 stack pointer. + */ + if ((*vcpu_cpsr(vcpu) & PSR_MODE_MASK) == PSR_MODE_EL2h) + ctxt->hw_pstate |= PSR_MODE_EL1h; + else + ctxt->hw_pstate |= PSR_MODE_EL1t; + } ctxt->hw_sys_regs = ctxt->shadow_sys_regs; ctxt->hw_sp_el1 = vcpu_el2_sreg(vcpu, SP_EL2); @@ -182,8 +184,14 @@ static void sync_shadow_special_regs(struct kvm_vcpu *vcpu) { struct kvm_cpu_context *ctxt = &vcpu->arch.ctxt; - *vcpu_cpsr(vcpu) &= PSR_MODE_MASK; - *vcpu_cpsr(vcpu) |= ctxt->hw_pstate & ~PSR_MODE_MASK; + *vcpu_cpsr(vcpu) = ctxt->hw_pstate; + *vcpu_cpsr(vcpu) &= ~PSR_MODE_MASK; + /* Set vcpu exception level depending on the physical EL */ + if ((ctxt->hw_pstate & PSR_MODE_MASK) == PSR_MODE_EL0t) + *vcpu_cpsr(vcpu) |= PSR_MODE_EL0t; + else + *vcpu_cpsr(vcpu) |= PSR_MODE_EL2h; + vcpu_el2_sreg(vcpu, SP_EL2) = ctxt->hw_sp_el1; vcpu_el2_sreg(vcpu, ELR_EL2) = ctxt->hw_elr_el1; vcpu_el2_sreg(vcpu, SPSR_EL2) = ctxt->hw_spsr_el1; @@ -218,7 +226,7 @@ void kvm_arm_setup_shadow_state(struct kvm_vcpu *vcpu) { struct kvm_cpu_context *ctxt = &vcpu->arch.ctxt; - if (unlikely(vcpu_mode_el2(vcpu))) { + if (unlikely(is_hyp_ctxt(vcpu))) { flush_shadow_special_regs(vcpu); flush_shadow_el1_sysregs(vcpu); flush_shadow_non_trap_el1_state(vcpu); @@ -236,7 +244,7 @@ void kvm_arm_setup_shadow_state(struct kvm_vcpu *vcpu) */ void kvm_arm_restore_shadow_state(struct kvm_vcpu *vcpu) { - if (unlikely(vcpu_mode_el2(vcpu))) { + if (unlikely(is_hyp_ctxt(vcpu))) { sync_shadow_special_regs(vcpu); sync_shadow_non_trap_el1_state(vcpu); } else