fix: pmp sector walk hang on accesses at the top of the address space - #61
Open
cphurley82 wants to merge 2 commits into
Open
cphurley82 wants to merge 2 commits into
cphurley82 wants to merge 2 commits into
Conversation
added 2 commits
September 30, 2026 18:51
The pmp-tests job set no timeout anywhere, so a firmware test that hangs the simulator would hold the runner until GitHub's six-hour default. A PMP check that never terminates produces exactly that: no trap, no log, no exit. Wrap every riscv-sim invocation in `timeout 60` so a hang fails its own step with exit 124, and cap the job at ten minutes as a backstop for the steps around it. Each test runs in under 0.1s locally and the whole job has taken 20 to 40 seconds on recent runs, so neither bound is close. The no-PMP CSR step, which expects exit 2, still fails on a timeout because 124 is not 2.
pmp_check bounded its sector walk with cur_addr <= last_sector. When the access touches the top sector, the step past it wraps to 0 and the loop never ends, hanging the simulation with no trap or log. A zero-length access at address 0 hangs the same way. Bound the walk on a 64-bit byte count instead, which cannot wrap. Counting from the start of the first sector keeps misaligned accesses covering their last sector. pmp-top-sector-test loads from the top sector in M mode with one entry enabled elsewhere. It hung before this change and passes now.
cphurley82
marked this pull request as ready for review
October 1, 2026 23:42
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.
Problem
pmp_checkwalks every 4-byte sector an access touches, with an address as the loop bound:for(cur_addr = first_sector; cur_addr <= last_sector; cur_addr += sector_size)
last_sectorwrapscur_addrto 0. That is still<= last_sector, so the loop never ends. The simulator hangs with no trap and no log.addr + len - 1underflows, solast_sectorbecomes the top sector.Fix
len.addr % 4 == 2still checks both sectors it spans.Tests
pmp-top-sector-test: programs one NA4 entry well away from the top, then does an M-mode load from the top 4-byte sector. Before the fix this hangs. With the fix, no entry matches and the load completes under the M-mode default.riscv-simstep in that job now runs undertimeout 60, and the job has a 10-minute limit. A hang like this one now fails CI instead of stalling it.