From 6fe976545d646a3f076a84a7ca22be63df8da718 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 31 May 2023 12:06:02 +0000 Subject: [PATCH] runtime: handle SIGPE exception for p256 crypto package on s390x 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 Reviewed-by: Keith Randall Reviewed-by: Cherry Mui Run-TryBot: Cherry Mui TryBot-Bypass: Cherry Mui --- src/runtime/asm_s390x.s | 1 + src/runtime/os_linux_s390x.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/runtime/asm_s390x.s b/src/runtime/asm_s390x.s index a7f414ef91..a8e1424bf1 100644 --- a/src/runtime/asm_s390x.s +++ b/src/runtime/asm_s390x.s @@ -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) diff --git a/src/runtime/os_linux_s390x.go b/src/runtime/os_linux_s390x.go index b9651f186c..0a1d95975e 100644 --- a/src/runtime/os_linux_s390x.go +++ b/src/runtime/os_linux_s390x.go @@ -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) + } +} -- 2.50.0