Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp515453rwl; Thu, 23 Mar 2023 20:34:36 -0700 (PDT) X-Google-Smtp-Source: AKy350aw7MdwMz/+R6rOyym0y+2AAPhuAHljq64Pcyy7q533ZFU3KMwTLAs1gcWM22iatIRDlRAX X-Received: by 2002:a17:906:2cc8:b0:93d:cbf8:ca14 with SMTP id r8-20020a1709062cc800b0093dcbf8ca14mr892995ejr.75.1679628876520; Thu, 23 Mar 2023 20:34:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679628876; cv=none; d=google.com; s=arc-20160816; b=FYxn66GSpLKL2gZjKJQCIwDEJ5RwuN8bDyuy5v965WuQ8epO6tk0YvOPKwa4QWp4aN 6tx7x41IAUyBNJrsjk3iwR1YdJG9BG1hk9f4165+Y34nE9zhcRABh7fSUsLtqgooY26g YmIt5yMYuDQhDrZgWaMJTpaVw8Fj4OQrUAY0zK8ucq8CIfcPpY0vnyzscj61jMIk2Z2u DeACqNQvTC5Rkib8aivyM2ZC5+IrO90zhOYIGy1ze81ZzBvfaMUWXfQ8ciLEwpL3WisN c84tyKKbROyJO+wUckRzPLimZecjo5Y+OS9EywaPACJFiWo2l8FlKzzyYLczXQx58/U5 hJtA== 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=S9BJk1e+2LLLQGl05zYwFfMwJU9nto7kayYKWs6smtA=; b=cbR/1jhpnA71KjKVwKLhONvfAb19lCHeSrFZ+EbhK56yElfzYIeG63dfvw+2j1VeJL XjyeHJeBxxAm8SuQQp8ZQlAAXzYiJrnp7SkO13dsUVXOK2Dkp8ClOYcb4LQCgxN7kXhb 0RaBWR0qIoSHU6b8fZrl25LBOOgbiYC8f16IfPl99KwlQXsXP6rk1aF9YQ9aSkXOxW/X xJt14WgBb3m32w3gMpti2ZCm1POjyMeTeAdhHxSTZZ+4w4LQ9bDoA6LpADiPY/S1D75P LQoUUOhICLf2ulTdAhbl4ae5Oneo5AQb9Ra8nybpJsNimVfb7arOJ57xbHpM+ZVLZ7LG oCwg== 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 hu11-20020a170907a08b00b00933bc889bf3si13756535ejc.292.2023.03.23.20.34.12; Thu, 23 Mar 2023 20:34:36 -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 S231289AbjCXDUt (ORCPT + 99 others); Thu, 23 Mar 2023 23:20:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbjCXDUq (ORCPT ); Thu, 23 Mar 2023 23:20:46 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AA50520D31; Thu, 23 Mar 2023 20:20:40 -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 382F912FC; Thu, 23 Mar 2023 20:21:24 -0700 (PDT) Received: from [10.162.40.17] (unknown [10.162.40.17]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B32133F67D; Thu, 23 Mar 2023 20:20:35 -0700 (PDT) Message-ID: <4665d03f-b801-679c-0b52-c426404284b9@arm.com> Date: Fri, 24 Mar 2023 08:50:32 +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> <4d93a3de-c86d-454b-8a43-b24e62ea3be7@sirena.org.uk> From: Anshuman Khandual In-Reply-To: <4d93a3de-c86d-454b-8a43-b24e62ea3be7@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 On 3/23/23 18:24, Mark Brown wrote: > On Thu, Mar 23, 2023 at 09:55:47AM +0530, Anshuman Khandual wrote: >> On 3/22/23 00:32, Mark Brown wrote: > >>> 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. > > Right, for backwards compatibility all newly added fields are trap by > default. Okay > >> 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. > > It should prevent the host as well shouldn't it? In a EL2 host environment, BRBE is being enabled either in EL2 (kernel/hv) or in EL0 (user space), it never gets enabled on EL1. Moreover BRBIALL/BRBINJ instructions are always executed while being inside EL2 (kernel/hv). Hence how could these instructions cause trap in EL2 ? > >> I guess something like the following (untested) needs to be done, to enable >> BRBE in guests. > >> + 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_\@: > > Yes, looks roughly what I'd expect. I could send an stand alone patch after your latest series [1], which disables BRBINJ/BRBIALL instruction trap in EL2 to enable BRBE usage in the guest. https://lore.kernel.org/all/20230306-arm64-fgt-reg-gen-v3-2-decba93cbaab@kernel.org/T/ > >>> 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. > > No fields at the minute but yes, like the other conversions. Sure.