diff options
| author | Jason A. Donenfeld <Jason@zx2c4.com> | 2024-09-22 03:45:29 +0200 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2024-09-28 01:07:09 +0000 |
| commit | eb6f2c24cd17c0ca1df7e343f8d9187eef7d6e13 (patch) | |
| tree | d76c58100622eb5d33e3ffc451dd726a3dd898bd /src/runtime/sys_linux_arm64.s | |
| parent | 677b6cc17544e5e667d4bb67d063f5d775c69e32 (diff) | |
| download | go-eb6f2c24cd17c0ca1df7e343f8d9187eef7d6e13.tar.xz | |
runtime: use vDSO for getrandom() on linux
Linux 6.11 supports calling getrandom() from the vDSO. It operates on a
thread-local opaque state allocated with mmap using flags specified by
the vDSO.
Opaque states are allocated in chunks, ideally ncpu at a time as a hint,
rounding up to as many fit in a complete page. On first use, a state is
assigned to an m, which owns that state, until the m exits, at which
point it is given back to the pool.
Performance appears to be quite good:
│ sec/op │ sec/op vs base │
Read/4-16 222.45n ± 3% 27.13n ± 6% -87.80% (p=0.000 n=10)
│ B/s │ B/s vs base │
Read/4-16 17.15Mi ± 3% 140.61Mi ± 6% +719.82% (p=0.000 n=10)
Fixes #69577.
Change-Id: Ib6f44e8f2f3940c94d970eaada0eb566ec297dc7
Reviewed-on: https://go-review.googlesource.com/c/go/+/614835
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Jason Donenfeld <Jason@zx2c4.com>
Reviewed-by: Paul Murphy <murp@ibm.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/runtime/sys_linux_arm64.s')
| -rw-r--r-- | src/runtime/sys_linux_arm64.s | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/runtime/sys_linux_arm64.s b/src/runtime/sys_linux_arm64.s index 51c87bea05..7a81d5479e 100644 --- a/src/runtime/sys_linux_arm64.s +++ b/src/runtime/sys_linux_arm64.s @@ -785,3 +785,48 @@ TEXT runtime·sbrk0(SB),NOSPLIT,$0-8 SVC MOVD R0, ret+0(FP) RET + +// func vgetrandom1(buf *byte, length uintptr, flags uint32, state uintptr, stateSize uintptr) int +TEXT runtime·vgetrandom1<ABIInternal>(SB),NOSPLIT,$16-48 + MOVD RSP, R20 + + MOVD runtime·vdsoGetrandomSym(SB), R8 + MOVD g_m(g), R21 + + MOVD m_vdsoPC(R21), R9 + MOVD R9, 8(RSP) + MOVD m_vdsoSP(R21), R9 + MOVD R9, 16(RSP) + MOVD LR, m_vdsoPC(R21) + MOVD $buf-8(FP), R9 + MOVD R9, m_vdsoSP(R21) + + MOVD RSP, R9 + BIC $15, R9 + MOVD R9, RSP + + MOVBU runtime·iscgo(SB), R9 + CBNZ R9, nosaveg + MOVD m_gsignal(R21), R9 + CBZ R9, nosaveg + CMP g, R9 + BEQ nosaveg + MOVD (g_stack+stack_lo)(R9), R22 + MOVD g, (R22) + + BL (R8) + + MOVD ZR, (R22) + B restore + +nosaveg: + BL (R8) + +restore: + MOVD R20, RSP + MOVD 16(RSP), R1 + MOVD R1, m_vdsoSP(R21) + MOVD 8(RSP), R1 + MOVD R1, m_vdsoPC(R21) + NOP R0 // Satisfy go vet, since the return value comes from the vDSO function. + RET |
