Skip to content

Commit

Permalink
Lguest support for Virtio
Browse files Browse the repository at this point in the history
This makes lguest able to use the virtio devices.

We change the device descriptor page from a simple array to a variable
length "type, config_len, status, config data..." format, and
implement virtio_config_ops to read from that config data.

We use the virtio ring implementation for an efficient Guest <-> Host
virtqueue mechanism, and the new LHCALL_NOTIFY hypercall to kick the
host when it changes.

We also use LHCALL_NOTIFY on kernel addresses for very very early
console output.  We could have another hypercall, but this hack works
quite well.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
Rusty Russell committed Oct 23, 2007
1 parent 1504527 commit 19f1537
Show file tree
Hide file tree
Showing 5 changed files with 421 additions and 28 deletions.
5 changes: 5 additions & 0 deletions arch/x86/lguest/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ config LGUEST_GUEST
bool "Lguest guest support"
select PARAVIRT
depends on !X86_PAE
select VIRTIO
select VIRTIO_RING
select VIRTIO_CONSOLE
help
Lguest is a tiny in-kernel hypervisor. Selecting this will
allow your kernel to boot under lguest. This option will increase
your kernel size by about 6k. If in doubt, say N.

If you say Y here, make sure you say Y (or M) to the virtio block
and net drivers which lguest needs.
21 changes: 21 additions & 0 deletions arch/x86/lguest/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include <linux/clockchips.h>
#include <linux/lguest.h>
#include <linux/lguest_launcher.h>
#include <linux/virtio_console.h>
#include <asm/paravirt.h>
#include <asm/param.h>
#include <asm/page.h>
Expand Down Expand Up @@ -849,6 +850,23 @@ static __init char *lguest_memory_setup(void)
return "LGUEST";
}

/* Before virtqueues are set up, we use LHCALL_NOTIFY on normal memory to
* produce console output. */
static __init int early_put_chars(u32 vtermno, const char *buf, int count)
{
char scratch[17];
unsigned int len = count;

if (len > sizeof(scratch) - 1)
len = sizeof(scratch) - 1;
scratch[len] = '\0';
memcpy(scratch, buf, len);
hcall(LHCALL_NOTIFY, __pa(scratch), 0, 0);

/* This routine returns the number of bytes actually written. */
return len;
}

/*G:050
* Patching (Powerfully Placating Performance Pedants)
*
Expand Down Expand Up @@ -1048,6 +1066,9 @@ __init void lguest_init(void *boot)
* adapted for lguest's use. */
add_preferred_console("hvc", 0, NULL);

/* Register our very early console. */
virtio_cons_early_init(early_put_chars);

/* Last of all, we set the power management poweroff hook to point to
* the Guest routine to power off. */
pm_power_off = lguest_power_off;
Expand Down
3 changes: 3 additions & 0 deletions drivers/lguest/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Guest requires the device configuration and probing code.
obj-$(CONFIG_LGUEST_GUEST) += lguest_device.o

# Host requires the other files, which can be a module.
obj-$(CONFIG_LGUEST) += lg.o
lg-y = core.o hypercalls.o page_tables.o interrupts_and_traps.o \
Expand Down
Loading

0 comments on commit 19f1537

Please sign in to comment.