Reputation: 2224
I am working on a kernel virtualization driver for x86 CPUs. The driver uses Intel VT-x for virtualization of some guest code.
I stumbled upon a piece of driver code that saves and restores VMM's value of LDTR, local descriptor table register, before and after running inside the VMX non-root mode. I wonder if it is something necessary on modern 64-bit operating systems, specifically on Linux and Windows.
For the purposes of correct guest operation, its guest LDTR values is loaded and saved in the VMCS fields at appropriate moments, which is fine because we cannot make assumptions about the register being non-zero.
When it comes to the host value, it is not saved anywhere in the VMCS before entry. At the VM-exit, the value is zeroed out, as SDM volume 3 section 28.5.2, says that:
The host-state area does not contain a selector field for LDTR. LDTR is established as follows on all VM exits: the selector is cleared to 0000H, the segment is marked unusable and is otherwise undefined.
I wonder if I can safely remove this code supporting state management of host's LDTR.
My assumption is that the OSes themselves never normally read nor write this register.
Searching through Linux sources shows that lldt
instruction is possibly invoked in some paravirtualization context, and sldt
is only used to print value after a kernel panic.
For Windows, I find some hints that there is no direct API to operate on LDTR, but does that mean it is not used by the OS itself?
Upvotes: 1
Views: 34