Skip to content

Commit 68ed692

Browse files
pratiksampatsean-jc
authored andcommitted
KVM: selftests: SEV-SNP test for KVM_SEV_INIT2
Add the X86_FEATURE_SEV_SNP CPU feature to the architectural definition for the SEV-SNP VM type to exercise the KVM_SEV_INIT2 call. Ensure that the SNP test is skipped in scenarios where CPUID supports it but KVM does not, preventing reporting of failure in such cases. Reviewed-by: Nikunj A Dadhania <[email protected]> Signed-off-by: Pratik R. Sampat <[email protected]> Link: https://lore.kernel.org/r/[email protected] [sean: use the same pattern as SEV and SEV-ES] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 45eb291 commit 68ed692

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

tools/testing/selftests/kvm/include/x86/processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ struct kvm_x86_cpu_feature {
203203
#define X86_FEATURE_IDLE_HLT KVM_X86_CPU_FEATURE(0x8000000A, 0, EDX, 30)
204204
#define X86_FEATURE_SEV KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 1)
205205
#define X86_FEATURE_SEV_ES KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 3)
206+
#define X86_FEATURE_SEV_SNP KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 4)
206207
#define X86_FEATURE_PERFMON_V2 KVM_X86_CPU_FEATURE(0x80000022, 0, EAX, 0)
207208
#define X86_FEATURE_LBR_PMC_FREEZE KVM_X86_CPU_FEATURE(0x80000022, 0, EAX, 2)
208209

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
int kvm_fd;
2929
u64 supported_vmsa_features;
3030
bool have_sev_es;
31+
bool have_snp;
3132

3233
static int __sev_ioctl(int vm_fd, int cmd_id, void *data)
3334
{
@@ -83,6 +84,9 @@ void test_vm_types(void)
8384
if (have_sev_es)
8485
test_init2(KVM_X86_SEV_ES_VM, &(struct kvm_sev_init){});
8586

87+
if (have_snp)
88+
test_init2(KVM_X86_SNP_VM, &(struct kvm_sev_init){});
89+
8690
test_init2_invalid(0, &(struct kvm_sev_init){},
8791
"VM type is KVM_X86_DEFAULT_VM");
8892
if (kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SW_PROTECTED_VM))
@@ -138,15 +142,24 @@ int main(int argc, char *argv[])
138142
"sev-es: KVM_CAP_VM_TYPES (%x) does not match cpuid (checking %x)",
139143
kvm_check_cap(KVM_CAP_VM_TYPES), 1 << KVM_X86_SEV_ES_VM);
140144

145+
have_snp = kvm_cpu_has(X86_FEATURE_SEV_SNP);
146+
TEST_ASSERT(have_snp == !!(kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SNP_VM)),
147+
"sev-snp: KVM_CAP_VM_TYPES (%x) indicates SNP support (bit %d), but CPUID does not",
148+
kvm_check_cap(KVM_CAP_VM_TYPES), KVM_X86_SNP_VM);
149+
141150
test_vm_types();
142151

143152
test_flags(KVM_X86_SEV_VM);
144153
if (have_sev_es)
145154
test_flags(KVM_X86_SEV_ES_VM);
155+
if (have_snp)
156+
test_flags(KVM_X86_SNP_VM);
146157

147158
test_features(KVM_X86_SEV_VM, 0);
148159
if (have_sev_es)
149160
test_features(KVM_X86_SEV_ES_VM, supported_vmsa_features);
161+
if (have_snp)
162+
test_features(KVM_X86_SNP_VM, supported_vmsa_features);
150163

151164
return 0;
152165
}

0 commit comments

Comments
 (0)