cs152/252 spring 2018 computer architecture and...

39
WU UCB CS152/252 SP18 CS152/252 Spring 2018 Computer Architecture and Engineering Graduate Computer Architecture Lecture 22: Virtual Machines Lisa Wu, Krste Asanovic http://inst.eecs.berkeley.edu/~cs152/sp18

Upload: others

Post on 14-Mar-2020

18 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

WU UCB CS152/252 SP18

CS152/252 Spring 2018Computer Architecture and Engineering

Graduate Computer Architecture

Lecture 22:Virtual Machines

Lisa Wu, Krste Asanovichttp://inst.eecs.berkeley.edu/~cs152/sp18

Page 2: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

Outline

§ WhatareVirtualMachinesandwhydoweneedthem?

§ TypesofVirtualMachine-User-level- System-level

§ Techniquesforimplementingallorpartsofanon-nativeISAonahostmachine:- Interpreter- Staticbinarytranslation- Dynamicbinarytranslation- Hardwareemulation

2

Page 3: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

WU UCB CS152/252 SP18

A Computer System Abstraction

3

Page 4: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

WU UCB CS152/252 SP18

What are Virtual Machines (VMs)?

4

“Virtual Machines (VMs) eliminate real machine constraints and enable a much higher degree of portability and flexibility.”

“Virtual Machines: Architectures, Implementations and Applications”, J. E. Smith and Ravi Nair, Morgan Kaufmann Publishers, 2004

“A virtual machine may have an operating system, instruction set, or both, that differ from those implemented on the underlying real hardware.”

“A virtual machine is implemented by adding software to an execution platform to give it the appearance of a different platform or for that matter, to give the appearance of multiple platforms.”

Page 5: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

TypesofVirtualMachine(VM)§ User/ProcessVirtualMachinesrunasingleapplicationaccordingtosomestandardapplicationbinaryinterface(ABI).- ExampleuserABIsincludeWin32forwindowsandJavaVirtualMachine(JVM)

§ (Operating)SystemVirtualMachines provideacompletesystem-levelenvironment- E.g.,IBMVM/370,VMwareESXServer,andXen- SinglecomputerrunsmultipleVMs,andcansupportamultiple,differentOSes- Onconventionalplatform,singleOS“owns”allHWresources- WithaVM,multipleOSes allshareHWresources

§ UnderlyingHWplatformiscalledthehost,whereitsresourcesusedtorunguestVMs(userand/orsystem)

5

Page 6: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

WU UCB CS152/252 SP18

User(Process) Virtual Machines

6

http://www.ittc.ku.edu/~kulkarni/teaching/EECS768/slides/chapter1.pdf“Virtual Machines: Architectures, Implementations and Applications”, J. E. Smith and Ravi Nair, Morgan Kaufmann Publishers, 2004

Page 7: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

WU UCB CS152/252 SP18

System Virtual Machines

7

“Virtual Machines: Architectures, Implementations and Applications”, J. E. Smith and Ravi Nair, Morgan Kaufmann Publishers, 2004

Page 8: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

SoftwareApplications

§ Howisasoftwareapplicationencoded?-Whatareyougettingwhenyoubuyasoftwareapplication?

-Whatmachineswillitworkon?-Whodoyoublameifitdoesn’twork,i.e.,whatcontract(s)wereviolated?

8

Page 9: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

WU UCB CS152/252 SP18

Interoperability

9

“Virtual Machines: Architectures, Implementations and Applications”, J. E. Smith and Ravi Nair, Morgan Kaufmann Publishers, 2004

Page 10: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

UserVirtualMachine=ISA+EnvironmentISAalonenotsufficienttowriteusefulprograms,needI/Otoo!§ DirectaccesstomemorymappedI/Oviaload/storeinstructionsproblematic- time-sharedsystems- portability

§ Operatingsystem usuallyresponsibleforI/O- sharingdevicesandmanagingsecurity- hidingdifferenttypesofhardware(e.g.,EIDEvs.SCSIdisks)

§ ISAcommunicateswithoperatingsystemthroughsomestandardmechanism,i.e.,syscall instructions- exampleconventiontoopenfile:addi x1, x0, 27 # 27 is code for file openaddu x2, x0, rfname # x2 points to filename string

syscall # cause trap into OS# On return from syscall, x1 holds file descriptor

10

Page 11: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

WU UCB CS152/252 SP1811

