From patchwork Thu Dec 7 17:06:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 10100311 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 06EF160360 for ; Thu, 7 Dec 2017 17:15:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEB4F284CE for ; Thu, 7 Dec 2017 17:15:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1DAE284DE; Thu, 7 Dec 2017 17:15:03 +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 DDAEE2844C for ; Thu, 7 Dec 2017 17:15:02 +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=2pgkooEqHRliLNGFdI/Bw2plSrkl6u8JnlyFMeH0aEI=; b=k+8M1150cVFGnesKpNVHd5ybY+ eYrGQuFz2rBA7uNXITVRmdSoXxXICHrnB5/JDviF8jSc0r3KJ9ys9Wi+qIXtIS4we0COMmsKrIN4/ 36p/mttT7gHQ4USRrd5zz4XZWtjNw9Xy5LxxQ9zteAToCufwtMMXSTw4rZuFagzwrM1CTbq+c/RS9 c/7OJTI78gu+9QGhv/3wL7t6SpLOS/VNmgu8cF1k3EjmsWUCUPNx7y9X3sFJ00OG5kKfElTZBdzpA oi6lK7fiAILu8nsiOYkADJY4aofsDOlTa3XnBHZY4/rSnnlasPUeex97GuRm6HQJxE/xM0J7uWoij 1mKrQ1pA==; 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 1eMzlF-0002kG-7H; Thu, 07 Dec 2017 17:15:01 +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 1eMzfE-0004ae-Mk for linux-arm-kernel@bombadil.infradead.org; Thu, 07 Dec 2017 17:08:48 +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=zgOK4A1ZINIYf90PnFcTml4QmVf5wkYQ5u9dGYY4QFg=; b=V0tZ+0ZnqOqjYh0CTNaj9TYst tNpBvbZqWsvIMMX5hg6gCRwvS/oL0BL5kHnoMYsguhNg2Ca/lmJXvgQmngYODhg4KrelqJDoXBErc ScuLm9XnRUSLz9TWNg69e8k1ONTvTe9foJZVHK1t37zgsfMC2boVpVii6KDrFax/L9SjjFxKLQKvb chfi6+UpHcWxrMWcxyZuihiQ4J7twiyrMQSCex8cYXHl+8xqL8o5XsgTIKf4cup+RBmu3kw4l8F0g xkBvaUx6vIO9QKlzL5HAR9WfU/Rz/Vl49u0w5W3nbCjDcNsFG+eSfSmfhpC+/hl7zIFjOuFxmdpMJ cxLNQrZ9Q==; Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMzeJ-0001yc-28 for linux-arm-kernel@lists.infradead.org; Thu, 07 Dec 2017 17:07:53 +0000 Received: by mail-wm0-x243.google.com with SMTP id g75so14433019wme.0 for ; Thu, 07 Dec 2017 09:07:30 -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=zgOK4A1ZINIYf90PnFcTml4QmVf5wkYQ5u9dGYY4QFg=; b=iGcThPH7D/VlB+6alYqmHt7V14d7cknrGyvMlP1T62HCWWcer/sq6TkqnuoleEiyk9 j8z3d1AagkbiQYOIaiYbwjOBjzHyL7eq6bLTqHH5uZ/QqCwIckKGiyiW0SqjO8B6nHYC ydzygQB/k1FBZ+vrbyTc3wyjPfV9iGrh2XCQ8= 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=zgOK4A1ZINIYf90PnFcTml4QmVf5wkYQ5u9dGYY4QFg=; b=dynezCEpn1zns1Cjy89hF8bXTDMdMqjXAMFEqaxf/2oCVoF0vLWlTkwqZyh2SOC0Y6 POkczrTg9tUCdbm3nsnWPteFwR3GXjIqbA/DiPG/y6qiuFG3KN8VkcoBnwlb8fztB9HO QgyEVSWfoGME+KE3VNeHsRPLZPfYJRVwki0K71g5Pagy265rBPPi3GafskA2JXqW4lj2 BpU7mDw7SbDe5RARH6VWrnLzVxXRuyey4ASVApMUvGv+VOfJEMltRTci+8sO1d4P/8Qy NxcvP0LjX7kn1F8qltt9Mukn9twKak9LgaTVF90hTym/xU2PvOBdOg9/zIXGiN3KZOkj gZXQ== X-Gm-Message-State: AKGB3mICS/No0+NSnEIacrVxXL7iisymo9LPGLfA5KZMEy/RCbc4wUbS EEhzMjdYC96mwuhlqdvvFhZMWw== X-Google-Smtp-Source: AGs4zMYYD5Y1ZYtH4YrzBmEvoL3Gg/u8NnGfyrSuSOnDcwZWao1Dg6h5ItqKHPVuN30+vYTTQJTbCA== X-Received: by 10.80.244.132 with SMTP id s4mr1913549edm.294.1512666448798; Thu, 07 Dec 2017 09:07:28 -0800 (PST) Received: from localhost.localdomain (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id a16sm2868270edd.19.2017.12.07.09.07.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Dec 2017 09:07:27 -0800 (PST) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 30/36] KVM: arm64: Separate activate_traps and deactive_traps for VHE and non-VHE Date: Thu, 7 Dec 2017 18:06:24 +0100 Message-Id: <20171207170630.592-31-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171207170630.592-1-christoffer.dall@linaro.org> References: <20171207170630.592-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171207_170751_175342_5357FC06 X-CRM114-Status: GOOD ( 15.97 ) 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 f039aad86c27..f9f104bfc27b 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); } static void __hyp_text __activate_traps_nvhe(struct kvm_vcpu *vcpu) @@ -126,44 +144,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 @@ -174,7 +163,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 void __hyp_text __activate_vm(struct kvm *kvm) @@ -391,7 +387,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); @@ -409,7 +405,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); @@ -433,7 +429,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); @@ -459,7 +455,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); @@ -485,7 +481,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); } @@ -509,7 +505,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,