From patchwork Mon Jan 9 06:24:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9503843 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 E8FE060757 for ; Mon, 9 Jan 2017 06:28:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D950F280D0 for ; Mon, 9 Jan 2017 06:28:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD7FC2815E; Mon, 9 Jan 2017 06:28:38 +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 6409F280D0 for ; Mon, 9 Jan 2017 06:28:38 +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 1cQTRa-0005po-MM; Mon, 09 Jan 2017 06:28:34 +0000 Received: from outprodmail01.cc.columbia.edu ([128.59.72.39]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cQTPB-0001y5-L7 for linux-arm-kernel@lists.infradead.org; Mon, 09 Jan 2017 06:26:08 +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 v096PX6b017321 for ; Mon, 9 Jan 2017 01:25:41 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id CF5068D for ; Mon, 9 Jan 2017 01:25:41 -0500 (EST) Received: from sendprodmail01.cc.columbia.edu (sendprodmail01.cc.columbia.edu [128.59.72.13]) by hazelnut (Postfix) with ESMTP id A4B5B8E for ; Mon, 9 Jan 2017 01:25:41 -0500 (EST) Received: from mail-qk0-f198.google.com (mail-qk0-f198.google.com [209.85.220.198]) by sendprodmail01.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096PfPu040617 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:25:41 -0500 Received: by mail-qk0-f198.google.com with SMTP id d75so52975193qkc.0 for ; Sun, 08 Jan 2017 22:25:41 -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=o9kwvAhK/55Ebidna7vjgevhaQVg/d74HviugU/HtKo=; b=DcGyl4WvvpxD8g2cr04XmhJmKe1ToQ+aib1zxuKb+ljPfwFANuFJjh8JNtc4JQ4NEB KUn2KaNoUa208tw3pxyp6KqxO26Xel3ZHE8i3TkDnDQs8gbAjAOCV8tGkY77MTsgWiXU /cCVpW2JjabAbrmyhqAIAcfm/a+bKRbKrLkL3urCKT1olFnBA6VY4bobSKCOVPzoqHqf ZCf93LyPcyc32C4wFJqnoMLD5/mvDGOeJWr6QOYQvL3nDchIKh9V975IcKl8oMdo8Q7D 0I2/vdwam9+cd5XRivOb2CmpnVIcS9I8OASvIATHjNHjQ5JRHvA+FGnJ1MzrXMKVLxSi pfZg== X-Gm-Message-State: AIkVDXIPu5fCI/zoRy9qNYzc1Ung7PRPK3LQJsUnLJKyr7kqd5XfBsrZvR+sXs7leafgre1ysnB2FleLevFtYFSgh6VGYp29ebgE5iDeySK7wbWcErHtjzmKNWErg5dujgQamUmp6JH4OHDcryKB5AVEcGVxGsHrNod4Eg== X-Received: by 10.55.107.4 with SMTP id g4mr51222175qkc.75.1483943141262; Sun, 08 Jan 2017 22:25:41 -0800 (PST) X-Received: by 10.55.107.4 with SMTP id g4mr51222146qkc.75.1483943141112; Sun, 08 Jan 2017 22:25:41 -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.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Jan 2017 22:25:40 -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 08/55] KVM: arm64: Set virtual EL2 context depending on the guest exception level Date: Mon, 9 Jan 2017 01:24:04 -0500 Message-Id: <1483943091-1364-9-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.13 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170108_222605_917186_A5F9496D X-CRM114-Status: GOOD ( 11.81 ) 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 From: Christoffer Dall Set up virutal EL2 context to hardware if the guest exception level is EL2. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm64/kvm/context.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/context.c b/arch/arm64/kvm/context.c index 320afc6..acb4b1e 100644 --- a/arch/arm64/kvm/context.c +++ b/arch/arm64/kvm/context.c @@ -25,10 +25,25 @@ void kvm_arm_setup_shadow_state(struct kvm_vcpu *vcpu) { struct kvm_cpu_context *ctxt = &vcpu->arch.ctxt; + if (unlikely(vcpu_mode_el2(vcpu))) { + ctxt->hw_pstate = *vcpu_cpsr(vcpu) & ~PSR_MODE_MASK; - ctxt->hw_pstate = *vcpu_cpsr(vcpu); - ctxt->hw_sys_regs = ctxt->sys_regs; - ctxt->hw_sp_el1 = ctxt->gp_regs.sp_el1; + /* + * We emulate virtual EL2 mode in hardware EL1 mode using the + * same stack pointer mode as the guest expects. + */ + 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 = ctxt->el2_regs[SP_EL2]; + } else { + ctxt->hw_pstate = *vcpu_cpsr(vcpu); + ctxt->hw_sys_regs = ctxt->sys_regs; + ctxt->hw_sp_el1 = ctxt->gp_regs.sp_el1; + } } /** @@ -38,9 +53,14 @@ void kvm_arm_setup_shadow_state(struct kvm_vcpu *vcpu) void kvm_arm_restore_shadow_state(struct kvm_vcpu *vcpu) { struct kvm_cpu_context *ctxt = &vcpu->arch.ctxt; - - *vcpu_cpsr(vcpu) = ctxt->hw_pstate; - ctxt->gp_regs.sp_el1 = ctxt->hw_sp_el1; + if (unlikely(vcpu_mode_el2(vcpu))) { + *vcpu_cpsr(vcpu) &= PSR_MODE_MASK; + *vcpu_cpsr(vcpu) |= ctxt->hw_pstate & ~PSR_MODE_MASK; + ctxt->el2_regs[SP_EL2] = ctxt->hw_sp_el1; + } else { + *vcpu_cpsr(vcpu) = ctxt->hw_pstate; + ctxt->gp_regs.sp_el1 = ctxt->hw_sp_el1; + } } void kvm_arm_init_cpu_context(kvm_cpu_context_t *cpu_ctxt)