System Interfaces“Virtual Machines: Architectures, Implementations and Applications”, J. E. Smith and Ravi Nair, Morgan Kaufmann Publishers, 2004

Page 12: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

ApplicationBinaryInterface(ABI)

§ TheABIisaspecificationofthebinaryformatusedtoencodeprogramsforavirtualmachine,encodesprogramtext(instructions)andinitialvaluesofsomedatasegments

§ Virtualmachinespecificationsinclude-whatstateisavailableatprocesscreation-whichinstructionsareavailable(theISA)-whatsystemcallsarepossible(I/O,ortheenvironment)

§ Operatingsystemimplementsthevirtualmachine- atprocessstartup,OSreadsthebinaryprogram,createsanenvironmentforit,thenbeginstoexecutethecode,handlingtrapsforI/Ocalls,emulation,etc.

12

Page 13: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

OSCanSupportMultipleUserVMs

§ Virtualmachinefeatureschangeovertimewithnewversionsofoperatingsystem- newISAinstructionsadded- newtypesofI/Oareadded(e.g.,asynchronousfileI/O)

§ CommontoprovidebackwardscompatibilitysooldbinariesrunonnewOS- SunOS5(SystemVRelease4Unix,Solaris)canrunbinariescompiledforSunOS4(BSD-styleUnix)

-Windows98runsMS-DOSprograms§ IfABIneedsinstructionsnotsupportedbynativehardware,OScanprovideinsoftware

13

Page 14: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

ISAImplementationsPartlyinSoftware

§ OftengoodideatoimplementpartofISAinsoftware:§ ExpensivebutrarelyusedinstructionscancausetraptoOSemulationroutine:- e.g.,decimalarithmeticinstructionsinMicroVaximplementationofVAXISA

§ Infrequentbutdifficultoperandvaluescancausetrap- e.g.,IEEEfloating-pointdenormals causetrapsinmanyfloating-pointunitimplementations

§ Oldmachinecantrapunusedopcodes,allowsbinariesfornewISAtorunonoldhardware- e.g.,SunSPARCv8addedintegermultiplyinstructions,olderv7CPUstrapandemulate

14

Page 15: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

SupportingNon-NativeISAs§ RunprogramsforoneISAonhardwarewithdifferentISA§ SoftwareInterpreter(OSsoftwareinterpretsinstructionsatrun-time)- E.g.,OS9forPowerPCMacshadinterpreterfor68000code

§ BinaryTranslation(convertatinstalland/orloadtime)- IBMAS/400tomodifiedPowerPCcores- DECtoolsforVAX->MIPS->Alpha

§ DynamicTranslation(non-nativeISAtonativeISAatruntime)- Sun’sHotSpot JavaJIT(just-in-time)compiler- Transmeta Crusoe,x86->VLIWcodemorphing- OSXforIntelMacshasdynamicbinarytranslatorforPowerPC(Rosetta)

§ Run-timeHardwareEmulation- IBM360hadoptionalIBM1401emulatorinmicrocode- IntelItaniumconvertsx86tonativeVLIW(twosoftware-visibleISAs)- ARMcoressupport32-bitARM,16-bitThumb,andJVM(threesoftware-visibleISAs!)

15

Page 16: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

SoftwareInterpreter

16

§ Fetchanddecodeoneinstructionatatimeinsoftware

MemoryimageofguestVMlivesinhost

interpreterdatamemory

InterpreterData

InterpreterCode

InterpreterStack

while(!stop){inst=Code[PC];PC+=4;execute(inst);}

fetch-decodeloop

GuestISACode

GuestISAData

ExecutableonDisk

GuestISACode

GuestISAData

GuestStack

Loadintointerpreterprocessmemory

Page 17: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

SoftwareInterpreter

§ Easytocode,smallcodefootprint§ Slow,approximately100xslowerthannativeexecutionforRISCISAhostedonRISCISA

§ Problemistimetakentodecodeinstructions- fetchinstructionfrommemory- switchtablestodecodeopcodes- extractregisterspecifiersusingbitshifts- accessregisterfiledatastructure- executeoperation- returntomainfetchloop

17

Page 18: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

BinaryTranslation

§ EachguestISAinstructiontranslatesintosomesetofhost(ornative)ISAinstructions

§ Insteadofdynamicallyfetchinganddecodinginstructionsatrun-time,translateentirebinaryprogramandsaveresultasnewnativeISAexecutable

§ Removesinterpretivefetch-decodeoverhead§ Candocompileroptimizationsontranslatedcodetoimproveperformance- registerallocationforvaluesflowingbetweenguestISAinstructions- nativeinstructionschedulingtoimproveperformance- removeunreachablecode- inlineassemblyprocedures

18

Page 19: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

BinaryTranslation,Take1

19

Guest ISA

Code

Guest ISA Data

Executable on Disk

Native ISA

Code

Guest ISA Data

Executable on Disk

Native DataTranslate to

native ISA code

Data unchanged

Native translation might need extra data

workspace

Page 20: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

BinaryTranslationProblems

20

BranchandJumptargets- guestcode:

j L1...

L1: lw r1, (r4)jr (r1)

- nativecodej

translation

lwtranslation

jrtranslation

nativejumpatendofblockjumpstonativetranslationoflw

Whereshouldthejumpregistergo?

Page 21: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

PCMappingTable§ TablegivestranslatedPCforeachguestPC§ Indirectjumpstranslatedintocodethatlooksintabletofindwheretojumpto- canoptimizewell-behavedguestcodeforsubroutinecall/returnbyusingnativePCinreturnlinks

§ IfcanbranchtoanyguestPC,thenneedonetableentryforeveryinstructioninhostedprogramè bigtable

§ IfcanbranchtoanyPC,theneither- limitinter-instructionoptimizations- largecodeexplosiontoholdoptimizationsforeachpossibleentryintosequentialcodesequence

§ Onlyminorityofguestinstructionsareindirectjumptargets,wanttofindthese- designahighlystructuredVMdesign- userun-timefeedbackoftargetlocations

21

Page 22: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

BinaryTranslationProblems

22

§ Self-modifyingcode!- sw r1, (r2)# r2 points into code space

§ Rareinmostcode,buthastobehandledifallowedbyguestISA

§ Usuallyhandledbyincludinginterpreterandmarkingmodifiedcodepagesas“interpretonly”

§ Havetoinvalidateallnativebranchesintomodifiedcodepages

Page 23: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

BinaryTranslation,Take2

23

GuestISACode

GuestISAData

ExecutableonDisk

NativeISACode

ExecutableonDisk

PCMappingTable

GuestISACode

GuestISAData

NativeInterpreter

TranslatetonativeISAcode

Keepcopyofcodeanddatain

nativedatasegment

Interpreterusedforrun-timemodifiedcode,checksforjumpsbackinto

nativecodeusingPCmappingtable

Translationhastocheckformodified

codepagesthenjumptointerpeter

Mappingtableusedforindirectjumpsand

tojumpfrominterpreterbackintonativetranslations

Page 24: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

IBMSystem/38andAS/400

24

§ System/38announced1978- AS/400isfollow-online,nowcalled“SystemI”or“iSeries”

§ High-levelinstructionsetinterfacedesignedforbinarytranslation§ Memory-memory instructionset,neverdirectlyexecutedbyhardware

HardwareMachine

HorizontalMicrocode

VerticalMicrocode

High-LevelArchitectureInterface

Languages,Database,Utilities

ControlProgramFacility

UserApplications

ReplacedbymodifiedPowerPCcoresin

newer iSeries machinesUsed48-bitCISCengineinearlier

machines

Page 25: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

DynamicTranslation

§ Translatecodesequencesasneededatrun-time,butcacheresults

§ Canoptimizecodesequencesbasedondynamicinformation(e.g.,branchtargetsencountered)

§ Tradeoffbetweenoptimizerrun-timeandtimesavedbyoptimizationsintranslatedcode

§ TechniqueusedinJavaJIT(Just-In-Time)compilers,andVirtualMachineMonitors(forsystemVMs)

§ Also,Transmeta Crusoeforx86emulation

25

Page 26: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

SystemVMs:SupportingMultipleOSsonSameHardware

§ Canvirtualizetheenvironmentthatanoperatingsystemsees,anOS-levelVM,orsystemVM

§ HypervisorlayerimplementssharingofrealhardwareresourcesbymultipleOSVMsthateachthinktheyhaveacompletecopyofthemachine- PopularinearlydaystoallowmainframetobesharedbymultiplegroupsdevelopingOScode

-UsedinmodernmainframestoallowmultipleversionsofOStoberunningsimultaneouslyè OSupgradeswithnodowntime!

- ExampleforPCs:VMwareallowsWindowsOStorunontopofLinux(orvice-versa)

§ Requirestraponaccesstoprivilegedhardwarestate- easierifOSinterfacetohardwarewelldefined

26

Page 27: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

IntroductiontoSystemVirtualMachines

§ VMsdevelopedinlate1960s- Remainedimportantinmainframecomputingovertheyears- Largelyignoredinsingleusercomputersof1980sand1990s

§ Recentlyregainedpopularitydueto- increasingimportanceofisolationandsecurityinmodernsystems,- failuresinsecurityandreliabilityofstandardoperatingsystems,- sharingofasinglecomputeramongmanyunrelatedusers,- andthedramaticincreasesinrawspeedofprocessors,whichmakestheoverheadofVMsmoreacceptable

27

Page 28: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

VirtualMachineMonitors(VMMs)

§ Virtualmachinemonitor (VMM)orhypervisor issoftwarethatsupportsVMs

§ VMMdetermineshowtomapvirtualresourcestophysicalresources

§ Physicalresourcemaybetime-shared,partitioned,oremulatedinsoftware

§ VMMismuchsmallerthanatraditionalOS;- isolationportionofaVMMis» 10,000linesofcode

28

Page 29: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

VMMOverhead?§ Dependsontheworkload§ User-levelprocessor-bound programs(e.g.,SPEC)havezero-virtualizationoverhead- RunsatnativespeedssinceOSrarelyinvoked

§ I/O-intensiveworkloads thatareOS-intensive executemanysystemcallsandprivilegedinstructions,canresultinhighvirtualizationoverhead- ForSystemVMs,goalofarchitectureandVMMistorunalmostallinstructionsdirectlyonnativehardware

§ IfI/O-intensiveworkloadisalsoI/O-bound, lowprocessorutilizationsincewaitingforI/O- processorvirtualizationcanbehidden,solowvirtualizationoverhead

29

Page 30: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

OtherUsesofVMs

1. ManagingSoftware- VMs provideanabstractionthatcanrunthecompleteSWstack,evenincludingoldOSes likeDOS

- Typicaldeployment:someVMs runninglegacyOSes,manyrunningcurrentstableOSrelease,fewtestingnextOSrelease

2. ManagingHardware- VMs allowseparateSWstackstorunindependentlyyetshareHW,therebyconsolidatingnumberofservers-SomeruneachapplicationwithcompatibleversionofOSonseparatecomputers,asseparationhelpsdependability

- MigraterunningVMtoadifferentcomputer-EithertobalanceloadortoevacuatefromfailingHW

30

Page 31: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

WU UCB CS152/252 SP18

Example Use Cases of VMs

31

“Virtual Machines: Architectures, Implementations and Applications”, J. E. Smith and Ravi Nair, Morgan Kaufmann Publishers, 2004

Page 32: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

RequirementsofaVirtualMachineMonitor

§ AVMMonitor- PresentsaSWinterfacetoguestsoftware,- Isolatesstateofguestsfromeachother,and- Protectsitselffromguestsoftware(includingguestOSes)

§ GuestsoftwareshouldbehaveonaVMexactlyasifrunningonthenativeHW- Exceptforperformance-relatedbehaviororlimitationsoffixedresourcessharedbymultipleVMs

§ Guestsoftwareshouldnotbeabletochangeallocationofrealsystemresourcesdirectly

§ Hence,VMMmustcontrol» everythingeventhoughguestVMandOScurrentlyrunningistemporarilyusingthem- Accesstoprivilegedstate,Addresstranslation,I/O,ExceptionsandInterrupts,…

32

Page 33: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

RequirementsofaVirtualMachineMonitor

§ VMMmustbeathigherprivilegelevelthanguestVM,whichgenerallyruninusermodeÞExecutionofprivilegedinstructionshandledbyVMM

§ E.g.,Timerinterrupt:VMMsuspendscurrentlyrunningguestVM,savesitsstate,handlesinterrupt,determinewhichguestVMtorunnext,andthenloaditsstate- GuestVMsthatrelyontimerinterruptprovidedwith

virtualtimerandanemulatedtimerinterruptbyVMM§ Requirementsofsystemvirtualmachinesare

sameaspaged-virtualmemory:1. Atleast2processormodes,systemanduser2. Privilegedsubsetofinstructionsavailableonlyin

systemmode,trapifexecutedinusermode- Allsystemresourcescontrollableonlyviathese

instructions

33

Page 34: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

