KVM: Use syscore_ops instead of sysdev class and sysdev

KVM uses a sysdev class and a sysdev for executing kvm_suspend()
after interrupts have been turned off on the boot CPU (during system
suspend) and for executing kvm_resume() before turning on interrupts
on the boot CPU (during system resume). However, since both of these
functions ignore their arguments, the entire mechanism may be
replaced with a struct syscore_ops object which is simpler.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Avi Kivity <avi@redhat.com>

+8 -26
+8 -26
virt/kvm/kvm_main.c
··· 30 #include <linux/debugfs.h> 31 #include <linux/highmem.h> 32 #include <linux/file.h> 33 - #include <linux/sysdev.h> 34 #include <linux/cpu.h> 35 #include <linux/sched.h> 36 #include <linux/cpumask.h> ··· 2447 debugfs_remove(kvm_debugfs_dir); 2448 } 2449 2450 - static int kvm_suspend(struct sys_device *dev, pm_message_t state) 2451 { 2452 if (kvm_usage_count) 2453 hardware_disable_nolock(NULL); 2454 return 0; 2455 } 2456 2457 - static int kvm_resume(struct sys_device *dev) 2458 { 2459 if (kvm_usage_count) { 2460 WARN_ON(raw_spin_is_locked(&kvm_lock)); 2461 hardware_enable_nolock(NULL); 2462 } 2463 - return 0; 2464 } 2465 2466 - static struct sysdev_class kvm_sysdev_class = { 2467 - .name = "kvm", 2468 .suspend = kvm_suspend, 2469 .resume = kvm_resume, 2470 - }; 2471 - 2472 - static struct sys_device kvm_sysdev = { 2473 - .id = 0, 2474 - .cls = &kvm_sysdev_class, 2475 }; 2476 2477 struct page *bad_page; ··· 2550 goto out_free_2; 2551 register_reboot_notifier(&kvm_reboot_notifier); 2552 2553 - r = sysdev_class_register(&kvm_sysdev_class); 2554 - if (r) 2555 - goto out_free_3; 2556 - 2557 - r = sysdev_register(&kvm_sysdev); 2558 - if (r) 2559 - goto out_free_4; 2560 - 2561 /* A kmem cache lets us meet the alignment requirements of fx_save. */ 2562 if (!vcpu_align) 2563 vcpu_align = __alignof__(struct kvm_vcpu); ··· 2557 0, NULL); 2558 if (!kvm_vcpu_cache) { 2559 r = -ENOMEM; 2560 - goto out_free_5; 2561 } 2562 2563 r = kvm_async_pf_init(); ··· 2574 goto out_unreg; 2575 } 2576 2577 kvm_preempt_ops.sched_in = kvm_sched_in; 2578 kvm_preempt_ops.sched_out = kvm_sched_out; 2579 ··· 2587 kvm_async_pf_deinit(); 2588 out_free: 2589 kmem_cache_destroy(kvm_vcpu_cache); 2590 - out_free_5: 2591 - sysdev_unregister(&kvm_sysdev); 2592 - out_free_4: 2593 - sysdev_class_unregister(&kvm_sysdev_class); 2594 out_free_3: 2595 unregister_reboot_notifier(&kvm_reboot_notifier); 2596 unregister_cpu_notifier(&kvm_cpu_notifier); ··· 2614 misc_deregister(&kvm_dev); 2615 kmem_cache_destroy(kvm_vcpu_cache); 2616 kvm_async_pf_deinit(); 2617 - sysdev_unregister(&kvm_sysdev); 2618 - sysdev_class_unregister(&kvm_sysdev_class); 2619 unregister_reboot_notifier(&kvm_reboot_notifier); 2620 unregister_cpu_notifier(&kvm_cpu_notifier); 2621 on_each_cpu(hardware_disable_nolock, NULL, 1);
··· 30 #include <linux/debugfs.h> 31 #include <linux/highmem.h> 32 #include <linux/file.h> 33 + #include <linux/syscore_ops.h> 34 #include <linux/cpu.h> 35 #include <linux/sched.h> 36 #include <linux/cpumask.h> ··· 2447 debugfs_remove(kvm_debugfs_dir); 2448 } 2449 2450 + static int kvm_suspend(void) 2451 { 2452 if (kvm_usage_count) 2453 hardware_disable_nolock(NULL); 2454 return 0; 2455 } 2456 2457 + static void kvm_resume(void) 2458 { 2459 if (kvm_usage_count) { 2460 WARN_ON(raw_spin_is_locked(&kvm_lock)); 2461 hardware_enable_nolock(NULL); 2462 } 2463 } 2464 2465 + static struct syscore_ops kvm_syscore_ops = { 2466 .suspend = kvm_suspend, 2467 .resume = kvm_resume, 2468 }; 2469 2470 struct page *bad_page; ··· 2557 goto out_free_2; 2558 register_reboot_notifier(&kvm_reboot_notifier); 2559 2560 /* A kmem cache lets us meet the alignment requirements of fx_save. */ 2561 if (!vcpu_align) 2562 vcpu_align = __alignof__(struct kvm_vcpu); ··· 2572 0, NULL); 2573 if (!kvm_vcpu_cache) { 2574 r = -ENOMEM; 2575 + goto out_free_3; 2576 } 2577 2578 r = kvm_async_pf_init(); ··· 2589 goto out_unreg; 2590 } 2591 2592 + register_syscore_ops(&kvm_syscore_ops); 2593 + 2594 kvm_preempt_ops.sched_in = kvm_sched_in; 2595 kvm_preempt_ops.sched_out = kvm_sched_out; 2596 ··· 2600 kvm_async_pf_deinit(); 2601 out_free: 2602 kmem_cache_destroy(kvm_vcpu_cache); 2603 out_free_3: 2604 unregister_reboot_notifier(&kvm_reboot_notifier); 2605 unregister_cpu_notifier(&kvm_cpu_notifier); ··· 2631 misc_deregister(&kvm_dev); 2632 kmem_cache_destroy(kvm_vcpu_cache); 2633 kvm_async_pf_deinit(); 2634 + unregister_syscore_ops(&kvm_syscore_ops); 2635 unregister_reboot_notifier(&kvm_reboot_notifier); 2636 unregister_cpu_notifier(&kvm_cpu_notifier); 2637 on_each_cpu(hardware_disable_nolock, NULL, 1);