Interrupt Virtualization
Reference:- Hardware Assisted Virtualization Intel Virtualization Technology, by Mat as Zabalj auregui
VMX support for handling interrupts
External interrupt virtualization
mm
mm
mm
Example of handling external interrupts:
1. Guest setup:
VMM必須要先設定當external interrupt發生時 Guest會產生VM exit
(set "external-interrupt exiting" bit in VMCS)
2. CPU對external interrupt的處理
Interrupt會被自動mask, 藉由clearing RFLAGS.IF.
如果VMM使用acknowledge-on-exit的功能,
The processor acknowledges the interrupts, retrieves the host vector, and saves the interrupt in the exist-interruption-information field before transitioning control to the VMM.
再將控制權交給VMM之前, CPU會自動將Host vector取出, 把目前state存入VMCS
3. VMM處理Interrupt
如前例, 此時若acknowledge-interrupt-on-exit有設定, VMM可以直接使用Host vector去呼叫相對應的interrupt handler. 此時就跟VM無直接關係.
若沒有設定, 則VMM必須要re-enable interrupt (by setting RFLAGS.IF) to allow vectoring of external interrupts through the monitor/host IDT. 此時考慮兩種情況
[a] Host owned I/O devices
如果這個device是屬於VMM的, 那相對應的ISR會被呼叫, 此過程和一般interrupt service routine一樣. 但當ISR結束之後, VMM會檢查是此次的interrupt需要其他virtual interrupt的產生 (例如VMM接收到packet之後, 需要轉送給VM的虛擬網卡).
這時候對每個"affected virtual device", VMM會injects virtual external interrupt event.
[b] Direct pass-through I/O devices
如果這個device是屬於VM的, 此時是由VM內部driver的ISR來處理此interrupt.
- Interrupt causes VM exits to the VMM and vectoring through Host IDT to a registered handler (應該是專門給passthrough device的handler)
- VMM此時會map host vector到corresponding guest vector to inject virtual interrupt into the assigned VM.
- The guest software does EOI write to the virtual interrupt controller.
如何inject virtual interrupt?
4. 產生Virtual Interrupt
[a] 首先要檢查processor interruptibility state.
[b] 如果Processor屬於"not interruptible", VMM則使用"interrupt-window exiting"功能, 也就是說當processor變成可interrupt時, 會產生VM exit通知VMM
[c] 檢查virtual interrupt controller的狀態
- 有無使用Local APIC? 或routed through local vector table (LVT)? I/O APIC是否mask virtual interrupt?
[d] Priority:
因為virtual interrupt是被queue在VMM並且利用VM entry送入, 所以VMM可以設計不同的priority機制.
[e] Update the virtual interrupt controller state
"When the above checks have passed, before generating the virtual interrupt to the guest, the VMM updates the virtual interrupt controller state (Local-APIC, IO-APIC and/or PIC) to reflect assertion of the virtual interrupt."
[f] Inject the virtual interrupt on VM entry
VMM藉由設定VMCS去產生virtual interrupt.
當VM entry時, Processor會執行相對應的guest IDT, 完成interrupt的處理