diff options
author | Xi Ruoyao <xry111@xry111.site> | 2023-07-21 02:07:04 +0000 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2023-07-28 12:39:41 +1000 |
commit | c612289b77c37f7295d5af0d0e6b6c04e6ba727c (patch) | |
tree | 8d2c541d218c93a8ce658ebae4db163869015fe2 /crypto/loongarchcap.c | |
parent | 7f14656e1cc002a09b2d6148302a1fc71a30f7cd (diff) |
vpaes: LoongArch: Use getauxval(AT_HWCAP) for LSX detection
Running LSX instructions requires both the hardware support and the
kernel support. The `cpucfg` instruction only tests the hardware
support, causing a SIGILL if the hardware supports LSX but the kernel
does not.
Use `getauxval(AT_HWCAP)` as the ["Software Development and Build
Convention for LoongArch Architectures"][1] manual suggests.
The LOONGARCH_HWCAP_LSX and LOONGARCH_HWCAP_LASX bits are copied from
the manual too. In Glibc 2.38 they'll be provided by <sys/auxv.h> as
well, but they are unavailable in earlier Glibc versions so we cannot
rely on it.
The getauxval syscall and Glibc wrapper are available since day one
(Linux-5.19 and Glibc-2.36) for LoongArch.
Fixes #21508.
[1]:https://github.com/loongson/la-softdev-convention/blob/master/la-softdev-convention.adoc#kernel-constraints
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21509)
Diffstat (limited to 'crypto/loongarchcap.c')
-rw-r--r-- | crypto/loongarchcap.c | 11 |
1 files changed, 3 insertions, 8 deletions
diff --git a/crypto/loongarchcap.c b/crypto/loongarchcap.c index 67e3c02b41..8983909938 100644 --- a/crypto/loongarchcap.c +++ b/crypto/loongarchcap.c @@ -6,17 +6,12 @@ * in the file LICENSE in the source distribution or at * https://www.openssl.org/source/license.html */ +#include <sys/auxv.h> #include "loongarch_arch.h" -unsigned int OPENSSL_loongarchcap_P = 0; +unsigned int OPENSSL_loongarch_hwcap_P = 0; void OPENSSL_cpuid_setup(void) { - unsigned int reg; - __asm__ volatile( - "cpucfg %0, %1 \n\t" - : "+&r"(reg) - : "r"(LOONGARCH_CFG2) - ); - OPENSSL_loongarchcap_P = reg; + OPENSSL_loongarch_hwcap_P = getauxval(AT_HWCAP); } |