Cooperative Linux
Total Page:16
File Type:pdf, Size:1020Kb
Cooperative Linux Dan Aloni [email protected] Abstract trol on the physical hardware, where the other is provided only with virtual hardware abstrac- tion. From this point on in the paper I’ll refer In this paper I’ll describe Cooperative Linux, a to these two kernels as the host operating sys- port of the Linux kernel that allows it to run as tem, and the guest Linux VM respectively. The an unprivileged lightweight virtual machine in host can be every OS kernel that exports basic kernel mode, on top of another OS kernel. It al- primitives that provide the Cooperative Linux lows Linux to run under any operating system portable driver to run in CPL0 mode (ring 0) that supports loading drivers, such as Windows and allocate memory. or Linux, after minimal porting efforts. The pa- per includes the present and future implemen- The special CPL0 approach in Cooperative tation details, its applications, and its compar- Linux makes it significantly different than ison with other Linux virtualization methods. traditional virtualization solutions such as Among the technical details I’ll present the VMware, plex86, Virtual PC, and other meth- CPU-complete context switch code, hardware ods such as Xen. All of these approaches work interrupt forwarding, the interface between the by running the guest OS in a less privileged host OS and Linux, and the management of the mode than of the host kernel. This approach VM’s pseudo physical RAM. allowed for the extensive simplification of Co- operative Linux’s design and its short early- 1 Introduction beta development cycle which lasted only one month, starting from scratch by modifying the vanilla Linux 2.4.23-pre9 release until reach- Cooperative Linux utilizes the rather under- ing to the point where KDE could run. used concept of a Cooperative Virtual Machine (CVM), in contrast to traditional VMs that The only downsides to the CPL0 approach is are unprivileged and being under the complete stability and security. If it’s unstable, it has the control of the host machine. potential to crash the system. However, mea- sures can be taken, such as cleanly shutting it The term Cooperative is used to describe two down on the first internal Oops or panic. An- entities working in parallel, e.g. coroutines [2]. other disadvantage is security. Acquiring root In that sense the most plain description of Co- user access on a Cooperative Linux machine operative Linux is turning two operating sys- can potentially lead to root on the host ma- tem kernels into two big coroutines. In that chine if the attacker loads specially crafted ker- mode, each kernel has its own complete CPU nel module or uses some very elaborated ex- context and address space, and each kernel de- ploit in case which the Cooperative Linux ker- cides when to give control back to its partner. nel was compiled without module support. However, only one of the two kernels has con- 24 • Linux Symposium 2004 • Volume One Most of the changes in the Cooperative Linux workstation computer that runs Cooper- patch are on the i386 tree—the only supported ative Linux as a screen saver—when the architecture for Cooperative at the time of this secretary goes home at the end of the day writing. The other changes are mostly addi- and leaves the computer unattended, the tions of virtual drivers: cobd (block device), office’s cluster gets more CPU cycles for conet (network), and cocon (console). Most of free. the changes in the i386 tree involve the initial- ization and setup code. It is a goal of the Coop- • Running an otherwise-dual-booted erative Linux kernel design to remain as close Linux system from the other OS. The as possible to the standalone i386 kernel, so all Windows port of Cooperative Linux changes are localized and minimized as much allows it to mount real disk partitions as possible. as block devices. Numerous people are using this in order to access, rescue, or just run their Linux system from their 2 Uses ext3 or reiserfs file systems. Cooperative Linux in its current early state • Using Linux as a Windows firewall on can already provide some of the uses that the same machine. As a likely competi- User Mode Linux[1] provides, such as vir- tor to other out-of-the-box Windows fire- tual hosting, kernel development environment, walls, iptables along with a stripped-down research, and testing of new distributions or Cooperative Linux system can potentially buggy software. It also enabled new uses: serve as a network firewall. • Linux kernel development / debugging • Relatively effortless migration path / research and study on another operat- from Windows. In the process of switch- ing systems. ing to another OS, there is the choice be- tween installing another computer, dual- Digging inside a running Cooperative booting, or using a virtualization soft- Linux kernel, you can hardly tell the ware. The first option costs money, the difference between it and a standalone second is tiresome in terms of operation, Linux. All virtual addresses are the but the third can be the most quick and same—Oops reports look familiar and the easy method—especially if it’s free. This architecture dependent code works in the is where Cooperative Linux comes in. It same manner, excepts some transparent is already used in workplaces to convert conversions, which are described in the Windows users to Linux. next section in this paper. • Adding Windows machines to Linux • Development environment for porting clusters. The Cooperative Linux patch to and from Linux. is minimal and can be easily combined with others such as the MOSIX or Open- MOSIX patches that add clustering ca- 3 Design Overview pabilities to the kernel. This work in progress allows to add Windows machines to super-computer clusters, where one In this section I’ll describe the basic meth- illustration could tell about a secretary ods behind Cooperative Linux, which include Linux Symposium 2004 • Volume One • 25 complete context switches, handling of hard- host OS kernel. Most of the driver is OS- ware interrupts by forwarding, physical ad- independent code that interfaces with the OS dress translation and the pseudo physical mem- dependent primitives that include page alloca- ory RAM. tions, debug printing, and interfacing with user space. 3.1 Minimum Changes When a Cooperative Linux VM is created, the driver loads a kernel image from a vmlinux To illustrate the minimal effect of the Cooper- file that was compiled from the patched kernel ative Linux patch on the source tree, here is a with CONFIG_COOPERATIVE. The vmlinux diffstat listing of the patch on Linux 2.4.26 as file doesn’t need any cross platform tools in or- of May 10, 2004: der to be generated, and the same vmlinux file can be used to run a Cooperative Linux VM on CREDITS | 6 several OSes of the same architecture. Documentation/devices.txt | 7 Makefile | 8 arch/i386/config.in | 30 The VM is associated with a per-process arch/i386/kernel/Makefile | 2 arch/i386/kernel/cooperative.c | 181 +++++ resource—a file descriptor in Linux, or a de- arch/i386/kernel/head.S | 4 arch/i386/kernel/i387.c | 8 vice handle in Windows. The purpose of this arch/i386/kernel/i8259.c | 153 ++++ arch/i386/kernel/ioport.c | 10 arch/i386/kernel/process.c | 28 association makes sense: if the process run- arch/i386/kernel/setup.c | 61 + arch/i386/kernel/time.c | 104 +++ ning the VM ends abnormally in any way, all arch/i386/kernel/traps.c | 9 arch/i386/mm/fault.c | 4 resources are cleaned up automatically from a arch/i386/mm/init.c | 37 + arch/i386/vmlinux.lds | 82 +- callback when the system frees the per-process drivers/block/Config.in | 4 drivers/block/Makefile | 1 resource. drivers/block/cobd.c | 334 ++++++++++ drivers/block/ll_rw_blk.c | 2 drivers/char/Makefile | 4 drivers/char/colx_keyb.c | 1221 +++++++++++++* drivers/char/mem.c | 8 3.3 Pseudo Physical RAM drivers/char/vt.c | 8 drivers/net/Config.in | 4 drivers/net/Makefile | 1 drivers/net/conet.c | 205 ++++++ drivers/video/Makefile | 4 In Cooperative Linux, we had to work around drivers/video/cocon.c | 484 +++++++++++++++ include/asm-i386/cooperative.h | 175 +++++ the Linux MM design assumption that the en- include/asm-i386/dma.h | 4 include/asm-i386/io.h | 27 tire physical RAM is bestowed upon the ker- include/asm-i386/irq.h | 6 include/asm-i386/mc146818rtc.h | 7 nel on startup, and instead, only give Cooper- include/asm-i386/page.h | 30 include/asm-i386/pgalloc.h | 7 ative Linux a fixed set of physical pages, and include/asm-i386/pgtable-2level.h | 8 include/asm-i386/pgtable.h | 7 then only do the translations needed for it to include/asm-i386/processor.h | 12 include/asm-i386/system.h | 8 include/linux/console.h | 1 work transparently in that set. All the memory include/linux/cooperative.h | 317 +++++++++ include/linux/major.h | 1 which Cooperative Linux considers as physi- init/do_mounts.c | 3 init/main.c | 9 cal is in that allocated set, which we call the kernel/Makefile | 2 kernel/cooperative.c | 254 +++++++ Pseudo Physical RAM. kernel/panic.c | 4 kernel/printk.c | 6 50 files changed, 3828 insertions(+), 74 deletions(-) The memory is allocated in the host OS using the appropriate kernel function— alloc_pages() in Linux and 3.2 Device Driver MmAllocatePagesForMdl() in Windows—so it is not mapped in any ad- The device driver port of Cooperative Linux dress space on the host for not wasting PTEs. is used for accessing kernel mode and using The allocated pages are always resident and the kernel primitives that are exported by the not freed until the VM is downed.