diff options
-rw-r--r-- | drivers/kvm/kvm_main.c | 42 | ||||
-rw-r--r-- | drivers/kvm/segment_descriptor.h | 12 | ||||
-rw-r--r-- | drivers/kvm/x86.c | 33 |
3 files changed, 45 insertions, 42 deletions
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c index c632e3a3b514..cf163bddfbd3 100644 --- a/drivers/kvm/kvm_main.c +++ b/drivers/kvm/kvm_main.c | |||
@@ -18,7 +18,6 @@ | |||
18 | #include "kvm.h" | 18 | #include "kvm.h" |
19 | #include "x86.h" | 19 | #include "x86.h" |
20 | #include "x86_emulate.h" | 20 | #include "x86_emulate.h" |
21 | #include "segment_descriptor.h" | ||
22 | #include "irq.h" | 21 | #include "irq.h" |
23 | 22 | ||
24 | #include <linux/kvm.h> | 23 | #include <linux/kvm.h> |
@@ -104,50 +103,9 @@ static struct dentry *debugfs_dir; | |||
104 | #define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR) | 103 | #define CR8_RESERVED_BITS (~(unsigned long)X86_CR8_TPR) |
105 | #define EFER_RESERVED_BITS 0xfffffffffffff2fe | 104 | #define EFER_RESERVED_BITS 0xfffffffffffff2fe |
106 | 105 | ||
107 | #ifdef CONFIG_X86_64 | ||
108 | /* LDT or TSS descriptor in the GDT. 16 bytes. */ | ||
109 | struct segment_descriptor_64 { | ||
110 | struct segment_descriptor s; | ||
111 | u32 base_higher; | ||
112 | u32 pad_zero; | ||
113 | }; | ||
114 | |||
115 | #endif | ||
116 | |||
117 | static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl, | 106 | static long kvm_vcpu_ioctl(struct file *file, unsigned int ioctl, |
118 | unsigned long arg); | 107 | unsigned long arg); |
119 | 108 | ||
120 | unsigned long segment_base(u16 selector) | ||
121 | { | ||
122 | struct descriptor_table gdt; | ||
123 | struct segment_descriptor *d; | ||
124 | unsigned long table_base; | ||
125 | unsigned long v; | ||
126 | |||
127 | if (selector == 0) | ||
128 | return 0; | ||
129 | |||
130 | asm("sgdt %0" : "=m"(gdt)); | ||
131 | table_base = gdt.base; | ||
132 | |||
133 | if (selector & 4) { /* from ldt */ | ||
134 | u16 ldt_selector; | ||
135 | |||
136 | asm("sldt %0" : "=g"(ldt_selector)); | ||
137 | table_base = segment_base(ldt_selector); | ||
138 | } | ||
139 | d = (struct segment_descriptor *)(table_base + (selector & ~7)); | ||
140 | v = d->base_low | ((unsigned long)d->base_mid << 16) | | ||
141 | ((unsigned long)d->base_high << 24); | ||
142 | #ifdef CONFIG_X86_64 | ||
143 | if (d->system == 0 && (d->type == 2 || d->type == 9 || d->type == 11)) | ||
144 | v |= ((unsigned long) \ | ||
145 | ((struct segment_descriptor_64 *)d)->base_higher) << 32; | ||
146 | #endif | ||
147 | return v; | ||
148 | } | ||
149 | EXPORT_SYMBOL_GPL(segment_base); | ||
150 | |||
151 | static inline int valid_vcpu(int n) | 109 | static inline int valid_vcpu(int n) |
152 | { | 110 | { |
153 | return likely(n >= 0 && n < KVM_MAX_VCPUS); | 111 | return likely(n >= 0 && n < KVM_MAX_VCPUS); |
diff --git a/drivers/kvm/segment_descriptor.h b/drivers/kvm/segment_descriptor.h index 71fdf458619a..56fc4c873389 100644 --- a/drivers/kvm/segment_descriptor.h +++ b/drivers/kvm/segment_descriptor.h | |||
@@ -1,3 +1,6 @@ | |||
1 | #ifndef __SEGMENT_DESCRIPTOR_H | ||
2 | #define __SEGMENT_DESCRIPTOR_H | ||
3 | |||
1 | struct segment_descriptor { | 4 | struct segment_descriptor { |
2 | u16 limit_low; | 5 | u16 limit_low; |
3 | u16 base_low; | 6 | u16 base_low; |
@@ -14,4 +17,13 @@ struct segment_descriptor { | |||
14 | u8 base_high; | 17 | u8 base_high; |
15 | } __attribute__((packed)); | 18 | } __attribute__((packed)); |
16 | 19 | ||
20 | #ifdef CONFIG_X86_64 | ||
21 | /* LDT or TSS descriptor in the GDT. 16 bytes. */ | ||
22 | struct segment_descriptor_64 { | ||
23 | struct segment_descriptor s; | ||
24 | u32 base_higher; | ||
25 | u32 pad_zero; | ||
26 | }; | ||
17 | 27 | ||
28 | #endif | ||
29 | #endif | ||
diff --git a/drivers/kvm/x86.c b/drivers/kvm/x86.c index b84cb6707f78..5a959220410a 100644 --- a/drivers/kvm/x86.c +++ b/drivers/kvm/x86.c | |||
@@ -16,16 +16,49 @@ | |||
16 | 16 | ||
17 | #include "kvm.h" | 17 | #include "kvm.h" |
18 | #include "x86.h" | 18 | #include "x86.h" |
19 | #include "segment_descriptor.h" | ||
19 | #include "irq.h" | 20 | #include "irq.h" |
20 | 21 | ||
21 | #include <linux/kvm.h> | 22 | #include <linux/kvm.h> |
22 | #include <linux/fs.h> | 23 | #include <linux/fs.h> |
23 | #include <linux/vmalloc.h> | 24 | #include <linux/vmalloc.h> |
25 | #include <linux/module.h> | ||
24 | 26 | ||
25 | #include <asm/uaccess.h> | 27 | #include <asm/uaccess.h> |
26 | 28 | ||
27 | #define MAX_IO_MSRS 256 | 29 | #define MAX_IO_MSRS 256 |
28 | 30 | ||
31 | unsigned long segment_base(u16 selector) | ||
32 | { | ||
33 | struct descriptor_table gdt; | ||
34 | struct segment_descriptor *d; | ||
35 | unsigned long table_base; | ||
36 | unsigned long v; | ||
37 | |||
38 | if (selector == 0) | ||
39 | return 0; | ||
40 | |||
41 | asm("sgdt %0" : "=m"(gdt)); | ||
42 | table_base = gdt.base; | ||
43 | |||
44 | if (selector & 4) { /* from ldt */ | ||
45 | u16 ldt_selector; | ||
46 | |||
47 | asm("sldt %0" : "=g"(ldt_selector)); | ||
48 | table_base = segment_base(ldt_selector); | ||
49 | } | ||
50 | d = (struct segment_descriptor *)(table_base + (selector & ~7)); | ||
51 | v = d->base_low | ((unsigned long)d->base_mid << 16) | | ||
52 | ((unsigned long)d->base_high << 24); | ||
53 | #ifdef CONFIG_X86_64 | ||
54 | if (d->system == 0 && (d->type == 2 || d->type == 9 || d->type == 11)) | ||
55 | v |= ((unsigned long) \ | ||
56 | ((struct segment_descriptor_64 *)d)->base_higher) << 32; | ||
57 | #endif | ||
58 | return v; | ||
59 | } | ||
60 | EXPORT_SYMBOL_GPL(segment_base); | ||
61 | |||
29 | /* | 62 | /* |
30 | * List of msr numbers which we expose to userspace through KVM_GET_MSRS | 63 | * List of msr numbers which we expose to userspace through KVM_GET_MSRS |
31 | * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST. | 64 | * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST. |