Skip to content

Commit 9f54288

Browse files
committed
lguest: update comments
Also removes a long-unused #define and an extraneous semicolon. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 3c3ed48 commit 9f54288

9 files changed

Lines changed: 50 additions & 39 deletions

File tree

‎Documentation/virtual/lguest/lguest.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#include <asm/bootparam.h>
5252
#include "../../../include/linux/lguest_launcher.h"
5353
/*L:110
54-
* We can ignore the 42 include files we need for this program, but I do want
54+
* We can ignore the 43 include files we need for this program, but I do want
5555
* 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
@@ -65,7 +65,6 @@ typedef uint16_t u16;
6565
typedef uint8_t u8;
6666
/*:*/
6767

68-
#define PAGE_PRESENT 0x7 /* Present, RW, Execute */
6968
#define BRIDGE_PFX "bridge:"
7069
#ifndef SIOCBRADDIF
7170
#define SIOCBRADDIF 0x89a2 /* add interface to bridge */
@@ -1359,7 +1358,7 @@ static void setup_console(void)
13591358
* --sharenet=<name> option which opens or creates a named pipe. This can be
13601359
* used to send packets to another guest in a 1:1 manner.
13611360
*
1362-
* More sopisticated is to use one of the tools developed for project like UML
1361+
* More sophisticated is to use one of the tools developed for project like UML
13631362
* to do networking.
13641363
*
13651364
* Faster is to do virtio bonding in kernel. Doing this 1:1 would be
@@ -1369,7 +1368,7 @@ static void setup_console(void)
13691368
* multiple inter-guest channels behind one interface, although it would
13701369
* require some manner of hotplugging new virtio channels.
13711370
*
1372-
* Finally, we could implement a virtio network switch in the kernel.
1371+
* Finally, we could use a virtio network switch in the kernel, ie. vhost.
13731372
:*/
13741373

13751374
static u32 str2ip(const char *ipaddr)
@@ -2006,10 +2005,7 @@ int main(int argc, char *argv[])
20062005
/* Tell the entry path not to try to reload segment registers. */
20072006
boot->hdr.loadflags |= KEEP_SEGMENTS;
20082007

2009-
/*
2010-
* We tell the kernel to initialize the Guest: this returns the open
2011-
* /dev/lguest file descriptor.
2012-
*/
2008+
/* We tell the kernel to initialize the Guest. */
20132009
tell_kernel(start);
20142010

20152011
/* Ensure that we terminate if a device-servicing child dies. */

‎arch/x86/include/asm/lguest_hcall.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ hcall(unsigned long call,
6161
: "memory");
6262
return call;
6363
}
64+
/*:*/
6465

6566
/* Can't use our min() macro here: needs to be a constant */
6667
#define LGUEST_IRQS (NR_IRQS < 32 ? NR_IRQS: 32)

‎arch/x86/lguest/boot.c‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
#include <asm/stackprotector.h>
7272
#include <asm/reboot.h> /* for struct machine_ops */
7373

74-
/*G:010 Welcome to the Guest!
74+
/*G:010
75+
* Welcome to the Guest!
7576
*
7677
* The Guest in our tale is a simple creature: identical to the Host but
7778
* behaving in simplified but equivalent ways. In particular, the Guest is the
@@ -190,15 +191,23 @@ static void lazy_hcall4(unsigned long call,
190191
#endif
191192

192193
/*G:036
193-
* When lazy mode is turned off reset the per-cpu lazy mode variable and then
194-
* issue the do-nothing hypercall to flush any stored calls.
195-
:*/
194+
* When lazy mode is turned off, we issue the do-nothing hypercall to
195+
* flush any stored calls, and call the generic helper to reset the
196+
* per-cpu lazy mode variable.
197+
*/
196198
static void lguest_leave_lazy_mmu_mode(void)
197199
{
198200
hcall(LHCALL_FLUSH_ASYNC, 0, 0, 0, 0);
199201
paravirt_leave_lazy_mmu();
200202
}
201203

