mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: support riscv64 SV57 mode
riscv64 has SV57 mode when user-space VA is 56 bits. Linux kernel recently got support for this mode and Go binaries started crashing as: runtime: lfstack.push invalid packing: node=0xffffff5908a940 cnt=0x1 packed=0xffff5908a9400001 -> node=0xffff5908a940 Adjust lfstack code to use only 8 top bits of pointers on riscv64. For context see: https://groups.google.com/g/syzkaller-bugs/c/lU0GQTZoNQQ/m/O_c3vmE3AAAJ Update #54104 Change-Id: Ib5d3d6a79c0c6eddf11618d73fcc8bc1832a9c25 Reviewed-on: https://go-review.googlesource.com/c/go/+/409055 Reviewed-by: Joel Sing <joel@sing.id.au> Reviewed-by: Meng Zhuo <mzh@golangcn.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
parent
f28fa952b5
commit
1e3c19f3fe
1 changed files with 12 additions and 0 deletions
|
|
@ -36,12 +36,21 @@ const (
|
||||||
// We use one bit to distinguish between the two ranges.
|
// We use one bit to distinguish between the two ranges.
|
||||||
aixAddrBits = 57
|
aixAddrBits = 57
|
||||||
aixCntBits = 64 - aixAddrBits + 3
|
aixCntBits = 64 - aixAddrBits + 3
|
||||||
|
|
||||||
|
// riscv64 SV57 mode gives 56 bits of userspace VA.
|
||||||
|
// lfstack code supports it, but broader support for SV57 mode is incomplete,
|
||||||
|
// and there may be other issues (see #54104).
|
||||||
|
riscv64AddrBits = 56
|
||||||
|
riscv64CntBits = 64 - riscv64AddrBits + 3
|
||||||
)
|
)
|
||||||
|
|
||||||
func lfstackPack(node *lfnode, cnt uintptr) uint64 {
|
func lfstackPack(node *lfnode, cnt uintptr) uint64 {
|
||||||
if GOARCH == "ppc64" && GOOS == "aix" {
|
if GOARCH == "ppc64" && GOOS == "aix" {
|
||||||
return uint64(uintptr(unsafe.Pointer(node)))<<(64-aixAddrBits) | uint64(cnt&(1<<aixCntBits-1))
|
return uint64(uintptr(unsafe.Pointer(node)))<<(64-aixAddrBits) | uint64(cnt&(1<<aixCntBits-1))
|
||||||
}
|
}
|
||||||
|
if GOARCH == "riscv64" {
|
||||||
|
return uint64(uintptr(unsafe.Pointer(node)))<<(64-riscv64AddrBits) | uint64(cnt&(1<<riscv64CntBits-1))
|
||||||
|
}
|
||||||
return uint64(uintptr(unsafe.Pointer(node)))<<(64-addrBits) | uint64(cnt&(1<<cntBits-1))
|
return uint64(uintptr(unsafe.Pointer(node)))<<(64-addrBits) | uint64(cnt&(1<<cntBits-1))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,5 +63,8 @@ func lfstackUnpack(val uint64) *lfnode {
|
||||||
if GOARCH == "ppc64" && GOOS == "aix" {
|
if GOARCH == "ppc64" && GOOS == "aix" {
|
||||||
return (*lfnode)(unsafe.Pointer(uintptr((val >> aixCntBits << 3) | 0xa<<56)))
|
return (*lfnode)(unsafe.Pointer(uintptr((val >> aixCntBits << 3) | 0xa<<56)))
|
||||||
}
|
}
|
||||||
|
if GOARCH == "riscv64" {
|
||||||
|
return (*lfnode)(unsafe.Pointer(uintptr(val >> riscv64CntBits << 3)))
|
||||||
|
}
|
||||||
return (*lfnode)(unsafe.Pointer(uintptr(val >> cntBits << 3)))
|
return (*lfnode)(unsafe.Pointer(uintptr(val >> cntBits << 3)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue