mmu: enforce full PMP match across memory operations - #1889
Open
Syed-Moeed-Ali wants to merge 1 commit into
Open
Syed-Moeed-Ali wants to merge 1 commit into
Syed-Moeed-Ali wants to merge 1 commit into
Conversation
Signed-off-by: Syed-Moeed-Ali <syedmoeedali2006@gmail.com>
Contributor
|
Thank you for looking at this. I'm not certain the bug is real. PMP is subtle. riscvassertions_wally sets minimum bounds on G when misaligned accesses are possible. They are intended to avoid any cases where the end needs to be checked. Also, note that accesses spanning cache line boundaries are split into multiple accesses, each of which should satisfy the PMP rule. Can you construct any test cases (and configurations) where this fix is truly needed? This PR adds a significant amount of hardware, so I'm reluctant to add it unless the problem is real. If the problem is real, let's look for the lowest-cost solution. |
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.
Partially addresses #1833 (PMP item 1).
Summary
The PMP checker currently determines the matching PMP entry using only the starting physical address of a memory operation.
According to the RISC-V privileged specification, the lowest-numbered PMP entry that matches any byte of an access must match all bytes of that access. If a memory operation crosses into another PMP region, the access must fail even if both regions independently allow the requested operation.
Changes
This PR:
Computes the address of the final byte of each memory operation.
Performs PMP matching on both the starting and ending addresses.
Determines the highest-priority PMP entry for both endpoints.
Raises an access fault when the first and last byte match different PMP entries.
Applies the boundary check independently of the PMP R/W/X permission bits.
Uses the cache-line access size for cache-block operations.
Why this is needed
Previously, an access beginning inside a permitted PMP entry could extend beyond that entry without checking whether the same PMP entry covered the complete operation.
For example, an access crossing between two adjacent readable PMP regions must still fault because no single PMP entry covers the entire access.
This change compares the selected PMP entry for the first and last byte instead of only checking permissions at the ending address.
Scope
This PR specifically addresses the PMP full-memory-operation matching issue described in #1833.
Other MMU issues tracked in #1833 are outside the scope of this change.