Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp4117420rwe; Tue, 30 Aug 2022 05:05:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR6yePQTXgF0jQEAtAaz23OWlpOcbnjA2LxRyAs0vpfYMyaMAA0iYqkH2mW9Xu23SlOgIRpS X-Received: by 2002:a17:903:1106:b0:172:9801:cb96 with SMTP id n6-20020a170903110600b001729801cb96mr20939443plh.91.1661861141592; Tue, 30 Aug 2022 05:05:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661861141; cv=none; d=google.com; s=arc-20160816; b=AFCnCVziQ8Wxlh3RrAzYi+Gn8o6vNn5r/km6yKSAJYH2HhvEpEnpEulo1m6Fxjjv1i OLC8ZBRz25ulMVhOjiPV8mrpgnRcmiiiDWCIST0o8/nfiz4kl8TvQqPByoOI1RrKDfFg nN/Y/G2DuOJo4UUKou2/Z23sXiGKN5YuOmzHNz2wuVYIKGWlExibOBc1cFUGNUOntb3/ lRjb2dSIefBiEz8dDpkVEeu8F/1qP7NpzT1YbGdmLw156fcqGLQExOZmDAUfNV38o3Bd Cfdw/pRrtqYIBUdJMbFvGAOWmu88GLQ7TNMwqG1lP99jsCo/bHBu093/9uJnqmJ4G0yp NWpQ== 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=0StpxgxwLCYOSE5gRKnyApKH6T+2C6NmAGj7I+lB68w=; b=w680jVD8KKST7Wyn+FIY8IVSBFXYsiobo1v9VEMdhGkZl+/YVF3cZRZ0K/7KOxnFym X1ryWciG3Z7VDAekyEu9FlOWIKwXlFwCOAMWyVqssW5fdMEOcjaAAuqLu6Vpq9BCGbxK KWGdIt9w+sqtVTPYeCwyuNlSDSk8Tz0treu9CM4H+obebtFS6dPV+XW73w794Nv23Ph8 HZ1x8YLgnZ3bXhkBQ7J1+e4Xb2I0PVRL8+6pZ6YHCjyTPXXc50tqZT9E6fX8NvAn8nGc 45L1PErQw9UWtM4KgdfliFl4ok6mh5MRlJXlYOGbn2gPQBXxHWO3UNj6V3YgvoWB0jC8 /vhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=f4ylNust; 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 a184-20020a624dc1000000b0053642e7f0b0si11532665pfb.275.2022.08.30.05.05.28; Tue, 30 Aug 2022 05:05:41 -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=f4ylNust; 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 S231149AbiH3MCq (ORCPT + 99 others); Tue, 30 Aug 2022 08:02:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230109AbiH3MCC (ORCPT ); Tue, 30 Aug 2022 08:02:02 -0400 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C5BCE830A; Tue, 30 Aug 2022 05:02:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1661860921; x=1693396921; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tGT6aN2J7OkyrHuSTFcMkwLGe6Avk3mojHwqe3QkYZQ=; b=f4ylNustuQ8RJJdGNZY1dGRnZigmahv1TpRC28RHtwRNfmfoDtxg/XQr FLdo+7lWq3UNEgPepevrepRt8AL5cvcSmtSw6ID15c1tUjQgX0+3VQ7M0 dTDG37Z1TNz+QIPv1jw5c8c1hXqtHfbjNVAx3OTgnegm9E/spzSjwbXRU fo3JFABFKb7XHytgcNfzJoNIK/r7r4KlWhN5nLtJVDja5IP5m45M2gdLO z0V/AO+48r1OVKYqvySoYNjjlrkZBMMXf1/KDrdBG9RZRJqUl9AIk5mur cItWYcp7U2WXmv5S10Nxsqm8cmcjxExsjuggubdTyqJDn3KTlfqKrMKIZ Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10454"; a="356870985" X-IronPort-AV: E=Sophos;i="5.93,274,1654585200"; d="scan'208";a="356870985" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 05:01:58 -0700 X-IronPort-AV: E=Sophos;i="5.93,274,1654585200"; d="scan'208";a="787469647" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2022 05:01:58 -0700 From: isaku.yamahata@intel.com To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Paolo Bonzini , Sean Christopherson , Kai Huang , Chao Gao , Will Deacon Subject: [PATCH v2 12/19] KVM: kvm_arch.c: Remove a global variable, hardware_enable_failed Date: Tue, 30 Aug 2022 05:01:27 -0700 Message-Id: <078f2c056134ffe867c5ce72a1e7608fa4064779.1661860550.git.isaku.yamahata@intel.com> 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 A global variable hardware_enable_failed in kvm_arch.c is used only by kvm_arch_add_vm() and hardware_enable(). It doesn't have to be a global variable. Make it function local. Signed-off-by: Isaku Yamahata --- virt/kvm/kvm_arch.c | 56 +++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/virt/kvm/kvm_arch.c b/virt/kvm/kvm_arch.c index 491e92ef9e3d..3990f85edab3 100644 --- a/virt/kvm/kvm_arch.c +++ b/virt/kvm/kvm_arch.c @@ -13,14 +13,13 @@ #include static cpumask_t cpus_hardware_enabled = CPU_MASK_NONE; -static atomic_t hardware_enable_failed; __weak int kvm_arch_post_init_vm(struct kvm *kvm) { return 0; } -static void hardware_enable(void *junk) +static int __hardware_enable(void) { int cpu = raw_smp_processor_id(); int r; @@ -28,17 +27,21 @@ static void hardware_enable(void *junk) WARN_ON_ONCE(preemptible()); if (cpumask_test_cpu(cpu, &cpus_hardware_enabled)) - return; - - cpumask_set_cpu(cpu, &cpus_hardware_enabled); - + return 0; r = kvm_arch_hardware_enable(); - - if (r) { - cpumask_clear_cpu(cpu, &cpus_hardware_enabled); - atomic_inc(&hardware_enable_failed); + if (r) pr_info("kvm: enabling virtualization on CPU%d failed\n", cpu); - } + else + cpumask_set_cpu(cpu, &cpus_hardware_enabled); + return r; +} + +static void hardware_enable(void *arg) +{ + atomic_t *failed = arg; + + if (__hardware_enable()) + atomic_inc(failed); } static void hardware_disable(void *junk) @@ -64,15 +67,16 @@ __weak void kvm_arch_pre_hardware_unsetup(void) */ __weak int kvm_arch_add_vm(struct kvm *kvm, int usage_count) { + atomic_t failed; int r = 0; if (usage_count != 1) return 0; - atomic_set(&hardware_enable_failed, 0); - on_each_cpu(hardware_enable, NULL, 1); + atomic_set(&failed, 0); + on_each_cpu(hardware_enable, &failed, 1); - if (atomic_read(&hardware_enable_failed)) { + if (atomic_read(&failed)) { r = -EBUSY; goto err; } @@ -95,23 +99,15 @@ __weak int kvm_arch_del_vm(int usage_count) __weak int kvm_arch_online_cpu(unsigned int cpu, int usage_count) { - int ret = 0; - - /* - * Abort the CPU online process if hardware virtualization cannot - * be enabled. Otherwise running VMs would encounter unrecoverable - * errors when scheduled to this CPU. - */ if (usage_count) { - WARN_ON_ONCE(atomic_read(&hardware_enable_failed)); - - hardware_enable(NULL); - if (atomic_read(&hardware_enable_failed)) { - atomic_set(&hardware_enable_failed, 0); - ret = -EIO; - } + /* + * Abort the CPU online process if hardware virtualization cannot + * be enabled. Otherwise running VMs would encounter unrecoverable + * errors when scheduled to this CPU. + */ + return __hardware_enable(); } - return ret; + return 0; } __weak int kvm_arch_offline_cpu(unsigned int cpu, int usage_count) @@ -137,5 +133,5 @@ __weak int kvm_arch_suspend(int usage_count) __weak void kvm_arch_resume(int usage_count) { if (usage_count) - hardware_enable(NULL); + (void)__hardware_enable(); } -- 2.25.1