From patchwork Fri Jan 12 12:07:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10160657 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 9B8B160327 for ; Fri, 12 Jan 2018 12:27:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 84700289D3 for ; Fri, 12 Jan 2018 12:27:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7947A289D7; Fri, 12 Jan 2018 12:27:54 +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 0FDE3289D3 for ; Fri, 12 Jan 2018 12:27: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=RICdhfp6n4BhAb7cEi8NtSzndlFEkuFP5Xc04xQYAGw=; b=bfGP6bjYFXuevTnIKUQ3tKpH6W fTwIHau3PVQVsw8AT7SprCKjJIqQkqvH4rnX7cN5AbOjcBgN8Ry1OorPhmpm4s5Gv2oDFRlSgDFO8 By/QjMpEShJ2iSjyNhzZvD+aFAASGQrGAzYbpkzPSyIKb/zWGtAGAr/NjLVrSAOnv1vUfnmLDs/HM ARfib75EaUlGGJTKgsgsCZLIl1neEnISbnftKbXcQst22MFkDbEkLP0mmlf4opZ6Xf7gtKmLz8hFn cxI5dx6MPpXutEgcmiUn2bTK5bhXjxvz49w8skHM0pA3EkcbBw1b1lLe8blfDZQnCV4ZBy662K4oR yXM4Y5mQ==; 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 1eZyR6-0005Ep-2L; Fri, 12 Jan 2018 12:27:52 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eZyNu-0007CK-C2 for linux-arm-kernel@bombadil.infradead.org; Fri, 12 Jan 2018 12:24:34 +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=T30k3z3TnvBdkT8i4EcxtjtZX1D5oCrER0B6lFYU4sI=; b=cne5zeWJscXD7yuFWIaXeK+1g wrgD4vRHwI+766CfbOO7mjnzLH5+vvjldlhh01PbBSXqX22yXpb0HaTE4t4HdAlUPdqUCy1DhaISE JeDeKxmgrBphTo8ivle2mc/57A2IcCxKrnvU/oDJMUjaY8b88ADYxswD5/uQ2IXSZ/4/yP2gKoJ42 N1ZenLVEyKsjwQ6d/B7BdWHyka00KSk2dExF5k0UWRzj8ZH2ScCwxs9SGCLp/g+Nhh14wQ/zKG9tM EREupZojTiJVm0yQ6y/CvmGybJ/mXTlG2wDok1aOaoPM2d/ACGAeoN0zFve6szDxGg8pOpJHojKcj p0BRCa8vQ==; Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by casper.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eZy8h-00039j-CB for linux-arm-kernel@lists.infradead.org; Fri, 12 Jan 2018 12:08:53 +0000 Received: by mail-wm0-x242.google.com with SMTP id i186so11589376wmi.4 for ; Fri, 12 Jan 2018 04:08:41 -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=T30k3z3TnvBdkT8i4EcxtjtZX1D5oCrER0B6lFYU4sI=; b=JXYnquqH+7yeHRsB9qNwngQSLPnhSDh10uw4hv9L71EiqedzHoJPTzcb6/eIBEy68t qRxMXOeb5H4ahWZS++O0wnO5q+jX2+xUV5VIwVkhTGfV1QXFA8R2+3o0RCyg+4YAZ5AZ 2uHJtybqgnzsRx66GXPxDD6fJe3MbKTevP9Eo= 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=T30k3z3TnvBdkT8i4EcxtjtZX1D5oCrER0B6lFYU4sI=; b=c12VhuxYjhgShgrtqnlizq830bAl/1gu1V82x14pQmzWsV7iQVgr2gtPDpT7RqHQGN alhB8V0dQSibjGzkV50k5LzguBIZlux74bT8D1N73lWBb5zmdoEQYxGjbMLeVnqidU8+ c+rO1y3xvHmIqvjq+8ajLpzrNq6YypgSQIHdIox+jFrZP6MXc7sHcNrQ4o8kpBHAy7u8 Tdcgr3zVf9diZ3LrkQc8C/K4wnMnSDKIg/njja02BJtypR8vTM9Zfom6zgP1whZEk9WE sjrsNQW6bsEYcA0DavYN7hzYOvCJh3ov13V67+fBxpgruK5QNCO8b1ClChUq5OWkHm7l K6rQ== X-Gm-Message-State: AKwxytcGD2bUsOf63naBjdPRuRc+fD9Dw/FPdKytfZQh7wHuUEKOKpGZ /KcbRCJMdvDrClZtLslMIQX9NY8DoEs= X-Google-Smtp-Source: ACJfBougS+2HdM38DwlRsJiJFzdHV8P8FEsOBGif1NBqb7a5nyzryQp1V0SZRTL0Ltb6JWbIU6xhEw== X-Received: by 10.80.153.194 with SMTP id n2mr17149108edb.303.1515758920213; Fri, 12 Jan 2018 04:08:40 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id f16sm13489705edj.65.2018.01.12.04.08.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jan 2018 04:08:39 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 32/41] KVM: arm64: Move common VHE/non-VHE trap config in separate functions Date: Fri, 12 Jan 2018 13:07:38 +0100 Message-Id: <20180112120747.27999-33-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20180112120747.27999-1-christoffer.dall@linaro.org> References: <20180112120747.27999-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180112_120851_404288_D2AD5024 X-CRM114-Status: GOOD ( 17.90 ) 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 , Andrew Jones , 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. Reviewed-by: Marc Zyngier Signed-off-by: Christoffer Dall --- arch/arm64/kvm/hyp/switch.c | 68 ++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index 05f266b505ce..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,33 +96,7 @@ static hyp_alternate_select(__activate_traps_arch, static void __hyp_text __activate_traps(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 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 +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)