From: Aman Priyadarshi <apeureka@amazon.de>
To: Marc Zyngier <maz@kernel.org>
Cc: Alexander Graf <graf@amazon.com>,
kvmarm@lists.cs.columbia.edu, Ali Saidi <alisaidi@amazon.com>
Subject: Re: KVM: arm64: pmu: Reset sample period on overflow handling
Date: Wed, 16 Jun 2021 12:52:42 +0200 [thread overview]
Message-ID: <094d40a0e7f5389ce5a13d96b96d4b7588c71d74.camel@amazon.de> (raw)
In-Reply-To: <87lf7am77t.wl-maz@kernel.org>
On Wed, 2021-06-16 at 11:31 +0100, Marc Zyngier wrote:
>
> Hi Aman,
>
> On Wed, 16 Jun 2021 10:17:28 +0100,
> Aman Priyadarshi <apeureka@amazon.de> wrote:
> >
> > Hi Marc,
> >
> > On Tue, 2021-06-15 at 18:05 +0100, Marc Zyngier wrote:
> > >
> > > Can you reproduce the issue with vanilla guest kernels? It'd be
> > > interesting to understand what makes it work on the guest side. Can
> > > you please bisect it?
> > >
> >
> > yes, I was able to narrow it down to the commit 0cbb058be904 ("arm64:
> > perf:
> > Disable PMU while processing counter overflows"), which fixes the
> > problem
> > on the guest side.
>
> Which is 3cce50dfec4a5b0414c974190940f47dd32c6dee in mainline. This
> doesn't seem to have ever been backported before 4.18. So I don't know
> why your 4.15 kernel was correctly behaving, but it could be that the
> distro had randomly picked up the correct patch!
Yes. https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1836117
>
> You may want to backport it to 4.14.y and let Greg know about that.
>
Ack.
> >
> > I _think_, I understand the problem now. Please correct me if I am
> > wrong.
> >
> > commit 30d97754b2d1 ("KVM: arm/arm64: Re-create event when setting
> > counter
> > value") adds a new code path for perf event when counter value is set,
> > therefore kvm would generate more events than before. Without this
> > change,
> > we have a lot less events, thus reducing the chances of guest messing
> > things up.
>
> Without this fix, we don't communicate the new guest sample period to
> the host's perf counter, and depending on what the guest wrote (and
> the previous value), it can go one way or the other.
>
> > On the other side, commit 8c3252c06516 ("KVM: arm64: pmu: Reset sample
> > period on overflow handling") resets the sample period to the max
> > value,
> > thus reducing the number of overflow events to guest to an optimal
> > value
> > (note, number of interrupts actually handled by guest would remain same
> > in
> > either case). Less number of overflow interrupts to the guest, reduces
> > the
> > chance of guest making up for any left over overflow event that it did
> > not
> > see earlier.
>
> This fix is the natural complement of the previous one. We need to
> emulate the actual overflow, and prevent perf from doing its thing on
> the host (reloading from the previously provided value). So we reset
> the period to the value that perf did observe on taking the physical
> interrupt.
>
> Together, these two patches provide a more correct PMU emulation.
>
> The guest patch fixes prevents additional overflow being observed due
> while the guest is reprogramming its counters and observe a moving
> target. Note that the host itself needs that initial fix to correctly
> emulate the PMU! ;-)
>
> It is pretty hard to picture exactly *what* happens when you are
> missing any of these 3 patches. Both the kernel and KVM were buggy at
> some point, and you need all three patches to ensure something
> correct.
>
Thanks for the explanation!
Regards,
Aman Priyadarshi
Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
next prev parent reply other threads:[~2021-06-16 12:08 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-15 15:15 KVM: arm64: pmu: Reset sample period on overflow handling Aman Priyadarshi
2021-06-15 17:05 ` Marc Zyngier
2021-06-16 9:17 ` Aman Priyadarshi
2021-06-16 10:31 ` Marc Zyngier
2021-06-16 10:52 ` Aman Priyadarshi [this message]
2021-06-16 11:03 ` Marc Zyngier
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=094d40a0e7f5389ce5a13d96b96d4b7588c71d74.camel@amazon.de \
--to=apeureka@amazon.de \
--cc=alisaidi@amazon.com \
--cc=graf@amazon.com \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=maz@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