do not use "fill" class for vmware images, it breaks printing
[slides-virt.git] / index.rst
1
2 .. System Virtualization and OS Virtual Machines slides file, created by
3    hieroglyph-quickstart on Mon Oct 28 09:39:30 2013.
4
5 =============================================
6 System Virtualization and OS Virtual Machines
7 =============================================
8
9 :Date: 2013-12-19
10 :Authors: Ivan Boule, Olivier Matz
11
12 Plan
13 ====
14
15 Contents
16 --------
17
18 - History of Virtualization
19 - Virtualization Usage and Taxonomy
20 - Process Level Virtualization
21
22   - ABI Emulation
23   - Virtual Servers
24
25 - System Level Virtualization
26
27   - Transparent Hardware Emulation
28   - Transparent Hardware Virtualization
29   - Paravirtualization
30   - Hardware-Assisted Virtualization
31
32 - Conclusion
33
34 Who am I?
35 ---------
36
37 - Olivier MATZ ``<olivier.matz@6wind.com>``
38 - Software engineer since 10 years at 6WIND
39 - 6WIND is a software company designing high performance network
40   software
41
42   - http://www.6wind.com
43
44 - I'm mainly developing low-level code: Linux kernel, drivers and
45   applications close to the operating system
46
47 History of Virtual Machines
48 ===========================
49
50 Sixties: introduction of IBM/370 series
51 ---------------------------------------
52
53 - Generalization of virtual memory
54 - Microprogramation of instructions on small models
55 - CP/CMS hypervisor
56
57 .. figure:: ibm370.jpg
58    :width: 60%
59
60 .. note::
61
62    - IBM/370: généralisation de la mémoire virtuelle
63    - IBM/370: microprogrammation de certaines instructions sur les
64      petits modeles
65    - IBM/370: hyperviseur CP/CMS (Control Program/Conversational
66      Monitoring System), gérant des machines virtuelles sous lequel on
67      pouvait faire tourner indifféremment des CMS, des DOS et des
68      OS. Proposé à des clients le temps d’effectuer des migrations des
69      DOS vers OS, il sera souvent conservé pour la très grande
70      convivialité de CMS utilisé comme système de temps partagé.
71
72      le produit VM/370, créé par IBM dans les années 1970, permettait à
73      plusieurs usagers d'utiliser en temps partagé un ordinateur qui
74      exécute le système d'exploitation IBM DOS. IBM DOS tout seul
75      n'offrait pas la possibilité d'utilisation en temps partagé2.
76
77      - temps partagé entre VM
78
79 Eighties: IBM AS/400
80 --------------------
81
82 - Many logical machines in one physical machine
83 - High level (virtual) ISA including I/Os (TIMI)
84
85   - Take advantage of advances in hardware without recompilation
86   - User binaries contain both TIMI instructions and machine instructions
87   - Easier transition to PowerPC
88
89 .. figure:: ibm-as400.jpg
90    :width: 40%
91
92 .. note::
93
94    - IBM/AS-400: c'est un mini-ordinateur de la gamme IBM, fin des années 1980
95    - IBM/AS-400: possibilité de "découper" plusieurs machines logiques
96      dans une machine physique.
97    - IBM/AS-400: un programme ne parle pas directement au matériel, il
98      utilise un set d'instructions haut-niveau (ISA), ce qui rend le
99      programme indépendant du CPU sur lequel il tourne. Ceci a facilité
100      la transition vers les PowerPC.
101    - http://en.wikipedia.org/wiki/IBM_System_i
102    - XXX IBM/AS-400: pourquoi "co-designed VM" ? XXX rechercher sur internet
103    - emulation des instructions CPU de "haut niveau"
104      XXX regarder comment ca marche: est-ce que c'est un hyperviseur ou
105      un interpreteur.
106
107 Nineties and later: application VMs
108 -----------------------------------
109
110 .. figure:: java.png
111    :width: 15%
112
113 - Java
114
115   - a Java program is compiled into a portable bytecode
116   - the JVM is a fictive computer that is able to run this bytecode
117
118 - Microsoft Common Language Infrastructure (.Net)
119
120 .. note::
121
122    - http://en.wikipedia.org/wiki/Java_virtual_machine
123
124 Now: OS virtual machines
125 ------------------------
126
127 - Run an operating system virtualized top of a virtual machine
128 - Examples:
129
130   - VMware products (virtualized PC on x86)
131   - KVM
132   - Virtual PC (PC emulation on Mac OS/PowerPC)
133   - Many others : Bochs, VirtualBox, Qemu, ...
134
135 Virtualization Usages
136 =====================
137
138 System Virtualization Principles
139 --------------------------------
140
141 - Run multiple OS's on the same machine
142
143 - By design, an OS assumes to have full control over all physical
144   resources of the machine
145
146 - Manage sharing/partitioning of machine resources between Guest OS's
147
148   - CPU
149   - Physical memory & MMU
150   - I/O devices
151
152 Goals of System Virtualization
153 ------------------------------
154
155 - Reduction of Total Cost of Ownership (TCO)
156
157   - Increase utilisation of server resources
158   - Spawn new servers "on demand" (ex: Amazon EC2 and Elastic Load
159     Balancer)
160
161 - Reduction of Total Cost of Functioning
162
163   - Energy consumption
164   - Cooling
165   - Occupied Space
166
167 - Isolation of OS for security purposes (Qubes, Cells)
168
169 .. note::
170
171    - reduction TCO + TCF: parler du cas data center. On peut parler DE
172      migration à chaud, d'élasticité, ...
173    - amazon ec2:
174
175      - un client peut créer des machines virtuelles à la demande
176      - Elastic Load Balancer: Les ELB permettent de répartir la charge
177        entre les instances EC2
178      - Autoscaling: Permet de gérér automatiquement l'élasticité sur
179        un ou plusieurs groupes d'instances EC2
180      - Cloud Watch: Permet de suivre et monitorer des métriques des
181        instances EC2 pour envoyer des notifications ou prendre des
182        actions
183
184    - "qubes" (security) http://qubes-os.org/trac/wiki/QubesScreenshots
185
186      - Based on a secure bare-metal hypervisor (Xen)
187      - Networking code sand-boxed in an unprivileged VM (using IOMMU/VT-d)
188      - USB stacks and drivers sand-boxed in an unprivileged VM (currently
189        experimental feature)
190      - No networking code in the privileged domain (dom0)
191      - All user applications run in “AppVMs”, lightweight VMs based on
192        Linux
193      - Centralized updates of all AppVMs based on the same template
194      - Qubes GUI virtualization presents applications like if they were
195        running locally
196      - Qubes GUI provides isolation between apps sharing the same desktop
197      - Secure system boot based (optional)
198
199 Virtualization in high-throughput network equipments
200 ----------------------------------------------------
201
202 .. figure:: high-thput.svg
203    :width: 100%
204
205 .. note::
206
207    - Initialement, on a un système qui tourne sur plusieurs anciennes
208      cartes (plus la carte de management sous linux). On veut mettre à
209      jour le matériel, il est alors possible si la nouvelle carte est
210      plus puissante de virtualiser les anciennes sans modifier le
211      logiciel.
212
213      dataplane + control plane -> en une carte
214
215    - Reprendre ce qui a été dit au slide précédent
216
217 Usages of Virtual Machines
218 --------------------------
219
220 - Server virtualization
221
222   - Web sites hosting
223
224 - OS/kernel education & training
225
226   - OS fault recovery
227   - OS kernel development
228   - Test machine = development host
229
230 - Keep backward compatibility of legacy software
231
232 - Run applications not supported by host OS
233
234 - OS migration without reinstalling it on a new hardware
235
236 .. note::
237
238    - time sharing: on veut utiliser plusieurs OS sur la meme machine:
239      analogie avec plusieurs processes.
240
241    - eduction & training: on peut imaginer le cas d'un TP, comme présenté
242      dans l'article linux mag 140 sur la libvirt: chaque étudiant
243      travaille sur une machine virtuelle préconfigurée XXX a relire
244
245    - backward compatibility: préciser que c'est utile lorsque le matériel
246      n'est plus disponible par exemple.
247
248    - run app not supported by host OS: wine
249
250    - Certains services ne sont accessibles qu'au niveau de l'OS
251      (routage, filtrage, ...). Avoir plusieurs OS permet de les
252      dupliquer (ex: daisy chain tcp avec des VR)
253
254 Recovery Servers
255 ----------------
256
257 - Another example: one backup server to replace any machine
258
259 .. figure:: recovery.png
260    :width: 100%
261
262 .. note::
263
264    - La virtualisation permet de faire de la haute disponibilité à pas
265      cher. Souvent c'est le logiciel qui crashe. On peut dupliquer tout
266      une architecture reseau:
267      - apache
268      - mySQL
269      - mail
270      - etc...
271
272    - Un seul serveur backup à droite pour tous les autres
273      serveurs. Permet de ne pas avoir 8 machines. Si un des 4 se casse la
274      gueule, c'est celui de droite qui prend la main.
275
276    - en effet, chaque machine a sa propre configuration
277      systeme/reseau/filtrage... Il n'est pas forcément évident de
278      mettre les 4 services sur une même machine sans virtualisation.
279
280 Multi-Core CPU Issues (1)
281 -------------------------
282
283 - CPU power gain
284
285   - No more achieved through Frequency/Speed increase
286   - But obtained with higher density & multi-core chips
287
288 - Many RTOS designed with mono-processor assumption
289
290   - Adding multi-processor support is complex & costly
291   - Scaling requires time, at best...
292
293 - Legacy RT applications also designed for mono-processor
294
295   - Adaptation to multi-pro even more difficult than RTOS
296
297 .. note::
298
299    - cas des applications multi-threadées mais conçues avec en tête le
300      fait que la machine n'a qu'un seul core. la virtualisation systeme
301      permet de paralleliser ces applis sur des machine physiques
302      multicores (chaque VM étant mono-core), expliqué slide suivant.
303
304    - Beaucoup d'applications sont encore monoprocesseur. Cela simplifie
305      drastiquement la manière de coder, il n'y a pas de race condition,
306      pas besoin de locks/mutex. XXX
307
308    - ce probleme se pose moins sur un système classique que sur des
309      systèmes anciens ou des systèmes temps réel. En effet, les systèmes
310      classiques modernes supportent très bien le multicore et il
311      suffirait de lancer plusieurs applications simultanément. XXX
312
313    - certaines applications RT multithreadées comptent sur le fait qu'il
314      n'y a qu'un CPU, et que 2 threads ne sont jamais executés de manière
315      réellement concurrente
316
317 Multi-Core CPU Issues (2)
318 -------------------------
319
320 - OS virtualization allows to run simultaneously on a multi-cores CPU
321   multiple instances of mono-processor OS's
322
323 - Each OS instance is run in a mono-processor
324
325 - Virtual Machine assigned to a single CPU core
326
327 - No need to change legacy software
328
329 - Scalability managed at virtualization level
330
331 .. note::
332
333    - La virtualisation système permet de faire tourner plusieurs instance
334      d'un système d'exploitation non SMP sur un processeur multicore.
335
336    - Cela peut permettre d'éviter de réécrire un logiciel conçu pour une
337      machine mono-core. Le logiciel dont il est question ici est plutôt
338      un logiciel RT ou un noyau, car si c'est une application standard,
339      le problème ne se pose pas.
340
341 Virtualization Taxonomy
342 =======================
343
344 .. note::
345
346    taxonomy = inventaire
347
348 Machines Interfaces
349 -------------------
350
351 .. figure:: isa-abi.svg
352    :width: 70%
353
354 - ISA = Instruction Set Architecture
355
356   - System level interface
357   - All CPU instructions, memory architecture, I/O
358
359 - ABI = Application Binary Interface
360
361   - Process level interface
362   - User-level non privileged ISA instructions + OS systems calls
363
364 .. note::
365
366    - ISA: Instruction Set Architecture
367
368      les instructions du CPU (donner des exemples, comme le MOV, CLI/STI
369      pour vérouiller les interruptions), les périphériques, la MMU
370      (comment elle est doit être configurée), ...
371
372      C'est l'interface qui est utilisé par le système d'exploitation.
373
374    - ABI: Application Binary Interface
375
376      C'est l'interface qui permet à un processus de communiquer avec
377      l'extérieur. Il s'agit principalement d'appels systèmes (read,
378      write, gettimeofday, execve, sleep).
379
380      l'abi contient les instructions non-privilegiées + l'api de l'OS.
381      D'autres instructions comme le cli/sti ne font pas partie de l'ISA.
382
383    - exemple de la couche de compatibilité pour une application 32 bits
384      tournant sur un kernel 64 bits.
385
386 Virtualization Taxonomy
387 -----------------------
388
389 - Virtualization at process level (ABI)
390
391   - Emulation of Operating System ABI
392   - Virtual Servers
393
394 - Virtualization at system level (ISA)
395
396   - Standalone vs Hosted Virtualization
397   - Machine Emulation vs Machine Virtualization
398
399 .. note::
400
401    - un processus tourne déjà dans une machine virtuelle fournie par
402      l'OS, mais pas au même niveau. Historiquement, l'objectif d'un
403      système d'exploitation multitâche est de fournir des machines
404      virtuelles pour les applications (donc les utilisateurs). Chaque
405      application "pense" qu'elle est tout seule sur le processeur.
406
407      Chaque application peut avoir accès aux ressources via les appels
408      systèmes, comme si l'application était la seule à parler aux
409      périphériques. C'est au système d'exploitation d'ordonnancer les
410      processus et leurs requetes.
411
412    - la virtualisation systeme fonctionne sur le même principe mais à un
413      niveau différent. Nous allons voir dans les slides suivants les
414      différents types de virtualisation (standalone vs hosted, et
415      emulation vs virtualisation).
416
417 Hosted versus Standalone Virtualization
418 ---------------------------------------
419
420 - Hosted Virtualization
421
422   - Hosted VM Monitor (VMM) runs on top of native OS
423   - VMware WKS, Microsoft VirtualPC, QEMU/KVM, UML
424
425 - Standalone Virtualization
426
427   - VMM directly runs on bare hardware
428   - VMware ESX, IBM/VM, Xen
429
430 - OS run in a VM is named a Guest OS
431
432 .. note::
433
434    - hosted = hebergée
435
436    - guest = invité
437
438    - standalone = autonome, plus petit
439
440    - en général, le "hosted" n'accede pas réellement au hardware mais à des
441      périphériques émulés
442
443    - le cas kvm est ambigu: le kernel qui tourne en mode root
444      s'execute réellement sur le bare-hardware.
445
446 Hosted Virtualization
447 ---------------------
448
449 .. figure:: hosted.svg
450    :width: 100%
451
452 Example: VMware Workstation (1)
453 -------------------------------
454
455 .. figure:: vmware-wks.svg
456    :width: 100%
457
458 Example: VMware Workstation (2)
459 -------------------------------
460
461 - Hosted VM
462 - Unmodified OSes
463 - Specific device drivers
464 - x86 only
465 - Guest OS executed in user mode
466
467 Standalone Virtualization
468 -------------------------
469
470 .. figure:: standalone.svg
471    :width: 100%
472
473 Example: VMware ESX (1)
474 -----------------------
475
476 .. figure:: vmware-esx.svg
477    :width: 100%
478
479 Example: VMware ESX (2)
480 -----------------------
481
482 - Standalone VMM
483 - Supports unmodified OS binaries
484
485   - Configuration with appropriate device drivers
486
487 - x86 only
488 - No Intel-VT
489 - Guest OS
490 - runs in user mode
491
492 Process Level Virtualization: ABI Emulation
493 ===========================================
494
495 Process level ABI Emulation
496 ---------------------------
497
498 - Goal: execute binary applications of a given system **X** on the ABI of
499   another system *Y*
500
501 - Emulate system **X** ABI on top of system *Y* ABI
502
503   - Emulation done by application-level code
504
505 - System *Y* must provide services equivalent to those of system
506   **X** (file system, sockets, etc...)
507
508 - Example: **X** = Windows and *Y* = Linux
509
510 .. note::
511
512   - exemple du CreateFile() de windows qui serait émulé par un open()
513     sur un unix
514
515 Process Level (ABI) Emulators
516 -----------------------------
517
518 - Wine run Windows applications on POSIX-compliant operating
519   systems
520
521   - Windows API in userland
522   - Adobe Photoshop, Google Picasa, ...
523
524 - Cygwin: recompile POSIX applications so they can run under Windows
525
526   - Unix emulation on Windows
527   - POSIX library
528   - Bash shell + many Unix commands
529   - GNU development tool chain (gcc, gdb)
530   - X Window, GNOME, Apache, sshd, ...
531
532 .. note::
533
534    - **DEMO**: lancer un .exe avec wine64
535    - l'ABI dépend du système d'exploitation mais aussi de l'architecture.
536
537      - les appels systèmes sont différents entre linux et windows
538      - mais les appels systemes ne s'invoquent pas de la même manière
539        sur 2 architectures différentes. Par exemple, sur un x86, on
540        utilise un INT 0x80 (en fait SYSENTER maintenant), et les
541        arguments sont placés dans des registres particuliers
542
543    - google picasa for linux inclut une version embarquée de wine
544
545 Process Level Cross-architecture Emulators
546 ------------------------------------------
547
548 - Emulate the Operating System ABI
549
550   - Emulated OS and native OS are the same (ex: both are linux)
551   - Emulated arch is different than native architecture (ex: x86 and
552     powerpc)
553   - Note: we define what is "emulation" later in the presentation
554
555 - Example: qemu-user
556
557 .. code-block:: sh
558
559       $ gcc hello.c
560       $ ./a.out
561       hello
562       $ powerpc-linux-gnu-gcc -static hello.c
563       $ ./a.out
564       bash: ./a.out: cannot execute binary file
565       $ qemu-ppc ./a.out
566       hello
567
568 .. note::
569
570    - par exemple, vous récupérer une freebox ou un routeur basé sur du
571      mips ou arm, et vous voulez lancer et débugger une application.
572
573 Process Level Virtualization: virtual servers
574 =============================================
575
576 Virtual Servers (1)
577 -------------------
578
579 - Single OS kernel / Multiple resource instances
580
581   - can run several linux distributions on the same kernel
582
583 - Isolated kernel execution environments
584
585   - Root file system
586   - Network: Routing table, IP tables, interfaces...
587   - Process signals
588
589 - Solaris 10 Containers
590 - LXC, Linux-VServer, openVZ: namespaces and cgroups
591 - FreeBSD Jail
592
593 .. note::
594
595    - tous les processus sont vus par le kernel
596
597    - les processus ont des vues différentes du système d'exploitation et
598      sont cloisonnés. Ils n'ont pas conscience des domaines adjacents et
599      ont des vues différentes du système (FS, réseau, ...).
600
601    - Les namespaces de linux sont un bon exemple (lxc, openVZ).
602
603    - XXX reflechir à une demo... ?
604
605    - expliquer comment ça peut être implémenté dans le kernel: un
606      parametre supplémentaire pour chaque appel systeme
607
608    - dire que niveau sécurité, c'est pas encore ça pour cloisonner.
609
610    - voir dessin slide suivant
611
612    - signal -> table of process ?
613
614 Virtual Servers (2)
615 -------------------
616
617 .. figure:: virtual-servers.svg
618    :width: 100%
619
620 Virtual Servers (3)
621 -------------------
622
623 - Pro's
624
625   - CPU independent
626   - Lightweight
627
628     - Low memory footprint
629     - Low CPU overhead
630
631   - Scalable
632
633 - Con's
634
635   - No OS heterogeneity
636   - Single OS binary instance (common point of failure)
637
638 System Level Virtualization: Transparent Hardware Emulation
639 ===========================================================
640
641 Transparent Hardware Emulation (1)
642 ----------------------------------
643
644 - Run unmodified OS binaries
645
646 - Includes emulation of physical devices
647
648 - Cross ISA Emulation
649
650   - qemu-system
651
652 - Same ISA Emulation
653
654   - VirtualBox (Intel x86)
655
656 Transparent Hardware Emulation (2)
657 ----------------------------------
658
659 - Emulate machine **X** on top of machine *Y*
660
661 - Interpretation: read, decode, execute
662
663   - 1 instruction of **X** executed by N instructions of *Y*
664   - Huge slow down method
665
666 - Dynamic Binary Translation
667
668   - Convert blocs of **X** instructions in *Y* instructions
669   - Conversion is done once per basic block
670   - Advanced: dynamic optimization of 'hot' blocs
671
672 - The emulator is usually a standard application running on a native
673   OS
674
675 .. note::
676
677    - Expliquer comment un emulateur peut être implémenté, c'est un gros
678      switch/case, chaque instruction doit être parsée et son comportement
679      doit être émulé. L'émulateur doit conserver dans des variables
680      l'état des registres.
681
682    - Voilà pourquoi on en arrive à faire de la translation de blocs de
683      code. Attention, la translation dynamique ne se fait qu'à la volée,
684      c'est plus difficile de prendre le binaire, le convertir, et l'executer
685      (translation statique).
686
687      - https://en.wikipedia.org/wiki/Binary_translation
688      - Dynamic binary translation looks at a short sequence of
689        code—typically on the order of a single basic block—then
690        translates it and caches the resulting sequence.
691      - Code is only translated as it is discovered and when possible, and
692        branch instructions are made to point to already translated and
693        saved code (memoization).
694      - Apple Computer implemented a dynamic translating emulator for M68K
695        code in their PowerPC line of Macintoshes, which achieved a very
696        high level of reliability, performance and compatibility
697      - Intel: IA32 over Itanium
698
699 QEMU: Hosted Hardware Emulator
700 ------------------------------
701
702 - Cross ISA Emulation
703
704   - Emulate machine **X** on top of machine *Y*
705
706 - Interpretation + translation
707
708 - Intel x86, PowerPC, ARM, Mips, Sparc, ...
709
710 - Emulation of SMP architectures
711
712 - Emulates physical I/O devices
713
714   - Hard Disk drives, CD-ROM, network controllers, USB controllers, ...
715   - Synchronous emulation of device I/O operations
716
717 .. note::
718
719    - **DEMO**: lancer kid icarus avec mednafen
720    - ``mednafen -vdriver sdl -nes.xscale 4 -nes.yscale 4 ~/cours_ivan/cours_virt/Kid\ Icarus\ \(Europe\)\ \(Rev\ A\).zip``
721    - voir /usr/share/doc/mednafen/mednafen.html
722    - http://idoc64.free.fr/ASM/instruction.htm
723    - QSDZ = dir, ret=start, tab=select, OP=buttons
724    - Alt-D affiche le debugger
725    - addresse A6 diminue qd on perd des vies
726    - shift-W: write breakpoint, R pour run
727    - on peut essayer de mettre une grosse valeur:
728      Poke A6 30 1
729    - ne marche pas, car sature
730    - breakpoint à A6
731    - shift P (poke in rom): ED45 60 1 (on met un RTS)
732      c'est l'endroit qui sature
733    - Poke A6 30 1
734    - à l'adresse DB6C, c'est l'endroit où on stocke A6 après s'etre fait toucher
735      par un monstre::
736
737        LDA A6: charge la valeur
738        SEC: set carry
739        SBC: sub with carry
740        BCS: branch on carry set (on comprend que si ça vaut < 0, on met 0)
741
742    - 7E42 0 1 -> on met 0 sur le decrement des monstres
743
744 System Level Virtualization: Transparent Hardware Virtualization
745 ================================================================
746
747 Transparent Hardware Virtualization
748 -----------------------------------
749
750 - Guest and host architectures are the same
751
752 - Execute native/unmodified OS binary images
753
754 - Provide in each VM a complete simulation of hardware
755
756   - Full CPU instruction set
757   - Interrupts, exceptions
758   - Memory access and MMU
759   - I/O devices
760
761 - Share machine resources among multiple VMs
762
763 .. note::
764
765    - le slide décrit la problematique qui est la meme que pour l'émulation
766
767    - peut etre donner aussi les exemples style kqemu ou virtualbox
768      (modules accélération). Dire aussi que ça ne concerne toujours pas
769      les Intel-VT, dire que ça va plus vite que l'émulation
770
771    - share machine resource: exemple des pages memoires en copy-on-write
772
773 Full CPU Virtualization (1)
774 ---------------------------
775
776 - Present same functional CPU to all Guest OSes
777
778 - VMM manages a CPU context for each vCPU of each VM
779
780   - saved copy of CPU registers
781   - representation of software-emulated CPU context
782
783 - VMM shares physical CPUs among all vCPU of VMs
784
785   - VMM includes a VM scheduler
786
787     - round-robin
788     - priority-based
789
790 .. note::
791
792    - representation of software-emulated CPU context: exemple, savoir que
793      les IT sont masquées ou non.
794
795 Full CPU Virtualization (2)
796 ---------------------------
797
798 - Relationships between a VMM and VMs similar to relationships between
799   native OS and applications
800
801   - Guarantee mutual isolation between all VMs
802   - Protect VMM from all VMs
803
804 - Directly execute native binary images of Guest OS's in
805   non-privileged mode
806
807 - VMM emulates access to protected resources performed by Guest OSs
808
809 CPU Virtualization
810 ------------------
811
812 - Run each Guest OS in non-privileged mode
813
814 .. figure:: cpu-virt.svg
815    :width: 100%
816
817 "Hardware-Sensitive" Instructions
818 ---------------------------------
819
820 - Interact with protected hardware resources
821
822   - Privileged Instructions (cannot be executed in user mode)
823   - Critical Instructions (can be, but should not be executed by Guest OS)
824
825 - Must be detected and faked by VMM
826
827 - Dynamic Binary Translation of kernel code
828
829   - Done once, saved in Translation Cache
830   - Example: Vmware
831
832 .. note::
833
834    - instructions priviligées: ex, masquage des IT
835
836    - intruction critiques: ex, read de status flag, de CR3, ...
837
838 Privileged Instructions Virtualization
839 --------------------------------------
840
841 - Only allowed in supervisor mode
842
843   - Ex: **cli/sti** to mask/unmask interrupts on Intel x86
844
845 - When executed in non-privileged mode
846
847   - CPU automatically detects a privilege violation
848   - Triggers a “privilege-violation” exception
849
850 - Caught by VMM which fakes the expected effect of the privileged
851   instruction
852
853   - Ex: **cli/sti**
854
855     - VMM does not mask/unmask CPU interrupts
856     - records « interrupt mask status » in context of VM
857
858 Critical Instructions Virtualization (1)
859 ----------------------------------------
860
861 - Hardware-sensitive instructions
862
863 - Ex: Intel IA-32 pushf/popf::
864
865     pushf /* save EFLAG reg. to stack */
866     cli   /* mask interrupts => clear EFLAG.IF */
867     ...
868     popf /* restore EFLAG reg. => unmask interrupts */
869
870 - When executed in non-privileged mode
871
872   - The cli instruction triggers an exception caught by VMM => VMM
873     record interrupts masked for current VM
874
875   - But no exception for popf => VMM not aware of Guest OS action
876     (unmask interrupts)
877
878 .. note::
879
880    - premier pb: pushf est autorisé et met toujours en pile des flags
881      disant que les IT sont autorisées
882    - popf doit aussi être intercepté car il faut mettre à jour le
883      statut des IT
884
885 Critical Instructions Virtualization (2)
886 ----------------------------------------
887
888 - Must be detected and emulated by VMM
889
890 - VMM dynamically analyses Guest OS binary code to find critical instructions
891
892 - VMM replaces critical instructions by a « trap » instruction to enter the VMM
893
894 - VMM emulates expected effect of critical instruction, if any.
895
896 .. note::
897
898    - **PAUSE**
899    - XXX est-ce que la translation doit être faite uniquement sur le
900      code qui a vocation à tourner en ring 0 ?
901
902 Full Memory Virtualization
903 --------------------------
904
905 - CPU include a Memory Management Unit (MMU)
906
907   - Isolated memory addressing spaces
908   - Independant of underlying physical memory layout
909   - Run mutually protected applications in parallel
910
911 - Virtual Memory managed by OS kernel
912
913   - Provides a virtual address space to each process
914
915     - 4 GB on most 32-bit architectures (Intel x86, PowerPC)
916
917   - Manages virtual page → physical page mappings
918   - Manages « swap » space to extend physical memory
919
920 .. note::
921
922    - la MMU est un composant hardware
923
924 Reminder about MMU (1)
925 ----------------------
926
927 - Here is a minimal code example:
928
929   .. code-block:: sh
930
931     # a program that takes x and y in memory, and
932     # computes the sum
933     mov    %0x200000,eax        # retrieve <x> in eax
934     mov    %0x200004,ebx        # retrieve <y> in ebx
935     add    ebx,eax              # compute x+y in eax
936     mov    eax,%0x200008        # save the result in memory
937
938 - This program can run on one cpu
939 - If the addresses are physical, it is not possible to run multiple
940   instance of this program as they would modify the same memory
941
942 .. note::
943
944    - une mauvaise solution est de modifier le binaire à chaque execution
945
946 Reminder about MMU (2)
947 ----------------------
948
949 .. figure:: mmu-slide1.svg
950    :width: 70%
951
952 Reminder about MMU (3)
953 ----------------------
954
955 .. figure:: mmu-slide2.svg
956    :width: 95%
957
958 Reminder about MMU (4): Intel x86 MMU
959 -------------------------------------
960
961 .. figure:: mmu2.svg
962    :width: 100%
963
964 Memory Virtualization (1)
965 -------------------------
966
967 .. figure:: mmu-slide3.svg
968    :width: 70%
969
970 Memory Virtualization (2)
971 -------------------------
972
973 - Machine Physical Memory
974
975   - Physical memory available on the machine
976
977 - Guest OS Physical Memory
978
979   - Part of machine memory assigned to a VM by VMM
980
981   - ∑ Guest Physical Memory can be > Machine Memory
982
983     - VMM uses « swap » space
984
985 - Guest OS Virtual Memory
986
987   - Guest OS manages virtual address spaces of its processes
988
989 Memory Virtualization (3)
990 -------------------------
991
992 - Guest OS manages Guest Physical Pages
993
994   - Manages MMU with its own page entries
995   - Translates Virtual Addresses into Guest Physical Addresses (GPA)
996
997 - VMM transparently manages Machine Physical Pages
998
999   - Guest Physical Address ≠ Machine Physical Address
1000   - VMM dynamically translates Guest Physical Pages into Machine
1001     Physical Pages
1002
1003 Memory Virtualization (4)
1004 -------------------------
1005
1006 .. figure:: mmu-slide4.svg
1007    :width: 95%
1008
1009 .. note::
1010
1011    - passer en dynamique, expliquer comment sont fait les
1012      translations, parler du tlb
1013      montrer l'ordre chronologique des choses
1014    - on dézoome un coup, en statique
1015      virtual memory vs VM memory vs host physical memory
1016      pas de mmu dans ce cas
1017    - montrer en dynamique avec une seule MMU comment
1018      l'hyperviseur configure la MMU
1019
1020    utiliser les memes couleurs pour les types de memoire
1021    on va détourner la mmu pour faire la translation qui nous
1022    va bien
1023
1024    - mettre un nombre dans CR3
1025    - mettre des barres verticales dans les page tables
1026    - TLB sous la forme d'un tableau avec des lignes vides
1027    - find -> get
1028    - mmu plus large
1029    - zoom sur les PTE à droite
1030    - faire apparaitre les adresses
1031    - dissocier les valeurs des adresses virtuelles et physiques, mettre
1032      des couleurs différentes pour ces adresses
1033    - voir si on ne peut pas faire apparaitre que les 20 bits significatifs
1034      et pas les 12 bits d'offset qd on parle des adresses
1035
1036    - Lorsque le guest accede à CR3 (ou un PTE), cela génère une faute,
1037      gérée par le VMM. Le VMM va translater l'adresse donnée par l'OS de
1038      la VM et remplir le registre CR3 avec l'adresse physique
1039      correspondant à la zone utilisée par la VM pour y stocker ses tables
1040      de pages. Il faut que tout accès à cette table de page génère une
1041      faute pour que le VMM soit notifié de tout changement et puisse
1042      configurer la MMU réelle en conséquence (en faisant la translation
1043      d'adresse).  (slide 47)
1044
1045    - La lecture de CR3 ne génère pas de TRAP, il faut donc faire comme
1046      pour les pushf et popf, c'est à dire de la translation de code.
1047
1048 Memory Virtualization (5)
1049 -------------------------
1050
1051 - VMM maintains Shadow Page Tables
1052
1053   - Copies of Guest OS translation tables
1054
1055 - VMM catches updates operations of translation tables performed by a
1056   Guest OS
1057
1058   - RW-protect all guest OS page tables
1059   - Emulates operation in shadow page table
1060   - Updates effective MMU page table entry, if needed
1061
1062 Memory Virtualization (6)
1063 -------------------------
1064
1065 - PTE entries can be tagged with a context ID
1066
1067   - Avoids to flush TLB when switching current address space upon
1068     scheduling of a new process
1069
1070   - usually PTE tag = OS process identifier
1071
1072 - Processes of different Guest OSes can be assigned the same Process
1073   ID
1074
1075   - VMM must flush TLB when switching VMs
1076
1077 Memory Virtualization (7)
1078 -------------------------
1079
1080 - VMM must respect Guest OS virtual page faults
1081
1082   - Not map virtual pages unmapped by Guest OS
1083   - When Guest OS unmaps a virtual page:
1084
1085     - VMM must delete the associated real-page/physical page
1086       mapping, if any.
1087
1088 - Conversely, VMM can transparently:
1089
1090   - Introduce & resolve real-page faults for Guest OSes
1091   - Share physical pages between Guest OS's
1092
1093     - Pages with same content's (e.g. zero-ed pages)
1094
1095 Memory Virtualization (8)
1096 -------------------------
1097
1098 - VMM can swap real pages of a VM
1099
1100   - on "swap" space managed by VMM
1101
1102 - VMM can dynamically distribute physical memory among VMs
1103
1104   - Needs a specific support in Guest OS (Linux module)
1105
1106   - VMM asks Guest OS to release memory
1107
1108     - Guest OS self-allocates real pages
1109     - no more available for normal kernel allocation service
1110     - VMM assigns same amount of physical pages to other VM's
1111
1112 .. note::
1113
1114    - ballooning: un module kernel est dans les guests, il communique
1115      avec le VMM. Si le VMM a besoin de mémoire physique pour une
1116      autre VM, il peut demander au module d'allouer de la mémoire, qui
1117      est alors perdue pour les autres services. Cette mémoire est
1118      "redonnée" au VMM.
1119    - besoin de précisions et sources là dessus
1120
1121 System Level Virtualization: Paravirtualization
1122 ===============================================
1123
1124 CPU Paravirtualization
1125 ----------------------
1126
1127 - Still run each Guest OS in non-privileged mode, but with minimal
1128   virtualization overhead
1129
1130 - OS adaptation to avoid binary translation overhead
1131
1132   - Remove Hardware-Sensitive Instructions, use fast VMM system calls
1133   - Minimize/avoid usage of Privileged Instructions
1134
1135 - Only affect Machine/CPU dependant part of OS
1136
1137 - OS portage on new architecture with same CPU, without system ISA
1138
1139 - Examples: Xen legacy, User Mode Linux (UML), CoLinux
1140
1141 I/O Paravirtualization
1142 ----------------------
1143
1144 - Multiplexing VMM physical devices among VMs
1145
1146   - Front-end driver in Guest OS
1147   - Back-end driver in VMM
1148   - Virtual ethernet, virtual disks
1149
1150 - Fast virtual devices for VM to VM communications
1151
1152   - Example: vmxnet3
1153
1154 - Data transfer through syscalls, shmem, rings, ...
1155 - Pros: scalability, VM migration
1156
1157 Virtual I/O Devices
1158 -------------------
1159
1160 .. figure:: virt-devices.svg
1161    :width: 100%
1162
1163 Paravirtualization Example: Xen Legacy
1164 --------------------------------------
1165
1166 - Objectives
1167
1168   - Scalable
1169   - Share resources of Server machines
1170
1171 - Intel IA-32, x86-64, ARM, ...
1172
1173 - Special first Guest OS called Domain 0
1174
1175   - Run in privileged mode
1176   - Have access (and manages) all physical devices
1177   - Modified version of Linux, FreeBSD
1178
1179 .. note::
1180
1181    XXX vérifier le coup de domain 0
1182
1183 System Level Virtualization: Hardware-Assisted Virtualization
1184 =============================================================
1185
1186 Hardware Assisted Virtualization (1)
1187 ------------------------------------
1188
1189 - Support of Virtualization in Hardware
1190 - Run unmodified OS binaries
1191 - With minimal virtualization overhead
1192 - Simplify VMM development
1193 - Examples
1194
1195   - KVM
1196   - VMware
1197
1198 Hardware Assisted Virtualization (2)
1199 ------------------------------------
1200
1201 - CPU virtualization
1202
1203   - AMD-V
1204   - Intel VT-x (x86), Intel VT-i (Itanium) architectures
1205   - ARM Cortex-A15
1206
1207 - MMU virtualization
1208
1209   - Intel Extended Page Tables (EPT)
1210   - AMD Nested Page Tables (NPT)
1211
1212 Hardware Assisted Virtualization (3)
1213 ------------------------------------
1214
1215 - Directed I/O virtualization
1216
1217   - IO-MMU (Intel VT-d)
1218
1219 - I/O Device virtualization
1220
1221   - Self-Virtualizing devices
1222   - Single Root I/O Virtualization and Sharing Specification (SR-IOV)
1223   - Extensions to PCIe (PCI Express) Bus standard
1224
1225 Intel VT-x Architecture
1226 -----------------------
1227
1228 - Support unmodified Guest OS with no need for paravirtualization
1229   and/or binary code translation
1230
1231 - Simplify VMM tasks & improve VMM performances
1232
1233 - Minimize VMM memory footprint
1234
1235   - Suppress shadowing of Guest OS page tables
1236
1237 - Enable Guest OS to directly manage I/O devices
1238
1239   - Without performance lost
1240   - While enforcing VM isolation and mutual protection
1241
1242 Intel VT-x Architecture Overview
1243 --------------------------------
1244
1245 .. figure:: vt-x.svg
1246    :width: 100%
1247
1248 Intel VT-x CPU Virtualization (1)
1249 ---------------------------------
1250
1251 - Virtual Machine eXtension (VMX)
1252
1253   - Two new meta-modes of CPU operation
1254
1255 - VMX root mode
1256
1257   - Behaviour similar to IA-32 without VT
1258   - Intended for VMM execution
1259
1260 - VMX non-root mode
1261
1262   - Alternative IA-32 execution environment
1263   - Controlled by a VMM
1264   - Designed to run unchanged Guest OS in a VM
1265
1266 - Both modes support rings 0-3 privilege levels
1267
1268   - Allow VMM to use several privilege levels
1269
1270 Intel VT-x CPU Virtualization (2)
1271 ---------------------------------
1272
1273 - Two additional CPU mode transitions
1274
1275 - From VMX root-mode to VMX non-root mode
1276
1277   - Named VM Enter (VMLaunch instruction)
1278
1279 - From VMX non-root mode to VMX root mode
1280
1281   - Named VM Exit (event)
1282
1283 - VM entries & VM exits use a new data structure
1284
1285   - Virtual Machine Control Structure (VMCS) per VM CPU (vCPU)
1286   - Referenced with a memory physical address
1287   - Format and layout hidden
1288   - New VT-x instructions to access a VMCS
1289
1290 Intel VT-x CPU Virtualization (3)
1291 ---------------------------------
1292
1293 - Guest State Area
1294
1295   - Saved value of registers before beeing changed by
1296     VM Exits (e.g. Segment Registers, CR3, IDTR)
1297
1298   - Hidden CPU state (e.g., CPU Interruptibility State)
1299
1300 - Host State Area
1301
1302 - VM Control Fields
1303
1304   - Interrupt Virtualization
1305   - Exceptions bitmaps
1306   - I/O bitmaps
1307   - Model Specific Register R/W bitmaps
1308   - Execution rights for CPU Privileged Instructions
1309
1310 .. note::
1311
1312    - host state area est l'endroit ou l'état du processeur du VMM est
1313      stocké. Il est restauré sur VMExit.
1314
1315    - Switching from root mode to non-root mode is called "VM entry", the
1316      switch back is "VM exit". The VMCS includes a guest and host state
1317      area which is saved/restored at VM entry and exit. Most importantly,
1318      the VMCS controls which guest operations will cause VM exits.
1319
1320      The VMCS provides fairly fine-grained control over what the guests
1321      can and can't do. For example, a hypervisor can allow a guest to
1322      write certain bits in shadowed control registers, but not
1323      others. This enables efficient virtualization in cases where guests
1324      can be allowed to write control bits without disrupting the
1325      hypervisor, while preventing them from altering control bits over
1326      which the hypervisor needs to retain full control. The VMCS also
1327      provides control over interrupt delivery and exceptions.
1328
1329      Whenever an instruction or event causes a VM exit, the VMCS contains
1330      information about the exit reason, often with accompanying
1331      detail. For example, if a write to the CR0 register causes an exit,
1332      the offending instruction is recorded, along with the fact that a
1333      write access to a control register caused the exit, and information
1334      about source and destination register. Thus the hypervisor can
1335      efficiently handle the condition without needing advanced techniques
1336      such as CSAM and PATM described above.
1337
1338      VT-x inherently avoids several of the problems which software
1339      virtualization faces. The guest has its own completely separate
1340      address space not shared with the hypervisor, which eliminates
1341      potential clashes. Additionally, guest OS kernel code runs at
1342      privilege ring 0 in VMX non-root mode, obviating the problems by
1343      running ring 0 code at less privileged levels. For example the
1344      SYSENTER instruction can transition to ring 0 without causing
1345      problems. Naturally, even at ring 0 in VMX non-root mode, any I/O
1346      access by guest code still causes a VM exit, allowing for device
1347      emulation.
1348
1349    - Tout l'état du processur visible est sauvé dans ou restauré depuis
1350      la memoire:
1351
1352      - tous les registres, meme ceux de controle
1353      - interruptability state
1354
1355    - La VMCS contient ce que la VM a le droit de faire
1356
1357    - IO bitmaps = bitfield qui dit quels ports IO (instructions in et
1358      out) sont autorisés.
1359
1360 Intel VT-x Interrupt Virtualization
1361 -----------------------------------
1362
1363 - VMCS External Interrupt Exiting
1364
1365   - All external interrupts cause VM Exit
1366   - Guest OS cannot mask external interrupts when executing Interrupt
1367     Masking instructions
1368
1369 - VMCS Interrupt Window Exiting
1370
1371   - VM Exit occurs whenever Guest OS ready to serve external interrupts
1372
1373 - Used by VMM to control VM interrupts
1374
1375 .. note::
1376
1377    - la window permet de délayer l'interruption hardware (et donc le vm
1378      exit) tant que le guest n'a pas demasqué ses IT.
1379
1380    - VT-x also includes an interrupt-window exiting VM-execution
1381      control. When this control is set to 1, a VM exit occurs whenever
1382      guest software is ready to receive interrupts. A VMM can set this
1383      control when it has a virtual interrupt to deliver to a
1384      guest. Similarly, VT-i includes a PAL service that a VMM can use to
1385      register that it has a virtual interrupt pending. When guest
1386      software is ready to receive such an interrupt, the service
1387      transfers control to the VMM via the new virtual external interrupt
1388      vector.
1389
1390 Intel VT-x MMU Virtualization
1391 -----------------------------
1392
1393 - Extended Page Tables (EPT)
1394
1395   - Second level of Page Tables in MMU
1396   - Translate Guest OS Physical Address into Machine Physical Address
1397   - Controlled by VMM
1398
1399 - Virtual Processor IDentifier (VPID)
1400
1401   - Used to tag TLB entries
1402   - Avoid to flush TLB upon VM switch
1403
1404 Virtual Memory Virtualization
1405 -----------------------------
1406
1407 .. figure:: vt-x-mem.svg
1408    :width: 100%
1409
1410 Intel VT-x Extended Page Tables (1)
1411 -----------------------------------
1412
1413 - VMM controls Extended Page Tables
1414
1415 - EPT used in VMX non-root operation
1416
1417   - Activated on VM Enter
1418   - Desactivated on VM exit
1419
1420 - EPTP register points to Extended Page Tables
1421
1422   - Instanciated by VMM
1423   - Saved in VMCS
1424   - Loaded from VMCS on VM entry
1425
1426
1427 Intel VT-x Extended Page Tables (2)
1428 -----------------------------------
1429
1430 .. figure:: vt-x-mmu.svg
1431    :width: 100%
1432
1433 .. note::
1434
1435    - le TLB contient cache les 2 translations VA->GPA et GPA->MPA
1436
1437    - There is only one downside: nested paging or EPT makes the virtual
1438      to real physical address translation a lot more complex if the TLB
1439      does not have the right entry. For each step we take in the blue
1440      area, we need to do all the steps in the orange area. Thus, four
1441      table searches in the "native situation" have become 16 searches
1442      (for each of the four blue steps, four orange steps).
1443
1444      http://www.anandtech.com/show/2480/10
1445
1446 TLB Flush Issue
1447 ---------------
1448
1449 .. figure:: tlb-flush-issue.svg
1450    :width: 100%
1451
1452 .. note::
1453
1454    - 2 processes dans dess VMs différentes peuvent utiliser la même
1455      adresse virtuelle
1456
1457 Intel VT-x Virtual Processor Identifier
1458 ---------------------------------------
1459
1460 - 16-bit VPID used to tag TLB entries
1461
1462   - Enabled by VMM in VMCS
1463   - Unique VPID is assigned by VMM to each VM
1464   - VPID 0 reserved for VMM
1465
1466 - Current VPID is 0x0000 when
1467
1468   - Outside VMX operation
1469   - In VMX root mode operation
1470   - In VMX non-root mode if VPID disabled in VMCS
1471
1472 - VPID loaded from VMCS on VM Enter
1473
1474 .. note::
1475
1476    - faire la demo de Windows dans un KVM, on peut parcourir le
1477      gestionnaire de périphérique pour voir que ce n'est pas du tout ce
1478      que j'ai sur mon PC. En plus ça fait bien la transition avec la
1479      virtualisation DMA.
1480
1481 .. Intel Virtualization Technology for Directed I/O
1482    ================================================
1483
1484 Intel VT-d Principles
1485 ---------------------
1486
1487 - Enable Guest OS to directly manage physical I/O devices
1488
1489   - Guest I/O operations bypass VMM
1490
1491 - In full transparent mode
1492
1493   - Use native device drivers of Guest OS
1494   - Guest OS unaware of underlying physical memory virtualization
1495
1496 - Enforce isolation between Guest VMs
1497
1498   - Guest OS can only access I/O ressources (ports, PCI devices) assigned to it
1499   - PCI I/O device can only perform DMA to machine physical pages assigned to
1500     Guest VM owning that device.
1501
1502 Intel Directed IO
1503 -----------------
1504
1505 .. figure:: dma-virt.svg
1506    :width: 100%
1507
1508 DMA Principles
1509 --------------
1510
1511 .. figure:: dma.svg
1512    :width: 100%
1513
1514 DMA Virtualization Issue
1515 ------------------------
1516
1517 - Guest OS driver setup I/O registers of device with Guest Physical
1518   Address of I/O buffers
1519
1520 - Guest Physical Address must be translated into its corresponding
1521   Machine Physical Address when used for DMA operations by device
1522
1523 - GPA -> MPA translation cannot be done by VMM
1524
1525   - VMM cannot catch device-specific driver operations to setup I/O
1526     buffers addresses
1527
1528 - GPA -> MPA translation done by IOMMU on the Bus Controller
1529
1530 Intel VT-d Protection Domains
1531 -----------------------------
1532
1533 - Intel VT-d provides DMA Protection Domain
1534
1535   - Extension of IOMMU translation mechanism
1536   - Isolated context of a subset of the Machine Physical Memory
1537   - Corresponds to the portion of Machine Physical Memory allocated to
1538     a VM
1539
1540 - I/O devices associated by VMM with a DMA Protection Domain
1541
1542   - Achieves DMA isolation by restricting memory access of I/O devices
1543     through DMA address translation
1544
1545 Intel VT-d DMA Translation
1546 --------------------------
1547
1548 - VT-d hardware treats address specified in DMA request as DMA Virtual
1549   Address (DVA)
1550
1551 - DVA = GPA of the VM to which the I/O device is assigned
1552
1553 - VT-d translates the DVA into its corresponding Machine Physical
1554   Address
1555
1556 - Support of multiple Protection Domains
1557
1558   - DVA to MPA translation table per Protection Domain
1559   - Must identify the device issuing a DMA request
1560
1561 VT-d PCI Express North Bridge
1562 -----------------------------
1563
1564 .. figure:: vt-d.svg
1565    :width: 100%
1566
1567 PCI DMA Requester Identification
1568 --------------------------------
1569
1570 - Mapping between PCI Device and Protection Domains
1571 - 16-bit PCI DMA Requester Identifier
1572
1573   .. figure:: dma-req-id.svg
1574    :width: 80%
1575
1576 - Assigned by PCI configuration software
1577 - Bus # indexes Bus Context Table in Root Context Table
1578 - (Device #, Function #) indexes Device Protection Domain in Bus
1579   Context Table
1580
1581 Device / Protection Domain Mapping
1582 ----------------------------------
1583
1584 .. figure:: device-domain-mapping.svg
1585    :width: 100%
1586
1587 Virtual DMA Address Translation
1588 -------------------------------
1589
1590 - DVA ↔ MPA Page Tables similar to IA-32 processor Page Tables
1591
1592 - 4KB or larger page size granularity
1593
1594 - Read/Write permissions
1595
1596 - Protection Domains managed by VMM
1597
1598   - Initialized at VM creation time
1599   - With same translations of the VM Extended Page Table
1600
1601 VMM and Directed I/O
1602 --------------------
1603
1604 - Unplugs assigned PCI device from VMM driver and reset it
1605
1606 - Associates PCI device with VT-d Protection Domain of the Guest VM
1607
1608 - Maps device memory BARs in Guest VM physical space
1609
1610 - Arranges for OS of Guest VM to probe PCI device(s) assigned to it
1611
1612 - Handles device interrupts and redirect them to Guest VM
1613
1614 - Reset assigned PCI device upon Guest VM shut down
1615
1616 .. Device Virtualization
1617    =====================
1618
1619 Device Virtualization Principles
1620 --------------------------------
1621
1622 - Share I/O device among multiple Guest VMs
1623
1624   - With no performance lost
1625   - While enforcing VM isolation and protection
1626
1627 - Move device virtualization from the VMM to the device itself
1628
1629 - PCIe extension
1630
1631 - PF/VF requires support from the device
1632
1633 Ethernet Device Virtual Functions
1634 ---------------------------------
1635
1636 .. figure:: ethernet-dev-virt.svg
1637
1638 Single Root I/O Virtualization
1639 ------------------------------
1640
1641 - SR-IOV capable PCI Device can be partitionned into multiple Virtual
1642   Functions
1643
1644 - SR-IOV Device appears in PCI configuration space as multiple PCI
1645   Virtual Functions
1646
1647 - Virtual Functions are "lightweight" PCI functions including
1648
1649   - PCI probing capabilities
1650   - DMA streams
1651   - Interrupts
1652
1653 - Requires VT-d for DMA virtualization
1654
1655 - Virtual Functions have no configuration resources
1656
1657 SR-IOV Device Management
1658 ------------------------
1659
1660 - VMM manages the physical PCI device
1661
1662 - VMM creates a PCI Virtual Function for each VM
1663
1664   - Includes it into VM PCI configuration space to be probed by OS kernel
1665     of Guest VM
1666   - Associates VF with VT-d Protection Domain of the Guest VM
1667
1668 - VMM programs the sharing of physical devices ressources between VFs
1669
1670 - Virtual Functions managed by specific VF-aware drivers in kernel of
1671   Guest OS (kind of Para-Virtualization)
1672
1673 Intel Niantic Virtual Functions (1)
1674 -----------------------------------
1675
1676 .. figure:: eth-sr-iov.svg
1677    :width: 80%
1678
1679 Intel Niantic Virtual Functions (2)
1680 -----------------------------------
1681
1682 - Virtual Devices on Intel Niantic (10GB) NICs
1683
1684 - Layer-2 packet filtering based on destination MAC address
1685
1686 - Filters multiple unicast MAC addresses / VLAN identifiers
1687
1688 - Can duplicate Broadcast / Multicast packets for all VFs
1689
1690 - Multiple RX queues per VF (RSS)
1691
1692 - Load balancing between TX packets sent by VFs
1693
1694 - Anti-Spoofing mechanism on transmission
1695
1696   - Source MAC address
1697   - VLAN identifier
1698
1699 Pro/Cons of I/O hardware virtualization
1700 ---------------------------------------
1701
1702 - Improves I/O performances on physical devices directly managed by Guest VMs
1703
1704 - Only useful in specific configurations
1705
1706 - PCI device Virtual Functions intended to scale, but require locking
1707   of total VM physical memory into machine physical memory
1708
1709 - Not compatible with transparent VM migration
1710
1711 Conclusion / Evolution of Virtualization
1712 ========================================
1713
1714 Conclusion
1715 ----------
1716
1717 - Emulation : slow, multi-arch, simulates ISA (full machine) or ABI
1718   (process level)
1719 - Accelerated emulation : faster, code is executed natively, overhead
1720   for privilegied actions
1721 - Virtual servers : fast and scalable, but same OS and one kernel
1722 - Paravirtualization : fast, needs a modified OS (or drivers)
1723 - HW-assisted virtualization : solves most of the issues
1724
1725 .. note::
1726
1727    - needs a modified OS is not true for devices
1728
1729 Evolutions of Virtualization
1730 ----------------------------
1731
1732 - Cloud computing
1733
1734   - Big amount of data
1735   - Virtualization brings flexibility to data center
1736
1737 - Operating systems in browsers ?
1738
1739   - State of OS is stored remotely
1740
1741 - Virtualization on desktops and small devices
1742
1743   - Security (isolates work and personal area)
1744
1745 Thanks
1746 ------
1747
1748 - Any question ?