From nobody Tue Feb 28 22:17:06 2023 X-Original-To: dev-commits-src-main@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 4PRBYZ3Q1Xz3v1hQ; Tue, 28 Feb 2023 22:17:06 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PRBYZ2t74z481H; Tue, 28 Feb 2023 22:17:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677622626; 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=9kY6sVQVOVLYhP16QJNYJsPmnEi9/7E/Z9wd7vVCq7w=; b=OEnOwomooDEPqPLfsGGQ9mPI0aTntuh9TtlLgZgFyrgpRzbKNUhibaTeEdO13L3nycYA7A hUQsSGHrB50N1+BQYyiTB+mA3mZW2l3mQwfYYQVIIrP5Rzf+qvNL6mPF0vZwaDcdQbzyRF ixKt2V4zlfOX8cQhkNLY+5dpJCTa6Vev38Ww7D2ananzy3sWO9zBEtml4lzXIGiJMYfczr MdGEJtQDTQeAVT5t4zCHm9LjRSjqcWbdHn0zSTQJP+JJ6hhNmkhksiNHrmvOaN7mdBT4bZ z/KYgY3R8I+apEs19HJmoNC4dNWAGC0gTLxzggZoqmEzWKdUjsUd+QJACl2oGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1677622626; 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=9kY6sVQVOVLYhP16QJNYJsPmnEi9/7E/Z9wd7vVCq7w=; b=Cm9NLEqanFsb57gaY/PJwQJC75BRv+0ebWRTiGDuvZQpYy/B4wVHDGzZDJX0sNOjmF1it5 m2eINckkNyqfSGpFJtQDjI8SnBgvgmglTsSSuyvNbKP+7+qmuy+95ohRe3xwlL0SiBHtQs lnmjoZ7FXLcFJEqRyAwMkKTOdbAbXWGzKjpd9YXiLeuRTrmCDSWhSIt5P8nfcDXfA3wRz3 vlMulcEQFkZvELhdvQiZHuXZ1iNrbtVuLn0unVkRKwlL1hlD3yqpC4ZMMqyTKtSBx+F8QV NKxZvrdAzOoz7P4WVEJxZ1rZTAD0b9upvwqnuWwIEU27XUpimeQo45wLNPx3cQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1677622626; a=rsa-sha256; cv=none; b=hIu+EFATIhPYKG7iUs7OLj90MNV3sLN7/gk1qhqeu9p2Ra5FHIDwhM3pMWlM32Dj6/Zt0C 5FL9gMGNlJMP+ApL67j4QNtJY2RmTeCOQFM47PGlyvH3C3nawLO3F2BnnFUDZ/r4R31F2T 0yv2jNkIFWgLoJGOccZfMvUGijFZPXUcJzTgRsFxAXhlN544L8Yheo3YzuDBM/T3/4UbBT /hEm+dXe5hhz+gbebvV3A3+xJ4cUcb8TGZB+LrVtVuI+eAMFi0ewrEKMpeF8Rt52jJzA+t mTp0abQdFwytOtCdMiY5RxoaSMFObJW4nw4VT9w6XrVPM8gqR7JgAp24dy7uUg== 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 4PRBYZ1tLzz1PFG; Tue, 28 Feb 2023 22:17:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 31SMH6jm095792; Tue, 28 Feb 2023 22:17:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31SMH6Gs095791; Tue, 28 Feb 2023 22:17:06 GMT (envelope-from git) Date: Tue, 28 Feb 2023 22:17:06 GMT Message-Id: <202302282217.31SMH6Gs095791@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kyle Evans Subject: git: dc8616edc580 - main - arm64: set FPEN if we're stuck with HCR_EL2.E2H List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kevans X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: dc8616edc580806afb1efaec1cdc3cc9a1b3804e Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kevans: URL: https://cgit.FreeBSD.org/src/commit/?id=dc8616edc580806afb1efaec1cdc3cc9a1b3804e commit dc8616edc580806afb1efaec1cdc3cc9a1b3804e Author: Kyle Evans AuthorDate: 2023-02-24 19:37:20 +0000 Commit: Kyle Evans CommitDate: 2023-02-28 22:16:14 +0000 arm64: set FPEN if we're stuck with HCR_EL2.E2H On Apple Silicon systems, E2H can't actually be cleared; we're stuck with it. Check it again when we're setting up CPTR_EL2 and set FPEN appropriately to avoid later trapping to EL2 on writes to SIMD registers. Reviewed by: andrew Differential Revision: https://reviews.freebsd.org/D38819 --- sys/arm64/arm64/locore.S | 15 +++++++++++++-- sys/arm64/include/hypervisor.h | 4 ++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/sys/arm64/arm64/locore.S b/sys/arm64/arm64/locore.S index b37442f15f05..da3001711955 100644 --- a/sys/arm64/arm64/locore.S +++ b/sys/arm64/arm64/locore.S @@ -263,6 +263,10 @@ LENTRY(drop_to_el1) ldr x2, =(HCR_RW | HCR_APK | HCR_API) 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 @@ -275,8 +279,15 @@ LENTRY(drop_to_el1) ldr x2, .Lsctlr_res1 msr sctlr_el1, x2 - /* Don't trap to EL2 for exceptions */ - mov x2, #CPTR_RES1 + /* + * 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. + */ + tst x4, #HCR_E2H + mov x3, #CPTR_RES1 /* HCR_E2H == 0 */ + mov x4, #CPTR_FPEN /* HCR_E2H == 1 */ + csel x2, x3, x4, eq msr cptr_el2, x2 /* Don't trap to EL2 for CP15 traps */ diff --git a/sys/arm64/include/hypervisor.h b/sys/arm64/include/hypervisor.h index 84abe17f310e..0a0f0c2b3d07 100644 --- a/sys/arm64/include/hypervisor.h +++ b/sys/arm64/include/hypervisor.h @@ -45,9 +45,13 @@ #define CNTHCTL_EL1PCTEN (1 << 0) /*Allow EL0/1 physical counter access*/ /* CPTR_EL2 - Architecture feature trap register */ +/* Valid if HCR_EL2.E2H == 0 */ #define CPTR_RES0 0x7fefc800 #define CPTR_RES1 0x000033ff #define CPTR_TFP 0x00000400 +/* Valid if HCR_EL2.E2H == 1 */ +#define CPTR_FPEN 0x00300000 +/* Unconditionally valid */ #define CPTR_TTA 0x00100000 #define CPTR_TCPAC 0x80000000