Skip to content

Commit f0708a0

Browse files
dvyukovjproberts
authored andcommitted
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 golang#54104 Change-Id: Ib5d3d6a79c0c6eddf11618d73fcc8bc1832a9c25 Reviewed-on: https://go-review.googlesource.com/c/go/+/409055 Reviewed-by: Joel Sing <[email protected]> Reviewed-by: Meng Zhuo <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 528d51e commit f0708a0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/runtime/lfstack_64bit.go

+12
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,21 @@ const (
3636
// We use one bit to distinguish between the two ranges.
3737
aixAddrBits = 57
3838
aixCntBits = 64 - aixAddrBits + 3
39+
40+
// riscv64 SV57 mode gives 56 bits of userspace VA.
41+
// lfstack code supports it, but broader support for SV57 mode is incomplete,
42+
// and there may be other issues (see #54104).
43+
riscv64AddrBits = 56
44+
riscv64CntBits = 64 - riscv64AddrBits + 3
3945
)
4046

4147
func lfstackPack(node *lfnode, cnt uintptr) uint64 {
4248
if GOARCH == "ppc64" && GOOS == "aix" {
4349
return uint64(uintptr(unsafe.Pointer(node)))<<(64-aixAddrBits) | uint64(cnt&(1<<aixCntBits-1))
4450
}
51+
if GOARCH == "riscv64" {
52+
return uint64(uintptr(unsafe.Pointer(node)))<<(64-riscv64AddrBits) | uint64(cnt&(1<<riscv64CntBits-1))
53+
}
4554
return uint64(uintptr(unsafe.Pointer(node)))<<(64-addrBits) | uint64(cnt&(1<<cntBits-1))
4655
}
4756

@@ -54,5 +63,8 @@ func lfstackUnpack(val uint64) *lfnode {
5463
if GOARCH == "ppc64" && GOOS == "aix" {
5564
return (*lfnode)(unsafe.Pointer(uintptr((val >> aixCntBits << 3) | 0xa<<56)))
5665
}
66+
if GOARCH == "riscv64" {
67+
return (*lfnode)(unsafe.Pointer(uintptr(val >> riscv64CntBits << 3)))
68+
}
5769
return (*lfnode)(unsafe.Pointer(uintptr(val >> cntBits << 3)))
5870
}

0 commit comments

Comments
 (0)