[PATCH v2] KVM: arm64: pmu: Resync EL0 state on counter rotation

Will Deacon will at kernel.org
Tue Aug 22 02:59:59 PDT 2023


On Tue, Aug 22, 2023 at 07:48:28AM +0100, Mark Rutland wrote:
> On Sun, Aug 20, 2023 at 10:01:08AM +0100, Marc Zyngier wrote:
> > Huang Shijie reports that, when profiling a guest from the host
> > with a number of events that exceeds the number of available
> > counters, the reported counts are wildly inaccurate. Without
> > the counter oversubscription, the reported counts are correct.
> > 
> > Their investigation indicates that upon counter rotation (which
> > takes place on the back of a timer interrupt), we fail to
> > re-apply the guest EL0 enabling, leading to the counting of host
> > events instead of guest events.
> > 
> > In order to solve this, add yet another hook between the host PMU
> > driver and KVM, re-applying the guest EL0 configuration if the
> > right conditions apply (the host is VHE, we are in interrupt
> > context, and we interrupted a running vcpu). This triggers a new
> > vcpu request which will apply the correct configuration on guest
> > reentry.
> > 
> > With this, we have the correct counts, even when the counters are
> > oversubscribed.
> > 
> > Reported-by: Huang Shijie <shijie at os.amperecomputing.com>
> > Suggested-by: Oliver Upton <oliver.upton at linux.dev>
> > Tested_by: Huang Shijie <shijie at os.amperecomputing.com>
> > Signed-off-by: Marc Zyngier <maz at kernel.org>
> > Cc: Leo Yan <leo.yan at linaro.org>
> > Cc: Mark Rutland <mark.rutland at arm.com>
> > Cc: Will Deacon <will at kernel.org>
> > Link: https://lore.kernel.org/r/20230809013953.7692-1-shijie@os.amperecomputing.com
> 
> This looks sane to me so:
> 
> Acked-by: Mark Rutland <mark.rutland at arm.com>
> 
> It doesn't look like we have any PMU patches queued that would conflict, so if
> Will's happy I reckon this should go through the KVM/arm64 tree.

Fine by me!

Will



More information about the linux-arm-kernel mailing list