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

MXR in effect at the effective privilege level #83

Closed
kdockser opened this issue Aug 28, 2024 · 5 comments
Closed

MXR in effect at the effective privilege level #83

kdockser opened this issue Aug 28, 2024 · 5 comments

Comments

@kdockser
Copy link

kdockser commented Aug 28, 2024

When MXR is in effect at the effective privilege mode where explicit memory access is performed, pointer masking does not apply.

Originally posted by @martinmaas in #70 (comment)

This specification text is contradicted by other changes such as the non-normative statement recently made in #82

"For the same reason, pointer masking does not apply when MXR is set."

It is also contradicted by riscv-software-src/riscv-isa-sim#1784

if (!proc || proc->get_xlen() != 64 || (proc->state.sstatus->read() & MSTATUS_MXR) || flags.hlvx)

If these contradictory statements were true, the specification text could be simplified to

When mstatus.MXR is true, pointer masking does not apply.

Which is correct?

@kdockser
Copy link
Author

To further clarify my question, what is the intention of the phrase:
at the effective privilege mode where explicit memory access is performed
In
When MXR is in effect at the effective privilege mode where explicit memory access is performed, pointer masking does not apply.

Is it implying that the implementation needs to look at the MXR for the effective privilege mode. One of:

  • mstatus.MXR
  • sstatus.MXR
  • vsstatus.MXR

Furthermore, does this MXR disabling of pointer masking extend down to U and VU mode?

kdockser referenced this issue in YenHaoChen/riscv-isa-sim Aug 29, 2024
@martinmaas
Copy link
Collaborator

Apologies for the slightly delayed response. This was a detail where there was quite a bit of iteration with the Architecture Review Committee. The intention is that whichever MXR field governs a particular memory access (if there is such a field), that MXR field is used to determine whether pointer masking applies (if MXR is set, pointer masking does not apply; if it is not set or there is no governing MXR field, pointer masking does apply).

I believe the two quotes you mentioned in your first comment are consistent and correct in this regard. However, I think the Spike implementation might be slightly incorrect – here is how MXR is determined for regular memory accesses, which I think is the same logic that pointer masking would use as well:

https://github.com/riscv-software-src/riscv-isa-sim/blob/3c5b1bb09ef6daf4146e311d1303cb8dd67c5ff3/riscv/mmu.cc#L407

I think the reason this is correct is that (IIUC) the MXR bit exposed via sstatus is the same as the one in mstatus (the privileged spec states: "The mstatus bit MXR has been exposed to S-mode via sstatus"). I therefore think it is probably correct to only look at sstatus. The case where the current Spike implementation might be incorrect is 2-stage translation, since it is not taken into account here when it should be.

Is it implying that the implementation needs to look at the MXR for the effective privilege mode.

I believe this is the case. Let me add @aswaterman @Adam-pi3 to also take a look and confirm.

@aswaterman
Copy link
Member

aswaterman commented Aug 30, 2024

This was fixed in Spike over the last few days: riscv-software-src/riscv-isa-sim#1791

@Adam-pi3
Copy link
Collaborator

Adam-pi3 commented Sep 4, 2024

I'm aligned with @martinmaas analysis.

@aswaterman
Copy link
Member

Since the Spike fix is consistent with Martin's analysis, I think we can probably close this one.

@kdockser kdockser closed this as completed Sep 5, 2024
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

No branches or pull requests

4 participants