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: 94511 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp267826vqo; Tue, 16 May 2023 01:35:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4HlHwn6akap1TvOkr80cKTy/Rtm7OrJ/5BKhJDivGl9Co2Ehw2OvbvgyynKl0ZBvghSTvb X-Received: by 2002:a05:6a21:9011:b0:f2:ad27:f98a with SMTP id tq17-20020a056a21901100b000f2ad27f98amr39008459pzb.14.1684226134325; Tue, 16 May 2023 01:35:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684226134; cv=none; d=google.com; s=arc-20160816; b=ydzZ1soGTTKIvV6cgVJ5qPQp0hxU2//v90QVyIPVdkv8qeuHtcAFIOHlI7Q2FfZj92 B+HwwPSfRmMO1RnRlgYYvVXKhajbpFoLpTOHq3vRujoXhtFcq6+S35mh7SXfD51Yzu+g EUEIyx/kdVi7Fsv3dw0MZdwijWqZQ3Wl9J4zwczjl4JxKlJJhYqymtMgGYWVDfikqvee 0pLK53cHZlnQSwpGCwIURicPqVmpHTXsgaaxR/c625c4VQDfs/9Fby/6DgGx76R+YuVF Ojrx3iR6eVo8lybvvH19IMc96Z2NDAhgeYHZoS+hgmifKjd9xv/ORV27GzwaH6WktCe2 4Q4A== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q17-20020a638c51000000b0052d7238ad5asi18433720pgn.721.2023.05.16.01.35.22; Tue, 16 May 2023 01:35:34 -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 S231645AbjEPIab (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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766039103070262321?= X-GMAIL-MSGID: =?utf-8?q?1766039103070262321?= 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_\@