From patchwork Tue Jul 18 16:58:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9849009 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 13FF4600CC for ; Tue, 18 Jul 2017 17:03:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1D292857E for ; Tue, 18 Jul 2017 17:03:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4E51285D1; Tue, 18 Jul 2017 17:03:07 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 8EBFF285D8 for ; Tue, 18 Jul 2017 17:03:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752431AbdGRRAd (ORCPT ); Tue, 18 Jul 2017 13:00:33 -0400 Received: from mail-it0-f44.google.com ([209.85.214.44]:37782 "EHLO mail-it0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752417AbdGRRA2 (ORCPT ); Tue, 18 Jul 2017 13:00:28 -0400 Received: by mail-it0-f44.google.com with SMTP id v127so6950695itd.0 for ; Tue, 18 Jul 2017 10:00:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=A5YKrD4BtfvlL3J+aGGhT8lU0VAdDRDlOkZU8kaE8W0=; b=RRIsYyXZk0ZaC61bIj5a7z1oKwvvUJszTVEwlkcVnk39LamkoxelynQ28vW/RYbMdg +JXXSQarnXBbqjH1uvCdX+804N6HAJUt+ieOSJX6TiyqMKXFR2BW1FJ4JgWC7EzqBM/b /51qfbOqbkuTTkpRYuQqICwWWbeOvuFFLRrJI= 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=A5YKrD4BtfvlL3J+aGGhT8lU0VAdDRDlOkZU8kaE8W0=; b=WMN51z7rhpH/WKsHlAVpf6wtBP0pL3PIkbTTENpNCAB3KSwkdO/YCPKyHgb+jzsZV1 4GFy+juAMAcezlUxEazSAuYthUg6D7hf/fo99xqiNfIILl3Rxt5SP0IAmVaYJIaIqrFF kk5uJE8ZjnFzOGcTwuIXdhs2kG6STHslPLDyiSb5oDlsp+HH8H0Ate0ofbZ6bGg4X9lD 6Mk7UqKP/wUpPNaO7lqbD9GMCFazRBtn7GLb67muBQseqWM20tahEZDrLmG/fq3DcTmH K/hdaWAHY5tREymIRL9x6n9dPswwcD1beRTl1Bi7rNZhOQBXD3TMTiNylWdV3/ZU7ZZ2 /lyg== X-Gm-Message-State: AIVw112NdOwYokBPf615sh+htTTf7UqgBS5ejHwD7AlSD9ebTJDvBzAX cQYAMPZ6Guv2niQl X-Received: by 10.36.129.2 with SMTP id q2mr3548517itd.80.1500397228232; Tue, 18 Jul 2017 10:00:28 -0700 (PDT) Received: from node.jintackl-qv26972.kvmarm-pg0.wisc.cloudlab.us (c220g1-030822.wisc.cloudlab.us. [128.104.222.82]) by smtp.gmail.com with ESMTPSA id j96sm1413075ioo.49.2017.07.18.10.00.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 10:00:26 -0700 (PDT) From: Jintack Lim To: kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com Cc: corbet@lwn.net, pbonzini@redhat.com, rkrcmar@redhat.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, akpm@linux-foundation.org, mchehab@kernel.org, cov@codeaurora.org, daniel.lezcano@linaro.org, david.daney@cavium.com, mark.rutland@arm.com, suzuki.poulose@arm.com, stefan@hello-penguin.com, andy.gross@linaro.org, wcohen@redhat.com, ard.biesheuvel@linaro.org, shankerd@codeaurora.org, vladimir.murzin@arm.com, james.morse@arm.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jintack Lim Subject: [RFC PATCH v2 30/38] KVM: arm64: Allow the virtual EL2 to access EL2 states without trap Date: Tue, 18 Jul 2017 11:58:56 -0500 Message-Id: <1500397144-16232-31-git-send-email-jintack.lim@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500397144-16232-1-git-send-email-jintack.lim@linaro.org> References: <1500397144-16232-1-git-send-email-jintack.lim@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When the virtual E2H bit is set, we can support EL2 register accesses via EL1 registers from the virtual EL2 by doing trap-and-emulate. A better alternative, however, is to allow the virtual EL2 to access EL2 register states without trap. This can be easily achieved by not traping EL1 registers since those registers already have EL2 register states. Signed-off-by: Jintack Lim --- arch/arm64/kvm/hyp/switch.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index d513da9..fffd0c7 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -74,6 +74,7 @@ static hyp_alternate_select(__activate_traps_arch, static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu) { u64 val; + u64 vhcr_el2; /* * We are about to set CPTR_EL2.TFP to trap all floating point @@ -89,8 +90,26 @@ static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu) write_sysreg(1 << 30, fpexc32_el2); isb(); } - if (vcpu_mode_el2(vcpu)) - val |= HCR_TVM | HCR_TRVM; + + if (is_hyp_ctxt(vcpu)) { + /* + * For a guest hypervisor on v8.0, trap and emulate the EL1 + * virtual memory control register accesses. + */ + if (!vcpu_el2_e2h_is_set(vcpu)) + val |= HCR_TVM | HCR_TRVM; + /* + * For a guest hypervisor on v8.1 (VHE), allow to access the + * EL1 virtual memory control registers natively. These accesses + * are to access EL2 register states. + * Note that we stil need to respect the virtual HCR_EL2 state. + */ + else { + vhcr_el2 = vcpu_sys_reg(vcpu, HCR_EL2); + val |= vhcr_el2 & (HCR_TVM | HCR_TRVM); + } + } + write_sysreg(val, hcr_el2); /* Trap on AArch32 cp15 c15 accesses (EL1 or EL0) */ write_sysreg(1 << 15, hstr_el2);