aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm
diff options
context:
space:
mode:
authorZhang Xiantao <xiantao.zhang@intel.com>2007-11-14 07:40:21 -0500
committerAvi Kivity <avi@qumranet.com>2008-01-30 10:53:03 -0500
commitf8c16bbaa9e14b309ffcf29cac0ea377a35b0dd2 (patch)
treefde560989f7c3aa77d0f869a90084369c72d7dc4 /drivers/kvm
parentcb498ea2ce1d3f3c0bc0a2522241dca10263e437 (diff)
KVM: Portability: Move x86 specific code from kvm_init() to kvm_arch()
Signed-off-by: Zhang Xiantao <xiantao.zhang@intel.com> Acked-by: Carsten Otte <cotte@de.ibm.com> Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm')
-rw-r--r--drivers/kvm/kvm.h5
-rw-r--r--drivers/kvm/kvm_main.c26
-rw-r--r--drivers/kvm/x86.c27
3 files changed, 35 insertions, 23 deletions
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 5e7be1504664..96d9c7da14c2 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -495,7 +495,7 @@ void vcpu_put(struct kvm_vcpu *vcpu);
495void decache_vcpus_on_cpu(int cpu); 495void decache_vcpus_on_cpu(int cpu);
496 496
497 497
498int kvm_init(struct kvm_x86_ops *ops, unsigned int vcpu_size, 498int kvm_init(void *opaque, unsigned int vcpu_size,
499 struct module *module); 499 struct module *module);
500void kvm_exit(void); 500void kvm_exit(void);
501 501
@@ -649,7 +649,8 @@ int kvm_arch_vcpu_ioctl_debug_guest(struct kvm_vcpu *vcpu,
649 struct kvm_debug_guest *dbg); 649 struct kvm_debug_guest *dbg);
650int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run); 650int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
651 651
652__init void kvm_arch_init(void); 652int kvm_arch_init(void *opaque);
653void kvm_arch_exit(void);
653 654
654int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu); 655int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
655void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu); 656void kvm_arch_vcpu_uninit(struct kvm_vcpu *vcpu);
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 2b3736e7483c..e0f20d020281 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1434,7 +1434,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
1434 kvm_arch_vcpu_put(vcpu); 1434 kvm_arch_vcpu_put(vcpu);
1435} 1435}
1436 1436
1437int kvm_init(struct kvm_x86_ops *ops, unsigned int vcpu_size, 1437int kvm_init(void *opaque, unsigned int vcpu_size,
1438 struct module *module) 1438 struct module *module)
1439{ 1439{
1440 int r; 1440 int r;
@@ -1446,7 +1446,9 @@ int kvm_init(struct kvm_x86_ops *ops, unsigned int vcpu_size,
1446 1446
1447 kvm_init_debug(); 1447 kvm_init_debug();
1448 1448
1449 kvm_arch_init(); 1449 r = kvm_arch_init(opaque);
1450 if (r)
1451 goto out4;
1450 1452
1451 bad_page = alloc_page(GFP_KERNEL | __GFP_ZERO); 1453 bad_page = alloc_page(GFP_KERNEL | __GFP_ZERO);
1452 1454
@@ -1455,22 +1457,6 @@ int kvm_init(struct kvm_x86_ops *ops, unsigned int vcpu_size,
1455 goto out; 1457 goto out;
1456 } 1458 }
1457 1459
1458 if (kvm_x86_ops) {
1459 printk(KERN_ERR "kvm: already loaded the other module\n");
1460 return -EEXIST;
1461 }
1462
1463 if (!ops->cpu_has_kvm_support()) {
1464 printk(KERN_ERR "kvm: no hardware support\n");
1465 return -EOPNOTSUPP;
1466 }
1467 if (ops->disabled_by_bios()) {
1468 printk(KERN_ERR "kvm: disabled by bios\n");
1469 return -EOPNOTSUPP;
1470 }
1471
1472 kvm_x86_ops = ops;
1473
1474 r = kvm_arch_hardware_setup(); 1460 r = kvm_arch_hardware_setup();
1475 if (r < 0) 1461 if (r < 0)
1476 goto out; 1462 goto out;
@@ -1534,7 +1520,7 @@ out_free_1:
1534out_free_0: 1520out_free_0:
1535 kvm_arch_hardware_unsetup(); 1521 kvm_arch_hardware_unsetup();
1536out: 1522out:
1537 kvm_x86_ops = NULL; 1523 kvm_arch_exit();
1538 kvm_exit_debug(); 1524 kvm_exit_debug();
1539 kvm_mmu_module_exit(); 1525 kvm_mmu_module_exit();
1540out4: 1526out4:
@@ -1552,7 +1538,7 @@ void kvm_exit(void)
1552 unregister_cpu_notifier(&kvm_cpu_notifier); 1538 unregister_cpu_notifier(&kvm_cpu_notifier);
1553 on_each_cpu(hardware_disable, NULL, 0, 1); 1539 on_each_cpu(hardware_disable, NULL, 0, 1);
1554 kvm_arch_hardware_unsetup(); 1540 kvm_arch_hardware_unsetup();
1555 kvm_x86_ops = NULL; 1541 kvm_arch_exit();
1556 kvm_exit_debug(); 1542 kvm_exit_debug();
1557 __free_page(bad_page); 1543 __free_page(bad_page);
1558 kvm_mmu_module_exit(); 1544 kvm_mmu_module_exit();
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c
index 4902b35060f5..bbfa810bf8bd 100644
--- a/drivers/kvm/x86.c
+++ b/drivers/kvm/x86.c
@@ -1645,11 +1645,36 @@ int kvm_emulate_pio_string(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
1645} 1645}
1646EXPORT_SYMBOL_GPL(kvm_emulate_pio_string); 1646EXPORT_SYMBOL_GPL(kvm_emulate_pio_string);
1647 1647
1648__init void kvm_arch_init(void) 1648int kvm_arch_init(void *opaque)
1649{ 1649{
1650 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
1651
1650 kvm_init_msr_list(); 1652 kvm_init_msr_list();
1653
1654 if (kvm_x86_ops) {
1655 printk(KERN_ERR "kvm: already loaded the other module\n");
1656 return -EEXIST;
1657 }
1658
1659 if (!ops->cpu_has_kvm_support()) {
1660 printk(KERN_ERR "kvm: no hardware support\n");
1661 return -EOPNOTSUPP;
1662 }
1663 if (ops->disabled_by_bios()) {
1664 printk(KERN_ERR "kvm: disabled by bios\n");
1665 return -EOPNOTSUPP;
1666 }
1667
1668 kvm_x86_ops = ops;
1669
1670 return 0;
1651} 1671}
1652 1672
1673void kvm_arch_exit(void)
1674{
1675 kvm_x86_ops = NULL;
1676 }
1677
1653int kvm_emulate_halt(struct kvm_vcpu *vcpu) 1678int kvm_emulate_halt(struct kvm_vcpu *vcpu)
1654{ 1679{
1655 ++vcpu->stat.halt_exits; 1680 ++vcpu->stat.halt_exits;