Skip to content

Add satp mode guard #807

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KotorinMinami
Copy link
Contributor

From #796 , as the spec say

Implementations are not required to support all MODE settings, and if satp is written with an unsupported MODE, the entire write has no effect; no fields in satp are modified.

so adding extensionenabled and applying guard in legalize_satp I think might work.

Copy link
Collaborator

@jordancarlin jordancarlin left a comment

Choose a reason for hiding this comment

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

Need to think about whether extensionEnabled() makes sense for this. Technically only one of these extensions is ever enabled at a time (whichever is set in satp), but this may be the simplest way to implement this.

Copy link

github-actions bot commented Mar 21, 2025

Test Results

400 tests  ±0   400 ✅ ±0   1m 55s ⏱️ +2s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 03e322f. ± Comparison against base commit 8ff2a70.

♻️ This comment has been updated with latest results.

@jrtc27
Copy link
Collaborator

jrtc27 commented Mar 21, 2025

Need to think about whether extensionEnabled() makes sense for this. Technically only one of these extensions is ever enabled at a time (whichever is set in satp), but this may be the simplest way to implement this.

No? The extension just means it's a supported option for satp.MODE, not that it's the currently active one.

@jordancarlin
Copy link
Collaborator

Need to think about whether extensionEnabled() makes sense for this. Technically only one of these extensions is ever enabled at a time (whichever is set in satp), but this may be the simplest way to implement this.

No? The extension just means it's a supported option for satp.MODE, not that it's the currently active one.

The way it's handled in the model right now, we use extensionEnabled() to mean an extension is active and sys_enable_XXX() to indicate it's a supported extension. For example, extensionEnabled(Ext_F) is only true when mstatus.FS is not set to off. It seems like the analogue would be for the extensionEnabled() clauses to be dependent on satp.MODE, but I'm not sure that scheme totally works for the VM mode extensions for the same reason you just mentioned.

@jrtc27
Copy link
Collaborator

jrtc27 commented Mar 21, 2025

Need to think about whether extensionEnabled() makes sense for this. Technically only one of these extensions is ever enabled at a time (whichever is set in satp), but this may be the simplest way to implement this.

No? The extension just means it's a supported option for satp.MODE, not that it's the currently active one.

The way it's handled in the model right now, we use extensionEnabled() to mean an extension is active and sys_enable_XXX() to indicate it's a supported extension. For example, extensionEnabled(Ext_F) is only true when mstatus.FS is not set to off. It seems like the analogue would be for the extensionEnabled() clauses to be dependent on satp.MODE, but I'm not sure that scheme totally works for the VM mode extensions for the same reason you just mentioned.

The extension is always active, there's no way to turn it off. You just may not currently be using that specific mode in satp. It makes total sense for extensionEnabled to be true for each of the SvXX that the model is configured to support, because that's what the architecture says happens.

@KotorinMinami
Copy link
Contributor Author

If I understand correctly, my current implementation should be fine, right? Going forward, we just need to add the sys_enable_svxx() function and use them in isextensionEnable().

Copy link
Collaborator

@jordancarlin jordancarlin left a comment

Choose a reason for hiding this comment

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

LGTM now

Copy link
Collaborator

@arichardson arichardson left a comment

Choose a reason for hiding this comment

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

LGTM, but I think minor simplification is possible.

Copy link
Collaborator

@jordancarlin jordancarlin left a comment

Choose a reason for hiding this comment

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

From section 3.1.6.4 of the privileged spec:

SUM is read-only 0 if S-mode is not supported or if satp.MODE is read-only 0.

Right now mstatus.SUM is guarded on S, but now that we are adding a way to disable writes to satp it needs to be guarded on that as well. Same for sstatus.SUM.

Copy link
Collaborator

@jordancarlin jordancarlin left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@jordancarlin jordancarlin left a comment

Choose a reason for hiding this comment

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

Just needs to be updated for the new config system. Then should be good to go.

@@ -160,6 +160,19 @@ function sys_enable_supervisor() -> bool = true
function clause extensionEnabled(Ext_U) = misa[U] == 0b1
function clause extensionEnabled(Ext_S) = misa[S] == 0b1

// TODO: Make configurable
function clause extensionEnabled(Ext_Svbare) = extensionEnabled(Ext_S)
function clause extensionEnabled(Ext_Sv32) = extensionEnabled(Ext_S) & (xlen == 32)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Update

Suggested change
function clause extensionEnabled(Ext_Sv32) = extensionEnabled(Ext_S) & (xlen == 32)
function clause currentlyEnabled(Ext_Sv32) = currentlyEnabled(Ext_S) & (xlen == 32) & hartSupports(Ext_Sv32)

@jordancarlin jordancarlin added the configuration Additional configuration settings needed for the model label Apr 11, 2025
@@ -183,6 +183,18 @@
"supported" : true
},
"Svinval" : {
"supported" : false
Copy link
Collaborator

Choose a reason for hiding this comment

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

This shouldn’t be disabling Svinval.

Copy link
Collaborator

@arichardson arichardson left a comment

Choose a reason for hiding this comment

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

Comment on lines 204 to 208
function clause hartSupports(Ext_Sv39) = config extensions.Sv39.supported
enum clause extension = Ext_Sv48
function clause hartSupports(Ext_Sv48) = config extensions.Sv48.supported
enum clause extension = Ext_Sv57
function clause hartSupports(Ext_Sv57) = config extensions.Sv57.supported
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should these have an xlen check (or a configuration sanity check that gives a fatal error if you try to enable them for RV32?)? That would allow us to remove the checks lower down.

Copy link
Collaborator

Choose a reason for hiding this comment

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

They should definitely check xlen, similar to sv32.

We probably need a whole new file/function that checks for illegal configurations since there a number of other extensions that have the same issue. I’d hold off on that part in this PR.

Copy link
Collaborator

@jordancarlin jordancarlin left a comment

Choose a reason for hiding this comment

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

Looks great!

@jordancarlin jordancarlin added the will be merged Scheduled to be merged in a few days if nobody objects label Apr 15, 2025
Copy link
Collaborator

@Timmmm Timmmm left a comment

Choose a reason for hiding this comment

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

LGTM. The only other thing I wonder is if we should enforce that Sv48 depends on Sv39 and Sv57 depends on Sv48? E.g. you can't just enable Sv57.

@jordancarlin
Copy link
Collaborator

LGTM. The only other thing I wonder is if we should enforce that Sv48 depends on Sv39 and Sv57 depends on Sv48? E.g. you can't just enable Sv57.

True, and maybe that is the easiest way for now.

@Timmmm Timmmm added tgmm-agenda Tagged for the next Golden Model meeting agenda. and removed will be merged Scheduled to be merged in a few days if nobody objects labels Apr 16, 2025
@Timmmm
Copy link
Collaborator

Timmmm commented Apr 28, 2025

Discussed in the meeting. We think we're going to eventually have a config validation function to check you don't enable Sv57 without Sv48 etc. so this is fine.

@Timmmm Timmmm added the will be merged Scheduled to be merged in a few days if nobody objects label Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
configuration Additional configuration settings needed for the model tgmm-agenda Tagged for the next Golden Model meeting agenda. will be merged Scheduled to be merged in a few days if nobody objects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configuration of supported SATP Virtual Memory modes
5 participants