Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp7065906rwl; Wed, 22 Mar 2023 21:28:20 -0700 (PDT) X-Google-Smtp-Source: AK7set8H/os8xjA5prXRWlQMC7wtiZxprezWMu6dXScL/jq5bZuNLwS1T5qwKFGs2WMB4gnIBHni X-Received: by 2002:a05:6a20:3554:b0:d9:ab8b:9f4b with SMTP id f20-20020a056a20355400b000d9ab8b9f4bmr1779643pze.46.1679545700642; Wed, 22 Mar 2023 21:28:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679545700; cv=none; d=google.com; s=arc-20160816; b=c+z6GrMbOQTGpOjICF53S42bCxiFB1bY3e+OYyDd8kiTHo5sJQQRif2Oz/GjeBs5UB 3N1671/px+OZKRwGD6HXBayNaNChMUeLtLESLp8qbuAV+qiIRLKerm6Ixquwt9QPRKbi UECqDNPyqcTq7vUZqk4sYgosOvwqAAgQIAUv/GbwcM78liIoR3UIwYypONgj6Zrk4Kgo tRxLk+XqKKvdoWsKWruTMXj6Y0DF/i8TMiRdvy6FTDNz7boGX3nvweSSwXI9gpsaON2l DrJOvZvGnRhZa3JBDSb2t3oq5sb1/Ay2+H7HPYK6pc3529aH8JZW1/wcaNmANIrP/LMJ EQJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=SXl3EkY8trUygxpupdKm9DFmEwm5CIWK80+hyql43kQ=; b=jRXS4Plx2i+2q7LV/xA8ykpRTKGbTcokn/M4dceFKhpgx2IKynXeh0FlaQCHsWfM83 mbixKggbSjPtfXgtu843vcP6LllUEk+GT0NWH9t1TuF7kV4dni9/7+DgmmFZc7Iv1utd hbSqy39HEawNJQORcCGZdrX7+E3ZtkHzoYwIaff+J/ASxShy4pn6Ig34KNBebsDKuLrQ Kba+Pz9/zCykwq/XrGlI5PM04JGTexBFcP524LN3zM3l1bxaU/BYkB4cQOtIpT/SJvYD fps3eOsfNuPeuXpNimHGaSYrgCUYbgQsz7VaSqfCZc1rMUyHkHu2EgNq5eTYAxs91xwK jjsQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q25-20020a637519000000b0050c0f15c68fsi16927387pgc.77.2023.03.22.21.28.08; Wed, 22 Mar 2023 21:28:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229690AbjCWE0A (ORCPT + 99 others); Thu, 23 Mar 2023 00:26:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbjCWEZ4 (ORCPT ); Thu, 23 Mar 2023 00:25:56 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7B873AD31; Wed, 22 Mar 2023 21:25:55 -0700 (PDT) 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 0106B4B3; Wed, 22 Mar 2023 21:26:39 -0700 (PDT) Received: from [10.162.40.16] (a077893.blr.arm.com [10.162.40.16]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C720E3F766; Wed, 22 Mar 2023 21:25:50 -0700 (PDT) Message-ID: Date: Thu, 23 Mar 2023 09:55:47 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH V9 00/10] arm64/perf: Enable branch stack sampling Content-Language: en-US To: Mark Brown Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, will@kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, James Clark , Rob Herring , Marc Zyngier , Suzuki Poulose , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , linux-perf-users@vger.kernel.org References: <20230315051444.1683170-1-anshuman.khandual@arm.com> <655ff114-99d2-4612-9167-cc8688f2b6b2@sirena.org.uk> From: Anshuman Khandual In-Reply-To: <655ff114-99d2-4612-9167-cc8688f2b6b2@sirena.org.uk> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.3 required=5.0 tests=NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello Mark, On 3/22/23 00:32, Mark Brown wrote: > On Wed, Mar 15, 2023 at 10:44:34AM +0530, Anshuman Khandual wrote: >> This series enables perf branch stack sampling support on arm64 platform >> via a new arch feature called Branch Record Buffer Extension (BRBE). All >> relevant register definitions could be accessed here. >> >> https://developer.arm.com/documentation/ddi0601/2021-12/AArch64-Registers > > While looking at another feature I noticed that HFGITR_EL2 has two traps > for BRBE instructions, nBRBINJ and nBRBIALL which trap BRB INJ and BRB > IALL. Even if we don't use those right now does it make sense to Right, current branch stack sampling experiments have been on EL2 host itself. > document a requirement for those traps to be disabled now in case we > need them later, and do so during EL2 setup for KVM guests? That could > always be done incrementally. Unlike all other instruction trap enable fields in SYS_HFGITR_EL2, these BRBE instructions ones are actually inverted in semantics i.e the particular fields need to be set for these traps to be disabled in EL2. SYS_HFGITR_EL2.nBRBIALL SYS_HFGITR_EL2.nBRBINJ By default entire SYS_HFGITR_EL2 is set as cleared during init and that would prevent a guest from using BRBE. init_kernel_el() init_el2() init_el2_state() __init_el2_fgt() ........ msr_s SYS_HFGITR_EL2, xzr ........ I guess something like the following (untested) needs to be done, to enable BRBE in guests. diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h index 037724b19c5c..309708127a2a 100644 --- a/arch/arm64/include/asm/el2_setup.h +++ b/arch/arm64/include/asm/el2_setup.h @@ -161,6 +161,15 @@ msr_s SYS_HFGWTR_EL2, x0 msr_s SYS_HFGITR_EL2, xzr + mrs x1, id_aa64dfr0_el1 + ubfx x1, x1, #ID_AA64DFR0_EL1_BRBE_SHIFT, #4 + cbz x1, .Lskip_brbe_\@ + mov x0, xzr + orr x0, x0, #HFGITR_EL2_nBRBIALL + orr x0, x0, #HFGITR_EL2_nBRBINJ + msr_s SYS_HFGITR_EL2, x0 + +.Lskip_brbe_\@: mrs x1, id_aa64pfr0_el1 // AMU traps UNDEF without AMU ubfx x1, x1, #ID_AA64PFR0_EL1_AMU_SHIFT, #4 cbz x1, .Lskip_fgt_\@ diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysreg.h index b3bc03ee22bd..3b939c42f3b8 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -527,6 +527,9 @@ #define SYS_HFGITR_EL2 sys_reg(3, 4, 1, 1, 6) #define SYS_HACR_EL2 sys_reg(3, 4, 1, 1, 7) +#define HFGITR_EL2_nBRBIALL (BIT(56)) +#define HFGITR_EL2_nBRBINJ (BIT(55)) + #define SYS_TTBR0_EL2 sys_reg(3, 4, 2, 0, 0) #define SYS_TTBR1_EL2 sys_reg(3, 4, 2, 0, 1) #define SYS_TCR_EL2 sys_reg(3, 4, 2, 0, 2) > > I've got a patch adding the definition of that register to sysreg which > I should be sending shortly, no need to duplicate that effort. Sure, I assume you are moving the existing definition for SYS_HFGITR_EL2 along with all its fields from ../include/asm/sysreg.h to ../tools/sysreg. Right, it makes sense. - Anshuman