diff options
author | Carsten Otte <cotte@de.ibm.com> | 2007-10-29 11:08:51 -0400 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2008-01-30 10:52:57 -0500 |
commit | 5fb76f9be1a050a25e21a44ab2003c9d36a72a77 (patch) | |
tree | fa5a184ade52e55746efb1bab59fa283ee3535ed /drivers | |
parent | 1fe779f8eccd16e527315e1bafd2b3a876ff2489 (diff) |
KVM: Portability: Move memory segmentation to x86.c
This patch moves the definition of segment_descriptor_64 for AMD64 and
EM64T from kvm_main.c to segment_descriptor.h. It also adds a proper
#ifndef...#define...#endif around that header file.
The implementation of segment_base is moved from kvm_main.c to x86.c.
Signed-off-by: Carsten Otte <cotte@de.ibm.com>
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
Acked-by: Hollis Blanchard <hollisb@us.ibm.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers')
-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 c632e3a3b51..cf163bddfbd 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 71fdf458619..56fc4c87338 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 b84cb6707f7..5a959220410 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. |