From patchwork Mon Jan 9 06:24:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9504041 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 3C53C60757 for ; Mon, 9 Jan 2017 06:39:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AF4228112 for ; Mon, 9 Jan 2017 06:39:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D0EE2815E; Mon, 9 Jan 2017 06:39: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=-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 92B86280DE for ; Mon, 9 Jan 2017 06:39:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S939397AbdAIGZo (ORCPT ); Mon, 9 Jan 2017 01:25:44 -0500 Received: from outprodmail01.cc.columbia.edu ([128.59.72.39]:37983 "EHLO outprodmail01.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939367AbdAIGZk (ORCPT ); Mon, 9 Jan 2017 01:25:40 -0500 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 v096PXK1017324 for ; Mon, 9 Jan 2017 01:25:39 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id 459F188 for ; Mon, 9 Jan 2017 01:25:39 -0500 (EST) Received: from sendprodmail04.cc.columbia.edu (sendprodmail04.cc.columbia.edu [128.59.72.16]) by hazelnut (Postfix) with ESMTP id 24DF28B for ; Mon, 9 Jan 2017 01:25:39 -0500 (EST) Received: from mail-qt0-f199.google.com (mail-qt0-f199.google.com [209.85.216.199]) by sendprodmail04.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096PcNo004467 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:25:39 -0500 Received: by mail-qt0-f199.google.com with SMTP id x49so82673115qtc.7 for ; Sun, 08 Jan 2017 22:25:39 -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=V3b6tgAtbQnU61gfPeTsMhd9QPDt0SVJZLHP8RaE8RA=; b=ZSaP3ntiR0G+OE93pDyiX6Pygo3iZDdakA1D+mSmIU6aRClpRHFSFLYtKgSskPxei3 zYnwbRkiMh86XCyC147lpEmfErjV7l7tPog8/TYDeSM1eZUaN2pgV44eOkjjwuJ9JwF9 IE6nceuAwdIKr/if30m/om/dgsMR+czDVtoKrby3DAx5m2dlDuFN+ph/WUKL0SOa8FqE O3tcrISZDmxTWKa0mWXwEAVz6mnXlmzbz6oeBSWVEjVhy74nBVh3FbLSSTg8fOo1YIGk fBm1D+uHZT42Umj2eUd8YkgLSbLQmf2RmYpMYPgk46nb2aZRujngEDt7klTtKlRKODgA u+iw== X-Gm-Message-State: AIkVDXKav+FTLnjOvXNByvESxcHNNTLjuyrcJysx42Imd8lEK139G77U/KP+XqPzRUEE/r+zgXQqRBvsSvdYDlEaOxB58e2C1amJv0m25fwIZm2Hz898dK7RfoIEOJ8pVKrblcITOWQSyeA= X-Received: by 10.55.165.76 with SMTP id o73mr64460155qke.32.1483943138708; Sun, 08 Jan 2017 22:25:38 -0800 (PST) X-Received: by 10.55.165.76 with SMTP id o73mr64460146qke.32.1483943138550; Sun, 08 Jan 2017 22:25:38 -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.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Jan 2017 22:25:37 -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 06/55] KVM: arm64: Add EL2 execution context for nesting Date: Mon, 9 Jan 2017 01:24:02 -0500 Message-Id: <1483943091-1364-7-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 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With the nested virtualization support, the context of the guest includes EL2 register states. The host manages a set of virtual EL2 registers. In addition to that, the guest hypervisor supposed to run in EL2 is now deprivilaged and runs in EL1. So, the host also manages a set of shadow system registers to be able to run the guest hypervisor in EL1. Signed-off-by: Jintack Lim Signed-off-by: Christoffer Dall --- arch/arm64/include/asm/kvm_host.h | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index c0c8b02..ed78d73 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -146,6 +146,42 @@ enum vcpu_sysreg { NR_SYS_REGS /* Nothing after this line! */ }; +enum el2_regs { + ELR_EL2, + SPSR_EL2, + SP_EL2, + AMAIR_EL2, + MAIR_EL2, + TCR_EL2, + TTBR0_EL2, + VTCR_EL2, + VTTBR_EL2, + VMPIDR_EL2, + VPIDR_EL2, /* 10 */ + MDCR_EL2, + CNTHCTL_EL2, + CNTHP_CTL_EL2, + CNTHP_CVAL_EL2, + CNTHP_TVAL_EL2, + CNTVOFF_EL2, + ACTLR_EL2, + AFSR0_EL2, + AFSR1_EL2, + CPTR_EL2, /* 20 */ + ESR_EL2, + FAR_EL2, + HACR_EL2, + HCR_EL2, + HPFAR_EL2, + HSTR_EL2, + RMR_EL2, + RVBAR_EL2, + SCTLR_EL2, + TPIDR_EL2, /* 30 */ + VBAR_EL2, + NR_EL2_REGS /* Nothing after this line! */ +}; + /* 32bit mapping */ #define c0_MPIDR (MPIDR_EL1 * 2) /* MultiProcessor ID Register */ #define c0_CSSELR (CSSELR_EL1 * 2)/* Cache Size Selection Register */ @@ -193,6 +229,23 @@ struct kvm_cpu_context { u64 sys_regs[NR_SYS_REGS]; u32 copro[NR_COPRO_REGS]; }; + + u64 el2_regs[NR_EL2_REGS]; /* only used for nesting */ + u64 shadow_sys_regs[NR_SYS_REGS]; /* only used for virtual EL2 */ + + /* + * hw_* will be used when switching to a VM. They point to either + * the virtual EL2 or EL1/EL0 context depending on vcpu mode. + */ + + /* pointing shadow_sys_regs or sys_regs */ + u64 *hw_sys_regs; + + /* copy of either gp_regs.sp_el1 or el2_regs[SP_EL2] */ + u64 hw_sp_el1; + + /* pstate written to SPSR_EL2 */ + u64 hw_pstate; }; typedef struct kvm_cpu_context kvm_cpu_context_t; @@ -277,6 +330,7 @@ struct kvm_vcpu_arch { #define vcpu_gp_regs(v) (&(v)->arch.ctxt.gp_regs) #define vcpu_sys_reg(v,r) ((v)->arch.ctxt.sys_regs[(r)]) +#define vcpu_el2_reg(v, r) ((v)->arch.ctxt.el2_regs[(r)]) /* * CP14 and CP15 live in the same array, as they are backed by the * same system registers.