* [PATCH] KVM: selftests: Use GUEST_ASSERT_EQ() to check exit codes in Hyper-V SVM test
@ 2025-11-14 16:40 Sean Christopherson
2025-11-14 16:58 ` Yosry Ahmed
0 siblings, 1 reply; 2+ messages in thread
From: Sean Christopherson @ 2025-11-14 16:40 UTC (permalink / raw)
To: Sean Christopherson, Paolo Bonzini; +Cc: kvm, linux-kernel, Yosry Ahmed
Use GUEST_ASSERT_EQ() instead of GUEST_ASSERT(x == SVM_EXIT_<code>) in the
Hyper-V SVM test so that the test prints the actual vs. expected values on
failure. E.g. instead of printing:
vmcb->control.exit_code == SVM_EXIT_VMMCALL
print:
0x7c != 0x81 (vmcb->control.exit_code != SVM_EXIT_VMMCALL)
Cc: Yosry Ahmed <yosry.ahmed@linux.dev>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
.../testing/selftests/kvm/x86/hyperv_svm_test.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/tools/testing/selftests/kvm/x86/hyperv_svm_test.c b/tools/testing/selftests/kvm/x86/hyperv_svm_test.c
index 0ddb63229bcb..7fb988df5f55 100644
--- a/tools/testing/selftests/kvm/x86/hyperv_svm_test.c
+++ b/tools/testing/selftests/kvm/x86/hyperv_svm_test.c
@@ -94,7 +94,7 @@ static void __attribute__((__flatten__)) guest_code(struct svm_test_data *svm,
GUEST_SYNC(2);
run_guest(vmcb, svm->vmcb_gpa);
- GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL);
+ GUEST_ASSERT_EQ(vmcb->control.exit_code, SVM_EXIT_VMMCALL);
GUEST_SYNC(4);
vmcb->save.rip += 3;
@@ -102,13 +102,13 @@ static void __attribute__((__flatten__)) guest_code(struct svm_test_data *svm,
vmcb->control.intercept |= 1ULL << INTERCEPT_MSR_PROT;
__set_bit(2 * (MSR_FS_BASE & 0x1fff), svm->msr + 0x800);
run_guest(vmcb, svm->vmcb_gpa);
- GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_MSR);
+ GUEST_ASSERT_EQ(vmcb->control.exit_code, SVM_EXIT_MSR);
vmcb->save.rip += 2; /* rdmsr */
/* Enable enlightened MSR bitmap */
hve->hv_enlightenments_control.msr_bitmap = 1;
run_guest(vmcb, svm->vmcb_gpa);
- GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_MSR);
+ GUEST_ASSERT_EQ(vmcb->control.exit_code, SVM_EXIT_MSR);
vmcb->save.rip += 2; /* rdmsr */
/* Intercept RDMSR 0xc0000101 without telling KVM about it */
@@ -117,13 +117,13 @@ static void __attribute__((__flatten__)) guest_code(struct svm_test_data *svm,
vmcb->control.clean |= HV_VMCB_NESTED_ENLIGHTENMENTS;
run_guest(vmcb, svm->vmcb_gpa);
/* Make sure we don't see SVM_EXIT_MSR here so eMSR bitmap works */
- GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL);
+ GUEST_ASSERT_EQ(vmcb->control.exit_code, SVM_EXIT_VMMCALL);
vmcb->save.rip += 3; /* vmcall */
/* Now tell KVM we've changed MSR-Bitmap */
vmcb->control.clean &= ~HV_VMCB_NESTED_ENLIGHTENMENTS;
run_guest(vmcb, svm->vmcb_gpa);
- GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_MSR);
+ GUEST_ASSERT_EQ(vmcb->control.exit_code, SVM_EXIT_MSR);
vmcb->save.rip += 2; /* rdmsr */
@@ -132,16 +132,16 @@ static void __attribute__((__flatten__)) guest_code(struct svm_test_data *svm,
* no VMCALL exit expected.
*/
run_guest(vmcb, svm->vmcb_gpa);
- GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_MSR);
+ GUEST_ASSERT_EQ(vmcb->control.exit_code, SVM_EXIT_MSR);
vmcb->save.rip += 2; /* rdmsr */
/* Enable synthetic vmexit */
*(u32 *)(hv_pages->partition_assist) = 1;
run_guest(vmcb, svm->vmcb_gpa);
- GUEST_ASSERT(vmcb->control.exit_code == HV_SVM_EXITCODE_ENL);
+ GUEST_ASSERT_EQ(vmcb->control.exit_code, HV_SVM_EXITCODE_ENL);
GUEST_ASSERT(vmcb->control.exit_info_1 == HV_SVM_ENL_EXITCODE_TRAP_AFTER_FLUSH);
run_guest(vmcb, svm->vmcb_gpa);
- GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL);
+ GUEST_ASSERT_EQ(vmcb->control.exit_code, SVM_EXIT_VMMCALL);
GUEST_SYNC(6);
GUEST_DONE();
base-commit: 16ec4fb4ac95d878b879192d280db2baeec43272
--
2.52.0.rc1.455.g30608eb744-goog
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] KVM: selftests: Use GUEST_ASSERT_EQ() to check exit codes in Hyper-V SVM test
2025-11-14 16:40 [PATCH] KVM: selftests: Use GUEST_ASSERT_EQ() to check exit codes in Hyper-V SVM test Sean Christopherson
@ 2025-11-14 16:58 ` Yosry Ahmed
0 siblings, 0 replies; 2+ messages in thread
From: Yosry Ahmed @ 2025-11-14 16:58 UTC (permalink / raw)
To: Sean Christopherson; +Cc: Paolo Bonzini, kvm, linux-kernel
On Fri, Nov 14, 2025 at 08:40:01AM -0800, Sean Christopherson wrote:
> Use GUEST_ASSERT_EQ() instead of GUEST_ASSERT(x == SVM_EXIT_<code>) in the
> Hyper-V SVM test so that the test prints the actual vs. expected values on
> failure. E.g. instead of printing:
>
> vmcb->control.exit_code == SVM_EXIT_VMMCALL
>
> print:
>
> 0x7c != 0x81 (vmcb->control.exit_code != SVM_EXIT_VMMCALL)
>
> Cc: Yosry Ahmed <yosry.ahmed@linux.dev>
> Signed-off-by: Sean Christopherson <seanjc@google.com>
LGTM:
Reviewed-by: Yosry Ahmed <yosry.ahmed@linux.dev>
For the record, there are a few more instances:
$ git grep "GUEST_ASSERT(vmcb->control.exit_code"
tools/testing/selftests/kvm/x86/hyperv_svm_test.c: GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL);
tools/testing/selftests/kvm/x86/hyperv_svm_test.c: GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_MSR);
tools/testing/selftests/kvm/x86/hyperv_svm_test.c: GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_MSR);
tools/testing/selftests/kvm/x86/hyperv_svm_test.c: GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL);
tools/testing/selftests/kvm/x86/hyperv_svm_test.c: GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_MSR);
tools/testing/selftests/kvm/x86/hyperv_svm_test.c: GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_MSR);
tools/testing/selftests/kvm/x86/hyperv_svm_test.c: GUEST_ASSERT(vmcb->control.exit_code == HV_SVM_EXITCODE_ENL);
tools/testing/selftests/kvm/x86/hyperv_svm_test.c: GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL);
tools/testing/selftests/kvm/x86/state_test.c: GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL);
tools/testing/selftests/kvm/x86/state_test.c: GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL);
tools/testing/selftests/kvm/x86/svm_int_ctl_test.c: GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL);
tools/testing/selftests/kvm/x86/svm_nested_soft_inject_test.c: __GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL,
tools/testing/selftests/kvm/x86/svm_nested_soft_inject_test.c: __GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_HLT,
tools/testing/selftests/kvm/x86/svm_vmcall_test.c: GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL);
There's also a lot for VMX, you can find all/most of them by running git
grep "vmreadz(VM_EXIT_REASON)".
> ---
> .../testing/selftests/kvm/x86/hyperv_svm_test.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/x86/hyperv_svm_test.c b/tools/testing/selftests/kvm/x86/hyperv_svm_test.c
> index 0ddb63229bcb..7fb988df5f55 100644
> --- a/tools/testing/selftests/kvm/x86/hyperv_svm_test.c
> +++ b/tools/testing/selftests/kvm/x86/hyperv_svm_test.c
> @@ -94,7 +94,7 @@ static void __attribute__((__flatten__)) guest_code(struct svm_test_data *svm,
>
> GUEST_SYNC(2);
> run_guest(vmcb, svm->vmcb_gpa);
> - GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL);
> + GUEST_ASSERT_EQ(vmcb->control.exit_code, SVM_EXIT_VMMCALL);
> GUEST_SYNC(4);
> vmcb->save.rip += 3;
>
> @@ -102,13 +102,13 @@ static void __attribute__((__flatten__)) guest_code(struct svm_test_data *svm,
> vmcb->control.intercept |= 1ULL << INTERCEPT_MSR_PROT;
> __set_bit(2 * (MSR_FS_BASE & 0x1fff), svm->msr + 0x800);
> run_guest(vmcb, svm->vmcb_gpa);
> - GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_MSR);
> + GUEST_ASSERT_EQ(vmcb->control.exit_code, SVM_EXIT_MSR);
> vmcb->save.rip += 2; /* rdmsr */
>
> /* Enable enlightened MSR bitmap */
> hve->hv_enlightenments_control.msr_bitmap = 1;
> run_guest(vmcb, svm->vmcb_gpa);
> - GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_MSR);
> + GUEST_ASSERT_EQ(vmcb->control.exit_code, SVM_EXIT_MSR);
> vmcb->save.rip += 2; /* rdmsr */
>
> /* Intercept RDMSR 0xc0000101 without telling KVM about it */
> @@ -117,13 +117,13 @@ static void __attribute__((__flatten__)) guest_code(struct svm_test_data *svm,
> vmcb->control.clean |= HV_VMCB_NESTED_ENLIGHTENMENTS;
> run_guest(vmcb, svm->vmcb_gpa);
> /* Make sure we don't see SVM_EXIT_MSR here so eMSR bitmap works */
> - GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL);
> + GUEST_ASSERT_EQ(vmcb->control.exit_code, SVM_EXIT_VMMCALL);
> vmcb->save.rip += 3; /* vmcall */
>
> /* Now tell KVM we've changed MSR-Bitmap */
> vmcb->control.clean &= ~HV_VMCB_NESTED_ENLIGHTENMENTS;
> run_guest(vmcb, svm->vmcb_gpa);
> - GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_MSR);
> + GUEST_ASSERT_EQ(vmcb->control.exit_code, SVM_EXIT_MSR);
> vmcb->save.rip += 2; /* rdmsr */
>
>
> @@ -132,16 +132,16 @@ static void __attribute__((__flatten__)) guest_code(struct svm_test_data *svm,
> * no VMCALL exit expected.
> */
> run_guest(vmcb, svm->vmcb_gpa);
> - GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_MSR);
> + GUEST_ASSERT_EQ(vmcb->control.exit_code, SVM_EXIT_MSR);
> vmcb->save.rip += 2; /* rdmsr */
> /* Enable synthetic vmexit */
> *(u32 *)(hv_pages->partition_assist) = 1;
> run_guest(vmcb, svm->vmcb_gpa);
> - GUEST_ASSERT(vmcb->control.exit_code == HV_SVM_EXITCODE_ENL);
> + GUEST_ASSERT_EQ(vmcb->control.exit_code, HV_SVM_EXITCODE_ENL);
> GUEST_ASSERT(vmcb->control.exit_info_1 == HV_SVM_ENL_EXITCODE_TRAP_AFTER_FLUSH);
>
> run_guest(vmcb, svm->vmcb_gpa);
> - GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL);
> + GUEST_ASSERT_EQ(vmcb->control.exit_code, SVM_EXIT_VMMCALL);
> GUEST_SYNC(6);
>
> GUEST_DONE();
>
> base-commit: 16ec4fb4ac95d878b879192d280db2baeec43272
> --
> 2.52.0.rc1.455.g30608eb744-goog
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-11-14 16:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-14 16:40 [PATCH] KVM: selftests: Use GUEST_ASSERT_EQ() to check exit codes in Hyper-V SVM test Sean Christopherson
2025-11-14 16:58 ` Yosry Ahmed
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®