From patchwork Thu Feb 15 21:03:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10223669 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 A00ED602CB for ; Thu, 15 Feb 2018 21:17:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E1E628F56 for ; Thu, 15 Feb 2018 21:17:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 804C9290D6; Thu, 15 Feb 2018 21:17:55 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 81DC627B13 for ; Thu, 15 Feb 2018 21:17:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=rimIpsBymIftqM8XkMsii5MuaQt93cJ7CH+QJOlIfHU=; b=s5BqbNIttRX2FhF0nB4qGS2Aik cFdgkiu2toJl98hoWS0MFLuvi3RYHNb8zm5nwKVrKQ2zOQokUoX5QWN7b5M8qrOIywhntaUL4oOfj mOFWn2FkkJYeDGD7X/vycCi2ggoqdiobQ9MIaJegW+p+sf1iPr/nLiBSz99qv4hphEtBMpndzGMFn B4SZSrWziqa0cnsrB5nVDKC0LMqLLvYSdde/FBO6+q6imvUTjh+AyjoEwNlECUSZmaC3TN0wrpnZL /Nn5pvYKxd9CpnWlmtb3pOEdltlQmLiW+XLdJGEvC4LEezi+5wkDAVbczMX2iUHmdFgzonLcEETT8 Gg0/qkWA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1emQud-0004Jo-H8; Thu, 15 Feb 2018 21:17:51 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1emQi8-0000jD-SG for linux-arm-kernel@bombadil.infradead.org; Thu, 15 Feb 2018 21:04:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=dUVJqWKPuVyhmccyKoHs1Y1c6AewTNLQUlnd98IyzTY=; b=mxK5uupxo8JsIn94VXAIQ1ygN 0nydvuPDtKHhCogi4tt3SnD0uCbAqJKa3sgqX+JgYzfxxfqSigYekRXaAEbLS8Nk1Wvi6fN3/Jx4V Q5bcokdMpelYkLzIbEqEuM8s0nWb9ASwVlYfXdZysmcUQn+gnH4z/8CxNPkIsqgEisDcHUJn1PGuU 81yhEbjn5uajduxTi+5YvuAG7j1yDmSXLxGkPkychQRHd5SVSmI8Aeb63z/4gmCnNuj7tb+6dlLAU jkizJk2ajU9neviq7huOW0Me/1GU4GJoFFaXYQmYL9iXlC/KI3EG11l3MsLvUXji6DYphHy1LC5d7 7ygIAuumA==; Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by merlin.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1emQi4-0000Tq-U6 for linux-arm-kernel@lists.infradead.org; Thu, 15 Feb 2018 21:04:54 +0000 Received: by mail-wm0-x242.google.com with SMTP id t74so3296992wme.3 for ; Thu, 15 Feb 2018 13:04:38 -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=dUVJqWKPuVyhmccyKoHs1Y1c6AewTNLQUlnd98IyzTY=; b=V4o61RFpt3NqA0aWEPoCpCfqgfP5uosBgpwwqGHyUhgB5y3pJmJbSz5dVEf/2rnczQ cweCaS3nAUnCRIw80dm5GfAn8ROfpZpatV1yKwM2lixK9duAoh5Tp+J7I9H0CRQiUsYB yL+GA8rq3hfdmbKxj0CFhgWjiB5phLQUGZwpo= 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=dUVJqWKPuVyhmccyKoHs1Y1c6AewTNLQUlnd98IyzTY=; b=qBux/hRAmYPQS5yHbaGb3CD+k4AEhYnIa64DXiT6G1OyMhB6uVIW3EeunooRwBAJk3 slNHhmcoRl2D74dRzLA6tJz8U1i334485a28UX6VkMLR0KoKbTEkF6op8KRU4LN+sJGD cEg2Fao2A9vbsq+o6e3GNYxx1msPsvo0mXp03z1/SyEKabg4vxP/YjU8QhZnUZHJ5lOc exC3gI4oVGY14NP88WYi5E042QKHKX4u5stIFILwy3AfVh5Qg9ws9WwN8sfDlpBLCthl Ru9PusuHcZ1kQv6lBYIk6RGNaXEG0jGaHE+ZbPwJ/0YOFKzd5TrFugVBJkdO4WHFg681 fSyQ== X-Gm-Message-State: APf1xPBs0AJKWvI4RjMyO717Hbnycx7En/0oKwNabtGI7uNQfqXZYU3y dSIhQyELfsHRVwBmgmLz1QK6cQ== X-Google-Smtp-Source: AH8x224faZinbMhqZEnrfo77xdxWD043QyOm1na8hTG8zJgAPtbMqYIaxoj9KmsUYS7pPH/LkG6Lhw== X-Received: by 10.80.145.82 with SMTP id f18mr5216238eda.92.1518728675827; Thu, 15 Feb 2018 13:04:35 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id p55sm8220030edc.15.2018.02.15.13.04.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Feb 2018 13:04:34 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 31/40] KVM: arm64: Move common VHE/non-VHE trap config in separate functions Date: Thu, 15 Feb 2018 22:03:23 +0100 Message-Id: <20180215210332.8648-32-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180215210332.8648-1-christoffer.dall@linaro.org> References: <20180215210332.8648-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180215_160453_190053_2D5F44AB X-CRM114-Status: GOOD ( 17.32 ) 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: Andrew Jones , kvm@vger.kernel.org, Marc Zyngier , Tomasz Nowicki , Julien Grall , Yury Norov , Christoffer Dall , Dave Martin , Shih-Wei Li MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.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 Reviewed-by: Andrew Jones --- Notes: Changes since v3: - Separate fpsimd32 trap configuration into a separate function which is still called from __activate_traps, because we no longer defer saving/restoring of VFP registers to load/put. arch/arm64/kvm/hyp/switch.c | 76 +++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index 909aa3fe9196..17e3c6f26a34 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -56,7 +56,45 @@ static inline void __hyp_text __fpsimd_save_fpexc32(struct kvm_vcpu *vcpu) vcpu->arch.ctxt.sys_regs[FPEXC32_EL2] = read_sysreg(fpexc32_el2); } -static void __hyp_text __activate_traps_vhe(void) +static void __hyp_text __activate_traps_fpsimd32(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()) { + write_sysreg(1 << 30, fpexc32_el2); + isb(); + } +} + +static void __hyp_text __activate_traps_common(struct kvm_vcpu *vcpu) +{ + /* 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; @@ -68,7 +106,7 @@ static void __hyp_text __activate_traps_vhe(void) write_sysreg(kvm_get_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; @@ -85,37 +123,14 @@ static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu) { u64 hcr = vcpu->arch.hcr_el2; - /* - * 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()) { - write_sysreg(1 << 30, fpexc32_el2); - isb(); - } + write_sysreg(hcr, hcr_el2); if (cpus_have_const_cap(ARM64_HAS_RAS_EXTN) && (hcr & HCR_VSE)) write_sysreg_s(vcpu->arch.vsesr_el2, SYS_VSESR_EL2); - write_sysreg(hcr, 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_arch()(); + __activate_traps_fpsimd32(vcpu); + __activate_traps_common(vcpu); + __activate_traps_arch()(vcpu); } static void __hyp_text __deactivate_traps_vhe(void) @@ -160,9 +175,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)