From patchwork Mon Nov 27 11:45:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 13469425 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 AE7CCC0755A for ; Mon, 27 Nov 2023 11:46:55 +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:References:In-Reply-To: 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: List-Owner; bh=rgAeTkuhoiLZjeUAgrsb4bTzZpqLA7SqoZQvPgcYHe4=; b=conwvx2xgzMDQO RiHO9BtsVoe2VAorEQ1cIihN1rpQz4EjN1kJF9kN9Cti1FvSQxZwSsIjlAS1+LuPau6AJSS95roml LScOHgBGddRcMZuoQ2OIG7XoCPv6D5qH9lk/zDlA5GEUKrvwA4kUmjwKNlbqCeUm6WXwRX96r1dM1 ph0IptsgVq/d9fRaEy80jLlDXVP0MMSiJxYfIUVX7Jb13vg7BpLBclX27o5EFHwR9uFtukEVfGZvm u1Ll5YHhQmJyGQHR4S0JcMsB3jtbslHrhy8wvdg+vVElYtB9BRB6jOtWM1bLu7jz2qhgMlIgYnaOC gQwYBV+1y8BTfT3pKSIg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r7a4I-002IIR-07; Mon, 27 Nov 2023 11:46:26 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r7a41-002I2U-0R for linux-arm-kernel@lists.infradead.org; Mon, 27 Nov 2023 11:46:11 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id CA189B83537; Mon, 27 Nov 2023 11:46:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72031C433CA; Mon, 27 Nov 2023 11:46:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701085567; bh=wchZuZ8oVspJaTJG03KJWaPwl4lF7iOcaZLZI/ftVTM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S4LNQnlGPlTqdjWE8whauUpgCOjD1Rb3PmpNajyWQ9z4URgBQS83GBhsv8Tnd0zbi Oq2ZU97Z6Uq1HcWvryGwUdtbSVQkW3ZOQuO08Y4/pfHAY2M33XYXnv0qHPcWn1h1oL R05Sgc0fIP6N/UQjV+upmHG4fn9INCLaAQAk0tsX6H/7tbzEb/2ktY3XE80KOwPAiT C+EpL7YQhG69ffJZ3eVFApRt0zbjJGCUtWkcyQxazjKJceBAnBBgTXPPROUbGqWRjj QILw144ZvltQPGZJ9xrGEys08PT4EdXWIssXm65Z47gzeep0C0FXo8DbEJSn9iGrNo Jv+wBRpWs95yQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1r7a3x-00GleL-Jj; Mon, 27 Nov 2023 11:46:05 +0000 From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Cc: Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu Subject: [PATCH v3 08/13] arm64: Treat HCR_EL2.E2H as RES1 when ID_AA64MMFR4_EL1.E2H0 is negative Date: Mon, 27 Nov 2023 11:45:54 +0000 Message-Id: <20231127114559.990314-9-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231127114559.990314-1-maz@kernel.org> References: <20231127114559.990314-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, catalin.marinas@arm.com, will@kernel.org, mark.rutland@arm.com, ardb@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231127_034609_459720_AA51CFAF X-CRM114-Status: GOOD ( 13.06 ) 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 For CPUs that have ID_AA64MMFR4_EL1.E2H0 as negative, it is important to avoid the boot path that sets HCR_EL2.E2H=0. Fortunately, we already have this path to cope with fruity CPUs. Tweak init_el2 to look at ID_AA64MMFR4_EL1.E2H0 first. Reviewed-by: Suzuki K Poulose Signed-off-by: Marc Zyngier --- arch/arm64/kernel/head.S | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 7b236994f0e1..57e39bc3b2b5 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -584,25 +584,32 @@ SYM_INNER_LABEL(init_el2, SYM_L_LOCAL) mov_q x1, INIT_SCTLR_EL1_MMU_OFF /* - * Fruity CPUs seem to have HCR_EL2.E2H set to RES1, - * making it impossible to start in nVHE mode. Is that - * compliant with the architecture? Absolutely not! + * Compliant CPUs advertise their VHE-onlyness with + * ID_AA64MMFR4_EL1.E2H0 < 0. HCR_EL2.E2H can be + * RES1 in that case. + * + * Fruity CPUs seem to have HCR_EL2.E2H set to RES1, but + * don't advertise it (they predate this relaxation). */ + mrs_s x0, SYS_ID_AA64MMFR4_EL1 + ubfx x0, x0, #ID_AA64MMFR4_EL1_E2H0_SHIFT, #ID_AA64MMFR4_EL1_E2H0_WIDTH + tbnz x0, #(ID_AA64MMFR4_EL1_E2H0_SHIFT + ID_AA64MMFR4_EL1_E2H0_WIDTH - 1), 1f + mrs x0, hcr_el2 and x0, x0, #HCR_E2H - cbz x0, 1f - + cbz x0, 2f +1: /* Set a sane SCTLR_EL1, the VHE way */ pre_disable_mmu_workaround msr_s SYS_SCTLR_EL12, x1 mov x2, #BOOT_CPU_FLAG_E2H - b 2f + b 3f -1: +2: pre_disable_mmu_workaround msr sctlr_el1, x1 mov x2, xzr -2: +3: __init_el2_nvhe_prepare_eret mov w0, #BOOT_CPU_MODE_EL2