Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pmp] Fix ePMP related trap handling #903

Merged
merged 12 commits into from
Oct 24, 2022

Conversation

marnovandermaas
Copy link
Contributor

@marnovandermaas marnovandermaas commented Oct 13, 2022

The RISCV-DV PMP trap handler is quite an intricate procedure. In essence, it iterates through the PMP entries to find the one that caused the trap, then tries to amend that entry to give it the permissions it needs and continues the test program if that was successful. This works quite well when most entries are unlocked since whenever you get an access fault, the entry is changed to allow the operation and the instruction is retried. However, there are a few problems with this approach:

  • The checking for locked entries did not take into account that MML mode.
  • In cases where most entries are locked (e.g. MML mode), tests would be very short ending after just the first failed load, store or fetch.

Besides the trap handling, the population of entries had some shortcomings, which lead to poor coverage:

  • NAPOT regions would have a random address, which made it very unlikely large regions are selected, which require a consecutive sequence of 1s at the end.
  • The top of TOR regions was never lower than its base.

This PR addresses these issues. This is quite a big PR, but I have split it up into smaller commits to make reviewing easier. Please have a look at each commit message, but in summary these changes include:

  • Fixes to make MML tests work
  • PMP trap handler:
    • Skipping faulting loads and stores
    • Checking for MML and MMWP
    • Stop overwriting mscratch
  • Improved PMP configuration and debugging
  • Improved coverage of NAPOT and illegal TOR regions

@marnovandermaas
Copy link
Contributor Author

@hcallahan-lowrisc would you be able to have a look at this?

@marnovandermaas
Copy link
Contributor Author

@vogelpi, in case you have time would you be able to review this PR?

Except for the full random test in which case the signature and stack
stay just after the code region.
This change is necessary to not break the default configuration of PMP
entries, which rely on consecutive TOR regions.

Signed-off-by: Marno van der Maas <[email protected]>
- Renamed pmp_allow_addr_overlap to pmp_allow_illegal_tor
- If illegal tor is enabled make chance of constraint being
  dropped 1 / XLEN
- Add constraint that NAPOT addresses have a random size

Signed-off-by: Marno van der Maas <[email protected]>
Signed-off-by: Marno van der Maas <[email protected]>
Copy link
Contributor

@ctopal ctopal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it looks good, I am not sure about the skipping in the case of seeing a load/store fault solution but also can't see another way as well. Just had a minor thing for the last commit but I think it shouldn't matter that much so I think this one is good to go.

pmp_cfg[code_entry].offset = assign_default_addr_offset(pmp_num_regions, 0);
pmp_cfg[code_entry].offset = assign_default_addr_offset(pmp_num_regions, code_entry);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I believe this fix probably needs to go to the first commit.

Copy link
Contributor

@GregAC GregAC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One tiny nit on a comment but otherwise this looks good. Probably not worth the faff in fixing the comment as marno is away. @hcallahan-lowrisc have you seen any issues with this, are you happy with it? If there's no problems we should get this merged.

$sformatf("csrw 0x%0x, x%0d", MEPC, scratch_reg[0]),
$sformatf("j 34f"),
$sformatf("28: csrr x%0d, 0x%0x", scratch_reg[0], MEPC),
// Increase MEPC by 4 in case instruction is compressed.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compressed -> uncompressed

@hcallahan-lowrisc
Copy link
Contributor

@GregAC @ctopal no I have not seen any issues, happy to merge as-is.

@GregAC
Copy link
Contributor

GregAC commented Oct 24, 2022

@weicaiyang PTAL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants