From nobody Wed Aug 21 08:48:26 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Wpg3H2S4Bz5TT9p; Wed, 21 Aug 2024 08:48:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Wpg3H0f9gz4c8Y; Wed, 21 Aug 2024 08:48:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724230107; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YWBfyD4ndYV1MgSpqYqj6FAt0y3YD+cJiVKAwhpCugw=; b=Ikqt7Akeywm/ns0559sX4HCt6A1JMXPzDlqA1PV2m/y/WZSB8oHCquexjqyAbA63GdYw0B Fq+dludkAlQ5jUH4pzh2+zXlQT54fvAYWym4G/tjfypfrJelnIjzfQWMn1GALbF7exUBlL TSj+O5gIZe9mwCvs/Q21LDyJbtsqDnVyiI7bbvNXna8r4iNYXacNt9KJL6gBiCCyes+HAG Qpx4Te9/xyFg5vgLEg6PuILAODfNLh/RjNEglkug7mV2DlpCWLV3Qyh5qp2P21Oj1Nsbvs F9ldW2LlfmTQfUeE9+ONllvimVTQFZ90zZn9mBwhxdqe7Xh0iVpv8ioteefhlQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1724230107; a=rsa-sha256; cv=none; b=jxWTLGQWbMrwtvvMIsNXIzrh5J6oX7nID3mzQuhD/cBRei0sJ6i9zh7znWkJeGkvCo14Fq nUtdm4iIZR3jA3uEl2btomYpPKoMU83J5dAdKj4cnVkTdc1tUFKgzZNiOntn6krQL3J/fE x7I8Kp8OygX+KzGamVknlyypnRAtkUwn7x/sFBGftt0o1vHIXj3Jy8RQoANPflRO2BKFit JgGpwd/P6b6BRYFb3E4EJu9X6dKptv9yQ6TXB66QdlYUPcq0n1z0g7miKrz1O29R1qF5iO rNWMaoY3Bxcln4rJKYkEcWVGoVFNlaKnTuQT2rLEmXaR/NQX+yfxUPzFMfitaQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1724230107; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YWBfyD4ndYV1MgSpqYqj6FAt0y3YD+cJiVKAwhpCugw=; b=FohFSvBde6F3V8eJB3IgMCM25y+06lGjS5GKrJ+qMqWBXtQ9ET/FMBLT/KA+E7RgG8bSzg 21KyQJqjve0P65Bv+IGqEdDQChhx3bvA791n959ifedpxiK6th6LBBaZBimS0opFkeQYVR 2f2sW3ll/Hdmv1U0/QKmjx3P+ufVFAg8ZgY3r05i0oM8e5nkO3/QV07eCB3CO90KPRTYvP ln6E6JQY+lFpAs1Zpl4vs7awQTVen3xICnhOjri1a+bvuB0Czn1HG3EvFb6fbwOCiuELOa rjFHK4ho48SiEKwY1gJNlz+9rzsY9HgwL484Pw4CtQyK9KSupaWQrWulNk9qyg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Wpg3G66zHzd6x; Wed, 21 Aug 2024 08:48:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 47L8mQbJ091842; Wed, 21 Aug 2024 08:48:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 47L8mQce091839; Wed, 21 Aug 2024 08:48:26 GMT (envelope-from git) Date: Wed, 21 Aug 2024 08:48:26 GMT Message-Id: <202408210848.47L8mQce091839@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: 0054693392f0 - main - arm64: Boot into VHE mode when able List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 0054693392f094c035fd396db339b8ceb16f17dd Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=0054693392f094c035fd396db339b8ceb16f17dd commit 0054693392f094c035fd396db339b8ceb16f17dd Author: Andrew Turner AuthorDate: 2024-08-19 12:46:10 +0000 Commit: Andrew Turner CommitDate: 2024-08-21 08:46:59 +0000 arm64: Boot into VHE mode when able When FEAT_VHE is present the HCR_EL2 E2H field will be implemented. Try setting this and checking if it's still set to decide if we can boot into VHE mode or not. When it is implemented the kernel will boot into EL2 rather than EL1 it currently boots to. The parts of the kernel that need to know if they are in EL1 or EL2 have been updated other than the CoreSight driver as there doesn't appear to be any way to currently use it and it will be updated soon with the new HWT framework. Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D46087 --- sys/arm64/arm64/locore.S | 65 +++++++++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 25 deletions(-) diff --git a/sys/arm64/arm64/locore.S b/sys/arm64/arm64/locore.S index ab1fea0c4716..b71e02538716 100644 --- a/sys/arm64/arm64/locore.S +++ b/sys/arm64/arm64/locore.S @@ -296,8 +296,12 @@ LEND(mpentry_common) #endif /* - * If we are started in EL2, configure the required hypervisor - * registers and drop to EL1. + * Enter the exception level the kernel will use: + * + * - If in EL1 continue in EL1 + * - If the CPU supports FEAT_VHE then set HCR_E2H and HCR_TGE and continue + * in EL2 + * - Configure EL2 to support running the kernel at EL1 and exit to that */ LENTRY(enter_kernel_el) #define INIT_SCTLR_EL1 (SCTLR_LSMAOE | SCTLR_nTLSMD | SCTLR_EIS | \ @@ -335,13 +339,14 @@ LENTRY(enter_kernel_el) isb /* Configure the Hypervisor */ - ldr x2, =(HCR_RW | HCR_APK | HCR_API) + ldr x2, =(HCR_RW | HCR_APK | HCR_API | HCR_E2H) msr hcr_el2, x2 /* Stash value of HCR_EL2 for later */ isb mrs x4, hcr_el2 + /* Load the Virtualization Process ID Register */ mrs x2, midr_el1 msr vpidr_el2, x2 @@ -354,41 +359,51 @@ LENTRY(enter_kernel_el) ldr x2, =INIT_SCTLR_EL1 msr sctlr_el1, x2 + /* Check if the E2H flag is set */ + tst x4, #HCR_E2H + b.eq .Lno_vhe + /* - * On some hardware, e.g., Apple M1, we can't clear E2H, so make sure we - * don't trap to EL2 for SIMD register usage to have at least a - * minimally usable system. + * The kernel will be running in EL2, route exceptions here rather + * than EL1. */ - tst x4, #HCR_E2H - mov x3, #CPTR_RES1 /* HCR_E2H == 0 */ - mov x5, #CPTR_FPEN /* HCR_E2H == 1 */ - csel x2, x3, x5, eq + orr x4, x4, #(HCR_TGE) + msr hcr_el2, x4 + isb + + msr SCTLR_EL12_REG, x2 + ldr x2, =(CPTR_FPEN) + ldr x3, =(CNTHCTL_E2H_EL1PCTEN | CNTHCTL_E2H_EL1PTEN) + ldr x5, =(PSR_DAIF | PSR_M_EL2h) + b .Ldone_vhe + +.Lno_vhe: + /* Hypervisor trap functions */ + adrp x2, hyp_stub_vectors + add x2, x2, :lo12:hyp_stub_vectors + msr vbar_el2, x2 + + ldr x2, =(CPTR_RES1) + ldr x3, =(CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN) + ldr x5, =(PSR_DAIF | PSR_M_EL1h) + +.Ldone_vhe: + msr cptr_el2, x2 + /* Enable access to the physical timers at EL1 */ + msr cnthctl_el2, x3 + /* Set the return PSTATE */ + msr spsr_el2, x5 /* Don't trap to EL2 for CP15 traps */ msr hstr_el2, xzr - /* Enable access to the physical timers at EL1 */ - tst x4, #HCR_E2H - ldr x3, =(CNTHCTL_EL1PCTEN | CNTHCTL_EL1PCEN) - ldr x5, =(CNTHCTL_E2H_EL1PCTEN | CNTHCTL_E2H_EL1PTEN) - csel x2, x3, x5, eq - msr cnthctl_el2, x2 - /* Set the counter offset to a known value */ msr cntvoff_el2, xzr - /* Hypervisor trap functions */ - adrp x2, hyp_stub_vectors - add x2, x2, :lo12:hyp_stub_vectors - msr vbar_el2, x2 - /* Zero vttbr_el2 so a hypervisor can tell the host and guest apart */ msr vttbr_el2, xzr - mov x2, #(PSR_DAIF | PSR_M_EL1h) - msr spsr_el2, x2 - /* Configure GICv3 CPU interface */ mrs x2, id_aa64pfr0_el1 /* Extract GIC bits from the register */