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.


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