aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/kvm_main.c
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2007-07-30 07:12:19 -0400
committerAvi Kivity <avi@qumranet.com>2007-10-13 04:18:21 -0400
commitc16f862d0257349607b7a9be7b4a4b7ed419a3ab (patch)
treef84e9f43f845640a0cc887fe8697ab0b3a4e788b /drivers/kvm/kvm_main.c
parente7d5d76cae970117affe07f809faf0f18bbac675 (diff)
KVM: Use kmem cache for allocating vcpus
Avi wants the allocations of vcpus centralized again. The easiest way is to add a "size" arg to kvm_init_arch, and expose the thus-prepared cache to the modules. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/kvm_main.c')
-rw-r--r--drivers/kvm/kvm_main.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 4bbd89e03324..4166a08ce500 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -53,6 +53,8 @@ static LIST_HEAD(vm_list);
53static cpumask_t cpus_hardware_enabled; 53static cpumask_t cpus_hardware_enabled;
54 54
55struct kvm_arch_ops *kvm_arch_ops; 55struct kvm_arch_ops *kvm_arch_ops;
56struct kmem_cache *kvm_vcpu_cache;
57EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
56 58
57static __read_mostly struct preempt_ops kvm_preempt_ops; 59static __read_mostly struct preempt_ops kvm_preempt_ops;
58 60
@@ -3104,7 +3106,8 @@ static void kvm_sched_out(struct preempt_notifier *pn,
3104 kvm_arch_ops->vcpu_put(vcpu); 3106 kvm_arch_ops->vcpu_put(vcpu);
3105} 3107}
3106 3108
3107int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module) 3109int kvm_init_arch(struct kvm_arch_ops *ops, unsigned int vcpu_size,
3110 struct module *module)
3108{ 3111{
3109 int r; 3112 int r;
3110 3113
@@ -3142,6 +3145,14 @@ int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module)
3142 if (r) 3145 if (r)
3143 goto out_free_3; 3146 goto out_free_3;
3144 3147
3148 /* A kmem cache lets us meet the alignment requirements of fx_save. */
3149 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size,
3150 __alignof__(struct kvm_vcpu), 0, 0);
3151 if (!kvm_vcpu_cache) {
3152 r = -ENOMEM;
3153 goto out_free_4;
3154 }
3155
3145 kvm_chardev_ops.owner = module; 3156 kvm_chardev_ops.owner = module;
3146 3157
3147 r = misc_register(&kvm_dev); 3158 r = misc_register(&kvm_dev);
@@ -3156,6 +3167,8 @@ int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module)
3156 return r; 3167 return r;
3157 3168
3158out_free: 3169out_free:
3170 kmem_cache_destroy(kvm_vcpu_cache);
3171out_free_4:
3159 sysdev_unregister(&kvm_sysdev); 3172 sysdev_unregister(&kvm_sysdev);
3160out_free_3: 3173out_free_3:
3161 sysdev_class_unregister(&kvm_sysdev_class); 3174 sysdev_class_unregister(&kvm_sysdev_class);
@@ -3173,6 +3186,7 @@ out:
3173void kvm_exit_arch(void) 3186void kvm_exit_arch(void)
3174{ 3187{
3175 misc_deregister(&kvm_dev); 3188 misc_deregister(&kvm_dev);
3189 kmem_cache_destroy(kvm_vcpu_cache);
3176 sysdev_unregister(&kvm_sysdev); 3190 sysdev_unregister(&kvm_sysdev);
3177 sysdev_class_unregister(&kvm_sysdev_class); 3191 sysdev_class_unregister(&kvm_sysdev_class);
3178 unregister_reboot_notifier(&kvm_reboot_notifier); 3192 unregister_reboot_notifier(&kvm_reboot_notifier);