Skip to content

several RISC-V hwcap fixes#1999

Merged
Dead2 merged 1 commit intozlib-ng:developfrom
Icenowy:riscv-hwcap-fixes
Nov 13, 2025
Merged

several RISC-V hwcap fixes#1999
Dead2 merged 1 commit intozlib-ng:developfrom
Icenowy:riscv-hwcap-fixes

Conversation

@Icenowy
Copy link
Copy Markdown
Contributor

@Icenowy Icenowy commented Nov 11, 2025

This PR drops the code that checks uname before accessing AT_HWCAP (because this auxval always exist in RISC-V Linux), and drops the bogus HWCAP bit for Zbc (because it's never part of upstream Linux UAPI).

cc @ziyao233

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Nov 11, 2025

Walkthrough

Removed kernel-version branching and compile-time feature checks from RISC-V feature detection; riscv_check_features now always uses runtime hardware capability detection and ZBC-related compile-time checks and helper were removed.

Changes

Cohort / File(s) Summary
RISC-V feature detection simplification
arch/riscv/riscv_features.c
Deleted is_kernel_version_greater_or_equal_to_6_5 and riscv_check_features_compile_time; removed compile-time ZBC checks and associated code paths; simplified riscv_check_features to always use runtime HW capability detection (RVV from HWCAP) and treat ZBC as disabled.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Init as Kernel init
    participant Features as riscv_check_features
    participant HW as Hardware HWCAP
    participant Compile as Compile-time checks (old)

    rect `#f0f8ff`
    Note over Init,Features: Old flow (before change)
    Init->>Features: call riscv_check_features
    alt kernel >= 6.5
        Features->>Compile: run compile-time checks
        Compile-->>Features: compile-time results
    else kernel < 6.5
        Features->>HW: read runtime HWCAP
        HW-->>Features: hw capability bits
    end
    Features-->>Init: feature bitmap
    end

    rect `#f7fff0`
    Note over Init,Features: New flow (after change)
    Init->>Features: call riscv_check_features
    Features->>HW: read runtime HWCAP (RVV from HWCAP)
    HW-->>Features: hw capability bits
    Features-->>Init: feature bitmap (ZBC disabled)
    end
Loading

Possibly related PRs

Suggested labels

Architecture

Suggested reviewers

  • Dead2

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'several RISC-V hwcap fixes' is clearly related to the changeset, which removes kernel version checking and incorrect HWCAP bits in RISC-V feature detection code.
Description check ✅ Passed The PR description accurately explains the changes: removing uname checks before AT_HWCAP access and removing the bogus Zbc HWCAP bit, which align with the code modifications removing version checks and simplifying feature detection.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b989f77 and 331f8c4.

📒 Files selected for processing (1)
  • arch/riscv/riscv_features.c (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • arch/riscv/riscv_features.c
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (100)
  • GitHub Check: macOS Clang (Intel, Target 10.10)
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: macOS Clang ASAN (Intel)
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang (Intel, Target 10.10)
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: macOS Clang ASAN (Intel)
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang (Intel, Target 10.10)
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: macOS Clang ASAN (Intel)
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang (Intel, Target 10.10)
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: macOS Clang ASAN (Intel)
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang (Intel, Target 10.10)
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: macOS Clang ASAN (Intel)
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang (Intel, Target 10.10)
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: macOS Clang ASAN (Intel)
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang (Intel, Target 10.10)
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: macOS Clang ASAN (Intel)
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang (Intel, Target 10.10)
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: macOS Clang ASAN (Intel)
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang (Intel, Target 10.10)
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: macOS Clang ASAN (Intel)
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: macOS Clang (Intel, Target 10.10)
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: Windows ClangCl Win64 Native Instructions (AVX)
  • GitHub Check: macOS Clang ASAN (Intel)
  • GitHub Check: Windows MSVC 2022 v140 Win32
  • GitHub Check: Windows MSVC 2022 v141 Win64
  • GitHub Check: Windows MSVC 2022 v141 Win32
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: EL10 GCC S390X DFLTCC UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Nov 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.78%. Comparing base (20083c8) to head (331f8c4).
⚠️ Report is 3 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1999      +/-   ##
===========================================
- Coverage    83.31%   82.78%   -0.53%     
===========================================
  Files          161      161              
  Lines        12960    12952       -8     
  Branches      3149     3145       -4     
===========================================
- Hits         10797    10722      -75     
- Misses        1133     1170      +37     
- Partials      1030     1060      +30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Nov 12, 2025

Calling something downstream "bogus" is not going to help getting this PR approved... Only way this PR is going to get approved is to combine it with adding support for hwprobe.

@Dead2
Copy link
Copy Markdown
Member

Dead2 commented Nov 12, 2025

Only way this PR is going to get approved is to combine it with adding support for hwprobe.

That would have to be after the first 2.3 stable release.
As I said earlier, I want a PR that only fixes the critical problems now before 2.3, proper hwprobe implementation will have to come later.

This PR disables ZBC completely, and while that is certainly not ideal, I am fine with that for now if that fixes a real problem.

@ziyao233
Copy link
Copy Markdown

ziyao233 commented Nov 12, 2025

I've discussed the change privately earlier with Icenowy, and would prefer this PR over #1996 since it keeps the detection of RVV version (the asm volatile block) and thus won't break problematic downstream kernels that set HWCAP_ISA_V even with RVV v0.7.1.

We could drop the extra detection later when hwprobe support is introduced: these problematic kernels don't have hwprobe support backported, so hwprobe will fail and we could simply fallback to GC. But serving as a quick fix, keeping most of the logic and only fixing the real problem sounds better to me.

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Nov 12, 2025

This PR disables ZBC completely, and while that is certainly not ideal, I am fine with that for now if that fixes a real problem.

Disabling ZBC detection would discourage downstream projects from switching to zlib-ng until we implement hwprobe, which is more than just not ideal. It makes the project look unprofessional. This PR can be split in two by removing any controversial changes and delaying adding support for hwprobe to later zlib-ng release.

We can list in 2.3.0 release notes that minimum supported kernel version for optimised variants is 6.5 as that is already established as safe requirement.

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Nov 12, 2025

I've discussed the change privately earlier with Icenowy, and would prefer this PR over #1996 since it keeps the detection of RVV version (the asm volatile block) and thus won't break problematic downstream kernels that set HWCAP_ISA_V even with RVV v0.7.1.

We could drop the extra detection later when hwprobe support is introduced: these problematic kernels don't have hwprobe support backported, so hwprobe will fail and we could simply fallback to GC. But serving as a quick fix, keeping most of the logic and only fixing the real problem sounds better to me.

Even after hwprobe syscall support is added in zlib-ng, there will be "short" gap before we change the minimum kernel version requirement... It might be possible when 2.4.0 is eventually released, but not before... This gives downstream projects enough time to switch to kernel that implements hwprobe syscall.

@Icenowy
Copy link
Copy Markdown
Contributor Author

Icenowy commented Nov 12, 2025

I am okay to strip the Zbc commit out, although technically this is incorrect and may lead to problems in the future (but at least not now).

The HWCAP facility comes at day 1 of Linux RISC-V support (date back to
4.15), only the V bit definition is added in 6.5 (because proper vector
support is added in that version too).

There should be no need to test kernel version number before accessing
hwcap, only the V bit will never be present on kernel older than 6.5
(except dirty patched downstream ones).

For Xtheadvector systems that bogusly announce V bit in HWCAP, the
assembly code should be able to factor them out. This is tested on
a Sophgo SG2042 machine with 6.1 kernel.

Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
@Icenowy
Copy link
Copy Markdown
Contributor Author

Icenowy commented Nov 12, 2025

Dropped the Zbc patch and fixed the problem that riscv_check_features_compile_time() is forgot to be removed .

Copy link
Copy Markdown
Member

@Dead2 Dead2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Dead2 Dead2 merged commit 29cf624 into zlib-ng:develop Nov 13, 2025
155 of 156 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants