aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/kvm/kvm_main.c
diff options
context:
space:
mode:
authorMike Day <ncmike@ncultra.org>2007-10-08 09:02:08 -0400
committerAvi Kivity <avi@qumranet.com>2008-01-30 10:52:50 -0500
commitd77c26fce93d07802db97498959587eb9347b31d (patch)
treeed49397152d9a8c2ce3dda751a235283f07ef220 /drivers/kvm/kvm_main.c
parent7e620d16b8838bc0ad5b27d2dd55796270cd588c (diff)
KVM: CodingStyle cleanup
Signed-off-by: Mike D. Day <ncmike@ncultra.org> Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/kvm_main.c')
-rw-r--r--drivers/kvm/kvm_main.c58
1 files changed, 30 insertions, 28 deletions
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 9ea9277014aa..a1983d2d5b8f 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -104,7 +104,7 @@ static struct dentry *debugfs_dir;
104#define EFER_RESERVED_BITS 0xfffffffffffff2fe 104#define EFER_RESERVED_BITS 0xfffffffffffff2fe
105 105
106#ifdef CONFIG_X86_64 106#ifdef CONFIG_X86_64
107// LDT or TSS descriptor in the GDT. 16 bytes. 107/* LDT or TSS descriptor in the GDT. 16 bytes. */
108struct segment_descriptor_64 { 108struct segment_descriptor_64 {
109 struct segment_descriptor s; 109 struct segment_descriptor s;
110 u32 base_higher; 110 u32 base_higher;
@@ -121,27 +121,27 @@ unsigned long segment_base(u16 selector)
121 struct descriptor_table gdt; 121 struct descriptor_table gdt;
122 struct segment_descriptor *d; 122 struct segment_descriptor *d;
123 unsigned long table_base; 123 unsigned long table_base;
124 typedef unsigned long ul;
125 unsigned long v; 124 unsigned long v;
126 125
127 if (selector == 0) 126 if (selector == 0)
128 return 0; 127 return 0;
129 128
130 asm ("sgdt %0" : "=m"(gdt)); 129 asm("sgdt %0" : "=m"(gdt));
131 table_base = gdt.base; 130 table_base = gdt.base;
132 131
133 if (selector & 4) { /* from ldt */ 132 if (selector & 4) { /* from ldt */
134 u16 ldt_selector; 133 u16 ldt_selector;
135 134
136 asm ("sldt %0" : "=g"(ldt_selector)); 135 asm("sldt %0" : "=g"(ldt_selector));
137 table_base = segment_base(ldt_selector); 136 table_base = segment_base(ldt_selector);
138 } 137 }
139 d = (struct segment_descriptor *)(table_base + (selector & ~7)); 138 d = (struct segment_descriptor *)(table_base + (selector & ~7));
140 v = d->base_low | ((ul)d->base_mid << 16) | ((ul)d->base_high << 24); 139 v = d->base_low | ((unsigned long)d->base_mid << 16) |
140 ((unsigned long)d->base_high << 24);
141#ifdef CONFIG_X86_64 141#ifdef CONFIG_X86_64
142 if (d->system == 0 142 if (d->system == 0 && (d->type == 2 || d->type == 9 || d->type == 11))
143 && (d->type == 2 || d->type == 9 || d->type == 11)) 143 v |= ((unsigned long) \
144 v |= ((ul)((struct segment_descriptor_64 *)d)->base_higher) << 32; 144 ((struct segment_descriptor_64 *)d)->base_higher) << 32;
145#endif 145#endif
146 return v; 146 return v;
147} 147}
@@ -721,7 +721,7 @@ static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
721 if (!new.phys_mem) 721 if (!new.phys_mem)
722 goto out_unlock; 722 goto out_unlock;
723 723
724 new.rmap = vmalloc(npages * sizeof(struct page*)); 724 new.rmap = vmalloc(npages * sizeof(struct page *));
725 725
726 if (!new.rmap) 726 if (!new.rmap)
727 goto out_unlock; 727 goto out_unlock;
@@ -904,17 +904,17 @@ static int kvm_vm_ioctl_get_irqchip(struct kvm *kvm, struct kvm_irqchip *chip)
904 r = 0; 904 r = 0;
905 switch (chip->chip_id) { 905 switch (chip->chip_id) {
906 case KVM_IRQCHIP_PIC_MASTER: 906 case KVM_IRQCHIP_PIC_MASTER:
907 memcpy (&chip->chip.pic, 907 memcpy(&chip->chip.pic,
908 &pic_irqchip(kvm)->pics[0], 908 &pic_irqchip(kvm)->pics[0],
909 sizeof(struct kvm_pic_state)); 909 sizeof(struct kvm_pic_state));
910 break; 910 break;
911 case KVM_IRQCHIP_PIC_SLAVE: 911 case KVM_IRQCHIP_PIC_SLAVE:
912 memcpy (&chip->chip.pic, 912 memcpy(&chip->chip.pic,
913 &pic_irqchip(kvm)->pics[1], 913 &pic_irqchip(kvm)->pics[1],
914 sizeof(struct kvm_pic_state)); 914 sizeof(struct kvm_pic_state));
915 break; 915 break;
916 case KVM_IRQCHIP_IOAPIC: 916 case KVM_IRQCHIP_IOAPIC:
917 memcpy (&chip->chip.ioapic, 917 memcpy(&chip->chip.ioapic,
918 ioapic_irqchip(kvm), 918 ioapic_irqchip(kvm),
919 sizeof(struct kvm_ioapic_state)); 919 sizeof(struct kvm_ioapic_state));
920 break; 920 break;
@@ -932,17 +932,17 @@ static int kvm_vm_ioctl_set_irqchip(struct kvm *kvm, struct kvm_irqchip *chip)
932 r = 0; 932 r = 0;
933 switch (chip->chip_id) { 933 switch (chip->chip_id) {
934 case KVM_IRQCHIP_PIC_MASTER: 934 case KVM_IRQCHIP_PIC_MASTER:
935 memcpy (&pic_irqchip(kvm)->pics[0], 935 memcpy(&pic_irqchip(kvm)->pics[0],
936 &chip->chip.pic, 936 &chip->chip.pic,
937 sizeof(struct kvm_pic_state)); 937 sizeof(struct kvm_pic_state));
938 break; 938 break;
939 case KVM_IRQCHIP_PIC_SLAVE: 939 case KVM_IRQCHIP_PIC_SLAVE:
940 memcpy (&pic_irqchip(kvm)->pics[1], 940 memcpy(&pic_irqchip(kvm)->pics[1],
941 &chip->chip.pic, 941 &chip->chip.pic,
942 sizeof(struct kvm_pic_state)); 942 sizeof(struct kvm_pic_state));
943 break; 943 break;
944 case KVM_IRQCHIP_IOAPIC: 944 case KVM_IRQCHIP_IOAPIC:
945 memcpy (ioapic_irqchip(kvm), 945 memcpy(ioapic_irqchip(kvm),
946 &chip->chip.ioapic, 946 &chip->chip.ioapic,
947 sizeof(struct kvm_ioapic_state)); 947 sizeof(struct kvm_ioapic_state));
948 break; 948 break;
@@ -1341,7 +1341,7 @@ int emulate_clts(struct kvm_vcpu *vcpu)
1341 return X86EMUL_CONTINUE; 1341 return X86EMUL_CONTINUE;
1342} 1342}
1343 1343
1344int emulator_get_dr(struct x86_emulate_ctxt* ctxt, int dr, unsigned long *dest) 1344int emulator_get_dr(struct x86_emulate_ctxt *ctxt, int dr, unsigned long *dest)
1345{ 1345{
1346 struct kvm_vcpu *vcpu = ctxt->vcpu; 1346 struct kvm_vcpu *vcpu = ctxt->vcpu;
1347 1347
@@ -1934,7 +1934,7 @@ static void pio_string_write(struct kvm_io_device *pio_dev,
1934 mutex_unlock(&vcpu->kvm->lock); 1934 mutex_unlock(&vcpu->kvm->lock);
1935} 1935}
1936 1936
1937int kvm_emulate_pio (struct kvm_vcpu *vcpu, struct kvm_run *run, int in, 1937int kvm_emulate_pio(struct kvm_vcpu *vcpu, struct kvm_run *run, int in,
1938 int size, unsigned port) 1938 int size, unsigned port)
1939{ 1939{
1940 struct kvm_io_device *pio_dev; 1940 struct kvm_io_device *pio_dev;
@@ -2089,7 +2089,7 @@ static int __vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
2089 int r; 2089 int r;
2090 2090
2091 if (unlikely(vcpu->mp_state == VCPU_MP_STATE_SIPI_RECEIVED)) { 2091 if (unlikely(vcpu->mp_state == VCPU_MP_STATE_SIPI_RECEIVED)) {
2092 printk("vcpu %d received sipi with vector # %x\n", 2092 pr_debug("vcpu %d received sipi with vector # %x\n",
2093 vcpu->vcpu_id, vcpu->sipi_vector); 2093 vcpu->vcpu_id, vcpu->sipi_vector);
2094 kvm_lapic_reset(vcpu); 2094 kvm_lapic_reset(vcpu);
2095 kvm_x86_ops->vcpu_reset(vcpu); 2095 kvm_x86_ops->vcpu_reset(vcpu);
@@ -2363,7 +2363,8 @@ static int kvm_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu,
2363 sizeof sregs->interrupt_bitmap); 2363 sizeof sregs->interrupt_bitmap);
2364 pending_vec = kvm_x86_ops->get_irq(vcpu); 2364 pending_vec = kvm_x86_ops->get_irq(vcpu);
2365 if (pending_vec >= 0) 2365 if (pending_vec >= 0)
2366 set_bit(pending_vec, (unsigned long *)sregs->interrupt_bitmap); 2366 set_bit(pending_vec,
2367 (unsigned long *)sregs->interrupt_bitmap);
2367 } else 2368 } else
2368 memcpy(sregs->interrupt_bitmap, vcpu->irq_pending, 2369 memcpy(sregs->interrupt_bitmap, vcpu->irq_pending,
2369 sizeof sregs->interrupt_bitmap); 2370 sizeof sregs->interrupt_bitmap);
@@ -2436,7 +2437,8 @@ static int kvm_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
2436 /* Only pending external irq is handled here */ 2437 /* Only pending external irq is handled here */
2437 if (pending_vec < max_bits) { 2438 if (pending_vec < max_bits) {
2438 kvm_x86_ops->set_irq(vcpu, pending_vec); 2439 kvm_x86_ops->set_irq(vcpu, pending_vec);
2439 printk("Set back pending irq %d\n", pending_vec); 2440 pr_debug("Set back pending irq %d\n",
2441 pending_vec);
2440 } 2442 }
2441 } 2443 }
2442 2444
@@ -3155,8 +3157,7 @@ static long kvm_vm_ioctl(struct file *filp,
3155 kvm->vpic = NULL; 3157 kvm->vpic = NULL;
3156 goto out; 3158 goto out;
3157 } 3159 }
3158 } 3160 } else
3159 else
3160 goto out; 3161 goto out;
3161 break; 3162 break;
3162 case KVM_IRQ_LINE: { 3163 case KVM_IRQ_LINE: {
@@ -3448,7 +3449,7 @@ static int kvm_cpu_hotplug(struct notifier_block *notifier, unsigned long val,
3448} 3449}
3449 3450
3450static int kvm_reboot(struct notifier_block *notifier, unsigned long val, 3451static int kvm_reboot(struct notifier_block *notifier, unsigned long val,
3451 void *v) 3452 void *v)
3452{ 3453{
3453 if (val == SYS_RESTART) { 3454 if (val == SYS_RESTART) {
3454 /* 3455 /*
@@ -3655,7 +3656,7 @@ int kvm_init_x86(struct kvm_x86_ops *ops, unsigned int vcpu_size,
3655 3656
3656 r = misc_register(&kvm_dev); 3657 r = misc_register(&kvm_dev);
3657 if (r) { 3658 if (r) {
3658 printk (KERN_ERR "kvm: misc device register failed\n"); 3659 printk(KERN_ERR "kvm: misc device register failed\n");
3659 goto out_free; 3660 goto out_free;
3660 } 3661 }
3661 3662
@@ -3683,6 +3684,7 @@ out:
3683 kvm_x86_ops = NULL; 3684 kvm_x86_ops = NULL;
3684 return r; 3685 return r;
3685} 3686}
3687EXPORT_SYMBOL_GPL(kvm_init_x86);
3686 3688
3687void kvm_exit_x86(void) 3689void kvm_exit_x86(void)
3688{ 3690{
@@ -3696,6 +3698,7 @@ void kvm_exit_x86(void)
3696 kvm_x86_ops->hardware_unsetup(); 3698 kvm_x86_ops->hardware_unsetup();
3697 kvm_x86_ops = NULL; 3699 kvm_x86_ops = NULL;
3698} 3700}
3701EXPORT_SYMBOL_GPL(kvm_exit_x86);
3699 3702
3700static __init int kvm_init(void) 3703static __init int kvm_init(void)
3701{ 3704{
@@ -3710,7 +3713,9 @@ static __init int kvm_init(void)
3710 3713
3711 kvm_init_msr_list(); 3714 kvm_init_msr_list();
3712 3715
3713 if ((bad_page = alloc_page(GFP_KERNEL)) == NULL) { 3716 bad_page = alloc_page(GFP_KERNEL);
3717
3718 if (bad_page == NULL) {
3714 r = -ENOMEM; 3719 r = -ENOMEM;
3715 goto out; 3720 goto out;
3716 } 3721 }
@@ -3736,6 +3741,3 @@ static __exit void kvm_exit(void)
3736 3741
3737module_init(kvm_init) 3742module_init(kvm_init)
3738module_exit(kvm_exit) 3743module_exit(kvm_exit)
3739
3740EXPORT_SYMBOL_GPL(kvm_init_x86);
3741EXPORT_SYMBOL_GPL(kvm_exit_x86);