I have written a simple VMM that executes a small program under VTx. Everything is working fine with the exception of one item, if I receive an NMI while running the code that executes after the vmexit, the system crashes (this is on Windows). The issue is that before calling vmlaunch/vmresume I perform some modifications to the host state such as setting IA32_LSTAR msr to facilitate the code running under VTx as well as restoring register state, etc for the code to continue executing.
I am guessing the issue is that I have not fully restored the host to a state where the NMI can be processed and my code returned to successfully. So my question is how do I ensure that I can successfully perform all the necessary changes to get the host back to a working state before I receive an NMI?