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: 10160519 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 3CA9860327 for ; Fri, 12 Jan 2018 12:14:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F9F3289D1 for ; Fri, 12 Jan 2018 12:14:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 149FB289D3; Fri, 12 Jan 2018 12:14:22 +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 8B2D1289D1 for ; Fri, 12 Jan 2018 12:14:21 +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=Iwbl1Bo80ZKVtiesorlSHzUpQ2jwOoyE+rEZyFIPxPY=; b=Kq8xvRWJU8Q4ItoARKSzZLIcWJ ivxViPDqlbEYAtXYdZMpsuEgt2kqgca9d9PDAgv7lPXmZk9q4c6st/TN0qeNQ9Skk+bUSlAulfCSM bpdLNm26RCo6pjh0mXFiNF60h56xfOn05OybDRAiPgwx6W10TjIG1GJ7ZZraBotCJlYuUye5D5xAG lPY3GccvWoXps/Wz2exSD6tO4MkVBEVf9hG6++eTrUZOsr7mevYVdFYjHmh+LeoBD4kfGeHpa2JnL Fch4TI4lhwRtSwRHsUnnIXo3mYqvjF05lNP1z576xmMlELTDX/L7jvBWs21t1xQhQIc9VyjtcH4+I W9loWLrA==; 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 1eZyDz-0000TM-DX; Fri, 12 Jan 2018 12:14:19 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eZy8l-0000yw-Uq for linux-arm-kernel@lists.infradead.org; Fri, 12 Jan 2018 12:09:27 +0000 Received: by mail-wm0-x244.google.com with SMTP id v123so2214190wmd.5 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=aQ/o0/RaskVrQ5GbmheDR+/ddSYvlct2z0CpTpXMv0NDHGl6U09uaHvBTYQhx6YXmb 2W8OKvhapa3sgDUqddF9lPLdusx8NvNRuLx0hNqkpl++CYfQ12odKGOTABzjs77n34iv tXjE00/S+yV+e8Od3lWdrykXVOhHAc+Z8DbLf5AbttqrQN4qPqV6DiL1JvnF4db+HV3V ttXpQhl4JY2tYbfZ7nAFzmHOKLKxYkgRD8DBL6HhQVPzfk3fWn/vIa7er/Nv/WIMolg3 yIG+/73wNpmZxUuYss5ACD8PPJUzMrlxIQeSp2wSxsqLRh3vM4Zqjfr8Qg9O+fjJobxK e5gA== X-Gm-Message-State: AKwxyte3oWQdU4hCC8HIqjDC7D7axn0m0s2wZSJz+bxrwdjJ/npt1NOb 9sK2DsAH2xEB09SNieZK4qHItQ== 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180112_040856_380882_386CFE83 X-CRM114-Status: GOOD ( 14.80 ) 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 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,