Notes about vt-x "acknowledge interrupt on exit" feature
本文将介绍VT-x中的”acknowledge interrupt on exit” feature。
definition
sdm中的相关描述:
description
The “acknowledge interrupt on exit” VM-exit control in the controlling VMCS controls processor behavior for external interrupt acknowledgement. If the control is 1, the processor acknowledges the interrupt controller to acquire the interrupt vector upon VM exit, and stores the vector in the VM-exit interruption-information field. If the control is 0, the external interrupt is not acknowledged during VM exit. Since RFLAGS.IF is automatically cleared on VM exits due to external interrupts, VMM re-enabling of interrupts(setting RFLAGS.IF = 1) initiates the external interrupt acknowledgement and vectoring of the external interrupt through the monitor/host IDT.
总结
- 当“acknowledge interrupt on exit” VM-exit control位为0:
当vCPU在non-root mode时,external interrupt会导致VM Exit,此时VM Exit interruption information field is marked as invalid。在root mode下,lapic的IRR对应的bit位会被置上。在root mode下,硬件会完成interrupt evaluation和interrupt recognition,当hypervisor设置RFLAGS.IF后,就会发生interrupt delivery,处理器就调用IDT对应的中断处理函数。
- 当“acknowledge interrupt on exit” VM-exit control位为1:
当vCPU在non-root mode时,external interrupt会导致VM Exit,此时VM Exit interruption information field is marked as valid,并且会记录external interrupt的vector号,此时lapic的IRR对应的bit位并没有被置上,但lapic ISR对应的bit位会被置上(logical processor acknowledges the interrupt controller)。在root mode下,由于lapic的IRR对应的bit位并没有被置上,此时就不会走interrupt evaluation和interrupt recognition这条路径了,也就不会发生interrupt delivery了,处理器不会通过IDT调用中断处理函数。此时需要hypervisor手动调用IDT的中断处理函数。
代码解析
本文参考的内核版本为v5.0。
1 | static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu) = { |
1 | static __always_inline int handle_external_interrupt(struct kvm_vcpu *vcpu) |
由代码可知,external interrupt的handler只是增加统计信息而已,并没有处理外部中断。
最终是vmx_handle_external_intr进行了外部中断的真正处理。1
2
3vcpu_run
└── vcpu_enter_guest
└── vmx_handle_external_intr[kvm_x86_ops->handle_external_intr]
1 | static void vmx_handle_external_intr(struct kvm_vcpu *vcpu) |
参考资料: