All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Lara Lazier <laramglazier@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: [kvm-unit-tests PATCH] nSVM: Added test for VGIF feature
Date: Mon, 2 Aug 2021 15:09:56 +0000	[thread overview]
Message-ID: <YQgKxFwd8TpdWaOc@google.com> (raw)
In-Reply-To: <20210722131718.11667-1-laramglazier@gmail.com>

Nit, s/Added/Add in the shortlog

On Thu, Jul 22, 2021, Lara Lazier wrote:
> When VGIF is enabled STGI executed in guest mode
> sets bit 9, while CLGI clears bit 9 in the int_ctl (offset 60h)
> of the VMCB.
> 
> Signed-off-by: Lara Lazier <laramglazier@gmail.com>
> ---

...

> --- a/x86/svm_tests.c
> +++ b/x86/svm_tests.c
> @@ -2772,6 +2772,73 @@ static void svm_vmload_vmsave(void)
>  	vmcb->control.intercept = intercept_saved;
>  }
>  
> +static void prepare_vgif_enabled(struct svm_test *test)
> +{
> +    default_prepare(test);
> +}
> +
> +static void test_vgif(struct svm_test *test)
> +{
> +    asm volatile ("vmmcall\n\tstgi\n\tvmmcall\n\tclgi\n\tvmmcall\n\t");

While amusing, this isn't very readable :-)  The SVM tests that use this for
back-to-back VMMCALL are setting a bad example.  The space between "volatile" and
the opening "(" can go too.

	asm volatile("vmmcall\n\t"
		     "stgi\n\t"
		     "vmmcall\n\t"
		     "clgi\n\t"
		     "vmmcall\n\t");

> +

Unnecessary newline.

> +}
> +
> +static bool vgif_finished(struct svm_test *test)
> +{
> +    switch (get_test_stage(test))
> +    {
> +    case 0:
> +        if (vmcb->control.exit_code != SVM_EXIT_VMMCALL) {
> +            report(false, "VMEXIT not due to vmmcall.");
> +            return true;
> +        }
> +        vmcb->control.int_ctl |= V_GIF_ENABLED_MASK;

Setting and restoring a control flag should be done in setup/teardown, e.g. this
approach will leave V_GIF_ENABLED_MASK set if a VMMCALL check fails.

> +        vmcb->save.rip += 3;
> +        inc_test_stage(test);
> +        break;
> +    case 1:
> +        if (vmcb->control.exit_code != SVM_EXIT_VMMCALL) {
> +            report(false, "VMEXIT not due to vmmcall.");
> +            return true;
> +        }
> +        if (!(vmcb->control.int_ctl & V_GIF_MASK)) {
> +            report(false, "Failed to set VGIF when executing STGI.");
> +            vmcb->control.int_ctl &= ~V_GIF_ENABLED_MASK;
> +            return true;

Are the VGIF checks really fatal?   I.e. can we keep running of a STGI/CLGI test
fails?  That would allow for slightly cleaner code.

> +        }
> +        report(true, "STGI set VGIF bit.");
> +        vmcb->save.rip += 3;
> +        inc_test_stage(test);
> +        break;
> +    case 2:
> +        if (vmcb->control.exit_code != SVM_EXIT_VMMCALL) {
> +            report(false, "VMEXIT not due to vmmcall.");
> +            return true;
> +        }
> +        if (vmcb->control.int_ctl & V_GIF_MASK) {
> +            report(false, "Failed to clear VGIF when executing CLGI.");
> +            vmcb->control.int_ctl &= ~V_GIF_ENABLED_MASK;
> +            return true;
> +        }
> +        report(true, "CLGI cleared VGIF bit.");
> +        vmcb->save.rip += 3;
> +        inc_test_stage(test);
> +        vmcb->control.int_ctl &= ~V_GIF_ENABLED_MASK;
> +        break;


Something like this is more reader friendly as the boilerplate is consoliated,
abd the interesting test code is isolated in the switch statement.

	bool is_vmmcall_exit = (vmcb->control.exit_code == SVM_EXIT_VMMCALL);

	report(is_vmmcall_exit, ...);
	if (!is_vmmcall_exit)
		return true;

	switch (get_test_stage())
	{
	case 0:
		vmcb->control.int_ctl |= V_GIF_ENABLED_MASK;
		break;
	case 1:
		report(vmcb->control.int_ctl & V_GIF_MASK, ...);
		break;
	case 2:
		report(!(vmcb->control.int_ctl & V_GIF_MASK), ...);
		break;
	default:
		break;
	}

	vmcb->save.rip += 3;
	inc_test_stage(test);

	return get_test_stage() >= 3;

> +    default:
> +        return true;
> +        break;
> +    }

      reply	other threads:[~2021-08-02 15:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-22 13:17 [kvm-unit-tests PATCH] nSVM: Added test for VGIF feature Lara Lazier
2021-08-02 15:09 ` Sean Christopherson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YQgKxFwd8TpdWaOc@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=laramglazier@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.