Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1218515rwb; Thu, 22 Sep 2022 11:44:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5oJlYnKfvefbK941FwMu0MKE9pLMysDvYlMhzDP66rcaiMXfhZ4dfNFL8R7N8RJzvwDHU7 X-Received: by 2002:a17:906:fd8a:b0:75d:c79a:47c8 with SMTP id xa10-20020a170906fd8a00b0075dc79a47c8mr3920275ejb.389.1663872295079; Thu, 22 Sep 2022 11:44:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663872295; cv=none; d=google.com; s=arc-20160816; b=Nl5gc/ZEB0L5EsyuGYcXcK38DPRVOKYEZMsykaulFBW1jbNl1Wh7zm5aTSPOU7ryaK wOu/CMck27VWgau69/EQOv5dxe0orWRQ7W1TZKHydX+3iilKGS5StaH+tFq7eVmfxhHG WmoHMi74eEYvo7YJXHMIEaizJ79e+txVSlRhOrX9V0ByoH7DAjQif7EZrOUl8IledQHT S0ZZ5fxABL2Kk4vObgp+2MEZ32atn+jYGMFAlsekjLy2fl4o4bsZFUwqUDXdKVgrK/Hd jPFYnUKx0+8PQc9WlJCbAZvAO28x+g2Bf/OcoWd07Cgx+71hMcmrpQaPXOx1DIDGGtIn Vpbw== 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=3jmemktiv7IFHHbRBIJfFXgrUSigvo/emAUxMJGcAv4=; b=qfsnhCdsH/LRGyM+MET3wFt8IYGxBspibI5UiP6dVU05W5gLpvbQeGGNaWnZMFIIGI iU5gUicx6KQr2QvqnzXrkBPbdXe3WG27MWFlcnII30GtPyGos3xV6BqODy44MH4hwlDh 8oifVVH0f2jvUg+ZcWJLnq3E9P4BYN4RlkN8APVsW+c223hiAS6V3lwkYLwjgQ7fRV58 Ez1PokhppfvMRwOGqRKW29f5n01tWDU+AvEpuJpM9rOYh6OLCoYYbtdvyRzk54xLwwCe qKv1JOTvd5btZ5TK64iX79C9smlVJnK8jN7n7CFsPWITfEhIRgnUcj2Bo1xa6mvW7a5H XdrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=JdKoPH4g; 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 hv22-20020a17090760d600b0078239e3f846si3528609ejc.1.2022.09.22.11.44.29; Thu, 22 Sep 2022 11:44:55 -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=JdKoPH4g; 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 S232613AbiIVSX2 (ORCPT + 99 others); Thu, 22 Sep 2022 14:23:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36316 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232511AbiIVSWq (ORCPT ); Thu, 22 Sep 2022 14:22:46 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B0DC109608; Thu, 22 Sep 2022 11:21:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1663870919; x=1695406919; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e6y3hm3ayzpDm9GqLzCdSOZ8vwYZDKw7HR+mXt4ONKk=; b=JdKoPH4gn0x+Waseq6+mHA1t/BQ16eTmtMy4bIVsc5n/JtLY+aLsOcTp zqBSs3VO8cZ2dSfjpzDVUqX1nos3wT6v/ojmoSMBvP+M1+08NmDJiiXBx OeHoy82E8f2AdNVmrJ89z0+GZddsvpapUuA5zmglfBHCOR5I7gI3G2bTB pwHehQZEmbkXtCyUBRk1zOAhLsFOUcMlwQvaVN0vU0s4ZWjCHqR+YWrVa 7C8apRa7hckKxux1J+emhLQoI8usm7WeAQBk3l5ASTBQJ45vQMhpQO75D PPQbMCIksIhDxei+bw4F8KQLel3SmewH6GL6bdyw8GJ7nr12EkV8mUkff w==; X-IronPort-AV: E=McAfee;i="6500,9779,10478"; a="326712904" X-IronPort-AV: E=Sophos;i="5.93,337,1654585200"; d="scan'208";a="326712904" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2022 11:21:23 -0700 X-IronPort-AV: E=Sophos;i="5.93,337,1654585200"; d="scan'208";a="653086790" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Sep 2022 11:21:23 -0700 From: isaku.yamahata@intel.com To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Thomas Gleixner , Marc Zyngier , Will Deacon Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com, Kai Huang , Chao Gao , Atish Patra , Shaokun Zhang , Daniel Lezcano , Huang Ying , Huacai Chen , Dave Hansen , Borislav Petkov Subject: [PATCH v5 19/30] KVM: kvm_arch.c: Remove a global variable, hardware_enable_failed Date: Thu, 22 Sep 2022 11:20:48 -0700 Message-Id: <7f85a41f7aaad91c062eef37669c1eda2632ba45.1663869838.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=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE 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 | 61 ++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/virt/kvm/kvm_arch.c b/virt/kvm/kvm_arch.c index e6bf9de18cba..10fd29bdd6e1 100644 --- a/virt/kvm/kvm_arch.c +++ b/virt/kvm/kvm_arch.c @@ -13,7 +13,6 @@ #include static cpumask_t cpus_hardware_enabled = CPU_MASK_NONE; -static atomic_t hardware_enable_failed; /* * Called after the VM is otherwise initialized, but just before adding it to @@ -24,7 +23,7 @@ int __weak 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; @@ -32,18 +31,22 @@ 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_warn("kvm: enabling virtualization on CPU%d failed during %pSb\n", cpu, __builtin_return_address(0)); - } + 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,15 @@ static void hardware_disable(void *junk) */ int __weak kvm_arch_add_vm(struct kvm *kvm, int usage_count) { + atomic_t failed = ATOMIC_INIT(0); int r = 0; if (usage_count != 1) return 0; - atomic_set(&hardware_enable_failed, 0); - on_each_cpu(hardware_enable, NULL, 1); + on_each_cpu(hardware_enable, &failed, 1); - if (atomic_read(&hardware_enable_failed)) { + if (atomic_read(&failed)) { r = -EBUSY; goto err; } @@ -95,33 +98,29 @@ int __weak kvm_arch_del_vm(int usage_count) int __weak kvm_arch_online_cpu(unsigned int cpu, int usage_count) { - int ret = 0; + int ret; ret = kvm_arch_check_processor_compat(); if (ret) return ret; + if (!usage_count) + return 0; + + /* + * arch callback kvm_arch_hardware_enable() assumes that + * preemption is disabled for historical reason. Disable + * preemption until all arch callbacks are fixed. + */ + preempt_disable(); /* * 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)); + ret = __hardware_enable(); + preempt_enable(); - /* - * arch callback kvm_arch_hardware_eanble() assumes that - * preemption is disabled for historical reason. Disable - * preemption until all arch callbacks are fixed. - */ - preempt_disable(); - hardware_enable(NULL); - preempt_enable(); - if (atomic_read(&hardware_enable_failed)) { - atomic_set(&hardware_enable_failed, 0); - ret = -EIO; - } - } return ret; } @@ -160,5 +159,5 @@ int __weak kvm_arch_suspend(int usage_count) void __weak kvm_arch_resume(int usage_count) { if (usage_count) - hardware_enable(NULL); + (void)__hardware_enable(); } -- 2.25.1