Message ID | 20230515105328.239204-1-anshuman.khandual@arm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp6839146vqo; Mon, 15 May 2023 04:18:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7Ec5+/Ntru9tW4WpjGFs/09nlagvwGznf8cd/lQ21uB/Cywhb2p1/iPd3c4QAWhQMkkO9B X-Received: by 2002:a17:903:245:b0:1a9:85f2:5df6 with SMTP id j5-20020a170903024500b001a985f25df6mr40574136plh.6.1684149483908; Mon, 15 May 2023 04:18:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684149483; cv=none; d=google.com; s=arc-20160816; b=i1ZOCyA0XHi4a7CKY7KS1io6hbp7XJk9oc3JM8yC39+LC6MGVIrcESmf2LaAQXIAEL uthnMjtYnrzOqZd/vEo37G0KkE3IuAFxMHoLSSgUetuXBcARcBCHRrLEcUgC7ln6iaQg vh3N+qOE9NldkAsEYld8N0GJDwBcuX5UgfwyEc6eTh+U2urWydbV7DPEexm+qwkxQIFu 9lNL7RQ0PZIdxLsD3YpClbUYjENMPShtgGbRvdGl6SKn2z/vrQyjHEaZD+JP5R/V1l3m kNJA385A4n6LbmlgBY5ZG/EshiM96wsJcyllUPd0VzecHikGfkO2MDmFKOjwTyNwi0N8 8gTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=8WYOPuFZ2jZUf0hzr6eRdkeBfxRVlA1SvCZzB2pY5bc=; b=HjKE9W9NFurQLoAXCvpPNva61O/b1rzT9OD6l+HFcozksyyLkqap/j3VSbGGmCXG9a 5NoYaVSAGrGy8EozEE9dg/uTSyoUla//0joRjQrsZu5h+fjmlhgl8PYRQcgTi4i/5On/ AKbfZEONaHb5zgBdQ93vwFHB+Gu6pEIRjRIa//0UJIgtm8Hb1Kfvr6y9h89zsp+M0mDb yFX4+yO6UZj+ZeFiQrqPxPfWPbTuw5LAFG1WqrE9Ac5CuBi+pzmd2duw7Or44Oetrlhl +AWKpRKK5cr6N2h7yOOFAJ+5ExSxagCibkhFeiXBUu+Pt4AoICwhbme1oj9Myy8ZpVwU XPLg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id je20-20020a170903265400b001ae001e8bc9si4835511plb.188.2023.05.15.04.17.48; Mon, 15 May 2023 04:18:03 -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 S240784AbjEOKxo (ORCPT <rfc822;peekingduck44@gmail.com> + 99 others); Mon, 15 May 2023 06:53:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235490AbjEOKxm (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 15 May 2023 06:53:42 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 912BC10CA for <linux-kernel@vger.kernel.org>; Mon, 15 May 2023 03:53:41 -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 C59242F4; Mon, 15 May 2023 03:54:25 -0700 (PDT) Received: from a077893.arm.com (unknown [10.163.70.57]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 256023F7BD; Mon, 15 May 2023 03:53:37 -0700 (PDT) From: Anshuman Khandual <anshuman.khandual@arm.com> To: linux-arm-kernel@lists.infradead.org Cc: Anshuman Khandual <anshuman.khandual@arm.com>, Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>, Mark Brown <broonie@kernel.org>, Marc Zyngier <maz@kernel.org>, linux-kernel@vger.kernel.org Subject: [PATCH V2] arm64: Disable EL2 traps for BRBE instructions executed in EL1 Date: Mon, 15 May 2023 16:23:28 +0530 Message-Id: <20230515105328.239204-1-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765958729015424486?= X-GMAIL-MSGID: =?utf-8?q?1765958729015424486?= |
Series |
[V2] arm64: Disable EL2 traps for BRBE instructions executed in EL1
|
|
Commit Message
Anshuman Khandual
May 15, 2023, 10:53 a.m. UTC
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 <catalin.marinas@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
Cc: Marc Zyngier <maz@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com>
---
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(+)
Comments
On Mon, 15 May 2023 11:53:28 +0100, Anshuman Khandual <anshuman.khandual@arm.com> 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 <catalin.marinas@arm.com> > Cc: Will Deacon <will@kernel.org> > Cc: Mark Brown <broonie@kernel.org> > Cc: Marc Zyngier <maz@kernel.org> > Cc: linux-arm-kernel@lists.infradead.org > Cc: linux-kernel@vger.kernel.org > Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> > --- > 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. M.
On 5/15/23 19:12, Marc Zyngier wrote: > On Mon, 15 May 2023 11:53:28 +0100, > Anshuman Khandual <anshuman.khandual@arm.com> 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 <catalin.marinas@arm.com> >> Cc: Will Deacon <will@kernel.org> >> Cc: Mark Brown <broonie@kernel.org> >> Cc: Marc Zyngier <maz@kernel.org> >> Cc: linux-arm-kernel@lists.infradead.org >> Cc: linux-kernel@vger.kernel.org >> Signed-off-by: Anshuman Khandual <anshuman.khandual@arm.com> >> --- >> 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_\@
On Tue, 16 May 2023 03:43:27 +0100, Anshuman Khandual <anshuman.khandual@arm.com> wrote: > > > > On 5/15/23 19:12, Marc Zyngier wrote: > > On Mon, 15 May 2023 11:53:28 +0100, > > Anshuman Khandual <anshuman.khandual@arm.com> wrote: > >> [...] > >> 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_\@ Yes, this is much better. M.
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 + +.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_\@