Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


ab70a55cdd743baba8d8316285ec40a834ea28c3
[palacios.git] / manual / manual.tex
1
2 \documentclass[11pt]{article}
3
4 \usepackage{calc}
5 \usepackage{graphics}
6 %\usepackage{latex8}
7 \usepackage{times}
8 \usepackage{epsf}
9 \usepackage{epsfig}
10 \usepackage{graphicx}
11 \usepackage{changebar}
12 \usepackage{portland}
13 \usepackage{lscape}
14
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} 
24
25 \newcommand{\note}[1]{{$\rightarrow$ \bf Note: \emph{#1}}}
26
27 \begin{document}
28
29 \title{
30 \includegraphics[height=1.5in]{v3vee.pdf}
31 \includegraphics[height=1.5in]{logo6.png} \\
32 \vspace{0.5in} 
33 Palacios Internal Developer Manual
34 }
35
36
37 \maketitle
38
39
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}.  You will also
46 want to read the document {\em Building a bootable guest image for
47 Palacios and Kitten} in order to understand how to build an extremely
48 lightweight guest environment, suitable for testing.
49
50 Please note that Palacios and Kitten are under rapid development,
51 hence this manual may very well be out of date!
52
53 \newpage
54 \tableofcontents
55 \newpage
56 \listoffigures
57 \newpage
58
59 \section{Overview}
60
61
62 Both Palacios and Kitten follow a hybrid development process that
63 uses both the centralized repository and distributed development
64 models. A central repository exists that holds the master version of
65 the code base. This central repository is cloned by multiple people
66 and in multiple places to support various development efforts. A
67 feature of \texttt{git} is that every developer actually has a fully copy of
68 the entire repository, and so can function independently until such
69 time as they need to re-sync with the master version. 
70
71 There are typically multiple levels of access to the central
72 repository, that are granted based on the type of developer being
73 granted access. The three basic developer types and their access
74 privileges are:
75
76 \begin{itemize}
77 \item Core developers: These are the lead developers and are in
78 charge of managing the master repository. They have full read/write
79 access permissions to the central repository.
80
81 \item Internal developers: Formal members of the development
82 team. These people are capable of pulling directly from the central
83 repository, but lack the ability to write directly to it. 
84
85 \item External developers: People who are not actual members of the
86 development team. These people can only access the public repository
87 which is only updated to contain the release versions. 
88 \end{itemize}
89
90 Students doing independent study or REUs related to Palacios are set
91 up as internal developers.  EECS 441 (Resource Virtualization)
92 students are generally either set up as internal or external
93 developers, depending on their projects.
94
95 Because internal and external developers cannot write directly to the
96 master repository, they need to first submit their changes to a core
97 developer before they can be added to the mainline. We will discuss
98 that process in Section~\ref{sec:submission}.
99
100
101 \section{Checking out Palacios}
102
103 The central Palacios repository is located on {\em
104 newskysaw.cs.northwestern.edu} in {\em /home/palacios/palacios}. All
105 internal developers have read access to the directory. Each developer
106 must create their own local version of the repository, this is done
107 with {\em git clone}.
108
109 \begin{verbatim}
110 git clone /home/palacios/palacios
111 \end{verbatim}
112
113 On the machine {\em newbehemoth.cs.northwestern.edu} you will want to
114 use the following command instead. The {\em newskysaw} home
115 directories are NFS-mounted on /home-remote.
116
117
118 \begin{verbatim}
119 git clone /home-remote/palacios/palacios
120 \end{verbatim}
121
122
123 On any other machine, you can clone the repository via ssh, provided
124 you have a newskysaw account:
125  
126 \begin{verbatim}
127 git clone ssh://you@newskysaw.cs.northwestern.edu//home/palaicos/palacios
128 \end{verbatim}
129
130 This creates a local copy of the repository at {\em ./palacios/}.
131
132 Note that both {\em newskysaw} and {\em newbehemoth} have all the
133 tools installed that are needed to build and test Palacios and Kitten.
134 If you develop on another machine, you will need to set those tools up
135 for yourself.  This isn't hard and the tools are all free.  See the
136 technical report for what tools you will need.
137
138 When you first clone the repository, you will get the {\em master}
139 branch, which is used to generate releases.   All development work is
140 done in the {\em devel} branch of the repository. The developer can
141 access this branch via:
142
143 \begin{verbatim}
144 git checkout --track -b devel origin/devel
145 \end{verbatim}
146
147 or 
148
149 \begin{verbatim}
150 /opt/vmm-tools/bin/checkout_branch devel
151 \end{verbatim}
152
153 {\em Important:}
154 Note that Palacios is very actively developed so the contents of the
155 {\em devel} branch are frequently changing. In order to keep up to
156 date with the latest version, it is necessary to periodically pull the
157 latest changes from the master repository by running \verb.git pull..
158
159
160
161 \section{Checking out Kitten}
162
163 Kitten is available from Sandia National Labs, and is the main host OS
164 we are targeting with Palacios. Loosely speaking, core Palacios
165 developers are internal Kitten developers, and internal Palacios
166 developers are external Kitten developers. The public repository for
167 Kitten is at {\em http://code.google.com/kitten}.  To simplify things,
168 we are maintaining a local mirror copy in {\em /home/palacios/kitten}
169 that tracks the public repository.
170
171 Kitten uses Mercurial for their source management, so you will have to
172 make sure the local mercurial version is configured correctly.
173 Specifically you should add the following Python path to your shell environment.
174
175 \begin{verbatim}
176 export PYTHONPATH=/usr/local/lib64/python2.4/site-packages/
177 \end{verbatim}
178
179 You can then clone Kitten from the local mirror.   On {\em newskysaw},
180 run: 
181 \begin{verbatim}
182 hg clone /home/palacios/kitten
183 \end{verbatim}
184 On {\em newbehemoth}, run
185 \begin{verbatim}
186 hg clone /home-remote/palacios/kitten
187 \end{verbatim}
188 On other machines, run
189 \begin{verbatim}
190 hg clone ssh://you@newskysaw.cs.northwestern.edu//home/palacios/kitten
191 \end{verbatim}
192
193
194 Both the Kitten and Palacios clone commands should be run from the
195 same directory. This means that both repositories should be located at
196 the same directory level. The Kitten build process depends on this.
197
198 {\em Important:} Like Palacios, Kitten is under active development,
199 and its source tree is frequently changing. In order to keep up to
200 date with the latest version, it is necessary to periodically pull the
201 latest changes from the mirror repository by running \verb.hg.
202 pull. followed by \verb.hg update..
203
204 \section{Compiling Palacios}
205
206 The Palacios build process has been changed recently from a homegrown
207 environment to the widely used KBuild environment.  KBuild is also
208 used for building Kitten.  Because KBuild is the build environment
209 used for Linux, much of what you learn about configuring and building
210 Linux kernels is readily applicable to Palacios and Kitten. 
211
212 The output of the Palacios build process is a static library that
213 includes the Palacios VMM and relevant guest support code blocks. This
214 static library is then linked into a host operating system. Palacios
215 internally supports GeekOS and can generate a complete OS image via a
216 unified build process.  By complete OS image, we mean an ISO image
217 containing GeekOS, Palacios, and a guest image (another ISO image) for
218 testing. 
219
220 These days, however, Palacios is typically embedded into Kitten, not
221 GeekOS.  To combine Palacios with Kitten, it is necessary to first
222 configure and build Palacios, then to configure and build Kitten,
223 linking in Palacios.   Kitten can also be configured to link in a
224 guest image for testing.  
225
226 \subsection{Configuration}
227
228 To configure Palacios, enter the top level Palacios directory and
229 execute:
230 \begin{verbatim}
231 make clean
232 make xconfig
233 \end{verbatim}
234 At this point, you will see be presented with a KBuild configuration
235 screen, similar to what you would see in configuring a Linux kernel.
236 Palacios has far fewer options, however.   If you don't have X or
237 don't want the graphical configuration system, you can also use the
238 \verb.menuconfig. or \verb.config. targets.  The available options
239 change over time, so we do not cover all of them here, but here are a
240 few that are usually important, with their recommended values noted:
241 \begin{itemize}
242 \item Target Configuration:   
243 \begin{itemize}
244
245 \item Red Storm (Cray XT3/XT4) --- turn on to target Cray XT4
246 supercomputers.  (off)
247 \item AMD SVM Support --- targets AMD processors with the SVM hardware
248 virtualization features (on)
249 \item Intel VMX support --- targets Intel processors with the VMX
250 hardware virtualization features (on)
251 \item Compile for a multi-threaded OS (on)
252 \item Enable VMM telemetry support --- this is lightweight logging and
253 data collection (on)  
254 \item Enable VMM instrumentation --- this is heavyweight logging and
255 data collection (off)
256 \item Enable passthrough video --- this lets a guest write directly to
257 the video card (on)
258 \item Enable experimental options --- this makes it possible to select
259 features that are under current development (on).  You probably want
260 to leave VNET turned off.  VNET is an experimental VMM-embedded
261 overlay network under development by Lei Xia and Yuan Tang.
262 \item Enable built-in versions of stdlib functions --- this adds
263 needed stdlib functions that the host OS may not supply.  For use with
264 Kitten turn on and enable strncasecmp() and atoi().
265 \item Enable built-in versions of stdio functions (off)
266 \end{itemize}
267 \item Symbiotic Functions (these are experimental options for Jack
268 Lange's thesis). 
269 \begin{itemize}
270 \item Enable Symbiotic Functionality --- This adds symbiotic features
271 to Palacios, specifically support for discovery and configuration by
272 symbiotic guests, the SymSpy passive information interface for
273 asynchronous symtiotic guest $\leftrightarrow$ symbiotic VMM
274 information flow, and the SymCall functional interface for synchronous
275 symbiotic VMM $\rightarrow$ symbiotic guest upcalls.  (on)
276 \item Symbiotic Swap --- Enables the SwapBypass symbiotic service for
277 symbiotic Linux guests.  (off)
278 \end{itemize}
279 \item Debug Configuration
280 \begin{itemize}
281 \item Compile with Debug info --- adds debug symbols (-g)  (off)
282 \item Enable Debugging --- makes it possible to show PrintDebug output
283 (on).   You can selectively turn on debugging output for each major
284 VMM component, including shadow paging, nested paging, control
285 registers, interrupts, I/O, instruction emulation and XED, halt, and
286 the device manager.   Note that the more debugging output you turn on,
287 the slower the VMM will go since it will have to wait for the prints
288 to finish. 
289 \end{itemize}
290 \item BIOS Selection --- Lets you select which code blobs will be
291 used for bootstrapping the guest.   There are currently three:  a
292 BIOS, a Video BIOS, and the VMXAssist V8086 service (the latter is used only on
293 Intel VMX).   Generally, you should not need to change these.
294 \item Virtual Devices --- virtual devices can be instantiated and
295 added to a guest.   The following is a list of the currently
296 implemented virtual devices.
297 \begin{itemize}
298 \item BOCHS Debug Console Device --- used for debugging output from
299 the guest BIOS (on)
300 \item OS Debug Console Device --- used for debugging output from
301 the guest kernel (on)
302 \item 8259A PIC - legacy Programmable Interrupt Controller chip --- used
303 for bootstrap of most guests (on)
304 \item APIC - in-processor Advanced Programmable Interrupt Controller --- used
305 for interrupt delivery on almost all guests (on)
306 \item IOAPIC - Off-chip APIC  --- used for interrupt deliver for almost
307 all guests (on)
308 \item i440fx Northbridge --- emulation of a typical PC North Bridge
309 chip, used on almost all guests (on)
310 \item PIIX3 Southbridge --- emulation of a typical PC South Bridge
311 chip, used on almost all guests (on)
312 \item PCI --- emulation of a PCI bus - needed for attaching most
313 devices (on)   
314 \begin{itemize}
315 \item Passthrough PCI --- allows us to make a hardware PCI device visible and
316 directly accessible by the guest (on)
317 \end{itemize}
318 \item NVRAM - motherboard configuration memory --- needed by BIOS bootstrap (on)
319 \item Keyboard - Generic PS/2 keyboard, including mostly broken mouse
320 implementation (on)
321 \item IDE --- Support for virtual IDE controllers that support disks
322 and CD ROMs (on)
323
324 \item NE2K - NE2000 and RTL8139 network devices (off)
325 \item CGA - CGA video card (paritial implementation) (off)
326 \begin{itemize}
327 \item Telnet Virtual Console (off)   When CGA and Telnet Console are
328 on, it is possible to telnet to the console of the guest.   Eventually
329 the rest of this will provide simple bitmapped video console for VNC
330 access.
331 \end{itemize}
332 \item RAMDISK storage backend --- used to create RAM disk
333 implementations of block devices (on)
334 \item NETDISK storage backend --- used to create network-attached disk
335 implementations of block devices, e.g., network block devices (on)
336 \item TMPDISK storage backend --- used to create temporary storage
337 implementations of block devices (on)
338 \item Linux Virtio Balloon Device --- used for memory ballooning by
339 Linux virtio-compatible guests (on)
340 \item Linux Virtio Block Device --- used for fast block device support
341 by Linux virtio-compatible guests (on)
342 \item Linux Virtio Network Device --- used for fast network device support
343 by Linux virtio-compatible guests (on) 
344 \item Symbiotic Swap Disk (multiple versions) --- used for the
345 SwapBypass service (off)
346 \item Disk Performance Model --- used for the
347 SwapBypass service (off)
348 \end{itemize}
349 \end{itemize}
350
351 \subsection{Compilation}
352
353 After configuring Palacios---remember to save your changes---you can
354 compile it by executing
355 \begin{verbatim}
356 make 
357 \end{verbatim}
358 This will produce the file {\em libv3vee.a} in the current directory.
359 This static library contains the Palacios VMM and is ready for
360 embedding into an OS, such as Kitten.  The library provides the
361 ability to instantiate and run virtual machines.  By default, on a 64
362 bit machine, the library is compiled for 64 bit machines (x86\_64),
363 while on a 32 bit machine, it is compiled for 32 bit machines.  You
364 can override this using the ARCH=i386 or ARCH=x86\_64 arguments to the
365 make, provided you have the relevant tools available.  The 64 bit
366 version is what you need for use with Kitten.  A 64 bit Palacios can
367 run both 64 and 32 bit guests.  Both {\em newskysaw} and {\em
368 newbehemoth} are 64 bit machines. 
369
370
371 \section{Compiling Kitten}
372 Kitten requires a 64-bit version of Palacios, so make sure that
373 Palacios has been correctly compiled before compiling Kitten.  The
374 current default for Palacios is 64 bit. 
375
376 \subsection{Configuration}
377 Kitten borrows a lot of concepts from Linux, including the Linux build
378 process. As such it must be configured before it is actually compiled.
379 The Kitten configuration process is the same as Linux, and can be
380 accessed via any of these make targets.
381 \begin{itemize}
382 \item \verb.make xconfig.
383 \item \verb.make config.
384 \item \verb.make menuconfig.
385 \end{itemize}
386
387 Of course, there are a range of configuration options.  In the
388 following, we note only the most important:
389 \begin{itemize}
390 \item Target Configuration
391 \begin{itemize}
392 \item System Architecture --- you probably want to set this to
393 PC-Compatible, unless you are working on Red Storm.
394 \item Processor Family --- you want to set this to either
395 AMD-Opteron/Athlon64 or Intel-64/Core2, depending on whether you have
396 a 64 bit AMD or 64 bit Intel processor.
397 \end{itemize}
398 \item Virtualization
399 \begin{itemize}
400 \item Include Palacios VMM --- this will link against the Palacios
401 library (on)
402 \item Path to pre-built Palacios tree --- directory where libv3vee.a
403 can be found.
404 \item Path to guest image --- location of the test guest OS
405 image that will be embedded.  We will say more about this later.
406 Essentially, however, a guest image consists of a blob that begins
407 with an XML description of the desired guest environment and the
408 contents of the remainder of the blob.   The remainder of the blob
409 usually contains disk or cd images.
410 \end{itemize}
411 \item Networking 
412 \begin{itemize}
413 \item Enable LWIP TCP/IP stack.  This activates a simple TCP/IP stack
414 that things like NETDISK can use. (on)
415 \end{itemize}
416 \item Device Drivers
417 \begin{itemize}
418 \item VGA Console --- driver for basic video.  If you turn on
419 passthrough video in Palacios, you should turn this off.
420 \item Serial Console --- driver for serial port console.  (on)
421 \item VM Console --- driver for Kitten console on top of Palacios.  If
422 Kitten is run {\em as a guest}, and it has VM Console on, then it can output
423 cleanly via the Palacios OS Console device (off).
424 \item NE2K Device Driver --- driver for NE2K and RTL8139 network cards
425 (on)
426 \item VM Network Driver --- driver for Kitten network output using
427 Palacios.  If Kitten is run {\em as a guest}, and it has VM Network
428 Driver, then it can send and receive packets using the Palacios Linux
429 virtio network device.  (off)
430 \end{itemize}
431 \item ISOIMAGE configuration:  Kitten kernel arguments.   Note that
432 this is NOT for the guest image, but rather for the Kitten image.  You
433 can leave this alone.  For Palacios operation, it's important that the
434 option \verb.console=serial. appears.  If the NE2K/RTL8139 driver
435 should be used \verb.net=rtl8139. should appear. 
436 \item Kernel Hacking
437 \begin{itemize}
438 \item Kernel Debugging --- here you can turn on various Kitten
439 Linux-like debugging features.   Only a few are noted below:
440 \begin{itemize}
441 \item Compile the kernel with debug info --- if this is on, you will
442 have debugging information compiled in (-g)
443 \item KGDB --- if you have this enabled, you will be able to attach to
444 the running kernel from the GDB debugger.  This means you can also
445 attach to Palacios, which is embedded.   If you want to debug Palacios
446 using KGDB, be sure to turn on debugging in Palacios as well.
447 \end{itemize}
448 \end{itemize}
449 \item Include Linux compatability layer --- if this is on, you can 
450 selectively add Linux system calls and other functionality to Kitten.
451 Kitten is able to run Linux ELF executables as user processes with
452 this layer.   
453 \end{itemize}
454
455 The guest OS that is to be booted as a VM is included as a blob
456 pointed to by ``Path to guest image''.   The blob starts with an XML
457 description of the guest, followed by other chunks of data used, for
458 example, as the content of virtual hard drives or CD ROMs.  Please see
459 Section~\ref{sec:guestconfig} for basic information on how to use the
460 guest builder to assemble a guest OS blob. 
461
462 By default, the init task that is executed after Kitten boots (located
463 in user/hello\_world) does a number of Kitten tests.  One of these is
464 a test of the VMM API, which is implemented using Palacios.  When this
465 test is done, a VM is created, configured according to the XML, and
466 the guest OS blob is launched in it.
467
468
469 \subsection{Compilation}
470
471 After Kitten has been configured it can be compiled.  This is done
472 simply by executing
473 \begin{verbatim}
474 make isoimage
475 \end{verbatim}
476 This command will compile Kitten (with Palacios embedded in it) and
477 the init task (which will contain the guest OS blob), and then
478 assemble an ISO image file which can used to boot a machine.  The ISO
479 image is located at {\em ./arch/x86\_64/boot/image.iso}.  
480
481 This image file can be used for booting a QEMU emulation environment,
482 for booting a remote machine using PXE, or can be burned to CD/DVD for
483 booting a machine physically. 
484
485
486 \section{Basic Guest Configuration}
487 \label{sec:guestconfig}
488
489 To configure a guest, you write an XML configuration file, which
490 contains references to other files that contain data needed to
491 instantiate stateful devices such as virtual hard drives and CD ROMs.
492 You supply this information to a guest builder utility that assembles
493 a guest image suitable for reference in the Kitten configuration, as
494 described above.  
495
496 The guest builder utility is located in {\em
497 palacios/utils/guest\_creator}.  You will need to run \verb.make. in that
498 directory to compile it, resulting in the executable named {\em
499 build\_vm}.  Also located in that directory is an example configuration
500 file, named {\em default.xml}.   We typically use this file as a
501 template.  It is carefully commented.  In summary, a configuration
502 consists of
503 \begin{itemize}
504 \item Physical memory size of the gust
505 \item Basic VMM settings, such as what form of virtual paging is to be
506 used, the scheduler rate, whether services like telemetry are on, etc.
507 \item A memory map that maps regions of the host physical address
508 space to the guest physical address space.  This can, for example,
509 make a framebuffer visible in the guest.
510 \item A list of the files that will be used in assembling the image.
511 For example, the contents of a boot CD.
512 \item A list of the devices that the guest will have, including
513 configuration data for each device.
514 \end{itemize}
515 There are a few subtlies involved with devices.  One is that some
516 devices form attachement points for other devices.  The PCI device is
517 an example of this.  Another is that each device needs to define how
518 it is attached (e.g. direct (implicit), via a PCI bus, etc.)
519 Finally, there may be multiple instances of devices.   For example, a
520 PCI passthrough device is instantiated for every underlying PCI device
521 we want to make visible in the guest. 
522
523 The XML configuration format is carefully designed to be extensible.
524 For example, new devices could use additional or new configuration
525 options.  The configuration parser in Palacios essentially ignores XML
526 blocks it doesn't understand. 
527
528
529 To build a guest, one runs
530 \begin{verbatim}
531 palacios/utils/guest_creator/build_vm myconfig.xml -o myimage.dat
532 \end{verbatim}
533 Here, {\em myimage.dat} is the guest image that can be given to
534 Kitten. 
535
536 A common kind of guest used for testing is one that boots some form of
537 bootable Linux distribution, or other a live OS distribution.  These
538 distributions are CD ROM images (ISOs).  A range of them are available
539 on {\em newskysaw} under {\em /opt/vmm-tools/isos}.  We often use
540 Puppy Linux ({\em puppy.iso}) or Finnix ({\em finnix.iso}), for
541 example, but isos are also available for Windows of different flavors,
542 DOS, GeekOS, and others.  If you just want to use some guest ISO image
543 like this, you can generally just copy the default XML file, and
544 modify the
545 \verb.filename=. attribute here:
546 \begin{verbatim}
547  <files>
548     <!-- The file 'id' is used as a reference for 
549          other configuration components -->
550     <file id="boot-cd" filename="/home/jarusl/image.iso" />
551     <!--<file id="harddisk" filename="firefox.img" />-->
552  </files>
553 \end{verbatim}
554
555 For careful, repeatable experimentation, it is often convenient to
556 build your own simplified Linux guest image.  It will boot {\em much}
557 faster than a full blown distribution and you can readily set up an
558 environment in which you can exert very tight control, being able to
559 modify the Linux kernel, the included files (e.g., benchmarks), and
560 other components very rapidly.  To learn more about how to do this,
561 please consult the separate document named {\em Building a bootable
562 guest image for Palacios and Kitten}.
563
564 \section{Running Palacios/Kitten}
565 Kitten and Palacios are capable of running under QEMU, which makes
566 debugging much simpler.  QEMU is a user-level Linux or Windows program
567 that emulates a PC machine. 
568
569 The basic form of the command to start the QEMU emulator is:
570 \begin{verbatim}
571 /usr/local/qemu/bin/qemu-system-x86_64 -smp 1 -m 1024 \
572         -serial file:./serial.out \
573         -cdrom ./arch/x86_64/boot/image.iso  \
574         < /dev/null
575 \end{verbatim}
576
577 The command starts up a single processor emulated machine, with 1GB of
578 RAM and a CD-ROM drive loaded with the Kitten ISO image.  All output
579 to the serial port is written directly to a file called {\em
580   serial.out}. This command can be copied into a shell script for easy
581 access.
582
583 We can also run Palacios/Kitten on physical hardware.  The slow way is
584 to burn the Kitten ISO image onto a CD ROM and then boot the test
585 machine with it.  The much faster way is to set the test machine up to
586 use the PXE network boot system (most modern BIOSes support this), and
587 boot your Kitten image over the network.  The debugging output will
588 then appear on the actual serial port of the physical machine.  For
589 the Northwestern environment, please talk to Jack Lange or Peter Dinda
590 if you need to be able to do this.  Northwestern has a range of AMD
591 and Intel boxes for testing, as do UNM and Sandia.    A different form
592 of network boot is used for Red Storm. 
593
594
595 \section{Development Guidelines}
596
597 There are standard requirements we have for code entering the mainline. 
598
599 First and foremost, Palacios is designed to be OS independent and
600 support 32-bit and 64-bit architectures. This means that developers should
601 not include any external OS specific dependencies in any Palacios
602 component. Also all changes need to be tested on both 32-bit and 64-bit
603 architectures to make sure that they compile as well as run correctly.
604
605 \paragraph*{Coding Style}
606
607 ``The use of equal negative space, as a balance to positive space, in a
608 composition is considered by many as good design. This basic and often
609 overlooked principle of design gives the eye a 'place to rest,'
610 increasing the appeal of a composition through subtle means.''
611 \newline\newline
612 Translation: Use the space bar, newlines, and parentheses. 
613
614 Curly-brackets are not optional, even for single line conditionals. 
615
616 Tabs should be 4 characters in width.
617
618 {\em Special:} If you are using XEmacs add the following to your \verb!init.el! file:
619 \begin{verbatim}
620 (setq c-basic-offset 4)
621 (c-set-offset 'case-label 4)
622 \end{verbatim}
623
624 {\em Bad}
625 \begin{verbatim}
626 if(a&&b==5||c!=0) return;
627 \end{verbatim}
628
629
630 {\em Good}
631 \begin{verbatim}
632 if (((a) && (b == 5)) || 
633     (c != 0)) {
634         return;
635 }
636 \end{verbatim}
637
638
639
640 \paragraph*{Fail Stop}
641 Because booting a basic Linux kernel results in over 1 million VM exits
642 catching silent errors is next to impossible. For this reason
643 ANY time your code has an error it should return -1, and expect the
644 execution to halt. 
645
646 This includes unimplemented features and unhandled cases. These cases
647 should ALWAYS return -1. 
648
649
650 \paragraph*{Function names}
651 Externally visible function names should be used rarely and have
652 unique names. Currently we have several techniques for achieving this:
653
654 \begin{enumerate}
655 \item \verb.#ifdefs. in the header file
656 \newline
657 When the V3 Hypervisor is compiled it defines the symbol
658 \verb.__V3VEE__. Any function that is not needed outside the Hypervisor
659 context should be inside an \verb.#ifdef __V3VEE__. block, this will make it
660 invisible to the host environment.
661
662 \item Static Functions
663 \newline
664 Any utility functions that are only needed in the .c file where they
665 are defined should be declared as static and not included in the
666 header file. You should make an effort to use static functions
667 whenever possible. 
668
669 \item \verb.v3_. prefix \newline Major interface functions should be
670   named with the prefix \verb.v3_. This allows easy understanding of
671   how to interact with the subsystems.  In the case that they need to
672   be externally visible to the host OS, make them unlikely to collide
673   with other functions.
674 \end{enumerate}
675
676 \paragraph*{Debugging Output}
677 Debugging output is sent through the host OS via functions in the
678 \verb.os_hooks. structure. These functions have various wrappers of the form
679 \verb.Print*., with \texttt{printf}-style semantics. 
680
681 Two functions of note are \verb.PrintDebug. and \verb.PrintError..
682
683 \begin{itemize}
684
685 \item PrintDebug:
686 \newline
687 Should be used for debugging output that will often be turned off
688 selectively by the VMM configuration.
689
690 \item PrintError
691 \newline
692 Should be used when an error occurs, this will never be optimized out
693 and will always print. 
694 \end{itemize}
695
696
697 \section{Code Submission}
698 \label{sec:submission}
699
700 To commit changes to the central repository they need to be exported
701 as a patch set that can be applied directly to a mainline. Both Git
702 and Mercurial contain functionality to allow developers to maintain
703 changes as a patch set. There are also a few options that make dealing
704 with patches easier.
705
706 \subsection{Palacios}
707
708 Git includes support for directly exporting local repository commits
709 as a patch set. The basic operation is for a developer to commit a
710 change to a local repository, and then export that change as a patch
711 that can be applied to another git repository. While this is
712 functionally possible, there are a number of issues. The main problem
713 is that it is difficult to fully encapsulate a new feature in a single
714 commit, and dealing with multiple patches that often overwrite each
715 other is not a viable option either. Furthermore, once a patch is
716 applied to the mainline, it will generate a conflicting commit that
717 will become present when the developer next pulls from the central
718 repository. This can result in both repositories getting out of
719 sync. It is possible to deal with this by manually re-basing the local
720 repository, but it is difficult and error-prone. 
721
722 This approach also does not map well when patches are being revised. A
723 normal patch will go through multiple revisions as it is reviewed and
724 modified by others. This often leads to synchronization issues as well
725 as errors with patch revisions. Ultimately it is the responsibility of
726 the developer to generate a patch that will apply cleanly to the
727 mainline.
728
729 For this reason most internal developers should seriously consider
730 {\em stacked git}. Stacked git is designed to make patch development
731 easier and less of a headache. The basic mode of operation is for a
732 developer to initialize a patch for a new feature and then continuously
733 apply changes to the patch. Stacked Git allows a developer to layer a
734 series of patches on top of a local git repository, without causing
735 the repository to unsync due to local commits. Basically, the
736 developer never commits changes to the repository itself but instead
737 commits the changes to a specific patch. The local patches are managed
738 using stack operations (push/pop) which allows a developer to apply
739 and unapply patches as needed. Stacked git also manages new changes to
740 the underlying git repository as a result of a pull operation and
741 prevents collisions as changes are propagated upstream. For instance
742 if you have a local patch that is applied to the mainline as a commit,
743 when the commit is pulled down the patch becomes empty because it is
744 effectively identical to the mainline. It also makes incorporating
745 external revisions to a patch easier. Stacked git is installed on {\em
746 newskysaw} in \verb./opt/vmm-tools/bin/. 
747
748 Brief command overview:
749 \begin{itemize}
750 \item \verb.stg init. -- Initialize stacked git in a given branch
751 \item \verb.stg new. -- create a new patch set, an editor will open
752 asking for a commit message that will be used when the patch is
753 ultimately committed.
754 \item \verb.stg pop. -- pops a patch off of the source tree.
755 \item \verb.stg push. -- pushes a patch back on to a source tree.
756 \item \verb.stg export. -- exports a patch to a directory as a file
757 that can then be emailed.
758 \item \verb.stg refresh. -- commits local changes to the patch set at
759 the top of the applied stack.
760 \item \verb.stg fold. -- Apply a patch file to the current
761 pat1ch. (This is how you can manage revisions that are made by other developers).
762 \end{itemize}
763
764 You should definitely look at the online documentation to better
765 understand how stacked git works. It is not required of course, but if
766 you want your changes to be applied its up to you to generate a patch
767 that is acceptable to a core developer. Ultimately using Stacked git
768 should be easier than going it alone.
769
770
771 All patches should be emailed to Jack for inclusion in the
772 mainline. An overview of the organization is given in
773 Figure~\ref{fig:process}. You should assume that the first revision of
774 a patch will not be accepted, and that you will have to make
775 changes. Furthermore, the final form of the patch most likely will not
776 be exactly what you submitted. 
777
778  
779 \begin{figure}[t]
780 \begin{center}
781 \includegraphics[height=3.5in]{dev_chart.pdf}
782 \end{center}
783 \caption{Development organization}
784 \label{fig:process}
785 \end{figure}
786
787
788 \subsection{Kitten}
789
790 Writing code for Kitten follows essentially the same process as
791 Palacios. The difference is that the patches need to be emailed to the
792 Kitten developers. To send in a patch, you can just email it to the
793 V3Vee development list.
794
795
796 Also, instead of Stacked git you should use Mercurial patch
797 queues. This feature is enabled in your .hgrc file.
798 \begin{verbatim}
799 [extensions]
800 hgext.mq=
801 \end{verbatim}
802
803 Mercurial queues use the same stack operations as stacked git, however
804 it does not automatically handle the synchronization with pull
805 operations. Before you update from the central version of Kitten you
806 need to pop all of the patches, and then push them once the update is
807 complete.
808
809 Basically:
810 \begin{verbatim}
811 hg qpop -a
812 hg pull
813 hg update
814 hg qpush -a
815 \end{verbatim}
816
817
818 %Also, remember that Kitten is not a Northwestern project and is being
819 %developed by professional developers at Sandia National Labs. So keep
820 %in mind that you are representing Northwestern and the rest of the
821 %Palacios development group. We are collaborating with them because
822 %Kitten and the resources they have are very important for our research
823 %efforts. They are collaborating with us because they believe that
824 %Palacios might be able to help them. Therefore it is important that we
825 %continue to ensure that they see value in our collaboration. In plain
826 %terms, we need to make sure they think we're smart and know what we're
827 %doing. So please keep that in mind when dealing with the Kitten group.
828
829
830 \section{Networking}
831
832 Both the Kitten and GeekOS substrates on which Palacios can run
833 currently include drivers for two simple network cards, the NE2000,
834 and the RTL8139.  The Kitten substrate is acquiring an ever increasing
835 set of drivers for specialized network systems.   A lightweight
836 networking stack is included so that TCP/IP networking is possible
837 from within the host OS kernel and in Palacios.  
838
839 When debugging Palacios on QEMU, it is very convenient to add an
840 RTL8139 card to your QEMU configuration, and then drive it from within
841 Palacios.  QEMU can be configured to provide local connectivity to the
842 QEMU emulated machine, including bridging the emulated machine with a
843 physical network.  Local connectivity can be done with redirection, or
844 with a TAP interface.  For global connectivity, a TAP interface must
845 be used; it is bridged to a physical interface.
846
847 \section{Configuring the development host's QEMU network}
848
849 To get local connectivity with redirection, no networking changes on
850 the host are needed.  However, people usually want to use TAP-based
851 networking, which does require changes.  For one thing, TAP interfaces
852 can be inspected with tools like wireshark, which makes for much
853 easier debugging of network code.
854
855 In order to get QEMU networking to function, it is necessary to create
856 TAP interfaces, and, optionally, to bridge them to real networks.  A
857 development machine typically will have several TAP interfaces, and
858 more can be created.  Generally, each developer should have a TAP
859 interface of his or her own.  In the following, we will use our
860 development machine, newskysaw, as an example.
861
862 To set up a TAP interface on newskysaw, the following command is used:
863 \begin{verbatim}
864 /root/util/tap_create tapX
865 \end{verbatim}
866
867 When QEMU runs with a tap interface, it will use /etc/qemu-ifup to
868 bring up the interface.  On newskysaw, /etc/qemu-ifup looks like this:
869
870 \begin{verbatim}
871 #!/bin/bash
872 echo "Executing /etc/qemu-ifup - no external bridging"
873 echo "Bringing up $1 for bridged mode..."
874 NET=`echo $1 | cut -dp -f2` 
875 sudo /sbin/ifconfig $1 172.2${NET}.0.1 up
876 sleep 2
877 \end{verbatim}
878
879 The interface tap$N$ is brought up with the IP address 172.2$N$.0.1.
880 ifconfig will also create a routing rule that sends 172.2$N$.0.1/16
881 traffic to tap$N$.  The upshot is that if the code running in QEMU
882 uses an IP address in this network (for example: 172.2$N$.0.2), you
883 will be able to talk to it from newskysaw.  For example, from
884 newskysaw, if you ping 172.21.0.2, the packet (and ARP) will go out via
885 tap1.  The source address will appear to be 172.21.0.1.  The QEMU
886 machine will see these packets on its interface, and the software
887 controlling its interface can respond to 172.21.0.1.  
888
889 This form of networking is local to the machine.  You can also bridge
890 a TAP interface with a physical interface.  The result of this is that
891 a packet sent on it will be sent on the physical interface.  To do
892 this requires more effort (and is not set up by default on newskysaw).
893 As an example, consider that on newskysaw, the physical interface eth1
894 is connected to a private network switch to which the lab test
895 computers (v-test-amd, v-test-amd2, etc.) are connected.  To bridge,
896 for example, tap10, to this interface, you would do the following
897 (with root's help):
898 \begin{enumerate}
899 \item You need to bring up eth1 (ifconfig eth1 up {\em address}
900 netmask {\em mask}).  It is important that the address and mask you
901 choose are appropriate for the network eth1 is connected to.
902 \item You would bring up tap10 without an address:  /sbin/ifconfig
903 tap10 up
904 \item You would bridge tap10 and eth1:  /usr/sbin/brctl addif br0
905 tap10; /usr/sbin/brctl addif eth1.  This assumes that br0 was
906 previously created. 
907 \end{enumerate}
908
909 Bridging tap$N$ with eth1 will only work (where ``work'' means sending
910 a packet on the network and making the packet visible on localhost) if
911 the IP address in the code running in QEMU is set correctly.  This
912 means that it needs to be set to correspond to the network of eth1).  
913 For the newskysaw configuration, this is a 10-net address.
914
915
916 \subsection{Configuring Kitten}
917
918 Kitten needs to be explicitly configured to use networking. Currently
919 only a subset of the networking configurations are supported. To
920 enable an Ethernet network you should enable the following options:
921
922 \begin{itemize}
923 \item Enable TCP Support
924 \item Enable UDP Support
925 \item Enable socket API
926 \item Enable ARP support
927 \end{itemize}
928
929 The other options are not supported, and enabling them will probably
930 break the kernel compilation.
931
932 To allow Kitten to communicate with the QEMU network card you also
933 need to enable the appropriate device driver: \newline
934 \verb.NE2K Device Driver (rtl8139).
935
936 The driver then needs to be listed as a Kernel Command Line argument
937 in the {\em ISOIMAGE configuration}. To do this add
938 \verb.net=rtl819. to the end of the argument string.
939
940 Kitten currently does not support the dynamic assignment or IP
941 addresses at runtime. Because of this it is necessary to hardcode the
942 IP address into the device driver. For the rtl8139 network driver look
943 in the file {\em drivers/net/ne2k/rtl8139.c} for the function
944 \verb.rtl8139_init..
945
946 There should be a block of code that looks like the following:
947 \begin{verbatim}
948   struct ip_addr ipaddr = { htonl(0 | 10 << 24 | 0 << 16 | 2 << 8 | 16 << 0) }; 
949   struct ip_addr netmask = { htonl(0xffffff00) }; 
950   struct ip_addr gw = { htonl(0 | 10 << 24 | 0 << 16 | 2 << 8 | 2 << 0) };
951 \end{verbatim}
952
953 This sets the IP address as 10.0.2.16, netmask 255.255.255.0 and
954 gateway address 10.0.2.2. Change these assignments to match your configuration.
955
956
957 \paragraph*{Kitten as the Guest OS}
958
959 When running Kitten as a VM, the above applies except that you will
960 want to enable the {\em VMNET} device driver instead of the {\em rtl8139}.
961
962
963 \subsection{Running with networking}
964
965 \paragraph*{TAP Interface}
966 Running with a TAP interface provides either local or global
967 connectivity (depending on how the TAP interface is configured and/or
968 bridged).  From the perspective of the QEMU command line, both look
969 the same, however.  You simply add something like this to the command
970 line:
971 \begin{verbatim}
972 -net tap,ifname=tap2 -net nic,model=rtl8139
973 \end{verbatim}
974 The first \verb.-net. option indicates that you want to use a tap
975 interface, specifically \verb.tap2..   The second \verb.-net. option
976 specifies that this interface will appear to code in the QEMU machine
977 to be a network interface card of the specific model RTL8139.  Note
978 that this is a model for which we have a driver.  If tap2 were
979 bridged, we'd get global connectivity.  If not, we would just get
980 local connectivity.  
981
982
983 \paragraph*{Redirection}
984 It is also possible to achieve limited local connectivity even if you
985 have no TAP support on your development machine.  In redirection, QEMU
986 essentially acts as a proxy, translating TCP or other connections and
987 low-level packet operations on the network interface in the QEMU
988 machine.  For example, the following options will redirect the host's
989 9555 port to the QEMU machine's 80 port:
990 \begin{verbatim}
991 -net user -net nic,model=rtl8139  -redir tcp:9555:10.10.10.33:80
992 \end{verbatim}
993 The first \verb.-net. option indicates that we are using user-level
994 networking (proxying).  The second \verb.-net. option indicates that
995 this user-level network will appear in the QEMU machine as an RTL8139
996 network card.   The \verb.-redir. option indicates that connections on
997 localhost:9555 will be translated into equivalent packet exchanges on
998 the RTL8139 card in the QEMU machine.  However, we have to tell QEMU
999 which IP address and port to use on the QEMU machine's side.  This is
1000 what the 10.10.10.33 address, and port 80 are.  In the example, if you
1001 access port 9555 on localhost, say with:
1002 \begin{verbatim}
1003 telnet localhost 9555
1004 \end{verbatim}
1005 The packets that appear in the QEMU machine will be bound for
1006 10.10.10.33, port 80.  Within the QEMU machine, your RTL8139 interface
1007 had better then be up on that address. 
1008
1009 QEMU has many options to build up virtual or real networking. See
1010 http://www.h7.dion.ne.jp/$\sim$qemu-win/HowToNetwork-en.html for more
1011 information.
1012
1013
1014 For more questions, talk to Jack, Lei,  or Peter.
1015
1016 \end{document}