Fix hgatp unsupported mode writes - #3552
Merged
JeanRochCoulon merged 6 commits intoSep 15, 2026
Merged
JeanRochCoulon merged 6 commits into
JeanRochCoulon merged 6 commits into
Conversation
Preserve the current hgatp mode when software writes an unsupported MODE value, while still committing the legalized PPN and VMID fields. Add a directed regression for the unsupported MODE WARL behavior.
Contributor
|
@ASintzoff can you approve ? |
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.
Description
Fix the WARL handling of
hgatp.MODEwhen software writes an unsupported MODE value.The current
hgatpwrite path only commitshgatp_dwhen the written MODE is eitherBare(ModeOff) or the virtual-memory mode supported by the selected CVA6 configuration.When software writes an unsupported MODE value, the assignment to
hgatp_dis skipped completely. As a result, the entire write is discarded and the previous PPN and VMID values remain unchanged together with the previous MODE.This behavior is incorrect for
hgatp.Unlike
satp, anhgatpwrite containing an unsupported MODE value must not cause the entire CSR write to be ignored. The MODE field must be legalized according to its WARL behavior while the remaining writable fields are still allowed to take their legal values.The fix keeps the currently valid
hgatp.MODEwhen the written MODE is unsupported and then commits the rest of the legalizedhgatpvalue. This allows the newly written PPN and VMID fields to update instead of retaining values from the previous guest.The existing
satpandvsatpbehavior is not changed.Related issue
Fixes #3495
Root cause
The existing
CSR_HGATPwrite handling contains logic equivalent to:This means that when the incoming MODE is unsupported,
hgatp_dis never updated.For example:
Initial legal value:
Second write:
MODE value 1 is unsupported for this configuration.
Before this fix, the second write is discarded entirely and the CSR remains equivalent to:
The expected WARL behavior is:
The legal MODE is retained while the legal PPN field from the new write is accepted.
Changes
The
CSR_HGATPwrite path incore/csr_regfile.svis changed so that:hgatp_q.mode;hgatpvalue is always committed tohgatp_d;satpandvsatphandling remain unchanged.A directed regression test is also added to reproduce the bug and verify the corrected WARL behavior.
Regression test
Added:
Testlist:
Test name:
The regression performs the following sequence:
Write a legal
hgatpvalue with MODE set to Sv39x4 and PPN set to0x100.Read back
hgatpand verify that the legal write was accepted.Write
hgatpagain with unsupported MODE value1and PPN set to0x200.Read back
hgatp.Verify that MODE remains Sv39x4 while PPN changes to
0x200.The second check specifically detects the original bug where the complete second write was discarded.
Verification
Target configuration:
The Verilator model was built with:
The post-change Verilator build completed successfully with exit status 0.
Before the fix
The directed regression reproduced the bug:
The simulation terminated after approximately 2928 cycles.
The failure occurs at test number 2, which is the unsupported-MODE write/read-back check.
This confirms that the original RTL retains the previous PPN after the unsupported MODE write instead of accepting the new PPN.
After the fix
After rebuilding the Verilator model with the RTL change, the exact same regression passed:
The post-fix RTL run returned:
This demonstrates the expected transition:
The directed test was also compiled and run against Spike as the reference model to confirm the expected WARL behavior.
Files changed
Scope
This change is intentionally limited to the
hgatpunsupported-MODE WARL handling.It does not modify the behavior of:
satp;vsatp;Limitations
Local directed RTL verification was performed with the
cv64a6_imafdch_sv39configuration.Broader configuration and regression coverage is expected to be exercised by the CVA6 continuous-integration flow.