From: "Tycho Andersen (AMD)" As in the comment, check to make sure that SEV-ES VMs are allowed before running the test. Otherwise, there is a generic: ==== Test Assertion Failure ==== lib/x86/sev.c:91: !ret pid=3678 tid=3678 errno=5 - Input/output error 1 0x0000000000417000: sev_vm_launch at sev.c:91 (discriminator 4) 2 0x0000000000417d49: vm_sev_launch at sev.c:191 3 0x0000000000402a7d: test_sev at sev_smoke_test.c:132 4 0x000000000040328f: test_sev_smoke at sev_smoke_test.c:198 5 0x00000000004026c8: main at sev_smoke_test.c:223 6 0x00007fdde5c2a1c9: ?? ??:0 7 0x00007fdde5c2a28a: ?? ??:0 8 0x00000000004027f4: _start at ??:? KVM_SEV_LAUNCH_START failed, rc: -1 errno: 5 (Input/output error) Signed-off-by: Tycho Andersen (AMD) --- .../selftests/kvm/x86/sev_smoke_test.c | 37 ++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/x86/sev_smoke_test.c b/tools/testing/selftests/kvm/x86/sev_smoke_test.c index 86ad1c7d068f..c7fda9fc324b 100644 --- a/tools/testing/selftests/kvm/x86/sev_smoke_test.c +++ b/tools/testing/selftests/kvm/x86/sev_smoke_test.c @@ -213,13 +213,48 @@ static void test_sev_smoke(void *guest, uint32_t type, uint64_t policy) } } +static bool sev_es_allowed(void) +{ + struct kvm_sev_launch_start launch_start = { + .policy = SEV_POLICY_ES, + }; + struct kvm_vcpu *vcpu; + struct kvm_vm *vm; + int firmware_error, ret; + bool supported = true; + + if (!kvm_cpu_has(X86_FEATURE_SEV_ES)) + return false; + + if (!kvm_cpu_has(X86_FEATURE_SEV_SNP)) + return true; + + /* + * In some cases when SEV-SNP is enabled, firmware disallows starting + * an SEV-ES VM. When SEV-SNP is enabled try to launch an SEV-ES, and + * check the underlying firmware error for this case. + */ + vm = vm_sev_create_with_one_vcpu(KVM_X86_SEV_ES_VM, guest_sev_es_code, + &vcpu); + + ret = __vm_sev_ioctl(vm, KVM_SEV_LAUNCH_START, &launch_start, + &firmware_error); + if (ret == -1 && firmware_error == SEV_RET_UNSUPPORTED) { + pr_info("SEV-ES not supported with SNP\n"); + supported = false; + } + + kvm_vm_free(vm); + return supported; +} + int main(int argc, char *argv[]) { TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SEV)); test_sev_smoke(guest_sev_code, KVM_X86_SEV_VM, 0); - if (kvm_cpu_has(X86_FEATURE_SEV_ES)) + if (sev_es_allowed()) test_sev_smoke(guest_sev_es_code, KVM_X86_SEV_ES_VM, SEV_POLICY_ES); if (kvm_cpu_has(X86_FEATURE_SEV_SNP)) -- 2.53.0