nested virtualization friendly kvm...nested virtualization friendly kvm sheng yang, qing he, eddie...

15
Software & Services Group Nested Virtualization Friendly KVM Sheng Yang, Qing He, Eddie Dong 1

Upload: others

Post on 22-Jan-2021

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Nested Virtualization Friendly KVM...Nested Virtualization Friendly KVM Sheng Yang, Qing He, Eddie Dong 1 Software & Services Group Virtualization vs. Nested Virtualization • Single-Layer

Software & Services Group

Nested Virtualization Friendly KVM

Sheng Yang, Qing He, Eddie Dong

1

Page 2: Nested Virtualization Friendly KVM...Nested Virtualization Friendly KVM Sheng Yang, Qing He, Eddie Dong 1 Software & Services Group Virtualization vs. Nested Virtualization • Single-Layer

Software & Services Group

Virtualization vs. Nested Virtualization

• Single-Layer

Virtualization

• Multi-Layer (Nested)

Virtualization

2

HW Platform

VMM

Virtual Platform

(L0) HW Platform

(L0) VMM

(L1) Virtual Platform

(L1) VMM

(L2) Virtual Platform

Page 3: Nested Virtualization Friendly KVM...Nested Virtualization Friendly KVM Sheng Yang, Qing He, Eddie Dong 1 Software & Services Group Virtualization vs. Nested Virtualization • Single-Layer

Software & Services Group

Challenge of Nested Virtualization

• Ideal virtualization model:

– The Virtual Platform is exactly the same as the real

hardware platform, except for timing/performance.

– However, commercial VMM typically presents only a

subset of hardware features in the virtual platform

• Enough to accommodate commercial OS

• But can’t run the VMM inside � No nested virtualization

– KVM/Xen/Vmware/Hyper-V are all examples

• Challenges of nested virtualization:

– Present full underlying hardware features to the virtual

platform efficiently, such as VMX, EPT.

3

Page 4: Nested Virtualization Friendly KVM...Nested Virtualization Friendly KVM Sheng Yang, Qing He, Eddie Dong 1 Software & Services Group Virtualization vs. Nested Virtualization • Single-Layer

Software & Services Group

Nested Virtualization: Virtual VMX

• Virtual VMX • Significant virtualization

overhead was observed

due to shadow page fault

in L1 VMM

– Kernel build in L2 guest is

only 1/3 of L1 guest

4

L0 VMM

L2 Guest

VMCS02VMCS01

VMCS12

L0

L1

L2

L1 VMM

VM exit/entry to L1 guest

VM exit/entry to L2 guest

Shadowing

Page 5: Nested Virtualization Friendly KVM...Nested Virtualization Friendly KVM Sheng Yang, Qing He, Eddie Dong 1 Software & Services Group Virtualization vs. Nested Virtualization • Single-Layer

Software & Services Group

Nested Virtualization: Virtual EPT

• Shadow-like virtual EPT– Write-protection guest EPT table

• Update sEPT when gEPT

changes

– Directly invept of guest

– May suffer from global lock

• VTLB-like virtual EPT– No write-protection to gEPT

– Trap-and-emulate guest INVEPT

• Updating sEPT when cached

mappings may (?) be changed

– Better SMP scalability (Preferred)

5

Guest EPT Table(gEPT)

Cachedmappings

Shadow EPT Table(sEPT)

Guest

(L1 VMM)

L0 VMM

Guest EPT Table(gEPT)

Cachedmappings

Shadow EPT Table(sEPT)

Guest

(L1 VMM)

L0 VMM

Prefer VTLB-like virtual EPT for better scalability!Prefer VTLB-like virtual EPT for better scalability!

Page 6: Nested Virtualization Friendly KVM...Nested Virtualization Friendly KVM Sheng Yang, Qing He, Eddie Dong 1 Software & Services Group Virtualization vs. Nested Virtualization • Single-Layer

Software & Services Group

Performance Challenges

• L1 VMM VMCS register access is trapped-and-

emulated by L0 VMM

– An L1 VM exit may trigger tens of VMCS access,

which is trapped-and-emulated by L0 VMM

– Emulation of INVEPT is extremely expensive

• The entire sEPT has to be re-generated ☺

• Reducing the frequency of L1 VM exit is key

– Virtual EPT significantly improves performance

– Virtual VT-d etc.

– Nested virtualization friendly guest

6

Page 7: Nested Virtualization Friendly KVM...Nested Virtualization Friendly KVM Sheng Yang, Qing He, Eddie Dong 1 Software & Services Group Virtualization vs. Nested Virtualization • Single-Layer

Software & Services Group

Optimizations

• Minimize the frequency of L1 VM exit

– Build as possible as static guest EPT table

– Mitigate the host swap activity in L1 VMM

– Cross-layer I/O para-virtualization

• Accelerate handling of virtual VM exit

– Minimize privilege resource access per virtual VM exit

• Such as VMCS access

– Avoid unnecessary INVEPT

– Choose efficient operands

7

