From: Paolo Bonzini <pbonzini@redhat.com>
To: Cathy Avery <cavery@redhat.com>,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH kvm-unit-tests] svm: Test V_IRQ injection
Date: Sat, 9 May 2020 14:58:32 +0200 [thread overview]
Message-ID: <4097f4fe-f941-a8ef-8d93-3164f0b0441d@redhat.com> (raw)
In-Reply-To: <20200509111622.2184-1-cavery@redhat.com>
On 09/05/20 13:16, Cathy Avery wrote:
> Test V_IRQ injection from L1 to L2 with V_TPR less
> than or greater than V_INTR_PRIO. Also test VINTR
> intercept with differing V_TPR and V_INTR_PRIO.
>
> Signed-off-by: Cathy Avery <cavery@redhat.com>
> ---
> x86/svm_tests.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 150 insertions(+)
>
> diff --git a/x86/svm_tests.c b/x86/svm_tests.c
> index 65008ba..aa6f3c2 100644
> --- a/x86/svm_tests.c
> +++ b/x86/svm_tests.c
> @@ -1595,6 +1595,153 @@ static bool exc_inject_check(struct svm_test *test)
> return count_exc == 1 && get_test_stage(test) == 3;
> }
>
> +static volatile bool virq_fired;
> +
> +static void virq_isr(isr_regs_t *regs)
> +{
> + virq_fired = true;
> +}
> +
> +static void virq_inject_prepare(struct svm_test *test)
> +{
> + handle_irq(0xf1, virq_isr);
> + default_prepare(test);
> + vmcb->control.int_ctl = V_INTR_MASKING_MASK | V_IRQ_MASK |
> + (0x0f << V_INTR_PRIO_SHIFT); // Set to the highest priority
> + vmcb->control.int_vector = 0xf1;
> + virq_fired = false;
> + set_test_stage(test, 0);
> +}
> +
> +static void virq_inject_test(struct svm_test *test)
> +{
> + if (virq_fired) {
> + report(false, "virtual interrupt fired before L2 sti");
> + set_test_stage(test, -1);
> + vmmcall();
> + }
> +
> + irq_enable();
> + asm volatile ("nop");
> + irq_disable();
> +
> + if (!virq_fired) {
> + report(false, "virtual interrupt not fired after L2 sti");
> + set_test_stage(test, -1);
> + }
> +
> + vmmcall();
> +
> + if (virq_fired) {
> + report(false, "virtual interrupt fired before L2 sti after VINTR intercept");
> + set_test_stage(test, -1);
> + vmmcall();
> + }
> +
> + irq_enable();
> + asm volatile ("nop");
> + irq_disable();
> +
> + if (!virq_fired) {
> + report(false, "virtual interrupt not fired after return from VINTR intercept");
> + set_test_stage(test, -1);
> + }
> +
> + vmmcall();
> +
> + irq_enable();
> + asm volatile ("nop");
> + irq_disable();
> +
> + if (virq_fired) {
> + report(false, "virtual interrupt fired when V_IRQ_PRIO less than V_TPR");
> + set_test_stage(test, -1);
> + }
> +
> + vmmcall();
> + vmmcall();
> +}
> +
> +static bool virq_inject_finished(struct svm_test *test)
> +{
> + vmcb->save.rip += 3;
> +
> + switch (get_test_stage(test)) {
> + case 0:
> + if (vmcb->control.exit_code != SVM_EXIT_VMMCALL) {
> + report(false, "VMEXIT not due to vmmcall. Exit reason 0x%x",
> + vmcb->control.exit_code);
> + return true;
> + }
> + if (vmcb->control.int_ctl & V_IRQ_MASK) {
> + report(false, "V_IRQ not cleared on VMEXIT after firing");
> + return true;
> + }
> + virq_fired = false;
> + vmcb->control.intercept |= (1ULL << INTERCEPT_VINTR);
> + vmcb->control.int_ctl = V_INTR_MASKING_MASK | V_IRQ_MASK |
> + (0x0f << V_INTR_PRIO_SHIFT);
> + break;
> +
> + case 1:
> + if (vmcb->control.exit_code != SVM_EXIT_VINTR) {
> + report(false, "VMEXIT not due to vintr. Exit reason 0x%x",
> + vmcb->control.exit_code);
> + return true;
> + }
> + if (virq_fired) {
> + report(false, "V_IRQ fired before SVM_EXIT_VINTR");
> + return true;
> + }
> + vmcb->control.intercept &= ~(1ULL << INTERCEPT_VINTR);
> + break;
> +
> + case 2:
> + if (vmcb->control.exit_code != SVM_EXIT_VMMCALL) {
> + report(false, "VMEXIT not due to vmmcall. Exit reason 0x%x",
> + vmcb->control.exit_code);
> + return true;
> + }
> + virq_fired = false;
> + // Set irq to lower priority
> + vmcb->control.int_ctl = V_INTR_MASKING_MASK | V_IRQ_MASK |
> + (0x08 << V_INTR_PRIO_SHIFT);
> + // Raise guest TPR
> + vmcb->control.int_ctl |= 0x0a & V_TPR_MASK;
> + break;
> +
> + case 3:
> + if (vmcb->control.exit_code != SVM_EXIT_VMMCALL) {
> + report(false, "VMEXIT not due to vmmcall. Exit reason 0x%x",
> + vmcb->control.exit_code);
> + return true;
> + }
> + vmcb->control.intercept |= (1ULL << INTERCEPT_VINTR);
> + break;
> +
> + case 4:
> + // INTERCEPT_VINTR should be ignored because V_INTR_PRIO < V_TPR
> + if (vmcb->control.exit_code != SVM_EXIT_VMMCALL) {
> + report(false, "VMEXIT not due to vmmcall. Exit reason 0x%x",
> + vmcb->control.exit_code);
> + return true;
> + }
> + break;
> +
> + default:
> + return true;
> + }
> +
> + inc_test_stage(test);
> +
> + return get_test_stage(test) == 5;
> +}
> +
> +static bool virq_inject_check(struct svm_test *test)
> +{
> + return get_test_stage(test) == 5;
> +}
> +
> #define TEST(name) { #name, .v2 = name }
>
> /*
> @@ -1750,6 +1897,9 @@ struct svm_test svm_tests[] = {
> { "nmi_hlt", smp_supported, nmi_prepare,
> default_prepare_gif_clear, nmi_hlt_test,
> nmi_hlt_finished, nmi_hlt_check },
> + { "virq_inject", default_supported, virq_inject_prepare,
> + default_prepare_gif_clear, virq_inject_test,
> + virq_inject_finished, virq_inject_check },
> TEST(svm_guest_state_test),
> { NULL, NULL, NULL, NULL, NULL, NULL, NULL }
> };
>
Queued, thanks.
Paolo
prev parent reply other threads:[~2020-05-09 12:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-09 11:16 Cathy Avery
2020-05-09 12:58 ` Paolo Bonzini [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=4097f4fe-f941-a8ef-8d93-3164f0b0441d@redhat.com \
--to=pbonzini@redhat.com \
--cc=cavery@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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 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®