From nobody Mon Apr 6 09:44:06 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F3EBC6FA82 for ; Thu, 8 Sep 2022 23:26:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230026AbiIHX0Q (ORCPT ); Thu, 8 Sep 2022 19:26:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229817AbiIHX0H (ORCPT ); Thu, 8 Sep 2022 19:26:07 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76246C167C; Thu, 8 Sep 2022 16:26:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662679565; x=1694215565; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wfRlIdF7igCLq7ULumpJnznD7PdyklLJuoeH8ATvUgc=; b=jMPcBaz3Mh8yJMjxqNo64joZbz0Cs1OcqeiEweV88XmMLUCQnmOZGXMU Y7riw6j1NvZxJEi4zSzkwG95F9sEUDruCqSpnbZgmdUNAEV/rXZJJsa0h H7XAHpBe7mhZnlqGlHm6ixM0GgUdVWDxGP/ETXcc7EKHItgN248kUF5eJ lqy6W/+/wZefeBLRWkZRinQDmQBgpnqg/dXsOQvHwakJReZxK/P6u4cYA yoVk9ghrOfIb5abgovM4WOt1ILAFI2jQQK8IRsvhsUqCmSSN8OjIhLD7q XyBsjE1RDQpSP47+RZHDoczyAE6MmDpU9pa2shHrRuraUA3JLdhqzj7R7 w==; X-IronPort-AV: E=McAfee;i="6500,9779,10464"; a="298686975" X-IronPort-AV: E=Sophos;i="5.93,300,1654585200"; d="scan'208";a="298686975" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2022 16:26:04 -0700 X-IronPort-AV: E=Sophos;i="5.93,300,1654585200"; d="scan'208";a="610863151" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Sep 2022 16:26:03 -0700 From: isaku.yamahata@intel.com To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Marc Zyngier , Will Deacon , Yuan Yao Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Kai Huang , Chao Gao , Atish Patra , Shaokun Zhang , Qi Liu , John Garry , Daniel Lezcano , Huang Ying , Huacai Chen , Yuan Yao Subject: [PATCH v4 03/26] KVM: x86: Move check_processor_compatibility from init ops to runtime ops Date: Thu, 8 Sep 2022 16:25:19 -0700 Message-Id: <6b43a79970d886877f87a357e2a152464fe5dde2.1662679124.git.isaku.yamahata@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Chao Gao so that KVM can do compatibility checks on hotplugged CPUs. Drop __init from check_processor_compatibility() and its callees. use a static_call() to invoke .check_processor_compatibility. Opportunistically rename {svm,vmx}_check_processor_compat to conform to the naming convention of fields of kvm_x86_ops. Signed-off-by: Chao Gao Reviewed-by: Sean Christopherson Link: https://lore.kernel.org/r/20220216031528.92558-2-chao.gao@intel.com Signed-off-by: Isaku Yamahata Reviewed-by: Yuan Yao --- arch/x86/include/asm/kvm-x86-ops.h | 1 + arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/svm/svm.c | 4 ++-- arch/x86/kvm/vmx/vmx.c | 14 +++++++------- arch/x86/kvm/x86.c | 3 +-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-= x86-ops.h index 51f777071584..3bc45932e2d1 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -129,6 +129,7 @@ KVM_X86_OP(msr_filter_changed) KVM_X86_OP(complete_emulated_msr) KVM_X86_OP(vcpu_deliver_sipi_vector) KVM_X86_OP_OPTIONAL_RET0(vcpu_get_apicv_inhibit_reasons); +KVM_X86_OP(check_processor_compatibility) =20 #undef KVM_X86_OP #undef KVM_X86_OP_OPTIONAL diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index 2c96c43c313a..5df5d88d345f 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1445,6 +1445,7 @@ static inline u16 kvm_lapic_irq_dest_mode(bool dest_m= ode_logical) struct kvm_x86_ops { const char *name; =20 + int (*check_processor_compatibility)(void); int (*hardware_enable)(void); void (*hardware_disable)(void); void (*hardware_unsetup)(void); @@ -1655,7 +1656,6 @@ struct kvm_x86_nested_ops { struct kvm_x86_init_ops { int (*cpu_has_kvm_support)(void); int (*disabled_by_bios)(void); - int (*check_processor_compatibility)(void); int (*hardware_setup)(void); unsigned int (*handle_intel_pt_intr)(void); =20 diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index f3813dbacb9f..371300f03f55 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4134,7 +4134,7 @@ svm_patch_hypercall(struct kvm_vcpu *vcpu, unsigned c= har *hypercall) hypercall[2] =3D 0xd9; } =20 -static int __init svm_check_processor_compat(void) +static int svm_check_processor_compatibility(void) { return 0; } @@ -4740,6 +4740,7 @@ static struct kvm_x86_ops svm_x86_ops __initdata =3D { .name =3D "kvm_amd", =20 .hardware_unsetup =3D svm_hardware_unsetup, + .check_processor_compatibility =3D svm_check_processor_compatibility, .hardware_enable =3D svm_hardware_enable, .hardware_disable =3D svm_hardware_disable, .has_emulated_msr =3D svm_has_emulated_msr, @@ -5122,7 +5123,6 @@ static struct kvm_x86_init_ops svm_init_ops __initdat= a =3D { .cpu_has_kvm_support =3D has_svm, .disabled_by_bios =3D is_disabled, .hardware_setup =3D svm_hardware_setup, - .check_processor_compatibility =3D svm_check_processor_compat, =20 .runtime_ops =3D &svm_x86_ops, .pmu_ops =3D &amd_pmu_ops, diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index d7f8331d6f7e..3cf7f18a4115 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2495,8 +2495,8 @@ static bool cpu_has_sgx(void) return cpuid_eax(0) >=3D 0x12 && (cpuid_eax(0x12) & BIT(0)); } =20 -static __init int adjust_vmx_controls(u32 ctl_min, u32 ctl_opt, - u32 msr, u32 *result) +static int adjust_vmx_controls(u32 ctl_min, u32 ctl_opt, + u32 msr, u32 *result) { u32 vmx_msr_low, vmx_msr_high; u32 ctl =3D ctl_min | ctl_opt; @@ -2514,7 +2514,7 @@ static __init int adjust_vmx_controls(u32 ctl_min, u3= 2 ctl_opt, return 0; } =20 -static __init u64 adjust_vmx_controls64(u64 ctl_opt, u32 msr) +static u64 adjust_vmx_controls64(u64 ctl_opt, u32 msr) { u64 allowed; =20 @@ -2523,8 +2523,8 @@ static __init u64 adjust_vmx_controls64(u64 ctl_opt, = u32 msr) return ctl_opt & allowed; } =20 -static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf, - struct vmx_capability *vmx_cap) +static int setup_vmcs_config(struct vmcs_config *vmcs_conf, + struct vmx_capability *vmx_cap) { u32 vmx_msr_low, vmx_msr_high; u32 min, opt, min2, opt2; @@ -7417,7 +7417,7 @@ static int vmx_vm_init(struct kvm *kvm) return 0; } =20 -static int __init vmx_check_processor_compat(void) +static int vmx_check_processor_compatibility(void) { struct vmcs_config vmcs_conf; struct vmx_capability vmx_cap; @@ -8015,6 +8015,7 @@ static struct kvm_x86_ops vmx_x86_ops __initdata =3D { =20 .hardware_unsetup =3D vmx_hardware_unsetup, =20 + .check_processor_compatibility =3D vmx_check_processor_compatibility, .hardware_enable =3D vmx_hardware_enable, .hardware_disable =3D vmx_hardware_disable, .has_emulated_msr =3D vmx_has_emulated_msr, @@ -8404,7 +8405,6 @@ static __init int hardware_setup(void) static struct kvm_x86_init_ops vmx_init_ops __initdata =3D { .cpu_has_kvm_support =3D cpu_has_kvm_support, .disabled_by_bios =3D vmx_disabled_by_bios, - .check_processor_compatibility =3D vmx_check_processor_compat, .hardware_setup =3D hardware_setup, .handle_intel_pt_intr =3D NULL, =20 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 0368eab6a7b5..a7fa55ba344d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -12001,7 +12001,6 @@ void kvm_arch_hardware_unsetup(void) int kvm_arch_check_processor_compat(void *opaque) { struct cpuinfo_x86 *c =3D &cpu_data(smp_processor_id()); - struct kvm_x86_init_ops *ops =3D opaque; =20 WARN_ON(!irqs_disabled()); =20 @@ -12009,7 +12008,7 @@ int kvm_arch_check_processor_compat(void *opaque) __cr4_reserved_bits(cpu_has, &boot_cpu_data)) return -EIO; =20 - return ops->check_processor_compatibility(); + return static_call(kvm_x86_check_processor_compatibility)(); } =20 bool kvm_vcpu_is_reset_bsp(struct kvm_vcpu *vcpu) --=20 2.25.1