···5151#include <asm/bootparam.h>5252#include "../../../include/linux/lguest_launcher.h"5353/*L:1105454- * We can ignore the 42 include files we need for this program, but I do want5454+ * We can ignore the 43 include files we need for this program, but I do want5555 * to draw attention to the use of kernel-style types.5656 *5757 * As Linus said, "C is a Spartan language, and so should your naming be." I···6565typedef uint8_t u8;6666/*:*/67676868-#define PAGE_PRESENT 0x7 /* Present, RW, Execute */6968#define BRIDGE_PFX "bridge:"7069#ifndef SIOCBRADDIF7170#define SIOCBRADDIF 0x89a2 /* add interface to bridge */···13581359 * --sharenet=<name> option which opens or creates a named pipe. This can be13591360 * used to send packets to another guest in a 1:1 manner.13601361 *13611361- * More sopisticated is to use one of the tools developed for project like UML13621362+ * More sophisticated is to use one of the tools developed for project like UML13621363 * to do networking.13631364 *13641365 * Faster is to do virtio bonding in kernel. Doing this 1:1 would be···13681369 * multiple inter-guest channels behind one interface, although it would13691370 * require some manner of hotplugging new virtio channels.13701371 *13711371- * Finally, we could implement a virtio network switch in the kernel.13721372+ * Finally, we could use a virtio network switch in the kernel, ie. vhost.13721373:*/1373137413741375static u32 str2ip(const char *ipaddr)···20052006 /* Tell the entry path not to try to reload segment registers. */20062007 boot->hdr.loadflags |= KEEP_SEGMENTS;2007200820082008- /*20092009- * We tell the kernel to initialize the Guest: this returns the open20102010- * /dev/lguest file descriptor.20112011- */20092009+ /* We tell the kernel to initialize the Guest. */20122010 tell_kernel(start);2013201120142012 /* Ensure that we terminate if a device-servicing child dies. */
+1
arch/x86/include/asm/lguest_hcall.h
···6161 : "memory");6262 return call;6363}6464+/*:*/64656566/* Can't use our min() macro here: needs to be a constant */6667#define LGUEST_IRQS (NR_IRQS < 32 ? NR_IRQS: 32)
+15-6
arch/x86/lguest/boot.c
···7171#include <asm/stackprotector.h>7272#include <asm/reboot.h> /* for struct machine_ops */73737474-/*G:010 Welcome to the Guest!7474+/*G:0107575+ * Welcome to the Guest!7576 *7677 * The Guest in our tale is a simple creature: identical to the Host but7778 * behaving in simplified but equivalent ways. In particular, the Guest is the···191190#endif192191193192/*G:036194194- * When lazy mode is turned off reset the per-cpu lazy mode variable and then195195- * issue the do-nothing hypercall to flush any stored calls.196196-:*/193193+ * When lazy mode is turned off, we issue the do-nothing hypercall to194194+ * flush any stored calls, and call the generic helper to reset the195195+ * per-cpu lazy mode variable.196196+ */197197static void lguest_leave_lazy_mmu_mode(void)198198{199199 hcall(LHCALL_FLUSH_ASYNC, 0, 0, 0, 0);200200 paravirt_leave_lazy_mmu();201201}202202203203+/*204204+ * We also catch the end of context switch; we enter lazy mode for much of205205+ * that too, so again we need to flush here.206206+ *207207+ * (Technically, this is lazy CPU mode, and normally we're in lazy MMU208208+ * mode, but unlike Xen, lguest doesn't care about the difference).209209+ */203210static void lguest_end_context_switch(struct task_struct *next)204211{205212 hcall(LHCALL_FLUSH_ASYNC, 0, 0, 0, 0);···649640650641/*651642 * The Guest calls this after it has set a second-level entry (pte), ie. to map652652- * a page into a process' address space. Wetell the Host the toplevel and643643+ * a page into a process' address space. We tell the Host the toplevel and653644 * address this corresponds to. The Guest uses one pagetable per process, so654645 * we need to tell the Host which one we're changing (mm->pgd).655646 */···11481139static __init char *lguest_memory_setup(void)11491140{11501141 /*11511151- *The Linux bootloader header contains an "e820" memory map: the11421142+ * The Linux bootloader header contains an "e820" memory map: the11521143 * Launcher populated the first entry with our memory limit.11531144 */11541145 e820_add_region(boot_params.e820_map[0].addr,
+11-7
arch/x86/lguest/i386_head.S
···66#include <asm/processor-flags.h>7788/*G:02099- * Our story starts with the kernel booting into startup_32 in1010- * arch/x86/kernel/head_32.S. It expects a boot header, which is created by1111- * the bootloader (the Launcher in our case).99+1010+ * Our story starts with the bzImage: booting starts at startup_32 in1111+ * arch/x86/boot/compressed/head_32.S. This merely uncompresses the real1212+ * kernel in place and then jumps into it: startup_32 in1313+ * arch/x86/kernel/head_32.S. Both routines expects a boot header in the %esi1414+ * register, which is created by the bootloader (the Launcher in our case).1215 *1316 * The startup_32 function does very little: it clears the uninitialized global1417 * C variables which we expect to be zero (ie. BSS) and then copies the boot1515- * header and kernel command line somewhere safe. Finally it checks the1616- * 'hardware_subarch' field. This was introduced in 2.6.24 for lguest and Xen:1717- * if it's set to '1' (lguest's assigned number), then it calls us here.1818+ * header and kernel command line somewhere safe, and populates some initial1919+ * page tables. Finally it checks the 'hardware_subarch' field. This was2020+ * introduced in 2.6.24 for lguest and Xen: if it's set to '1' (lguest's2121+ * assigned number), then it calls us here.1822 *1923 * WARNING: be very careful here! We're running at addresses equal to physical2020- * addesses (around 0), not above PAGE_OFFSET as most code expectes2424+ * addesses (around 0), not above PAGE_OFFSET as most code expects2125 * (eg. 0xC0000000). Jumps are relative, so they're OK, but we can't touch any2226 * data without remembering to subtract __PAGE_OFFSET!2327 *
+1-1
drivers/lguest/core.c
···117117118118 /*119119 * Now the Switcher is mapped at the right address, we can't fail!120120- * Copy in the compiled-in Switcher code (from <arch>_switcher.S).120120+ * Copy in the compiled-in Switcher code (from x86/switcher_32.S).121121 */122122 memcpy(switcher_vma->addr, start_switcher_text,123123 end_switcher_text - start_switcher_text);
+2-2
drivers/lguest/interrupts_and_traps.c
···427427428428/*429429 * Direct traps also mean that we need to know whenever the Guest wants to use430430- * a different kernel stack, so we can change the IDT entries to use that431431- * stack. The IDT entries expect a virtual address, so unlike most addresses430430+ * a different kernel stack, so we can change the guest TSS to use that431431+ * stack. The TSS entries expect a virtual address, so unlike most addresses432432 * the Guest gives us, the "esp" (stack pointer) value here is virtual, not433433 * physical.434434 *
+10-7
drivers/lguest/lguest_user.c
···11-/*P:200 This contains all the /dev/lguest code, whereby the userspace launcher22- * controls and communicates with the Guest. For example, the first write will33- * tell us the Guest's memory layout and entry point. A read will run the44- * Guest until something happens, such as a signal or the Guest doing a NOTIFY55- * out to the Launcher.11+/*P:200 This contains all the /dev/lguest code, whereby the userspace22+ * launcher controls and communicates with the Guest. For example,33+ * the first write will tell us the Guest's memory layout and entry44+ * point. A read will run the Guest until something happens, such as55+ * a signal or the Guest doing a NOTIFY out to the Launcher. There is66+ * also a way for the Launcher to attach eventfds to particular NOTIFY77+ * values instead of returning from the read() call.68:*/79#include <linux/uaccess.h>810#include <linux/miscdevice.h>···359357 goto free_eventfds;360358361359 /*362362- * Initialize the Guest's shadow page tables, using the toplevel363363- * address the Launcher gave us. This allocates memory, so can fail.360360+ * Initialize the Guest's shadow page tables. This allocates361361+ * memory, so can fail.364362 */365363 err = init_guest_pagetable(lg);366364 if (err)···518516 .read = read,519517 .llseek = default_llseek,520518};519519+/*:*/521520522521/*523522 * This is a textbook example of a "misc" character device. Populate a "struct
+2-2
drivers/lguest/page_tables.c
···155155}156156157157/*158158- * These functions are just like the above two, except they access the Guest158158+ * These functions are just like the above, except they access the Guest159159 * page tables. Hence they return a Guest address.160160 */161161static unsigned long gpgd_addr(struct lg_cpu *cpu, unsigned long vaddr)···195195#endif196196/*:*/197197198198-/*M:014198198+/*M:007199199 * get_pfn is slow: we could probably try to grab batches of pages here as200200 * an optimization (ie. pre-faulting).201201:*/
+4-6
drivers/lguest/x86/core.c
···272272 unsigned int insnlen = 0, in = 0, shift = 0;273273 /*274274 * The eip contains the *virtual* address of the Guest's instruction:275275- * guest_pa just subtracts the Guest's page_offset.275275+ * walk the Guest's page tables to find the "physical" address.276276 */277277 unsigned long physaddr = guest_pa(cpu, cpu->regs->eip);278278···409409 * These values mean a real interrupt occurred, in which case410410 * the Host handler has already been run. We just do a411411 * friendly check if another process should now be run, then412412- * return to run the Guest again412412+ * return to run the Guest again.413413 */414414 cond_resched();415415 return;···459459 int i;460460461461 /*462462- * Most of the i386/switcher.S doesn't care that it's been moved; on462462+ * Most of the x86/switcher_32.S doesn't care that it's been moved; on463463 * Intel, jumps are relative, and it doesn't access any references to464464 * external code or data.465465 *···587587 clear_cpu_cap(&boot_cpu_data, X86_FEATURE_PGE);588588 }589589 put_online_cpus();590590-};590590+}591591/*:*/592592593593void __exit lguest_arch_host_fini(void)···670670/*:*/671671672672/*L:030673673- * lguest_arch_setup_regs()674674- *675673 * Most of the Guest's registers are left alone: we used get_zeroed_page() to676674 * allocate the structure, so they will be 0.677675 */