Skip to content

RFC KVM: VMX: Introduce Intel Mode-Based Execute Control (MBEC)

Jon Kohler kvm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest18 patches 56 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/18KVM: VMX: Remove EPT_VIOLATIONS_ACC_*_BIT definesarch/x86/include/asm/vmx.h+5 -100 replies
2/18KVM: nVMX: Decouple EPT RWX bits from EPT Violation protection bitsarch/x86/include/asm/vmx.h arch/x86/kvm/mmu/paging_tmpl.h arch/x86/kvm/vmx/vmx.c+13 -50 replies
3/18KVM: x86: Add module parameter for Intel MBECarch/x86/include/asm/kvm_host.h arch/x86/kvm/x86.c+5 -04 replies
4/18KVM: VMX: add cpu_has_vmx_mbec helperarch/x86/kvm/vmx/capabilities.h+6 -02 replies
5/18KVM: x86: Add pt_guest_exec_control to kvm_vcpu_archarch/x86/include/asm/kvm_host.h+2 -03 replies
6/18KVM: VMX: Wire up Intel MBEC enable/disable logicarch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+18 -010 replies
7/18KVM: VMX: Define VMX_EPT_USER_EXECUTABLE_MASKarch/x86/include/asm/vmx.h+1 -00 replies
8/18KVM: x86/mmu: Remove SPTE_PERM_MASKarch/x86/kvm/mmu/spte.h+0 -30 replies
9/18KVM: x86/mmu: Extend access bitfield in kvm_mmu_page_rolearch/x86/include/asm/kvm_host.h arch/x86/kvm/mmu/mmu.c arch/x86/kvm/mmu/mmutrace.h +1 more+16 -83 replies
10/18KVM: VMX: Extend EPT Violation protection bitsarch/x86/include/asm/vmx.h+9 -02 replies
11/18KVM: VMX: Enhance EPT violation handler for PROT_USER_EXECarch/x86/include/asm/vmx.h arch/x86/kvm/mmu/paging_tmpl.h arch/x86/kvm/vmx/vmx.c+21 -82 replies
12/18KVM: x86/mmu: Introduce shadow_ux_maskarch/x86/kvm/mmu.h arch/x86/kvm/mmu/spte.c arch/x86/kvm/mmu/spte.h +1 more+23 -53 replies
13/18KVM: x86/mmu: Adjust SPTE_MMIO_ALLOWED_MASK to understand MBECarch/x86/include/asm/vmx.h arch/x86/kvm/mmu/spte.h+11 -84 replies
14/18KVM: x86/mmu: Extend is_executable_pte to understand MBECarch/x86/kvm/mmu/mmu.c arch/x86/kvm/mmu/mmutrace.h arch/x86/kvm/mmu/spte.h +1 more+29 -144 replies
15/18KVM: x86/mmu: Extend make_spte to understand MBECarch/x86/kvm/mmu/paging_tmpl.h arch/x86/kvm/mmu/spte.c+29 -44 replies
16/18KVM: nVMX: Setup Intel MBEC in nested secondary controlsarch/x86/kvm/vmx/nested.c+4 -02 replies
17/18KVM: VMX: Allow MBEC with EVMCSarch/x86/kvm/vmx/hyperv.c arch/x86/kvm/vmx/hyperv_evmcs.h+5 -13 replies
18/18KVM: x86: Enable module parameter for MBECarch/x86/kvm/x86.c+1 -10 replies

Reviews trailers per patch

1 of 18 patches has a Reviewed-by or Acked-by.

PatchNikolay Borisov
1/18
2/18R-b
3/18
4/18
5/18
6/18
7/18
8/18
9/18
10/18
11/18
12/18
13/18
14/18
15/18
16/18
17/18
18/18

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [RFC PATCH 00/18] KVM: VMX: Introduce Intel Mode-Based Execute Control (MBEC)

## Summary
This series introduces support for Intel Mode-Based Execute Control (MBEC) to KVM and nested VMX virtualization, aiming to significantly reduce VMexits and improve performance for Windows guests running with Hypervisor-Protected Code Integrity (HVCI).

## What?
Intel MBEC is a hardware feature, introduced in the Kabylake generation, that allows for more granular control over execution permissions. MBEC enables the separation and tracking of execution permissions for supervisor (kernel) and user-mode code. It is used as an accelerator for Microsoft's Memory Integrity [1] (also known as hypervisor-protected code integrity or HVCI).

## Why?
The primary reason for this feature is performance.

Without hardware-level MBEC, enabling Windows HVCI runs a 'software MBEC' known as Restricted User Mode, which imposes a runtime overhead due to increased state transitions between the guest's L2 root partition and the L2 secure partition for running kernel mode code integrity operations.

In practice, this results in a significant number of exits. For example, playing a YouTube video within the Edge Browser produces roughly 1.2 million VMexits/second across an 8 vCPU Windows 11 guest.

Most of these exits are VMREAD/VMWRITE operations, which can be emulated with Enlightened VMCS (eVMCS). However, even with eVMCS, this configuration still produces around 200,000 VMexits/second.

With MBEC exposed to the L1 Windows Hypervisor, the same scenario results in approximately 50,000 VMexits/second, a *24x* reduction from the baseline.

