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.


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