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

Added support of Smepmp in Sail RISCV #196

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

Conversation

HamzaKh01
Copy link

Description

This PR includes the support of ePMP in sail risc-v. Model is verified by running the tests of ePMP (can be found here ) on the RiscOf environment which runs the tests on spike and sail and compare their signatures. So, it can be said that, this Sail model has a same behaviour for ePMP as of spike. Kindly review this PR. In addition the testplan for writting the tests is attached here

@github-actions
Copy link

github-actions bot commented Dec 15, 2022

Unit Test Results

712 tests  ±0   712 ✔️ ±0   0s ⏱️ ±0s
    6 suites ±0       0 💤 ±0 
    1 files   ±0       0 ±0 

Results for commit 3fa70d4. ± Comparison against base commit 9547a30.

♻️ This comment has been updated with latest results.

Copy link
Collaborator

@jrtc27 jrtc27 left a comment

Choose a reason for hiding this comment

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

Do you not also need 0x757 on RV32 for mseccfgh?

.gitignore Outdated Show resolved Hide resolved
model/riscv_pmp_control.sail Outdated Show resolved Hide resolved
model/riscv_pmp_control.sail Outdated Show resolved Hide resolved
model/riscv_pmp_control.sail Outdated Show resolved Hide resolved
model/riscv_pmp_control.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
@jrtc27
Copy link
Collaborator

jrtc27 commented Dec 16, 2022

You have tabs in your changes

@HamzaKh01
Copy link
Author

Should I remove tabs that are for indentation?

@jrtc27
Copy link
Collaborator

jrtc27 commented Dec 16, 2022

Yes, as documented in CODE_STYLE.md indentation is two spaces (though some places currently use 4, so divergence to match surrounding style there is fine)

@HamzaKh01
Copy link
Author

Ok, I will remove them and what about other changes are they fine, and in addition "Do you not also need 0x757 on RV32 for mseccfgh?" I will come back to you about this question a little later.

@HamzaKh01
Copy link
Author

Added 0x757 on RV32 for mseccfgh. In addition removed the tabs spaces and added two spaces for block level indentation
as mention in CODE_STYLE.md and if some seems to be tab spaces then the code has a repetitive structure and to improve readability added spaces as CODE_STYLE.md says.

Copy link

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

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

To keep a clean commit history can you remove adding the z3_problems files from the first commit instead of removing them in the second?

model/riscv_pmp_control.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
@HamzaKh01
Copy link
Author

@marnovandermaas changes you are referring to regarding the MMLcheck function are fixed in a later commit as it was used just once so removed. In addition, the formatting changes are also fixed in a later commit.

@jrtc27 @marnovandermaas To fix all problems related to formatting and functionality added that is 0x757 added later I am thinking of squashing two commits of formatting into my first commit and will separate the last commit(of 0x757 added) and its formatting too.

As a result now as a final state, We will have only two commits

  1. The First one will contain support of 0x747 with formatting done by default now
  2. The second commit will now have the support of 0x757 on RV32 for mseccfgh

Please let me know so, I do that for clean commit history.

@HamzaKh01 HamzaKh01 force-pushed the master branch 2 times, most recently from 80d2c90 to 5fe3b59 Compare January 2, 2023 08:02
@jrtc27
Copy link
Collaborator

jrtc27 commented Jan 2, 2023

No, RV32 support should be part of the first commit as without it it’s not a complete implementation

@HamzaKh01
Copy link
Author

@jrtc27 Done.

model/riscv_pmp_control.sail Outdated Show resolved Hide resolved
model/riscv_pmp_control.sail Outdated Show resolved Hide resolved
model/riscv_pmp_control.sail Outdated Show resolved Hide resolved
model/riscv_pmp_control.sail Outdated Show resolved Hide resolved
model/riscv_pmp_control.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
@HamzaKh01
Copy link
Author

No it's not

Here you are referring to outdated file, in updated it is fixed moved in a single line

@HamzaKh01
Copy link
Author

No it wouldn't. As it stands nobody reading this code has any clue what these magic sets of bits are. The whole point of the types is so that these magic bits get names that the code uses everywhere. You should only be using bitvectors when necessary, and never accessing bits within them directly.

It is fixed completely according to comments

@HamzaKh01
Copy link
Author

@jrtc27 kindly review this as soon as you get time so, I can wind this up.

@jrtc27
Copy link
Collaborator

jrtc27 commented Feb 2, 2023

No it's not

Here you are referring to outdated file, in updated it is fixed moved in a single line

