Skip to content

i386: Support CET for KVM

Zhao Liu kvm qemu-devel 3 versions – Applied

Status from this message: Queued, thanks.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest22 patches 1 replyApplied
  2. v423 patches 6 repliesSuperseded
  3. v320 patches 45 repliesSuperseded

Changes in v5 from the cover letter

- Drop previous patch "i386/kvm: Initialize x86_ext_save_areas[] based on KVM support", and continue to use host_cpuid to initialize x86_ext_save_areas[].
- For migration, check whether pl0_ssp is in-use instead of checking FRED & CET-SHSTK CPUIDs.
- Polish commit message of patch 6 "i386/cpu: Use x86_ext_save_areas[] for CPUID.0XD subleaves".

Patches in v5 Applied

#Subject and filesSizeRepliesApplied
1/22i386/cpu: Clean up indent style of x86_ext_save_areas[]target/i386/cpu.c+33 -250 replies
2/22i386/cpu: Clean up arch lbr xsave struct and commenttarget/i386/cpu.c target/i386/cpu.h+5 -60 replies
3/22i386/cpu: Reorganize arch lbr structure definitionstarget/i386/cpu.h+19 -190 replies
4/22i386/cpu: Make ExtSaveArea store an array of dependenciestarget/i386/cpu.c target/i386/cpu.h+65 -220 replies
5/22i386/cpu: Add avx10 dependency for Opmask/ZMM_Hi256/Hi16_ZMMtarget/i386/cpu.c+3 -60 replies
6/22i386/cpu: Use x86_ext_save_areas[] for CPUID.0XD subleavestarget/i386/cpu.c+8 -110 replies
7/22i386/cpu: Reorganize dependency check for arch lbr statetarget/i386/cpu.c+10 -160 replies
8/22i386/cpu: Drop pmu check in CPUID 0x1C encodingtarget/i386/cpu.c+9 -40 replies
9/22i386/cpu: Fix supervisor xstate initializationtarget/i386/cpu.c+6 -30 replies
10/22i386/cpu: Add missing migratable xsave featurestarget/i386/cpu.c+9 -30 replies
11/22i386/cpu: Enable xsave support for CET statestarget/i386/cpu.c target/i386/cpu.h+39 -10 replies
12/22i386/cpu: Add CET support in CR4target/i386/cpu.h target/i386/helper.c+19 -20 replies
13/22i386/cpu: Save/restore SSP0 MSR for FREDtarget/i386/cpu.h target/i386/kvm/kvm.c+19 -00 replies
14/22i386/kvm: Add save/restore support for CET MSRstarget/i386/cpu.h target/i386/kvm/kvm.c+98 -190 replies
15/22i386/kvm: Add save/restore support for KVM_REG_GUEST_SSPtarget/i386/cpu.h target/i386/kvm/kvm.c+41 -10 replies
16/22i386/cpu: Migrate MSR_IA32_PL0_SSP for FRED and CET-SHSTKtarget/i386/machine.c+23 -00 replies
17/22i386/machine: Add vmstate for cet-shstk and cet-ibttarget/i386/machine.c+52 -00 replies
18/22i386/cpu: Mark cet-u & cet-s xstates as migratabletarget/i386/cpu.c+2 -10 replies
19/22i386/cpu: Advertise CET related flags in feature wordstarget/i386/cpu.c target/i386/cpu.h+6 -40 replies
20/22i386/cpu: Enable cet-ss & cet-ibt for supported CPU modelstarget/i386/cpu.c+44 -00 replies
21/22i386/tdx: Fix missing spaces in tdx_xfam_deps[]target/i386/kvm/tdx.c+9 -90 replies
22/22i386/tdx: Add CET SHSTK/IBT into the supported CPUID by XFAMtarget/i386/kvm/tdx.c+2 -00 replies

Reviews trailers per patch

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

PatchFarrah ChenXiaoyao LiZide Chen
1/22T-b R-b
2/22T-b R-b R-b
3/22T-b R-b R-b
4/22T-b
5/22T-b R-b
6/22T-b
7/22T-b R-b
8/22T-b R-b R-b
9/22T-b R-b
10/22T-b
11/22T-b R-b
12/22T-b
13/22T-b
14/22T-b
15/22T-b R-b
16/22T-b
17/22T-b
18/22T-b
19/22T-b R-b
20/22T-b R-b
21/22T-b R-b
22/22T-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 3 reviewers.

Read the v5 thread

Cover letter [PATCH v5 00/22] i386: Support CET for KVM

Hi,

This the v4 series to support CET (CET-SHSTK & CET-IBT) in QEMU, which is based on the master branch at the commit 05f36f7c0512c ("Update version for v10.2.0-rc2 release"). And you can also find the code here:

