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 5FFF627817D; Wed, 28 May 2025 16:09:18 +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=1748448560; cv=none; b=tchcmLfnlgpmHPWJy0aK6qhO4hh4S89euPjpN59rhUi4NYtyL/ZWxIE1Mh3TAlxUac+V25SQfeNQh1TGcjwH8lySbaJvJ3cBtK/3pThHfKi8uNdSCZyZ+3g/+NlCi5ZUzPZOU+AL03miVFbrR3dKpBpFNrqFO9ZNc1dGsEbj4yU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748448560; c=relaxed/simple; bh=O2qtelB4US+cJIhzPme3LIw1Jt2jPMgLescTbOZA/UE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=jT+NIGTPkbdbfNCpJMihc7xENwkERpzYdQDPBX3PF/o9RTFa7cV0YCs/nidGtl4Cf7T8fhmHUl1Nsi3Ue5Bsk87TTuW8TJ/O5DsfKAc4pVe1vto6Iil6kq2bVXGUYIEKNe5f/p+SSm2fVZ+YCGCqb2UnuhxPsAD1X8jd/LmZiSc= 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 1FEFF1A2D; Wed, 28 May 2025 09:09:01 -0700 (PDT) Received: from [10.57.48.160] (unknown [10.57.48.160]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7C4D93F673; Wed, 28 May 2025 09:09:14 -0700 (PDT) Message-ID: <4f5c956e-19e7-4df0-b1f2-d8750c0af4d7@arm.com> Date: Wed, 28 May 2025 17:09:12 +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 v21 3/4] 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: <20250407-arm-brbe-v19-v21-0-ff187ff6c928@kernel.org> <20250407-arm-brbe-v19-v21-3-ff187ff6c928@kernel.org> From: Suzuki K Poulose In-Reply-To: <20250407-arm-brbe-v19-v21-3-ff187ff6c928@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 07/04/2025 18:41, 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 > Signed-off-by: Rob Herring (Arm) Reviewed-by: Suzuki K Poulose