From patchwork Fri Jan 12 12:07:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10160447 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 5716E602D8 for ; Fri, 12 Jan 2018 12:09:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A7E228518 for ; Fri, 12 Jan 2018 12:09:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D90F289CD; Fri, 12 Jan 2018 12:09:15 +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 B1D9828518 for ; Fri, 12 Jan 2018 12:09:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933380AbeALMJM (ORCPT ); Fri, 12 Jan 2018 07:09:12 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:39590 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933736AbeALMIp (ORCPT ); Fri, 12 Jan 2018 07:08:45 -0500 Received: by mail-wm0-f68.google.com with SMTP id i11so11334312wmf.4 for ; Fri, 12 Jan 2018 04:08:45 -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=Egb7ynW8Hv0LJqOVi99wmb7mfzlNq//EhZj84X6tZHY=; b=R/mLZ9Ub9EcATii4DJMVp/OjD+F8obKNxrB6V3Z3j1RXXig2hxrvuzB6G6VQ9qGWsj afLViDUDaLHvRh2nFQb++P4JTwB0jYuvktBRyGiLcVvBEZ0SiG1xInL+lwH8kV/oWBH+ vSsmyDvcXa0GLhHC2P8Xj7GFURmozk+ya+L/4= 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=Egb7ynW8Hv0LJqOVi99wmb7mfzlNq//EhZj84X6tZHY=; b=jq1CwVTCU4m7QXMsTJJZmdvy2BUcBYCginF+nsVt1r9FTfFxkTexMz7BF2hGaJBG+Z lUbK4rYpxAmIa+cyYAp3lJ+JiYV+oI6WwdymFoe4f1A/OP5GmIA/XsuxVYSffDW5l7M5 P9KOKcGgldCiiqnV0UbA5D7UkyhozS5Vh3Vg6EruCHGqxjiMCCoXEjxGpoZCgqAz+zN5 sTYfTRT98oLJiVqUbL4ytxEszl3q+jH+7Co9mWN5YLXH4g9vBD+YxHo+17vaI2Q7yxNH b2qy/XJX0a3/BNqmjJ4RshHhjm6x4tmiSCIgTUzszs2xAOK/xsX33hUrB/V8fltEkMi2 f5Bw== X-Gm-Message-State: AKwxyteO3xXb92m5rGMj4ZnlunAfnCtoJP74GbIe0O/hUcVlV8D2Kn3N x5xj1XUxdOnmOAWXdpVNjZzjcohDOYU= X-Google-Smtp-Source: ACJfBos922SNjZ5PeoWk8/HT7GJuz2zVcLMp6IYVI7O5i0tGuxQUxXxkGo6/zLvdPNml28MjpnluTw== X-Received: by 10.80.134.123 with SMTP id 56mr6737805edt.285.1515758924467; Fri, 12 Jan 2018 04:08:44 -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.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jan 2018 04:08:43 -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 v3 35/41] KVM: arm64: Separate activate_traps and deactive_traps for VHE and non-VHE Date: Fri, 12 Jan 2018 13:07:41 +0100 Message-Id: <20180112120747.27999-36-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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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 6ff9fab4233e..53a137821ee9 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -103,9 +103,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); } void __hyp_text __activate_traps_nvhe_load(struct kvm_vcpu *vcpu) @@ -136,44 +154,15 @@ static void __hyp_text __activate_traps_nvhe(struct kvm_vcpu *vcpu) { /* Activate traps on impdef sysregs, PMU, and debug */ __activate_traps_common(vcpu); -} -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) +static void __hyp_text __deactivate_traps_nvhe(struct kvm_vcpu *vcpu) { - 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) { - u64 mdcr_el2 = read_sysreg(mdcr_el2); - - __deactivate_traps_common(); - - 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); -} - -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 @@ -183,7 +172,14 @@ 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_arch()(); + __deactivate_traps_common(); + + 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); } static void __hyp_text __activate_vm(struct kvm *kvm) @@ -400,7 +396,7 @@ int kvm_vcpu_run_vhe(struct kvm_vcpu *vcpu) sysreg_save_host_state_vhe(host_ctxt); - __activate_traps(vcpu); + activate_traps_vhe(vcpu); __activate_vm(vcpu->kvm); __vgic_restore_state(vcpu); @@ -418,7 +414,7 @@ int kvm_vcpu_run_vhe(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); @@ -442,7 +438,7 @@ int __hyp_text __kvm_vcpu_run_nvhe(struct kvm_vcpu *vcpu) __sysreg_save_state_nvhe(host_ctxt); - __activate_traps(vcpu); + __activate_traps_nvhe(vcpu); __activate_vm(kern_hyp_va(vcpu->kvm)); __vgic_restore_state(vcpu); @@ -468,7 +464,7 @@ int __hyp_text __kvm_vcpu_run_nvhe(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); @@ -494,7 +490,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); } @@ -518,7 +514,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(vcpu); + deactivate_traps_vhe(vcpu); sysreg_restore_host_state_vhe(host_ctxt); panic(__hyp_panic_string,