aboutsummaryrefslogtreecommitdiff
path: root/src/internal/runtime
diff options
context:
space:
mode:
authorRoland Shoemaker <roland@golang.org>2026-02-24 08:58:39 -0800
committerRoland Shoemaker <roland@golang.org>2026-02-24 13:58:57 -0800
commitfa8595702eba16f757860705157f17f8054a92df (patch)
treea77f444bced1cc293af91400d5ef542df28e4c93 /src/internal/runtime
parente237976802f31e13e98cbde121fa0348f77d8df4 (diff)
downloadgo-fa8595702eba16f757860705157f17f8054a92df.tar.xz
internal/runtime/sys: only use speculation barrier for DIT on Apple Silicon
The Apple documentation [0] indicates that when enabling DIT (via MSR), a speculation barrier should be used. The rationale for this is not explained, but one could assume that they perhaps do not treat MSR of a PSTATE bit as a context synchronization event, and thus the CPU might speculatively execute instructions that would be affected by DIT before the MSR takes effect. Arm on the other hand [1], explicitly states that MSR of a PSTATE bit is a context synchronization event, and thus speculation barriers are not needed. In order to square this circle, we keep the speculation barrier, but only use it on Apple Silicon. [0] http://go/appledoc/xcode/writing-arm64-code-for-apple-platforms#Enable-DIT-for-constant-time-cryptographic-operations [1] https://developer.arm.com/documentation/100941/0101/Barriers?lang=en Fixes #77776 Change-Id: I17a91adc8e4d90fe2288592547986c82a9356cde Reviewed-on: https://go-review.googlesource.com/c/go/+/748460 Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Keith Randall <khr@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/internal/runtime')
-rw-r--r--src/internal/runtime/sys/dit_arm64.s8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/internal/runtime/sys/dit_arm64.s b/src/internal/runtime/sys/dit_arm64.s
index cc5642f838..483ac6bf21 100644
--- a/src/internal/runtime/sys/dit_arm64.s
+++ b/src/internal/runtime/sys/dit_arm64.s
@@ -11,9 +11,17 @@ TEXT ·EnableDIT(SB),$0-1
MOVB R1, ret+0(FP)
TBNZ $0, R1, ret
MSR $1, DIT
+#ifdef GOOS_darwin
+ // Arm documents that barriers are not necessary when writing to, or reading
+ // from, PSTATE fields. However, Apple documentation indicates that barriers
+ // should be used, in particular when setting the PSTATE.DIT field. Barriers
+ // aren't cheap, so only use them on Apple silicon for now.
+ //
+ // See go.dev/issue/77776.
MOVBU internal∕cpu·ARM64+const_offsetARM64HasSB(SB), R2
TBZ $0, R2, sbFallback
SB
+#endif
ret:
RET
sbFallback: