Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2059636rwd; Mon, 15 May 2023 06:50:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6JvukJrhMOYMETvGCKd3ZRbDhRQVcwn8SRSZxeuquntONDs+5t8mIcnSiRv+1hjfBVPA3u X-Received: by 2002:a17:902:edd0:b0:1aa:e425:2527 with SMTP id q16-20020a170902edd000b001aae4252527mr34061448plk.21.1684158613846; Mon, 15 May 2023 06:50:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684158613; cv=none; d=google.com; s=arc-20160816; b=JbaXA1st/hfzRulxgSLjgmhfE02Lj5C73Jwz0fsPybEv3afvwBEbfTWV/kzRpTTPne YGBzxfDcVdNQzU6KdRZuWh12cu9OXxVj2rLzJmhVgJxH2q3xktjxQA4Sef907oww7akH rzcSitdeyUXzFWPONzjCt77+tkNejfkAfPGzPCzvY+Hnxor1WLn0aqIKtU6ltEVZggxI mSuQS1CrOooJz0lv6w/mSXg89imW3TeQX2unbOeo/vjTq0vFWLlMXUCU1+oRFu1QzdRg MxX6pNh+8Tghbs9aXzvFTlEVtt490TcT7AK00XEYnMlTg8i0XP69UtQFuZNq27TMQuck NbLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature; bh=N9iuXqNrvBK4z6/TGbUd7aDLHBKsLLsQ8rhTYtqqRrY=; b=rs49HHEhINHsV1VrO3wuSdymyjMtCqfggGrti5NwFdEbCDtVxGJe20Tmsg9puylkOR l7VbMDWOpbcla+dNbWoXrtoAwSj2XBhTMqgR97z8gsvEOh1k7kkm4Rd0GncJof47d9sL acZkj+P5VUVw+MSv+8NXMxgFtjHF87/dyGvAylzYVo//j4A9QBV5N8N9Ujdbtfssc+4U cGzSQh9KAwQAQFqfvXnA2fFx6irQOufTJMrSr0LedaRsVssqwfdwQxaVG3OHBw+E35uv xhZSSzC1wsbOPamDpus3P0Mh0LxEHVSHjgSwauCoYrILhxKS2DaS6cBdWCu23sTO0x6V Iisw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TmqSVDEx; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i12-20020a17090332cc00b001a59439dbfesi17019235plr.529.2023.05.15.06.50.00; Mon, 15 May 2023 06:50:13 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TmqSVDEx; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241640AbjEONmP (ORCPT + 99 others); Mon, 15 May 2023 09:42:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240509AbjEONmN (ORCPT ); Mon, 15 May 2023 09:42:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4D0F10EA for ; Mon, 15 May 2023 06:42:12 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3A528624B7 for ; Mon, 15 May 2023 13:42:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B237C433EF; Mon, 15 May 2023 13:42:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684158131; bh=M4oE5zTdWt8UHV4GZZzQWHxwvY1pWNA64W1u7qoq6ps=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=TmqSVDExYGsRO2K8Sr504iEbECj7mmXN+tX+jBP/YkiNJyOFVguN1tx/fz/upZnb2 x+kFp89hzh5BTr3BJTqPmsiN+i28yvRIFmOf+Aw3VZ6seA42mRALby3YUM5YSpnIt6 hdLbuG0L1xvPDCNVbF46ocLxq7LPd+GdoaBUKYIf2jEK5bqiLa+9V5UZvv+aA5bWL4 MP6ggou/A/Yq/YfODE7zL5mGm1T3L/cY1lZ9E7R2hlOLehBOm5br3W+QYYIzTg3Gpd DuIsOxiEcmaLfeKhV8Gf4KzNGtaN9hiXkwpxpX101QU5nZlXPTF9/RsIH4tMA5oH9w 3/X0VJbNyJEgw== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pyYSm-00FFaJ-W0; Mon, 15 May 2023 14:42:09 +0100 Date: Mon, 15 May 2023 14:42:08 +0100 Message-ID: <86ilctn233.wl-maz@kernel.org> From: Marc Zyngier To: Anshuman Khandual Cc: linux-arm-kernel@lists.infradead.org, Catalin Marinas , Will Deacon , Mark Brown , linux-kernel@vger.kernel.org Subject: Re: [PATCH V2] arm64: Disable EL2 traps for BRBE instructions executed in EL1 In-Reply-To: <20230515105328.239204-1-anshuman.khandual@arm.com> References: <20230515105328.239204-1-anshuman.khandual@arm.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: anshuman.khandual@arm.com, linux-arm-kernel@lists.infradead.org, catalin.marinas@arm.com, will@kernel.org, broonie@kernel.org, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,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 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. M. -- Without deviation from the norm, progress is not possible.