Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp5927277rwr; Tue, 9 May 2023 08:03:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ52KD9R1CmH/Z4+XGxcB28rIE+xatzWyfy5f9H2F0dXiaive83FEi2HMiRQYRR6xw6sxtj8 X-Received: by 2002:a17:902:d483:b0:1ac:896f:f655 with SMTP id c3-20020a170902d48300b001ac896ff655mr6357241plg.50.1683644637069; Tue, 09 May 2023 08:03:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683644637; cv=none; d=google.com; s=arc-20160816; b=CCvHgNBahGZqjJgl+UBeXT/a3/66hca4eMu/zBi0O0CNNlOb7e97bKTius0uPH4+l9 ALvrPusbWNjEVykKGfxqjvHONThXqgDvh7WeGtodH8N0vSyY0GiAKduwMlWkwLWj6dfD kzTtca7xM6lQJ5IeqqrkyxdKgk0t991DFPBv0AK6yv5Fa7vUufrPHOrIQeEV12YwWGeK AiwH/yW/IeGS2QCWksHlkNh9h9Vp+tQJ5e+sjD609uftdyrio7YzYTlOnHDWvg9LylT/ G3sppOprtaLy7Hl/r9lAGCBv7qInRUJG70l+knM3gL6rMc0YIGmajC8Dk17+K7mZ7cmo wW6g== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Uey4E2qzP2ZpdOGL5TGVtTTmSbNzbKcfhNcbwS/hZWA=; b=xZrY1ZsYyoeXURNVTzGqduHXPf+y+zx79WPTj1MxE76z0Fee5pAWwPB+XIFZDc625l BeQh/BIyJjYfc1VxUjSzfvwO0KUgy3LjVIVdbp+m6qN1qqFb8XjBXqpUW+7zZrEbVJFH bnojmU5kqqu8wHFe1tbivSKxOS7ThGqZGypwhy0DGLAvynJ9w7O3QdseFlrxmwBHD99N d49OGPvM5+HSI8pIa/69cEnj/g0AXEf/VvXwJqwLXLDdah+viQQ5QJ0dFkSkAjwFvh8+ FzIm7zCZoz3rAKERFapBU9GKdUUObCPGncdQxY3+iAMagpdfG5vJEKt1glehZ+/pDnJf rUNA== 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 n5-20020a170902e54500b001a8173f468fsi1807784plf.314.2023.05.09.08.03.35; Tue, 09 May 2023 08:03:57 -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 S235655AbjEIOXY (ORCPT + 99 others); Tue, 9 May 2023 10:23:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234641AbjEIOXU (ORCPT ); Tue, 9 May 2023 10:23:20 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 61CDC30E3 for ; Tue, 9 May 2023 07:23:18 -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 9B7951063; Tue, 9 May 2023 07:24:02 -0700 (PDT) Received: from e126864.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 39FB43F663; Tue, 9 May 2023 07:23:15 -0700 (PDT) From: Kristina Martsenko To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Cc: Catalin Marinas , 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: [PATCH v2 01/11] KVM: arm64: initialize HCRX_EL2 Date: Tue, 9 May 2023 15:22:25 +0100 Message-Id: <20230509142235.3284028-2-kristina.martsenko@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230509142235.3284028-1-kristina.martsenko@arm.com> References: <20230509142235.3284028-1-kristina.martsenko@arm.com> 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 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. This is also needed to ensure that the register is reinitialized after a kexec by a future kernel. In addition, move SMPME setup over to the new flags, as it would otherwise get overridden. It is safe to set the bit even if SME is not (uniformly) supported, as it will write to a RES0 bit (having no effect), and SME will be disabled by the cpufeature framework. (Similar to how e.g. the API bit is handled in HCR_HOST_NVHE_FLAGS.) Signed-off-by: Kristina Martsenko --- arch/arm64/include/asm/el2_setup.h | 18 ++++++++++-------- arch/arm64/include/asm/kvm_arm.h | 3 +++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/arch/arm64/include/asm/el2_setup.h b/arch/arm64/include/asm/el2_setup.h index 037724b19c5c..0201577863ca 100644 --- a/arch/arm64/include/asm/el2_setup.h +++ b/arch/arm64/include/asm/el2_setup.h @@ -22,6 +22,15 @@ isb .endm +.macro __init_el2_hcrx + mrs x0, id_aa64mmfr1_el1 + ubfx x0, x0, #ID_AA64MMFR1_EL1_HCX_SHIFT, #4 + cbz x0, .Lskip_hcrx_\@ + mov_q x0, HCRX_HOST_FLAGS + msr_s SYS_HCRX_EL2, x0 +.Lskip_hcrx_\@: +.endm + /* * Allow Non-secure EL1 and EL0 to access physical timer and counter. * This is not necessary for VHE, since the host kernel runs in EL2, @@ -184,6 +193,7 @@ */ .macro init_el2_state __init_el2_sctlr + __init_el2_hcrx __init_el2_timers __init_el2_debug __init_el2_lor @@ -284,14 +294,6 @@ cbz x1, .Lskip_sme_\@ msr_s SYS_SMPRIMAP_EL2, xzr // Make all priorities equal - - mrs x1, id_aa64mmfr1_el1 // HCRX_EL2 present? - ubfx x1, x1, #ID_AA64MMFR1_EL1_HCX_SHIFT, #4 - cbz x1, .Lskip_sme_\@ - - mrs_s x1, SYS_HCRX_EL2 - orr x1, x1, #HCRX_EL2_SMPME_MASK // Enable priority mapping - msr_s SYS_HCRX_EL2, x1 .Lskip_sme_\@: .endm diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h index baef29fcbeee..fb7fe28b8eb8 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -9,6 +9,7 @@ #include #include +#include #include /* Hyp Configuration Register (HCR) bits */ @@ -92,6 +93,8 @@ #define HCR_HOST_NVHE_PROTECTED_FLAGS (HCR_HOST_NVHE_FLAGS | HCR_TSC) #define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H) +#define HCRX_HOST_FLAGS (HCRX_EL2_SMPME) + /* TCR_EL2 Registers bits */ #define TCR_EL2_RES1 ((1U << 31) | (1 << 23)) #define TCR_EL2_TBI (1 << 20) -- 2.25.1