diff mbox series

[11/11] KVM: selftests: Ensure KVM supports AVX for SEV-ES VMSA FPU test

Message ID 20241003234337.273364-12-seanjc@google.com (mailing list archive)
State New, archived
Headers show
Series KVM: selftests: AVX support + fixes | expand

Commit Message

Sean Christopherson Oct. 3, 2024, 11:43 p.m. UTC
Verify that KVM's supported XCR0 includes AVX (and earlier features) when
running the SEV-ES VMSA XSAVE test.  In practice, the issue will likely
never pop up, since KVM support for AVX predates KVM support for SEV-ES,
but checking for KVM support makes the requirement more obvious.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 tools/testing/selftests/kvm/x86_64/sev_smoke_test.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Vitaly Kuznetsov Oct. 4, 2024, 9:14 a.m. UTC | #1
Sean Christopherson <seanjc@google.com> writes:

> Verify that KVM's supported XCR0 includes AVX (and earlier features) when
> running the SEV-ES VMSA XSAVE test.  In practice, the issue will likely
> never pop up, since KVM support for AVX predates KVM support for SEV-ES,
> but checking for KVM support makes the requirement more obvious.
>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>  tools/testing/selftests/kvm/x86_64/sev_smoke_test.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c b/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c
> index 965fc362dee3..ae77698e6e97 100644
> --- a/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c
> @@ -181,6 +181,8 @@ static void test_sev_es_shutdown(void)
>  
>  int main(int argc, char *argv[])
>  {
> +	const u64 xf_mask = XFEATURE_MASK_X87_AVX;
> +
>  	TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SEV));
>  
>  	test_sev(guest_sev_code, SEV_POLICY_NO_DBG);
> @@ -193,7 +195,7 @@ int main(int argc, char *argv[])
>  		test_sev_es_shutdown();
>  
>  		if (kvm_has_cap(KVM_CAP_XCRS) &&
> -		    (xgetbv(0) & XFEATURE_MASK_X87_AVX) == XFEATURE_MASK_X87_AVX) {
> +		    (xgetbv(0) & kvm_cpu_supported_xcr0() & xf_mask) == xf_mask) {
>  			test_sync_vmsa(0);
>  			test_sync_vmsa(SEV_POLICY_NO_DBG);
>  		}

Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
diff mbox series

Patch

diff --git a/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c b/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c
index 965fc362dee3..ae77698e6e97 100644
--- a/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c
+++ b/tools/testing/selftests/kvm/x86_64/sev_smoke_test.c
@@ -181,6 +181,8 @@  static void test_sev_es_shutdown(void)
 
 int main(int argc, char *argv[])
 {
+	const u64 xf_mask = XFEATURE_MASK_X87_AVX;
+
 	TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SEV));
 
 	test_sev(guest_sev_code, SEV_POLICY_NO_DBG);
@@ -193,7 +195,7 @@  int main(int argc, char *argv[])
 		test_sev_es_shutdown();
 
 		if (kvm_has_cap(KVM_CAP_XCRS) &&
-		    (xgetbv(0) & XFEATURE_MASK_X87_AVX) == XFEATURE_MASK_X87_AVX) {
+		    (xgetbv(0) & kvm_cpu_supported_xcr0() & xf_mask) == xf_mask) {
 			test_sync_vmsa(0);
 			test_sync_vmsa(SEV_POLICY_NO_DBG);
 		}