]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: handle SIGPE exception for p256 crypto package on s390x
authorroot <vishwanatha.hd@ibm.com>
Wed, 31 May 2023 12:06:02 +0000 (12:06 +0000)
committerCherry Mui <cherryyz@google.com>
Tue, 1 Aug 2023 17:36:28 +0000 (17:36 +0000)
Older s390x before z13 did not have support to carry out floating point operations i.e. they didn't have the support for vector instructions like VX/VL, etc.

Starting with Go1.19, z13 is the minimum hardware level for running Go on LoZ (s390x). The main cause of this issue was the refactoring of elliptic curve to internal/nistec. The new code structures made it difficult to dynamically switch implementations at runtime, so it became necessary (in order machines to continue to use the accelerated implementation) to require z13 as the minimum hardware.

Hence, Go programs, when run on unsupported hardware, should crash on startup instead of crashing out in crypto code.

Fixes: #58465
Change-Id: I7c1a816205d19b5ddd2f1464839d16fa96815384
Reviewed-on: https://go-review.googlesource.com/c/go/+/499495
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Bypass: Cherry Mui <cherryyz@google.com>

src/runtime/asm_s390x.s
src/runtime/os_linux_s390x.go

index a7f414ef91f1177dd33e628c96bc53748a3659fd..a8e1424bf1813ded69495643380b2fb0c740ae3c 100644 (file)
@@ -142,6 +142,7 @@ nocgo:
 
        // argc/argv are already prepared on stack
        BL      runtime·args(SB)
+       BL      runtime·checkS390xCPU(SB)
        BL      runtime·osinit(SB)
        BL      runtime·schedinit(SB)
 
index b9651f186c3fe8a336a31916925b66c2668108cc..0a1d95975edd673e9e8b32e8e999c13b104ad5d5 100644 (file)
@@ -6,6 +6,10 @@ package runtime
 
 import "internal/cpu"
 
+const (
+       _HWCAP_VX = 1 << 11 // vector facility
+)
+
 func archauxv(tag, val uintptr) {
        switch tag {
        case _AT_HWCAP:
@@ -14,3 +18,14 @@ func archauxv(tag, val uintptr) {
 }
 
 func osArchInit() {}
+
+func checkS390xCPU() {
+       // Check if the present z-system has the hardware capability to carryout
+       // floating point operations. Check if hwcap reflects CPU capability for the
+       // necessary floating point hardware (HasVX) availability.
+       // Starting with Go1.19, z13 is the minimum machine level for running Go on LoZ
+       if cpu.HWCap&_HWCAP_VX == 0 {
+               print("runtime: This CPU has no floating point hardware, so this program cannot be run. \n")
+               exit(1)
+       }
+}