From: Paolo Bonzini <pbonzini@redhat.com>
To: "Sean Christopherson" <sean.j.christopherson@intel.com>,
"Radim Krčmář" <rkrcmar@redhat.com>
Cc: kvm@vger.kernel.org, Nadav Amit <nadav.amit@gmail.com>
Subject: Re: [kvm-unit-tests PATCH] x86: apic: Preserve APIC base and BSP bits during x2APIC tests
Date: Tue, 16 Apr 2019 17:22:27 +0200 [thread overview]
Message-ID: <c203fe9e-76dc-a3d5-9f39-e91758744680@redhat.com> (raw)
In-Reply-To: <20190415200034.6839-1-sean.j.christopherson@intel.com>
On 15/04/19 22:00, Sean Christopherson wrote:
> ...and reset to xAPIC mode unless x2APIC was already enabled. Make the
> "APIC disabled to APIC enabled" a reported subtest so that it's
> (slightly) more obviously that the vCPU is transitioning back to legacy
> xAPIC mode and that the APIC was disabled via a previous subtest, i.e.
> won't fault due to an illegal transition.
>
> Note, reset_apic() is overkill since the vCPU is already in legacy xAPIC
> mode, i.e. the test really just needs "apic_ops = &xapic_ops;". But two
> MSR accesses are negligible in the grand scheme and using reset_apic() is
> less reliant on the exact flow of the test.
>
> Reported-by: Nadav Amit <nadav.amit@gmail.com>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
> x86/apic.c | 30 +++++++++++++++++++++---------
> 1 file changed, 21 insertions(+), 9 deletions(-)
>
> diff --git a/x86/apic.c b/x86/apic.c
> index 51744cf..7f711c0 100644
> --- a/x86/apic.c
> +++ b/x86/apic.c
> @@ -69,32 +69,44 @@ static void do_write_apicbase(void *data)
>
> static bool test_write_apicbase_exception(u64 data)
> {
> - data |= APIC_DEFAULT_PHYS_BASE | APIC_BSP;
> return test_for_exception(GP_VECTOR, do_write_apicbase, &data);
> }
>
> static void test_enable_x2apic(void)
> {
> + u64 orig_apicbase = rdmsr(MSR_IA32_APICBASE);
> + u64 apicbase;
> +
> if (enable_x2apic()) {
> printf("x2apic enabled\n");
>
> + apicbase = orig_apicbase & ~(APIC_EN | APIC_EXTD);
> report("x2apic enabled to invalid state",
> - test_write_apicbase_exception(APIC_EXTD));
> + test_write_apicbase_exception(apicbase | APIC_EXTD));
> report("x2apic enabled to apic enabled",
> - test_write_apicbase_exception(APIC_EN));
> + test_write_apicbase_exception(apicbase | APIC_EN));
>
> report("x2apic enabled to disabled state",
> - !test_write_apicbase_exception(0));
> + !test_write_apicbase_exception(apicbase | 0));
> report("disabled to invalid state",
> - test_write_apicbase_exception(APIC_EXTD));
> + test_write_apicbase_exception(apicbase | APIC_EXTD));
> report("disabled to x2apic enabled",
> - test_write_apicbase_exception(APIC_EN | APIC_EXTD));
> + test_write_apicbase_exception(apicbase | APIC_EN | APIC_EXTD));
>
> - wrmsr(MSR_IA32_APICBASE, APIC_EN);
> + report("apic disabled to apic enabled",
> + !test_write_apicbase_exception(apicbase | APIC_EN));
> report("apic enabled to invalid state",
> - test_write_apicbase_exception(APIC_EXTD));
> + test_write_apicbase_exception(apicbase | APIC_EXTD));
>
> - wrmsr(MSR_IA32_APICBASE, APIC_EN | APIC_EXTD);
> + if (orig_apicbase & APIC_EXTD)
> + enable_x2apic();
> + else
> + reset_apic();
> +
> + /*
> + * Disabling the APIC resets various APIC registers, restore them to
> + * their desired values.
> + */
> apic_write(APIC_SPIV, 0x1ff);
> } else {
> printf("x2apic not detected\n");
>
Queued, thanks.
Paolo
prev parent reply other threads:[~2019-04-16 15:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-15 20:00 [kvm-unit-tests PATCH] x86: apic: Preserve APIC base and BSP bits during x2APIC tests Sean Christopherson
2019-04-16 15:22 ` 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=c203fe9e-76dc-a3d5-9f39-e91758744680@redhat.com \
--to=pbonzini@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=nadav.amit@gmail.com \
--cc=rkrcmar@redhat.com \
--cc=sean.j.christopherson@intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox