Xen Test Framework
NMI Taskswitch with increasing privilege

32bit versions of Windows use a Task Gate for handling #NMI, and use NMI IPIs between vCPUs in some circumstances.

A regression was introduced during the Xen 4.9 development cycle which caused a task switch which changed CPL to corrupt VMCB/VMCS state and result in a vmentry failure. To make this regression test reliable, it is simplified to a single vCPU using a self-NMI IPI to trigger the task switch.

Notes for people writing reusable x86 tasks:

x86 Tasks and hardware task switching are basically unused in practice. As a result, there is precious little information online. The following issues caught me by surprise while developing this code. Some are now obvious in retrospect, while some are not.

  • Entering a task doesn't push an exception frame, although an error code will be pushed if applicable.
  • Exiting a task overwrites all GPR state in the TSS, which gets recalled on the subsequent entry. For the task to be reusable, the iret to leave it must be immediately before the entry point.
See also
tests/nmi-taskswitch-priv/main.c