Re: [PATCH 2/2] nSVM: Test reserved values for 'Type' and invalid vectors in EVENTINJ

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> On Oct 16, 2020, at 5:02 PM, Krish Sadhukhan <krish.sadhukhan@xxxxxxxxxx> wrote:
> 
> 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 | 40 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 40 insertions(+)
> 
> diff --git a/x86/svm_tests.c b/x86/svm_tests.c
> index f78c9e4..e6554e4 100644
> --- a/x86/svm_tests.c
> +++ b/x86/svm_tests.c
> @@ -2132,6 +2132,45 @@ 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.
> +	 */
> +	i = 32;
> +	while (i < 256) {
> +		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);
> +		i += 4;
> +	}

I know that kvm-unit-tests has nothing to do with style, but can’t this loop
be turned into a for-loop for readability?

And why "i += 4" ?





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux