TL;DR
Yes, an unprivileged process can trigger a VMExit in a hardware-virtualized system without direct kernel cooperation, but it’s indirect. It relies on the hypervisor monitoring specific guest actions and triggering the exit based on those actions, even if initiated by user space.
Understanding VMExits
VMExits are transitions from running a virtual machine (guest) to the hypervisor (host). They happen for various reasons: accessing hardware directly, executing privileged instructions, or hitting breakpoints. The kernel isn’t *directly* involved in initiating these exits; it simply handles them when they occur.
How User Space Can Cause a VMExit
- Direct Hardware Access Attempts (Emulated): A user-space process might try to access hardware directly. However, this is usually trapped by the operating system and handled through system calls. The hypervisor then intercepts these attempts because they’re effectively trying to bypass virtualization.
- Example: Trying to read from a physical memory address without permission.
- Privileged Instruction Execution (Emulated): User-space code can attempt to execute privileged instructions (e.g., those requiring ring 0 access). These are intercepted by the OS and then, crucially, by the hypervisor.
- Example: Attempting an `SGDT` or `SLDT` instruction.
- Hypervisor-Defined Triggers: The hypervisor can be configured to trigger VMExits on specific events, regardless of whether they originate from user space.
- Example: Monitoring for writes to a particular memory page (using EPT or NPT).
- Example: Detecting the use of certain CPU features.
- VMCall/VMLAUNCH/Hypercalls: These are explicit calls from the guest OS to the hypervisor, initiated by user-space code through system calls.
- Example: A virtual device driver making a call to request access to host resources.
Practical Example (EPT/NPT Memory Monitoring)
Extended Page Tables (EPT) or Nested Page Tables (NPT) allow the hypervisor to control memory access within the guest VM. You can configure EPT/NPT to trigger a VMExit when a specific page is accessed.
- Configure EPT/NPT: Set up an EPT entry for a particular guest physical address (GPA) that triggers a #PF (Page Fault) exception when accessed.
# This is conceptual; the exact commands depend on your hypervisor. - User-Space Access: A user-space process within the VM attempts to write to that GPA.
int main() { char *addr = (char *)0x12345678; // Example GPA *addr = 'A'; return 0; } - VMExit Triggered: The hypervisor detects the access to the monitored page via EPT/NPT and triggers a VMExit.
- The kernel (host OS) then handles the VMExit, typically by logging the event or taking other appropriate action.
Important Considerations
- Hypervisor Configuration: The hypervisor *must* be configured to monitor for these events. A default installation might not trigger VMExits on all user-space actions.
- Indirect Trigger: The user space process doesn’t directly call a VMExit function; it triggers an event that the hypervisor responds to.
- Performance Impact: Excessive monitoring can significantly degrade performance.

