From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B1122472BC; Wed, 21 May 2025 09:36:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747820222; cv=none; b=R1gdlfGnokxH4GOWpFrRtpP1UH9xsLAqmQdMtDvWZ/XWc22TGA6w11I5ByVirGlUOgQ6n8o7zxyR/esrseweUWGddni091om5XSdMuo0QSLUAdTHpJR2czhpWJ1Ne5zd28nsxpaKIV+eDzx+0JVk1dD15eLgzGtTBGNW2zdwKVQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747820222; c=relaxed/simple; bh=1PncFmIAJ84Ts3xsxuSGdS6jgxzdgBDMZOlYYKVRVY8=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=gB+Lb7WjGGZSodJP7uSPuNCEVxPip2zRH/O46m9lm5XCIaY2fna6ETD2yjeDmbuwR3vz5T3wPIkhKLV6Af1uKm7HIHLJx3dgT0UBoZWGeQ9mSW2FxSzg86iZKXzCUKT7Y+2dfvarRcNGD/py8KTmd9GA5HnxedMK4GP5t0r8IgM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id BCA4A1515; Wed, 21 May 2025 02:36:45 -0700 (PDT) Received: from [10.57.50.40] (unknown [10.57.50.40]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id F39DC3F6A8; Wed, 21 May 2025 02:36:56 -0700 (PDT) Message-ID: Date: Wed, 21 May 2025 10:36:56 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v22 4/5] KVM: arm64: nvhe: Disable branch generation in nVHE guests Content-Language: en-GB To: "Rob Herring (Arm)" , Will Deacon , Mark Rutland , Catalin Marinas , Jonathan Corbet , Marc Zyngier , Oliver Upton , Joey Gouly , Zenghui Yu , James Clark , Anshuman Khandual , Leo Yan Cc: linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kvmarm@lists.linux.dev References: <20250520-arm-brbe-v19-v22-0-c1ddde38e7f8@kernel.org> <20250520-arm-brbe-v19-v22-4-c1ddde38e7f8@kernel.org> From: Suzuki K Poulose In-Reply-To: <20250520-arm-brbe-v19-v22-4-c1ddde38e7f8@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 20/05/2025 23:27, Rob Herring (Arm) wrote: > From: Anshuman Khandual > > 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 > Signed-off-by: Mark Rutland > Co-developed-by: Rob Herring (Arm) > Tested-by: James Clark > Reviewed-by: Leo Yan > Signed-off-by: Rob Herring (Arm) Reviewed-by: Suzuki K Poulose