From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Nadav Amit <nadav.amit@gmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>, kvm@vger.kernel.org
Subject: Re: [kvm-unit-tests PATCH] x86: Prevent APIC base address from changing in test_enable_x2apic()
Date: Mon, 15 Apr 2019 12:37:51 -0700 [thread overview]
Message-ID: <20190415193751.GK24010@linux.intel.com> (raw)
In-Reply-To: <04ECBA2D-C623-487B-89E2-FC6FD7062C19@gmail.com>
On Mon, Apr 15, 2019 at 12:12:58PM -0700, Nadav Amit wrote:
> > On Apr 15, 2019, at 12:09 PM, Nadav Amit <nadav.amit@gmail.com> wrote:
> >
> >> On Apr 15, 2019, at 12:00 PM, Sean Christopherson <sean.j.christopherson@intel.com> wrote:
> >>
> >> On Mon, Apr 15, 2019 at 11:31:00AM -0700, nadav.amit@gmail.com wrote:
> >>> From: Nadav Amit <nadav.amit@gmail.com>
> >>>
> >>> test_enable_x2apic() unintentionally changes the APIC base address to
> >>> zero and resets the BSP indication. This actually causes the local APIC
> >>> to overlap the IDT area, which is wrong. Prevent it from happening by
> >>> keeping the APIC base address and BSP-bit as it was before.
> >>>
> >>> Signed-off-by: Nadav Amit <nadav.amit@gmail.com>
> >>> ---
> >>> x86/apic.c | 4 ++--
> >>> 1 file changed, 2 insertions(+), 2 deletions(-)
> >>>
> >>> diff --git a/x86/apic.c b/x86/apic.c
> >>> index 51744cf..0849f87 100644
> >>> --- a/x86/apic.c
> >>> +++ b/x86/apic.c
> >>> @@ -90,11 +90,11 @@ static void test_enable_x2apic(void)
> >>> report("disabled to x2apic enabled",
> >>> test_write_apicbase_exception(APIC_EN | APIC_EXTD));
> >>>
> >>> - wrmsr(MSR_IA32_APICBASE, APIC_EN);
> >>> + wrmsr(MSR_IA32_APICBASE, APIC_EN | APIC_DEFAULT_PHYS_BASE | APIC_BSP);
> >>> report("apic enabled to invalid state",
> >>> test_write_apicbase_exception(APIC_EXTD));
> >>>
> >>> - wrmsr(MSR_IA32_APICBASE, APIC_EN | APIC_EXTD);
> >>> + wrmsr(MSR_IA32_APICBASE, APIC_EN | APIC_EXTD | APIC_DEFAULT_PHYS_BASE | APIC_BSP);
> >>
> >> It probably doesn't matter since AFAIK kvm-unit-tests always uses the
> >> default base, but preserving the current base+BSP would be preferred.
> >> The #GP tests get away with using APIC_DEFAULT_PHYS_BASE because the
> >> WRMSR will never succeed, but even that is poor form. And the test
> >> should also reset to xAPIC when it's done.
> >>
> >> I think the attached patch covers everything.
> >
> > Thanks. The base is indeed the default, so it should not matter, but your
> > change should make the code more robust.
> >
> > One important comment regarding your patch:
> >
> >> + if (!(orig_apicbase & APIC_EXTD))
> >> + reset_apic();
> >
> > This is not needed, since enable_x2apic() will only return true if it
> > succeeded in enabling x2apic. In addition, this is wrong, since reset_apic()
> > should (usually, and specifically in this case) be followed with:
> >
> > apic_write(APIC_SPIV, 0x1ff);
> >
> > And not the other way around (there are actually a couple of missing writes
> > to software-enable the APIC after reset_apic(), which I’ll send later).
>
> Correcting myself - I understand (now) that you want to reset back to xapic, so
> that’s fine. Just keep "apic_write(APIC_SPIV, 0x1ff);” after the reset, please.
Ah, will do, I glazed over the apic_write() and didn't consider its purpose.
next prev parent reply other threads:[~2019-04-15 19:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-15 18:31 [kvm-unit-tests PATCH] x86: Prevent APIC base address from changing in test_enable_x2apic() nadav.amit
2019-04-15 19:00 ` Sean Christopherson
2019-04-15 19:09 ` Nadav Amit
2019-04-15 19:12 ` Nadav Amit
2019-04-15 19:37 ` Sean Christopherson [this message]
2019-04-15 19:55 ` Nadav Amit
2019-04-15 19:59 ` Sean Christopherson
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=20190415193751.GK24010@linux.intel.com \
--to=sean.j.christopherson@intel.com \
--cc=kvm@vger.kernel.org \
--cc=nadav.amit@gmail.com \
--cc=pbonzini@redhat.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;
as well as URLs for NNTP newsgroup(s).