-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runtime: clean up system call code #51087
Comments
All or most of the information we would need to generate the stubs is already in the syscall package. The needs of the syscall package are of course a bit different, but the metadata should be effectively the same. Orthogonal to code generation, given a generic runtime Syscall function (or a few of them for different numbers of arguments), would there even be any overhead to having the stubs be in Go rather than assembly? In addition to significantly reducing the amount of assembly, I think this would encourage us to do better error handling. |
Just to add another pain point: the stubs handle errors differently. Some returns errno (negated or not?), some just crash hard (writing to an invalid address), which is difficult to debug sometimes. |
Change https://go.dev/cl/383999 mentions this issue: |
Add a generic syscall package for use by the runtime. Eventually we'd like to clean up system calls in the runtime to use more code generation and be moved out of the main runtime package. The implementations of the assembly functions are based on copies of syscall.RawSyscall6, modified slightly for more consistency between arches. e.g., renamed trap to num, always set syscall num register first. For now, this package is just the bare minimum needed for doAllThreadsSyscall to make an arbitrary syscall. For #51087. For #50113. Change-Id: Ibecb5e6303279ce15286759e1cd6a2ddc52f7c72 Reviewed-on: https://go-review.googlesource.com/c/go/+/383999 Trust: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
@ii64 this issue is about a plan for the future, not what has happened. Your comment is unrelated to this issue. Looks like you are using gollvm. What version of gollvm are you using? Try updating to the latest. If that still fail, please file a new issue. Thanks. |
Change https://go.dev/cl/388094 mentions this issue: |
Change https://go.dev/cl/388477 mentions this issue: |
Change https://go.dev/cl/388475 mentions this issue: |
Change https://go.dev/cl/388478 mentions this issue: |
Change https://go.dev/cl/388095 mentions this issue: |
Change https://go.dev/cl/388476 mentions this issue: |
Change https://go.dev/cl/388479 mentions this issue: |
Change https://go.dev/cl/388474 mentions this issue: |
Change https://go.dev/cl/401096 mentions this issue: |
Change https://go.dev/cl/401337 mentions this issue: |
CL 388095 will change this file significantly. Move it preemptively to ensure git tracks the move properly. For #51087 Change-Id: I1408aecf8675723041b64e54cf44cdec38cc655c Reviewed-on: https://go-review.googlesource.com/c/go/+/388094 Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This CL exports the existing ir.UintptrKeepAlive via the new directive //go:uintptrkeepalive. This makes the compiler insert KeepAlives for pointers converted to uintptr in calls, keeping them alive for the duration of the call. //go:uintptrkeepalive requires //go:nosplit, as stack growth can't handle these arguments (it cannot know which are pointers). We currently check this on the immediate function, but the actual restriction applies to all transitive calls. The existing //go:uintptrescapes is an extension of //go:uintptrkeepalive which forces pointers to escape to the heap, thus eliminating the stack growth issue. This pragma is limited to the standard library. For #51087 Change-Id: If9a19d484d3561b4219e5539b70c11a3cc09391e Reviewed-on: https://go-review.googlesource.com/c/go/+/388095 Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Future CLs will be changing the provenance of these functions. Move the declarations to the individual OS files now so that future CLs can change only 1 OS at a time rather than changing all at once. For #51087 Change-Id: I5e1bca71e670263d8c0faa586c1b6b4de1a114b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/388474 Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
…mplementation on linux For #51087 Change-Id: I75a1bdeb5089454595f5ca04765a9c6e45cf9bd5 Reviewed-on: https://go-review.googlesource.com/c/go/+/388475 Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
For #51087 Change-Id: I63e07638507328efe33dbf7dd5f8a8b78890e037 Reviewed-on: https://go-review.googlesource.com/c/go/+/388476 Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
For #51087 Change-Id: I9de7e85ccf137ae73662759382334bcbe7208150 Reviewed-on: https://go-review.googlesource.com/c/go/+/388477 Run-TryBot: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This reverts CL 401096. Grandparent CL 388477 breaks cmd/go TestScript/cover_pkgall_runtime. For #51087. For #52472. Change-Id: Ie82fe5f50975f66eb91fb0d01cd8bbbd0265eb4e Reviewed-on: https://go-review.googlesource.com/c/go/+/401634 Run-TryBot: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This reverts CL 388478. Parent CL 388477 breaks cmd/go TestScript/cover_pkgall_runtime. For #51087. For #52472. Change-Id: Id5d5a4e138792cf130ecdcc6b996c8102d142a7e Reviewed-on: https://go-review.googlesource.com/c/go/+/401635 Run-TryBot: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This reverts CL 388477, which breaks cmd/go TestScript/cover_pkgall_runtime. For #51087. For #52472. Change-Id: Id58af419a889281f15df2471c58fece011fcffbc Reviewed-on: https://go-review.googlesource.com/c/go/+/401636 Run-TryBot: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Change https://go.dev/cl/401654 mentions this issue: |
Change https://go.dev/cl/401656 mentions this issue: |
Change https://go.dev/cl/401655 mentions this issue: |
This is a re-do of CL 388477, fixing #52472. It is unsafe to call syscall.RawSyscall from syscall.Syscall with -coverpkg=all and -race. This is because: 1. Coverage adds a sync/atomic call in RawSyscall to increment the coverage counter. 2. Race mode instruments sync/atomic calls with TSAN runtime calls. TSAN eventually calls runtime.racecallbackfunc, which expects getg().m.p != 0, which is no longer true after entersyscall(). cmd/go actually avoids adding coverage instrumention to package runtime in race mode entirely to avoid these kinds of problems. Rather than also excluding all of syscall for this one function, work around by calling RawSyscall6 instead, which avoids coverage instrumention both by being written in assembly and in package runtime/*. For #51087 Fixes #52472 Change-Id: Iaffd27df03753020c4716059a455d6ca7b62f347 Reviewed-on: https://go-review.googlesource.com/c/go/+/401654 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
This is an exact copy of CL 388478 after fixing #52472 in CL 401654. For #51087 For #52472 Change-Id: I6c6bd7ddcab1512c682e6b44f61c7bcde97f5c58 Reviewed-on: https://go-review.googlesource.com/c/go/+/401655 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
Everything I expect to get into 1.19 is in. Moving future work to 1.20. |
This is an exact copy of CL 401096 after fixing #52472 in CL 401654. For #51087 For #52472 Change-Id: Ib3c914949a15517aacdca2d72e69e1c7b217e430 Reviewed-on: https://go-review.googlesource.com/c/go/+/401656 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
Change https://go.dev/cl/402914 mentions this issue: |
RawSyscall is used in a variety of rather unsafe conditions, such as after fork in forkAndExecInChild1. Disable race instrumentation to avoid calling TSAN in unsafe conditions. For #51087 Change-Id: I47c35e6f0768c77ddab99010ea0404c45ad2f1da Reviewed-on: https://go-review.googlesource.com/c/go/+/402914 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com>
Change https://go.dev/cl/421994 mentions this issue: |
This change moves Linux epoll's syscalls implementation to the "runtime/internal/syscall" package. The intention in this CL was to minimise behavioural changes but make the code more generalised. This also will allow adding new syscalls (like epoll_pwait2) without the need to implement assembly stubs for each arch. It also drops epoll_create as not all architectures provide this call. epoll_create1 was added to the kernel in version 2.6.27 and Go requires Linux kernel version 2.6.32 or later since Go 1.18. So it is safe to always use epoll_create1. For #53824 For #51087 Change-Id: I9a6a26b7f2075a38e041de1bab4691da0ecb94fc Reviewed-on: https://go-review.googlesource.com/c/go/+/421994 Reviewed-by: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Pratt <mpratt@google.com>
Change https://go.dev/cl/437295 mentions this issue: |
This reverts CL 421994. Reason for revert: breaks runtime.TestCheckPtr2 For #53824 For #51087 Change-Id: I044ea4d6efdffe0a4b7fb0d2bb3717d9f391fc59 Reviewed-on: https://go-review.googlesource.com/c/go/+/437295 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Michael Pratt <mpratt@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Bryan Mills <bcmills@google.com>
Change https://go.dev/cl/440115 mentions this issue: |
This change moves Linux epoll's syscalls implementation to the "runtime/internal/syscall" package. The intention in this CL was to minimise behavioural changes but make the code more generalised. This also will allow adding new syscalls (like epoll_pwait2) without the need to implement assembly stubs for each arch. It also drops epoll_create as not all architectures provide this call. epoll_create1 was added to the kernel in version 2.6.27 and Go requires Linux kernel version 2.6.32 or later since Go 1.18. So it is safe to always use epoll_create1. This is a resubmit as the previous CL 421994 was reverted due to test failures after the merge with the master. The issue was fixed in CL 438615 For #53824 For #51087 Change-Id: I1bd0f23a85b4f9b80178c5dd36fd3e95ff4f9648 Reviewed-on: https://go-review.googlesource.com/c/go/+/440115 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com>
This change moves Linux epoll's syscalls implementation to the "runtime/internal/syscall" package. The intention in this CL was to minimise behavioural changes but make the code more generalised. This also will allow adding new syscalls (like epoll_pwait2) without the need to implement assembly stubs for each arch. It also drops epoll_create as not all architectures provide this call. epoll_create1 was added to the kernel in version 2.6.27 and Go requires Linux kernel version 2.6.32 or later since Go 1.18. So it is safe to always use epoll_create1. This is a resubmit as the previous CL 421994 was reverted due to test failures after the merge with the master. The issue was fixed in CL 438615 For golang#53824 For golang#51087 Change-Id: I1bd0f23a85b4f9b80178c5dd36fd3e95ff4f9648 Reviewed-on: https://go-review.googlesource.com/c/go/+/440115 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Michael Pratt <mpratt@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Michael Pratt <mpratt@google.com>
Add Getrandom to internal/runtime/syscall. Use Getrandom instead of reading /dev/urandom to simplify the code. Since Go 1.24 needs Linux kernel >= 3.2, and getrandom(2) was introduced by Linux kernel 3.17, Getrandom could return ENOSYS. This doesn't matter because the Linux kernel always sets startupRand, so readRandom is usually not reachable. We also have a time-based fallback even if readRandom fails. Updates golang#51087 Fixes golang#68278
Change https://go.dev/cl/612715 mentions this issue: |
The code used to make system calls from the runtime is a mess and a big pain point when making OS-level changes in the runtime.
Quick summary of some of the pain points:
syscall
.sys*
files (57, to be precise, mostly assembly), totaling ~23k lines of code [1], which is 100% hand-written. Adding a new syscall stub often requires adding new assembly to 10+ files.Syscall
function that can be used to make an arbitrary system call. You must add a new stub to make a new call.Some things we could do to improve the situation:
Syscall
functions, used by other stubs. And/or use code generation to generate stubs rather than doing so manually.runtime/internal/syscall
or perhapsruntime/internal/linux
?) to avoid littering theruntime
package itself with so many files.syscall
depend on the runtime'sSyscall
stub so we only have a single implementation.[1] Some of this code is things other than syscall stubs, like thread entrypoints.
cc @aclements @mknyszek @cherrymui
The text was updated successfully, but these errors were encountered: