From patchwork Thu Oct 12 10:41:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10001705 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 3EF656028A for ; Thu, 12 Oct 2017 11:49:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2669D28D89 for ; Thu, 12 Oct 2017 11:49:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B02328D8B; Thu, 12 Oct 2017 11:49:39 +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 1033128D8A for ; Thu, 12 Oct 2017 11:49:37 +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=DDs9Ak1WPE5cuPflylhVof4rmsbcz5JjaYh2GxrgRzY=; b=raIXo/6UkLXwufxE2yWMkBie41 Z4YKXsstXZL2ghg1UdrQ6Zl6+N1fGPUtUsN+Md9qaPbhvjjJUMFfXq3XvkNvj8/mcbT2c6ulb1B2r XIfM0B4hgtTfriA1Ssk5L6EdZsLey3LzQTfNcgkth6z+msKDXZXZk6qF8hFHb8JY4TqY8xfDCZGvV /B0HdQS388HrF1GQOtUS3wp1e1xY9HQooDalhof9bkp322KEFWqz8GVVj31FCwaMZaWB4INYIge+3 thPJI7rQzWRBnFN5wufH126/b4P0CEGd1bFV6Kz51QVGKelgd/ZLwriuFPMG14317LnDGrkeg943x EIetTKdQ==; 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 1e2bzG-00064R-Qz; Thu, 12 Oct 2017 11:49:14 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e2bzE-00063q-R8 for linux-arm-kernel@bombadil.infradead.org; Thu, 12 Oct 2017 11:49:13 +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=mOkTrit/WzM22ES0/wFyZxEcNlIlb6oHrms9HOeleIM=; b=2kusHqEO7BmPHwTqll3Al+VJQ FZUoVZW/H3OTYA8ak+hCT2GbFKKLspDPlwzsveoxbWC6NXVaHNEVp1JrtYpHPzf0HQZMKXQSvqOGQ 3yr3qy6g324L14HalWI4TGUVw+4TMGWX3+uU2rXycK01o43lRp5+1mnlsJC1h9rJmkRqe5e/nou/9 fHkzFKOkLkED0hj35JSgnIuWPS3gHd3huDLC3e3FEr7LAqW1fYWCh7/u9E7sAhANO5fpYUY2uynhH P4UIxXBVPIYTUoVt72FSixmxSEu1Ai8KvFVLHcSoxfYolOjxCkliKYpO1ZUbeY4LIpw4UH7DyYJYL bcNI277Ug==; Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1e2awx-0004Nh-NJ for linux-arm-kernel@lists.infradead.org; Thu, 12 Oct 2017 10:42:48 +0000 Received: by mail-wm0-x234.google.com with SMTP id i124so11860232wmf.3 for ; Thu, 12 Oct 2017 03:42:27 -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=mOkTrit/WzM22ES0/wFyZxEcNlIlb6oHrms9HOeleIM=; b=XCip+lbvv82JCr5NYFkMuVtBieraZGC4qm2iVRhO6qdqa90tHiBxZ8oSPrYk0vFr9D ebZ+rOJU4hs29Kon5Zyp6Fa92rG8ykxFRBbqib+PtIgg+bQtxs/RF6/vBiCM8L226Vvw M76jgNvEx0NBdATEr91gah3EMgwTq73kl+AOw= 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=mOkTrit/WzM22ES0/wFyZxEcNlIlb6oHrms9HOeleIM=; b=arwpevzN5L5up7OVfi0ZFB3hNg+yZumETxmJ8IOIGnVUqnKnmvNHUjlVw5ldKw7Jli hH1rO9LlKv5tBlL+1NPS3SWcWLqQtRr0vWnRQmln9KntYgyKW804h3UfsoE1bMi7mWnJ 2FG6sHmeRdCrxG3kUQUzrjmIgzI3WlCWCDfOzbr9SYKGt8plzi1RoFF/m6WkxxaLYH2C orRD3JYD4hAJv8zoYHCJnxhUiztW44D17lhL9jvUJ0iGCsx2LHuKREQoZuIvAQEqSXSm 8+3dTOmLiTfIlOLL1kqyW5rF7QWecjKtU3g98CrdSDXVLiG4Esz1RXrVMEn7EWruJv18 +eIA== X-Gm-Message-State: AMCzsaW9eDnp/4AbqTI7Ho7EEEtn5wJTCBueDyiPNQGJ13/owgT96IlZ iB0uXxQeT9zRXovuk1LRwqHb8w== X-Google-Smtp-Source: AOwi7QCmeTN1Pkx+XiEkw+aBnZWvazcPRub4qU3UWyyrzXVN4RYJkUADApztEnNb0hOTR8d9fEvkVw== X-Received: by 10.80.148.37 with SMTP id p34mr2432834eda.254.1507804944802; Thu, 12 Oct 2017 03:42:24 -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.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Oct 2017 03:42:23 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH 31/37] KVM: arm64: Separate activate_traps and deactive_traps for VHE and non-VHE Date: Thu, 12 Oct 2017 12:41:35 +0200 Message-Id: <20171012104141.26902-32-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-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 To make the code more readable and to avoid the overhead of a function call, let's get rid of a pair of the alternative function selectors and explicitly call the VHE and non-VHE functions instead, telling the compiler to try to inline the static function if it can. Signed-off-by: Christoffer Dall --- arch/arm64/kvm/hyp/switch.c | 78 +++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 41 deletions(-) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index 13e137e..5692aa0 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -101,9 +101,27 @@ void deactivate_traps_vhe_put(void) write_sysreg(mdcr_el2, mdcr_el2); } -static void __hyp_text __activate_traps_vhe(struct kvm_vcpu *vcpu) +static inline void activate_traps_vhe(struct kvm_vcpu *vcpu) { - write_sysreg(__kvm_hyp_vector, vbar_el1); + write_sysreg(vcpu->arch.hcr_el2, hcr_el2); + write_sysreg_el2(__kvm_hyp_vector, vbar); +} + +static inline void deactivate_traps_vhe(struct kvm_vcpu *vcpu) +{ + extern char vectors[]; /* kernel exception vectors */ + + /* + * If we pended a virtual abort, preserve it until it gets + * cleared. See D1.14.3 (Virtual Interrupts) for details, but + * the crucial bit is "On taking a vSError interrupt, + * HCR_EL2.VSE is cleared to 0." + */ + if (vcpu->arch.hcr_el2 & HCR_VSE) + vcpu->arch.hcr_el2 = read_sysreg(hcr_el2); + + write_sysreg(HCR_HOST_VHE_FLAGS, hcr_el2); + write_sysreg(vectors, vbar_el1); } static void __hyp_text __activate_traps_nvhe(struct kvm_vcpu *vcpu) @@ -124,44 +142,15 @@ static void __hyp_text __activate_traps_nvhe(struct kvm_vcpu *vcpu) else val |= CPTR_EL2_TFP; write_sysreg(val, cptr_el2); -} -static hyp_alternate_select(__activate_traps_arch, - __activate_traps_nvhe, __activate_traps_vhe, - ARM64_HAS_VIRT_HOST_EXTN); - -static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu) -{ - __activate_traps_arch()(vcpu); + /* Configure all other hypervisor traps and features */ write_sysreg(vcpu->arch.hcr_el2, hcr_el2); } -static void __hyp_text __deactivate_traps_vhe(void) -{ - extern char vectors[]; /* kernel exception vectors */ - - write_sysreg(HCR_HOST_VHE_FLAGS, hcr_el2); - write_sysreg(vectors, vbar_el1); -} - -static void __hyp_text __deactivate_traps_nvhe(void) +static void __hyp_text __deactivate_traps_nvhe(struct kvm_vcpu *vcpu) { - u64 mdcr_el2 = read_sysreg(mdcr_el2); - - mdcr_el2 &= MDCR_EL2_HPMN_MASK; - mdcr_el2 |= MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT; - - write_sysreg(mdcr_el2, mdcr_el2); - write_sysreg(HCR_RW, hcr_el2); - write_sysreg(CPTR_EL2_DEFAULT, cptr_el2); -} - -static hyp_alternate_select(__deactivate_traps_arch, - __deactivate_traps_nvhe, __deactivate_traps_vhe, - ARM64_HAS_VIRT_HOST_EXTN); + u64 mdcr_el2; -static void __hyp_text __deactivate_traps(struct kvm_vcpu *vcpu) -{ /* * If we pended a virtual abort, preserve it until it gets * cleared. See D1.14.3 (Virtual Interrupts) for details, but @@ -172,7 +161,14 @@ static void __hyp_text __deactivate_traps(struct kvm_vcpu *vcpu) vcpu->arch.hcr_el2 = read_sysreg(hcr_el2); __deactivate_traps_common(); - __deactivate_traps_arch()(); + + mdcr_el2 = read_sysreg(mdcr_el2); + mdcr_el2 &= MDCR_EL2_HPMN_MASK; + mdcr_el2 |= MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT; + + write_sysreg(mdcr_el2, mdcr_el2); + write_sysreg(HCR_RW, hcr_el2); + write_sysreg(CPTR_EL2_DEFAULT, cptr_el2); } static inline void __hyp_text __activate_vm(struct kvm_vcpu *vcpu) @@ -371,7 +367,7 @@ int kvm_vcpu_run(struct kvm_vcpu *vcpu) sysreg_save_host_state_vhe(host_ctxt); - __activate_traps(vcpu); + activate_traps_vhe(vcpu); __activate_vm(vcpu); __vgic_restore_state(vcpu); @@ -390,7 +386,7 @@ int kvm_vcpu_run(struct kvm_vcpu *vcpu) sysreg_save_guest_state_vhe(guest_ctxt); __vgic_save_state(vcpu); - __deactivate_traps(vcpu); + deactivate_traps_vhe(vcpu); sysreg_restore_host_state_vhe(host_ctxt); @@ -418,7 +414,7 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu) __sysreg_save_state_nvhe(host_ctxt); - __activate_traps(vcpu); + __activate_traps_nvhe(vcpu); __activate_vm(vcpu); __vgic_restore_state(vcpu); @@ -445,7 +441,7 @@ int __hyp_text __kvm_vcpu_run(struct kvm_vcpu *vcpu) __timer_disable_traps(vcpu); __vgic_save_state(vcpu); - __deactivate_traps(vcpu); + __deactivate_traps_nvhe(vcpu); __deactivate_vm(vcpu); __sysreg_restore_state_nvhe(host_ctxt); @@ -471,7 +467,7 @@ static void __hyp_text __hyp_call_panic_nvhe(u64 spsr, u64 elr, u64 par, if (read_sysreg(vttbr_el2)) { __timer_disable_traps(vcpu); - __deactivate_traps(vcpu); + __deactivate_traps_nvhe(vcpu); __deactivate_vm(vcpu); __sysreg_restore_state_nvhe(__host_ctxt); } @@ -495,7 +491,7 @@ static void __hyp_call_panic_vhe(u64 spsr, u64 elr, u64 par, struct kvm_vcpu *vcpu; vcpu = host_ctxt->__hyp_running_vcpu; - __deactivate_traps_vhe(); + deactivate_traps_vhe(vcpu); sysreg_restore_host_state_vhe(host_ctxt); panic(__hyp_panic_string,