Skip to content

Conversation

@pmundkur
Copy link
Collaborator

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 #1503.

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.
@github-actions
Copy link

github-actions bot commented Jan 27, 2026

Test Results

2 117 tests  +2   2 117 ✅ +2   23m 45s ⏱️ +4s
    1 suites ±0       0 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit c44b5aa. ± Comparison against base commit 89935a8.

♻️ This comment has been updated with latest results.

match p {
User => 0b00,
VirtualUser => 0b00,
Supervisor => if currentlyEnabled(Ext_H) then 0b10 else 0b01,
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

Copy link
Collaborator Author

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

Copy link
Collaborator

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?

Suggested change
Supervisor => if currentlyEnabled(Ext_H) then 0b10 else 0b01,
Supervisor => 0b10,

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

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.

check_CSR_priv breaks for hypervisor

5 participants