From patchwork Thu Dec 7 17:06:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10100187 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 726CE60360 for ; Thu, 7 Dec 2017 17:07:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C1D9284CE for ; Thu, 7 Dec 2017 17:07:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5100C284F5; Thu, 7 Dec 2017 17:07:35 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham 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 A5253284CE for ; Thu, 7 Dec 2017 17:07:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932295AbdLGRH2 (ORCPT ); Thu, 7 Dec 2017 12:07:28 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:43633 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932222AbdLGRHZ (ORCPT ); Thu, 7 Dec 2017 12:07:25 -0500 Received: by mail-wm0-f67.google.com with SMTP id n138so14266360wmg.2 for ; Thu, 07 Dec 2017 09:07:24 -0800 (PST) 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=xgRlOlyxgYLnF1Hny53g2NIDwQ7HPsnSpsoYL3hJpqM=; b=WKRtQNxYzCY5ziER8p+TTavaLPHXStr0fvWQLuTna+LdkNkrUJ/sgFigKcvaE1xQQM Dm3QGvnKoDiltI1hhsh/2WaXGnbo3vlUBKPpXsrqKMsK6O+VhHxW7HA+TAdyisY/Wmt0 /hBNGtQ2xkr6wme+PLrEGdFEpSJ7vcNF4hTko= 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=xgRlOlyxgYLnF1Hny53g2NIDwQ7HPsnSpsoYL3hJpqM=; b=f6DidMVW90IitUpMXWXvUtdkn/e+jc9q127J0m1K6GPU4AfBd1fo9vwlR7TufHKkaz 9nWab09yREpchHagEt1M/Ur6Oim95n6nmO3FYdvvSPNkxFWHixERgnvMFbFbLYZIew9w UaXKvnkMexoCXCVEL+VeJcmNuwUEVb7E+OdeBV8FFwMDZEQZZDocoFHf5SxZOUN4y5// f+JCvboU5xBiHFzSCUfCZONoOdwvxOVy1wC4MAGdJqHUd+GPu4pg9+6S6J1JZViiRpGd QkIS4lE+PyKlQjXUKqntAgpoU8ChKWyToIzvtGX7sSyia4A/T1w56HZHPCezhx8TVJdX LzOw== X-Gm-Message-State: AJaThX7AyUgNBy5FhYD1+sZmrg28Kdvxvgf3vMiQ/eVM5TeJ9ITQKLkO cKwzt3TuZf0+5FY/YJjylIdWRg== X-Google-Smtp-Source: AGs4zMaUaweY26uUII1WqgqNBm2GEiCHzO+LuNb4KWp/A7drdCk8vsuZrKeJlBiiZSjGfuFwuJHTFg== X-Received: by 10.80.150.70 with SMTP id y64mr35475069eda.223.1512666443970; Thu, 07 Dec 2017 09:07:23 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id a16sm2868270edd.19.2017.12.07.09.07.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Dec 2017 09:07:22 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, Marc Zyngier , Shih-Wei Li , Andrew Jones , Christoffer Dall Subject: [PATCH v2 27/36] KVM: arm64: Move common VHE/non-VHE trap config in separate functions Date: Thu, 7 Dec 2017 18:06:21 +0100 Message-Id: <20171207170630.592-28-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171207170630.592-1-christoffer.dall@linaro.org> References: <20171207170630.592-1-christoffer.dall@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 As we are about to be more lazy with some of the trap configuration register read/writes for VHE systems, move the logic that is currently shared between VHE and non-VHE into a separate function which can be called from either the world-switch path or from vcpu_load/vcpu_put. Signed-off-by: Christoffer Dall Reviewed-by: Marc Zyngier --- arch/arm64/kvm/hyp/switch.c | 72 ++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index 2ac8af354de0..c01bcfc3fb52 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -24,6 +24,43 @@ #include #include +static void __hyp_text __activate_traps_common(struct kvm_vcpu *vcpu) +{ + /* + * We are about to set CPTR_EL2.TFP to trap all floating point + * register accesses to EL2, however, the ARM ARM clearly states that + * traps are only taken to EL2 if the operation would not otherwise + * trap to EL1. Therefore, always make sure that for 32-bit guests, + * we set FPEXC.EN to prevent traps to EL1, when setting the TFP bit. + * If FP/ASIMD is not implemented, FPEXC is UNDEFINED and any access to + * it will cause an exception. + */ + if (vcpu_el1_is_32bit(vcpu) && system_supports_fpsimd() && + !vcpu->arch.guest_vfp_loaded) { + write_sysreg(1 << 30, fpexc32_el2); + isb(); + } + write_sysreg(vcpu->arch.hcr_el2, hcr_el2); + + /* Trap on AArch32 cp15 c15 (impdef sysregs) accesses (EL1 or EL0) */ + write_sysreg(1 << 15, hstr_el2); + /* + * Make sure we trap PMU access from EL0 to EL2. Also sanitize + * PMSELR_EL0 to make sure it never contains the cycle + * counter, which could make a PMXEVCNTR_EL0 access UNDEF at + * EL1 instead of being trapped to EL2. + */ + write_sysreg(0, pmselr_el0); + write_sysreg(ARMV8_PMU_USERENR_MASK, pmuserenr_el0); + write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2); +} + +static void __hyp_text __deactivate_traps_common(void) +{ + write_sysreg(0, hstr_el2); + write_sysreg(0, pmuserenr_el0); +} + static void __hyp_text __activate_traps_vhe(struct kvm_vcpu *vcpu) { u64 val; @@ -59,37 +96,7 @@ static hyp_alternate_select(__activate_traps_arch, static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu) { - u64 val; - - /* - * We are about to set CPTR_EL2.TFP to trap all floating point - * register accesses to EL2, however, the ARM ARM clearly states that - * traps are only taken to EL2 if the operation would not otherwise - * trap to EL1. Therefore, always make sure that for 32-bit guests, - * we set FPEXC.EN to prevent traps to EL1, when setting the TFP bit. - * If FP/ASIMD is not implemented, FPEXC is UNDEFINED and any access to - * it will cause an exception. - */ - val = vcpu->arch.hcr_el2; - - if (vcpu_el1_is_32bit(vcpu) && system_supports_fpsimd() && - !vcpu->arch.guest_vfp_loaded) { - write_sysreg(1 << 30, fpexc32_el2); - isb(); - } - write_sysreg(val, hcr_el2); - - /* Trap on AArch32 cp15 c15 accesses (EL1 or EL0) */ - write_sysreg(1 << 15, hstr_el2); - /* - * Make sure we trap PMU access from EL0 to EL2. Also sanitize - * PMSELR_EL0 to make sure it never contains the cycle - * counter, which could make a PMXEVCNTR_EL0 access UNDEF at - * EL1 instead of being trapped to EL2. - */ - write_sysreg(0, pmselr_el0); - write_sysreg(ARMV8_PMU_USERENR_MASK, pmuserenr_el0); - write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2); + __activate_traps_common(vcpu); __activate_traps_arch()(vcpu); } @@ -135,9 +142,8 @@ static void __hyp_text __deactivate_traps(struct kvm_vcpu *vcpu) if (vcpu->arch.hcr_el2 & HCR_VSE) vcpu->arch.hcr_el2 = read_sysreg(hcr_el2); + __deactivate_traps_common(); __deactivate_traps_arch()(); - write_sysreg(0, hstr_el2); - write_sysreg(0, pmuserenr_el0); } static void __hyp_text __activate_vm(struct kvm *kvm)