2 \documentclass[11pt]{article}
11 \usepackage{changebar}
15 \setlength{\textheight}{8.50in}
16 \setlength{\textwidth}{6.5in}
17 \setlength{\topmargin}{-0.3in}
18 %\setlength{\leftmargin}{2.9in}
19 %\setlength{\rightmargin}{-2.9in}
20 \setlength{\oddsidemargin}{0in}
21 \setlength{\parindent}{0.5in}
22 \setlength\parindent{0in}
23 \setlength\parskip{0.1in}
25 \newcommand{\note}[1]{{$\rightarrow$ \bf Note: \emph{#1}}}
30 \includegraphics[height=1.5in]{v3vee.pdf}
31 \includegraphics[height=1.5in]{logo6.png} \\
33 Palacios Internal Developer Manual
40 This manual is written for Internal Palacios developers. It contains
41 information on how to obtain the palacios code base, how to go about
42 the development process, and how to commit those changes to the
43 mainline source tree. This assumes that the reader has read {\em An
44 Introduction to the Palacios Virtual Machine Monitor -- Release 1.0}
45 and also has a slight working knowledge of {\em git}.
51 Both Palacios and Kitten follow a hybrid development process that
52 uses both the centralized repository and distributed development
53 models. A central repository exists that holds the master version of
54 the code base. This central repository is cloned by multiple people
55 and in multiple places to support various development efforts. A
56 feature of git is that every developer actually has a fully copy of
57 the entire repository, and so can function independently until such
58 time as they need to resync with the master version.
60 There are typically multiple levels of access to the central
61 repository, that are granted based on the type of developer being
62 granted access. The three basic developer types and their access
66 \item Core Developers: These are the lead developers and are in
67 charge of managing the master repository. They have full read/write
68 access permissions to the central repository.
70 \item Internal Developers: Formal members of the development
71 team. These people are capable of pulling directly from the central
72 repository, but lack the ability to write directly to it.
74 \item External Developers: People who are not actual members of the
75 development team. These people can only access the public repository
76 which is only updated to contain the release versions.
79 Because internal and external developers cannot write directly to the
80 master repository, they need to first submit their changes to a core
81 developer before they can be added to the mainline. We will discuss
82 that process in Section~\ref{sec:submission}.
85 \section{Checking out Palacios}
86 The central palacios repository is located on {\em
87 newskysaw.cs.northwestern.edu} in {\em /home/palacios/palacios}. All
88 internal developers have read access to the directory. Each developer
89 must create their own local version of the repository, this is done
93 git clone /home/palacios/palacios
96 This creates a local copy of the repository at {\em ./palacios/}.
99 All development work is done in the {\em devel} branch of the
100 repository. The developer can access this branch via:
103 git checkout --track -b devel origin/devel
109 /opt/vmm-tools/bin/checkout_branch devel
113 Note that palacios is very actively developed so the contents of the
114 {\em devel} branch are frequently changing. In order to keep up to
115 date with the latest version, it is necessary to periodically pull the
116 latest changes from the master repository by running \verb.git pull..
120 \section{Checking out Kitten}
122 Kitten is available from Sandia National Labs, and is the main host OS
123 we are targetting with Palacios. Loosely speaking core Palacios
124 developers are internal Kitten developers, and internal Palacios
125 developers are external Kitten developers. Because we have limited
126 access to the Kitten repository, we are maintaining a local mirror
127 copy in {\em /home/palacios/kitten}.
129 Kitten uses Mercurial for their source management, so you will have to
130 make sure the local mercurial version is configured correctly.
131 Specifically you should add the following python path to your shell environment.
134 export PYTHONPATH=/usr/local/lib64/python2.4/site-packages/
137 You can then clone Kitten from the local mirror:
139 hg clone /home/palacios/kitten
142 Both the Kitten and Palacios clone commands should be run from the
143 same direcotyr. This means that both repositories should be located at
144 the same directory level. The Kitten build process depends on this.
146 {\em Important:} Like Palacios, Kitten is very actively developed so
147 source tree is frequently changing. In order to keep up to date with
148 the latest version, it is necessary to periodically pull the latest
149 changes from the mirror repository by running \verb.hg pull. followed
152 \section{Compiling Palacios}
153 Palacios is capable of targeting 32 and 64 bit operating systems, and
154 includes a build process that supports both these
155 architectures. Furthermore, Palacios has multiple build locations,
156 with multiple makefiles: a top level build directory and a Palacios
157 specific build directory. The Palacios build process first generates a
158 static library that includes the Palacios VMM. This static library is
159 then linked into a host operating system. Palacios internally supports
160 GeekOS and can generate a complete OS image via a unified build
161 process. To combine Palacios with Kitten, it is necessary to first
162 compile Palacios and then to compile Kitten externally link it with
163 Palacios. The output of the compilation process is a bit more complex
164 and generates multiple binaries, and the specifics can be found in the
167 The top level build directory provides a number of high level make
168 targets, and is located in {\em palacios/build/}. It supports building
169 32 and 64 bit versions of the Palacios library independently as well
170 as building an integrated version of GeekOS. The basic targets are:
172 \item \verb.make palacios-full32. -- Generates a 32 bit version of the Palacios static library
173 \item \verb.make palacios-full64. -- Generates a 64 bit version of the
174 Palacios static library
175 \item \verb.make geekos. -- Compiles the GeekOS kernel, and link it with the
176 Palacios static library
177 \item \verb.make geekos-iso. -- Generate an ISO boot disk image from the
178 GeekOS kernel that has been compiled
181 The second build directory is located at {\em palacios/palacios/build}
182 and handles only the Palacios compilation process. It supports a
183 differnt set of targets and arguments:
185 \item \verb.make ARCH=32. -- iteratively compiles a 32 bit version of Palacios
186 \item \verb.make ARCH=64. -- iteratively compiles a 64 bit version of
188 \item \verb.make ARCH=32 world. -- fully recompiles a 32 bit version of
190 \item \verb.make ARCH=64 world. -- fully recompiles a 64 bit version of
194 Both build levels support compilation directives that control the
195 debugging messages that are generated by Palacios. These are specified
196 by appending a \verb.DEBUG_<COMPONENT>=1. to the end of the
197 \verb.make. command. The components that are currently supported are:
199 \item \verb.DEBUG_ALL=1. -- enables debugging for all the VMM components
200 ({\em Warning:} this generates a {\em lot} of debug information.
201 \item \verb.DEBUG_SHADOW_PAGING=1.
202 \item \verb.DEBUG_CTRL_REGS=1.
203 \item \verb.DEBUG_INTERRUPTS=1.
204 \item \verb.DEBUG_IO=1.
205 \item \verb.DEBUG_KEYBOARD=1.
206 \item \verb.DEBUG_PIC=1.
207 \item \verb.DEBUG_PIT=1.
208 \item \verb.DEBUG_NVRAM=1.
209 \item \verb.DEBUG_GENERIC=1.
210 \item \verb.DEBUG_EMULATOR=1.
211 \item \verb.DEBUG_RAMDISK=1.
212 \item \verb.DEBUG_XED=1.
213 \item \verb.DEBUG_HALT=1.
214 \item \verb.DEBUG_DEV_MGR=1.
215 \item \verb.DEBUG_APIC=1.
220 \section{Compiling Kitten}
221 Kitten requires a 64 bit version of Palacios, so make sure that
222 Palacios has been correctly compiled before compiling Kitten.
224 \subsection{Configuration}
225 Kitten borrows a lot of concepts from Linux, including the Linux build
226 process. As such it must be configured before it is actually compiled.
227 The Kitten configuration process is the same as Linux, and can be
228 accessed via any of these make targets.
230 \item \verb.make xconfig.
231 \item \verb.make config.
232 \item \verb.make menuconfig.
235 There are some specific configuration options that should be disabled
236 to work with Palacios. Because Palacios is configured by default to
237 provide a guest with direct access to the VGA console, the {\em VGA
238 console} device driver should be disbabled in the Kitten
239 configuration. Similarly the {\em VM console} driver should be
242 Furthermore, because the VGA console is not being used the {\em Kernel
243 Command Line Arguments} must be modified to remove the {\em VGA}
244 device from the console list.
246 The guest OS that is booted as a VM is included as an ISO image in raw
247 binary format inside Kitten's {\em init\_task}. To change the guest
248 ISO, you must change the makefile for the init\_task. This is located
249 in {\em user/hello\_world/Makefile} and the syntax is well commented.
250 On {\em newskysaw} a collection of guest ISO images are located in
251 {\em /opt/vmm-tools/isos/}.
254 \subsection{Compilation}
255 After Kitten has been configured the compilation can be done. The
256 general process is to compile a reference build of Kitten, followed by
257 compiling Palacios support as a kernel module, and then doing a new
258 full recompilation of Kitten.
260 The specific compilation steps are run from the top level Kitten directory:
265 cp built-in.o ../modules/palacios-mod.o
271 \note{This should probably explain how to change the iso (helloworld,etc)}
273 This generates an ISO boot image containing Kitten, Palacios, and the
274 guest that will be run as a VM. The ISO image is located at {\em
275 ./arch/x86\_64/boot/image.iso}.
278 \section{Running Palacios/Kitten}
279 Kitten and Palacios are capable of running under Qemu, which makes
280 debugging much simpler.
282 The basic form of the command to start the Qemu emulator is:
284 /usr/local/qemu/bin/qemu-system-x86_64 -smp 1 -m 1024 \
285 -serial file:./serial.out \
286 -cdrom ./arch/x86_64/boot/image.iso \
290 The command starts up a single processor emulated machine, with 1gig
291 of RAM and a cdrom drive loaded with the Kitten ISO image. Furthermore
292 all output to the serial port is written directly to a file called
293 {\em serial.out}. This command can be copied into a shell script for easy access.
295 \section{Development Guidelines}
297 There are standard requirements we have for code entering the mainline.
299 First and foremost, Palacios is designed to be OS indenpendent and
300 support 32 and 64 bit architectures. This means that developers should
301 not include any external OS specific dependencies in any Palacios
302 component. Also all changes need to be tested on both 32 and 64 bit
303 architectures to make sure that they compile as well as run corrrectly.
305 \paragraph*{Coding Style}
307 "The use of equal negative space, as a balance to positive space, in a
308 composition is considered by many as good design. This basic and often
309 overlooked principle of design gives the eye a "place to rest,"
310 increasing the appeal of a composition through subtle means."
312 Translation: Use the spacebar, newlines, and parentheses.
314 Curly-brackets are not optional, even for single line conditionals.
316 Tabs should be 4 characters in width.
318 {\em Special:} If you are using XEmacs add the following to your \verb.init\.el. file:
320 (setq c-basic-offset 4)
321 (c-set-offset 'case-label 4)
326 if(a&&b==5||c!=0) return;
333 if (((a) && (b == 5)) ||
341 \paragraph*{Fail Stop}
342 Because booting a basic linux kernel results in over 1 million VM exits
343 catching silent errors is next to impossible. For this reason
344 ANY time your code has an error it should return -1, and expect the
347 This includes unimplemented features and unhandled cases. These cases
348 should ALWAYS return -1.
351 \paragraph*{Function names}
352 Externally visible function names should be used rarely and have
353 unique names. Currently we have several techniques for achieving this:
356 \item \verb.#ifdefs. in the header file
358 When the V3 Hypervisor is compiled it defines the symbol
359 \verb.__V3VEE__. Any function that is not needed outside the Hypervisor
360 context should be inside an \verb.#ifdef __V3VEE__. block, this will make it
361 invisible to the host environment.
363 \item Static Functions
365 Any utility functions that are only needed in the .c file where they
366 are defined should be declared as static and not included in the
367 header file. You should make an effort to use static functions
370 \item \verb.v3_. prefix
372 Major interface functions should be named with the prefix \verb.v3_. This
373 xallows easy understanding of how to interact with the subsystems. And
374 in the case that they need to be externally visible to the host os,
375 make them unlikely to collide with other functions.
378 \paragraph*{Debugging Output}
379 Debugging output is sent through the host os via functions in the
380 \verb.os_hooks. structure. These functions have various wrappers of the form
381 \verb.Print*., with printf style semantics.
383 Two functions of note are \verb.PrintDebug. and \verb.PrintError..
389 Should be used for debugging output that will often be turned off
390 selectively by the VMM configuration.
394 Should be used when an error occurs, this will never be optimized out
395 and will always print.
399 \section{Code Submission}
400 \label{sec:submission}
402 To commit changes to the central repository they need to be exported
403 as a patch set that can be applied directly to a mainline. Both Git
404 and Mercurial contain functionality to allow developers to maintain
405 changes as a patch set. There are also a few options that make dealing
408 \subsection{Palacios}
410 Git includes support for directly exporting local repository commits
411 as a patch set. The basic operation is for a developer to commit a
412 change to a local repository, and then export that change as a patch
413 that can be applied to another git repository. While this is
414 functionally possible, there are a number of issues. The main problem
415 is that it is difficult to fully encapsulate a new feature in a single
416 commit, and dealing with multiple patches that often overwrite each
417 other is not a viable option either. Furthermore, once a patch is
418 applied to the mainline, it will generate a conflicting commit that
419 will become present when the developer next pulls from the central
420 repository. This can result in both repositories getting out of
421 sync. It is possible to deal with this by manually rebasing the local
422 repository, but it is difficult and error-prone.
424 This approach also does not map well when patches are being revised. A
425 normal patch will go through multiple revisions as it is reviewed and
426 modified by others. This often leads to synchronization issues as well
427 as errors with patch revisions. Ultimately it is the responsibility of
428 the developer to generate a patch that will apply cleanly to the
431 For this reason most internal developers should seriously consider
432 {\em stacked git}. Stacked git is designed to make patch development
433 easier and less of a headache. The basic mode of operation is for a
434 developer to intialize a patch for a new feature and then continuously
435 apply changes to the patch. Stacked Git allows a developer to layer a
436 series of patches on top of a local git repository, without causing
437 the repository to unsync due to local commits. Basically, the
438 developer never commits changes to the repository itself but instead
439 commits the changes to a specific patch. The local patches are managed
440 using stack operations (push/pop) which allows a developer to apply
441 and unapply patches as needed. Stacked git also manages new changes to
442 the underlying git repository as a result of a pull operation and
443 prevents collisions as changes are propagated upstream. For instance
444 if you have a local patch that is applied to the mainline as a commit,
445 when the commit is pulled down the patch becomes empty because it is
446 effectively identical to the mainline. It also makes incorporating
447 external revisions to a patch easier. Stacked git is installed on {\em
448 newskysaw} in \verb./opt/vmm-tools/bin/.
450 Brief command overview:
452 \item \verb.stg init. -- Initialize stacked git in a given branch
453 \item \verb.stg new. -- create a new patch set, an editor will open
454 asking for a commit message that will be used when the patch is
455 ultimately committed.
456 \item \verb.stg pop. -- pops a patch off of the source tree.
457 \item \verb.stg push. -- pushes a patch back on to a source tree.
458 \item \verb.stg export. -- exports a patch to a directory as a file
459 that can then be emailed.
460 \item \verb.stg refresh. -- commits local changes to the patch set at
461 the top of the applied stack.
462 \item \verb.stg fold. -- Apply a patch file to the current
463 patch. (This is how you can manage revisions that are made by other developers).
466 You should definately look at the online documentation to better
467 understand how stacked git works. It is not required of course, but if
468 you want your changes to be applied its up to you to generate a patch
469 that is acceptable to a core developer. Ultimately using Stacked git
470 should be easier than going it alone.
473 All patches should be emailed to Jack for inclusion in the
474 mainline. An overview of the organization is given in
475 Figure~\ref{fig:process}. You should assume that the first revision of
476 a patch will not be accepted, and that you will have to make
477 changes. Furthermore, the final form of the patch most likely will not
478 be exactly what you submitted.
483 \includegraphics[height=3.5in]{dev_chart.pdf}
485 \caption{Development organization}
492 Writing code for Kitten follows essentially the same process as
493 Palacios. The difference is that the patches need to be emailed to the
494 Kitten developers. To send in a patch, you can just email it to the
495 V3Vee development list.
498 Also, instead of Stacked git you should use Mercurial patch
499 queues. This feature is enabled in your .hgrc file.
505 Mercurial queues use the same stack operations as stacked git, however
506 it does not automatically handle the synchronization with pull
507 operations. Before you update from the central version of Kitten you
508 need to pop all of the patches, and then push them once the update is
520 %Also, remember that Kitten is not a Northwestern project and is being
521 %developed by professional developers at Sandia National Labs. So keep
522 %in mind that you are representing Northwestern and the rest of the
523 %Palacios development group. We are collaborating with them because
524 %Kitten and the resources they have are very important for our research
525 %efforts. They are collaborating with us because they believe that
526 %Palacios might be able to help them. Therefore it is important that we
527 %continue to ensure that they see value in our collaboration. In plain
528 %terms, we need to make sure they think we're smart and know what we're
529 %doing. So please keep that in mind when dealing with the Kitten group.
534 Both the Kitten and GeekOS substrates on which Palacios can run
535 currently include drivers for two simple network cards, the NE2000,
536 and the RTL8139. The Kitten substrate is acquiring an ever increasing
537 set of drivers for specialized network systems. A lightweight
538 networking stack is included so that TCP/IP networking is possible
539 from within the host OS kernel and in Palacios.
541 When debugging Palacios on QEMU, it is very convenient to add an
542 RTL8139 card to your QEMU configuration, and then drive it from within
543 Palacios. QEMU can be configured to provide local connectivity to the
544 QEMU emulated machine, including bridging the emulated machine with a
545 physical network. Local connectivity can be done with redirection, or
546 with a TAP interface. For global connectivity, a TAP interface must
547 be used; it is bridged to a physical interface.
549 \section{Configuring the development host's QEMU network}
551 To get local connectivity with redirection, no networking changes on
552 the host are needed. However, people usually want to use TAP-based
553 networking, which does require changes. For one thing, TAP interfaces
554 can be inspected with tools like wireshark, which makes for much
555 easier debugging of network code.
557 In order to get QEMU networking to function, it is necessary to create
558 TAP interfaces, and, optionally, to bridge them to real networks. A
559 developmet machine typically will have several TAP interfaces, and
560 more can be created. Generally, each developer should have a TAP
561 interface of his or her own. In the following, we will use our
562 development machine, newskysaw, as an example.
564 To set up a TAP interface on newskysaw, the following comand is used:
566 /root/util/tap_create tapX
569 When QEMU runs with a tap interface, it will use /etc/qemu-ifup to
570 bring up the interface. On newskysaw, /etc/qemu-ifup looks like this:
574 echo "Executing /etc/qemu-ifup - no external bridging"
575 echo "Bringing up $1 for bridged mode..."
576 NET=`echo $1 | cut -dp -f2`
577 sudo /sbin/ifconfig $1 172.2${NET}.0.1 up
581 The interface tap$N$ is brought up with the IP address 172.2$N$.0.1.
582 ifconfig will also create a routing rule that sends 172.2$N$.0.1/16
583 traffic to tap$N$. The upshot is that if the code running in QEMU
584 uses an IP address in this network (for example: 172.2$N$.0.2), you
585 will be able to talk to it from newskysaw. For example, from
586 newskysaw, if you ping 172.21.0.2, the packet (and ARP) will go out via
587 tap1. The source address will appear to be 172.21.0.1. The QEMU
588 machine will see these packets on its interface, and the software
589 controling its interface can respond to 172.21.0.1.
591 This form of networking is local to the machine. You can also bridge
592 a TAP interface with a physical interface. The result of this is that
593 a packet sent on it will be sent on the physical interface. To do
594 this requires more effort (and is not set up by default on newskysaw).
595 As an example, consider that on newskysaw, the physical interface eth1
596 is connected to a private network switch to which the lab test
597 computers (v-test-amd, v-test-amd2, etc.) are connected. To bridge,
598 for example, tap10, to this interface, you would do the following
601 \item You need to bring up eth1 (ifconfig eth1 up {\em address}
602 netmask {\em mask}). It is important that the address and mask you
603 choose are appropriate for the network eth1 is connected to.
604 \item You would bring up tap10 without an address: /sbin/ifconfig
606 \item You would bridge tap10 and eth1: /usr/sbin/brctl addif br0
607 tap10; /usr/sbin/brctl addif eth1. This assumes that br0 was
611 Bridging tap$N$ with eth1 will only work (where ``work'' means sending
612 a packet on the network and making the packet visible on localhost) if
613 the IP address in the code running in QEMU is set correctly. This
614 means that it needs to be set to correspond to the network of eth1).
615 For the newskysaw configuration, this is a 10-net address.
618 \subsection{Configuring Kitten}
620 Kitten needs to be explicitly configured to use networking. Currently
621 only a subset of the networking configurations are supported. To
622 enable an ethernet network you should enable the following options:
625 \item Enable TCP Support
626 \item Enable UDP Support
627 \item Enable socket API
628 \item Enable ARP support
631 The other options are not supported, and enabling them will probably
632 break the kernel compilation.
634 To allow Kitten to communicate with the Qemu network card you also
635 need to enable the appropriate device driver: \newline
636 \verb.NE2K Device Driver (rtl8139).
638 The driver then needs to be listed as a Kernel Command Line argument
639 in the {\em ISOIMAGE configuration}. To do this add
640 \verb.net=rtl819. to the end of the argument string.
642 Kitten currently does not support the dynamic assignment or IP
643 addresses at runtime. Because of this it is necessary to hardcode the
644 IP address into the device driver. For the rtl8139 network driver look
645 in the file {\em drivers/net/ne2k/rtl8139.c} for the function
648 There shoule be a block of code that looks like the following:
650 struct ip_addr ipaddr = { htonl(0 | 10 << 24 | 0 << 16 | 2 << 8 | 16 << 0) };
651 struct ip_addr netmask = { htonl(0xffffff00) };
652 struct ip_addr gw = { htonl(0 | 10 << 24 | 0 << 16 | 2 << 8 | 2 << 0) };
655 This sets the ip address as 10.0.2.16, netmask 255.255.255.0 and
656 gateway address 10.0.2.2. Change these assignments to match your configuration.
659 \paragraph*{Kitten as the Guest OS}
661 When running Kitten as a VM, the above applies except that you will
662 want to enable the {\em VMNET} device driver instead of the {\em rtl8139}.
665 \subsection{Running with networking}
667 \paragraph*{TAP Interface}
668 Running with a TAP interface provides either local or global
669 connectivity (depending on how the TAP interface is configured and/or
670 bridged). From the perspective of the QEMU command line, both look
671 the same, however. You simply add something like this to the command
674 -net tap,ifname=tap2 -net nic,model=rtl8139
676 The first \verb.-net. option indicates that you want to use a tap
677 interface, specifically \verb.tap2.. The second \verb.-net. option
678 specifies that this interface will appear to code in the QEMU machine
679 to be a network interface card of the specific model RTL8139. Note
680 that this is a model for which we have a driver. If tap2 were
681 bridged, we'd get global connectivity. If not, we would just get
685 \paragraph*{Redirection}
686 It is also possible to achieve limited local connectivity even if you
687 have no TAP support on your development machine. In redirection, QEMU
688 essentially acts as a proxy, translating TCP or other connections and
689 low-level packet operations on the network interface in the QEMU
690 machine. For example, the following options will redirect the host's
691 9555 port to the QEMU machine's 80 port:
693 -net user -net nic,model=rtl8139 -redir tcp:9555:10.10.10.33:80
695 The first \verb.-net. option indicates that we are using user-level
696 networking (proxying). The secod \verb.-net. option indicates that
697 this user-level network will appear in the QEMU machine as an RTL8139
698 network card. The \verb.-redir. option indicates that connections on
699 localhost:9555 will be translated into equivalent packet exchanges on
700 the RTL8139 card in the QEMU machine. However, we have to tell QEMU
701 which IP address and port to use on the QEMU machine's side. This is
702 what the 10.10.10.33 address, and port 80 are. In the example, if you
703 access port 9555 on localhost, say with:
705 telnet localhost 9555
707 The packets that appear in the QEMU machine will be bound for
708 10.10.10.33, port 80. Within the QEMU machine, your RTL8139 interface
709 had better then be up on that address.
711 Qemu has many options to build up a virtual or real networking. See
712 http://www.h7.dion.ne.jp/$\sim$qemu-win/HowToNetwork-en.html for more
716 For more questions, talk to Jack, Lei, or Peter.