https://gitlab.com/zhao.liu/qemu/-/tree/i386-all-for-dmr-v2.1-12-10-2025

Compared to v4 [1], v5 continues to use host_cpuid for KVM's xstate initialization and simplify the migration check for PL0_SSP MSR.

Thanks for your review!

Overview
========

Control-flow enforcement technology includes 2 x86-architectural features:
- CET shadow stack (CET-SHSTK or CET-SS).
- CET indirect branch tracking (CET-IBT).

Intel has implemented both 2 features since Sapphire Rapids (P-core) & Sierra Forest (E-core).

AMD also implemented shadow stack since Zen3 [2] - this series has considerred only-shstk case and is supposed to work on AMD platform, but I hasn't tested this on AMD.

The basic CET support (patch 11-19) includes:
* CET-S & CET-U supervisor xstates support.
* CET CPUIDs enumeration.
* CET MSRs save & load.
* CET guest SSP register (KVM treats this as a special internal register - KVM_REG_GUEST_SSP) save & load.
* Vmstates for MSRs & guest SSP.

But before CET support, there's a lot of cleanup work needed for supervisor xstate.

Before CET-S/CET-U, QEMU has already supports arch lbr as the 1st supervisor xstate. Although arch LBR has not yet been merged into KVM (still planned), this series cleans up supervisor state-related support and avoids breaking the current arch LBR in QEMU - that's what patch 2-10 are doing.

Additionally, besides KVM, this series also supports CET for TDX.

Change Log
==========

Changes Since v4:
- Drop previous patch "i386/kvm: Initialize x86_ext_save_areas[] based on KVM support", and continue to use host_cpuid to initialize x86_ext_save_areas[].
- For migration, check whether pl0_ssp is in-use instead of checking FRED & CET-SHSTK CPUIDs.
- Polish commit message of patch 6 "i386/cpu: Use x86_ext_save_areas[] for CPUID.0XD subleaves".

Changes Since v3:
- Fill CPUID 0xD subleaves from KVM CPUID instead of host CPUID for non-dynamic xstates (i.e., except AMX xstates for now).
- Save/restore/migrate MSR_IA32_PL0_SSP for FRED.
- Fix migratable_flags for FEAT_XSAVE_XSS_LO.
- Refine commit message for CET TDX support.

[1]: https://lore.kernel.org/qemu-devel/[email protected]/
[2]: https://lore.kernel.org/all/[email protected]/

Thanks and Best Regards,
Zhao
---
Chao Gao (1):
i386/cpu: Fix supervisor xstate initialization

Chenyi Qiang (1):
i386/tdx: Add CET SHSTK/IBT into the supported CPUID by XFAM

Xin Li (Intel) (2):
i386/cpu: Save/restore SSP0 MSR for FRED i386/cpu: Migrate MSR_IA32_PL0_SSP for FRED and CET-SHSTK

Yang Weijiang (5):
i386/cpu: Enable xsave support for CET states i386/kvm: Add save/restore support for CET MSRs i386/kvm: Add save/restore support for KVM_REG_GUEST_SSP i386/machine: Add vmstate for cet-shstk and cet-ibt i386/cpu: Advertise CET related flags in feature words

Zhao Liu (13):
i386/cpu: Clean up indent style of x86_ext_save_areas[] i386/cpu: Clean up arch lbr xsave struct and comment i386/cpu: Reorganize arch lbr structure definitions i386/cpu: Make ExtSaveArea store an array of dependencies i386/cpu: Add avx10 dependency for Opmask/ZMM_Hi256/Hi16_ZMM i386/cpu: Use x86_ext_save_areas[] for CPUID.0XD subleaves i386/cpu: Reorganize dependency check for arch lbr state i386/cpu: Drop pmu check in CPUID 0x1C encoding i386/cpu: Add missing migratable xsave features i386/cpu: Add CET support in CR4
i386/cpu: Mark cet-u & cet-s xstates as migratable i386/cpu: Enable cet-ss & cet-ibt for supported CPU models i386/tdx: Fix missing spaces in tdx_xfam_deps[]

 target/i386/cpu.c     | 256 +++++++++++++++++++++++++++++-------------
 target/i386/cpu.h     | 107 ++++++++++++++----
 target/i386/helper.c  |  12 ++
 target/i386/kvm/kvm.c | 117 +++++++++++++++++++
 target/i386/kvm/tdx.c |  20 ++--
 target/i386/machine.c |  75 +++++++++++++
 6 files changed, 478 insertions(+), 109 deletions(-)
Signature · 1 line
2.34.1