Skip to content

Enable FRED with KVM VMX

Xin Li (Intel) kvm linux-doc lkml 7 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v9 Latest22 patches 108 repliesIn review
  2. v821 patches 10 repliesSuperseded
  3. v721 patches 3 repliesSuperseded
Earlier versions · 4
VersionPostedPatchesRepliesStatus
v620 patches12 repliesSuperseded
v523 patches6 repliesSuperseded
v419 patches24 repliesSuperseded
v327 patches53 repliesApplied

Changes in v9 from the cover letter

* Rebased to the latest kvm-x86/next branch, tag kvm-x86-next-2025.10.20-2.
* Guard FRED state save/restore with guest_cpu_cap_has(vcpu, X86_FEATURE_FRED) in patch 19 (syzbot & Chao).
* Use array indexing for exception stack access, eliminating the need for the ESTACKS_MEMBERS() macro in struct cea_exception_stacks, and then exported __this_cpu_ist_top_va() in a subsequent patch (Dave Hansen).
* Rewrote some of the change logs.

Patches in v9 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/22KVM: VMX: Enable support for secondary VM exit controlsarch/x86/include/asm/msr-index.h arch/x86/include/asm/vmx.h arch/x86/kvm/vmx/capabilities.h +3 more+46 -40 replies
2/22KVM: VMX: Initialize VM entry/exit FRED controls in vmcs_configarch/x86/include/asm/vmx.h arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+11 -22 replies
3/22KVM: VMX: Disable FRED if FRED consistency checks failarch/x86/kvm/vmx/capabilities.h arch/x86/kvm/vmx/vmx.c+13 -01 reply
4/22x86/cea: Prefix event stack names with ESTACK_arch/x86/coco/sev/noinstr.c arch/x86/coco/sev/vc-handle.c arch/x86/include/asm/cpu_entry_area.h +6 more+39 -390 replies
5/22x86/cea: Use array indexing to simplify exception stack accessarch/x86/include/asm/cpu_entry_area.h arch/x86/kernel/dumpstack_64.c arch/x86/mm/cpu_entry_area.c+44 -333 replies
6/22x86/cea: Export __this_cpu_ist_top_va() to KVMarch/x86/mm/cpu_entry_area.c+6 -07 replies
7/22KVM: VMX: Initialize VMCS FRED fieldsarch/x86/include/asm/vmx.h arch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.h+71 -010 replies
8/22KVM: VMX: Set FRED MSR interceptsarch/x86/kvm/vmx/vmx.c+47 -07 replies
9/22KVM: VMX: Save/restore guest FRED RSP0arch/x86/kvm/vmx/vmx.c arch/x86/kvm/vmx/vmx.h+14 -02 replies
10/22KVM: VMX: Add support for saving and restoring FRED MSRsarch/x86/include/asm/kvm_host.h arch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.c+132 -32 replies
11/22KVM: x86: Add a helper to detect if FRED is enabled for a vCPUarch/x86/kvm/kvm_cache_regs.h+15 -05 replies
12/22KVM: VMX: Virtualize FRED event_dataarch/x86/include/asm/kvm_host.h arch/x86/include/asm/vmx.h arch/x86/kvm/svm/svm.c +2 more+40 -75 replies
13/22KVM: VMX: Virtualize FRED nested exception trackingarch/x86/include/asm/kvm_host.h arch/x86/include/asm/vmx.h arch/x86/kvm/svm/svm.c +3 more+26 -53 replies
14/22KVM: x86: Save/restore the nested flag of an exceptionDocumentation/virt/kvm/api.rst arch/x86/include/asm/kvm_host.h arch/x86/include/uapi/asm/kvm.h +2 more+43 -31 reply
15/22KVM: x86: Mark CR4.FRED as not reservedarch/x86/include/asm/kvm_host.h arch/x86/kvm/x86.h+3 -17 replies
16/22KVM: VMX: Dump FRED context in dump_vmcs()arch/x86/kvm/vmx/vmx.c+36 -72 replies
17/22KVM: x86: Advertise support for FREDarch/x86/kvm/cpuid.c+1 -08 replies
18/22KVM: nVMX: Enable support for secondary VM exit controlsarch/x86/kvm/vmx/capabilities.h arch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmcs12.c +2 more+30 -36 replies
19/22KVM: nVMX: Handle FRED VMCS fields in nested VMX contextarch/x86/kvm/vmx/capabilities.h arch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/nested.h +4 more+243 -27 replies
20/22KVM: nVMX: Validate FRED-related VMCS fieldsarch/x86/kvm/vmx/nested.c+104 -133 replies
21/22KVM: nVMX: Guard SHADOW_FIELD_R[OW] macros with VMX feature checksarch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmcs_shadow_fields.h+83 -372 replies
22/22KVM: nVMX: Enable VMX FRED controlsarch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmx.c+4 -21 reply

Reviews trailers per patch

16 of 22 patches have a Reviewed-by or Acked-by.

PatchShan KangXuelian GuoChao GaoDave HansenBinbin Wu
1/22T-b
2/22T-b T-b R-b R-b
3/22T-b T-b R-b
4/22A-b
5/22A-b
6/22A-b
7/22T-b T-b R-b R-b
8/22T-b T-b
9/22T-b T-b R-b R-b
10/22T-b T-b R-b
11/22T-b T-b T-b R-b
12/22T-b T-b
13/22T-b T-b R-b
14/22T-b R-b
15/22T-b T-b R-b
16/22T-b T-b
17/22T-b T-b R-b
18/22T-b T-b
19/22T-b T-b
20/22T-b T-b R-b
21/22T-b T-b R-b
22/22T-b T-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 5 reviewers.

Read the v9 thread

Cover letter [PATCH v9 00/22] Enable FRED with KVM VMX

This patch set enables the Intel flexible return and event delivery (FRED) architecture with KVM VMX to allow guests to utilize FRED.

The FRED architecture defines simple new transitions that change privilege level (ring transitions). The FRED architecture was designed with the following goals:

1) Improve overall performance and response time by replacing event delivery through the interrupt descriptor table (IDT event delivery) and event return by the IRET instruction with lower latency transitions.

2) Improve software robustness by ensuring that event delivery establishes the full supervisor context and that event return establishes the full user context.

The new transitions defined by the FRED architecture are FRED event delivery and, for returning from events, two FRED return instructions. FRED event delivery can effect a transition from ring 3 to ring 0, but it is used also to deliver events incident to ring 0. One FRED instruction (ERETU) effects a return from ring 0 to ring 3, while the other (ERETS) returns while remaining in ring 0. Collectively, FRED event delivery and the FRED return instructions are FRED transitions.

Intel VMX architecture is extended to run FRED guests, and the major changes are:

1) New VMCS fields for FRED context management, which includes two new event data VMCS fields, eight new guest FRED context VMCS fields and eight new host FRED context VMCS fields.

2) VMX nested-exception support for proper virtualization of stack levels introduced with FRED architecture.

Search for the latest FRED spec in most search engines with this search pattern:

site:intel.com FRED (flexible return and event delivery) specification

Although FRED and CET supervisor shadow stacks are independent CPU features, FRED unconditionally includes FRED shadow stack pointer MSRs IA32_FRED_SSP[0123], and IA32_FRED_SSP0 is just an alias of the CET MSR IA32_PL0_SSP. IOW, the state management of MSR IA32_PL0_SSP becomes an overlap area, and Sean requested that FRED virtualization to land after CET virtualization [1].

With CET virtualization now merged in v6.18, the path is clear to submit the FRED virtualization patch series :).

Changes in v9:
* Rebased to the latest kvm-x86/next branch, tag kvm-x86-next-2025.10.20-2.
* Guard FRED state save/restore with guest_cpu_cap_has(vcpu, X86_FEATURE_FRED) in patch 19 (syzbot & Chao).
* Use array indexing for exception stack access, eliminating the need for the ESTACKS_MEMBERS() macro in struct cea_exception_stacks, and then exported __this_cpu_ist_top_va() in a subsequent patch (Dave Hansen).
* Rewrote some of the change logs.

