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

Removed that prefetch instructions can throw exceptions #7

Merged
merged 7 commits into from
Jan 23, 2024

Conversation

francislaus
Copy link
Contributor

I removed that prefetch instructions can throw exceptions. This is in line with the Zicbop rationale on prefetch instructions:

"A cache-block prefetch instruction is permitted to access the specified cache block whenever a load instruction,
store instruction, or instruction fetch is permitted to access the corresponding physical addresses. If access to the
cache block is not permitted, a cache-block prefetch instruction does not raise any exceptions and shall not
access any caches or memory. During address translation, the instruction does not check the accessed and dirty
bits and neither raises an exception nor sets the bits."

Furthermore, I added Zicbop as a prerequisite for the two prefetch.w instructions.

@andresag01
Copy link
Collaborator

@francislaus : Thanks for PR. This issue with prefetches was discussed extensively and it was decided that it is best to prevent software from arbitrarily execute prefetch instructions without at least some minimum requirements on the authorising capability. The rationale for this is to reduce the attack surface through prefetches.

The discussion is summarised in this issue from the original CHERI technical report: CTSRD-CHERI/cheri-specification#65

I agree that the prerequisites need fixing!

@francislaus
Copy link
Contributor Author

@andresag01 Thank you for your comment. I think there might have been a misunderstanding. The PR does not intend on allowing prefetches to execute if the authorising capability does not allow. I think the way to go in this case is to make them NOPs as suggested by Jessica.

However, what my PR intends on doing is to not throw exceptions in this case. That is exactly what the (Zicboc) RISC-V spec does. It does not allow access to the cache block, but it does also not raise exceptions. I think this would be sensible because pre-fetch instructions are HINTs and can be safely ignored. I think this PR is in line with the discussion you mentioned as well as the Zicboc extension.

It would probably be useful to explain the reasoning about this in the document. Do you think it would be sensible to add a few words explaining that?

@PeterRugg
Copy link
Contributor

@andresag01 Yes, I think the discussion, and the thrust of the conclusion in that issue, was to include the metadata to allow hardware to do checks and avoid side channels, not to throw exceptions. In the last reply to that thread, you said: "Do not start the prefetch if any of the checks above fails." Prefetch instructions aren't useful if they can throw exceptions.

@andresag01
Copy link
Collaborator

@francislaus @PeterRugg : Ah right! Sorry, I misunderstood your comments (and my own meeting minutes! 🤦). In that case, the change looks good, but it would be good to clarify in the text that the refetch is not supposed to go ahead if certain checks fail -- I do not think the current text makes that clear or spells out the checks to be done. What do you think?

@PeterRugg
Copy link
Contributor

Yes, @francislaus probably has comments due to his work on side channels, but we should have a section discussing what is allowed to happen even for traditional loads and stores. It doesn't (traditionally) belong in the architecture to discuss the allowed effects on microarchitectural state, but it seems appropriate to have some text, at least as a note, indicating that memory accesses where the checks fail should not escape to the memory hierarchy. It is particularly important for prefetches though because an attacker would be able to prefetch without having to squash the exception, presumably increasing the bandwidth considerably.

@andresag01
Copy link
Collaborator

Agreed. The checks that we previously discussed are listed in the table that is being deleted; clearly these must not raise exceptions though. It would be good to keep a record of that somewhere in the text even if its a microarchitectural comment, which the RISC-V specs do have in some places.

@tariqkurd-repo
Copy link
Collaborator

I agree 100% that prefetches must not throw exceptions, this was a mistake in the specification.

Copy link
Collaborator

@tariqkurd-repo tariqkurd-repo left a comment

Choose a reason for hiding this comment

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

agreed

@tariqkurd-repo
Copy link
Collaborator

@francislaus we should conditions under which execution the prefetch executes as a NOP (tag clear, sealed, no bytes in bounds in the cache line). Can you add this text?

@francislaus
Copy link
Contributor Author

@tariqkurd-repo Sure, I am just working on it.

@francislaus
Copy link
Contributor Author

@tariqkurd-repo It is all ready for the final approval now. I have added the conditions for the prefetch to not be issued as well as a very short intro text for our rationale on that. Credit to @PeterRugg for feedback.

@andresag01
Copy link
Collaborator

andresag01 commented Jan 22, 2024

@francislaus : Thanks for the change. It looks good in my humble opinion. One minor comment I would make is that here:

This instruction does not issue a prefetch if one or more of the following conditions of cs1 are met

It might not be clear what the word "issue" means at the ISA level. I would tweak this to say something like the memory access is not "performed"...

@francislaus
Copy link
Contributor Author

@andresag01 Sounds sensible to me.

* The tag is not set
* The sealed bit is set
* No bytes of the cache line requested is in bounds
* The X permission is not set
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be <<x_perm>> to get the cross reference

* The tag is not set
* The sealed bit is set
* No bytes of the cache line requested is in bounds
* The R permission is not set
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be <<r_perm>> to get the cross reference

* The tag is not set
* The sealed bit is set
* No bytes of the cache line requested is in bounds
* The W permission is not set
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be <<w_perm>> to get the cross reference

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.

Thanks for fixing this - I agree that prefetch should not raise exceptions. LGTM with the references fixed.

@andresag01 andresag01 merged commit bfabecf into riscv:main Jan 23, 2024
1 check passed
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.

5 participants