Not a typo, 24x reduction in VMexits.

## How?
This series implements core KVM support for exposing the MBEC bit in secondary execution controls (bit 22) to L1 and L2, based on configuration from user space and a module parameter 'enable_pt_guest_exec_control'. The inspiration for this series started with Mickaël's series for Heki [3], where we've extracted, refactored, and extended the MBEC-specific use case to be general-purpose.

MBEC, which appears in Linux /proc/cpuinfo as ept_mode_based_exec, splits the EPT exec bit (bit 2 in PTE) into two bits. When secondary execution control bit 22 is set, PTE bit 2 reflects supervisor mode executable, and PTE bit 10 reflects user mode executable.

The semantics for EPT violation qualifications also change when MBEC is enabled, with bit 5 reflecting supervisor/kernel mode execute permissions and bit 6 reflecting user mode execute permissions. This ultimately serves to expose this feature to the L1 hypervisor, which consumes MBEC and informs the L2 partitions not to use the software MBEC by removing bit 14 in 0x40000004 EAX [4].

## Where?
Enablement spans both VMX code and MMU code to teach the shadow MMU about the different execution modes, as well as user space VMM to pass secondary execution control bit 22. A patch for QEMU enablement is available [5].

## Testing
Initial testing has been on done on 6.12-based code with:
Guests
- Windows 11 24H2 26100.2894
- Windows Server 2025 24H2 26100.2894
- Windows Server 2022 W1H2 20348.825
Processors:
- Intel Skylake 6154
- Intel Sapphire Rapids 6444Y

## Acknowledgements
Special thanks to all contributors and reviewers who have provided valuable feedback and support for this patch series.

[1] https://learn.microsoft.com/en-us/windows/security/hardware-security/enable-virtualization-based-protection-of-code-integrity
[2] https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/nested-virtualization#enlightened-vmcs-intel
[3] https://patchwork.kernel.org/project/kvm/patch/[email protected]/
[4] https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/feature-discovery#implementation-recommendations---0x40000004
[5] https://github.com/JonKohler/qemu/tree/mbec-rfc-v1

Cc Alexander Grest <[email protected]>
Cc Nicolas Saenz Julienne <[email protected]>
Cc Madhavan T. Venkataraman <[email protected]>
Cc Mickaël Salaün <[email protected]>
Cc Tao Su <[email protected]>
Cc Xiaoyao Li <[email protected]>
Cc Zhao Liu <[email protected]>

Jon Kohler (11):
KVM: x86: Add module parameter for Intel MBEC
KVM: x86: Add pt_guest_exec_control to kvm_vcpu_arch
KVM: VMX: Wire up Intel MBEC enable/disable logic
KVM: x86/mmu: Remove SPTE_PERM_MASK
KVM: VMX: Extend EPT Violation protection bits
KVM: x86/mmu: Introduce shadow_ux_mask
KVM: x86/mmu: Adjust SPTE_MMIO_ALLOWED_MASK to understand MBEC
KVM: x86/mmu: Extend make_spte to understand MBEC
KVM: nVMX: Setup Intel MBEC in nested secondary controls
KVM: VMX: Allow MBEC with EVMCS
KVM: x86: Enable module parameter for MBEC

Mickaël Salaün (5):
KVM: VMX: add cpu_has_vmx_mbec helper
KVM: VMX: Define VMX_EPT_USER_EXECUTABLE_MASK
KVM: x86/mmu: Extend access bitfield in kvm_mmu_page_role
KVM: VMX: Enhance EPT violation handler for PROT_USER_EXEC
KVM: x86/mmu: Extend is_executable_pte to understand MBEC

Nikolay Borisov (1):
KVM: VMX: Remove EPT_VIOLATIONS_ACC_*_BIT defines

Sean Christopherson (1):
KVM: nVMX: Decouple EPT RWX bits from EPT Violation protection bits

 arch/x86/include/asm/kvm_host.h | 13 +++++----
 arch/x86/include/asm/vmx.h      | 45 ++++++++++++++++++++---------
 arch/x86/kvm/mmu.h              |  3 +-
 arch/x86/kvm/mmu/mmu.c          | 13 +++++----
 arch/x86/kvm/mmu/mmutrace.h     | 23 ++++++++++-----
 arch/x86/kvm/mmu/paging_tmpl.h  | 19 +++++++++---
 arch/x86/kvm/mmu/spte.c         | 51 ++++++++++++++++++++++++++++-----
 arch/x86/kvm/mmu/spte.h         | 36 +++++++++++++++--------
 arch/x86/kvm/mmu/tdp_mmu.c      |  2 +-
 arch/x86/kvm/vmx/capabilities.h |  6 ++++
 arch/x86/kvm/vmx/hyperv.c       |  5 +++-
 arch/x86/kvm/vmx/hyperv_evmcs.h |  1 +
 arch/x86/kvm/vmx/nested.c       |  4 +++
 arch/x86/kvm/vmx/vmx.c          | 21 ++++++++++++--
 arch/x86/kvm/vmx/vmx.h          |  7 +++++
 arch/x86/kvm/x86.c              |  4 +++
 16 files changed, 192 insertions(+), 61 deletions(-)
Signature · 1 line
2.43.0