From: Sean Christopherson <seanjc@google.com>
To: Like Xu <like.xu.linux@gmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Ravi Bangoria <ravi.bangoria@amd.com>,
Manali Shukla <manali.shukla@amd.com>
Subject: Re: [PATCH V2] KVM: x86/pmu: Disable vPMU if EVENTSEL_GUESTONLY bit doesn't exist
Date: Mon, 25 Sep 2023 16:31:58 -0700 [thread overview]
Message-ID: <ZRIYbu4wSVW9a+8i@google.com> (raw)
In-Reply-To: <6ee140c9-ccd5-9569-db17-a542a7e28d5c@gmail.com>
On Thu, Sep 14, 2023, Like Xu wrote:
> On 7/4/2023 11:37 pm, Sean Christopherson wrote:
> > On Fri, Apr 07, 2023, Like Xu wrote:
> /*
> * The guest vPMU counter emulation depends on the EVENTSEL_GUESTONLY bit.
> * If this bit is present on the host, the host needs to support at least
> the PERFCTR_CORE.
> */
...
> > /*
> > * KVM requires guest-only event support in order to isolate guest PMCs
> > * from host PMCs. SVM doesn't provide a way to atomically load MSRs
> > * on VMRUN, and manually adjusting counts before/after VMRUN is not
> > * accurate enough to properly virtualize a PMU.
> > */
> >
> > But now I'm really confused, because if I'm reading the code correctly, perf
> > invokes amd_core_hw_config() for legacy PMUs, i.e. even if PERFCTR_CORE isn't
> > supported. And the APM documents the host/guest bits only for "Core Performance
> > Event-Select Registers".
> >
> > So either (a) GUESTONLY isn't supported on legacy CPUs and perf is relying on AMD
> > CPUs ignoring reserved bits or (b) GUESTONLY _is_ supported on legacy PMUs and
> > pmu_has_guestonly_mode() is checking the wrong MSR when running on older CPUs.
> >
> > And if (a) is true, then how on earth does KVM support vPMU when running on a
> > legacy PMU? Is vPMU on AMD just wildly broken? Am I missing something?
> >
>
> (a) It's true and AMD guest vPMU have only been implemented accurately with
> the help of this GUESTONLY bit.
>
> There are two other scenarios worth discussing here: one is support L2 vPMU
> on the PERFCTR_CORE+ host and this proposal is disabling it; and the other
> case is to support AMD legacy vPMU on the PERFCTR_CORE+ host.
Oooh, so the really problematic case is when PERFCTR_CORE+ is supported but
GUESTONLY is not, in which case KVM+perf *think* they can use GUESTONLY (and
HOSTONLY).
That's a straight up KVM (as L0) bug, no? I don't see anything in the APM that
suggests those bits are optional, i.e. KVM is blatantly violating AMD's architecture
by ignoring those bits.
I would rather fix KVM (as L0). It doesn't seem _that_ hard to support, e.g.
modify reprogram_counter() to disable the counter if it's supposed to be silent
for the current mode, and reprogram all counters if EFER.SVME is toggled, and on
all nested transitions.
next prev parent reply other threads:[~2023-09-25 23:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-07 8:56 [PATCH V2] KVM: x86/pmu: Disable vPMU if EVENTSEL_GUESTONLY bit doesn't exist Like Xu
2023-04-07 15:37 ` Sean Christopherson
2023-09-14 8:23 ` Like Xu
2023-09-25 23:31 ` Sean Christopherson [this message]
2023-09-26 3:49 ` Like Xu
2023-09-26 15:44 ` 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=ZRIYbu4wSVW9a+8i@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=like.xu.linux@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=manali.shukla@amd.com \
--cc=pbonzini@redhat.com \
--cc=ravi.bangoria@amd.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