Skip to content

Enable CET Virtualization

Chao Gao kvm lkml 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v14 Latest22 patches 30 repliesIn review
  2. v1321 patches 17 repliesSuperseded
  3. v1224 patches 26 repliesApplied
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v1123 patches23 repliesSuperseded

Changes in v14 from the cover letter

1. rename the type of guest SSP register to KVM_X86_REG_KVM and add docs for register IDs in api.rst (Sean, Xiaoyao)
2. update commit message of patch 1
3. use rdmsrq/wrmsrq() instead of rdmsrl/wrmsrl() in patch 6 (Xin)
4. split the introduction of per-guest guest_supported_xss into a separate patch. (Xiaoyao)
5. make guest FPU and VMCS consistent regarding MSR_IA32_S_CET
6. collect reviews from Xiaoyao.

Patches in v14 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/22KVM: x86: Introduce KVM_{G,S}ET_ONE_REG uAPIs supportDocumentation/virt/kvm/api.rst arch/x86/include/uapi/asm/kvm.h arch/x86/kvm/x86.c+106 -03 replies
2/22KVM: x86: Report XSS as to-be-saved if there are supported featuresarch/x86/kvm/x86.c+5 -11 reply
3/22KVM: x86: Check XSS validity against guest CPUIDsarch/x86/include/asm/kvm_host.h arch/x86/kvm/cpuid.c arch/x86/kvm/x86.c+17 -53 replies
4/22KVM: x86: Refresh CPUID on write to guest MSR_IA32_XSSarch/x86/kvm/cpuid.c arch/x86/kvm/x86.c+4 -12 replies
5/22KVM: x86: Initialize kvm_caps.supported_xssarch/x86/kvm/x86.c+8 -31 reply
6/22KVM: x86: Load guest FPU state when access XSAVE-managed MSRsarch/x86/kvm/x86.c arch/x86/kvm/x86.h+59 -15 replies
7/22KVM: x86: Add fault checks for guest CR4.CET settingarch/x86/kvm/x86.c+6 -01 reply
8/22KVM: x86: Report KVM supported CET MSRs as to-be-savedarch/x86/kvm/x86.c+18 -00 replies
9/22KVM: VMX: Introduce CET VMCS fields and control bitsarch/x86/include/asm/vmx.h+8 -00 replies
10/22KVM: x86: Enable guest SSP read/write interface with new uAPIsDocumentation/virt/kvm/api.rst arch/x86/include/uapi/asm/kvm.h arch/x86/kvm/x86.c +1 more+29 -10 replies
11/22KVM: VMX: Emulate read and write to CET MSRsarch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.c arch/x86/kvm/x86.h+102 -03 replies
12/22KVM: x86: Save and reload SSP to/from SMRAMarch/x86/kvm/smm.c arch/x86/kvm/smm.h+9 -10 replies
13/22KVM: VMX: Set up interception for CET MSRsarch/x86/kvm/vmx/vmx.c+19 -00 replies
14/22KVM: VMX: Set host constant supervisor states to VMCS fieldsarch/x86/kvm/vmx/capabilities.h arch/x86/kvm/vmx/vmx.c arch/x86/kvm/x86.c +1 more+32 -01 reply
15/22KVM: x86: Don't emulate instructions guarded by CETarch/x86/kvm/emulate.c+35 -117 replies
16/22KVM: x86: Enable CET virtualization for VMX and advertise to userspacearch/x86/include/asm/kvm_host.h arch/x86/include/asm/vmx.h arch/x86/kvm/cpuid.c +6 more+68 -70 replies
17/22KVM: nVMX: Virtualize NO_HW_ERROR_CODE_CC for L1 event injection to L2arch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/nested.h+24 -90 replies
18/22KVM: nVMX: Prepare for enabling CET support for nested guestarch/x86/kvm/vmx/nested.c arch/x86/kvm/vmx/vmcs12.c arch/x86/kvm/vmx/vmcs12.h +2 more+101 -10 replies
19/22KVM: nVMX: Add consistency checks for CR0.WP and CR4.CETarch/x86/kvm/vmx/nested.c+6 -00 replies
20/22KVM: nVMX: Add consistency checks for CET statesarch/x86/kvm/vmx/nested.c+47 -00 replies
21/22KVM: nVMX: Advertise new VM-Entry/Exit control bits for CET statearch/x86/kvm/vmx/nested.c+3 -20 replies
22/22KVM: selftest: Add tests for KVM_{GET,SET}_ONE_REGtools/arch/x86/include/uapi/asm/kvm.h tools/testing/selftests/kvm/Makefile.kvm tools/testing/selftests/kvm/x86/get_set_one_reg.c+60 -01 reply

