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

AR: Comment on unimplemented CSR behavior. #870

Merged
merged 1 commit into from
Sep 12, 2023
Merged

AR: Comment on unimplemented CSR behavior. #870

merged 1 commit into from
Sep 12, 2023

Conversation

timsifive
Copy link
Contributor

@timsifive timsifive commented Aug 22, 2023

After a very long e-mail discussion, we landed on maintaining
unimplemented CSR behavior as-is. Just add a quick note to be explicit
about that intention. The end of the discussion is basically:
1. If Sdtrig CSRs are accessed when they are not implemented or Sdtrig
   is not implemented, the hart will trap. This is to maintain backwards
   compatibility with existing implementations that use this for
   discovery.
2. If Sdext CSRs are accessed when they are not implemented, the hart
   will trap. (No need to specify behavior when Sdext is not
   implemented, because in that case Debug Mode doesn't exist and the
   CSRs aren't accessible anyway.) This is to be consistent with Sdtrig
   behavior.

@pdonahue-ventana
Copy link
Collaborator

It is my understanding that there is no requirement for any particular behavior in the (as yet undocumented) behavior on accesses to unimplemented CSRs. They no longer need to trap but they also don't need to return 0.

Consider implementation X:

  • no triggers are implemented
  • nothing ever causes an illegal instruction exception. Look at all the gates we save. And medeleg[2] can be hardwired, saving one whole flop.
  • tinfo isn't implemented. Why would we if we have no triggers and we're skimping elsewhere?
  • reads of tinfo return the value from pmpcfg4 (or whatever). That's a nearby encoding and doing this saves a gate or two on this super-cheapskate implementation.

We get to step 4 of the enumeration recipe. Reading tinfo didn't cause an exception and it returned non-zero. The recipe says to parse the read value to discover the trigger type but we're actually parsing something that's not tinfo at all. I see no possible way that this can work. While the recipe will work on sane implementations, I think the general requirement is that the debugger needs to already know what is implemented. Unified discovery or maybe reading JTAG IDCODE and looking up in some database that the debugger as access to.

I think that it might be best to leave the recipe as-is and preface it all with "If an implementation raises an illegal instruction exception on accesses to unimplemented CSRs then the enumeration recipe is below. If it does not raise illegal instruction exceptions then the enumeration method is beyond the scope of this specification." That might get the ARC's attention about their contemplated backward-incompatible change to the priv spec.

@timsifive
Copy link
Contributor Author

This version is awkward, but I dislike it less than simply removing the requirement to raise an exception, because deep down I believe that the privspec won't be changed in a way that makes discovery impossible.

Sdext.tex Outdated
Comment on lines 210 to 211
At the time of this writing the Privileged Spec says one thing, but the
maintainers are planning to change it in the next revision.
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
At the time of this writing the Privileged Spec says one thing, but the
maintainers are planning to change it in the next revision.
Privileged spec v1.12 requires accesses to unimplemented CSRs to raise illegal instruction
exceptions, though that requirement may be relaxed in later versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Sdtrig.tex Outdated
@@ -26,16 +27,18 @@ \chapter{Sdtrig (ISA Extension)}

\section{Enumeration}

\begin{steps}{Each trigger may support a variety of features. A debugger can
\begin{steps}{Each trigger may support a variety of features.
If Sdtrig is implemented or unimplemented CSRs raise an exception,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible for Sdtrig to be implemented but with zero triggers? That seems kind of silly but I think that technically somebody could claim that their zero trigger core is Sdtrig complliant. That serves no real purpose but looks slightly more impressive in marketing Powerpoint (which is slimy but technically legit). To avoid this, I think that we should have a sentence somewhere that says that an Sdtrig-compliant implementation has at least one trigger (unless I'm forgetting some Sdtrig feature other than triggers that somebody might want to implement without doing triggers). That prevents any Powerpoint ethical gray areas and also makes this sentence correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was explicitly allowed back when there was a single debug extension, to keep triggers optional. You're right that it doesn't make sense to allow Sdtrig to be implemented with 0 triggers. I support the idea, but I don't think that fits in this PR, and it's also technically backwards incompatible.

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 it's incompatible. Old implementations would have said that they do the debug spec but there was no "Sdtrig" until recently. I guess that somebody in the last year or so could have claimed Sdtrig compliance without any triggers but that seems unlikely and I don't think that adding this new requirement would require them to change anything other than some Powerpoint slides.

This is along the lines of what I was talking about last week when I suggested explicitly saying that you can do external debug without Sdtrig, but you pointed out the diagram with the dotted line around the TM.

If we don't say that Sdtrig compliance => non-zero number of triggers then I worry that this recipe doesn't work for implementations that don't get exceptions on accesses to unimplemented CSRs. (In real life, I hope that everyone gets exceptions AND has at least one trigger if they claim compliance, but in theory there's a problem.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made #872 for this.

Sdtrig.tex Outdated
Comment on lines 367 to 368
At the time of this writing the Privileged Spec says one thing, but the
maintainers are planning to change it in the next revision.
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
At the time of this writing the Privileged Spec says one thing, but the
maintainers are planning to change it in the next revision.
Privileged spec v1.12 requires accesses to unimplemented CSRs to raise illegal instruction
exceptions, though that requirement may be relaxed in later versions.

@@ -149,8 +149,8 @@
<register name="Trigger Info" short="tinfo" address="0x7a4">
This register is optional if no triggers are implemented, or if
\FcsrTdataOneType is not writable and \FcsrTinfoVersion would be 0. In
this case the debugger can read the only supported type from
\RcsrTdataOne.
this case reading this register must return 0 or raise an exception, and
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
this case reading this register must return 0 or raise an exception, and
this case reading this register must return 0 or raise an illegal instruction exception, and

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, I think that it's ambiguous whether it must (return 0 OR (exception AND debugger can ...)) vs. ((return 0 OR exception) AND debugger can ...). The comma might be intended to help but it's not obvious to me until I think about it some more. Maybe two sentences: It must return 0 or exception. If either of those happen then the debugger can ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed about 2 sentences.

How strongly do you feel about "illegal instruction exception?" I was deliberately vague because the hypervisor extension mandates that CSRs that appear not to exist to a guest must raise a virtual instruction exception. But maybe we should just ignore that possibility, because I bet there are other places in the spec where we don't think about that scenario.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure, we can leave the type of exception off if you want. That requires the reader to figure it out but it's not rocket science. It's not like any sane reader would expect a page fault.

timsifive added a commit that referenced this pull request Aug 30, 2023
Based on discussion in #870, where Paul mentioned:
> I don't think that it's incompatible. Old implementations would have
> said that they do the debug spec but there was no "Sdtrig" until
> recently. I guess that somebody in the last year or so could have
> claimed Sdtrig compliance without any triggers but that seems unlikely
> and I don't think that adding this new requirement would require them to
> change anything other than some Powerpoint slides.
@timsifive
Copy link
Contributor Author

I'm putting this on hold, because now maybe ARC is going to allow the original phrasing where unimplemented CSRs raise an exception.

After a very long e-mail discussion, we landed on maintaining
unimplemented CSR behavior as-is. Just add a quick note to be explicit
about that intention. The end of the discussion is basically:
1. If Sdtrig CSRs are accessed when they are not implemented or Sdtrig
   is not implemented, the hart will trap. This is to maintain backwards
   compatibility with existing implementations that use this for
   discovery.
2. If Sdext CSRs are accessed when they are not implemented, the hart
   will trap. (No need to specify behavior when Sdext is not
   implemented, because in that case Debug Mode doesn't exist and the
   CSRs aren't accessible anyway.) This is to be consistent with Sdtrig
   behavior.
@timsifive timsifive changed the title AR: Can't require exception for CSR access. AR: Comment on unimplemented CSR behavior. Sep 11, 2023
Copy link
Collaborator

@pdonahue-ventana pdonahue-ventana left a comment

Choose a reason for hiding this comment

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

I am somewhat concerned that a subset of AR people think this is fine (per email discussions) but that others will disagree. But let's move forward with this. We're 100% compatible with the current priv spec and 1.13 is somewhat speculative.

@timsifive timsifive merged commit 27d6029 into master Sep 12, 2023
1 check passed
@timsifive timsifive deleted the exception branch September 12, 2023 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants