Our planned VMX demo Implementation-code for our ‘Guest’ VM and ‘Host’ VMM.

Slides:



Advertisements
Similar presentations
1/1/ / faculty of Electrical Engineering eindhoven university of technology Memory Management and Protection Part 3:Virtual memory, mode switching,
Advertisements

Hardware Assisted Virtualization
Using VMX within Linux We explore the feasibility of executing ROM-BIOS code within the Linux x86_64 kernel.
9/20/6Lecture 3 - Instruction Set - Al1 Exception Handling (2)
Virtualization Technology A first look at some aspects of Intel’s ‘Vanderpool’ initiative.
Intel MP.
Microprocessors system architectures – IA32 real and virtual-8086 mode Jakub Yaghob.
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
Introduction to the Intel x86’s support for “virtual” memory
Executing an ELF executable How to load an executable ELF file for execution in ‘extended’ physical memory.
IA32 Paging Scheme Introduction to the Intel x86’s support for “virtual” memory.
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
IA-32 Processor Architecture
The x86 Feature Flags On using the CPUID instruction for processor identification and feature determination.
The various x86 ‘modes’ On understanding key differences among the processor’s several execution-architectures.
Venturing into protected-mode A first look at the CPU registers and instructions which provide the essential supporting infrastructure.
Timeout for some demos An instructive look at how the Linux Operating System sets up system data-structures.
1 Hardware and Software Architecture Chapter 2 n The Intel Processor Architecture n History of PC Memory Usage (Real Mode)
X86 segmentation, page tables, and interrupts 3/17/08 Frans Kaashoek MIT
Memory Management (II)
IA32 Paging Scheme Introduction to the Pentium’s support for “virtual” memory.
CE6105 Linux 作業系統 Linux Operating System 許 富 皓. Chapter 2 Memory Addressing.
Executing an ELF executable
1 Process Description and Control Chapter 3. 2 Process Management—Fundamental task of an OS The OS is responsible for: Allocation of resources to processes.
Home: Phones OFF Please Unix Kernel Parminder Singh Kang Home:
Setup for VM launch Using ‘vmxwrite’ and ‘vmxread’ for access to state-information in a Virtual Machine Control Structure.
Executing an ELF executable How to load an executable ELF file for execution in ‘extended’ physical memory.
Venturing into 64-bit mode Examining the steps needed to take the processor into IA-32e mode -- and then back out again.
Venturing into protected-mode
Introduction to the Intel x86’s support for “virtual” memory
CS2422 Assembly Language & System Programming September 22, 2005.
On 64-bit ‘code-relocation’ How we can launch a procedure in 64-bit mode that resides in a page-frame at a high address.
Protected Mode. Protected Mode (1 of 2) 4 GB addressable RAM –( to FFFFFFFFh) Each program assigned a memory partition which is protected from.
Using Two Queues. Using Multiple Queues Suspended Processes Processor is faster than I/O so all processes could be waiting for I/O Processor is faster.
8086 emulation Using Virtual-8086 mode to execute real-mode procedures in a protected-mode environment.
Venturing into protected-mode A first look at the CPU registers and instructions which provide the essential supporting infrastructure.
Software Development and Software Loading in Embedded Systems.
UNIT 2 Memory Management Unit and Segment Description and Paging
Tanenbaum 8.3 See references
80386DX.
Memory Addressing in Linux  Logical Address machine language instruction location  Linear address (virtual address) a single 32 but unsigned integer.
1 Linux Operating System 許 富 皓. 2 Memory Addressing.
Innovation Center UFRGS/Microsoft Virtualization Instruction Set Architecture.
Microprocessor system architectures – IA32 introduction Jakub Yaghob.
Interrupts in the guest VM A look at the steps needed to “reflect” hardware interrupts back into the ROM-BIOS for servicing.
Chapter 4 Memory Management Virtual Memory.
System Address Registers/Memory Management Registers Four memory management registers are used to specify the locations of data structures which control.
 Virtual machine systems: simulators for multiple copies of a machine on itself.  Virtual machine (VM): the simulated machine.  Virtual machine monitor.
80386DX.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
1 i386 Memory Management Professor Ching-Chi Hsu 1998 年 4 月.
Virtual 8086 Mode  The supports execution of one or more 8086, 8088, 80186, or programs in an protected-mode environment.  An 8086.
Microprocessor system architectures – IA32 tasks Jakub Yaghob.
Segment Descriptor Segments are areas of memory defined by a programmer and can be a code, data or stack segment. In segments need not be all the.
Paravirtual/HVM linux examples Argentina Software Development Center Software and Solutions Group 31 July 2008.
Information Security - 2. CISC Vs RISC X86 is CISC while ARM is RISC CISC is Compiler’s heaven while RISC is Architecture’s heaven Orthogonal ISA in RISC.
Microprocessor Architecture
An Interrupt is either a Hardware generated CALL (externally derived from a hardware signal) OR A Software-generated CALL (internally derived from.
Microprocessor and Assembly Language
COMBINED PAGING AND SEGMENTATION
Memory Management References text: Tanenbaum ch.4.
x86 segmentation, page tables, and interrupts
OS Virtualization.
Operating Modes UQ: State and explain the operating modes of X86 family of processors. Show the mode transition diagram highlighting important features.(10.
Memory Management References text: Tanenbaum ch.4.
Introduction to the Intel x86’s support for “virtual” memory
Process Description and Control
First Generation 32–Bit microprocessor
Assembly Language for Intel-Based Computers, 5th Edition
Master’s Thesis Defense Ryan Wilson Dr. Fawcett December 2011
Presentation transcript:

Our planned VMX demo Implementation-code for our ‘Guest’ VM and ‘Host’ VMM

Quick review We plan to demonstrate use of Intel’s new VMX instructions in a ‘simple’ context: –One ‘Virtual-8086 mode’ guest-task (the VM) –A ’64-bit mode’ host-task (the VM Manager) Virtual Machine Manager (‘Host’) Virtual Machine (‘Guest’)

Guest ‘resources’ We identified the needed data-structures and procedures to support our ‘Guest’ VM: –Task State Segment (with permission-bitmap) –Global Descriptor Table (for TSS and LDT) –Local Descriptor Table (code, data, vram, flat) –Page-Directory Table (for one ‘4-MB’ frame) –Two stacks (for use in ring3 and in ring0) –Code for ‘guest_task’ (also ‘guest_isrGPF’)

Testing our ‘Guest’ We created ‘vmxstep1.s’ to implement our guest’s data-structures and its procedures We also wrote ‘trystep1.s’ as a testbed for resources in our ‘vmxstep1.s’ component Two files should be separately assembled, then linked to create the test ‘executable’ $ as vmxstep1.s -o vmxstep1.o $ as trystep1.s -o trystep1.o $ ld trystep1.o vmxstep1.o -T ldscript -o trystep1.b $ dd if=trystep1.b of=/dev/sda4 seek=1

What will our ‘Host’ do? Our VMM will need to take these actions: –Initially enter VMX mode (using ‘vmxon’) –Clear our guest’s VMCS (using ‘vmclear’) –Load the guest-pointer (using ‘vmptrld’) –Write VMCS parameters (using ‘vmwrite’) –Launch the guest-task (using ‘vmlaunch’) –Read guest-exit information (using ‘vmread’) –Maybe reenter the guest (using ‘vmresume’) –Eventually leave VMX mode (using ‘vmxoff’)

Host’s data-resources We need supporting VMM data-structures: –4-level page-tables (required for 64-bit code) –Task-State Segment (no permission-bitmap) –Global Descriptor Table (code, data, TSS) –Interrupt Descriptor Table (for GP faults) –One stack-region (for VMM’s ‘ring0’ code) –Virtual Machine Control Structures (two) –Collection of variables (VMCS parameters)

‘vmxstep2.s’ We created a preliminary implementation for our ‘Host’ data-structures, and part of its executable code Some ‘external’ data-items are referenced Our demo-program’s ‘Control’ component remains to be designed and implemented The required CPU initializations still have to be considered (and then implemented)

The ‘machine’ array We contemplate doing initialization of our guest’s Virtual Machine Control Structure within a single program-loop by our host That loop refers to an array of parameters that we’ve named ‘machine[]’ – its entries will need to be initialized We foresee that our VMM will do reading of many diagnostic parameters in a loop, using an array that we’ve names ‘results’

The array-formats whatwhere whatwhere whatwhere whatwhere whatwhere whatwhere whatwhere whatwhere whatwhere whatwhere whatwhere whatwhere whatwhere whatwhere whatwhere machine[]: … whatwhere whatwhere whatwhere whatwhere whatwhere whatwhere whatwhere results[]: …012345… The ‘what’ fields contain encodings for parameter-elements in a VMCS and the ‘where’ fields hold pointers to variables in our program where the parameter-values will be stored

CPU initializations As with Intel’s EM64T features, which are not automatically enabled at startup-time, the VTX features also need to be ‘enabled’ In a few cases, these will requires some additional background to be understood In other cases, they will merely require setting some extra bits in familiar registers

CPU has VMX support? Your software can confirm that your CPU implements the VMX instruction-set: use the CPUID instruction with EAX=1, and verify that bit #5 in register ECX is ‘1’ # using CPUID to check for Virtualization Technology support mov$1, %eax cpuid bt$5, %ecx jncno_vmx jmpok_vmx

reserved This is a Model-Specific Register having register-index 0x A LOCKLOCK ENABLEENABLE Feature Control Register Bit 2: ENABLE When this bit is 0, any attempt to execute the VMXON instruction causes a General Protection Exception (i.e., VMX will be unavailable) Bit 0: LOCK When this bit is 1, then the Feature Control Register’s value will be ‘locked’ (i.e., any attempt to execute WRMSR to modify the contents of this register will cause a General Protection Exception) until power-up. NOTE: On our ‘anchor’ machines the ROM-BIOS start-up code will initialize and ‘lock’ this register (based on an option our SysAdmin selected during SETUP).

Control Register CR4 reserved VMXEVMXE PAEPAE PSEPSE VMEVME PAE (Page-Addressing Extensions) 1 = enabled, 0 = disabled (must be enabled for 64-bit mode) VMXE (Virtual Machine Extensions Enabled) 1=yes, 0=no (default is no) PSE (Page-Size Extensions) 1 = enabled, 0 = disabled VME (Virtual-8086 Mode Extensions) 1=on, 0=off

Control Register CR0 reserved AMAM WPWP NENE ETET TSTS EMEM MPMP PEPE PGPG CDCD NWNW PG (Paging): 1=enabled, 0=disabled (must be ‘1’ for 64-bit mode) PE (Protection): 1=enabled, 0=disabled (must be ‘1’ for 64-bit mode) NE (Numeric Error) 1= native internal mechanism 0 = legacy PC-style mechanism (must be ‘1’ for VMX operations)

The A20 address-line main memory On contemporary platforms (with more than 20 address-bus lines), any faithful emulation of the 8086 processor’s ‘real-mode’ addressing-scheme at startup requires ‘forcing’ an address-wraparound at the 1MB boundary, accomplished by turning off the A20 address-line one magabyte Special circuitry is available for turning “on” or “off” the function of the 21 st address-line VMX-operation requires that A20 must be “on” The state of the A20-line can be controlled via software -- by toggling bit #1 at I/O-port 0x92 RESET A20 Port 0x A20: 1=on, 0=off

Turning “on” the A20-line Caution must be observed when turning “on” the A20 address-line via port 0x92 (since other bits affect vital operations!) # this code-fragment turns the A20-line “on” in$0x92, %al or$0x02, %al out%al, $0x92 # this code-fragment turns the A20-line “off” in$0x92, %al and$0xFD, %al out%al, $0x92

VMCS Your ‘Host’ and ‘Guest’ each will need to access a page-aligned VMCS region that is initialized with the VMX version-ID in its first longword The value to use for that version-Identifier can be discovered from reading the VMX Capability MSRs (register-index 0x480) For our Core-2 Duo processors, it’s 7

Alignment and initialization Here is assembly language code you can add that will set up one VMCS region:.equARENA, 0x10000# program load-address.section.data # align0x1000 vmcs1:.long0x # our VMX version-ID.zero4092# zeros in rest of frame # region:.quadvmcs1 + ARENA# physical address of vmcs1 #

In-class exercise #1 Assemble the ‘vmxstep1.s’ and ‘trystep1.s’ files, then link them (using our ‘ldscript’) to get a binary-executable named ‘trystep1.b’ Install ‘trystep1.b’ on the ‘/dev/sda4’ disk- partition of you assigned ‘anchor’ machine and verify that the guest-message can be received by ‘colby’ (via its serial cable)

In-class exercise #2 Use our ‘newapp64.cpp’ utility to quickly make the assembly language source-code for a test- platform you can use to try executing the Intel ‘vmxon’ instruction: –You need a page-aligned 4K memory-region with first longword initialized to version-ID=7 –You need a quadword-size variable holding the physical-address for that page-frame –You need to enable A20, set VMXE=1, NE=1 –Place instruction ‘vmxon region’ in 64-bit code