Reviews trailers per patch

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

PatchMathias KrauseJohn AllenRick EdgecombeMaxim LevitskyChao GaoXiaoyao LiBinbin Wu
1/22T-b T-b T-b R-b
2/22T-b T-b T-b R-b R-b R-b R-b
3/22R-b
4/22T-b T-b T-b R-b R-b R-b R-b
5/22T-b T-b T-b R-b R-b R-b
6/22T-b T-b T-b R-b
7/22T-b T-b T-b R-b R-b R-b
8/22T-b T-b T-b
9/22T-b T-b T-b R-b R-b
10/22T-b T-b T-b
11/22T-b T-b T-b
12/22T-b T-b T-b
13/22T-b T-b T-b
14/22T-b T-b T-b R-b R-b
15/22T-b T-b T-b
16/22T-b T-b T-b
17/22T-b T-b T-b R-b R-b
18/22T-b T-b T-b
19/22T-b T-b T-b
20/22T-b T-b T-b
21/22
22/22

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

Read the v14 thread

Cover letter [PATCH v14 00/22] Enable CET Virtualization

The FPU support for CET virtualization has already been merged into 6.17-rc1. Building on that, this series introduces Intel CET virtualization support for KVM.

Changes in v14
1. rename the type of guest SSP register to KVM_X86_REG_KVM and add docs for register IDs in api.rst (Sean, Xiaoyao)
2. update commit message of patch 1
3. use rdmsrq/wrmsrq() instead of rdmsrl/wrmsrl() in patch 6 (Xin)
4. split the introduction of per-guest guest_supported_xss into a separate patch. (Xiaoyao)
5. make guest FPU and VMCS consistent regarding MSR_IA32_S_CET
6. collect reviews from Xiaoyao.

---
Control-flow Enforcement Technology (CET) is a kind of CPU feature used to prevent Return/CALL/Jump-Oriented Programming (ROP/COP/JOP) attacks. It provides two sub-features(SHSTK,IBT) to defend against ROP/COP/JOP style control-flow subversion attacks.

Shadow Stack (SHSTK):
A shadow stack is a second stack used exclusively for control transfer operations. The shadow stack is separate from the data/normal stack and can be enabled individually in user and kernel mode. When shadow stack is enabled, CALL pushes the return address on both the data and shadow stack. RET pops the return address from both stacks and compares them. If the return addresses from the two stacks do not match, the processor generates a #CP.

Indirect Branch Tracking (IBT):
IBT introduces new instruction(ENDBRANCH)to mark valid target addresses of indirect branches (CALL, JMP etc...). If an indirect branch is executed and the next instruction is _not_ an ENDBRANCH, the processor generates a #CP. These instruction behaves as a NOP on platforms that doesn't support CET.

CET states management
=====================
KVM cooperates with host kernel FPU framework to manage guest CET registers. With CET supervisor mode state support in this series, KVM can save/restore full guest CET xsave-managed states.

CET user mode and supervisor mode xstates, i.e., MSR_IA32_{U_CET,PL3_SSP} and MSR_IA32_PL{0,1,2}, depend on host FPU framework to swap guest and host xstates. On VM-Exit, guest CET xstates are saved to guest fpu area and host CET xstates are loaded from task/thread context before vCPU returns to userspace, vice-versa on VM-Entry. See details in kvm_{load,put}_guest_fpu().

CET supervisor mode states are grouped into two categories : XSAVE-managed and non-XSAVE-managed, the former includes MSR_IA32_PL{0,1,2}_SSP and are controlled by CET supervisor mode bit(S_CET bit) in XSS, the later consists of MSR_IA32_S_CET and MSR_IA32_INTR_SSP_TBL.

