From nobody Thu Apr 9 03:10:03 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 5C7B9C43219 for ; Wed, 2 Nov 2022 06:24:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230139AbiKBGY2 (ORCPT ); Wed, 2 Nov 2022 02:24:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbiKBGYX (ORCPT ); Wed, 2 Nov 2022 02:24:23 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A7C025EB8; Tue, 1 Nov 2022 23:24:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667370262; x=1698906262; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hNotXspumrnx35AzALaMaKY1rG2NnMLZH3HRDC+yCBw=; b=LwDIJLJQE8BhJVR1li/x4OIHu4/uUFKfu037mpH4/H8Fabv39ozea0EP ZXTs7XcYI1tEAmfHk31ef4XzldR8/gxEk6mQyZROJ6Unog/y0/OzPxcoo sU7xTH/uaegv8NKZ2dDTGyhwMqadmmGgaV1+bzJwTrBai30JduKuXRjdT /VOc2xnEVZ0C5AW0PSgOtP4Q8ujNSFMiTIFedHnimNNJsQ2x9x0w4G/vm 82GEHaXq0jjrMAOMjsakSMr7ExVYcbZW8XAh9rQwg5rJwn192w18AbXQS 9jC9z9mIf+Tj83BNJqFdk1fK4s05xcOlCYrBoAmlh1VhP4HCzdwJD2nvs Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10518"; a="296765005" X-IronPort-AV: E=Sophos;i="5.95,232,1661842800"; d="scan'208";a="296765005" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2022 23:24:21 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10518"; a="703146396" X-IronPort-AV: E=Sophos;i="5.95,232,1661842800"; d="scan'208";a="703146396" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2022 23:24:21 -0700 From: isaku.yamahata@intel.com To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Marc Zyngier Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com Subject: [PATCH 1/4] KVM: Remove on_each_cpu(hardware_disable_nolock) in kvm_exit() Date: Tue, 1 Nov 2022 23:24:08 -0700 Message-Id: <439b5f7115c5df3e1440fe694269badb19390d55.1667369456.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: Isaku Yamahata hardware_enable/disable_nolock() check if the hardware is already enabled/disabled and work as nop when they are called multiple times. Also kvm_usage_count tracks the number of the existing VMs. When VM is created/destroyed by kvm_create/destroy_vm(), hardware_enable/disable_all() and module_get/put() are called. It means when kvm module is removed, it's guaranteed that there is no vm (kvm_usage_count =3D 0) and that hardware_disable_nolock() was called on ea= ch cpus. Although the module exit function, kvm_exit(), calls on_each_cpu(hardware_disable_nolock), it's essentially nop. Eliminate nop call in kvm_exit() and add WARN_ON(kvm_usage_count) to prove that there is no remaining VMs. Signed-off-by: Isaku Yamahata --- virt/kvm/kvm_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 1376a47fedee..a8c4e62b29ca 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -5945,6 +5945,8 @@ void kvm_exit(void) { int cpu; =20 + WARN_ON(kvm_usage_count); + debugfs_remove_recursive(kvm_debugfs_dir); misc_deregister(&kvm_dev); for_each_possible_cpu(cpu) @@ -5954,7 +5956,6 @@ void kvm_exit(void) unregister_syscore_ops(&kvm_syscore_ops); unregister_reboot_notifier(&kvm_reboot_notifier); cpuhp_remove_state_nocalls(CPUHP_AP_KVM_STARTING); - on_each_cpu(hardware_disable_nolock, NULL, 1); kvm_arch_hardware_unsetup(); kvm_arch_exit(); kvm_irqfd_exit(); --=20 2.25.1 From nobody Thu Apr 9 03:10:03 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 63569C4332F for ; Wed, 2 Nov 2022 06:24:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229570AbiKBGYa (ORCPT ); Wed, 2 Nov 2022 02:24:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230006AbiKBGYX (ORCPT ); Wed, 2 Nov 2022 02:24:23 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31CCC25EB6; Tue, 1 Nov 2022 23:24:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667370263; x=1698906263; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jWp6ZFqy1nSM5l64HCAa0km73/KG59GZikmLmohQJK4=; b=XNbr6MZkS3Hpi/ZXOw+82HBFWUFgAE5SaDJmxkHVRMdtX2AXo9eS5fEQ CEVpC5lgxuqEByXqBJB3Cj23PpnBupD3PkUzOQAK4o04f/hv0UvsdPAZz KhGRQsFF8ybMTzetbtRxbwMCOZFokHmmnuJrfH4AhP1scgKs1nlZDbv4k KX4v0zZM0Vh3KM+PRtlgzqdqLDYWUiuFJ78xtuwCwiPL2wScxVHUN4Lh1 YMKnZZ/MiCj39CpTlLaJN7UqjaARiZSKfknfdtzZtd/2vJdtxvRCRkjj/ WWks1Kz3Er/DOTYQv40622Ocpv96gqBEZRyggzdCBbHFwtZMinUVCq8+l w==; X-IronPort-AV: E=McAfee;i="6500,9779,10518"; a="296765009" X-IronPort-AV: E=Sophos;i="5.95,232,1661842800"; d="scan'208";a="296765009" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2022 23:24:21 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10518"; a="703146402" X-IronPort-AV: E=Sophos;i="5.95,232,1661842800"; d="scan'208";a="703146402" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2022 23:24:21 -0700 From: isaku.yamahata@intel.com To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Marc Zyngier Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com Subject: [PATCH 2/4] KVM: Make cpus_hardware_enabled cpumask_t instead of cpumask_var_t Date: Tue, 1 Nov 2022 23:24:09 -0700 Message-Id: <0b08309d04f1703b2d94b65f138d93554ce9e82c.1667369456.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: Isaku Yamahata On kvm module initialization, it dynamically allocates cpumask_var_t. Remove dynamic allocation by making it cpumask_t as static allocation. It simplifies module init and exit. Signed-off-by: Isaku Yamahata --- virt/kvm/kvm_main.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index a8c4e62b29ca..1a21b21ba326 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -103,7 +103,7 @@ DEFINE_MUTEX(kvm_lock); static DEFINE_RAW_SPINLOCK(kvm_count_lock); LIST_HEAD(vm_list); =20 -static cpumask_var_t cpus_hardware_enabled; +static cpumask_t cpus_hardware_enabled =3D CPU_MASK_NONE; static int kvm_usage_count; static atomic_t hardware_enable_failed; =20 @@ -5012,15 +5012,15 @@ static void hardware_enable_nolock(void *junk) int cpu =3D raw_smp_processor_id(); int r; =20 - if (cpumask_test_cpu(cpu, cpus_hardware_enabled)) + if (cpumask_test_cpu(cpu, &cpus_hardware_enabled)) return; =20 - cpumask_set_cpu(cpu, cpus_hardware_enabled); + cpumask_set_cpu(cpu, &cpus_hardware_enabled); =20 r =3D kvm_arch_hardware_enable(); =20 if (r) { - cpumask_clear_cpu(cpu, cpus_hardware_enabled); + cpumask_clear_cpu(cpu, &cpus_hardware_enabled); atomic_inc(&hardware_enable_failed); pr_info("kvm: enabling virtualization on CPU%d failed\n", cpu); } @@ -5039,9 +5039,9 @@ static void hardware_disable_nolock(void *junk) { int cpu =3D raw_smp_processor_id(); =20 - if (!cpumask_test_cpu(cpu, cpus_hardware_enabled)) + if (!cpumask_test_cpu(cpu, &cpus_hardware_enabled)) return; - cpumask_clear_cpu(cpu, cpus_hardware_enabled); + cpumask_clear_cpu(cpu, &cpus_hardware_enabled); kvm_arch_hardware_disable(); } =20 @@ -5849,11 +5849,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsig= ned vcpu_align, if (r) goto out_irqfd; =20 - if (!zalloc_cpumask_var(&cpus_hardware_enabled, GFP_KERNEL)) { - r =3D -ENOMEM; - goto out_free_0; - } - r =3D kvm_arch_hardware_setup(opaque); if (r < 0) goto out_free_1; @@ -5931,8 +5926,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsign= ed vcpu_align, out_free_2: kvm_arch_hardware_unsetup(); out_free_1: - free_cpumask_var(cpus_hardware_enabled); -out_free_0: kvm_irqfd_exit(); out_irqfd: kvm_arch_exit(); @@ -5959,7 +5952,6 @@ void kvm_exit(void) kvm_arch_hardware_unsetup(); kvm_arch_exit(); kvm_irqfd_exit(); - free_cpumask_var(cpus_hardware_enabled); kvm_vfio_ops_exit(); } EXPORT_SYMBOL_GPL(kvm_exit); --=20 2.25.1 From nobody Thu Apr 9 03:10:03 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 D6FFFC4332F for ; Wed, 2 Nov 2022 06:24:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230184AbiKBGYf (ORCPT ); Wed, 2 Nov 2022 02:24:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230013AbiKBGYX (ORCPT ); Wed, 2 Nov 2022 02:24:23 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 602EB26109; Tue, 1 Nov 2022 23:24:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667370263; x=1698906263; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0CO9zqn5QJQYlgV3XsYpGa3hDmGaoRGtQlVPOneiyEU=; b=EMK7UqWRLUMlJcDHWL1iOIwEoJE8MBwjpf9d1Tu9twfJz9MrPLS+F4vn Bs+isjbLzs870MU8zdquEfMmEPtJW+00DAbvP39lLZn/Ijj3MwG4gNCwX oUJ0GWV0XYfGKGWdmXDYEkV5ZU6S4Rj7Zf8V5sayW/Z7gVi2OgL6IZMQ5 ceB9mjgmENJvE9ULx60SYXObdjY+oQTpgc9MZYTo+g10Gsm+kv8xA0rxc kvBEnO/D20Lrs/H6fwN0Yes2L1hdHZ/2tSA5lFLXh5FYJ2Kbah1v/WRJJ qm7EuHnGfyjnmXcK+Xl9amcE5ZYK+4nNFW9oZb6LVs4WyxIVDMdeBwcBh Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10518"; a="296765013" X-IronPort-AV: E=Sophos;i="5.95,232,1661842800"; d="scan'208";a="296765013" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2022 23:24:22 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10518"; a="703146406" X-IronPort-AV: E=Sophos;i="5.95,232,1661842800"; d="scan'208";a="703146406" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2022 23:24:21 -0700 From: isaku.yamahata@intel.com To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Marc Zyngier Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com Subject: [PATCH 3/4] KVM: kvm_main.c: Remove a global variable, hardware_enable_failed Date: Tue, 1 Nov 2022 23:24:10 -0700 Message-Id: <0836ee2f6c40091907092fc07fd50e64a499e6d1.1667369456.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: Isaku Yamahata A global variable hardware_enable_failed in kvm_main.c is used only by hardware_enable_all() and hardware_enable_nolock(). It doesn't have to be a global variable. Make it function local. Signed-off-by: Isaku Yamahata --- virt/kvm/kvm_main.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 1a21b21ba326..ac24fef2c818 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -105,7 +105,6 @@ LIST_HEAD(vm_list); =20 static cpumask_t cpus_hardware_enabled =3D CPU_MASK_NONE; static int kvm_usage_count; -static atomic_t hardware_enable_failed; =20 static struct kmem_cache *kvm_vcpu_cache; =20 @@ -5007,30 +5006,36 @@ static struct miscdevice kvm_dev =3D { &kvm_chardev_ops, }; =20 -static void hardware_enable_nolock(void *junk) +static int __hardware_enable_nolock(void) { int cpu =3D raw_smp_processor_id(); int r; =20 - if (cpumask_test_cpu(cpu, &cpus_hardware_enabled)) - return; - - cpumask_set_cpu(cpu, &cpus_hardware_enabled); + if (cpumask_test_and_set_cpu(cpu, &cpus_hardware_enabled)) + return 0; =20 r =3D kvm_arch_hardware_enable(); =20 if (r) { cpumask_clear_cpu(cpu, &cpus_hardware_enabled); - atomic_inc(&hardware_enable_failed); pr_info("kvm: enabling virtualization on CPU%d failed\n", cpu); } + return r; +} + +static void hardware_enable_nolock(void *arg) +{ + atomic_t *failed =3D arg; + + if (__hardware_enable_nolock()) + atomic_inc(failed); } =20 static int kvm_starting_cpu(unsigned int cpu) { raw_spin_lock(&kvm_count_lock); if (kvm_usage_count) - hardware_enable_nolock(NULL); + (void)__hardware_enable_nolock(); raw_spin_unlock(&kvm_count_lock); return 0; } @@ -5072,16 +5077,16 @@ static void hardware_disable_all(void) =20 static int hardware_enable_all(void) { + atomic_t failed =3D ATOMIC_INIT(0); int r =3D 0; =20 raw_spin_lock(&kvm_count_lock); =20 kvm_usage_count++; if (kvm_usage_count =3D=3D 1) { - atomic_set(&hardware_enable_failed, 0); - on_each_cpu(hardware_enable_nolock, NULL, 1); + on_each_cpu(hardware_enable_nolock, &failed, 1); =20 - if (atomic_read(&hardware_enable_failed)) { + if (atomic_read(&failed)) { hardware_disable_all_nolock(); r =3D -EBUSY; } @@ -5702,7 +5707,7 @@ static void kvm_resume(void) { if (kvm_usage_count) { lockdep_assert_not_held(&kvm_count_lock); - hardware_enable_nolock(NULL); + (void)__hardware_enable_nolock(); } } =20 --=20 2.25.1 From nobody Thu Apr 9 03:10:03 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 567C0C433FE for ; Wed, 2 Nov 2022 06:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230229AbiKBGYl (ORCPT ); Wed, 2 Nov 2022 02:24:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229557AbiKBGYY (ORCPT ); Wed, 2 Nov 2022 02:24:24 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC91B2610C; Tue, 1 Nov 2022 23:24:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667370263; x=1698906263; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mIYUSSuIsu0WgSRrE7tEoP8B3O0y+uo/P/amOMScs7w=; b=eGr4OEXoOWokIF6IEkvhMIXRsUgp/yZ1qmhYY00N6WRG2ic9thLIk4gv wTkBAqAJ5Dcf7OzlIAQjvmTPvWY1XXrnJbrh1QwwBEgGPERNTjTLFKciP /4n3/kKjFR0O9tp7VosR5DcJzQfVn52zITYH4cR+mcs5qJvObZ2X3VaMB vq2RyM/LphnlDFCZL7vzXGU5lveK6AYLBXPyYW0mMvh59RI/G6aJqROyS yv6b51ZznqVM8H4UOkAdmsGyp6Izh7JkpTVifFB/ZXBACmtf/mkX9EAI9 88mv2FVXXjmnsVP2w2Ci8lOUBxRCIKV1lIaT+ohnrh01ntEFuLBMWX3qb A==; X-IronPort-AV: E=McAfee;i="6500,9779,10518"; a="296765017" X-IronPort-AV: E=Sophos;i="5.95,232,1661842800"; d="scan'208";a="296765017" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2022 23:24:22 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10518"; a="703146410" X-IronPort-AV: E=Sophos;i="5.95,232,1661842800"; d="scan'208";a="703146410" Received: from ls.sc.intel.com (HELO localhost) ([143.183.96.54]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2022 23:24:21 -0700 From: isaku.yamahata@intel.com To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson , Marc Zyngier Cc: isaku.yamahata@intel.com, isaku.yamahata@gmail.com Subject: [PATCH 4/4] KVM: arm64: Simplify the CPUHP logic Date: Tue, 1 Nov 2022 23:24:11 -0700 Message-Id: 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: Marc Zyngier For a number of historical reasons, the KVM/arm64 hotplug setup is pretty complicated, and we have two extra CPUHP notifiers for vGIC and timers. It looks pretty pointless, and gets in the way of further changes. So let's just expose some helpers that can be called from the core CPUHP callback, and get rid of everything else. This gives us the opportunity to drop a useless notifier entry, as well as tidy-up the timer enable/disable, which was a bit odd. Signed-off-by: Marc Zyngier Signed-off-by: Isaku Yamahata --- arch/arm64/kvm/arch_timer.c | 27 ++++++++++----------------- arch/arm64/kvm/arm.c | 13 +++++++++++++ arch/arm64/kvm/vgic/vgic-init.c | 19 ++----------------- include/kvm/arm_arch_timer.h | 4 ++++ include/kvm/arm_vgic.h | 4 ++++ include/linux/cpuhotplug.h | 3 --- 6 files changed, 33 insertions(+), 37 deletions(-) diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c index bb24a76b4224..33fca1a691a5 100644 --- a/arch/arm64/kvm/arch_timer.c +++ b/arch/arm64/kvm/arch_timer.c @@ -811,10 +811,18 @@ void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu) ptimer->host_timer_irq_flags =3D host_ptimer_irq_flags; } =20 -static void kvm_timer_init_interrupt(void *info) +void kvm_timer_cpu_up(void) { enable_percpu_irq(host_vtimer_irq, host_vtimer_irq_flags); - enable_percpu_irq(host_ptimer_irq, host_ptimer_irq_flags); + if (host_ptimer_irq) + enable_percpu_irq(host_ptimer_irq, host_ptimer_irq_flags); +} + +void kvm_timer_cpu_down(void) +{ + disable_percpu_irq(host_vtimer_irq); + if (host_ptimer_irq) + disable_percpu_irq(host_ptimer_irq); } =20 int kvm_arm_timer_set_reg(struct kvm_vcpu *vcpu, u64 regid, u64 value) @@ -976,18 +984,6 @@ void kvm_arm_timer_write_sysreg(struct kvm_vcpu *vcpu, preempt_enable(); } =20 -static int kvm_timer_starting_cpu(unsigned int cpu) -{ - kvm_timer_init_interrupt(NULL); - return 0; -} - -static int kvm_timer_dying_cpu(unsigned int cpu) -{ - disable_percpu_irq(host_vtimer_irq); - return 0; -} - static int timer_irq_set_vcpu_affinity(struct irq_data *d, void *vcpu) { if (vcpu) @@ -1185,9 +1181,6 @@ int kvm_timer_hyp_init(bool has_gic) goto out_free_irq; } =20 - cpuhp_setup_state(CPUHP_AP_KVM_ARM_TIMER_STARTING, - "kvm/arm/timer:starting", kvm_timer_starting_cpu, - kvm_timer_dying_cpu); return 0; out_free_irq: free_percpu_irq(host_vtimer_irq, kvm_get_running_vcpus()); diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 94d33e296e10..a15d9933edbd 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1675,7 +1675,15 @@ static void _kvm_arch_hardware_enable(void *discard) =20 int kvm_arch_hardware_enable(void) { + int was_enabled =3D __this_cpu_read(kvm_arm_hardware_enabled); + _kvm_arch_hardware_enable(NULL); + + if (!was_enabled) { + kvm_vgic_cpu_up(); + kvm_timer_cpu_up(); + } + return 0; } =20 @@ -1689,6 +1697,11 @@ static void _kvm_arch_hardware_disable(void *discard) =20 void kvm_arch_hardware_disable(void) { + if (__this_cpu_read(kvm_arm_hardware_enabled)) { + kvm_timer_cpu_down(); + kvm_vgic_cpu_down(); + } + if (!is_protected_kvm_enabled()) _kvm_arch_hardware_disable(NULL); } diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-ini= t.c index f6d4f4052555..6c7f6ae21ec0 100644 --- a/arch/arm64/kvm/vgic/vgic-init.c +++ b/arch/arm64/kvm/vgic/vgic-init.c @@ -465,17 +465,15 @@ int kvm_vgic_map_resources(struct kvm *kvm) =20 /* GENERIC PROBE */ =20 -static int vgic_init_cpu_starting(unsigned int cpu) +void kvm_vgic_cpu_up(void) { enable_percpu_irq(kvm_vgic_global_state.maint_irq, 0); - return 0; } =20 =20 -static int vgic_init_cpu_dying(unsigned int cpu) +void kvm_vgic_cpu_down(void) { disable_percpu_irq(kvm_vgic_global_state.maint_irq); - return 0; } =20 static irqreturn_t vgic_maintenance_handler(int irq, void *data) @@ -584,19 +582,6 @@ int kvm_vgic_hyp_init(void) return ret; } =20 - ret =3D cpuhp_setup_state(CPUHP_AP_KVM_ARM_VGIC_INIT_STARTING, - "kvm/arm/vgic:starting", - vgic_init_cpu_starting, vgic_init_cpu_dying); - if (ret) { - kvm_err("Cannot register vgic CPU notifier\n"); - goto out_free_irq; - } - kvm_info("vgic interrupt IRQ%d\n", kvm_vgic_global_state.maint_irq); return 0; - -out_free_irq: - free_percpu_irq(kvm_vgic_global_state.maint_irq, - kvm_get_running_vcpus()); - return ret; } diff --git a/include/kvm/arm_arch_timer.h b/include/kvm/arm_arch_timer.h index cd6d8f260eab..1638418f72dd 100644 --- a/include/kvm/arm_arch_timer.h +++ b/include/kvm/arm_arch_timer.h @@ -104,4 +104,8 @@ void kvm_arm_timer_write_sysreg(struct kvm_vcpu *vcpu, u32 timer_get_ctl(struct arch_timer_context *ctxt); u64 timer_get_cval(struct arch_timer_context *ctxt); =20 +/* CPU HP callbacks */ +void kvm_timer_cpu_up(void); +void kvm_timer_cpu_down(void); + #endif diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index 4df9e73a8bb5..fc4acc91ba06 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -431,4 +431,8 @@ int vgic_v4_load(struct kvm_vcpu *vcpu); void vgic_v4_commit(struct kvm_vcpu *vcpu); int vgic_v4_put(struct kvm_vcpu *vcpu, bool need_db); =20 +/* CPU HP callbacks */ +void kvm_vgic_cpu_up(void); +void kvm_vgic_cpu_down(void); + #endif /* __KVM_ARM_VGIC_H */ diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index f61447913db9..7337414e4947 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -186,9 +186,6 @@ enum cpuhp_state { CPUHP_AP_TI_GP_TIMER_STARTING, CPUHP_AP_HYPERV_TIMER_STARTING, CPUHP_AP_KVM_STARTING, - CPUHP_AP_KVM_ARM_VGIC_INIT_STARTING, - CPUHP_AP_KVM_ARM_VGIC_STARTING, - CPUHP_AP_KVM_ARM_TIMER_STARTING, /* Must be the last timer callback */ CPUHP_AP_DUMMY_TIMER_STARTING, CPUHP_AP_ARM_XEN_STARTING, --=20 2.25.1