mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-22 23:04:43 +00:00
lguest: fix comment style
I don't really notice it (except to begrudge the extra vertical space), but Ingo does. And he pointed out that one excuse of lguest is as a teaching tool, it should set a good example. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Cc: Ingo Molnar <mingo@redhat.com>
This commit is contained in:
parent
e969fed542
commit
2e04ef7691
17 changed files with 1906 additions and 1015 deletions
|
@ -1,6 +1,8 @@
|
|||
/*P:400 This contains run_guest() which actually calls into the Host<->Guest
|
||||
/*P:400
|
||||
* This contains run_guest() which actually calls into the Host<->Guest
|
||||
* Switcher and analyzes the return, such as determining if the Guest wants the
|
||||
* Host to do something. This file also contains useful helper routines. :*/
|
||||
* Host to do something. This file also contains useful helper routines.
|
||||
:*/
|
||||
#include <linux/module.h>
|
||||
#include <linux/stringify.h>
|
||||
#include <linux/stddef.h>
|
||||
|
@ -24,7 +26,8 @@ static struct page **switcher_page;
|
|||
/* This One Big lock protects all inter-guest data structures. */
|
||||
DEFINE_MUTEX(lguest_lock);
|
||||
|
||||
/*H:010 We need to set up the Switcher at a high virtual address. Remember the
|
||||
/*H:010
|
||||
* We need to set up the Switcher at a high virtual address. Remember the
|
||||
* Switcher is a few hundred bytes of assembler code which actually changes the
|
||||
* CPU to run the Guest, and then changes back to the Host when a trap or
|
||||
* interrupt happens.
|
||||
|
@ -33,7 +36,8 @@ DEFINE_MUTEX(lguest_lock);
|
|||
* Host since it will be running as the switchover occurs.
|
||||
*
|
||||
* Trying to map memory at a particular address is an unusual thing to do, so
|
||||
* it's not a simple one-liner. */
|
||||
* it's not a simple one-liner.
|
||||
*/
|
||||
static __init int map_switcher(void)
|
||||
{
|
||||
int i, err;
|
||||
|
@ -47,8 +51,10 @@ static __init int map_switcher(void)
|
|||
* easy.
|
||||
*/
|
||||
|
||||
/* We allocate an array of struct page pointers. map_vm_area() wants
|
||||
* this, rather than just an array of pages. */
|
||||
/*
|
||||
* We allocate an array of struct page pointers. map_vm_area() wants
|
||||
* this, rather than just an array of pages.
|
||||
*/
|
||||
switcher_page = kmalloc(sizeof(switcher_page[0])*TOTAL_SWITCHER_PAGES,
|
||||
GFP_KERNEL);
|
||||
if (!switcher_page) {
|
||||
|
@ -56,8 +62,10 @@ static __init int map_switcher(void)
|
|||
goto out;
|
||||
}
|
||||
|
||||
/* Now we actually allocate the pages. The Guest will see these pages,
|
||||
* so we make sure they're zeroed. */
|
||||
/*
|
||||
* Now we actually allocate the pages. The Guest will see these pages,
|
||||
* so we make sure they're zeroed.
|
||||
*/
|
||||
for (i = 0; i < TOTAL_SWITCHER_PAGES; i++) {
|
||||
unsigned long addr = get_zeroed_page(GFP_KERNEL);
|
||||
if (!addr) {
|
||||
|
@ -67,19 +75,23 @@ static __init int map_switcher(void)
|
|||
switcher_page[i] = virt_to_page(addr);
|
||||
}
|
||||
|
||||
/* First we check that the Switcher won't overlap the fixmap area at
|
||||
/*
|
||||
* First we check that the Switcher won't overlap the fixmap area at
|
||||
* the top of memory. It's currently nowhere near, but it could have
|
||||
* very strange effects if it ever happened. */
|
||||
* very strange effects if it ever happened.
|
||||
*/
|
||||
if (SWITCHER_ADDR + (TOTAL_SWITCHER_PAGES+1)*PAGE_SIZE > FIXADDR_START){
|
||||
err = -ENOMEM;
|
||||
printk("lguest: mapping switcher would thwack fixmap\n");
|
||||
goto free_pages;
|
||||
}
|
||||
|
||||
/* Now we reserve the "virtual memory area" we want: 0xFFC00000
|
||||
/*
|
||||
* Now we reserve the "virtual memory area" we want: 0xFFC00000
|
||||
* (SWITCHER_ADDR). We might not get it in theory, but in practice
|
||||
* it's worked so far. The end address needs +1 because __get_vm_area
|
||||
* allocates an extra guard page, so we need space for that. */
|
||||
* allocates an extra guard page, so we need space for that.
|
||||
*/
|
||||
switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
|
||||
VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
|
||||
+ (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
|
||||
|
@ -89,11 +101,13 @@ static __init int map_switcher(void)
|
|||
goto free_pages;
|
||||
}
|
||||
|
||||
/* This code actually sets up the pages we've allocated to appear at
|
||||
/*
|
||||
* This code actually sets up the pages we've allocated to appear at
|
||||
* SWITCHER_ADDR. map_vm_area() takes the vma we allocated above, the
|
||||
* kind of pages we're mapping (kernel pages), and a pointer to our
|
||||
* array of struct pages. It increments that pointer, but we don't
|
||||
* care. */
|
||||
* care.
|
||||
*/
|
||||
pagep = switcher_page;
|
||||
err = map_vm_area(switcher_vma, PAGE_KERNEL_EXEC, &pagep);
|
||||
if (err) {
|
||||
|
@ -101,8 +115,10 @@ static __init int map_switcher(void)
|
|||
goto free_vma;
|
||||
}
|
||||
|
||||
/* Now the Switcher is mapped at the right address, we can't fail!
|
||||
* Copy in the compiled-in Switcher code (from <arch>_switcher.S). */
|
||||
/*
|
||||
* Now the Switcher is mapped at the right address, we can't fail!
|
||||
* Copy in the compiled-in Switcher code (from <arch>_switcher.S).
|
||||
*/
|
||||
memcpy(switcher_vma->addr, start_switcher_text,
|
||||
end_switcher_text - start_switcher_text);
|
||||
|
||||
|
@ -124,8 +140,7 @@ out:
|
|||
}
|
||||
/*:*/
|
||||
|
||||
/* Cleaning up the mapping when the module is unloaded is almost...
|
||||
* too easy. */
|
||||
/* Cleaning up the mapping when the module is unloaded is almost... too easy. */
|
||||
static void unmap_switcher(void)
|
||||
{
|
||||
unsigned int i;
|
||||
|
@ -151,16 +166,19 @@ static void unmap_switcher(void)
|
|||
* But we can't trust the Guest: it might be trying to access the Launcher
|
||||
* code. We have to check that the range is below the pfn_limit the Launcher
|
||||
* gave us. We have to make sure that addr + len doesn't give us a false
|
||||
* positive by overflowing, too. */
|
||||
* positive by overflowing, too.
|
||||
*/
|
||||
bool lguest_address_ok(const struct lguest *lg,
|
||||
unsigned long addr, unsigned long len)
|
||||
{
|
||||
return (addr+len) / PAGE_SIZE < lg->pfn_limit && (addr+len >= addr);
|
||||
}
|
||||
|
||||
/* This routine copies memory from the Guest. Here we can see how useful the
|
||||
/*
|
||||
* This routine copies memory from the Guest. Here we can see how useful the
|
||||
* kill_lguest() routine we met in the Launcher can be: we return a random
|
||||
* value (all zeroes) instead of needing to return an error. */
|
||||
* value (all zeroes) instead of needing to return an error.
|
||||
*/
|
||||
void __lgread(struct lg_cpu *cpu, void *b, unsigned long addr, unsigned bytes)
|
||||
{
|
||||
if (!lguest_address_ok(cpu->lg, addr, bytes)
|
||||
|
@ -181,9 +199,11 @@ void __lgwrite(struct lg_cpu *cpu, unsigned long addr, const void *b,
|
|||
}
|
||||
/*:*/
|
||||
|
||||
/*H:030 Let's jump straight to the the main loop which runs the Guest.
|
||||
/*H:030
|
||||
* Let's jump straight to the the main loop which runs the Guest.
|
||||
* Remember, this is called by the Launcher reading /dev/lguest, and we keep
|
||||
* going around and around until something interesting happens. */
|
||||
* going around and around until something interesting happens.
|
||||
*/
|
||||
int run_guest(struct lg_cpu *cpu, unsigned long __user *user)
|
||||
{
|
||||
/* We stop running once the Guest is dead. */
|
||||
|
@ -195,8 +215,10 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user)
|
|||
if (cpu->hcall)
|
||||
do_hypercalls(cpu);
|
||||
|
||||
/* It's possible the Guest did a NOTIFY hypercall to the
|
||||
* Launcher, in which case we return from the read() now. */
|
||||
/*
|
||||
* It's possible the Guest did a NOTIFY hypercall to the
|
||||
* Launcher, in which case we return from the read() now.
|
||||
*/
|
||||
if (cpu->pending_notify) {
|
||||
if (!send_notify_to_eventfd(cpu)) {
|
||||
if (put_user(cpu->pending_notify, user))
|
||||
|
@ -209,29 +231,39 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user)
|
|||
if (signal_pending(current))
|
||||
return -ERESTARTSYS;
|
||||
|
||||
/* Check if there are any interrupts which can be delivered now:
|
||||
/*
|
||||
* Check if there are any interrupts which can be delivered now:
|
||||
* if so, this sets up the hander to be executed when we next
|
||||
* run the Guest. */
|
||||
* run the Guest.
|
||||
*/
|
||||
irq = interrupt_pending(cpu, &more);
|
||||
if (irq < LGUEST_IRQS)
|
||||
try_deliver_interrupt(cpu, irq, more);
|
||||
|
||||
/* All long-lived kernel loops need to check with this horrible
|
||||
/*
|
||||
* All long-lived kernel loops need to check with this horrible
|
||||
* thing called the freezer. If the Host is trying to suspend,
|
||||
* it stops us. */
|
||||
* it stops us.
|
||||
*/
|
||||
try_to_freeze();
|
||||
|
||||
/* Just make absolutely sure the Guest is still alive. One of
|
||||
* those hypercalls could have been fatal, for example. */
|
||||
/*
|
||||
* Just make absolutely sure the Guest is still alive. One of
|
||||
* those hypercalls could have been fatal, for example.
|
||||
*/
|
||||
if (cpu->lg->dead)
|
||||
break;
|
||||
|
||||
/* If the Guest asked to be stopped, we sleep. The Guest's
|
||||
* clock timer will wake us. */
|
||||
/*
|
||||
* If the Guest asked to be stopped, we sleep. The Guest's
|
||||
* clock timer will wake us.
|
||||
*/
|
||||
if (cpu->halted) {
|
||||
set_current_state(TASK_INTERRUPTIBLE);
|
||||
/* Just before we sleep, make sure no interrupt snuck in
|
||||
* which we should be doing. */
|
||||
/*
|
||||
* Just before we sleep, make sure no interrupt snuck in
|
||||
* which we should be doing.
|
||||
*/
|
||||
if (interrupt_pending(cpu, &more) < LGUEST_IRQS)
|
||||
set_current_state(TASK_RUNNING);
|
||||
else
|
||||
|
@ -239,8 +271,10 @@ int run_guest(struct lg_cpu *cpu, unsigned long __user *user)
|
|||
continue;
|
||||
}
|
||||
|
||||
/* OK, now we're ready to jump into the Guest. First we put up
|
||||
* the "Do Not Disturb" sign: */
|
||||
/*
|
||||
* OK, now we're ready to jump into the Guest. First we put up
|
||||
* the "Do Not Disturb" sign:
|
||||
*/
|
||||
local_irq_disable();
|
||||
|
||||
/* Actually run the Guest until something happens. */
|
||||
|
@ -327,8 +361,10 @@ static void __exit fini(void)
|
|||
}
|
||||
/*:*/
|
||||
|
||||
/* The Host side of lguest can be a module. This is a nice way for people to
|
||||
* play with it. */
|
||||
/*
|
||||
* The Host side of lguest can be a module. This is a nice way for people to
|
||||
* play with it.
|
||||
*/
|
||||
module_init(init);
|
||||
module_exit(fini);
|
||||
MODULE_LICENSE("GPL");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue