-
-
Notifications
You must be signed in to change notification settings - Fork 264
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
SSH connection to RISCV failed. #1769
Comments
Run-time feature detection on RISC-V is still quite a new feature and not all kernels support it, so knowing the kernel version will be important. |
Linux kernel 6.6.36 on SpacemiT K1. I compile and run #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/utsname.h>
#include <sys/auxv.h>
// see asm/hwcap.h
#define ISA_V_HWCAP (1 << ('v' - 'a'))
#define ISA_ZBC_HWCAP 45
struct riscv_cpu_features {
int has_rvv;
int has_zbc;
};
int is_kernel_version_greater_or_equal_to_6_5() {
struct utsname buffer;
uname(&buffer);
int major, minor;
if (sscanf(buffer.release, "%d.%d", &major, &minor) != 2) {
// Something bad with uname()
return 0;
}
if (major > 6 || major == 6 && minor >= 5)
return 1;
return 0;
}
void riscv_check_features_compile_time(struct riscv_cpu_features *features) {
printf("riscv_check_features_compile_time\n");
#if defined(__riscv_v) && defined(__linux__)
features->has_rvv = 1;
#else
features->has_rvv = 0;
#endif
#if defined(__riscv_zbc) && defined(__linux__)
features->has_zbc = 1;
#else
features->has_zbc = 0;
#endif
}
void riscv_check_features_runtime(struct riscv_cpu_features *features) {
printf("riscv_check_features_runtime\n");
unsigned long hw_cap = getauxval(AT_HWCAP);
features->has_rvv = hw_cap & ISA_V_HWCAP;
features->has_zbc = hw_cap & ISA_ZBC_HWCAP;
}
void riscv_check_features(struct riscv_cpu_features *features) {
if (is_kernel_version_greater_or_equal_to_6_5())
riscv_check_features_runtime(features);
else
riscv_check_features_compile_time(features);
printf("has_rvv = %08x\n", features->has_rvv);
printf("has_zbc = %08x\n", features->has_zbc);
}
int main(){
struct riscv_cpu_features rf;
riscv_check_features(&rf);
}
|
SSH connection to the RISC-V board using
The issue can be reproduced more efficiently in this way. |
Things also happend on Linux kernel 6.1. void Z_INTERNAL riscv_check_features(struct riscv_cpu_features *features) {
// if (is_kernel_version_greater_or_equal_to_6_5())
// riscv_check_features_runtime(features);
// else
riscv_check_features_compile_time(features);
} Connection succeed. |
If your CPU supports RVV, please replace the zlib-ng/arch/riscv/riscv_features.c Lines 47 to 52 in 5b04d9c
void Z_INTERNAL riscv_check_features(struct riscv_cpu_features *features) {
features->has_rvv = 1;
} If the error is reproducible, then the problem is in the implementation of zlib-ng algorithms for RISC-V. |
@phprus And thanks for reminding me. |
#1769 (comment) is not equivalent to #1769 (comment) For test we need to manual set of |
I follow this to manual set of features->has_rvv to 1. No error shows up during connection. And i don't understand why the equivalence is false. Because i also manually set features->has_rvv to 1 but only inside |
To differentiate a feature detector bug and an implementation bug, we need to completely remove the feature detector from the source and set the |
@phprus Thanks very much, i got it. We do have rvv feature and rvv is turned on and thing goes well. So that there is no problem with RISC-V zlib-ng algorithms? As i said, |
Only function call in I will try to get all the feature detection fixes added in #1770, when I know the root cause of all the failures and crashes. |
What happened?
I try to ssh connect to my RISC-V device by python asyncssh, but some how failed.
Python3 asyncssh code:
Fail log:
What i found?
I use zlib-ng (version 2.2.1) instead of zlib on my RISC-V board. When i turn
WITH_RUNTIME_CPU_DETECTION
off, everything went well.But things work fine on ARM. Guess something is wrong with riscv_check_features.
How to reproduce?
Make and install zlib-ng with/without
WITH_RUNTIME_CPU_DETECTION
. Compare the asyncssh connection using the code above.WITH_RUNTIME_CPU_DETECTION
on -> failed.cmake .. -DZLIB_COMPAT=on -DWITH_RUNTIME_CPU_DETECTION=on
WITH_RUNTIME_CPU_DETECTION
off -> succeed.cmake .. -DZLIB_COMPAT=on -DWITH_RUNTIME_CPU_DETECTION=off
What i want?
World peace.
The text was updated successfully, but these errors were encountered: