RISC-V: detect virtual address space at runtime using hwprobe#1296
Open
aurel32 wants to merge 1 commit into
Open
RISC-V: detect virtual address space at runtime using hwprobe#1296aurel32 wants to merge 1 commit into
aurel32 wants to merge 1 commit into
Conversation
The virtual address space on RISC-V is currently detected at build time by parsing /proc/cpuinfo. This works when the binary runs on the same hardware it was built, however running such a binary on a system with a larger address space just causes a segmentation fault. Replace the build time check with a runtime detection using the hwprobe interface (available since Linux 6.11, commit c9b8cd139c1d "riscv: hwprobe export highest virtual userspace address"). For older kernels, fallback to the default 48 bits. This is suboptimal on SV39 MMUs but still works.
Author
|
@microsoft-github-policy-service agree |
res2k
reviewed
May 18, 2026
|
|
||
| # Check /proc/cpuinfo for an SV39 MMU and limit the virtual address bits. | ||
| # (this will skip the aligned hinting in that case. Issue #939, #949) | ||
| if (EXISTS /proc/cpuinfo) |
Contributor
There was a problem hiding this comment.
Perhaps turn that into an explicit build time option? That way, people targeting an SV39 can at least explicitly request an appropriate number of bits.
(TBF, I have no idea how large that group may be.)
Contributor
There was a problem hiding this comment.
... targeting an SV39 and an older kernel.
Author
There was a problem hiding this comment.
I am not a big fan of configure options like that, because people don't really look at it until things are broken. I prefer when things work out of the box, but I understand your concern about supporting older kernels. What about adding a fallback parsing /proc/cpuinfo at runtime for older kernels?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The virtual address space on RISC-V is currently detected at build time by parsing /proc/cpuinfo. This works when the binary runs on the same hardware it was built, however running such a binary on a system with a larger address space just causes a segmentation fault.
Replace the build time check with a runtime detection using the hwprobe interface (available since Linux 6.11, commit c9b8cd139c1d "riscv: hwprobe export highest virtual userspace address"). For older kernels, fallback to the default 48 bits. This is suboptimal on SV39 MMUs but still works.