CS 423 Operating System Design: Process VMs Professor Michael - - PowerPoint PPT Presentation

cs 423 operating system design process vms
SMART_READER_LITE
LIVE PREVIEW

CS 423 Operating System Design: Process VMs Professor Michael - - PowerPoint PPT Presentation

CS 423 Operating System Design: Process VMs Professor Michael Bailey Spring 2018 CS 423: Operating Systems Design Goals for Today Learning Objective: Conclude discussion of virtualization w/ process VMs Announcements, etc:


slide-1
SLIDE 1

CS 423: Operating Systems Design

Professor Michael Bailey Spring 2018

CS 423
 Operating System Design: Process VMs

slide-2
SLIDE 2

CS 423: Operating Systems Design 2

Goals for Today

Reminder: Please put away devices at the start of class

  • Learning Objective:
  • Conclude discussion of virtualization w/ process VMs
  • Announcements, etc:
  • Midterm scores and debrief will come over spring break
  • MP2 extension: now due on March 25th (UTC-11)
  • MP3 released March 27th
  • MP2.5 (Extra Credit) release on March 27th also
slide-3
SLIDE 3

CS 423: Operating Systems Design

Dynamic Binary Translation

3

Edit: The original automata didn’t execute the current block unless there was a hit!

slide-4
SLIDE 4

CS 423: Operating Systems Design

Translation Chaining

4

  • Translation chaining

– The counterpart of threading in interpreters – The first time a jump is taken to a new destination, go through the emulation manager as usual – Subsequently, rather than going through the emulation manager at that jump (i.e., once destination block is known), just go to the right place.

  • What type of jumps can we do this with?
  • Fixed Destination Jumps Only!!!
slide-5
SLIDE 5

CS 423: Operating Systems Design

Indirect Jump Caching

5

  • Jump destination depends on value in register.
  • Must search map table for destination value

(expensive operation)

  • Solution?

– Caching: add a series of if statements, comparing register content to common jump source program counter values from past execution (most common first). – If there is a match, jump to corresponding target program counter location. – Else, go to emulation manager.

slide-6
SLIDE 6

CS 423: Operating Systems Design

Process VMs

6

  • Present the abstraction of a different machine

and OS to a process.

Guest Process

Runtime

Host OS

slide-7
SLIDE 7

CS 423: Operating Systems Design

Emulation Architecture

7

Guest Memory Image Emulation Engine Code Cache Manager Code Cache Exception Emulation OS Call Emulation Initialization Loader

Host OS

slide-8
SLIDE 8

CS 423: Operating Systems Design

Virtualization Isomorphism

8

  • Creation of an isomorphism that maps a virtual

guest system to a real host:

– Maps guest state S to host state V(S) – For any sequence of operations on the guest that changes guest state S1 to S2, there is a sequence of

  • perations on the host that maps state V(S1) to V(S2)
slide-9
SLIDE 9

CS 423: Operating Systems Design 9

S1 S2 S3 S4

e(S1) e(S2) e(S3)

S1` S2` S3` S4`

e`(S1) e`(S2) e`(S3) V(S1) V(S2) V(S3) V(S4) Host Guest

Virtualization Isomorphism

“State Equivalence”

slide-10
SLIDE 10

CS 423: Operating Systems Design

Violating State Equivalence?

10

  • Process state equivalence at the point of

interaction with the “external world”

– When control transfers from guest process to host OS, state equivalence must hold – When control transfers back to guest process, state equivalence must hold (both of user managed and OS managed state)

  • Consequences:

– State does not need to be mapped correctly in between interactions with OS

slide-11
SLIDE 11

CS 423: Operating Systems Design

State Mapping

11

  • Guest registers à Host registers/Memory

– Guest context (and context switch) – Depends on who has more registers

  • Memory address space mapping

– Guest application (virtual) address space

à Host application (virtual) address space

slide-12
SLIDE 12

CS 423: Operating Systems Design

Translation Table

12

Translation Table Guest Address Space Host (Virtual) Address Space Software translates guest to host virtual addresses. Disadvantage? 64K blocks

slide-13
SLIDE 13

CS 423: Operating Systems Design

Direct Access Translation

13

Guest Application Address Space Mapped Guest Application Address Space Runtime Host Virtual Address Space Guest Application Address Space Mapped Guest Application Address Space Runtime Host Virtual Address Space Offset Translation Direct Translation

slide-14
SLIDE 14

CS 423: Operating Systems Design

Direct Translation

14

Guest Application Address Space Mapped Guest Application Address Space Runtime Host Virtual Address Space Guest Application Address Space Mapped Guest Application Address Space Runtime Host Virtual Address Space Offset Translation Direct Translation

Limitations?

slide-15
SLIDE 15

CS 423: Operating Systems Design

Memory Arch Emulation

15

  • Host OS Offers:

– A system call to set memory protection (specifies page and access privileges) – A signal for a memory protection violation that can be delivered to the application (runtime)

  • Memory protection

– Each page has protection bits such as read/write or read/ write/execute (e.g., you cannot execute data, or overwrite code) – What if guest architecture has read/write/execute protection whereas host has read/write only?

slide-16
SLIDE 16

CS 423: Operating Systems Design

Page Size Issues

16

  • What if page size on guest is a multiple of page

size on host?

  • What if page size on host is a multiple of page

size on guest?

slide-17
SLIDE 17

CS 423: Operating Systems Design

Page Size Issues

17

  • What if page size on guest is a multiple of page

size on host?

– No problem. Just replicate page protection

  • What if page size on host is a multiple of page

size on guest?

– Different guest pages mapped to same host page?

  • Problems?

– Pad guest pages to size of host page?

  • Problems?
slide-18
SLIDE 18

CS 423: Operating Systems Design

Page Size Issues

18

  • What if page size on host is a multiple of page

size on guest?

– Different guest pages mapped to same host page? Problems?

  • What if pages have different protection?
  • Use the more conservative bits and handle violations

accordingly

– Pad guest pages to size of host page?

  • Makes address translation more difficult
  • Wastes resource
slide-19
SLIDE 19

CS 423: Operating Systems Design

Instruction Emulation

19

  • Interpretation versus binary translation?

– Interpretation:

  • no startup overhead
  • High overhead per instruction

– Binary translation:

  • High startup overhead
  • Low overhead per instruction

– Can we combine the best of both worlds?

slide-20
SLIDE 20

CS 423: Operating Systems Design

Instruction Emulation

20

  • Interpretation versus binary translation?

– Interpretation:

  • no startup overhead
  • High overhead per instruction

– Binary translation:

  • High startup overhead
  • Low overhead per instruction

– Can we combine the best of both worlds?

  • Small program: Do interpretation
  • Large program: Do binary translation

Program size Latency Binary translation Interpretation

slide-21
SLIDE 21

CS 423: Operating Systems Design

Instruction Emulation

21

  • Initially assume small program

– Do Interpretation

  • Count the number of times each block is

executed

  • If a block is executed more than N times, do

binary translation on this block

slide-22
SLIDE 22

CS 423: Operating Systems Design

Interrupts Emulation

22

  • Two types:

– Traps (caused by instructions in the program) – Hardware interrupts (caused by asynchronous external events)

  • For Traps and Exceptions:

– Ensure that all instructions prior to trap have been executed – Ensure that none of the instructions after the trap have been executed

  • For Interrupts:

– Emulated code must be in interruptible state…

slide-23
SLIDE 23

CS 423: Operating Systems Design

Traps & Exceptions

23

  • How to detect them?

– Both guest and host support same trap (e.g., page fault). Map guest trap to host trap: capture trap signal, execute the translated guest handler

  • Runtime intercepts all signals and handles them

– Guest supports trap/exception that host does not support (or does not deliver to the application). Check for exception conditions in the emulated software explicitly

slide-24
SLIDE 24

CS 423: Operating Systems Design

Interrupts

24

  • When an interrupt occurs:

– Interpretation: When an interrupt occurs, finish interpreting the current instruction and execute the interrupt handler – Binary translation: When an interrupt occurs, the emulated code may be in non-interruptible state (what does that mean?)

  • Need well-defined boundaries where emulated code is

interruptible.

  • What is a suitable boundary?
  • When interrupt occurs, execute emulated guest code until

boundary is reached, then execute the interrupt handler.

slide-25
SLIDE 25

CS 423: Operating Systems Design

Interrupts

25

  • When an interrupt occurs:

– Interpretation: When an interrupt occurs, finish interpreting the current instruction and execute the interrupt handler – Binary translation: When an interrupt occurs, the emulated code may be in non-interruptible state (what does that mean?)

  • Need well-defined boundaries where emulated code is

interruptible.

  • What is a suitable boundary? BLOCK BOUNDARIES
  • When interrupt occurs, execute emulated guest code until

boundary is reached, then execute the interrupt handler.

slide-26
SLIDE 26

CS 423: Operating Systems Design

Interrupts

26

  • When an interrupt occurs:

– Interpretation: When an interrupt occurs, finish interpreting the current instruction and execute the interrupt handler – Binary translation: When an interrupt occurs, the emulated code may be in non-interruptible state (what does that mean?)

  • Need well-defined boundaries where emulated code is

interruptible.

  • What is a suitable boundary? BLOCK BOUNDARIES
  • When interrupt occurs, execute emulated guest code until

boundary is reached, then execute the interrupt handler.

What if blocks are chained?

slide-27
SLIDE 27

CS 423: Operating Systems Design

Interrupts in Binary Translation

27

  • When an interrupt occurs, the emulated code

may be in non-interruptible state

– Determine which block is currently running – Unchain the block from the next by replacing the jump at the end of the block to a transfer of control to the emulation manager. – Let the block finish – Control is transferred to emulation manager which invoked interrupt handler.

slide-28
SLIDE 28

CS 423: Operating Systems Design

Note: Guest OS Emu

28

  • Does not have to translate guest OS instructions one a time

– Translate entire functions into equivalent ones – Example: replace a disk I/O system call on the guest with an equivalent disk I/O call on the host

  • Not all guest system calls need to be translated to host

calls; some are handled by the runtime.

– Example: Calls installing a new signal handler may be handled by the runtime since runtime intercepts all signals and maintains their handlers.

  • Generally an ad hoc process (case-by-case).