Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp8895026ybc; Fri, 29 Nov 2019 19:18:04 -0800 (PST) X-Google-Smtp-Source: APXvYqz9Kwl+asrN9EKhBK3ess+308q1dFLjZOmM+KteO2d8NVRY8q3YydgrUNZDTufgQreZU+8Z X-Received: by 2002:a05:6402:17e7:: with SMTP id t7mr42682007edy.114.1575083884254; Fri, 29 Nov 2019 19:18:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575083884; cv=none; d=google.com; s=arc-20160816; b=NiUAF7nc3NxggwqZ81vPV6vTYxotjApiJODJjuPpVtDfmBfdDsYO69z8nnEVC8s523 Jpv4U1US525tCju2ZPHcvjlg0aeoGHW5+8X+QKtIPL6wkDAdAo9LKmwGcYOnI38ud3Hy q2HCc+vNcEFr9S+HH1s8IjL7p+qHqFBIpXLgIm+AzwJejS46pJgzUPrG5ymfFW/nNlHT Uc0mtijLJ0EWOPuJTEjSz8mqt2xCsQ8dwv7t3xM83BQKUAacxEmlw0wD5L6mCx/J8zrg EBdlEeQ/RXcjm4uYnlUQ0USFut0rUQrNc5reoNgtcOmUZVh/IE1RLMhx2DB0B9RPhSMs 9/BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=8wqoQ1ih9Ae9Hzj6dQcy/LG90IWUfF36ztuBBhzmlTI=; b=FiIQZHiQmHcFZCg7Dtk2lzW8YohGOYLmwo9ZawlSqLoYJNmlQMX6hIVchb5Ynr+0ke WEnKBMGeV+xckEr9bJw5M0PdJBsixjCdtWLzYygg7oRBzfsZSinN2NQ0U6i6AxCtxnF8 JqX96xA1z05POOd+Wu6+BdBJrvUyDDtnf40euBkhB0uhFgylMNaiUKguMbXXtE7VME97 utTRDRraCOhuAZgcuXLontXqvCzhPCLl3rAxH3yT684ZjsHQcjFVclHd4VkJal/8S0yF djqy72OZMslqpZS9VSjV2E3zlo2ElWmyQOPFhujyLfSm5UQb7iAsxYarClkZ5NERAczT ZvKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i10si10191045edv.236.2019.11.29.19.17.40; Fri, 29 Nov 2019 19:18:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727227AbfK3DP7 (ORCPT + 99 others); Fri, 29 Nov 2019 22:15:59 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:6734 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727142AbfK3DP6 (ORCPT ); Fri, 29 Nov 2019 22:15:58 -0500 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 4D0FFA083DCA239A0AD2; Sat, 30 Nov 2019 11:15:57 +0800 (CST) Received: from linux-XCyijm.huawei.com (10.175.104.212) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.439.0; Sat, 30 Nov 2019 11:15:49 +0800 From: Heyi Guo To: , , CC: , Heyi Guo , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Will Deacon Subject: [PATCH] kvm/arm64: change gicv3_cpuif to static likely branch Date: Sat, 30 Nov 2019 11:14:43 +0800 Message-ID: <20191130031443.41696-1-guoheyi@huawei.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.104.212] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Platforms running hypervisor nowadays are normally powerful servers which at least support GICv3, so it should be better to switch kvm_vgic_global_state.gicv3_cpuif to static likely branch, which can reduce two "b" instructions to a single "nop" for GICv3 branches. We don't update arm32 specific code for they may still only have GICv2. Signed-off-by: Heyi Guo Cc: Marc Zyngier Cc: James Morse Cc: Julien Thierry Cc: Suzuki K Poulose Cc: Will Deacon --- arch/arm64/kvm/hyp/switch.c | 4 ++-- include/kvm/arm_vgic.h | 2 +- virt/kvm/arm/vgic/vgic-init.c | 9 +++++---- virt/kvm/arm/vgic/vgic.c | 9 +++++---- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index 799e84a40335..57e7d314211a 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -219,7 +219,7 @@ static void __hyp_text __deactivate_vm(struct kvm_vcpu *vcpu) /* Save VGICv3 state on non-VHE systems */ static void __hyp_text __hyp_vgic_save_state(struct kvm_vcpu *vcpu) { - if (static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif)) { + if (static_branch_likely(&kvm_vgic_global_state.gicv3_cpuif)) { __vgic_v3_save_state(vcpu); __vgic_v3_deactivate_traps(vcpu); } @@ -228,7 +228,7 @@ static void __hyp_text __hyp_vgic_save_state(struct kvm_vcpu *vcpu) /* Restore VGICv3 state on non_VEH systems */ static void __hyp_text __hyp_vgic_restore_state(struct kvm_vcpu *vcpu) { - if (static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif)) { + if (static_branch_likely(&kvm_vgic_global_state.gicv3_cpuif)) { __vgic_v3_activate_traps(vcpu); __vgic_v3_restore_state(vcpu); } diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index af4f09c02bf1..474e73dd3112 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -72,7 +72,7 @@ struct vgic_global { bool has_gicv4; /* GIC system register CPU interface */ - struct static_key_false gicv3_cpuif; + struct static_key_true gicv3_cpuif; u32 ich_vtr_el2; }; diff --git a/virt/kvm/arm/vgic/vgic-init.c b/virt/kvm/arm/vgic/vgic-init.c index 6f50c429196d..b03e5c8e1731 100644 --- a/virt/kvm/arm/vgic/vgic-init.c +++ b/virt/kvm/arm/vgic/vgic-init.c @@ -509,13 +509,14 @@ int kvm_vgic_hyp_init(void) switch (gic_kvm_info->type) { case GIC_V2: ret = vgic_v2_probe(gic_kvm_info); + if (!ret) { + static_branch_disable( + &kvm_vgic_global_state.gicv3_cpuif); + kvm_info("GIC system register CPU interface disabled\n"); + } break; case GIC_V3: ret = vgic_v3_probe(gic_kvm_info); - if (!ret) { - static_branch_enable(&kvm_vgic_global_state.gicv3_cpuif); - kvm_info("GIC system register CPU interface enabled\n"); - } break; default: ret = -ENODEV; diff --git a/virt/kvm/arm/vgic/vgic.c b/virt/kvm/arm/vgic/vgic.c index 45a870cb63f5..9dafeeb1457b 100644 --- a/virt/kvm/arm/vgic/vgic.c +++ b/virt/kvm/arm/vgic/vgic.c @@ -18,7 +18,7 @@ #include "trace.h" struct vgic_global kvm_vgic_global_state __ro_after_init = { - .gicv3_cpuif = STATIC_KEY_FALSE_INIT, + .gicv3_cpuif = STATIC_KEY_TRUE_INIT, }; /* @@ -841,12 +841,13 @@ static inline bool can_access_vgic_from_kernel(void) * memory-mapped, and VHE systems can access GICv3 EL2 system * registers. */ - return !static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif) || has_vhe(); + return !static_branch_likely(&kvm_vgic_global_state.gicv3_cpuif) || + has_vhe(); } static inline void vgic_save_state(struct kvm_vcpu *vcpu) { - if (!static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif)) + if (!static_branch_likely(&kvm_vgic_global_state.gicv3_cpuif)) vgic_v2_save_state(vcpu); else __vgic_v3_save_state(vcpu); @@ -873,7 +874,7 @@ void kvm_vgic_sync_hwstate(struct kvm_vcpu *vcpu) static inline void vgic_restore_state(struct kvm_vcpu *vcpu) { - if (!static_branch_unlikely(&kvm_vgic_global_state.gicv3_cpuif)) + if (!static_branch_likely(&kvm_vgic_global_state.gicv3_cpuif)) vgic_v2_restore_state(vcpu); else __vgic_v3_restore_state(vcpu); -- 2.19.1