From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6497CC6FD1D for ; Fri, 17 Mar 2023 14:25:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230458AbjCQOZk (ORCPT ); Fri, 17 Mar 2023 10:25:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbjCQOZi (ORCPT ); Fri, 17 Mar 2023 10:25:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5DFA1559CB for ; Fri, 17 Mar 2023 07:25:34 -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 ams.source.kernel.org (Postfix) with ESMTPS id 0E325B825AA for ; Fri, 17 Mar 2023 14:25:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 337D7C433EF; Fri, 17 Mar 2023 14:25:29 +0000 (UTC) Date: Fri, 17 Mar 2023 14:25:26 +0000 From: Catalin Marinas To: Kristina Martsenko Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, Will Deacon , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Mark Rutland , Mark Brown , Luis Machado , Vladimir Murzin , linux-kernel@vger.kernel.org Subject: Re: [PATCH 01/10] KVM: arm64: initialize HCRX_EL2 Message-ID: References: <20230216160012.272345-1-kristina.martsenko@arm.com> <20230216160012.272345-2-kristina.martsenko@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230216160012.272345-2-kristina.martsenko@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 16, 2023 at 04:00:03PM +0000, Kristina Martsenko wrote: > ARMv8.7/9.2 adds a new hypervisor configuration register HCRX_EL2. > Initialize the register to a safe value (all fields 0), to be robust > against firmware that has not initialized it. I think the risk of firmware not initialising this register is small given that EL3 needs to set SCR_EL3.HXEn to allow EL2 access. But it doesn't hurt to re-initialise it in the hypervisor. > diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S > index 212d93aca5e6..e06b34322339 100644 > --- a/arch/arm64/kernel/head.S > +++ b/arch/arm64/kernel/head.S > @@ -572,6 +572,13 @@ SYM_INNER_LABEL(init_el2, SYM_L_LOCAL) > msr hcr_el2, x0 > isb > > + mrs x0, ID_AA64MMFR1_EL1 > + ubfx x0, x0, #ID_AA64MMFR1_EL1_HCX_SHIFT, #4 > + cbz x0, 3f > + mov_q x1, HCRX_HOST_FLAGS > + msr_s SYS_HCRX_EL2, x1 > + isb > +3: > init_el2_state Nitpick: we can probably leave a single ISB after both HCR_EL2 and HCRX_EL2 are initialised. Well, we could probably drop all of them altogether, there's at least one down this path. > > /* Hypervisor stub */ > diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S > index a6d67c2bb5ae..01f854697c70 100644 > --- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S > +++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S > @@ -95,6 +95,12 @@ SYM_CODE_START_LOCAL(___kvm_hyp_init) > ldr x1, [x0, #NVHE_INIT_HCR_EL2] > msr hcr_el2, x1 > > + mrs x1, ID_AA64MMFR1_EL1 > + ubfx x1, x1, #ID_AA64MMFR1_EL1_HCX_SHIFT, #4 > + cbz x1, 1f > + mov_q x2, HCRX_HOST_FLAGS > + msr_s SYS_HCRX_EL2, x2 > +1: Maybe you could use a macro to avoid writing this sequence twice. I lost track of the KVM initialisation refactoring since pKVM, it looks like the other register values are loaded from a structure here. I guess a value of 0 doesn't make sense to store (unless at a later point it becomes non-zero). -- Catalin From mboxrd@z Thu Jan 1 00:00:00 1970 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 AFFE6C74A5B for ; Fri, 17 Mar 2023 14:26:21 +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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ZEaQ7/3RrYpkyGl+Y4ycRWEvjcXt7n9d2OICNt1YWUI=; b=hzfqv3qjPXJW73 pfyZehSuw2esTi5HJUM5C/UtfFFnyWCz5ljdzXV+ST7KTIIll4zGDDaphgS3ryu94Fz+4lBmrd6tA QJ0XVwdEhIUjLHMhWf/ThfZ9WIT7M2jT/Wf1iOgzWVA0rKKM6kCvrPlK9jt8D0BBo8T6kFEeSkhhb V/NMvnnqFLvAFkeRq60kTlNzE36uegL0YunIW0WKLiGPswLj9kp2xNueqBzq20R855Cf9mSeuUkGM kDS+46g16+5FVugAElVvHgIxBlEXjrxk5rIfa5Vb290A5fkCkov7aJNXn8h6GptgvZQBcXJ+kdjVZ NgKg3QE1ZqHMB1aeracg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pdB1T-002Rvz-2v; Fri, 17 Mar 2023 14:25:35 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pdB1Q-002Ruy-2n for linux-arm-kernel@lists.infradead.org; Fri, 17 Mar 2023 14:25:34 +0000 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 4361F622D2; Fri, 17 Mar 2023 14:25:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 337D7C433EF; Fri, 17 Mar 2023 14:25:29 +0000 (UTC) Date: Fri, 17 Mar 2023 14:25:26 +0000 From: Catalin Marinas To: Kristina Martsenko Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, Will Deacon , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Mark Rutland , Mark Brown , Luis Machado , Vladimir Murzin , linux-kernel@vger.kernel.org Subject: Re: [PATCH 01/10] KVM: arm64: initialize HCRX_EL2 Message-ID: References: <20230216160012.272345-1-kristina.martsenko@arm.com> <20230216160012.272345-2-kristina.martsenko@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230216160012.272345-2-kristina.martsenko@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230317_072532_942066_A0594E64 X-CRM114-Status: GOOD ( 17.66 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Feb 16, 2023 at 04:00:03PM +0000, Kristina Martsenko wrote: > ARMv8.7/9.2 adds a new hypervisor configuration register HCRX_EL2. > Initialize the register to a safe value (all fields 0), to be robust > against firmware that has not initialized it. I think the risk of firmware not initialising this register is small given that EL3 needs to set SCR_EL3.HXEn to allow EL2 access. But it doesn't hurt to re-initialise it in the hypervisor. > diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S > index 212d93aca5e6..e06b34322339 100644 > --- a/arch/arm64/kernel/head.S > +++ b/arch/arm64/kernel/head.S > @@ -572,6 +572,13 @@ SYM_INNER_LABEL(init_el2, SYM_L_LOCAL) > msr hcr_el2, x0 > isb > > + mrs x0, ID_AA64MMFR1_EL1 > + ubfx x0, x0, #ID_AA64MMFR1_EL1_HCX_SHIFT, #4 > + cbz x0, 3f > + mov_q x1, HCRX_HOST_FLAGS > + msr_s SYS_HCRX_EL2, x1 > + isb > +3: > init_el2_state Nitpick: we can probably leave a single ISB after both HCR_EL2 and HCRX_EL2 are initialised. Well, we could probably drop all of them altogether, there's at least one down this path. > > /* Hypervisor stub */ > diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S > index a6d67c2bb5ae..01f854697c70 100644 > --- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S > +++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S > @@ -95,6 +95,12 @@ SYM_CODE_START_LOCAL(___kvm_hyp_init) > ldr x1, [x0, #NVHE_INIT_HCR_EL2] > msr hcr_el2, x1 > > + mrs x1, ID_AA64MMFR1_EL1 > + ubfx x1, x1, #ID_AA64MMFR1_EL1_HCX_SHIFT, #4 > + cbz x1, 1f > + mov_q x2, HCRX_HOST_FLAGS > + msr_s SYS_HCRX_EL2, x2 > +1: Maybe you could use a macro to avoid writing this sequence twice. I lost track of the KVM initialisation refactoring since pKVM, it looks like the other register values are loaded from a structure here. I guess a value of 0 doesn't make sense to store (unless at a later point it becomes non-zero). -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel