-
Notifications
You must be signed in to change notification settings - Fork 244
Fix CSR privilege check for hypervisor mode. #1504
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
base: master
Are you sure you want to change the base?
Conversation
When hypervisor is enabled, `Supervisor` (HS-mode) and `VirtualSupervisor` (VS-mode) privileges are encoded as `0b01` in `privLevel_bits()`, but the CSR addresses for hypervisor and VS CSRs encode the required privilege as `0b10`. Define a private function to correct for this when checking privilege. Fixes riscv#1503.
44b77f5 to
2bc7f82
Compare
| match p { | ||
| User => 0b00, | ||
| VirtualUser => 0b00, | ||
| Supervisor => if currentlyEnabled(Ext_H) then 0b10 else 0b01, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would actually work if it was just 0b10 right? If hypervisor is disabled non of the 0b10 CSRs exist anyway. I dunno if that's necessarily better code though.
Also I think this is correct but I couldn't find anywhere that really explicitly says how this is meant to work in the spec. Just this
The next two bits (csr[9:8]) encode the lowest privilege level that can access the CSR.
Which is clear without hypervisor but not very clear at all with hypervisor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that this is not clear. Opened riscv/riscv-isa-manual#2630
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hopefully clearer now with riscv/riscv-isa-manual#2631
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about this?
| Supervisor => if currentlyEnabled(Ext_H) then 0b10 else 0b01, | |
| Supervisor => 0b10, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed that it may be redundant with an existence check, but I'm leaning towards keeping it as it is, to make sure we don't miss the condition when we refactor this for hypervisor in #1402.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just add a comment for now? // Note that this if is not strictly necessary. We could return 0b10 unconditionally since hypervisor CSRs don't exist anyway if hypervisor is not enabled.
When hypervisor is enabled,
Supervisor(HS-mode) andVirtualSupervisor(VS-mode) privileges are encoded as0b01inprivLevel_bits(), but the CSR addresses for hypervisor and VS CSRs encode the required privilege as0b10. Define a private function to correct for this when checking privilege.Fixes #1503.