diff options
Diffstat (limited to 'drivers/lguest')
-rw-r--r-- | drivers/lguest/lg.h | 1 | ||||
-rw-r--r-- | drivers/lguest/lguest_device.c | 25 | ||||
-rw-r--r-- | drivers/lguest/x86/core.c | 15 |
3 files changed, 19 insertions, 22 deletions
diff --git a/drivers/lguest/lg.h b/drivers/lguest/lg.h index 005bd045d2eb..5faefeaf6790 100644 --- a/drivers/lguest/lg.h +++ b/drivers/lguest/lg.h | |||
@@ -136,7 +136,6 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user); | |||
136 | * first step in the migration to the kernel types. pte_pfn is already defined | 136 | * first step in the migration to the kernel types. pte_pfn is already defined |
137 | * in the kernel. */ | 137 | * in the kernel. */ |
138 | #define pgd_flags(x) (pgd_val(x) & ~PAGE_MASK) | 138 | #define pgd_flags(x) (pgd_val(x) & ~PAGE_MASK) |
139 | #define pte_flags(x) (pte_val(x) & ~PAGE_MASK) | ||
140 | #define pgd_pfn(x) (pgd_val(x) >> PAGE_SHIFT) | 139 | #define pgd_pfn(x) (pgd_val(x) >> PAGE_SHIFT) |
141 | 140 | ||
142 | /* interrupts_and_traps.c: */ | 141 | /* interrupts_and_traps.c: */ |
diff --git a/drivers/lguest/lguest_device.c b/drivers/lguest/lguest_device.c index 8080249957af..1a8de57289eb 100644 --- a/drivers/lguest/lguest_device.c +++ b/drivers/lguest/lguest_device.c | |||
@@ -20,14 +20,11 @@ | |||
20 | /* The pointer to our (page) of device descriptions. */ | 20 | /* The pointer to our (page) of device descriptions. */ |
21 | static void *lguest_devices; | 21 | static void *lguest_devices; |
22 | 22 | ||
23 | /* Unique numbering for lguest devices. */ | ||
24 | static unsigned int dev_index; | ||
25 | |||
26 | /* For Guests, device memory can be used as normal memory, so we cast away the | 23 | /* For Guests, device memory can be used as normal memory, so we cast away the |
27 | * __iomem to quieten sparse. */ | 24 | * __iomem to quieten sparse. */ |
28 | static inline void *lguest_map(unsigned long phys_addr, unsigned long pages) | 25 | static inline void *lguest_map(unsigned long phys_addr, unsigned long pages) |
29 | { | 26 | { |
30 | return (__force void *)ioremap(phys_addr, PAGE_SIZE*pages); | 27 | return (__force void *)ioremap_cache(phys_addr, PAGE_SIZE*pages); |
31 | } | 28 | } |
32 | 29 | ||
33 | static inline void lguest_unmap(void *addr) | 30 | static inline void lguest_unmap(void *addr) |
@@ -325,8 +322,10 @@ static struct device lguest_root = { | |||
325 | * As Andrew Tridgell says, "Untested code is buggy code". | 322 | * As Andrew Tridgell says, "Untested code is buggy code". |
326 | * | 323 | * |
327 | * It's worth reading this carefully: we start with a pointer to the new device | 324 | * It's worth reading this carefully: we start with a pointer to the new device |
328 | * descriptor in the "lguest_devices" page. */ | 325 | * descriptor in the "lguest_devices" page, and the offset into the device |
329 | static void add_lguest_device(struct lguest_device_desc *d) | 326 | * descriptor page so we can uniquely identify it if things go badly wrong. */ |
327 | static void add_lguest_device(struct lguest_device_desc *d, | ||
328 | unsigned int offset) | ||
330 | { | 329 | { |
331 | struct lguest_device *ldev; | 330 | struct lguest_device *ldev; |
332 | 331 | ||
@@ -334,18 +333,14 @@ static void add_lguest_device(struct lguest_device_desc *d) | |||
334 | * it. */ | 333 | * it. */ |
335 | ldev = kzalloc(sizeof(*ldev), GFP_KERNEL); | 334 | ldev = kzalloc(sizeof(*ldev), GFP_KERNEL); |
336 | if (!ldev) { | 335 | if (!ldev) { |
337 | printk(KERN_EMERG "Cannot allocate lguest dev %u\n", | 336 | printk(KERN_EMERG "Cannot allocate lguest dev %u type %u\n", |
338 | dev_index++); | 337 | offset, d->type); |
339 | return; | 338 | return; |
340 | } | 339 | } |
341 | 340 | ||
342 | /* This devices' parent is the lguest/ dir. */ | 341 | /* This devices' parent is the lguest/ dir. */ |
343 | ldev->vdev.dev.parent = &lguest_root; | 342 | ldev->vdev.dev.parent = &lguest_root; |
344 | /* We have a unique device index thanks to the dev_index counter. */ | 343 | /* We have a unique device index thanks to the dev_index counter. */ |
345 | ldev->vdev.index = dev_index++; | ||
346 | /* The device type comes straight from the descriptor. There's also a | ||
347 | * device vendor field in the virtio_device struct, which we leave as | ||
348 | * 0. */ | ||
349 | ldev->vdev.id.device = d->type; | 344 | ldev->vdev.id.device = d->type; |
350 | /* We have a simple set of routines for querying the device's | 345 | /* We have a simple set of routines for querying the device's |
351 | * configuration information and setting its status. */ | 346 | * configuration information and setting its status. */ |
@@ -357,8 +352,8 @@ static void add_lguest_device(struct lguest_device_desc *d) | |||
357 | * virtio_device and calls device_register(). This makes the bus | 352 | * virtio_device and calls device_register(). This makes the bus |
358 | * infrastructure look for a matching driver. */ | 353 | * infrastructure look for a matching driver. */ |
359 | if (register_virtio_device(&ldev->vdev) != 0) { | 354 | if (register_virtio_device(&ldev->vdev) != 0) { |
360 | printk(KERN_ERR "Failed to register lguest device %u\n", | 355 | printk(KERN_ERR "Failed to register lguest dev %u type %u\n", |
361 | ldev->vdev.index); | 356 | offset, d->type); |
362 | kfree(ldev); | 357 | kfree(ldev); |
363 | } | 358 | } |
364 | } | 359 | } |
@@ -379,7 +374,7 @@ static void scan_devices(void) | |||
379 | break; | 374 | break; |
380 | 375 | ||
381 | printk("Device at %i has size %u\n", i, desc_size(d)); | 376 | printk("Device at %i has size %u\n", i, desc_size(d)); |
382 | add_lguest_device(d); | 377 | add_lguest_device(d, i); |
383 | } | 378 | } |
384 | } | 379 | } |
385 | 380 | ||
diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c index 5126d5d9ea0e..2e554a4ab337 100644 --- a/drivers/lguest/x86/core.c +++ b/drivers/lguest/x86/core.c | |||
@@ -176,7 +176,7 @@ void lguest_arch_run_guest(struct lg_cpu *cpu) | |||
176 | * we set it now, so we can trap and pass that trap to the Guest if it | 176 | * we set it now, so we can trap and pass that trap to the Guest if it |
177 | * uses the FPU. */ | 177 | * uses the FPU. */ |
178 | if (cpu->ts) | 178 | if (cpu->ts) |
179 | lguest_set_ts(); | 179 | unlazy_fpu(current); |
180 | 180 | ||
181 | /* SYSENTER is an optimized way of doing system calls. We can't allow | 181 | /* SYSENTER is an optimized way of doing system calls. We can't allow |
182 | * it because it always jumps to privilege level 0. A normal Guest | 182 | * it because it always jumps to privilege level 0. A normal Guest |
@@ -196,6 +196,10 @@ void lguest_arch_run_guest(struct lg_cpu *cpu) | |||
196 | * trap made the switcher code come back, and an error code which some | 196 | * trap made the switcher code come back, and an error code which some |
197 | * traps set. */ | 197 | * traps set. */ |
198 | 198 | ||
199 | /* Restore SYSENTER if it's supposed to be on. */ | ||
200 | if (boot_cpu_has(X86_FEATURE_SEP)) | ||
201 | wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0); | ||
202 | |||
199 | /* If the Guest page faulted, then the cr2 register will tell us the | 203 | /* If the Guest page faulted, then the cr2 register will tell us the |
200 | * bad virtual address. We have to grab this now, because once we | 204 | * bad virtual address. We have to grab this now, because once we |
201 | * re-enable interrupts an interrupt could fault and thus overwrite | 205 | * re-enable interrupts an interrupt could fault and thus overwrite |
@@ -203,13 +207,12 @@ void lguest_arch_run_guest(struct lg_cpu *cpu) | |||
203 | if (cpu->regs->trapnum == 14) | 207 | if (cpu->regs->trapnum == 14) |
204 | cpu->arch.last_pagefault = read_cr2(); | 208 | cpu->arch.last_pagefault = read_cr2(); |
205 | /* Similarly, if we took a trap because the Guest used the FPU, | 209 | /* Similarly, if we took a trap because the Guest used the FPU, |
206 | * we have to restore the FPU it expects to see. */ | 210 | * we have to restore the FPU it expects to see. |
211 | * math_state_restore() may sleep and we may even move off to | ||
212 | * a different CPU. So all the critical stuff should be done | ||
213 | * before this. */ | ||
207 | else if (cpu->regs->trapnum == 7) | 214 | else if (cpu->regs->trapnum == 7) |
208 | math_state_restore(); | 215 | math_state_restore(); |
209 | |||
210 | /* Restore SYSENTER if it's supposed to be on. */ | ||
211 | if (boot_cpu_has(X86_FEATURE_SEP)) | ||
212 | wrmsr(MSR_IA32_SYSENTER_CS, __KERNEL_CS, 0); | ||
213 | } | 216 | } |
214 | 217 | ||
215 | /*H:130 Now we've examined the hypercall code; our Guest can make requests. | 218 | /*H:130 Now we've examined the hypercall code; our Guest can make requests. |