Re: [PATCH v19 10/11] KVM: arm64: nvhe: Disable branch generation in nVHE guests
From: James Clark
Date: Mon Feb 03 2025 - 06:28:59 EST
On 03/02/2025 12:43 am, Rob Herring (Arm) wrote:
From: Anshuman Khandual <anshuman.khandual@xxxxxxx>
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@xxxxxxxxx/
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