aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/kvm')
-rw-r--r--drivers/kvm/kvm.h4
-rw-r--r--drivers/kvm/kvm_main.c16
-rw-r--r--drivers/kvm/svm.c5
-rw-r--r--drivers/kvm/vmx.c4
4 files changed, 23 insertions, 6 deletions
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 030b93bcdf1b..b362e8f8f832 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -141,6 +141,7 @@ struct kvm_mmu_page {
141}; 141};
142 142
143struct kvm_vcpu; 143struct kvm_vcpu;
144extern struct kmem_cache *kvm_vcpu_cache;
144 145
145/* 146/*
146 * x86 supports 3 paging modes (4-level 64-bit, 3-level 64-bit, and 2-level 147 * x86 supports 3 paging modes (4-level 64-bit, 3-level 64-bit, and 2-level
@@ -483,7 +484,8 @@ extern struct kvm_arch_ops *kvm_arch_ops;
483int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id); 484int kvm_vcpu_init(struct kvm_vcpu *vcpu, struct kvm *kvm, unsigned id);
484void kvm_vcpu_uninit(struct kvm_vcpu *vcpu); 485void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
485 486
486int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module); 487int kvm_init_arch(struct kvm_arch_ops *ops, unsigned int vcpu_size,
488 struct module *module);
487void kvm_exit_arch(void); 489void kvm_exit_arch(void);
488 490
489int kvm_mmu_module_init(void); 491int kvm_mmu_module_init(void);
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);
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index b25f4e117e71..8193651dd815 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -577,7 +577,7 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id)
577 struct page *page; 577 struct page *page;
578 int err; 578 int err;
579 579
580 svm = kzalloc(sizeof *svm, GFP_KERNEL); 580 svm = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
581 if (!svm) { 581 if (!svm) {
582 err = -ENOMEM; 582 err = -ENOMEM;
583 goto out; 583 goto out;
@@ -1849,7 +1849,8 @@ static struct kvm_arch_ops svm_arch_ops = {
1849 1849
1850static int __init svm_init(void) 1850static int __init svm_init(void)
1851{ 1851{
1852 return kvm_init_arch(&svm_arch_ops, THIS_MODULE); 1852 return kvm_init_arch(&svm_arch_ops, sizeof(struct vcpu_svm),
1853 THIS_MODULE);
1853} 1854}
1854 1855
1855static void __exit svm_exit(void) 1856static void __exit svm_exit(void)
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index f770f55d46cd..2b30274656f4 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -2365,7 +2365,7 @@ static void vmx_free_vcpu(struct kvm_vcpu *vcpu)
2365static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id) 2365static struct kvm_vcpu *vmx_create_vcpu(struct kvm *kvm, unsigned int id)
2366{ 2366{
2367 int err; 2367 int err;
2368 struct vcpu_vmx *vmx = kzalloc(sizeof(*vmx), GFP_KERNEL); 2368 struct vcpu_vmx *vmx = kmem_cache_zalloc(kvm_vcpu_cache, GFP_KERNEL);
2369 int cpu; 2369 int cpu;
2370 2370
2371 if (!vmx) 2371 if (!vmx)
@@ -2490,7 +2490,7 @@ static int __init vmx_init(void)
2490 memset(iova, 0xff, PAGE_SIZE); 2490 memset(iova, 0xff, PAGE_SIZE);
2491 kunmap(vmx_io_bitmap_b); 2491 kunmap(vmx_io_bitmap_b);
2492 2492
2493 r = kvm_init_arch(&vmx_arch_ops, THIS_MODULE); 2493 r = kvm_init_arch(&vmx_arch_ops, sizeof(struct vcpu_vmx), THIS_MODULE);
2494 if (r) 2494 if (r)
2495 goto out1; 2495 goto out1;
2496 2496