aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/lguest/x86
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2008-03-28 12:05:53 -0400
committerRusty Russell <rusty@rustcorp.com.au>2008-03-27 20:05:54 -0400
commita6bd8e13034dd7d60b6f14217096efa192d0adc1 (patch)
tree23890908b06eb8357e6ce633d35df1216f5e4213 /drivers/lguest/x86
parente18b094f0faa4889b06a112da17230a10b88c815 (diff)
lguest: comment documentation update.
Took some cycles to re-read the Lguest Journey end-to-end, fix some rot and tighten some phrases. Only comments change. No new jokes, but a couple of recycled old jokes. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'drivers/lguest/x86')
-rw-r--r--drivers/lguest/x86/core.c33
-rw-r--r--drivers/lguest/x86/switcher_32.S8
2 files changed, 25 insertions, 16 deletions
diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
index 635187812d52..5126d5d9ea0e 100644
--- a/drivers/lguest/x86/core.c
+++ b/drivers/lguest/x86/core.c
@@ -17,6 +17,13 @@
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */ 19 */
20/*P:450 This file contains the x86-specific lguest code. It used to be all
21 * mixed in with drivers/lguest/core.c but several foolhardy code slashers
22 * wrestled most of the dependencies out to here in preparation for porting
23 * lguest to other architectures (see what I mean by foolhardy?).
24 *
25 * This also contains a couple of non-obvious setup and teardown pieces which
26 * were implemented after days of debugging pain. :*/
20#include <linux/kernel.h> 27#include <linux/kernel.h>
21#include <linux/start_kernel.h> 28#include <linux/start_kernel.h>
22#include <linux/string.h> 29#include <linux/string.h>
@@ -157,6 +164,8 @@ static void run_guest_once(struct lg_cpu *cpu, struct lguest_pages *pages)
157 * also simplify copy_in_guest_info(). Note that we'd still need to restore 164 * also simplify copy_in_guest_info(). Note that we'd still need to restore
158 * things when we exit to Launcher userspace, but that's fairly easy. 165 * things when we exit to Launcher userspace, but that's fairly easy.
159 * 166 *
167 * We could also try using this hooks for PGE, but that might be too expensive.
168 *
160 * The hooks were designed for KVM, but we can also put them to good use. :*/ 169 * The hooks were designed for KVM, but we can also put them to good use. :*/
161 170
162/*H:040 This is the i386-specific code to setup and run the Guest. Interrupts 171/*H:040 This is the i386-specific code to setup and run the Guest. Interrupts
@@ -182,7 +191,7 @@ void lguest_arch_run_guest(struct lg_cpu *cpu)
182 * was doing. */ 191 * was doing. */
183 run_guest_once(cpu, lguest_pages(raw_smp_processor_id())); 192 run_guest_once(cpu, lguest_pages(raw_smp_processor_id()));
184 193
185 /* Note that the "regs" pointer contains two extra entries which are 194 /* Note that the "regs" structure contains two extra entries which are
186 * not really registers: a trap number which says what interrupt or 195 * not really registers: a trap number which says what interrupt or
187 * 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
188 * traps set. */ 197 * traps set. */
@@ -293,11 +302,10 @@ void lguest_arch_handle_trap(struct lg_cpu *cpu)
293 break; 302 break;
294 case 14: /* We've intercepted a Page Fault. */ 303 case 14: /* We've intercepted a Page Fault. */
295 /* The Guest accessed a virtual address that wasn't mapped. 304 /* The Guest accessed a virtual address that wasn't mapped.
296 * This happens a lot: we don't actually set up most of the 305 * This happens a lot: we don't actually set up most of the page
297 * page tables for the Guest at all when we start: as it runs 306 * tables for the Guest at all when we start: as it runs it asks
298 * it asks for more and more, and we set them up as 307 * for more and more, and we set them up as required. In this
299 * required. In this case, we don't even tell the Guest that 308 * case, we don't even tell the Guest that the fault happened.
300 * the fault happened.
301 * 309 *
302 * The errcode tells whether this was a read or a write, and 310 * The errcode tells whether this was a read or a write, and
303 * whether kernel or userspace code. */ 311 * whether kernel or userspace code. */
@@ -342,7 +350,7 @@ void lguest_arch_handle_trap(struct lg_cpu *cpu)
342 if (!deliver_trap(cpu, cpu->regs->trapnum)) 350 if (!deliver_trap(cpu, cpu->regs->trapnum))
343 /* If the Guest doesn't have a handler (either it hasn't 351 /* If the Guest doesn't have a handler (either it hasn't
344 * registered any yet, or it's one of the faults we don't let 352 * registered any yet, or it's one of the faults we don't let
345 * it handle), it dies with a cryptic error message. */ 353 * it handle), it dies with this cryptic error message. */
346 kill_guest(cpu, "unhandled trap %li at %#lx (%#lx)", 354 kill_guest(cpu, "unhandled trap %li at %#lx (%#lx)",
347 cpu->regs->trapnum, cpu->regs->eip, 355 cpu->regs->trapnum, cpu->regs->eip,
348 cpu->regs->trapnum == 14 ? cpu->arch.last_pagefault 356 cpu->regs->trapnum == 14 ? cpu->arch.last_pagefault
@@ -375,8 +383,8 @@ void __init lguest_arch_host_init(void)
375 * The only exception is the interrupt handlers in switcher.S: their 383 * The only exception is the interrupt handlers in switcher.S: their
376 * addresses are placed in a table (default_idt_entries), so we need to 384 * addresses are placed in a table (default_idt_entries), so we need to
377 * update the table with the new addresses. switcher_offset() is a 385 * update the table with the new addresses. switcher_offset() is a
378 * convenience function which returns the distance between the builtin 386 * convenience function which returns the distance between the
379 * switcher code and the high-mapped copy we just made. */ 387 * compiled-in switcher code and the high-mapped copy we just made. */
380 for (i = 0; i < IDT_ENTRIES; i++) 388 for (i = 0; i < IDT_ENTRIES; i++)
381 default_idt_entries[i] += switcher_offset(); 389 default_idt_entries[i] += switcher_offset();
382 390
@@ -416,7 +424,7 @@ void __init lguest_arch_host_init(void)
416 state->guest_gdt_desc.address = (long)&state->guest_gdt; 424 state->guest_gdt_desc.address = (long)&state->guest_gdt;
417 425
418 /* We know where we want the stack to be when the Guest enters 426 /* We know where we want the stack to be when the Guest enters
419 * the switcher: in pages->regs. The stack grows upwards, so 427 * the Switcher: in pages->regs. The stack grows upwards, so
420 * we start it at the end of that structure. */ 428 * we start it at the end of that structure. */
421 state->guest_tss.sp0 = (long)(&pages->regs + 1); 429 state->guest_tss.sp0 = (long)(&pages->regs + 1);
422 /* And this is the GDT entry to use for the stack: we keep a 430 /* And this is the GDT entry to use for the stack: we keep a
@@ -513,8 +521,8 @@ int lguest_arch_init_hypercalls(struct lg_cpu *cpu)
513{ 521{
514 u32 tsc_speed; 522 u32 tsc_speed;
515 523
516 /* The pointer to the Guest's "struct lguest_data" is the only 524 /* The pointer to the Guest's "struct lguest_data" is the only argument.
517 * argument. We check that address now. */ 525 * We check that address now. */
518 if (!lguest_address_ok(cpu->lg, cpu->hcall->arg1, 526 if (!lguest_address_ok(cpu->lg, cpu->hcall->arg1,
519 sizeof(*cpu->lg->lguest_data))) 527 sizeof(*cpu->lg->lguest_data)))
520 return -EFAULT; 528 return -EFAULT;
@@ -546,6 +554,7 @@ int lguest_arch_init_hypercalls(struct lg_cpu *cpu)
546 554
547 return 0; 555 return 0;
548} 556}
557/*:*/
549 558
550/*L:030 lguest_arch_setup_regs() 559/*L:030 lguest_arch_setup_regs()
551 * 560 *
diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
index 0af8baaa0d4a..3fc15318a80f 100644
--- a/drivers/lguest/x86/switcher_32.S
+++ b/drivers/lguest/x86/switcher_32.S
@@ -1,6 +1,6 @@
1/*P:900 This is the Switcher: code which sits at 0xFFC00000 to do the low-level 1/*P:900 This is the Switcher: code which sits at 0xFFC00000 astride both the
2 * Guest<->Host switch. It is as simple as it can be made, but it's naturally 2 * Host and Guest to do the low-level Guest<->Host switch. It is as simple as
3 * very specific to x86. 3 * it can be made, but it's naturally very specific to x86.
4 * 4 *
5 * You have now completed Preparation. If this has whet your appetite; if you 5 * You have now completed Preparation. If this has whet your appetite; if you
6 * are feeling invigorated and refreshed then the next, more challenging stage 6 * are feeling invigorated and refreshed then the next, more challenging stage
@@ -189,7 +189,7 @@ ENTRY(switch_to_guest)
189 // Interrupts are turned back on: we are Guest. 189 // Interrupts are turned back on: we are Guest.
190 iret 190 iret
191 191
192// We treat two paths to switch back to the Host 192// We tread two paths to switch back to the Host
193// Yet both must save Guest state and restore Host 193// Yet both must save Guest state and restore Host
194// So we put the routine in a macro. 194// So we put the routine in a macro.
195#define SWITCH_TO_HOST \ 195#define SWITCH_TO_HOST \