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

Improve Zicbom implementation. #718

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

Conversation

pmundkur
Copy link
Collaborator

@pmundkur pmundkur commented Feb 6, 2025

The bitwise check of xenvcfg.CBIE to check whether cbo.inval was enabled was incorrect, since CBIE is a four-valued setting. Specifically, it decoupled the bits in the reserved value 0b10 of CBIE.

This fixes the handling of the reserved value, and also throws an internal error when it is detected to indicate a possible bug in xenvcfg legalization.

The privilege check should extend to the hypervisor case, when two different illegal exceptions could be thrown. This check as written doesn't match the pseudo-Sail in the CMO spec, but is arguably clearer.

I've left the CBCFE handling alone, since it works for the single bit case.

I'd like to make sure that the handling of no S-mode case is correct (the pseudo-Sail in the spec doesn't seem to handle it explicitly).

Copy link

github-actions bot commented Feb 6, 2025

Test Results

392 tests  ±0   392 ✅ ±0   1m 19s ⏱️ ±0s
  1 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit e0d14c5. ± Comparison against base commit f07976f.

♻️ This comment has been updated with latest results.

@Timmmm
Copy link
Collaborator

Timmmm commented Feb 7, 2025

It wasn't incorrect. You can do anything with reserved values so I chose the (much) simpler implementation. And as you noted the legalisation prevents that value anyway (though I do like being able to detect mistakes in legalisation).

I think splitting the instructions up is probably a good idea (makes embedding in the spec nicer)... but it is definitely more complex. Let's discuss it in the meeting on Monday.

@Timmmm Timmmm added the tgmm-agenda Tagged for the next Golden Model meeting agenda. label Feb 7, 2025
@pmundkur
Copy link
Collaborator Author

pmundkur commented Feb 7, 2025

Sounds good; thanks for the review. Yeah, incorrect was probably too strong, apologies. I need to understand how we should handle reserved values; I'm not convinced we can do anything with them.

@Timmmm
Copy link
Collaborator

Timmmm commented Feb 7, 2025

Yeah I agree we don't quite have a clear strategy for reserved values.

I think we should probably have a global flag that allows two modes of operation:

  • Any reserved behaviour immediately asserts.
  • Reserved behaviour does something sensible, like a real chip would.

Let's discuss that too.

mapping encdec_cbie : cbie <-> bits(2) = {
CBIE_ILLEGAL <-> 0b00,
CBIE_EXEC_FLUSH <-> 0b01,
CBIE_RESERVED <-> 0b10,
Copy link
Contributor

Choose a reason for hiding this comment

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

How about handing the reserved value here instead?

- CBIE_RESERVED   <-> 0b10,
+ backwards 0b10 => internal_error(__FILE__, __LINE__, "reserved CBIE"),

This would allow us to remove some matches below.

(Making it impossible to set the reserved value in *envcfg would be better, but that is a bigger change.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think the encdec decoding of 10 to CBIE_RESERVED is an internal_error, so I'm not sure that's where it should be.

One of the goals of the PR was to get the privilege check in a form that can replace the pseudo-code in the Zicbom spec, and to be explicit about the handling of the reserved value there.

Afaict, the legalize_xenvcfg already make it impossible to set the reserved value.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Afaict, the legalize_xenvcfg already make it impossible to set the reserved value.

But that's the point. The architecture's WARL rules mean it is architecturally impossible to ever have a reserved value in the register. So if it does end up happing, that is an internal error / assertion failure / whatever you want to call it; it is an impossible state that does not need any architecturally-defined behaviour. Ideally that state wouldn't even be representable, e.g. by having the actual state use an enum and convert it to bits in CSRRW etc.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is a good point: the encdec should not make the reserved value representable. I'll push a fix.

CBIE_ILLEGAL <-> 0b00,
CBIE_EXEC_FLUSH <-> 0b01,
CBIE_EXEC_INVAL <-> 0b11,
backwards 0b11 => internal_error(__FILE__, __LINE__, "reserved CBIE"),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
backwards 0b11 => internal_error(__FILE__, __LINE__, "reserved CBIE"),
backwards 0b10 => internal_error(__FILE__, __LINE__, "reserved CBIE"),

Isn't it this one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops, good catch, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be nice if the type system caught this kind of mistakes...
Can a bijective mapping be expressed in Sail?

Clarify the privilege checking of xenvcfg.CBIE in cbo.inval.
The privilege check should extend to the hypervisor case, when
two possible illegal exceptions could be thrown.  This check as
written doesn't match the pseudo-Sail in the CMO spec, but is
arguably clearer.

Make sure that the reserved CBIE value is not representable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tgmm-agenda Tagged for the next Golden Model meeting agenda.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants