From patchwork Thu Oct 12 10:41:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10001647 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 DA9B260325 for ; Thu, 12 Oct 2017 10:51:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCE2528C7E for ; Thu, 12 Oct 2017 10:51:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1F6F28D6D; Thu, 12 Oct 2017 10:51:45 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 7102528C7E for ; Thu, 12 Oct 2017 10:51:45 +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=xaH19BK30qvI+audB3Ic+DymSOZ9RIzMCWblT/r6keQ=; b=ZEKUJJ5CcnFaKRCkCh2aksPaWJ 8UPMKzgnoj7mszDF4dkfkhd++TokNF4Wh6RY55oDyKTFbHVnoeDEMwLVoo4t4ff+fEHmmGU51A5jG e0d71eeXU6tEjBZNXUJGlI6fVVGWI5s9VLzxdwrH0QenwyE5YxepQo1APt/hB88OKn+C0h/y8MdqT 2pLF8D/s1+R6bTzmPIEqwbQftsuVeq90BtimqzViWNFzQJg4rxEy5KK0iJokAcmu/avo3V51Hz0mQ dX+JEhAaTQCfS1SwdKmo+CEXEIMbQruzneUHMxf/PCzKFDNcS6Zds/3yB0MVopte0DPBhEYKYJGLW Yx1/x3Rg==; 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 1e2b5Y-0001KL-Fo; Thu, 12 Oct 2017 10:51:40 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e2axy-0000PW-Q1 for linux-arm-kernel@bombadil.infradead.org; Thu, 12 Oct 2017 10:43:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.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=Nfj+f2es9PyqzcR/vd/NGneMshedKiGUxYYCbvKDMic=; b=GiRj7EHmsA5JvUZyJuFxrgNkg 2Rx4DRr7kblRuncd5XoJ77dkBGW8rybxuVwEnDVU/kKXNX110ESROBHTFMFofTJ261ZsoE3zCUK1f MENi+/eTYXTbBuPeUGcaf+1l2lRIZDD9/Sppx8k4yXXuz1laIUCgcGL2QZBysfagsWa2sjWov0S2R bm7Wl2OD6plgDWc5NemubP6mD0TMaMZEU2col2015XnjVuEYbEdOWo+IsqsaThacAIPS14H5hdZoZ rexmr6DdyNJVyAoynjAU5XvQMhtwaJAfMw2bciP++LaH8sC8a5wNHvRmwwPi0UQPDu5a1XSOdGc7y LgYEWhuIQ==; Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e2awr-0005LH-LN for linux-arm-kernel@lists.infradead.org; Thu, 12 Oct 2017 10:42:43 +0000 Received: by mail-wm0-x22b.google.com with SMTP id i124so12077124wmf.3 for ; Thu, 12 Oct 2017 03:42:21 -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=Nfj+f2es9PyqzcR/vd/NGneMshedKiGUxYYCbvKDMic=; b=a3wfCoWSg5HKj5LuqqAvDOkvViWejJXDCCTP+jDuU4nffVKDgu4RG7kVNRL5sYRB3Y n98iKrVf7VZu64RylZ+FcDUXDskANhyEj2V/LHUYQHKA22i6tcF+01L+KqQZT0I5PqG5 T/dj9MR2f3odsR7zb7z9Meck2J1Enwy4rwkX4= 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=Nfj+f2es9PyqzcR/vd/NGneMshedKiGUxYYCbvKDMic=; b=aiFg7s14Wz03+nn17ubxgwzKon0WrbxwXT8gTGWaQD0JgRBHxbrBo94EmHuTFA+F0R ud0sw5T0O9c7NDg+mxoDfWP84PNHDw1oZduaqwONUEpVbAuPQQo4YSC8a31hU0mRlMkb Ik4lnU3j2vmIcHsLeSlV8oJHs6xbRQalAtGilm8PNwmJqbfzVcycQEA9BwirKlu9q1hb 8jE+CM2xrI7zf1WM+/OsZ9pB61nsLYGql7RcJIOaYOe8ZSWE3nMo0iYeKOiOpW3d2SQE uc7z8IpYD5BSYs6Iy9x2EkN02dmL+kfojRvrBz2YQrCfWOV8CP4Pp2Nki6jAsTBOfwkm GbNg== X-Gm-Message-State: AMCzsaXAshX+JiwLzMLDxQSyDwwkYAg+AJqV8xUyIf1Mwpv6Z3DHW2Mn gatfKqAEzeMGIfQCz087e7nrBOGeep4= X-Google-Smtp-Source: AOwi7QDkHiFgVTzzHd2M6SwEenP3ZTATsEzUawlR4UQhg+GJI6zAexUZcgpJM1kHDYbHTK+v07UJCA== X-Received: by 10.80.153.59 with SMTP id k56mr2435243edb.208.1507804940327; Thu, 12 Oct 2017 03:42:20 -0700 (PDT) Received: from localhost.localdomain (xd93dd96b.cust.hiper.dk. [217.61.217.107]) by smtp.gmail.com with ESMTPSA id g49sm4798603edc.31.2017.10.12.03.42.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Oct 2017 03:42:19 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH 28/37] KVM: arm64: Move common VHE/non-VHE trap config in separate functions Date: Thu, 12 Oct 2017 12:41:32 +0200 Message-Id: <20171012104141.26902-29-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171012104141.26902-1-christoffer.dall@linaro.org> References: <20171012104141.26902-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171012_114241_710377_452FBA15 X-CRM114-Status: GOOD ( 18.05 ) 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: Marc Zyngier , Christoffer Dall , Shih-Wei Li , kvm@vger.kernel.org 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 --- arch/arm64/kvm/hyp/switch.c | 70 +++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index 6a12504..c587416 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -23,6 +23,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; @@ -57,35 +94,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); } @@ -131,9 +140,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 inline void __hyp_text __activate_vm(struct kvm_vcpu *vcpu)