Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp347406rwd; Tue, 16 May 2023 01:45:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4NOke6b9CRGWFnsnXkhSWVLZTFtKXL21D4zXYqmPlOeRKZUqd7uffRc9aKavf1SPC1sFz2 X-Received: by 2002:a17:903:32c5:b0:1aa:e5cd:647a with SMTP id i5-20020a17090332c500b001aae5cd647amr50877383plr.23.1684226731758; Tue, 16 May 2023 01:45:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684226731; cv=none; d=google.com; s=arc-20160816; b=tL6Vs+eFE3/dsDq0zhE/5x2XY3kWBnDTk+aCYfuW01+1Ed9taida7hNnX7P+kA+pCM EACBWzDJhqQY8y7tzCruzteKvOADs7/1fq403HLqciTNQs8bAF1qi8JAdhGn0OD3Un6E SRTeCoz/YjSFRqYbCl8zJUQexpl2OzPt6++YK/LoXV6WZ0W4ZZRtAECxrNPmApNLtAu7 AzybH9r9cQBSaOx9XsxkALNPgJe5wiMLahWXdIRfMX0ZQkLuCe0/bnb6+IKOpudMCOFP 3X9AeY1f8d9O4bUdy0vbcW00pr/nGHLeAcMmlLMCx8gr5aVLm04U6yQSkW0+KAB2V1W3 yX9g== 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=C1zuajbW4+S7k1AhX92BD377Le2K+XAGg7Bj2lftK8Q=; b=itOMJXQB6+47G/zEP3GgCrUm9ncwJWsATxSbjZrQCV0n2dsq23f6JFBnr8CvqoztFL wIZg1AsMo2fBZjNsWYxlMrZMpFWW+MCffZ+eH/pYaodjfjAj4+HIHv/jtTI53mm3MYXE JVPVdRV6oErZcppmP5YzTOeMTkH/aZSl3yIntjBOozq4COIdBP3MwkH+TkxZ8qyHHEFN wsUfS9ON6N44hX3kQ6S8UKQtS+3GITikMfYLjVrAc2G9Ey/7fgIu8a5rkuDmOHCZ3k3X gO6obD+B4TiK8ys54uEaS3KsB0kaAyY2D+Zn7MxL5UxEJq9/2fLiVW33gH+7Pgj1a2Zl uGkA== 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 n6-20020a1709026a8600b001a2a4eb10d6si17574939plk.58.2023.05.16.01.45.16; Tue, 16 May 2023 01:45:31 -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 S231644AbjEPIab (ORCPT + 99 others); Tue, 16 May 2023 04:30:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231490AbjEPIa2 (ORCPT ); Tue, 16 May 2023 04:30:28 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E1C041BFD for ; Tue, 16 May 2023 01:30:26 -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 355C22F4; Tue, 16 May 2023 01:31:11 -0700 (PDT) Received: from a077893.arm.com (unknown [10.163.70.134]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 99DE63F7BD; Tue, 16 May 2023 01:30:23 -0700 (PDT) From: Anshuman Khandual To: linux-arm-kernel@lists.infradead.org Cc: Anshuman Khandual , Catalin Marinas , Will Deacon , Mark Brown , Marc Zyngier , linux-kernel@vger.kernel.org Subject: [PATCH V3] arm64: Disable EL2 traps for BRBE instructions executed in EL1 Date: Tue, 16 May 2023 14:00:15 +0530 Message-Id: <20230516083015.569248-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: X-Mailing-List: linux-kernel@vger.kernel.org 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 V3: - Updated with RMW pattern as per Marc Changes in V2: https://lore.kernel.org/all/20230515105328.239204-1-anshuman.khandual@arm.com/ - 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..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_\@ -- 2.25.1