From nobody Tue Jan 13 16:27:14 2026 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 4drF5G4V3tz6NMNl for ; Tue, 13 Jan 2026 16:27:14 +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 "R13" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4drF5G3gfvz3KR5 for ; Tue, 13 Jan 2026 16:27:14 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768321634; 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=6zq8OBDEmLnN7XGf8DTaop8CFG5Zs0YU9JUNXWK/Hok=; b=Fa9cdDxsN5c1Tr59VavgnASGS4Plw6nNxpnHzM7hTBh8rsTczAzSCRusjcL1VbInkY/hT6 k3qUEVF+fwN2HWfyWVZzzyG81TtAR8zXg3Nc6K3S+38jKhE5bDg0k1waXOPVkZZf+vUNIj ImKNXIXcXpV3jR/aDpEdHZYBpFHfTLq1BAb/xd7UtGQ4GIW3ocfc47ucOFcN4ZY996t551 8g+fc/c21Adxn021/8DwV+jayygRq+YL0l4lcvcKaZXBcBWOhrPRkpL5Tqeg8vANR4kttp AK54xEze7bhzGTyLhfjzL1xlPQnB0u/VOGDOmRoVvfwGaQREnkoea3hYbfVnmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1768321634; 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=6zq8OBDEmLnN7XGf8DTaop8CFG5Zs0YU9JUNXWK/Hok=; b=IzlxdPnOBeYSAaReektdJ3n53t+gatuglVTE9WvvouaqZQKXVaktt9T5Qd17WovaudBptM aOuj0oaTzS2P42zistmIPu3QgjmNDjKNW+opJ67KCcn9pjPN/jYksJdwIsJfQDB1k9SK36 LroBQT7+SmS/e84hi/rzEkXNrZwNdKopwki4SCQSxX6HiEH3X05SSVoAP6CjoD/pTXefT3 FEHl1XZWYc7ASSgHV81nd20GJkDSG3zLADEbYQix8izZtCC+f0VQ2T3uiBDFwCwmcChiEM h6ANaytEhydiOQIaFCTrCVCcm8wlijLPRxPNQoOe+WFQ/I9tYhw0CIy6zT0GQA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1768321634; a=rsa-sha256; cv=none; b=PYZSbddzTiob8YcBdI9+9rvjxIMbEkRpAdlUGoap/KY03/x8s3f5tqR5wTm1YWTYJphAkz fxVBmQ4jEK/e2ED6nvxnek33uCRmX7tODfRv7Rx34vATmcxj/SAI+A90O8SarJflfcLao0 93Spp7PIgppphL33sXWD+7i824yW+Ia5U8zeGeOn52uaV6/btes8hzIAZanaZ8IvIuk965 LxBOh49TSp42WZP0PCz95L/5viuXrI/9UrM8YogCK93MJCc4S1I0/6xGatp8FwIbdAwMuZ 7mjyukS0NmNkgLFbktn0pkOJUsQHdvzEJRN/rfGrRS+F4WAu8wzPAvHyEgI+kg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4drF5G3DK8z46m for ; Tue, 13 Jan 2026 16:27:14 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 31305 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Tue, 13 Jan 2026 16:27:14 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andrew Turner Subject: git: c373926c8b8c - stable/15 - arm64: Set the endian without a memory access 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/stable/15 X-Git-Reftype: branch X-Git-Commit: c373926c8b8c29b57bf537899a886800862eb6b4 Auto-Submitted: auto-generated Date: Tue, 13 Jan 2026 16:27:14 +0000 Message-Id: <69667262.31305.61acc58@gitrepo.freebsd.org> The branch stable/15 has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=c373926c8b8c29b57bf537899a886800862eb6b4 commit c373926c8b8c29b57bf537899a886800862eb6b4 Author: Andrew Turner AuthorDate: 2025-09-19 10:05:47 +0000 Commit: Andrew Turner CommitDate: 2026-01-13 14:06:18 +0000 arm64: Set the endian without a memory access Early in the kernel we set the endian through the sctlr_el1 and sctlr_el2 registers. To get the value to put into these registers we load them from memory. As this will depend on the endian to get the fields in the correct order then it will fail if the endian is not what the kernel expects. Add a macro to load a 64-bit value into a register without a memory access and use this to set the register. As instructions are not affected by the endian set in sctlr this is safe. It is unlikely this will be hit as UEFI requires the processor to be in little endian mode, however when booting using the Linux ABI the kernel may start in big-endian, and secondary CPUs could be big-endian. Reviewed by: emaste Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D51012 (cherry picked from commit 0706d3464f4ef375fc31ecc7fa0733a13eca9d19) --- sys/arm64/arm64/locore.S | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/sys/arm64/arm64/locore.S b/sys/arm64/arm64/locore.S index 4a10a2b4f2d3..50a3eda846da 100644 --- a/sys/arm64/arm64/locore.S +++ b/sys/arm64/arm64/locore.S @@ -39,6 +39,23 @@ #define VIRT_BITS 48 +/* + * Loads a 64-bit value into reg using 1 to 4 mov/movk instructions. + * This can be used early on when we don't know the CPUs endianness. + */ +.macro mov_q reg, val + mov \reg, :abs_g0_nc:\val +.if (\val >> 16) & 0xffff != 0 + movk \reg, :abs_g1_nc:\val +.endif +.if (\val >> 32) & 0xffff != 0 + movk \reg, :abs_g2_nc:\val +.endif +.if (\val >> 48) & 0xffff != 0 + movk \reg, :abs_g3:\val +.endif +.endm + #if PAGE_SIZE == PAGE_SIZE_16K /* * The number of level 3 tables to create. 32 will allow for 1G of address @@ -324,15 +341,23 @@ LENTRY(enter_kernel_el) cmp x23, #(CURRENTEL_EL_EL2) b.eq 1f - ldr x2, =SCTLR_MMU_OFF + /* + * Ensure there are no memory operations here. If the boot loader + * enters the kernel in big-endian mode then loading sctlr will + * be incorrect. As instructions are the same in both endians it is + * safe to use mov instructions. + */ + mov_q x2, SCTLR_MMU_OFF msr sctlr_el1, x2 - /* SCTLR_EOS is set so eret is a context synchronizing event so we + /* + * SCTLR_EOS is set to make eret a context synchronizing event. We * need an isb here to ensure it's observed by later instructions, * but don't need it in the eret below. */ isb - /* Ensure SPSR_EL1 and pstate are in sync. The only wat to set the + /* + * Ensure SPSR_EL1 and pstate are in sync. The only way to set the * latter is to set the former and return from an exception with eret. */ mov x2, #(PSR_DAIF | PSR_M_EL1h) @@ -346,11 +371,19 @@ LENTRY(enter_kernel_el) * Set just the reserved bits in sctlr_el2. This will disable the * MMU which may have broken the kernel if we enter the kernel in * EL2, e.g. when using VHE. + * + * As with sctlr_el1 above use mov instructions to ensure there are + * no memory operations. */ - ldr x2, =(SCTLR_EL2_RES1 | SCTLR_EL2_EIS | SCTLR_EL2_EOS) + mov_q x2, (SCTLR_EL2_RES1 | SCTLR_EL2_EIS | SCTLR_EL2_EOS) msr sctlr_el2, x2 isb + /* + * The hardware is now in little-endian mode so memory operations + * are safe. + */ + /* Configure the Hypervisor */ ldr x2, =(HCR_RW | HCR_APK | HCR_API) msr hcr_el2, x2