From patchwork Mon Jan 9 06:24:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9503967 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 92C3B6075F for ; Mon, 9 Jan 2017 06:34:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 839B7280D0 for ; Mon, 9 Jan 2017 06:34:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 77FE42811C; Mon, 9 Jan 2017 06:34:02 +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 9ABE32817F for ; Mon, 9 Jan 2017 06:34:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161581AbdAIGd4 (ORCPT ); Mon, 9 Jan 2017 01:33:56 -0500 Received: from outprodmail01.cc.columbia.edu ([128.59.72.39]:38426 "EHLO outprodmail01.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939741AbdAIG0R (ORCPT ); Mon, 9 Jan 2017 01:26:17 -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 v096PXvq017320 for ; Mon, 9 Jan 2017 01:26:15 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id 5ECD289 for ; Mon, 9 Jan 2017 01:26:15 -0500 (EST) Received: from sendprodmail04.cc.columbia.edu (sendprodmail04.cc.columbia.edu [128.59.72.16]) by hazelnut (Postfix) with ESMTP id 3402C8F for ; Mon, 9 Jan 2017 01:26:15 -0500 (EST) Received: from mail-qt0-f198.google.com (mail-qt0-f198.google.com [209.85.216.198]) by sendprodmail04.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096QFxc005351 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:26:15 -0500 Received: by mail-qt0-f198.google.com with SMTP id l7so63078686qtd.2 for ; Sun, 08 Jan 2017 22:26:15 -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=Gn0TlZAhyrgr4rmfLx4S/Sp5aBBKM2bUiFIq8ZmXwvI=; b=kzRqLezgzsS4jQnsQqfGa/mYkjy+l+VLJ1ykHZ0O+hIQxVKkPbzGzDUfb5uDQrKp9T FVzqPGMUt7QmGDOxur8+CzSebZ51Hpxtb3EZdPD/VW+OYj0UlAGsh73stXDvZHgebcyl 0cqPvszXzxIFQOaW59xVGGilOdvoxYKkGTE9mV6vZEOJ0PAvhf9a+S66gdxoGgJDZcw4 BwTJ5vs1TgQ3fIWYbdrhschweZgl1niuJkqlvhvNAy4zGHet/cODWWqHRP2+4tm6BKPv uKyW1oeUgcz4PCHN+CKSL0mPxYvhx/+GUNg1kLS0pVcKUA/MIke+W0KUFu6GkzMCbP3I CjZw== X-Gm-Message-State: AIkVDXJQ+rnDmAjslYU+kqe9bPC0KAP9uiztdWlEhQdNGtnq1vuwHHID/gRoD9vbN+SzGXNjzi9vF47BKM2194xIsqBBhMWtCnp3vYy3HWDL/AkhX4l5U0IM7rD3Bs7yAdfkfgelTVTJJls= X-Received: by 10.55.176.194 with SMTP id z185mr1488663qke.26.1483943157415; Sun, 08 Jan 2017 22:25:57 -0800 (PST) X-Received: by 10.55.176.194 with SMTP id z185mr1488652qke.26.1483943157268; Sun, 08 Jan 2017 22:25:57 -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.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Jan 2017 22:25:56 -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 19/55] KVM: arm64: Trap CPACR_EL1 access in virtual EL2 Date: Mon, 9 Jan 2017 01:24:15 -0500 Message-Id: <1483943091-1364-20-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 For the same reason we trap virtual memory register accesses in virtual EL2, we trap CPACR_EL1 access too. Basically, we don't want the guest hypervisor to access the real CPACR_EL1, which is used to emulate virtual EL2. Instead, we want it to access virtual CPACR_EL1 which is used to run software in EL0/EL1 from the guest hypervisor's perspective. Signed-off-by: Jintack Lim --- arch/arm64/kvm/hyp/switch.c | 10 +++++++--- arch/arm64/kvm/sys_regs.c | 10 +++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index c05c48f..b7c8c30 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -41,7 +41,8 @@ bool __hyp_text __fpsimd_enabled(void) return __fpsimd_is_enabled()(); } -static void __hyp_text __activate_traps_vhe(void) +static void __hyp_text __activate_traps_vhe(struct kvm_vcpu *vcpu) + { u64 val; @@ -53,12 +54,15 @@ static void __hyp_text __activate_traps_vhe(void) write_sysreg(__kvm_hyp_vector, vbar_el1); } -static void __hyp_text __activate_traps_nvhe(void) +static void __hyp_text __activate_traps_nvhe(struct kvm_vcpu *vcpu) + { u64 val; val = CPTR_EL2_DEFAULT; val |= CPTR_EL2_TTA | CPTR_EL2_TFP; + if (vcpu_mode_el2(vcpu)) + val |= CPTR_EL2_TCPAC; write_sysreg(val, cptr_el2); } @@ -90,7 +94,7 @@ static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu) /* Make sure we trap PMU access from EL0 to EL2 */ write_sysreg(ARMV8_PMU_USERENR_MASK, pmuserenr_el0); write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2); - __activate_traps_arch()(); + __activate_traps_arch()(vcpu); } static void __hyp_text __deactivate_traps_vhe(void) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 59f9cc6..321ecbc 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -947,6 +947,14 @@ static bool access_vbar(struct kvm_vcpu *vcpu, return true; } +static bool access_cpacr(struct kvm_vcpu *vcpu, + struct sys_reg_params *p, + const struct sys_reg_desc *r) +{ + access_rw(p, &vcpu_sys_reg(vcpu, r->reg)); + return true; +} + static bool trap_el2_reg(struct kvm_vcpu *vcpu, struct sys_reg_params *p, const struct sys_reg_desc *r) @@ -1051,7 +1059,7 @@ static bool trap_el2_reg(struct kvm_vcpu *vcpu, access_vm_reg, reset_val, SCTLR_EL1, 0x00C50078 }, /* CPACR_EL1 */ { Op0(0b11), Op1(0b000), CRn(0b0001), CRm(0b0000), Op2(0b010), - NULL, reset_val, CPACR_EL1, 0 }, + access_cpacr, reset_val, CPACR_EL1, 0 }, /* TTBR0_EL1 */ { Op0(0b11), Op1(0b000), CRn(0b0010), CRm(0b0000), Op2(0b000), access_vm_reg, reset_unknown, TTBR0_EL1 },