Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp49997rwd; Mon, 15 May 2023 19:53:24 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6nPU+06jzHVNj8LrohcDLy7HUaBhjIVo+2w1XFQ8qELh5GNCADmHDElvhmRxCyhIdVb5HD X-Received: by 2002:a05:6a20:8f23:b0:106:4e09:151f with SMTP id b35-20020a056a208f2300b001064e09151fmr5615671pzk.60.1684205604436; Mon, 15 May 2023 19:53:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684205604; cv=none; d=google.com; s=arc-20160816; b=NM9xFJMtl3q6T9ElIRA9T82/z4qpLBiaCfBo1ANnJGObD1I7O2in79sEQoy/h3aaOr vzThyG5vp81jXpuCBpNtD/ZWtOwDlEwYB0EZG9/B2+am5SRp0MTudFTDRsw1a1S4vpYj AGpDbaeDccmz/UNcwL6z9yYxZn9YSd6/MVqVOY1XANIj3vYZ7+lhfnnaohYnWXPhTJch XguwQPt8Fq8/ojEL/UVc5vVoONOQQOZtixtZcm1Wr4DoMT74ry10emP+o5QiZoK7ruCk jsFd8cKdcYS4/yZq2ftmQpX5EA+/Ei2mubDLUcyngBV6BNuvLVbcQtsoUquINSefvjRf FdVA== 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=L+AVStYKwXzyC9zOUNVcRis+q7ebS+YCWtrNclAkQK4=; b=wv6VMciuhR1weBn1rZFkT4KicUUjkVtAMxyTQxzbMagmiDMb+s4XANX66nzRCVrEfF wq6cIsHpGDtuzCsjALNy8RMJnr6SLM/E1utWaA7crJKgjxXMmSCXcsHp/0CNPFSL5l7I CFuYtQSqF0KzJLB7rOqx5DHMBFFtGHwXZYMNbhFJOaA8wZ5rbjNSz+WoINBnG/ARY1OH aLCC5kWqJPgZgNoDlGmE7aK/i7QSAciQM0I0cwVznjkbWR+9cYpiwrK3oVVGvglri188 U2L8lJnPReYxJ09ws8WzL0Iy5Reg+rU03VVSokGGqMkk33EJIRe+N86SIOLDUaht100S DiEQ== 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 v1-20020a637a01000000b00517f0c53072si18631317pgc.170.2023.05.15.19.53.12; Mon, 15 May 2023 19:53:24 -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 S229741AbjEPCng (ORCPT + 99 others); Mon, 15 May 2023 22:43:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbjEPCnf (ORCPT ); Mon, 15 May 2023 22:43:35 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D529BE79 for ; Mon, 15 May 2023 19:43:33 -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 DD1B12F4; Mon, 15 May 2023 19:44:17 -0700 (PDT) Received: from [10.163.70.134] (unknown [10.163.70.134]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0596D3F663; Mon, 15 May 2023 19:43:30 -0700 (PDT) Message-ID: Date: Tue, 16 May 2023 08:13:27 +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 V2] arm64: Disable EL2 traps for BRBE instructions executed in EL1 Content-Language: en-US To: Marc Zyngier Cc: linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Mark Brown , linux-kernel@vger.kernel.org References: <20230515105328.239204-1-anshuman.khandual@arm.com> <86ilctn233.wl-maz@kernel.org> From: Anshuman Khandual In-Reply-To: <86ilctn233.wl-maz@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 5/15/23 19:12, Marc Zyngier wrote: > On Mon, 15 May 2023 11:53:28 +0100, > Anshuman Khandual wrote: >> >> This disables EL2 traps for BRBE instructions executed in EL1. This would >> enable BRBE to be configured and used successfully in the guest kernel. >> While here, this updates Documentation/arm64/booting.rst as well. >> >> Cc: Catalin Marinas >> Cc: Will Deacon >> Cc: Mark Brown >> Cc: Marc Zyngier >> Cc: linux-arm-kernel@lists.infradead.org >> Cc: linux-kernel@vger.kernel.org >> Signed-off-by: Anshuman Khandual >> --- >> This patch applies on v6.4-rc2 >> >> Changes in V2: >> >> - Updated Documentation/arm64/booting.rst >> >> Changes in V1: >> >> https://lore.kernel.org/all/20230324055127.2228330-1-anshuman.khandual@arm.com/ >> >> Documentation/arm64/booting.rst | 8 ++++++++ >> arch/arm64/include/asm/el2_setup.h | 10 ++++++++++ >> 2 files changed, 18 insertions(+) >> >> diff --git a/Documentation/arm64/booting.rst b/Documentation/arm64/booting.rst >> index ffeccdd6bdac..cb9e151f6928 100644 >> --- a/Documentation/arm64/booting.rst >> +++ b/Documentation/arm64/booting.rst >> @@ -379,6 +379,14 @@ Before jumping into the kernel, the following conditions must be met: >> >> - SMCR_EL2.EZT0 (bit 30) must be initialised to 0b1. >> >> + For CPUs with the Branch Record Buffer Extension (FEAT_BRBE): >> + >> + - If the kernel is entered at EL1 and EL2 is present: >> + >> + - HFGITR_EL2.nBRBINJ (bit 55) must be initialised to 0b1. >> + >> + - HFGITR_EL2.nBRBIALL (bit 56) must be initialised to 0b1. >> + >> The requirements described above for CPU mode, caches, MMUs, architected >> timers, coherency and system registers apply to all CPUs. All CPUs must >> enter the kernel in the same exception level. Where the values documented >> diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h >> index 037724b19c5c..06bf321a17be 100644 >> --- a/arch/arm64/include/asm/el2_setup.h >> +++ b/arch/arm64/include/asm/el2_setup.h >> @@ -161,6 +161,16 @@ >> 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 > > This will break badly if someone inserts something between this hunk > and the initial setting of HFGITR_EL2. I'd really prefer a RMW > approach. It's not that this code has to be optimised anyway. Something like this instead ? So that even if there are more changes before this hunk, it will be fetched correctly with first mrs_s and only additional bits related to BRBE will be set there after. diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h index 037724b19c5c..bfaf41ad9c4e 100644 --- a/arch/arm64/include/asm/el2_setup.h +++ b/arch/arm64/include/asm/el2_setup.h @@ -161,6 +161,16 @@ 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_\@ + + mrs_s x0, SYS_HFGITR_EL2 + 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_\@