Search code examples
virtual-machinevirtualizationhypervisorvirtual-address-space

Do different virtual machines running on one VMM share guest physical address space?


I recall reading about how different VMs running on the same VMM (obviously) have their own independent (guest) virtual address space but they all 'share' one (guest) physical address space. That is, if a process in VM1 has its virtual address 0x000a0000 mapped to physical address 0xfffa0000, then no processes of VM2 (nor any other processes of VM1) can have any of its virtual addresses mapped to the physical address 0xfffa0000.

I can't find any documents that state this, but I know that the extended page table pointer (EPTP) is a hardware register, meaning there is only one page table that can translate the guest physical addresses into host physical addresses, so there cannot be any overlapping guest physical addresses among different VMs.
However, I also found out that the value of EPTP is saved in the virtual machine control structure (VMCS) so maybe upon vmexit or vmenter the value of EPTP can be changed between different VMs?

In short, I'd like to know if different virtual machines can (or must) share one guest physical address space.
Thanks in advance!


Solution

  • The whole point of virtualization is to make it appear to each VM that it has a machine to itself. That would not be possible if the VMM couldn’t map the same GPAs in multiple VMs. And certainly you couldn’t prevent the guest OS from mapping the same GPA into multiple processes within the guest. So there has to be a separate EPTP for each VM, which contains the GPA to HPA mappings for that VM.

    A VMM uses a separate VMCS for each VCPU in each VM, so it can leave all of the VM- and VCPU-specific state in place in the VMCS, including the EPTP, even while another VM is executing. When switching from one VM to another, the VMM loads a different VMCS pointer. The VMM writes the same EPTP value into all of the VMCSes for a single VM.