VMX introduces new VMCS fields, {GUEST|HOST}_{S_CET,SSP,INTR_SSP_TABL}, to facilitate guest/host non-XSAVES-managed states. When VMX CET entry/exit load bits are set, guest/host MSR_IA32_{S_CET,INTR_SSP_TBL,SSP} are loaded from equivalent fields at VM-Exit/Entry. With these new fields, such supervisor states require no addtional KVM save/reload actions.

Tests
======
This series has successfully passed the basic CET user shadow stack test and kernel IBT test in both L1 and L2 guests. The newly added KVM-unit-tests [2] also passed, and its v11 has been tested with the AMD CET series by John [3].

For your convenience, you can use my WIP QEMU [1] for testing.

[1]: https://github.com/gaochaointel/qemu-dev qemu-cet
[2]: https://lore.kernel.org/kvm/[email protected]/
[3]: https://lore.kernel.org/kvm/[email protected]/

Chao Gao (5):
KVM: x86: Check XSS validity against guest CPUIDs
KVM: nVMX: Add consistency checks for CR0.WP and CR4.CET
KVM: nVMX: Add consistency checks for CET states
KVM: nVMX: Advertise new VM-Entry/Exit control bits for CET state
KVM: selftest: Add tests for KVM_{GET,SET}_ONE_REG

Sean Christopherson (2):
KVM: x86: Report XSS as to-be-saved if there are supported features
KVM: x86: Load guest FPU state when access XSAVE-managed MSRs

Yang Weijiang (15):
KVM: x86: Introduce KVM_{G,S}ET_ONE_REG uAPIs support
KVM: x86: Refresh CPUID on write to guest MSR_IA32_XSS
KVM: x86: Initialize kvm_caps.supported_xss
KVM: x86: Add fault checks for guest CR4.CET setting
KVM: x86: Report KVM supported CET MSRs as to-be-saved
KVM: VMX: Introduce CET VMCS fields and control bits
KVM: x86: Enable guest SSP read/write interface with new uAPIs
KVM: VMX: Emulate read and write to CET MSRs
KVM: x86: Save and reload SSP to/from SMRAM
KVM: VMX: Set up interception for CET MSRs
KVM: VMX: Set host constant supervisor states to VMCS fields
KVM: x86: Don't emulate instructions guarded by CET
KVM: x86: Enable CET virtualization for VMX and advertise to userspace
KVM: nVMX: Virtualize NO_HW_ERROR_CODE_CC for L1 event injection to L2
KVM: nVMX: Prepare for enabling CET support for nested guest

 Documentation/virt/kvm/api.rst                |   9 +
 arch/x86/include/asm/kvm_host.h               |   5 +-
 arch/x86/include/asm/vmx.h                    |   9 +
 arch/x86/include/uapi/asm/kvm.h               |  29 ++
 arch/x86/kvm/cpuid.c                          |  17 +-
 arch/x86/kvm/emulate.c                        |  46 ++-
 arch/x86/kvm/smm.c                            |   8 +
 arch/x86/kvm/smm.h                            |   2 +-
 arch/x86/kvm/svm/svm.c                        |   4 +
 arch/x86/kvm/vmx/capabilities.h               |   9 +
 arch/x86/kvm/vmx/nested.c                     | 163 ++++++++++-
 arch/x86/kvm/vmx/nested.h                     |   5 +
 arch/x86/kvm/vmx/vmcs12.c                     |   6 +
 arch/x86/kvm/vmx/vmcs12.h                     |  14 +-
 arch/x86/kvm/vmx/vmx.c                        |  85 +++++-
 arch/x86/kvm/vmx/vmx.h                        |   9 +-
 arch/x86/kvm/x86.c                            | 264 +++++++++++++++++-
 arch/x86/kvm/x86.h                            |  61 ++++
 tools/arch/x86/include/uapi/asm/kvm.h         |  29 ++
 tools/testing/selftests/kvm/Makefile.kvm      |   1 +
 .../selftests/kvm/x86/get_set_one_reg.c       |  30 ++
 21 files changed, 764 insertions(+), 41 deletions(-)
 create mode 100644 tools/testing/selftests/kvm/x86/get_set_one_reg.c
Signature · 1 line
2.47.3