[go] internal/runtime/sys: only use speculation barrier for DIT on Apple Silicon

1 view
Skip to first unread message

Roland Shoemaker (Gerrit)

unread,
Feb 24, 2026, 4:59:02 PM (11 hours ago) Feb 24
to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Go LUCI, Keith Randall, Keith Randall, golang-co...@googlegroups.com

Roland Shoemaker submitted the change with unreviewed changes

Unreviewed changes

1 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:

```
The name of the file: src/internal/runtime/sys/dit_arm64.s
Insertions: 6, Deletions: 0.

@@ -12,6 +12,12 @@
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
```

Change information

Commit message:
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-by: Keith Randall <k...@google.com>
Reviewed-by: Keith Randall <k...@golang.org>
Files:
  • M src/internal/runtime/sys/dit_arm64.s
Change size: XS
Delta: 1 file changed, 8 insertions(+), 0 deletions(-)
Branch: refs/heads/master
Submit Requirements:
  • requirement satisfiedCode-Review: +1 by Keith Randall, +2 by Keith Randall
  • requirement satisfiedTryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I17a91adc8e4d90fe2288592547986c82a9356cde
Gerrit-Change-Number: 748460
Gerrit-PatchSet: 4
Gerrit-Owner: Roland Shoemaker <rol...@golang.org>
Gerrit-Reviewer: Keith Randall <k...@golang.org>
Gerrit-Reviewer: Keith Randall <k...@google.com>
Gerrit-Reviewer: Roland Shoemaker <rol...@golang.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages