Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1259107rwn; Thu, 8 Sep 2022 16:29:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR7lv7jQEyLPvwWIhkC2yBhfs2S3vH+IIohnLvqUUiUG7Vv+jcNE6O7gkbd8mxTFubD8R6HX X-Received: by 2002:a17:90b:1812:b0:1fd:d509:93e5 with SMTP id lw18-20020a17090b181200b001fdd50993e5mr6722588pjb.25.1662679747022; Thu, 08 Sep 2022 16:29:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662679747; cv=none; d=google.com; s=arc-20160816; b=bhSLhJZNV4dG+o9T3padJIRYXjcUkv8XtEqd4pn3Ol7myq1LN4ZIsryzGJDWxNQvvU ks4+wP+lFMnT9glqF74tJbh9i35vxg/f0esGbDbyp6/fcBd2euiAHXabByrKbOR+gphB gjrAj0AMa1WEX3XX/i8ZHG7uqz4lFspNDmmEWDsP5zmhcsYEk73ooikMtbFJKEt6kIwY VxHyWtZjwHvfOQ04sK+bEuf/Bq/2wFaiYRNlCVuDGE+HdqirA78+5h09Q2oyzpDqxJQ4 jjzUGHo5HlgO+iztNXdTKJaJHZRiCgP0ovCfQmLWNrDwIV9Erz+X8PmneQ9B8s1qy+2s deBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ax7VUxeFu19Xx5xEaYm6m6RlFE4WoUcvVtDWOmzfnr4=; b=JUz71EA9khhntrfERFqESWu0fQUzELKWOL79e+3MJnuJmvesA1LkB3cOv9+0jJ05DN ymciaIw/YHLEzlByKYwqzv8HJUxs/W0e2YHxwko/flzk5m/EELfMXj95wMCVvo3bo9sz kzSI5PoZXSJ5H4XtZtkYXQKOgJLcTwOPkCTilZHHLZcO0D64T0M5yMl2Mb7J2RV9Kpgq 9PhztrYf7O0//6TfLhHob45uSN8tkH3fsvDNVvPr5UvecmNKCximkl+U29i9hAv9ayE/ yKC7cnZfRQI4repWhSo51FCribc8CSkVGCdk0C4AlfXBA9IVLMPDjT9USPuegr+BG6qS m7Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GhB2VPTM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ot4-20020a17090b3b4400b00200b067eb94si376509pjb.135.2022.09.08.16.28.55; Thu, 08 Sep 2022 16:29:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GhB2VPTM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230306AbiIHX1j (ORCPT + 99 others); Thu, 8 Sep 2022 19:27:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230220AbiIHX0j (ORCPT ); Thu, 8 Sep 2022 19:26:39 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 080F51098C5; Thu, 8 Sep 2022 16:26:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1662679576; x=1694215576; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=grUPy5igLiLP2txiwvePj0au0Jj6sSvLtTxS5GMrsGE=; b=GhB2VPTMStyBpiGTtoFnLx0sqFn0CYupQI3lo1AC0LD4Fu8KjMXoIaem NylB9i1xSUUej/8/k2h9pxBDtjOIr5XHKBFN+vjNrYknqSEn7hhnoWmOZ l0qFaea0JpCvnfYHJ7Gs3ihpmV5tMKZ4FAFFzQ62sAWxuYf18xwzw5Ovm /vtwxDGAVtBcbfdFDqUjToug3POGKpesi/Ec/YjnTWPEkQCTaaqbRsfEm H4YQh6NPG8DTLAqWInR6Hjj0s9f/00sFrJLtEm4CinaYKxiY/g87fhoDt Dcc+JGi93os5Jk2wqZdENOe23xWmDj0Rz3EtL3XrRa4Fux6ARK1vRgWcw g==; X-IronPort-AV: E=McAfee;i="6500,9779,10464"; a="298687020" X-IronPort-AV: E=Sophos;i="5.93,300,1654585200"; d="scan'208";a="298687020" 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:12 -0700 X-IronPort-AV: E=Sophos;i="5.93,300,1654585200"; d="scan'208";a="610863250" 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:12 -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 Subject: [PATCH v4 17/26] KVM: Introduce a arch wrapper to check all processor compatibility Date: Thu, 8 Sep 2022 16:25:33 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Isaku Yamahata Introduce a arch wrapper to check all processor compatibility and define default implementation as weak symbol to keep the current logic. The hardware feature compatibility check is arch dependent, only x86 KVM does cpu feature check on all processors. It doesn't make much sense to enforce the current implementation to invoke check function on each processors. Introduce a arch callback, kvm_arch_check_processor_compat_all(), so that arch code can override it. Eventually feature check should be pushed down into arch callback, (kvm_arch_hardware_setup(), kvm_arch_online_cpu(), and kvm_arch_resume()), the two compatibility check, kvm_arch_check_processor_compat{,_all}(), will be eliminated. This is a transitional step for it. Signed-off-by: Isaku Yamahata --- include/linux/kvm_host.h | 1 + virt/kvm/kvm_arch.c | 18 ++++++++++++++++++ virt/kvm/kvm_main.c | 13 +++---------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 60f4ae9d6f48..74cae99fbf09 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1440,6 +1440,7 @@ int kvm_arch_hardware_setup(void *opaque); void kvm_arch_pre_hardware_unsetup(void); void kvm_arch_hardware_unsetup(void); int kvm_arch_check_processor_compat(void); +int kvm_arch_check_processor_compat_all(void); int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu); bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu); int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu); diff --git a/virt/kvm/kvm_arch.c b/virt/kvm/kvm_arch.c index ad23537ebe3b..9476c500d571 100644 --- a/virt/kvm/kvm_arch.c +++ b/virt/kvm/kvm_arch.c @@ -98,6 +98,24 @@ __weak int kvm_arch_del_vm(int usage_count) return 0; } +static void check_processor_compat(void *rtn) +{ + *(int *)rtn = kvm_arch_check_processor_compat(); +} + +__weak int kvm_arch_check_processor_compat_all(void) +{ + int cpu; + int r; + + for_each_online_cpu(cpu) { + smp_call_function_single(cpu, check_processor_compat, &r, 1); + if (r < 0) + return r; + } + return 0; +} + __weak int kvm_arch_online_cpu(unsigned int cpu, int usage_count) { int ret; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 5373127dcdb6..51315d454dc2 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -5752,11 +5752,6 @@ void kvm_unregister_perf_callbacks(void) } #endif -static void check_processor_compat(void *rtn) -{ - *(int *)rtn = kvm_arch_check_processor_compat(); -} - int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align, struct module *module) { @@ -5782,11 +5777,9 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align, if (r < 0) goto out_free_1; - for_each_online_cpu(cpu) { - smp_call_function_single(cpu, check_processor_compat, &r, 1); - if (r < 0) - goto out_free_2; - } + r = kvm_arch_check_processor_compat_all(); + if (r < 0) + goto out_free_2; r = cpuhp_setup_state_nocalls(CPUHP_AP_KVM_ONLINE, "kvm/cpu:online", kvm_online_cpu, kvm_offline_cpu); -- 2.25.1