204+
/*
205+
* We also catch the end of context switch; we enter lazy mode for much of
206+
* that too, so again we need to flush here.
207+
*
208+
* (Technically, this is lazy CPU mode, and normally we're in lazy MMU
209+
* mode, but unlike Xen, lguest doesn't care about the difference).
210+
*/
202211
static void lguest_end_context_switch(struct task_struct *next)
203212
{
204213
hcall(LHCALL_FLUSH_ASYNC, 0, 0, 0, 0);
@@ -640,7 +649,7 @@ static void lguest_write_cr4(unsigned long val)
640649

641650
/*
642651
* The Guest calls this after it has set a second-level entry (pte), ie. to map
643-
* a page into a process' address space. Wetell the Host the toplevel and
652+
* a page into a process' address space. We tell the Host the toplevel and
644653
* address this corresponds to. The Guest uses one pagetable per process, so
645654
* we need to tell the Host which one we're changing (mm->pgd).
646655
*/
@@ -1139,7 +1148,7 @@ static struct notifier_block paniced = {
11391148
static __init char *lguest_memory_setup(void)
11401149
{
11411150
/*
1142-
*The Linux bootloader header contains an "e820" memory map: the
1151+
* The Linux bootloader header contains an "e820" memory map: the
11431152
* Launcher populated the first entry with our memory limit.
11441153
*/
11451154
e820_add_region(boot_params.e820_map[0].addr,

‎arch/x86/lguest/i386_head.S‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@
66
#include <asm/processor-flags.h>
77

88
/*G:020
9-
* Our story starts with the kernel booting into startup_32 in
10-
* arch/x86/kernel/head_32.S. It expects a boot header, which is created by
11-
* the bootloader (the Launcher in our case).
9+
10+
* Our story starts with the bzImage: booting starts at startup_32 in
11+
* arch/x86/boot/compressed/head_32.S. This merely uncompresses the real
12+
* kernel in place and then jumps into it: startup_32 in
13+
* arch/x86/kernel/head_32.S. Both routines expects a boot header in the %esi
14+
* 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 global
1417
* C variables which we expect to be zero (ie. BSS) and then copies the boot
15-
* header and kernel command line somewhere safe. Finally it checks the
16-
* 'hardware_subarch' field. This was introduced in 2.6.24 for lguest and Xen:
17-
* if it's set to '1' (lguest's assigned number), then it calls us here.
18+
* header and kernel command line somewhere safe, and populates some initial
19+
* page tables. Finally it checks the 'hardware_subarch' field. This was
20+
* introduced in 2.6.24 for lguest and Xen: if it's set to '1' (lguest's
21+
* assigned number), then it calls us here.
1822
*
1923
* WARNING: be very careful here! We're running at addresses equal to physical
20-
* addesses (around 0), not above PAGE_OFFSET as most code expectes
24+
* addesses (around 0), not above PAGE_OFFSET as most code expects
2125
* (eg. 0xC0000000). Jumps are relative, so they're OK, but we can't touch any
2226
* data without remembering to subtract __PAGE_OFFSET!
2327
*

‎drivers/lguest/core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static __init int map_switcher(void)
117117

118118
/*
119119
* Now the Switcher is mapped at the right address, we can't fail!
120-
* Copy in the compiled-in Switcher code (from <arch>_switcher.S).
120+
* 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);

‎drivers/lguest/interrupts_and_traps.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,8 @@ void pin_stack_pages(struct lg_cpu *cpu)
427427

428428
/*
429429
* Direct traps also mean that we need to know whenever the Guest wants to use
430-
* a different kernel stack, so we can change the IDT entries to use that
431-
* stack. The IDT entries expect a virtual address, so unlike most addresses
430+
* a different kernel stack, so we can change the guest TSS to use that
431+
* stack. The TSS entries expect a virtual address, so unlike most addresses
432432
* the Guest gives us, the "esp" (stack pointer) value here is virtual, not
433433
* physical.
434434
*

‎drivers/lguest/lguest_user.c‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
/*P:200 This contains all the /dev/lguest code, whereby the userspace launcher
2-
* controls and communicates with the Guest. For example, the first write will
3-
* tell us the Guest's memory layout and entry point. A read will run the
4-
* Guest until something happens, such as a signal or the Guest doing a NOTIFY
5-
* out to the Launcher.
1+
/*P:200 This contains all the /dev/lguest code, whereby the userspace
2+
* launcher controls and communicates with the Guest. For example,
3+
* the first write will tell us the Guest's memory layout and entry
4+
* point. A read will run the Guest until something happens, such as
5+
* a signal or the Guest doing a NOTIFY out to the Launcher. There is
6+
* also a way for the Launcher to attach eventfds to particular NOTIFY
7+
* values instead of returning from the read() call.
68
:*/
79
#include <linux/uaccess.h>
810
#include <linux/miscdevice.h>
@@ -357,8 +359,8 @@ static int initialize(struct file *file, const unsigned long __user *input)
357359
goto free_eventfds;
358360

359361
/*
360-
* Initialize the Guest's shadow page tables, using the toplevel
361-
* address the Launcher gave us. This allocates memory, so can fail.
362+
* Initialize the Guest's shadow page tables. This allocates
363+
* memory, so can fail.
362364
*/
363365
err = init_guest_pagetable(lg);
364366
if (err)
@@ -516,6 +518,7 @@ static const struct file_operations lguest_fops = {
516518
.read = read,
517519
.llseek = default_llseek,
518520
};
521+
/*:*/
519522

520523
/*
521524
* This is a textbook example of a "misc" character device. Populate a "struct

‎drivers/lguest/page_tables.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static pte_t *spte_addr(struct lg_cpu *cpu, pgd_t spgd, unsigned long vaddr)
155155
}
156156

157157
/*
158-
* These functions are just like the above two, except they access the Guest
158+
* These functions are just like the above, except they access the Guest
159159
* page tables. Hence they return a Guest address.
160160
*/
161161
static unsigned long gpgd_addr(struct lg_cpu *cpu, unsigned long vaddr)
@@ -195,7 +195,7 @@ static unsigned long gpte_addr(struct lg_cpu *cpu,
195195
#endif
196196
/*:*/
197197

198-
/*M:014
198+
/*M:007
199199
* get_pfn is slow: we could probably try to grab batches of pages here as
200200
* an optimization (ie. pre-faulting).
201201
:*/

‎drivers/lguest/x86/core.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static int emulate_insn(struct lg_cpu *cpu)
272272
unsigned int insnlen = 0, in = 0, shift = 0;
273273
/*
274274
* The eip contains the *virtual* address of the Guest's instruction:
275-
* guest_pa just subtracts the Guest's page_offset.
275+
* walk the Guest's page tables to find the "physical" address.
276276
*/
277277
unsigned long physaddr = guest_pa(cpu, cpu->regs->eip);
278278

@@ -409,7 +409,7 @@ void lguest_arch_handle_trap(struct lg_cpu *cpu)
409409
* These values mean a real interrupt occurred, in which case
410410
* the Host handler has already been run. We just do a
411411
* friendly check if another process should now be run, then
412-
* return to run the Guest again
412+
* return to run the Guest again.
413413
*/
414414
cond_resched();
415415
return;
@@ -459,7 +459,7 @@ void __init lguest_arch_host_init(void)
459459
int i;
460460

461461
/*
462-
* Most of the i386/switcher.S doesn't care that it's been moved; on
462+
* Most of the x86/switcher_32.S doesn't care that it's been moved; on
463463
* Intel, jumps are relative, and it doesn't access any references to
464464
* external code or data.
465465
*
@@ -587,7 +587,7 @@ void __init lguest_arch_host_init(void)
587587
clear_cpu_cap(&boot_cpu_data, X86_FEATURE_PGE);
588588
}
589589
put_online_cpus();
590-
};
590+
}
591591
/*:*/
592592

593593
void __exit lguest_arch_host_fini(void)
@@ -670,8 +670,6 @@ int lguest_arch_init_hypercalls(struct lg_cpu *cpu)
670670
/*:*/
671671

672672
/*L:030
673-
* lguest_arch_setup_regs()
674-
*
675673
* Most of the Guest's registers are left alone: we used get_zeroed_page() to
676674
* allocate the structure, so they will be 0.
677675
*/

0 commit comments

Comments
 (0)