Skip to content

Commit ada014f

Browse files
pratiksampatsean-jc
authored andcommitted
KVM: selftests: Add a basic SEV-SNP smoke test
Extend sev_smoke_test to also run a minimal SEV-SNP smoke test that initializes and sets up private memory regions required to run a simple SEV-SNP guest. Similar to its SEV-ES smoke test counterpart, this also does not support GHCB and ucall yet and uses the GHCB MSR protocol to trigger an exit of the type KVM_EXIT_SYSTEM_EVENT. Signed-off-by: Pratik R. Sampat <prsampat@amd.com> Link: https://lore.kernel.org/r/20250305230000.231025-11-prsampat@amd.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent a5d55f7 commit ada014f

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

tools/testing/selftests/kvm/x86/sev_smoke_test.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,18 @@
1616

1717
#define XFEATURE_MASK_X87_AVX (XFEATURE_MASK_FP | XFEATURE_MASK_SSE | XFEATURE_MASK_YMM)
1818

19+
static void guest_snp_code(void)
20+
{
21+
uint64_t sev_msr = rdmsr(MSR_AMD64_SEV);
22+
23+
GUEST_ASSERT(sev_msr & MSR_AMD64_SEV_ENABLED);
24+
GUEST_ASSERT(sev_msr & MSR_AMD64_SEV_ES_ENABLED);
25+
GUEST_ASSERT(sev_msr & MSR_AMD64_SEV_SNP_ENABLED);
26+
27+
wrmsr(MSR_AMD64_SEV_ES_GHCB, GHCB_MSR_TERM_REQ);
28+
vmgexit();
29+
}
30+
1931
static void guest_sev_es_code(void)
2032
{
2133
/* TODO: Check CPUID after GHCB-based hypercall support is added. */
@@ -180,7 +192,10 @@ static void test_sev_smoke(void *guest, uint32_t type, uint64_t policy)
180192
{
181193
const u64 xf_mask = XFEATURE_MASK_X87_AVX;
182194

183-
test_sev(guest, type, policy | SEV_POLICY_NO_DBG);
195+
if (type == KVM_X86_SNP_VM)
196+
test_sev(guest, type, policy | SNP_POLICY_DBG);
197+
else
198+
test_sev(guest, type, policy | SEV_POLICY_NO_DBG);
184199
test_sev(guest, type, policy);
185200

186201
if (type == KVM_X86_SEV_VM)
@@ -191,7 +206,10 @@ static void test_sev_smoke(void *guest, uint32_t type, uint64_t policy)
191206
if (kvm_has_cap(KVM_CAP_XCRS) &&
192207
(xgetbv(0) & kvm_cpu_supported_xcr0() & xf_mask) == xf_mask) {
193208
test_sync_vmsa(type, policy);
194-
test_sync_vmsa(type, policy | SEV_POLICY_NO_DBG);
209+
if (type == KVM_X86_SNP_VM)
210+
test_sync_vmsa(type, policy | SNP_POLICY_DBG);
211+
else
212+
test_sync_vmsa(type, policy | SEV_POLICY_NO_DBG);
195213
}
196214
}
197215

@@ -204,5 +222,8 @@ int main(int argc, char *argv[])
204222
if (kvm_cpu_has(X86_FEATURE_SEV_ES))
205223
test_sev_smoke(guest_sev_es_code, KVM_X86_SEV_ES_VM, SEV_POLICY_ES);
206224

225+
if (kvm_cpu_has(X86_FEATURE_SEV_SNP))
226+
test_sev_smoke(guest_snp_code, KVM_X86_SNP_VM, snp_default_policy());
227+
207228
return 0;
208229
}

0 commit comments

Comments
 (0)