ISASupportforVirtualMachines§ IfVMs areplannedforduringdesignofISA,easytoreduceinstructionsthatmustbeexecutedbyaVMMandhowlongittakestoemulatethem- SinceVMs havebeenconsideredfordesktop/PCserverappsonlyrecently,mostISAs werecreatedwithoutvirtualizationinmind,including80x86andmostRISCarchitectures

§ VMMmustensurethatguestsystemonlyinteractswithvirtualresourcesÞ conventionalguestOSrunsasusermodeprogramontopofVMM- IfguestOSattemptstoaccessormodifyinformationrelatedtoHWresourcesviaaprivilegedinstruction--forexample,readingorwritingthepagetablepointer--itwilltraptotheVMM

§ Ifnot,VMMmustinterceptinstructionandsupportavirtualversionofthesensitiveinformationastheguestOSexpects(examplessoon)

34

Page 35: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

ImpactofVMsonVirtualMemory§ VirtualizationofvirtualmemoryifeachguestOSineveryVMmanagesitsownsetofpagetables?

§ VMMseparatesreal andphysicalmemory- Makesrealmemoryaseparate,intermediatelevelbetweenvirtualmemoryandphysicalmemory

- Someusethetermsvirtualmemory,physicalmemory,andmachinememory tonamethe3levels

- GuestOSmapsvirtualmemorytorealmemoryviaitspagetables,andVMMpagetablesmaprealmemorytophysicalmemory

- InRISC-V,user-virtualaddresses,plussupervisor-physical,hypervisor-physical,machine-physicaladdresses

§ VMMmaintainsashadowpagetable thatmapsdirectlyfromtheguestvirtualaddressspacetothephysicaladdressspaceofHW- Ratherthanpayextralevelofindirectiononeverymemoryaccess- VMMmusttrapanyattemptbyguestOStochangeitspagetableortoaccessthepagetablepointer

35

Page 36: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

ISASupportforVMs&VirtualMemory

§ IBM370architectureaddedadditionallevelofindirectionthatismanagedbytheVMM- GuestOSkeepsitspagetablesasbefore,sotheshadowpagesareunnecessary

§ Tovirtualize softwareTLB,VMMmanagestherealTLBandhasacopyofthecontentsoftheTLBofeachguestVM- AnyinstructionthataccessestheTLBmusttrap- TLBs withProcessIDtagssupportamixofentriesfromdifferentVMs andtheVMM,therebyavoidingflushingoftheTLBonaVMswitch

§ RecentprocessordesignshaveaddedsimilarmechanismstoaccelerateVMMs

36

Page 37: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

ImpactofVirtualizationonI/O§ Mostdifficultpartofvirtualization- IncreasingnumberofI/Odevicesattachedtothecomputer- IncreasingdiversityofI/Odevicetypes- SharingofarealdeviceamongmultipleVMs,- Supportingthemyriadofdevicedriversthatarerequired,

especiallyifdifferentguestOSes aresupportedonthesameVMsystem

§ GiveeachVMgenericversionsofeachtypeofI/Odevicedriver,andletVMMhandlerealI/O

§ MethodformappingvirtualtophysicalI/Odevicedependsonthetypeofdevice:- DiskspartitionedbyVMMtocreatevirtualdisksforguest

VMs- NetworkinterfacessharedbetweenVMs inshorttime

slices,andVMMtracksmessagesforvirtualnetworkaddressestoensurethatguestVMs onlyreceivetheirmessages

37

Page 38: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

WU UCB CS152/252 SP18

Extra Resource for Learning VM• Recommended Reading:

• “An Overview of Virtual Machine Architectures”, J. E. Smith and Ravi Nair, 21-page article

• “Virtual Machines: Architectures, Implementations and Applications”, J. E. Smith and Ravi Nair, Textbook 2004

38

Page 39: CS152/252 Spring 2018 Computer Architecture and ...inst.eecs.berkeley.edu/~cs152/sp18/lectures/L22-VM.pdfOutline §What are Virtual ... -new ISA instructions added-new types of I/O

©KrsteAsanovic,2015CS252,Fall2015,Lecture17

Acknowledgements

§ ThiscourseispartlyinspiredbypreviousMIT6.823andBerkeleyCS252computerarchitecturecoursescreatedbymycollaboratorsandcolleagues:- Arvind (MIT)- JoelEmer (Intel/MIT)- JamesHoe(CMU)- JohnKubiatowicz (UCB)- DavidPatterson(UCB)

39