According to sections "Canonicalization and Consistency Checks" and "Event Injection" in APM vol 2 VMRUN exits with VMEXIT_INVALID error code if either: - Reserved values of TYPE have been specified, or - TYPE = 3 (exception) has been specified with a vector that does not correspond to an exception (this includes vector 2, which is an NMI, not an exception). Existing tests already cover part of the second rule. This patch covers the the first rule and the missing pieces of the second rule. Signed-off-by: Krish Sadhukhan <krish.sadhukhan@xxxxxxxxxx> --- x86/svm_tests.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index f78c9e4..b9be522 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -2132,6 +2132,43 @@ static void test_dr(void) vmcb->save.dr7 = dr_saved; } +static void test_event_inject(void) +{ + u32 i; + u32 event_inj_saved = vmcb->control.event_inj; + + handle_exception(DE_VECTOR, my_isr); + + report (svm_vmrun() == SVM_EXIT_VMMCALL && count_exc == 0, "Test " + "No EVENTINJ"); + + /* + * Reserved values for 'Type' in EVENTINJ causes VMEXIT_INVALID. + */ + for (i = 1; i < 8; i++) { + if (i != 1 && i < 5) + continue; + vmcb->control.event_inj = DE_VECTOR | + i << SVM_EVTINJ_TYPE_SHIFT | SVM_EVTINJ_VALID; + report(svm_vmrun() == SVM_EXIT_ERR && count_exc == 0, + "Test invalid TYPE (%x) in EVENTINJ", i); + } + + /* + * Invalid vector number for event type 'exception' in EVENTINJ + * causes VMEXIT_INVALID. + */ + for (i = 32; i < 256; i += 4) { + vmcb->control.event_inj = i | SVM_EVTINJ_TYPE_EXEPT | + SVM_EVTINJ_VALID; + report(svm_vmrun() == SVM_EXIT_ERR && count_exc == 0, + "Test invalid vector (%u) in EVENTINJ for event type " + "\'exception\'", i); + } + + vmcb->control.event_inj = event_inj_saved; +} + static void svm_guest_state_test(void) { test_set_guest(basic_guest_main); @@ -2141,6 +2178,7 @@ static void svm_guest_state_test(void) test_cr3(); test_cr4(); test_dr(); + test_event_inject(); } struct svm_test svm_tests[] = { -- 2.18.4