* [Buildroot] [PATCH v2 1/1] package/go: fix go on riscv64 in sv57 mode
@ 2022-08-04 2:44 Christian Stewart via buildroot
2022-08-07 13:46 ` Thomas Petazzoni via buildroot
0 siblings, 1 reply; 3+ messages in thread
From: Christian Stewart via buildroot @ 2022-08-04 2:44 UTC (permalink / raw)
To: buildroot; +Cc: Christian Stewart, Yann E . MORIN, Thomas Petazzoni
On machines supporting Riscv SV57 mode like Qemu, Go programs currently crash
with the following type of error:
runtime: lfstack.push invalid packing: node=0xffffff5908a940 cnt=0x1
packed=0xffff5908a9400001 -> node=0xffff5908a940
The upstream PR fixes this error, but has not yet been merged.
Upstream: https://go-review.googlesource.com/c/go/+/409055/4
Signed-off-by: Christian Stewart <christian@paral.in>
---
v1 -> v2:
- updated to upstream patchset version 4
- note: the upstream patchset has been code-reviewed and approved
- rebased against go 1.19 (patch is #0002)
- see: https://patchwork.ozlabs.org/project/buildroot/patch/20220804024126.1103291-1-christian@paral.in/
Signed-off-by: Christian Stewart <christian@paral.in>
---
...02-runtime-support-riscv64-SV57-mode.patch | 65 +++++++++++++++++++
1 file changed, 65 insertions(+)
create mode 100644 package/go/0002-runtime-support-riscv64-SV57-mode.patch
diff --git a/package/go/0002-runtime-support-riscv64-SV57-mode.patch b/package/go/0002-runtime-support-riscv64-SV57-mode.patch
new file mode 100644
index 0000000000..9b5393e1e4
--- /dev/null
+++ b/package/go/0002-runtime-support-riscv64-SV57-mode.patch
@@ -0,0 +1,65 @@
+From 6618c7af436488fa12018cdcd31eeedb3a698745 Mon Sep 17 00:00:00 2001
+From: Dmitry Vyukov <dvyukov@google.com>
+Date: Fri, 27 May 2022 18:55:35 +0200
+Subject: [PATCH] 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
+
+---
+
+Upstream: https://go-review.googlesource.com/c/go/+/409055/4
+---
+ src/runtime/lfstack_64bit.go | 12 ++++++++++++
+ 1 file changed, 12 insertions(+)
+
+diff --git a/src/runtime/lfstack_64bit.go b/src/runtime/lfstack_64bit.go
+index 154130cf63..39fa647b9e 100644
+--- a/src/runtime/lfstack_64bit.go
++++ b/src/runtime/lfstack_64bit.go
+@@ -36,12 +36,21 @@ const (
+ // We use one bit to distinguish between the two ranges.
+ aixAddrBits = 57
+ 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 {
+ if GOARCH == "ppc64" && GOOS == "aix" {
+ 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))
+ }
+
+@@ -54,5 +63,8 @@ func lfstackUnpack(val uint64) *lfnode {
+ if GOARCH == "ppc64" && GOOS == "aix" {
+ 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)))
+ }
+--
+2.35.1
+
--
2.35.1
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Buildroot] [PATCH v2 1/1] package/go: fix go on riscv64 in sv57 mode
2022-08-04 2:44 [Buildroot] [PATCH v2 1/1] package/go: fix go on riscv64 in sv57 mode Christian Stewart via buildroot
@ 2022-08-07 13:46 ` Thomas Petazzoni via buildroot
2022-09-14 21:24 ` Peter Korsgaard
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Petazzoni via buildroot @ 2022-08-07 13:46 UTC (permalink / raw)
To: Christian Stewart via buildroot; +Cc: Yann E . MORIN
On Wed, 3 Aug 2022 19:44:38 -0700
Christian Stewart via buildroot <buildroot@buildroot.org> wrote:
> On machines supporting Riscv SV57 mode like Qemu, Go programs currently crash
> with the following type of error:
>
> runtime: lfstack.push invalid packing: node=0xffffff5908a940 cnt=0x1
> packed=0xffff5908a9400001 -> node=0xffff5908a940
>
> The upstream PR fixes this error, but has not yet been merged.
>
> Upstream: https://go-review.googlesource.com/c/go/+/409055/4
>
> Signed-off-by: Christian Stewart <christian@paral.in>
>
> ---
Applied to master after renumbering the patch to have only one 0002
patch. Thanks!
Thomas
--
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Buildroot] [PATCH v2 1/1] package/go: fix go on riscv64 in sv57 mode
2022-08-07 13:46 ` Thomas Petazzoni via buildroot
@ 2022-09-14 21:24 ` Peter Korsgaard
0 siblings, 0 replies; 3+ messages in thread
From: Peter Korsgaard @ 2022-09-14 21:24 UTC (permalink / raw)
To: Thomas Petazzoni via buildroot; +Cc: Yann E . MORIN, Thomas Petazzoni
>>>>> "Thomas" == Thomas Petazzoni via buildroot <buildroot@buildroot.org> writes:
> On Wed, 3 Aug 2022 19:44:38 -0700
> Christian Stewart via buildroot <buildroot@buildroot.org> wrote:
>> On machines supporting Riscv SV57 mode like Qemu, Go programs currently crash
>> with the following type of error:
>>
>> runtime: lfstack.push invalid packing: node=0xffffff5908a940 cnt=0x1
>> packed=0xffff5908a9400001 -> node=0xffff5908a940
>>
>> The upstream PR fixes this error, but has not yet been merged.
>>
>> Upstream: https://go-review.googlesource.com/c/go/+/409055/4
>>
>> Signed-off-by: Christian Stewart <christian@paral.in>
>>
>> ---
> Applied to master after renumbering the patch to have only one 0002
> patch. Thanks!
Committed to 2022.05.x, thanks.
--
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-14 21:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-04 2:44 [Buildroot] [PATCH v2 1/1] package/go: fix go on riscv64 in sv57 mode Christian Stewart via buildroot
2022-08-07 13:46 ` Thomas Petazzoni via buildroot
2022-09-14 21:24 ` Peter Korsgaard
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.