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: 9504039 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 B1B3660757 for ; Mon, 9 Jan 2017 06:39:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1A35280DE for ; Mon, 9 Jan 2017 06:39:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 966B42815E; Mon, 9 Jan 2017 06:39:11 +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=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 1F56C280DE for ; Mon, 9 Jan 2017 06:39:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S939415AbdAIGZq (ORCPT ); Mon, 9 Jan 2017 01:25:46 -0500 Received: from outprodmail02.cc.columbia.edu ([128.59.72.51]:51843 "EHLO outprodmail02.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939372AbdAIGZm (ORCPT ); Mon, 9 Jan 2017 01:25:42 -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 v096OdxH005146 for ; Mon, 9 Jan 2017 01:25:41 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id CED1C87 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 9C23885 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 v096Pf9h040615 (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 a16so37630320qkc.6 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=Uj1bpZCDpRMY9pcJ4Zda9XkT5KYmk6GQn6S9vOLd1X+vtdJ3YwQfYqsF+GOVwFzXhc NwnLubPvRqdV2hq+O+M6fI4WNxwkVfdQIHuR4BVhknvuH2MjUDgD48+M04yJiWUPT4wk bICBWNqcbi0M1LPZLYnIDWnL5Cls6WnvYIk2iJk0r80SlLmn0GUJ5sPEdDiZeOFz+jSf 0JGBx/6Q/Bm9X3LbWuaFTk5lAFLro6EpJ7WyOAiSVsArdmK+3/g8PsiEnvt7ap21u1AP EbWr3jfBHnFR4+A9fs+tT5KHUseSSe6IvGHDK0Q5LYdr/sSbHVSerRZRrRe+iUrQOQbT Umag== X-Gm-Message-State: AIkVDXKIwVY26OhqqSARdBtrqSVO8J59VSWKIsRJuWu0wEi7vOLs7sp0B4hBHFpmq/LIL/TCQcxSnkoKGqAf/L1wRGjrBlYHyciZaW1flQ49bHaxLX49A+esTXHgcylyHQY/ycHKlIXM9/k= X-Received: by 10.55.107.4 with SMTP id g4mr51222166qkc.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 Cc: jintack@cs.columbia.edu 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 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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)