[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <86r00idrpd.wl-maz@kernel.org>
Date: Wed, 21 May 2025 14:22:06 +0100
From: Marc Zyngier <maz@...nel.org>
To: "Rob Herring (Arm)" <robh@...nel.org>
Cc: Will Deacon <will@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Catalin Marinas <catalin.marinas@....com>,
Jonathan Corbet <corbet@....net>,
Oliver Upton <oliver.upton@...ux.dev>,
Joey Gouly <joey.gouly@....com>,
Suzuki K Poulose <suzuki.poulose@....com>,
Zenghui Yu <yuzenghui@...wei.com>,
James Clark <james.clark@...aro.org>,
Anshuman Khandual <anshuman.khandual@....com>,
Leo Yan <leo.yan@....com>,
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
Subject: Re: [PATCH v22 4/5] KVM: arm64: nvhe: Disable branch generation in nVHE guests
On Tue, 20 May 2025 23:27:39 +0100,
"Rob Herring (Arm)" <robh@...nel.org> 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 (though events are).
> Support for BRBE in guests will supported by providing direct access
> to BRBE within the guests. That is how x86 LBR works for guests.
> Therefore, BRBE needs to be disabled on guest entry and restored on
> exit.
>
> 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. BRBE records would also need to be
> invalidated on guest entry/exit as guest/host EL1 and EL0 records can't
> be distinguished.
>
> Signed-off-by: Anshuman Khandual <anshuman.khandual@....com>
> Signed-off-by: Mark Rutland <mark.rutland@....com>
> Co-developed-by: Rob Herring (Arm) <robh@...nel.org>
> Tested-by: James Clark <james.clark@...aro.org>
> Reviewed-by: Leo Yan <leo.yan@....com>
> Signed-off-by: Rob Herring (Arm) <robh@...nel.org>
> ---
> v20:
> - Reword commit message about no guest recording.
> - Add BRBE to __kvm_vcpu_run() synchronization comment
>
> v19:
> - Rework due to v6.14 debug flag changes
> - Redo commit message
> ---
> arch/arm64/include/asm/kvm_host.h | 2 ++
> arch/arm64/kvm/debug.c | 4 ++++
> arch/arm64/kvm/hyp/nvhe/debug-sr.c | 32 ++++++++++++++++++++++++++++++++
> arch/arm64/kvm/hyp/nvhe/switch.c | 2 +-
> 4 files changed, 39 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
> index e98cfe7855a6..e3f1e7b5ce52 100644
> --- a/arch/arm64/include/asm/kvm_host.h
> +++ b/arch/arm64/include/asm/kvm_host.h
> @@ -654,6 +654,7 @@ struct kvm_host_data {
> #define KVM_HOST_DATA_FLAG_HAS_TRBE 1
> #define KVM_HOST_DATA_FLAG_TRBE_ENABLED 4
> #define KVM_HOST_DATA_FLAG_EL1_TRACING_CONFIGURED 5
> +#define KVM_HOST_DATA_FLAG_HAS_BRBE 6
Just as a heads up: this is going to clash with what is currently
queued in -next (bits 6 and 7 are already claimed).
Otherwise,
Acked-by: Marc Zyngier <maz@...nel.org>
M.
--
Without deviation from the norm, progress is not possible.
Powered by blists - more mailing lists