Signed-off-by: WenLei <lei.wen2@zte.com.cn>
Fix runtime detection of RISC-V ZBC and ZVBC crypto extensions.
Problems fixed:
- <sys/hwprobe.h> only exists in glibc >= 2.40 (released 2024-07-22).
Many production RISC-V distros still use older glibc (Ubuntu 22.04: 2.35,
Debian 12: 2.36, etc.) and would fail to compile.
Therefore we switch to the kernel UAPI header <asm/hwprobe.h>,
which works with all current glibc versions.
Proof:
- Absent in glibc 2.39:
https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h;hb=refs/tags/glibc-2.39
- Present in glibc 2.40:
https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/riscv/sys/hwprobe.h;hb=refs/tags/glibc-2.40
- Introducing commit:
https://sourceware.org/git/?p=glibc.git;a=commit;h=
426d0e1aa8f17426d13707594111df712d2b8911
- Incorrect fallback bit positions:
- RISCV_HWPROBE_EXT_ZBC was (1ULL << 15) → should be (1ULL << 7)
- RISCV_HWPROBE_EXT_ZVBC was (1ULL << 20) → should be (1ULL << 18)
Signed-off-by: WenLei <lei.wen2@zte.com.cn>
* Runtime detection of RISC-V vector crypto support.
*/
-#include <sys/hwprobe.h>
+#include <asm/hwprobe.h>
#include <sys/syscall.h>
#include <unistd.h>
int ceph_arch_riscv_zvbc = 0;
#ifndef RISCV_HWPROBE_EXT_ZBC
-#define RISCV_HWPROBE_EXT_ZBC (1ULL << 15)
+#define RISCV_HWPROBE_EXT_ZBC (1ULL << 7)
#endif
#ifndef RISCV_HWPROBE_EXT_ZVBC
-#define RISCV_HWPROBE_EXT_ZVBC (1ULL << 20)
+#define RISCV_HWPROBE_EXT_ZVBC (1ULL << 18)
#endif
static int do_hwprobe(struct riscv_hwprobe *pairs, size_t count)