No I wasn't. I opened the up to date file in a text editor before commenting. You still have trailing whitespace, one instance of which is on the line associated with that comment.

@HamzaKh01
Copy link
Author

No it's not

Here you are referring to outdated file, in updated it is fixed moved in a single line

No I wasn't. I opened the up to date file in a text editor before commenting. You still have trailing whitespace, one instance of which is on the line associated with that comment.

Fixed......... @jrtc27 Please see and let me know if everything is ok now !

@HamzaKh01
Copy link
Author

Hi @jrtc27, if everything looks ok now, Can I mention Bill and Martin? because they asked me to inform them, once everything is resolved. Thank you

model/riscv_pmp_control.sail Outdated Show resolved Hide resolved
model/riscv_pmp_control.sail Outdated Show resolved Hide resolved
model/riscv_pmp_control.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
@HamzaKh01
Copy link
Author

  • Used match instead of if else at most places now

  • Asked to add command line switch for epmp by Bill, added the switch, given table summarizes the behaviour of SAIL model

Serial no. Tests ran from ACT command line switch pmp command line switch epmp No. of tests passed No. of tests failed
1 PMP tests Off Off 7 15
2 PMP tests On Off 22 0
3 PMP tests Off On 22 0
4 PMP tests On On 22 0
5 ePMP tests Off Off 8 63
6 ePMP tests Off On 71 0
7 ePMP tests On Off ModelStuck
8 ePMP tests On On 71 0

Above table can be read as

  • As an example take entry 2, Ran PMP tests by turning on the PMP switch from command line and ePMP switch is off meanwhile, and all of the 22 tests are passing

Entry 1, 5 and 7 explanation from the table

  • If I turn off both the switches then some of the pmp tests are still passing the reason is these tests are checking maybe just the configurations set in pmpcfg csr, Switch does not prevent writing these csr it just prevent the effect of these written csr, if a test is checking maybe configuration is written properly in the csr then it is passing despite the switch being on or off (That is the behaviour of model, regarding pmp switch, that is already present)

  • In entry 5 as I added epmp switch I infered the same behaviour of model that exist for pmp switch as explained in above bullet. Some tests are passing despite switch is off because they may be checking bits that are set in mseccfg but the effect that these bits will cause is prevented because switch is off

  • In entry 7 model is stuck because i am running epmp tests by turning on pmp switch and turning off epmp switch. PMP extension does not translate the pmpcfg csr as epmp extension does and tests are written to check epmp behaviour that is why model is stuck in a test (Note it is expected behaviour)

Note

ePMP switch is superset of pmp switch as you can infer from the results in table. If ePMP switch is On pmp switch is redundant. Kindly guide me do I have interpreted the behaviour right??

Description of switch provided I will add a command line switch, "--Smepmp" that will enable the feature. Default behaviour is to NOT enable the feature. I will export a function, "haveSmepmp()", to the Sail model which will return true if the switch is set, false if it is not. You will need to enable/disable based on this function's return value. Used function haveSmepmp() in line 69 and 70 of riscv_pmp_regs.sail compiled the model multiple times with true and false output to check behaviour written in above table. One confusion is Do i have to keep lines 69 and 70 of riscv_pmp_regs.sail because for the moment I do not have the function haveSmepmp() it will not compile without it. because I have used that at numerous places

Both pmp and epmp tests are not merged in the ACT repo, they are for the time being just PR's

@allenjbaum
Copy link
Collaborator

allenjbaum commented Feb 14, 2023 via email

@billmcspadden-riscv
Copy link
Collaborator

billmcspadden-riscv commented Feb 14, 2023 via email

@jjscheel jjscheel mentioned this pull request Mar 16, 2023
13 tasks
model/riscv_mem.sail Outdated Show resolved Hide resolved
model/riscv_pmp_control.sail Outdated Show resolved Hide resolved
model/riscv_pmp_control.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
@allenjbaum
Copy link
Collaborator

allenjbaum commented Apr 25, 2023 via email

@ptomsich
Copy link
Collaborator

I am confused by the history on this PR:

  • The original author states "This is added temporarily and will not be the part of the final implementation. Just for checking purposes."
  • Allen raises a point regarding dependencies and interactions with other extensions that has not been addressed.

Is this PR final or should it have been marked as DRAFT?

@ptomsich ptomsich added the tgmm-agenda Tagged for the next Golden Model meeting agenda. label May 29, 2023
@HamzaKh01 HamzaKh01 closed this Jul 28, 2023
@HamzaKh01 HamzaKh01 force-pushed the master branch 2 times, most recently from 35e0983 to ae905fb Compare July 28, 2023 13:29
@HamzaKh01 HamzaKh01 reopened this Jul 28, 2023
@HamzaKh01
Copy link
Author

This: Surely you can't have Smepmp without the base PMP? That is, surely haveSmepmp should imply plat_enable_pmp and thus be redundant? is an interesting point - does Smepmp require PMP, or does Smepmp imply PMP? - from the point of view of Sail. Another way of looking at this is: should Sail assume that configurations passed in are legal, or must it check they are legal? havePMP and have_SmePMP are passed into Sail - should Sail assume that the combination have_SmePMP & !have_PMP will never passed in? If so, then perhaps the answer is that there is a separate checking stage, and when you get to this code, it is known that illegal combination can't happen. The next question is whether this separate checking stage is in Sail or separate from it (e.g. the riscv-config tool that was designed to explicitly check for this) That would mean that Sail can use imply rather than require, which I think is what Krste has stated in other discussions, e.g. RV32IMAFD is redundant, because RV32IMAD implies the F. How is this handled for F and D extensions in Sail?

Surely all your concerns will not arise because we are not supporting the Smepmp switch at the moment now. The switch implementation is taking too long and this PR seems to be stalled despite being functionally correct. The way it will work now is, if pmp is enabled and mseccfg(CSR of Smepmp extension) is used then PMP permissions will behave as ePMP.

@HamzaKh01
Copy link
Author

  • The original author states "This is added temporarily and will not be the part of the final implementation. Just for checking purposes."

For your context this PR was originally prepared to add just support for Smepmp extension. Later I was asked to modify the implementation to support as if it is controlled by the command line switch and I was just using API of that switch and compiling with true and false values to check my implementation not passing any value from command line and I was suppose to get this implementation of switch. That is why I said it is temporary thing because I have to define the variable to some value (True or False) otherwise build will fail.

Allen raises a point regarding dependencies and interactions with other extensions that has not been addressed.

I have addressed that in an above comment.

Is this PR final or should it have been marked as DRAFT?

Yes, it is final. The reason why I have taken back switch implementation from this is here . Can you please review it or ask someone, if any feedback comes I will fix appropriately.

@UmerShahidengr
Copy link

@billmcspadden-riscv are you merging this PR in today's meeting? If no, then what deliverables are still required from our side. By looking at the latest comments of @HamzaKh01, this PR has no dependencies with switch implementation so it can be merged right away.

@UmerShahidengr
Copy link

UmerShahidengr commented Aug 1, 2023

Since this PR is the part of an SoW submitted at DevPartners and it is also getting tracked here. @jjscheel and I are also interested in closing this PR soon as we have been waiting ro complete this work for last 7 months.

Copy link

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

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

I added some comments throughout the code. I'm afraid that this PR is not ready for merging as it is. My main concern is that I believe that pmpCheckPerms is not correctly implemented for MML.

model/riscv_pmp_control.sail Outdated Show resolved Hide resolved
model/riscv_pmp_control.sail Show resolved Hide resolved
model/riscv_pmp_control.sail Show resolved Hide resolved
model/riscv_pmp_control.sail Show resolved Hide resolved
model/riscv_pmp_control.sail Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Outdated Show resolved Hide resolved
model/riscv_pmp_regs.sail Show resolved Hide resolved
model/riscv_pmp_regs.sail Show resolved Hide resolved
@HamzaKh01
Copy link
Author

I added some comments throughout the code. I'm afraid that this PR is not ready for merging as it is. My main concern is that I believe that pmpCheckPerms is not correctly implemented for MML.

I have replied to each comment separately and I believe pmpCheckPerms is correctly implemented for MML. I have noted your suggestions for adding comments in new line and adding some comments in code. Waiting for any other feedback from others will push the feedback fixes once review settles.

Copy link

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

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

Thanks for your clarifications on pmpCheckPerms. I added a few more comments.

model/riscv_pmp_control.sail Show resolved Hide resolved
model/riscv_pmp_control.sail Show resolved Hide resolved
model/riscv_pmp_control.sail Show resolved Hide resolved
model/riscv_pmp_regs.sail Show resolved Hide resolved
@HamzaKh01
Copy link
Author

I think writing to MSECCFG should be part of this PR, but we should not be hardcoding that we only have 16 PMP registers.

Yes, you are right, but currently we only have 16 pmpcfg entries defined in the model. So, I am not hard-coding this to 16. Model has only the capability of adding up to 16 regions. If regions are increased up to 64 later only then this check can check 64 entries lock. I have still not understood your comment about how i avoid hard-coding up to 16 regions. The only solution which exists is to add support for up to 64 regions by increasing pmpcfg entries from 16 to 64 in the model as far as I know.

@allenjbaum
Copy link
Collaborator

This is a case where we need to add a command line (or YAML) parameter that indicates whether the DUT has 0, 16, or 64 PMP entries. This is going to permeate the existing PMP code, so it should be done as a separate PR

@HamzaKh01
Copy link
Author

Yes, agreed.

@billmcspadden-riscv billmcspadden-riscv removed the tgmm-agenda Tagged for the next Golden Model meeting agenda. label Oct 31, 2023
@billmcspadden-riscv
Copy link
Collaborator

I've added the command line support for Smepmp. You can find my code on the
branch, haveSmepmp_billmcspadden (https://github.com/riscv/sail-riscv/tree/haveSmepmp_billmcspadden),
in the sail-riscv repo.

The command line switch is: --enable-Smepmp
The Sail functional interface is: bool haveSmepmp()

I would suggest that you merge my code onto your branch and make
a unified PR that incorporates both my code and yours.

@KotorinMinami
Copy link
Contributor

@HamzaKh01
So, it's been 5 months since this project and still no further progress? If it's possible flower, could you let me integrate these code correspondences and resolve the conflicts? My latest work may be related to the mseccfg register.

Copy link

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

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

Thanks for putting these changes together. We have used this to check the Smepmp behavior in Ibex. I thought it would be useful to add a few changes here that we needed.

Comment on lines +103 to +105
0x747 => p == Machine, // mseccfg
0x757 => p == Machine & (sizeof(xlen) == 32), // mseccfgh

Choose a reason for hiding this comment

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

We recently used this code and needed to make the following change so that mseccfg does not exist when PMP is disabled:

diff --git a/model/riscv_sys_control.sail b/model/riscv_sys_control.sail
index c3ac1fe..e5a8cf7 100644
--- a/model/riscv_sys_control.sail
+++ b/model/riscv_sys_control.sail
@@ -50,8 +50,8 @@ function is_CSR_defined (csr : csreg, p : Privilege) -> bool =
     0x3D @ idx : bits(4) => p == Machine & sys_pmp_max_count() > unsigned(0b10 @ idx),
     0x3E @ idx : bits(4) => p == Machine & sys_pmp_max_count() > unsigned(0b11 @ idx),
 
-    0x747 => p == Machine, // mseccfg
-    0x757 => p == Machine & (sizeof(xlen) == 32), // mseccfgh
+    0x747 => p == Machine & sys_pmp_count() > 0, // mseccfg
+    0x757 => p == Machine & (sizeof(xlen) == 32) & sys_pmp_count() > 0, // mseccfgh
 
     0xB00 => p == Machine, // mcycle
     0xB02 => p == Machine, // minstret

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think that is strictly correct. You can have mseccfg without PMPs. Really we need a sys_has_mseccfg() flag or something like that, because it is optional. (As far as I remember anyway.)

Choose a reason for hiding this comment

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

I think you're right. Either way this code needs to be altered before we can merge.

Choose a reason for hiding this comment

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

For this file, we needed the following change:

diff --git a/model/riscv_pmp_control.sail b/model/riscv_pmp_control.sail
index 7cca3ba..ce3b1b0 100644
--- a/model/riscv_pmp_control.sail
+++ b/model/riscv_pmp_control.sail
@@ -139,6 +139,8 @@ function accessToFault(acc : AccessType(ext_access_type)) -> ExceptionType =
 
 function pmpCheck forall 'n, 'n > 0. (addr: int, width: int('n), acc: AccessType(ext_access_type), priv: Privilege)
                   -> option(ExceptionType) = {
+  if sys_pmp_count() == 0 then return None();
+
   foreach (i from 0 to 3) {
     let prev_pmpaddr = (if i > 0 then pmpReadAddrReg(i - 1) else zeros());
     match pmpMatchEntry(addr, width, acc, priv, pmpcfg_n[i], pmpReadAddrReg(i), prev_pmpaddr) {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm I think this is handled in phys_access_check() but maybe it makes more sense here.

Choose a reason for hiding this comment

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

Ah, then I should probably be using that function in my work as well. Thanks! This can thus be marked as resolved with relation to this PR.

@KotorinMinami
Copy link
Contributor

Perhaps we can discuss further in #601

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.

10 participants