Page 8: Nested Virtualization Friendly KVM...Nested Virtualization Friendly KVM Sheng Yang, Qing He, Eddie Dong 1 Software & Services Group Virtualization vs. Nested Virtualization • Single-Layer

Software & Services Group

Pre-build vs. On-demand EPT

• On-demand build of EPT hurts nested

virtualization

– KVM sets up EPT table on demand so far

– Page age checking of LRU zaps EPT entry

8

A command line option for static EPT ?A command line option for static EPT ?

Time Spent for 1st Round Touch of Guest

Memory (1GB)

0

1

2

3

4

5

On demand

EPT

Pre-build

EPT

Seconds Guest Run Time

Host MemoryPre-Alloc Time

3.1X Fast

Page 9: Nested Virtualization Friendly KVM...Nested Virtualization Friendly KVM Sheng Yang, Qing He, Eddie Dong 1 Software & Services Group Virtualization vs. Nested Virtualization • Single-Layer

Software & Services Group

Mitigate the Host Swap Activity

• Virtual host swap is expensive in L1 VMM

– It may generate up to ~4K/s EPT table modification

– Emulation of INVEPT has to zap and rebuilt the entire

shadow EPT table in vTLB-like virtual EPT

• L0 VMM may defer part of the shadow EPT rebuilt effort

9

Retain host swap in L0 VMM rather than L1 VMM by

presenting enough pseudo memory to L1 guest

Retain host swap in L0 VMM rather than L1 VMM by

presenting enough pseudo memory to L1 guest

Page 10: Nested Virtualization Friendly KVM...Nested Virtualization Friendly KVM Sheng Yang, Qing He, Eddie Dong 1 Software & Services Group Virtualization vs. Nested Virtualization • Single-Layer

Software & Services Group

Cross-Layer I/O Paravirualization

• Backend service from L1 may

trigger tremendous VM exit to

L0

• Can L0 directly service L2 I/O ?

– Network is stateless

– Cooperation between L1/L2 BE

10

L0 VMM

L1 VMM

L2 Guest

FE

BE

L0 VMM

L1 VMM

L2 Guest

FEBE

Give some data here: How L1 BE overhead is?Give some data here: How L1 BE overhead is?

BE

Page 11: Nested Virtualization Friendly KVM...Nested Virtualization Friendly KVM Sheng Yang, Qing He, Eddie Dong 1 Software & Services Group Virtualization vs. Nested Virtualization • Single-Layer

Software & Services Group

Accelerate Handling of Virtual VM exit

• # of privilege resource (VMCS) access in virtual

VM exit handler (top 3)

11

Extending cache_reg to efficiently reduce average VMCS access # !Extending cache_reg to efficiently reduce average VMCS access # !

0 1 2 3 4 5 6

GUEST_RFLAGS

GUEST_INTERRUPTIBILITY_INFO

GUEST_CS_SELECTOR

Avg. Access #

Read

Write

Page 12: Nested Virtualization Friendly KVM...Nested Virtualization Friendly KVM Sheng Yang, Qing He, Eddie Dong 1 Software & Services Group Virtualization vs. Nested Virtualization • Single-Layer

Software & Services Group

Avoid Unnecessary INVEPT

• Emulation of INVEPT in vTLB-like virtual EPT

implementation has to remove the entire sEPT

table

– Extreme heavy cost ☺

12

INVEPT During Qemu BuildINVEPT During Qemu BuildINVEPT During Qemu BuildINVEPT During Qemu Build

0

20

40

60

2.6.25 2.6.31 2.6.32 2.6.33 2.6.34

Linux (KVM) version

Frequency (Hz)

kvm_mmu_flush_tlb

CR3 opt.

CR0.ts opt.

Page 13: Nested Virtualization Friendly KVM...Nested Virtualization Friendly KVM Sheng Yang, Qing He, Eddie Dong 1 Software & Services Group Virtualization vs. Nested Virtualization • Single-Layer

Software & Services Group

Efficient Operands in VMCS

Access• Register operands can be easily emulated by L0

VMM, while memory operand is expansive

– Access of L1 memory needs additional map and un-

map in L0 VMM

13

So far KVM uses register operand for VMCS

read/write, keep the good behavior ☺

So far KVM uses register operand for VMCS

read/write, keep the good behavior ☺

0

500

1000

1500

2000

2500

3000

Read Write

Emulation Cost (Cycles)

Register Operand

Memory Operand

Page 14: Nested Virtualization Friendly KVM...Nested Virtualization Friendly KVM Sheng Yang, Qing He, Eddie Dong 1 Software & Services Group Virtualization vs. Nested Virtualization • Single-Layer

Software & Services Group

Performance Status

14

42434445464748495051

2.6.31 2.6.32 2.6.33 2.6.34 2.6.35-

rc5

w/ vmcs

caching

KB Time (Seconds)

Page 15: Nested Virtualization Friendly KVM...Nested Virtualization Friendly KVM Sheng Yang, Qing He, Eddie Dong 1 Software & Services Group Virtualization vs. Nested Virtualization • Single-Layer

Software & Services Group

15