From patchwork Mon Jan 9 06:24:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 90339 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp706929qgi; Sun, 8 Jan 2017 22:27:21 -0800 (PST) X-Received: by 10.99.19.65 with SMTP id 1mr101178613pgt.153.1483943241633; Sun, 08 Jan 2017 22:27:21 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id t11si64750850plm.267.2017.01.08.22.27.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 08 Jan 2017 22:27:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org 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 1cQTQM-0003um-1H; Mon, 09 Jan 2017 06:27:18 +0000 Received: from outprodmail02.cc.columbia.edu ([128.59.72.51]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cQTPA-0001z2-3E for linux-arm-kernel@lists.infradead.org; Mon, 09 Jan 2017 06:26:06 +0000 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 v096PXn1005357 for ; Mon, 9 Jan 2017 01:25:44 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id 5B60488 for ; Mon, 9 Jan 2017 01:25:44 -0500 (EST) Received: from sendprodmail01.cc.columbia.edu (sendprodmail01.cc.columbia.edu [128.59.72.13]) by hazelnut (Postfix) with ESMTP id 367F78C for ; Mon, 9 Jan 2017 01:25:44 -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 v096Phng040662 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:25:44 -0500 Received: by mail-qk0-f198.google.com with SMTP id a16so37630706qkc.6 for ; Sun, 08 Jan 2017 22:25:44 -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=+iKxvER5+wD2v6eB4z70wj1ZgT1B1wrePglRP2x690Y=; b=NRfaB93xJDHJwSDl0omuF8sVopkOaaffjppwNP+RgYqyr9xe8cxxM/pH21bQglOi+i 8uxTCRUzvGXEfRTT/CWBPjTPHqyBz1+xAwr7h35txZIQMLoQ8kJ95esj1pUbk/PZyZFk bfonU1T2kXs+ukyGkWOcsTSobK0KN85lyIkLxhpxfoFzYU2osg7Murl6zcrS7qvP9oHh 9TI2I1hh40G8TO/ZaD+j00p6U3jbsKijlDoTljj3FqbzQBhIqMM3rKJFbDvgn/Azhg3M 7IWbPA1g9/Wt3Jkia2f652/A/CrQJn+U/BVozc4l36/S1d0unuf1NFhewsluxusKKdmQ cufw== X-Gm-Message-State: AIkVDXJ9OyJScJeDSthFq4z54maXtIcwbI5AfqpE61HmzPr8hDHq/uzaw/UCOzFH2k4zuRkxqpH019j7YQsauUvG2ePYnYe1mQDaNNjVHUNkFy4XzOwUNS0qDnaI4GO0a7V8ISir+c13T7Rmw/0ONmH9sjsrkZ82ZTWeRw== X-Received: by 10.200.42.202 with SMTP id c10mr80493662qta.251.1483943143746; Sun, 08 Jan 2017 22:25:43 -0800 (PST) X-Received: by 10.200.42.202 with SMTP id c10mr80493652qta.251.1483943143543; Sun, 08 Jan 2017 22:25:43 -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.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Jan 2017 22:25:42 -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 10/55] KVM: arm64: Synchronize EL1 system registers on virtual EL2 entry and exit Date: Mon, 9 Jan 2017 01:24:06 -0500 Message-Id: <1483943091-1364-11-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_222604_464199_0F433ED3 X-CRM114-Status: GOOD ( 16.68 ) X-Spam-Score: -5.3 (-----) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-5.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.5 RCVD_IN_SORBS_SPAM RBL: SORBS: sender is a spam source [209.85.220.198 listed in dnsbl.sorbs.net] -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [128.59.72.51 listed in list.dnswl.org] -3.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 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+patch=linaro.org@lists.infradead.org From: Christoffer Dall When running in virtual EL2 we use the shadow EL1 systerm register array for the save/restore process, so that hardware and especially the memory subsystem behaves as code written for EL2 expects while really running in EL1. This works great for EL1 system register accesses that we trap, because these accesses will be written into the virtual state for the EL1 system registers used when eventually switching the VCPU mode to EL1. However, there was a collection of EL1 system registers which we do not trap, and as a consequence all save/restore operations of these registers were happening locally in the shadow array, with no benefit to software actually running in virtual EL1 at all. To fix this, simply synchronize the shadow and real EL1 state for these registers on entry/exit to/from virtual EL2 state. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm64/kvm/context.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) -- 1.9.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm64/kvm/context.c b/arch/arm64/kvm/context.c index 2e9e386..0025dd9 100644 --- a/arch/arm64/kvm/context.c +++ b/arch/arm64/kvm/context.c @@ -88,6 +88,51 @@ static void create_shadow_el1_sysregs(struct kvm_vcpu *vcpu) s_sys_regs[CPACR_EL1] = cptr_el2_to_cpacr_el1(el2_regs[CPTR_EL2]); } +/* + * List of EL1 registers which we allow the virtual EL2 mode to access + * directly without trapping and which haven't been paravirtualized. + * + * Probably CNTKCTL_EL1 should not be copied but be accessed via trap. Because, + * the guest hypervisor running in EL1 can be affected by event streams + * configured via CNTKCTL_EL1, which it does not expect. We don't have a + * mechanism to trap on CNTKCTL_EL1 as of now (v8.3), keep it in here instead. + */ +static const int el1_non_trap_regs[] = { + CNTKCTL_EL1, + CSSELR_EL1, + PAR_EL1, + TPIDR_EL0, + TPIDR_EL1, + TPIDRRO_EL0 +}; + +/** + * sync_shadow_el1_state - Going to/from the virtual EL2 state, sync state + * @vcpu: The VCPU pointer + * @setup: True, if on the way to the guest (called from setup) + * False, if returning form the guet (calld from restore) + * + * Some EL1 registers are accessed directly by the virtual EL2 mode because + * they in no way affect execution state in virtual EL2. However, we must + * still ensure that virtual EL2 observes the same state of the EL1 registers + * as the normal VM's EL1 mode, so copy this state as needed on setup/restore. + */ +static void sync_shadow_el1_state(struct kvm_vcpu *vcpu, bool setup) +{ + u64 *sys_regs = vcpu->arch.ctxt.sys_regs; + u64 *s_sys_regs = vcpu->arch.ctxt.shadow_sys_regs; + int i; + + for (i = 0; i < ARRAY_SIZE(el1_non_trap_regs); i++) { + const int sr = el1_non_trap_regs[i]; + + if (setup) + s_sys_regs[sr] = sys_regs[sr]; + else + sys_regs[sr] = s_sys_regs[sr]; + } +} + /** * kvm_arm_setup_shadow_state -- prepare shadow state based on emulated mode * @vcpu: The VCPU pointer @@ -107,6 +152,7 @@ void kvm_arm_setup_shadow_state(struct kvm_vcpu *vcpu) else ctxt->hw_pstate |= PSR_MODE_EL1t; + sync_shadow_el1_state(vcpu, true); create_shadow_el1_sysregs(vcpu); ctxt->hw_sys_regs = ctxt->shadow_sys_regs; ctxt->hw_sp_el1 = ctxt->el2_regs[SP_EL2]; @@ -125,6 +171,7 @@ void kvm_arm_restore_shadow_state(struct kvm_vcpu *vcpu) { struct kvm_cpu_context *ctxt = &vcpu->arch.ctxt; if (unlikely(vcpu_mode_el2(vcpu))) { + sync_shadow_el1_state(vcpu, false); *vcpu_cpsr(vcpu) &= PSR_MODE_MASK; *vcpu_cpsr(vcpu) |= ctxt->hw_pstate & ~PSR_MODE_MASK; ctxt->el2_regs[SP_EL2] = ctxt->hw_sp_el1;