fix: report guest-page fault for G-stage fetch - #3557
Open
124107157-KV wants to merge 3 commits into
Open
124107157-KV wants to merge 3 commits into
124107157-KV wants to merge 3 commits into
Conversation
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.
Why is this PR needed?
Under pure G-stage translation with
vsatp.MODE = Bareandhgatp.MODE = Sv39x4, the instruction-fetch address is a guest physical address (GPA).For Sv39x4, GPA bits [63:41] must be zero. If any of these bits are set, the access must raise a guest-page-fault exception.
The instruction-fetch path in
core/cva6_mmu/cva6_mmu.svcurrently combines the VS-stage virtual-address canonicality check and the pure G-stage GPA-width check in the same condition. As a result, both cases reportINSTR_PAGE_FAULT.The VS-stage case is correct, but the pure G-stage GPA-width failure must report
INSTR_GUEST_PAGE_FAULT.This distinction matters because
INSTR_PAGE_FAULTmay be delegated to VS-mode throughhedeleg, whileINSTR_GUEST_PAGE_FAULTmust remain under hypervisor control.What does this PR change?
This change separates the two instruction-fetch address checks.
INSTR_PAGE_FAULT.INSTR_GUEST_PAGE_FAULT.tval2remains zero for this exception path, which is permitted for a guest-page fault.A directed regression test is added with two variants:
rv64h-p-gstage-overflow-fetchrv64h-p-gstage-overflow-dataThe fetch variant enables pure G-stage Sv39x4 translation with
vsatp=Bare, enters VS-mode, and attempts to fetch from a GPA with bit 41 set.The data-side variant performs the corresponding load and is included as a control.
Verification
Target:
cv64a6_imafdch_sv39The directed tests were run with the Verilator test harness and Spike:
rv64h-p-gstage-overflow-fetchrv64h-p-gstage-overflow-dataBefore the fix, the fetch case exposes the mismatch: CVA6 reports
INSTR_PAGE_FAULTwith mcause 12 while Spike reportsINSTR_GUEST_PAGE_FAULTwith mcause 20.With this change applied, the fetch test agrees with Spike and passes.
The data-side control continues to report
LOAD_GUEST_PAGE_FAULTwith mcause 21 and passes on both CVA6 and Spike.The following existing regression tests were also checked:
rv64si-p-dirtyrv64mi-p-ma_addrBoth continue to pass.
git diff --checkalso passes.Related issue
Fixes #3428
Limitations
No known functional limitations.
The behavioral change is limited to the RV64 pure G-stage instruction-fetch GPA-width failure. Existing VS-stage page-fault behavior and non-hypervisor configurations are unchanged.