本文主要记录SDM中Relative Priority of Faults and VM Exits一节的相关笔记。
The following principles describe the ordering between existing faults and VM exits:

  • Certain exceptions have priority over VM exits. These include invalid-opcode exceptions (#UD), faults based on privilege level, and general-protection exceptions that are based on checking I/O permission bits in the taskstate segment (TSS). For example, execution of RDMSR with CPL = 3 generates a general-protection exception and not a VM exit.

XSETBVinstruction为例:

In non-root mode,if the current privileage level is not 0, VM exit won’t happen. Because faults based on privilege level has priority over VM exits.

In non-root mode,if CR4.OSXSAVE[bit 18] = 0, VM exit won’t happen. Because invalid-opcode exceptions(#UD) has priority over VM exits.

详细内容可参考patch:hv: vmexit: refine xsetbv_vmexit_handler API

当然,这里是有一个前提的,那就是exception bitmap中#UD位为0。

如果exception bitmap中#UD位置1,那么,non-root下,只要发生#UD, 一定会发生VM Exit。
KVM unconditionally intercept UD_VECTOR.

1
2
3
kvm_arch_vcpu_create
kvm_vcpu_reset
vmx_update_exception_bitmap

In vmx_update_exception_bitmap function, UD_VECTOR is set in the EXCEPTION_BITMAP.