[PATCH v4 0/7] KVM: SVM: Support direct setting of VMSA for SEV-SNP guests

From: Jörg Rödel

Date: Tue Dec 01 2026 - 04:46:29 EST


From: Joerg Roedel <joerg.roedel@xxxxxxx>

Hi,

here is the updated version of KVM-AMD changes to allow user-space to
directly set the boot VMSA (direct-vmsa) for an SEV-SNP virtual
machine.

The direct-vmsa support is required for stable launch measurements
when loading the initial SEV-SNP guest image from an IGVM file.
Without this support KVM measures a VMSA at a fixed GPA for every
VCPU, which makes the launch measurement dependent on the number of
VCPUs. Besides that the current KVM VMSA-allocation behavior poses
challenges for live migration of SEV-SNP VMs. The current behavior is
fully preserved when direct-vmsa is not used.

For a longer justification have a look at this email from the v1
thread:

https://lore.kernel.org/kvm/aiqwjn2DVOumfr3T@xxxxxxxxxx/

The user-space API has slightly changes since v3 of the series and
consists of three parts:

- A new KVM_CAP_SNP_DIRECT_VMSA VM-level capability which can
be queried and enabled from user-space. When user-space
enables the capability, KVM will no longer allocate VMSA
pages when creating VCPUs. This means that the capability
can only be enabled before any VCPUs are created.

- Allow VMSA pages in SNP launch updates. This was already
present in the previous versions, but has different
semantics since v3 of the patches. In this version all it
does is adding the VMSA pages to the initial image and the
launch measurement.

- A new per-VCPU MEM_ENC operation to get and set the VMSA and
GHCB addresses of a VCPU. User-space will use this operation
to set the GPA of the launch VMSA of the VCPUs, but can
also query and set the addresses during runtime.

New in v4 is that these operatations are only allowed after
SNP_LAUNCH_FINISH and only for SEV-SNP guests.

The changes are rebased to v7.4-rc5 and tested with lockdep enabled.

Changes since v3:

- Rebase onto v7.4-rc5 and update the ABI documentation.

- Gate GHCB APIC ID list discovery on KVM_CAP_SNP_DIRECT_VMSA.

- Drop the redundant SRCU lock from the guest-owned VMSA reload path.

- Validate all direct-mode vCPUs before protecting any of them, and scope
the capability's mutex guard to fix the Clang build.

- Require successful SNP launch finish before GET or SET and require a
protected vCPU for SET. Use the GHCB registration GPA, preserve the
GHCB MSR, and report the tracked VMSA GPA across deferred reloads.

- Fix the APIC ID selftest's variadic argument type and expand coverage
of feature opt-in, launch ordering, and VMSA invalidation.

Please review.

-Joerg

Joerg Roedel (7):
KVM: SEV: Document SNP direct VMSA userspace ABI
KVM: SEV: Add direct VMSA capability
KVM: SVM: Implement GET_AP_APIC_IDS NAE event
KVM: SEV: Allow VMSA pages in SNP launch updates
KVM: SEV: Add SNP vCPU state get and set commands
KVM: selftests: Test SNP vCPU state and direct VMSA launch
KVM: selftests: Test the SNP APIC-ID-list GHCB request

.../virt/kvm/x86/amd-memory-encryption.rst | 113 ++++-
arch/x86/include/asm/kvm-x86-ops.h | 1 +
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/include/asm/sev-common.h | 1 +
arch/x86/include/uapi/asm/kvm.h | 21 +
arch/x86/include/uapi/asm/svm.h | 1 +
arch/x86/kvm/svm/sev.c | 371 +++++++++++++-
arch/x86/kvm/svm/svm.c | 24 +
arch/x86/kvm/svm/svm.h | 2 +
arch/x86/kvm/x86.c | 6 +
include/uapi/linux/kvm.h | 2 +
tools/testing/selftests/kvm/Makefile.kvm | 2 +
tools/testing/selftests/kvm/include/x86/sev.h | 103 +++-
tools/testing/selftests/kvm/lib/x86/sev.c | 79 +++
.../selftests/kvm/x86/sev_snp_apic_id_test.c | 340 +++++++++++++
.../kvm/x86/sev_snp_direct_vmsa_test.c | 476 ++++++++++++++++++
16 files changed, 1511 insertions(+), 32 deletions(-)
create mode 100644 tools/testing/selftests/kvm/x86/sev_snp_apic_id_test.c
create mode 100644 tools/testing/selftests/kvm/x86/sev_snp_direct_vmsa_test.c


base-commit: fe6ff8d5d675c01793b9f051d16055dd4aa75244
--
2.53.0