126
ARMvisor Peter Chang This side is licensed under CC-BY-NC-SA 姓名標示─非商業性─相同方式分享 (http://creativecommons.org/licenses/by-nc-sa/3.0/tw/legalcode )

ARMvisor, more details

Embed Size (px)

Citation preview

Page 1: ARMvisor, more details

ARMvisorPeter Chang

This side is licensed under CC-BY-NC-SA姓名標示─非商業性─相同方式分享

(http://creativecommons.org/licenses/by-nc-sa/3.0/tw/legalcode)

Page 2: ARMvisor, more details

Who am I?

Page 3: ARMvisor, more details

Who am I?

• Peter Chang

Page 4: ARMvisor, more details

Who am I?

• Peter Chang

• One of the current developers of ARMvisor

Page 5: ARMvisor, more details

Who am I?

• Peter Chang

• One of the current developers of ARMvisor

• http://tw.linkedin.com/in/peterchangtw

Page 6: ARMvisor, more details

What is ARMvisor?

Page 7: ARMvisor, more details
Page 8: ARMvisor, more details

ARM

Page 9: ARMvisor, more details

ARM

Page 10: ARMvisor, more details

ARM

Page 11: ARMvisor, more details

What is KVM?

Page 12: ARMvisor, more details

What is KVM?

• A.k.a. Kernel-based Virtual Machine

Page 13: ARMvisor, more details

What is KVM?

• A.k.a. Kernel-based Virtual Machine

• Type-II Virtual Machine Monitor

Page 14: ARMvisor, more details

What is KVM?

• A.k.a. Kernel-based Virtual Machine

• Type-II Virtual Machine Monitor

• A module of Linux kernel

Page 15: ARMvisor, more details

What is KVM?

Page 16: ARMvisor, more details

What is KVM?

• Officially support x86/x64, PowerPC, S390

Page 17: ARMvisor, more details

What is KVM?

• Officially support x86/x64, PowerPC, S390

• No official support for ARM architecture

Page 18: ARMvisor, more details

What is ARMvisor?

Page 19: ARMvisor, more details

What is ARMvisor?

• ARM架構上的KVM

Page 20: ARMvisor, more details

What is ARMvisor?

• ARM架構上的KVM

• Para-virtualization

Page 21: ARMvisor, more details

What is ARMvisor?

• ARM架構上的KVM

• Para-virtualization

• Trap & Emulation

Page 22: ARMvisor, more details

What is ARMvisor?

• ARM架構上的KVM

• Para-virtualization

• Trap & Emulation

• Dynamic Memory Allocation

Page 23: ARMvisor, more details

What is ARMvisor?

• ARM架構上的KVM

• Para-virtualization

• Trap & Emulation

• Dynamic Memory Allocation

• virtio & IRQchip-in-kernel

Page 24: ARMvisor, more details

Hardware: ARM Cortex-A8

Host OS: Linux 2.6.38

ARMvisorDriver

QEMU 0.14

Device

Driver

Guest OS: Linux 2.6.35

Page 25: ARMvisor, more details

2012

2011

2010

2009

Page 26: ARMvisor, more details

2012

2011

2010

2009

Page 27: ARMvisor, more details

2012

2011

2010

2009

Starting Point

Page 28: ARMvisor, more details

2012

2011

2010

2009

Starting Point

Page 29: ARMvisor, more details

2012

2011

2010

2009

Starting Point

ARMvisor Prototype

Page 30: ARMvisor, more details

2012

2011

2010

2009

Starting Point

ARMvisor Prototype

Page 31: ARMvisor, more details

2012

2011

2010

2009

Starting Point

ARMvisor Prototype

CPU Opt & Mem Opt

Page 32: ARMvisor, more details

2012

2011

2010

2009

Starting Point

ARMvisor Prototype

CPU Opt & Mem Opt

Page 33: ARMvisor, more details

2012

2011

2010

2009

Starting Point

ARMvisor Prototype

CPU Opt & Mem Opt

I/O Opt

Page 34: ARMvisor, more details

Supported Hardware

ARM Realview-eb

ARM11

ARMv6 ISA

Page 35: ARMvisor, more details

Supported Hardware

TI BeagleBoard

Cortex-A8

ARMv7 ISA

Page 36: ARMvisor, more details

Supported Software

• Patched Host OS:

• Linaro Linux 2.6.38

• Host Root Filesystem

• Ubuntu/Debian RFS (CLI or GUI)

• QEMU 0.14

Page 37: ARMvisor, more details

Supported Software

• Patched Guest OS:

• Linux 2.6.35 (running on ARMv6 ISA)

• Guest Root Filesystem:

• Ubuntu/Debian RFS (CLI or GUI)

Page 38: ARMvisor, more details

System model of ARMvisor

Page 39: ARMvisor, more details

CPU virtualization

Page 40: ARMvisor, more details

CPU virtualization

• ARM is non-virtualizable CPU

• Patch guest OS

• “Trap and emulation”

Page 41: ARMvisor, more details

ARMv6 ISA1.Branch instructions2.Data-processing instructions3.Multiply instructions4.Parallel addition and subtraction instructions5.Extend instructions6.Miscellaneous arithmetic instructions7.Other miscellaneous instructions8.Status register access instructions9.Load and store instructions10.Load and Store Multiple instructions11.Semaphore instructions12.Exception-generating instructions13.Coprocessor instructions

Page 42: ARMvisor, more details

ARMv6 ISA1.Branch instructions2.Data-processing instructions3.Multiply instructions4.Parallel addition and subtraction instructions5.Extend instructions6.Miscellaneous arithmetic instructions7.Other miscellaneous instructions8.Status register access instructions9.Load and store instructions10.Load and Store Multiple instructions11.Semaphore instructions12.Exception-generating instructions13.Coprocessor instructions

Sensitive Instructions ?

Page 43: ARMvisor, more details

ARMv6 ISA1.Branch instructions2.Data-processing instructions3.Multiply instructions4.Parallel addition and subtraction instructions5.Extend instructions6.Miscellaneous arithmetic instructions7.Other miscellaneous instructions8.Status register access instructions9.Load and store instructions10.Load and Store Multiple instructions11.Semaphore instructions12.Exception-generating instructions13.Coprocessor instructions

Page 44: ARMvisor, more details

Data-processing instructions S-BIT: MOVS, ...

Status register access instructions MRS, MSR, CPS, SETEND

Load and store instructions T-BIT: LDRT, STRT, ...

Load and Store Multiple instructions LDM(2), LDM(3), STM(2)

Exception-generating instructions SWI, BKPT

Coprocessor instructions MCR, MRC, MCRR, ...

Sensitive Instructions

Page 45: ARMvisor, more details

Observation from Guest Linux Code

• MOVS• (MRS, MSR, CPS) • (LDRBT, LDRT, STRBT, STRT)• (LDM(2), LDM(3), STM(2))• SWI• (MCR, MRC, MCRR)

15 sensitive instructions used in the guest linux code

Page 46: ARMvisor, more details

“Trap & emulation”

User%space%%

Kernel%space�

Guest%OS�

VMM�

trap�

Page 47: ARMvisor, more details

How to “trap”?

…mov r0, r0add sp, spmovs pc, lr…

Page 48: ARMvisor, more details

How to “trap”?

…mov r0, r0add sp, spvirt_svc_movs “movs pc, lr”…

Page 49: ARMvisor, more details

How to “trap”?

…mov r0, r0add sp, spvirt_svc_movs “movs pc, lr”…

Page 50: ARMvisor, more details

How to “trap”?

…mov r0, r0add sp, spvirt_svc_movs “movs pc, lr”…

.macro virt_svc_movs, instSWI 0x190\inst.endm

Page 51: ARMvisor, more details

How to “emulate”?

Page 52: ARMvisor, more details

oxffff0000

oxffff1000

Kernel Vector0xffff001c

Page 53: ARMvisor, more details

oxffff0000

oxffff1000

Kernel Vector0xffff001c

Page 54: ARMvisor, more details

oxffff0000

oxffff1000

Kernel Vector0xffff001c

The KVM trapInterface

Page 55: ARMvisor, more details

KVM  Trap  Entry

KVM/Guest  Context  Switch  

UnitHost  Trap  Handler

Instruction  Emulation

Exception/Interrupt  Emulation

MMU  Emulation

QEMU  I/OEmulation

KVM  Trap  Dispatcher

UND ABORT SWI IRQ/FIQ

Page 56: ARMvisor, more details

Kernel space

KVM

User space

QEMU

Guest Mode

Guest OS

Page 57: ARMvisor, more details

Kernel space

KVM

User space

QEMU

Guest Mode

Guest OS

1. VM initialization

Page 58: ARMvisor, more details

Kernel space

KVM

User space

QEMU

Guest Mode

Guest OS

2. Return to QEMU

1. VM initialization

Page 59: ARMvisor, more details

Kernel space

KVM

User space

QEMU

Guest Mode

Guest OS

2. Return to QEMU

1. VM initialization

3. Run VM

Page 60: ARMvisor, more details

Kernel space

KVM

User space

QEMU

Guest Mode

Guest OS

2. Return to QEMU

1. VM initialization

3. Run VM4. Enter Guest

Page 61: ARMvisor, more details

Kernel space

KVM

User space

QEMU

Guest Mode

Guest OS

2. Return to QEMU

1. VM initialization

3. Run VM4. Enter Guest

5. Exit Guest

Page 62: ARMvisor, more details

Kernel space

KVM

User space

QEMU

Guest Mode

Guest OS

2. Return to QEMU

1. VM initialization

3. Run VM4. Enter Guest

5. Exit GuestLightweight trap

Page 63: ARMvisor, more details

Kernel space

KVM

User space

QEMU

Guest Mode

Guest OS

2. Return to QEMU

1. VM initialization

3. Run VM4. Enter Guest

5. Exit Guest

6. Enter Guest

Lightweight trap

Page 64: ARMvisor, more details

Kernel space

KVM

User space

QEMU

Guest Mode

Guest OS

2. Return to QEMU

1. VM initialization

3. Run VM4. Enter Guest

5. Exit Guest

6. Enter Guest

7. Exit Guest

Lightweight trap

Page 65: ARMvisor, more details

Kernel space

KVM

User space

QEMU

Guest Mode

Guest OS

2. Return to QEMU

1. VM initialization

3. Run VM4. Enter Guest

5. Exit Guest

6. Enter Guest

7. Exit Guest8. Return to QEMU

Lightweight trap

Page 66: ARMvisor, more details

Kernel space

KVM

User space

QEMU

Guest Mode

Guest OS

2. Return to QEMU

1. VM initialization

3. Run VM4. Enter Guest

5. Exit Guest

6. Enter Guest

7. Exit Guest8. Return to QEMU

Lightweight trap

Heavyweight trap

Page 67: ARMvisor, more details

Kernel space

KVM

User space

QEMU

Guest Mode

Guest OS

2. Return to QEMU

1. VM initialization

3. Run VM4. Enter Guest

5. Exit Guest

6. Enter Guest

7. Exit Guest8. Return to QEMU

9. Run VM

Lightweight trap

Heavyweight trap

Page 68: ARMvisor, more details

Kernel space

KVM

User space

QEMU

Guest Mode

Guest OS

2. Return to QEMU

1. VM initialization

3. Run VM4. Enter Guest

5. Exit Guest

6. Enter Guest

7. Exit Guest8. Return to QEMU

9. Run VM

10. Enter Guest

Lightweight trap

Heavyweight trap

Page 69: ARMvisor, more details

oxffff0000

oxffff1000

Kernel Vector0xffff001c

The KVM trapInterface

VCPU  Register  

FileSync

oxffff2000

Page 70: ARMvisor, more details

oxffff0000

oxffff1000

Kernel Vector0xffff001c

The KVM trapInterface

Shadow  Register  FileVCPU  

Register  File

Sync

oxffff2000

Page 71: ARMvisor, more details

oxffff0000

oxffff1000

Kernel Vector0xffff001c

The KVM trapInterface

Shadow  Register  File

mcr  cpsr,  r1

VCPU  Register  

FileSync

oxffff2000

Page 72: ARMvisor, more details

oxffff0000

oxffff1000

Kernel Vector0xffff001c

The KVM trapInterface

Shadow  Register  File

mcr  cpsr,  r1

VCPU  Register  

FileSync

oxffff2000

Page 73: ARMvisor, more details

oxffff0000

oxffff1000

Kernel Vector0xffff001c

The KVM trapInterface

Shadow  Register  FileRead/WriteInstructions

mcr  cpsr,  r1

VCPU  Register  

FileSync

oxffff2000

Page 74: ARMvisor, more details

oxffff0000

oxffff1000

Kernel Vector0xffff001c

The KVM trapInterface

Shadow  Register  FileRead/WriteInstructions

mcr  cpsr,  r1

VCPU  Register  

FileSync

oxffff2000

Page 75: ARMvisor, more details

Memory virtualization

Page 76: ARMvisor, more details

Virtual  Address

Physical  Address

PTB

Page 77: ARMvisor, more details

GVA

GPA

HVA

HPA

Page 78: ARMvisor, more details

Guest  PTBGVA

GPA

HVA

HPA

Page 79: ARMvisor, more details

Guest  PTBGVA

GPA

HVA

HPA

Page 80: ARMvisor, more details

Guest  PTBGVA

GPA

HVA

HPA

Host  PTB

Page 81: ARMvisor, more details

Guest  PTBGVA

GPA

HVA

HPA

Host  PTB

New  SPTE  !!!

Page 82: ARMvisor, more details
Page 83: ARMvisor, more details

PABT/DABT  trap

Page 84: ARMvisor, more details

PABT/DABT  trap

guest  page  table  walker

Page 85: ARMvisor, more details

PABT/DABT  trap

True  Translation  fault

guest  page  table  walker

Page 86: ARMvisor, more details

Guest  permission  checker

PABT/DABT  trap

True  Translation  fault

guest  page  table  walker

Page 87: ARMvisor, more details

Guest  permission  checker

PABT/DABT  trap

True  Translation  fault

True  permission  fault

guest  page  table  walker

Page 88: ARMvisor, more details

Guest  permission  checker

MMIO  access  checker

PABT/DABT  trap

True  Translation  fault

True  permission  fault

guest  page  table  walker

Page 89: ARMvisor, more details

Guest  permission  checker

MMIO  access  checker

PABT/DABT  trap

MMIO  emulationTrue  Translation  fault

True  permission  fault

guest  page  table  walker

Page 90: ARMvisor, more details

Guest  permission  checker

Shadow  page  table  

mapping

MMIO  access  checker

PABT/DABT  trap

MMIO  emulationTrue  Translation  fault

True  permission  fault

guest  page  table  walker

Page 91: ARMvisor, more details

Guest  permission  checker

Shadow  page  table  

mapping

MMIO  access  checker

PABT/DABT  trapHidden  protection  fault

MMIO  emulationTrue  Translation  fault

True  permission  fault

guest  page  table  walker

Page 92: ARMvisor, more details

Guest  permission  checker

Shadow  page  table  

mapping

MMIO  access  checker

PABT/DABT  trapHidden  protection  fault

Hidden  translation  fault

MMIO  emulationTrue  Translation  fault

True  permission  fault

guest  page  table  walker

Page 93: ARMvisor, more details

Guest  permission  checker

Shadow  page  table  update

Shadow  page  table  

mapping

MMIO  access  checker

PABT/DABT  trapHidden  protection  fault

Hidden  translation  fault

MMIO  emulationTrue  Translation  fault

True  permission  fault

guest  page  table  walker

Page 94: ARMvisor, more details

I/O virtualization

Page 95: ARMvisor, more details

I/O virtualization

• Emulation by QEMU

• virtio

• IRQ chip in kernel

Page 96: ARMvisor, more details

Emulate by QEMU

Page 97: ARMvisor, more details

Hardware: ARM Cortex-A8

Host OS: Linux 2.6.38

ARMvisor

Driver

QEMU 0.14

Device

Driver

Guest OS: Linux 2.6.35

Page 98: ARMvisor, more details

Hardware: ARM Cortex-A8

Host OS: Linux 2.6.38

ARMvisor

Driver

QEMU 0.14

Device

Driver

Guest OS: Linux 2.6.35

1

Page 99: ARMvisor, more details

Hardware: ARM Cortex-A8

Host OS: Linux 2.6.38

ARMvisor

Driver

QEMU 0.14

Device

Driver

Guest OS: Linux 2.6.35

1

2

Page 100: ARMvisor, more details

Hardware: ARM Cortex-A8

Host OS: Linux 2.6.38

ARMvisor

Driver

QEMU 0.14

Device

Driver

Guest OS: Linux 2.6.35

1

23

Page 101: ARMvisor, more details

Hardware: ARM Cortex-A8

Host OS: Linux 2.6.38

ARMvisor

Driver

QEMU 0.14

Device

Driver

Guest OS: Linux 2.6.35

1

23

4

Page 102: ARMvisor, more details

Hardware: ARM Cortex-A8

Host OS: Linux 2.6.38

ARMvisor

Driver

QEMU 0.14

Device

Driver

Guest OS: Linux 2.6.35

Page 103: ARMvisor, more details

Hardware: ARM Cortex-A8

Host OS: Linux 2.6.38

ARMvisor

Driver

QEMU 0.14

Device

Driver

Guest OS: Linux 2.6.35

5

Page 104: ARMvisor, more details

Hardware: ARM Cortex-A8

Host OS: Linux 2.6.38

ARMvisor

Driver

QEMU 0.14

Device

Driver

Guest OS: Linux 2.6.35

6

5

Page 105: ARMvisor, more details

Hardware: ARM Cortex-A8

Host OS: Linux 2.6.38

ARMvisor

Driver

QEMU 0.14

Device

Driver

Guest OS: Linux 2.6.35

76

5

Page 106: ARMvisor, more details

Hardware: ARM Cortex-A8

Host OS: Linux 2.6.38

ARMvisor

Driver

QEMU 0.14

Device

Driver

Guest OS: Linux 2.6.35

8

76

5

Page 107: ARMvisor, more details

virtio

Page 108: ARMvisor, more details

virtio

Vir,o  AMBA  Controller

Vir,o  Driver Guest

Vring Transport

Vir,o  AMBA  Controller

Vir,o  DeviceQEMU

Page 109: ARMvisor, more details

irq_chip in kernel

Page 110: ARMvisor, more details

Interrupt  ControllerOpera,ng  System

Deliver  Interrupt

Get  IRQ  number

Ack  IRQ  number1

Mask  IRQ2

End  of  IRQ3

Unmask  IRQ4

Page 111: ARMvisor, more details

irq_chip in kernel

ARMvisor�

GIC�

Device� Device� Device�

QEMU�

Guest�

IOCTL7

Deliver7IRQ7

Control7GIC7

Page 112: ARMvisor, more details

irq_chip in kernel

GIC$in$Kernel�

Device� Device� Device�

QEMU�

Guest�

KVM�

Deliver$IRQ$

Control$GIC$

Page 113: ARMvisor, more details

Future Works

Page 114: ARMvisor, more details

Future Works

Page 115: ARMvisor, more details

Future Works

• Support for ARM’s Virtualization extension

Page 116: ARMvisor, more details

Future Works

• Support for ARM’s Virtualization extension

• Cortex-A15 and beyond

Page 117: ARMvisor, more details

Future Works

• Support for ARM’s Virtualization extension

• Cortex-A15 and beyond

• SMP for host and guest

Page 118: ARMvisor, more details

Future Works

• Support for ARM’s Virtualization extension

• Cortex-A15 and beyond

• SMP for host and guest

• AArch64 Support

Page 119: ARMvisor, more details

Future Works

• Support for ARM’s Virtualization extension

• Cortex-A15 and beyond

• SMP for host and guest

• AArch64 Support

• ARMv8

Page 120: ARMvisor, more details

By the way, ...

Page 121: ARMvisor, more details

OpenSource

Page 122: ARMvisor, more details

OpenSource

• We HAVE opened source in late August, 2012.

Page 123: ARMvisor, more details

OpenSource

• We HAVE opened source in late August, 2012.

• GNU GPLv2

Page 124: ARMvisor, more details

OpenSource

• We HAVE opened source in late August, 2012.

• GNU GPLv2

• Source code of Host and Guest OS

Page 125: ARMvisor, more details

OpenSource

• We HAVE opened source in late August, 2012.

• GNU GPLv2

• Source code of Host and Guest OS

• https://github.com/SSLab-NTHU

Page 126: ARMvisor, more details

Q & A