From patchwork Tue May 16 08:30:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 13242782 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 06487C77B7A for ; Tue, 16 May 2023 08:30:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=fGctGNzHewXUpj5Uoz0gDQ5Po0AhN79dlEDaXQkS3eI=; b=gVC6AolqFT0+OH Hi+lMu29pVQCMGV6NxEZGv0kamFdIOUq7v1UueYXXUp2oIGWte6oK9vC8r7QUuEoTfRFJtwZiy4tI PsomHLvHxYZLIr4DINE/LJVPl9Pr0iY6z/AbkZRPhJSTptYaarq0/OQwd+Jyp694AU6XWx92H4fwe QgMfgSpSOssHPnJFc+zK7GReW4YsS2IpE+JwTehzbh91Svu3NXxsipajwJDTdnrtvmDI88qrmASKu 07lJ/p0FdujeZfD1Ndt2HdqeYIWF63YALZW+vtziETbHOhHXog6DDw1KmYBrkZIfUEK6VoJ7o5Jfz Jdej1tPPB8VOLV8e8+vQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pyq4t-004rH1-05; Tue, 16 May 2023 08:30:39 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pyq4p-004rE0-1a for linux-arm-kernel@lists.infradead.org; Tue, 16 May 2023 08:30:37 +0000 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230516_013035_596796_E59D8478 X-CRM114-Status: GOOD ( 10.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 Acked-by: Marc Zyngier --- 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_\@