Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RVV support enabled accidentally and leads to SIGILL on older kernels #1705

Open
xctan opened this issue Mar 27, 2024 · 3 comments
Open

RVV support enabled accidentally and leads to SIGILL on older kernels #1705

xctan opened this issue Mar 27, 2024 · 3 comments
Labels
Architecture Architecture specific Build Env

Comments

@xctan
Copy link

xctan commented Mar 27, 2024

PR #1585 has added runtime detection of RISC-V vector support for kernels newer than or equal to 6.5, and if the kernel is too old, zlib-ng would use compile time compiler support as fallback. However, this behavior is not safe for older kernels in conjunction with new compilers. In my case, I was using Linux 6.1.61 and GCC 13.2.1 when trying to compile starship 1.18.1 with default features enabled, including zlib-ng. Some git test cases of starship would fail because of the SIGILL signal coming from adler32_rvv.

I suggest using a more conservative assumption about runtime support of RVV when hwcap is not available. When the kernel is too old, or hwcap is disabled by the sandbox mechanism, RVV support should be disabled.

xctan added a commit to xctan/archriscv-packages that referenced this issue Mar 27, 2024
Workaround for buggy RVV detection in zlib-ng, see zlib-ng/zlib-ng#1705
felixonmars pushed a commit to felixonmars/archriscv-packages that referenced this issue Mar 28, 2024
Workaround for buggy RVV detection in zlib-ng, see zlib-ng/zlib-ng#1705
@mtl1979
Copy link
Collaborator

mtl1979 commented Apr 3, 2024

We enable everything by default if we can't detect availability of specific instructions... This is to encourage people to upgrade to at least oldest usable kernel and C library versions... Flipping the default to not enable everything would require the change for all architectures. We still allow disabling every optimisation to make it possible to compile for older kernels.

@nmoinvaz nmoinvaz added Build Env Architecture Architecture specific labels Apr 9, 2024
@ncopa
Copy link

ncopa commented May 9, 2024

I bumped into this on Alpine Linux with the Mlik-v pioneer machine, with sophgo 2042 and RVV 0.7.1.

In alpine we have previously bumped into same issue with ffmpeg and highway.

@ncopa
Copy link

ncopa commented May 9, 2024

We are using this workaround based on the fix from highway

diff --git a/arch/riscv/riscv_features.c b/arch/riscv/riscv_features.c
index b066f42..259a63a 100644
--- a/arch/riscv/riscv_features.c
+++ b/arch/riscv/riscv_features.c
@@ -42,4 +42,20 @@ void Z_INTERNAL riscv_check_features(struct riscv_cpu_features *features) {
         riscv_check_features_runtime(features);
     else
         riscv_check_features_compile_time(features);
+    if (features->has_rvv) {
+       size_t e8m1_vec_len;
+       int64_t vtype_reg_val;
+       // Check that a vuint8m1_t vector is at least 16 bytes and that tail
+       // agnostic and mask agnostic mode are supported
+       //
+       __asm__ volatile(
+               "vsetvli %0, zero, e8, m1, ta, ma\n\t"
+               "csrr %1, vtype"
+               : "=r"(e8m1_vec_len), "=r"(vtype_reg_val));
+
+       // The RVV target is supported if the VILL bit of VTYPE (the MSB bit of
+       // VTYPE) is not set and the length of a vuint8m1_t vector is at least 16
+       // bytes
+       features->has_rvv = (vtype_reg_val >= 0 && e8m1_vec_len >= 16);
+    }
 }

For 32 bit the vtype_reg_val needs to be int32_t, but I was lazy since Alpine only supports 64 bit riscv.

algitbot pushed a commit to alpinelinux/aports that referenced this issue May 9, 2024
The sophgo 2042 (milk-v pioneer) has RVV 0.7.1 which is not fully
compatible. Fix the RVV test.

Patch is adapted from: google/highway#2127

Note that it only works on 64 bit RISC-V.

upstream: zlib-ng/zlib-ng#1705
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Architecture Architecture specific Build Env
Projects
None yet
Development

No branches or pull requests

4 participants