[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <4aaaa1de-ec5d-433b-96c2-3b28a8cffe7e@linaro.org>
Date: Mon, 3 Feb 2025 11:28:44 +0000
From: James Clark <james.clark@...aro.org>
To: "Rob Herring (Arm)" <robh@...nel.org>
Cc: linux-arm-kernel@...ts.infradead.org, linux-perf-users@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-doc@...r.kernel.org,
kvmarm@...ts.linux.dev, Will Deacon <will@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Catalin Marinas <catalin.marinas@....com>, Jonathan Corbet <corbet@....net>,
Marc Zyngier <maz@...nel.org>, Oliver Upton <oliver.upton@...ux.dev>,
Joey Gouly <joey.gouly@....com>, Suzuki K Poulose <suzuki.poulose@....com>,
Zenghui Yu <yuzenghui@...wei.com>,
Anshuman Khandual <anshuman.khandual@....com>
Subject: Re: [PATCH v19 10/11] KVM: arm64: nvhe: Disable branch generation in
nVHE guests
On 03/02/2025 12:43 am, Rob Herring (Arm) wrote:
> From: Anshuman Khandual <anshuman.khandual@....com>
>
> While BRBE can record branches within guests, the host recording
> branches in guests is not supported by perf. Therefore, BRBE needs to be
> disabled on guest entry and restored on exit.
I don't think this is strictly true. You only need a Perf session in the
guest to records sideband events. That allows you to make sense of the
userspace addresses, but by then you might as well record BRBE in the
guest in the first place. See [1] for an example.
With kernel addresses it might be even easier as all you need is
--guestvmlinux, --guestkallsyms etc and no sideband events.
[1]:
https://lore.kernel.org/all/20220711093218.10967-25-adrian.hunter@intel.com/
>
> For nVHE, this requires explicit handling for guests. Before
> entering a guest, save the BRBE state and disable the it. When
> returning to the host, restore the state.
>
> For VHE, it is not necessary. We initialize
> BRBCR_EL1.{E1BRE,E0BRE}=={0,0} at boot time, and HCR_EL2.TGE==1 while
> running in the host. We configure BRBCR_EL2.{E2BRE,E0HBRE} to enable
> branch recording in the host. When entering the guest, we set
> HCR_EL2.TGE==0 which means BRBCR_EL1 is used instead of BRBCR_EL2.
> Consequently for VHE, BRBE recording is disabled at EL1 and EL0 when
> running a guest.
>
> Should recording in guests (by the host) ever be desired, the perf ABI
> will need to be extended to distinguish guest addresses (struct
> perf_branch_entry.priv) for starters.
There's already this which would be enough (if every entry in the branch
buffer matches it):
sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL
sample->cpumode == PERF_RECORD_MISC_GUEST_USER
But I don't think we need all the extra complexity. Just let the guest
use all of BRBE and then there isn't really a use case that's not
supported. I assume a lot of these workflows were added for trace
because it's not supported in guests, but I don't think that applies to
BRBE so we can skip them and go straight to full BRBE in guest support.
As a later change obviously, these comments are more about the commit
message.
James
Powered by blists - more mailing lists