aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/lguest/x86/core.c
diff options
context:
space:
mode:
authorGlauber de Oliveira Costa <gcosta@redhat.com>2008-01-07 08:05:32 -0500
committerRusty Russell <rusty@rustcorp.com.au>2008-01-30 06:50:11 -0500
commita53a35a8b485b9c16b73e5177bddaa4321971199 (patch)
tree8ed96838cb47d1263f63aba6dd6921b3c811f46c /drivers/lguest/x86/core.c
parenta3863f68b0d7fe2073c0f4efe534ec87a685c4fa (diff)
lguest: make registers per-vcpu
This is the most obvious per-vcpu field: registers. So this patch moves it from struct lguest to struct vcpu, and patch the places in which they are used, accordingly Signed-off-by: Glauber de Oliveira Costa <gcosta@redhat.com> Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/lguest/x86/core.c')
-rw-r--r--drivers/lguest/x86/core.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
index ae46c6b1f2f..d96a93d95ae 100644
--- a/drivers/lguest/x86/core.c
+++ b/drivers/lguest/x86/core.c
@@ -127,7 +127,7 @@ static void run_guest_once(struct lg_cpu *cpu, struct lguest_pages *pages)
127 /* Set the trap number to 256 (impossible value). If we fault while 127 /* Set the trap number to 256 (impossible value). If we fault while
128 * switching to the Guest (bad segment registers or bug), this will 128 * switching to the Guest (bad segment registers or bug), this will
129 * cause us to abort the Guest. */ 129 * cause us to abort the Guest. */
130 lg->regs->trapnum = 256; 130 cpu->regs->trapnum = 256;
131 131
132 /* Now: we push the "eflags" register on the stack, then do an "lcall". 132 /* Now: we push the "eflags" register on the stack, then do an "lcall".
133 * This is how we change from using the kernel code segment to using 133 * This is how we change from using the kernel code segment to using
@@ -195,11 +195,11 @@ void lguest_arch_run_guest(struct lg_cpu *cpu)
195 * bad virtual address. We have to grab this now, because once we 195 * bad virtual address. We have to grab this now, because once we
196 * re-enable interrupts an interrupt could fault and thus overwrite 196 * re-enable interrupts an interrupt could fault and thus overwrite
197 * cr2, or we could even move off to a different CPU. */ 197 * cr2, or we could even move off to a different CPU. */
198 if (lg->regs->trapnum == 14) 198 if (cpu->regs->trapnum == 14)
199 lg->arch.last_pagefault = read_cr2(); 199 lg->arch.last_pagefault = read_cr2();
200 /* Similarly, if we took a trap because the Guest used the FPU, 200 /* Similarly, if we took a trap because the Guest used the FPU,
201 * we have to restore the FPU it expects to see. */ 201 * we have to restore the FPU it expects to see. */
202 else if (lg->regs->trapnum == 7) 202 else if (cpu->regs->trapnum == 7)
203 math_state_restore(); 203 math_state_restore();
204 204
205 /* Restore SYSENTER if it's supposed to be on. */ 205 /* Restore SYSENTER if it's supposed to be on. */
@@ -225,12 +225,12 @@ static int emulate_insn(struct lg_cpu *cpu)
225 unsigned int insnlen = 0, in = 0, shift = 0; 225 unsigned int insnlen = 0, in = 0, shift = 0;
226 /* The eip contains the *virtual* address of the Guest's instruction: 226 /* The eip contains the *virtual* address of the Guest's instruction:
227 * guest_pa just subtracts the Guest's page_offset. */ 227 * guest_pa just subtracts the Guest's page_offset. */
228 unsigned long physaddr = guest_pa(lg, lg->regs->eip); 228 unsigned long physaddr = guest_pa(lg, cpu->regs->eip);
229 229
230 /* This must be the Guest kernel trying to do something, not userspace! 230 /* This must be the Guest kernel trying to do something, not userspace!
231 * The bottom two bits of the CS segment register are the privilege 231 * The bottom two bits of the CS segment register are the privilege
232 * level. */ 232 * level. */
233 if ((lg->regs->cs & 3) != GUEST_PL) 233 if ((cpu->regs->cs & 3) != GUEST_PL)
234 return 0; 234 return 0;
235 235
236 /* Decoding x86 instructions is icky. */ 236 /* Decoding x86 instructions is icky. */
@@ -273,12 +273,12 @@ static int emulate_insn(struct lg_cpu *cpu)
273 if (in) { 273 if (in) {
274 /* Lower bit tells is whether it's a 16 or 32 bit access */ 274 /* Lower bit tells is whether it's a 16 or 32 bit access */
275 if (insn & 0x1) 275 if (insn & 0x1)
276 lg->regs->eax = 0xFFFFFFFF; 276 cpu->regs->eax = 0xFFFFFFFF;
277 else 277 else
278 lg->regs->eax |= (0xFFFF << shift); 278 cpu->regs->eax |= (0xFFFF << shift);
279 } 279 }
280 /* Finally, we've "done" the instruction, so move past it. */ 280 /* Finally, we've "done" the instruction, so move past it. */
281 lg->regs->eip += insnlen; 281 cpu->regs->eip += insnlen;
282 /* Success! */ 282 /* Success! */
283 return 1; 283 return 1;
284} 284}
@@ -287,12 +287,12 @@ static int emulate_insn(struct lg_cpu *cpu)
287void lguest_arch_handle_trap(struct lg_cpu *cpu) 287void lguest_arch_handle_trap(struct lg_cpu *cpu)
288{ 288{
289 struct lguest *lg = cpu->lg; 289 struct lguest *lg = cpu->lg;
290 switch (lg->regs->trapnum) { 290 switch (cpu->regs->trapnum) {
291 case 13: /* We've intercepted a General Protection Fault. */ 291 case 13: /* We've intercepted a General Protection Fault. */
292 /* Check if this was one of those annoying IN or OUT 292 /* Check if this was one of those annoying IN or OUT
293 * instructions which we need to emulate. If so, we just go 293 * instructions which we need to emulate. If so, we just go
294 * back into the Guest after we've done it. */ 294 * back into the Guest after we've done it. */
295 if (lg->regs->errcode == 0) { 295 if (cpu->regs->errcode == 0) {
296 if (emulate_insn(cpu)) 296 if (emulate_insn(cpu))
297 return; 297 return;
298 } 298 }
@@ -307,7 +307,7 @@ void lguest_arch_handle_trap(struct lg_cpu *cpu)
307 * 307 *
308 * The errcode tells whether this was a read or a write, and 308 * The errcode tells whether this was a read or a write, and
309 * whether kernel or userspace code. */ 309 * whether kernel or userspace code. */
310 if (demand_page(lg, lg->arch.last_pagefault, lg->regs->errcode)) 310 if (demand_page(lg, lg->arch.last_pagefault, cpu->regs->errcode))
311 return; 311 return;
312 312
313 /* OK, it's really not there (or not OK): the Guest needs to 313 /* OK, it's really not there (or not OK): the Guest needs to
@@ -338,19 +338,19 @@ void lguest_arch_handle_trap(struct lg_cpu *cpu)
338 case LGUEST_TRAP_ENTRY: 338 case LGUEST_TRAP_ENTRY:
339 /* Our 'struct hcall_args' maps directly over our regs: we set 339 /* Our 'struct hcall_args' maps directly over our regs: we set
340 * up the pointer now to indicate a hypercall is pending. */ 340 * up the pointer now to indicate a hypercall is pending. */
341 cpu->hcall = (struct hcall_args *)lg->regs; 341 cpu->hcall = (struct hcall_args *)cpu->regs;
342 return; 342 return;
343 } 343 }
344 344
345 /* We didn't handle the trap, so it needs to go to the Guest. */ 345 /* We didn't handle the trap, so it needs to go to the Guest. */
346 if (!deliver_trap(cpu, lg->regs->trapnum)) 346 if (!deliver_trap(cpu, cpu->regs->trapnum))
347 /* If the Guest doesn't have a handler (either it hasn't 347 /* If the Guest doesn't have a handler (either it hasn't
348 * registered any yet, or it's one of the faults we don't let 348 * registered any yet, or it's one of the faults we don't let
349 * it handle), it dies with a cryptic error message. */ 349 * it handle), it dies with a cryptic error message. */
350 kill_guest(lg, "unhandled trap %li at %#lx (%#lx)", 350 kill_guest(lg, "unhandled trap %li at %#lx (%#lx)",
351 lg->regs->trapnum, lg->regs->eip, 351 cpu->regs->trapnum, cpu->regs->eip,
352 lg->regs->trapnum == 14 ? lg->arch.last_pagefault 352 cpu->regs->trapnum == 14 ? lg->arch.last_pagefault
353 : lg->regs->errcode); 353 : cpu->regs->errcode);
354} 354}
355 355
356/* Now we can look at each of the routines this calls, in increasing order of 356/* Now we can look at each of the routines this calls, in increasing order of
@@ -557,9 +557,9 @@ int lguest_arch_init_hypercalls(struct lg_cpu *cpu)
557 * 557 *
558 * Most of the Guest's registers are left alone: we used get_zeroed_page() to 558 * Most of the Guest's registers are left alone: we used get_zeroed_page() to
559 * allocate the structure, so they will be 0. */ 559 * allocate the structure, so they will be 0. */
560void lguest_arch_setup_regs(struct lguest *lg, unsigned long start) 560void lguest_arch_setup_regs(struct lg_cpu *cpu, unsigned long start)
561{ 561{
562 struct lguest_regs *regs = lg->regs; 562 struct lguest_regs *regs = cpu->regs;
563 563
564 /* There are four "segment" registers which the Guest needs to boot: 564 /* There are four "segment" registers which the Guest needs to boot:
565 * The "code segment" register (cs) refers to the kernel code segment 565 * The "code segment" register (cs) refers to the kernel code segment
@@ -586,5 +586,5 @@ void lguest_arch_setup_regs(struct lguest *lg, unsigned long start)
586 586
587 /* There are a couple of GDT entries the Guest expects when first 587 /* There are a couple of GDT entries the Guest expects when first
588 * booting. */ 588 * booting. */
589 setup_guest_gdt(lg); 589 setup_guest_gdt(cpu->lg);
590} 590}