Project 3: Writing a Kernel from Scratch

Project 3: Writing a Kernel from Scratch

Project 4: “PebPeb” Paravirtualization 15-410 Operating Systems April 18, 2011 Contents 1 Introduction 2 1.1 Overview ...................................... 2 1.2 Simplifications ................................... 2 1.3 Hand-in ....................................... 3 2 Build Infrastructure 4 3 Installing the “Page 1” code 4 4 Launching a Guest Kernel 5 5 The Hypervisor Call Interface 5 6 Interrupt/Exception/Trap Delivery 6 7 Hypervisor Calls 7 8 Virtual Consoles 8 8.1 System Call ..................................... 9 8.2 Utility Program ................................... 9 9 PlanofAttack 9 1 1 Introduction This semester Project 4 consists of implementing a paravirtualizing hypervisor (host kernel) capable of supporting paravirtualized Pebbles guest kernels. Because a kernel consumes the entire keyboard and screen while it’s running, there is no sensible way to run multiple kernels at the same time without multiple keyboards and screens. Because of this, Project 4 also includes implementing virtual consoles. Because writing a hypervisor is a non-trivial task, there are multiple levels of achievement which result in passing grades. In other words, substantial credit will be given for partially completing the assignment, as long as the completed parts work well and achieve interesting results. The lecture material includes a description of the various parts and expected grading approach. 1.1 Overview This document consists of the following parts: • A specification of virtual consoles • Specification of the “PebPeb” paravirtualization environment • Attack plan, including suggestions This document does not contain all information necessary to complete the project. In particular, it will be necessary to carefully study the lecture material and documentation in some source files we provide you with. Good luck! 1.2 Simplifications Due to the scope of the project and the time available, certain simplifications are reasonable. • Because the size of “kernel memory” is limited, it is reasonable for your hypervisor to support only a small number of guest kernels. In particular, mapping a complete 32-bit address space can require 4 megabytes of RAM, which is one fourth of the available kernel memory. While some VM implementations may make it easy to support a large number of guest kernels, it is reasonable if you can’t support more than two. Try to avoid being unable to support two, but in an emergency one will be better than none. • It may seem to you as if writing the “glue code” which transitions between address spaces is easier if interrupts are off. That is totally reasonable, since this code should take fairly small constant time. It should still be the case that long-running code, such as page-table translation and actual execution of guests, should be appropriately preemptible. 2 • Because keyboard input will be multiplexed between line-oriented consumers (readline()) and character-oriented consumers (virtual keyboard interrupts delivered to guest kernels), you are authorized to restructure your readline() implementation so that invoking threads essentially loop calling readchar(). Blocking should still happen, inside readchar(), but you do not need to avoid scheduling and running a readline() caller once per available character. • It may seem to you that a lot of execution time is spent building page tables which are used only briefly. This is true, and page-table caching substantially improves hypervisor performance, but it is outside the scope of this project. • Guest kernels will have an inaccurate notion of time, i.e., their clocks will not “tick” at the expected rate due to other threads competing for CPU time. This is not a problem. • If time is short, one thing to skimp on is correctly handling the cleaning up of crashed or exited hypervisors. It is probably a good idea to print out a somewhat detailed message indicating why a hypervisor is exiting, but in an emergency you could get away with just dropping a broken guest from the run queue. • Neither PebPeb guest kernels nor PebPeb host kernels are expected to use floating-point instructions. Be sure to document your approach and design decisions before you submit your project; also be sure to mention any shortcuts you were forced to take. We are interested in understanding what about the project did and didn’t work out in case it is used in the future. 1.3 Hand-in Please remember to make veryclean. When handed in, your kernel must be runnable! This means that it must, upon being built and booted, start running idle, init, and shell without user intervention. In particular, it must not drop into the Simics debugger. When we run the test suite, there will not be a human present to continue execution. Thus, the test harness will declare your kernel to have failed the entire suite. Also, your kernel should not generate reams of lprintf() debugging messages while running. Ideally you should adjust the setting of your trace facility so that it generates no messages, but in any case the normal loading, execution, and exiting of a program should not generate more than 20 lines of kernel.log output. It is very important that your README explains which parts of the project you have got working, and which are working solidly. 3 2 Build Infrastructure The Project 4 infrastructure is designed to build dual-purpose kernel binaries which can be booted on real hardware or launched inside a PebPeb hypervisor. This means that whether you are trying to build a PebPeb guest or a PebPeb host you will use the same tarball, update script, makefile, etc. The startup code that runs before kernel main() has been modified to check whether it has been launched as a kernel by the GRUB boot-loader on real hardware or as a PebPeb guest kernel by a PebPeb hypervisor host. In the guest-kernel case, the GDT/TSS/IDT-setup phase will be skipped; in either case, the LMM memory allocator will be configured appropriately and machine phys frames() will return the relevant memory-size information. In either case, hv isguest() will return whether the kernel image is running in guest or host (hypervisor) mode. In 410user/progs you will find not only Pebbles user-space programs but also PebPeb guest- kernel payloads. Each payload is provided in binary form (e.g., vast.bin); for some payloads we also provide source code in the same directory. This source code can’t be compiled into a guest kernel “in place”; in particular, it is missing hypervisor stubs. We have provided it for reference purposes, but if you want you can copy the source for a guest payload into the kern/ directory of a separate build tree and build it there. To build a payload into your kernel image, include a line like 410REQBINPROGS=vast (without the .bin). If you decide to pursue “Plan B” (writing a guest instead of a hypervisor), contact the course staff for directions. 3 Installing the “Page 1” code You will need to write some tricky address-space transition code (the “orange bar” in the lecture). Any time the processor encounters a “surprise” (interrupt, exception, trap) some of this code will be run. Because only one “kernel stack” page fits in this area, this one page will need to be shared among all threads the hypervisor is running. This means the transition code will need to run with interrupts off; its job will be to switch to the appropriate address space, copy relevant state from the top of the transition stack to a better place, switch stacks, and invoke higher-level code (which should enable interrupts at an appropriate time). By the way, we recommend that you consider “funneling” your invocation of higher-level code through a small number of entry points—for example, you might have functions called syscall dispatch() and interrupt dispatch() function which would take an integer parameter indicating the IDT entry to be handled. As discussed in the handout, this “Page 1” code will not be linked into your main kernel image. The standard Pebbles build process will assemble kern/page1.S and include it as an ELF image in the Pebbles RAM disk. Before your hypervisor encounters its first “surprise” you will need to extract the text region of the “page1” ELF image and copy it downto the appropriate location (see spec/hv glue.h). 4 4 Launching a Guest Kernel Guest kernels are launched with the standard Pebbles exec() system call. A host kernel distinguishes between regular user-space executables and guest-kernel executables by checking whether the beginning of the text region is at versus below USER MEM START. When a PebPeb host kernel launches a guest kernel, the execution state is as follows. • Some number of frames have been allocated to the guest. You can launch every guest with the same fixed size (we recommend 16 or 24 megabytes), or you can optionally parse argv[1] as a decimal integer indicating a number of megabytes. • A virtual address space has been prepared which direct-maps those frames (page X maps to frame X), with the exception that pages 0 through 3 are unmapped and no page maps to frames 0 through 3. This address space closely resembles hardware protected mode with paging disabled, though of course paging will be on for every instruction executed by the guest. • The guest’s ELF image (text, rodata, data, BSS) are all loaded into the guest’s address space at the indicated addresses. • %EAX contains the magic value 0x15410DE0U. • %EBX contains the maximum legal virtual frame number (due to the “missing frames”, this is not a count of the number of legal frames) • %CS contains a selector for a 32-bit ring-3 read/execute code segment with an offset of 0 and a limit of 0xFFFFFFFF. • %DS, %ES, %FS, %GS, and %SS each contain a selector for a 32-bit ring-3 read/write code segment with an offset of 0 and a limit of 0xFFFFFFFF.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    13 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us