Following is the link to v8 of this patch set:
https://lore.kernel.org/lkml/[email protected]/

[1]: https://lore.kernel.org/kvm/[email protected]/

Xin Li (18):
KVM: VMX: Enable support for secondary VM exit controls
KVM: VMX: Initialize VM entry/exit FRED controls in vmcs_config
KVM: VMX: Disable FRED if FRED consistency checks fail
KVM: VMX: Initialize VMCS FRED fields
KVM: VMX: Set FRED MSR intercepts
KVM: VMX: Save/restore guest FRED RSP0
KVM: VMX: Add support for saving and restoring FRED MSRs
KVM: x86: Add a helper to detect if FRED is enabled for a vCPU
KVM: VMX: Virtualize FRED event_data
KVM: VMX: Virtualize FRED nested exception tracking
KVM: x86: Mark CR4.FRED as not reserved
KVM: VMX: Dump FRED context in dump_vmcs()
KVM: x86: Advertise support for FRED
KVM: nVMX: Enable support for secondary VM exit controls
KVM: nVMX: Handle FRED VMCS fields in nested VMX context
KVM: nVMX: Validate FRED-related VMCS fields
KVM: nVMX: Guard SHADOW_FIELD_R[OW] macros with VMX feature checks
KVM: nVMX: Enable VMX FRED controls

Xin Li (Intel) (4):
x86/cea: Prefix event stack names with ESTACK_ x86/cea: Use array indexing to simplify exception stack access x86/cea: Export __this_cpu_ist_top_va() to KVM
KVM: x86: Save/restore the nested flag of an exception

 Documentation/virt/kvm/api.rst        |  21 +-
 arch/x86/coco/sev/noinstr.c           |   4 +-
 arch/x86/coco/sev/vc-handle.c         |   2 +-
 arch/x86/include/asm/cpu_entry_area.h |  70 +++---
 arch/x86/include/asm/kvm_host.h       |  13 +-
 arch/x86/include/asm/msr-index.h      |   1 +
 arch/x86/include/asm/vmx.h            |  48 +++-
 arch/x86/include/uapi/asm/kvm.h       |   4 +-
 arch/x86/kernel/cpu/common.c          |  10 +-
 arch/x86/kernel/dumpstack_64.c        |  18 +-
 arch/x86/kernel/fred.c                |   6 +-
 arch/x86/kernel/traps.c               |   2 +-
 arch/x86/kvm/cpuid.c                  |   1 +
 arch/x86/kvm/kvm_cache_regs.h         |  15 ++
 arch/x86/kvm/svm/svm.c                |   2 +-
 arch/x86/kvm/vmx/capabilities.h       |  25 +-
 arch/x86/kvm/vmx/nested.c             | 343 +++++++++++++++++++++++---
 arch/x86/kvm/vmx/nested.h             |  22 ++
 arch/x86/kvm/vmx/vmcs.h               |   1 +
 arch/x86/kvm/vmx/vmcs12.c             |  19 ++
 arch/x86/kvm/vmx/vmcs12.h             |  40 ++-
 arch/x86/kvm/vmx/vmcs_shadow_fields.h |  37 ++-
 arch/x86/kvm/vmx/vmx.c                | 247 +++++++++++++++++--
 arch/x86/kvm/vmx/vmx.h                |  54 +++-
 arch/x86/kvm/x86.c                    | 131 +++++++++-
 arch/x86/kvm/x86.h                    |   8 +-
 arch/x86/mm/cpu_entry_area.c          |  39 ++-
 arch/x86/mm/fault.c                   |   2 +-
 include/uapi/linux/kvm.h              |   1 +
 29 files changed, 1038 insertions(+), 148 deletions(-)

base-commit: 4cc167c50eb19d44ac7e204938724e685e3d8057

Signature · 1 line
2.51.0