# X86 虚拟化

X86 虚拟化是一组硬件与软件技术，使多个操作系统能够在单个 x86 或 x86-64 处理器上隔离运行。Microsoft Hyper-V 和 Linux KVM 等现代虚拟机监控器直接建立在这些扩展之上<sup>[1](https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/hyper-v-architecture)</sup><sup> • </sup><sup>[2](https://www.kernel.org/doc/html/latest/virt/kvm/x86/index.html)</sup>。

| 关键事实 | 详情 |
|---|---|
| Intel 扩展 | 虚拟机扩展（VMX）：虚拟机监控器运行于 VMX 根操作模式，客户机运行于 VMX 非根操作模式，二者之间的切换称为 VM 进入与 VM 退出<sup>[3](https://cdrdv2-public.intel.com/812396/326019-sdm-vol-3c.pdf)</sup> |
| AMD 扩展 | AMD-V，通过安全虚拟机（SVM）扩展实现；VMRUN 指令进入由虚拟机控制块（VMCB）描述的客户机<sup>[4](https://docs.amd.com/api/khub/documents/sD1_QL~h4Afq2_tvzxqqSQ/content)</sup> |
| 内存转换 | 二级地址转换，Intel 上称为扩展页表（EPT），AMD 上称为嵌套页表（NPT）；Windows Server 2016 及更高版本上的 Hyper-V 要求此功能<sup>[1](https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/hyper-v-architecture)</sup><sup> • </sup><sup>[5](https://learn.microsoft.com/en-us/windows-server/administration/performance-tuning/role/hyper-v-server/configuration)</sup> |
| I/O 虚拟化 | Intel VT-d 和 AMD-Vi（IOMMU）重映射设备 DMA 地址，并提供中断重映射以实现设备隔离<sup>[6](https://docs.kernel.org/driver-api/vfio.html)</sup> |
| 嵌套虚拟化 | KVM 的嵌套 VMX 特性允许客户机虚拟机监控器使用 VMX 指令；自 Linux 内核 v4.20 起默认启用<sup>[7](https://cdn.kernel.org/doc/html/latest/virt/kvm/x86/nested-vmx.html)</sup> |
| 性能 | 实测 VM 工作负载平均比原生环境低 5% 到 20%，VM 退出是开销的主要来源之一<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/improving-performance-vm-workloads-opt-poll-time.html)</sup> |
| 机密计算 | AMD SEV-SNP 为加密虚拟机增加内存完整性保护和客户机 attestation<sup>[9](https://www.amd.com/en/developer/sev.html)</sup> |

## 处理器虚拟化扩展

**Intel VMX。** Intel 虚拟机扩展定义了两种处理器操作模式。虚拟机监控器（VMM）运行于 VMX 根操作模式，保留对处理器资源、物理内存、中断管理和 I/O 的选择性控制；客户机软件运行于权限受限的 VMX 非根操作模式，因此 VMM 始终掌控平台<sup>[3](https://cdrdv2-public.intel.com/812396/326019-sdm-vol-3c.pdf)</sup>。进入非根操作模式称为 VM 进入，返回根操作模式称为 VM 退出。某些指令和事件——例如缺页异常或试图修改控制寄存器——本应正常处理，却会触发 VM 退出，交由虚拟机监控器处理<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/improving-performance-vm-workloads-opt-poll-time.html)</sup>。客户机状态通过虚拟机控制结构（VMCS）管理，客户机只能通过 VMREAD 和 VMWRITE 指令访问该结构<sup>[3](https://cdrdv2-public.intel.com/812396/326019-sdm-vol-3c.pdf)</sup>。

**AMD SVM。** AMD 的对应方案——安全虚拟机扩展——以 VMRUN 指令为核心。VMRUN 接受一个 4 KB 对齐的虚拟机控制块（VMCB）的物理地址，该控制块列明需要拦截的指令或事件、客户机执行环境的控制位，以及客户机保存的处理器状态<sup>[4](https://docs.amd.com/api/khub/documents/sD1_QL~h4Afq2_tvzxqqSQ/content)</sup>。VMRUN 仅在特权级 0 可用，且要求设置 EFER.SVME；处理器将宿主状态保存到宿主状态保存区，并从 VMCB 加载客户机状态<sup>[4](https://docs.amd.com/api/khub/documents/sD1_QL~h4Afq2_tvzxqqSQ/content)</sup>。AMD 的优化指南指出，世界切换——即 VMRUN 与 #VMEXIT 这一对操作及其周围的软件——是处理器周期的重要消耗者，并建议降低世界切换的频率<sup>[10](https://www.amd.com/content/dam/amd/en/documents/archived-tech-docs/software-optimization-guides/40546.pdf)</sup>。

## 内存虚拟化

客户机操作系统期望控制自己的页表，但虚拟机监控器必须确保客户机无法触及分配范围之外的内存。存在两种方法。在影子页表中，虚拟机监控器维护影子页表，将客户机虚拟地址直接映射到宿主物理地址，并与客户机页表保持同步；当客户机修改自身页表时，由 VMM 负责更新影子页表<sup>[4](https://docs.amd.com/api/khub/documents/sD1_QL~h4Afq2_tvzxqqSQ/content)</sup>。在二维分页中，硬件执行两次转换：Intel 的扩展页表和 AMD 的嵌套页表在硬件中将客户机物理地址转换为宿主物理地址，因此客户机可以直接使用自己的页表<sup>[11](https://docs.kernel.org/virt/kvm/x86/mmu.html)</sup>。

KVM 文档直接描述了这个权衡：当所需转换次数与硬件支持的能力匹配时，内存管理单元以直接模式运行；否则以影子模式运行，后者更复杂也更慢<sup>[11](https://docs.kernel.org/virt/kvm/x86/mmu.html)</sup>。Microsoft 将这一硬件特性称为[二级地址转换](https://www.edgepedia.org/zh/second-level-address-translation)（SLAT），Hyper-V 在 [Windows Server 2016](https://www.edgepedia.org/zh/windows-server-2016) 及更高版本上要求此功能<sup>[1](https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/hyper-v-architecture)</sup>。

## I/O 虚拟化

处理器扩展虚拟化了计算和内存，但设备需要自己的机制。Intel VT-d 和 AMD-Vi 提供输入输出内存管理单元（IOMMU），将设备发出的 DMA 请求中的地址转换为相应的宿主物理地址，为每个虚拟机提供私有的 I/O 空间，并防止未经授权的 DMA 访问系统内存或内存映射 I/O<sup>[6](https://docs.kernel.org/driver-api/vfio.html)</sup><sup> • </sup><sup>[12](https://instinct.docs.amd.com/projects/amdgpu-docs/en/31.20.0-preview/conceptual/iommu.html)</sup>。[IOMMU](https://www.edgepedia.org/zh/iommu) 还为多核平台提供中断重映射<sup>[12](https://instinct.docs.amd.com/projects/amdgpu-docs/en/31.20.0-preview/conceptual/iommu.html)</sup><sup> • </sup><sup>[19](https://cdrdv2-public.intel.com/831418/vt-directed-io-spec.pdf)</sup>。

在 Linux 上，VFIO 框架利用这些 IOMMU 设施，在受 IOMMU 保护的安全环境中向用户空间暴露直接的设备访问。虚拟机使用设备分配以获得最高的 I/O 性能，使 VM 成为用户空间驱动程序，从而降低延迟、提高带宽，并直接使用裸机设备驱动<sup>[6](https://docs.kernel.org/driver-api/vfio.html)</sup>。单根 I/O 虚拟化（SR-IOV）对此形成补充，它将单个适配器端口划分为多个虚拟功能，可分配给不同的客户机<sup>[13](https://builders.intel.com/docs/Open_Standard_Virtualization_White_Paper_v2013-06-25.pdf)</sup>。

## 虚拟机监控器实现

**Hyper-V** 是直接运行在硬件之上、虚拟化处理器和内存的 Type 1 虚拟机监控器。它将隔离组织为分区：运行 Windows 的根分区拥有虚拟化栈，并可直接访问物理 I/O 设备；子分区承载客户机操作系统，只能看到虚拟设备（VDev）。来自子分区的设备请求通过 VMBus——一种分区间的逻辑通信通道——重定向到根分区中的虚拟化服务提供者（VSP），由客户机中的虚拟化服务客户端（VSC）处理；此过程对客户机操作系统透明<sup>[1](https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/hyper-v-architecture)</sup>。 enlightened I/O 是一种感知虚拟化的协议实现（如 SCSI），直接使用 VMBus 并绕过设备模拟，使这种通信更高效，但要求客户机感知虚拟机监控器<sup>[1](https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/hyper-v-architecture)</sup>。Hyper-V 要求硬件辅助虚拟化（Intel VT 或 AMD-V），且自 Windows Server 2016 起要求 SLAT<sup>[1](https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/hyper-v-architecture)</sup>。

**KVM** 将 [Linux 内核](https://www.edgepedia.org/zh/linux-kernel)本身变为虚拟机监控器。其 x86 内存管理代码向客户机呈现标准 x86 MMU，同时将客户机物理地址转换为宿主物理地址，支持第一代硬件（原子分页模式切换）和二维分页（NPT 和 EPT）<sup>[11](https://docs.kernel.org/virt/kvm/x86/mmu.html)</sup>。KVM 还向客户机暴露厂商超级调用指令，将客户机的 VMCALL/VMMCALL 指令重写以匹配系统厂商<sup>[14](https://kernel.org/doc/html/v6.1/virt/kvm/api.html)</sup>。

## 嵌套虚拟化

嵌套虚拟化在虚拟机内部运行虚拟机监控器。KVM 文档使用三级术语：L0 是运行 KVM 的裸机宿主，L1 是客户机虚拟机监控器，L2 是嵌套客户机<sup>[7](https://cdn.kernel.org/doc/html/latest/virt/kvm/x86/nested-vmx.html)</sup>。通常 VMX 客户机不能自己使用 VMX 指令；KVM 的嵌套 VMX 特性允许客户机使用 VMX 指令，并利用单层硬件 VMX 正确高效地模拟它们<sup>[7](https://cdn.kernel.org/doc/html/latest/virt/kvm/x86/nested-vmx.html)</sup>。该特性自 Linux 内核 v4.20 起默认启用，其 ABI 为 Intel 的 VMX 规范，但并非所有 VMX 特性都得到完全支持<sup>[7](https://cdn.kernel.org/doc/html/latest/virt/kvm/x86/nested-vmx.html)</sup>。使用场景包括：在一台租用的云 VM 中测试多个操作系统上的软件、为负载均衡而对客户机虚拟机监控器进行实时迁移，以及在内部使用虚拟化实现安全隔离的操作系统<sup>[15](https://docs.kernel.org/virt/kvm/x86/running-nested-guests.html)</sup>。在 Intel x86 上，自 Linux 内核 5.3 和 QEMU 4.2.0 起，运行着嵌套客户机的 L1 客户机可以[实时迁移](https://www.edgepedia.org/zh/live-migration)；在 AMD 系统上，当 L2 客户机运行时迁移或保存 L1 客户机会产生未定义行为<sup>[15](https://docs.kernel.org/virt/kvm/x86/running-nested-guests.html)</sup>。

## 性能

VM 退出是[硬件虚拟化](https://www.edgepedia.org/zh/hardware-virtualization)的主要成本：每次退出都用向虚拟机监控器的切换取代了常规处理器行为，而响应指令和事件（如缺页异常）的退出是性能下降的关键来源<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/improving-performance-vm-workloads-opt-poll-time.html)</sup>。Intel 对 Android 和 Crostini VM 环境的测量发现，与原生环境相比平均性能差距为 5% 到 20%，VM 退出集中在 HLT、定时器和处理器间中断事件上<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/improving-performance-vm-workloads-opt-poll-time.html)</sup>。停机轮询优化让宿主在调度另一个线程之前短暂轮询，而不是在 HLT 上触发 VM 退出，使这些工作负载提升 2% 到 5%，并将 Android 工作负载的上下文切换平均减少 18%<sup>[8](https://www.intel.com/content/www/us/en/developer/articles/technical/improving-performance-vm-workloads-opt-poll-time.html)</sup>。

在 Hyper-V 上，主要的软件手段是半虚拟化：集成服务为 Hyper-V 专用 I/O 设备提供可感知虚拟化的驱动，与模拟设备相比显著降低 CPU 开销，Microsoft 建议在每个受支持的 VM 中安装这些驱动，作为首要的调优步骤<sup>[16](https://learn.microsoft.com/en-us/windows-server/administration/performance-tuning/role/hyper-v-server/processor-performance)</sup>。

## 迁移与兼容性

由于虚拟机监控器将宿主处理器特性透传给客户机，在不同 CPU 的宿主之间移动运行中的 VM 可能导致已开始使用目标机所缺特性的软件崩溃。Hyper-V 在每次实时迁移或保存/恢复开始时检查特性集，若不匹配则取消操作<sup>[17](https://learn.microsoft.com/en-us/windows-server/virtualization/hyper-v/processor-compatibility-mode)</sup>。处理器兼容模式必须按 VM 启用，它呈现一组有限的公共特性，隐藏较新的指令集；Windows Server 2025 引入的动态处理器兼容性则计算整个集群的公共特性集，使 VM 使用集群内所有主机都具备的最大能力<sup>[17](https://learn.microsoft.com/en-us/windows-server/virtualization/hyper-v/processor-compatibility-mode)</sup>。即使启用了兼容模式，VM 也不能在不同处理器厂商的宿主之间移动，例如从 Intel 移到 AMD<sup>[17](https://learn.microsoft.com/en-us/windows-server/virtualization/hyper-v/processor-compatibility-mode)</sup>。

## 机密计算

硬件虚拟化扩展也已成为机密计算的基础，在机密计算中客户机不信任虚拟机监控器。AMD 的安全加密虚拟化（SEV）加密客户机内存，SEV-SNP 通过完整性保护和客户机 attestation 强化 VM 隔离；反向映射表提供内存完整性，抵御控制页表的对手，客户机通过 GHCB 等协议与虚拟机监控器通信<sup>[9](https://www.amd.com/en/developer/sev.html)</sup><sup> • </sup><sup>[18](https://arxiv.org/abs/2608.04039)</sup>。KVM 将 SEV 和 Intel 信任域扩展（TDX）作为独立的 x86 特性予以支持<sup>[2](https://www.kernel.org/doc/html/latest/virt/kvm/x86/index.html)</sup>。

## References

1. [Hyper-V Architecture, Microsoft Learn](https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/hyper-v-architecture)
2. [KVM for x86 systems, The Linux Kernel documentation](https://www.kernel.org/doc/html/latest/virt/kvm/x86/index.html)
3. [Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 3C](https://cdrdv2-public.intel.com/812396/326019-sdm-vol-3c.pdf)
4. [AMD64 Architecture Programmer's Manual, Volume 2: System Programming](https://docs.amd.com/api/khub/documents/sD1_QL~h4Afq2_tvzxqqSQ/content)
5. [Hyper-V Configuration, Microsoft Learn](https://learn.microsoft.com/en-us/windows-server/administration/performance-tuning/role/hyper-v-server/configuration)
6. [VFIO - "Virtual Function I/O", The Linux Kernel documentation](https://docs.kernel.org/driver-api/vfio.html)
7. [Nested VMX, The Linux Kernel documentation](https://cdn.kernel.org/doc/html/latest/virt/kvm/x86/nested-vmx.html)
8. [VM workloads performance, Intel](https://www.intel.com/content/www/us/en/developer/articles/technical/improving-performance-vm-workloads-opt-poll-time.html)
9. [AMD Secure Encrypted Virtualization (SEV), AMD](https://www.amd.com/en/developer/sev.html)
10. [Software Optimization Guide for AMD Family 10h and 12h Processors](https://www.amd.com/content/dam/amd/en/documents/archived-tech-docs/software-optimization-guides/40546.pdf)
11. [The x86 kvm shadow mmu, The Linux Kernel documentation](https://docs.kernel.org/virt/kvm/x86/mmu.html)
12. [Input-Output Memory Management Unit (IOMMU), AMD GPU Driver documentation](https://instinct.docs.amd.com/projects/amdgpu-docs/en/31.20.0-preview/conceptual/iommu.html)
13. [High Performance, Open Standard Virtualization with NFV and SDN, Intel white paper](https://builders.intel.com/docs/Open_Standard_Virtualization_White_Paper_v2013-06-25.pdf)
14. [The Definitive KVM API Documentation, The Linux Kernel documentation](https://kernel.org/doc/html/v6.1/virt/kvm/api.html)
15. [Running nested guests with KVM, The Linux Kernel documentation](https://docs.kernel.org/virt/kvm/x86/running-nested-guests.html)
16. [Hyper-V processor performance, Microsoft Learn](https://learn.microsoft.com/en-us/windows-server/administration/performance-tuning/role/hyper-v-server/processor-performance)
17. [Processor compatibility for Hyper-V virtual machines, Microsoft Learn](https://learn.microsoft.com/en-us/windows-server/virtualization/hyper-v/processor-compatibility-mode)
18. [AMD SEV-SNP: A Confidential Computing Primer, arXiv](https://arxiv.org/abs/2608.04039)
19. [Vt Directed Io Spec.pdf, cdrdv2-public.intel.com](https://cdrdv2-public.intel.com/831418/vt-directed-io-spec.pdf)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Processors & processor engineering › Instruction set architectures › x86 and x86-64

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/x86-virtualization

English original: https://www.edgepedia.org/x86-virtualization
