1
0
mirror of https://github.com/golang/go synced 2024-11-23 05:50:05 -07:00
go/doc/next
Roland Shoemaker bc1da38c3d crypto/subtle: add DIT closure
Add a new function, WithDataIndependentTiming, which takes a function as
an argument, and encloses it with calls to set/unset the DIT PSTATE bit
on Arm64.

Since DIT is OS thread-local, for the duration of the execution of
WithDataIndependentTiming, we lock the goroutine to the OS thread, using
LockOSThread. For long running operations, this is likely to not be
performant, but we expect this to be tightly scoped around cryptographic
operations that have bounded execution times.

If locking to the OS thread turns out to be too slow, another option is
to add a bit to the g state indicating if a goroutine has DIT enabled,
and then have the scheduler enable/disable DIT when scheduling a g.

Additionally, we add a new GODEBUG, dataindependenttiming, which allows
setting DIT for an entire program. Running a program with
dataindependenttiming=1 enables DIT for the program during
initialization. In an ideal world PSTATE.DIT would be inherited from
the parent thread, so we'd only need to set it in the main thread and
then all subsequent threads would inherit the value. While this does
happen in the Linux kernel [0], it is not the case for darwin [1].
Rather than add complex logic to only set it on darwin for each new
thread, we just unconditionally set it in mstart1 and cgocallbackg1
regardless of the OS. DIT will already impose some overhead, and the
cost of setting the bit is only ~two instructions (CALL, MSR), so it
should be cheap enough.

Fixes #66450
Updates #49702

[0] e8bdb3c8be/arch/arm64/kernel/process.c (L373)
[1] 8d741a5de7/osfmk/arm64/status.c (L1666)

Change-Id: I78eda691ff9254b0415f2b54770e5850a0179749
Reviewed-on: https://go-review.googlesource.com/c/go/+/598336
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-19 16:47:03 +00:00
..
6-stdlib crypto/subtle: add DIT closure 2024-11-19 16:47:03 +00:00
1-intro.md doc: initialize next directory for Go 1.24 2024-07-22 17:55:04 +00:00
2-language.md doc: initialize next directory for Go 1.24 2024-07-22 17:55:04 +00:00
3-tools.md cmd/go: re-enable build JSON from go test -json, now with GODEBUG 2024-11-19 02:39:44 +00:00
4-runtime.md doc: initialize next directory for Go 1.24 2024-07-22 17:55:04 +00:00
5-toolchain.md cmd/dist: require Go 1.22.6 as minimum bootstrap toolchain 2024-08-20 17:52:42 +00:00
7-ports.md doc/next: pre-announce dropping macOS 11 support 2024-11-15 16:11:06 +00:00