From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753166AbcGSHRX (ORCPT ); Tue, 19 Jul 2016 03:17:23 -0400 Received: from terminus.zytor.com ([198.137.202.10]:45766 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752553AbcGSHRV (ORCPT ); Tue, 19 Jul 2016 03:17:21 -0400 Date: Tue, 19 Jul 2016 00:16:48 -0700 From: tip-bot for Thomas Gleixner Message-ID: Cc: mingo@kernel.org, peterz@infradead.org, pbonzini@redhat.com, linux-kernel@vger.kernel.org, rkrcmar@redhat.com, hpa@zytor.com, gleb@kernel.org, tglx@linutronix.de, torvalds@linux-foundation.org, bigeasy@linutronix.de, anna-maria@linutronix.de Reply-To: bigeasy@linutronix.de, anna-maria@linutronix.de, torvalds@linux-foundation.org, tglx@linutronix.de, gleb@kernel.org, rkrcmar@redhat.com, hpa@zytor.com, linux-kernel@vger.kernel.org, pbonzini@redhat.com, mingo@kernel.org, peterz@infradead.org In-Reply-To: <20160713153335.886159080@linutronix.de> References: <20160713153335.886159080@linutronix.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:smp/hotplug] virt: Convert kvm hotplug to state machine Git-Commit-ID: 8c18b2d2d0881b116ea52498c6d624c0a71e1fdc X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 8c18b2d2d0881b116ea52498c6d624c0a71e1fdc Gitweb: http://git.kernel.org/tip/8c18b2d2d0881b116ea52498c6d624c0a71e1fdc Author: Thomas Gleixner AuthorDate: Wed, 13 Jul 2016 17:16:37 +0000 Committer: Ingo Molnar CommitDate: Fri, 15 Jul 2016 10:40:23 +0200 virt: Convert kvm hotplug to state machine Install the callbacks via the state machine. The core won't invoke the callbacks on already online CPUs. Signed-off-by: Thomas Gleixner Signed-off-by: Anna-Maria Gleixner Reviewed-by: Sebastian Andrzej Siewior Acked-by: Paolo Bonzini Cc: Gleb Natapov Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Radim Krcmar Cc: kvm@vger.kernel.org Cc: rt@linutronix.de Link: http://lkml.kernel.org/r/20160713153335.886159080@linutronix.de Signed-off-by: Ingo Molnar --- include/linux/cpuhotplug.h | 1 + virt/kvm/kvm_main.c | 32 ++++++++------------------------ 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index a5b6a65..5423997 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -36,6 +36,7 @@ enum cpuhp_state { CPUHP_AP_PERF_XTENSA_STARTING, CPUHP_AP_ARM_VFP_STARTING, CPUHP_AP_PERF_ARM_STARTING, + CPUHP_AP_KVM_STARTING, CPUHP_AP_NOTIFY_STARTING, CPUHP_AP_ONLINE, CPUHP_TEARDOWN_CPU, diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 48bd520..c1d6cf5 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -3144,12 +3144,13 @@ static void hardware_enable_nolock(void *junk) } } -static void hardware_enable(void) +static int kvm_starting_cpu(unsigned int cpu) { raw_spin_lock(&kvm_count_lock); if (kvm_usage_count) hardware_enable_nolock(NULL); raw_spin_unlock(&kvm_count_lock); + return 0; } static void hardware_disable_nolock(void *junk) @@ -3162,12 +3163,13 @@ static void hardware_disable_nolock(void *junk) kvm_arch_hardware_disable(); } -static void hardware_disable(void) +static int kvm_dying_cpu(unsigned int cpu) { raw_spin_lock(&kvm_count_lock); if (kvm_usage_count) hardware_disable_nolock(NULL); raw_spin_unlock(&kvm_count_lock); + return 0; } static void hardware_disable_all_nolock(void) @@ -3208,21 +3210,6 @@ static int hardware_enable_all(void) return r; } -static int kvm_cpu_hotplug(struct notifier_block *notifier, unsigned long val, - void *v) -{ - val &= ~CPU_TASKS_FROZEN; - switch (val) { - case CPU_DYING: - hardware_disable(); - break; - case CPU_STARTING: - hardware_enable(); - break; - } - return NOTIFY_OK; -} - static int kvm_reboot(struct notifier_block *notifier, unsigned long val, void *v) { @@ -3489,10 +3476,6 @@ int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx, return r; } -static struct notifier_block kvm_cpu_notifier = { - .notifier_call = kvm_cpu_hotplug, -}; - static int kvm_debugfs_open(struct inode *inode, struct file *file, int (*get)(void *, u64 *), int (*set)(void *, u64), const char *fmt) @@ -3743,7 +3726,8 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align, goto out_free_1; } - r = register_cpu_notifier(&kvm_cpu_notifier); + r = cpuhp_setup_state_nocalls(CPUHP_AP_KVM_STARTING, "AP_KVM_STARTING", + kvm_starting_cpu, kvm_dying_cpu); if (r) goto out_free_2; register_reboot_notifier(&kvm_reboot_notifier); @@ -3797,7 +3781,7 @@ out_free: kmem_cache_destroy(kvm_vcpu_cache); out_free_3: unregister_reboot_notifier(&kvm_reboot_notifier); - unregister_cpu_notifier(&kvm_cpu_notifier); + cpuhp_remove_state_nocalls(CPUHP_AP_KVM_STARTING); out_free_2: out_free_1: kvm_arch_hardware_unsetup(); @@ -3820,7 +3804,7 @@ void kvm_exit(void) kvm_async_pf_deinit(); unregister_syscore_ops(&kvm_syscore_ops); unregister_reboot_notifier(&kvm_reboot_notifier); - unregister_cpu_notifier(&kvm_cpu_notifier); + cpuhp_remove_state_nocalls(CPUHP_AP_KVM_STARTING); on_each_cpu(hardware_disable_nolock, NULL, 1); kvm_arch_hardware_unsetup(); kvm_arch_exit();