opentitan icon indicating copy to clipboard operation
opentitan copied to clipboard

[prim] prim_reqack and dv push-pull agent

Open tjaychen opened this issue 5 years ago • 28 comments

I've noticed something interesting while hooking up the prim_reqack module to keymgr's edn interface.

  1. The prim_reqack module's destination facing req drops one cycle after the ack is asserted. This is intended behavior.
  2. The dv behavior for the push pull agent only keeps the data valid during this single cycle ack. Once the ack asserts and the corresponding req drops, the data returns to x.
  3. The ack seen by the source domain happens a few cycles later as expected.

The problem that comes up because of this is the source domain does not see the associated data sent along with the reqack since by the time the ack shows up in the source domain the data is long gone.

The simple answer is that logic outside the reqack should capture the data based on the destination side handshake, and this indeed passes the push-pull agent.

The reality of how this behaves though is a bit varied. For example otp_ctrl_kdi I believe holds the output until another request shows up. Which would mean the corresponding source domain doesn't actually need to hold this data. (@msfschaffner please correct me if i'm wrong)

edn on the other hand works more like a FIFO, ie the second the ack is received it pops and jumps to a new value. In this case, we do in fact need to capture the data.

So to me this means one of two things...

  1. we can either make all design behavior consistent, ie, if we know a prim_reqack is on the other side, we don't bother holding the data on the destination side to avoid the extra flops
  2. we introduce an option into push-pull to let it know there are differences to how its data is being handled.

I think what otp and edn are doing are both valid. otp is effectively assuming the other side is async and does not make any assumptions about what module is present. While edn currently assumes the other end is definitely sync so it can reasonably behave this way and put the onus on the receiving end.

I think it's reasonable to go with option 1, especially if as discussed during other issues we're putting the onus on the end points. So that would imply the destination domain does not need to have extra flops to hold the data.

Let me know what you guys think. This isn't a huge issue either way, just potentially cost us some flops and some mismatch in block vs chip level behavior.

tjaychen avatar Dec 08 '20 04:12 tjaychen

@mwbranstad @msfschaffner @eunchan @weicaiyang @udinator @cindychip @vogelpi

tjaychen avatar Dec 08 '20 04:12 tjaychen

Adding @senelson7 to the discussion.

I would vote for option 1, and keep all the modules behaving the same. Giving the design goal to keep flop count low (feedback from bronze level), we should not add more flops for this. This requires a change for EDN to hold the data N clocks after sending the ack. I would assume the timing between req and ack to remain as current, as documented. If we can agree on what a safe value for N hold cycles is, then I think we can have a consistent solution. An EDN PR will be made when N is specified. BTW I am thinking 3 or 4 for N.

mwbranstad avatar Dec 08 '20 15:12 mwbranstad

How about making N a parameter so we don't have to determine exactly what a safe value is at this time?

senelson7 avatar Dec 08 '20 15:12 senelson7

This seems like a good suggestion. I have not looked at any implementation details yet, but most likely will just be a small counter feed into the req/ack sm.

mwbranstad avatar Dec 08 '20 15:12 mwbranstad

I would vote for option 1 too.

weicaiyang avatar Dec 08 '20 20:12 weicaiyang

I favor option 1 as well, I think standardizing this sort of behavior would be better in the long run than having to essentially toggle between two different types of behavior in the DV environments on a case-by-case basis.

udinator avatar Dec 08 '20 22:12 udinator

@msfschaffner has drawn a very nice diagram illustrating the use for prim_sync_reqack inside OTP: otp_ctrl_key_req_ack

And he also explains that "Hence, if the scrambling device clock is faster or in the same order of magnitude as the OTP clock, the data can be directly sampled upon assertion of src_ack_o. If the scrambling device runs on a significantly slower clock than OTP, an additional register (as indicated with dashed grey lines in the figure) has to be added."

Back when I implemented the prim_sync_reqack I mainly had the use case in mind when the data flows from the source to destination. In this case, no additional buffering is needed independent of the clock ratio. Also, @eunchan noted that it would be nice to have the data go through the module as well in order to waive the CDC violation inside the module (see https://github.com/lowRISC/opentitan/pull/2067#pullrequestreview-402265070). So my suggestion would be:

i) Create a new module, say prim_sync_reqack_data that uses the existing prim_sync_reqack under the hood but also can feed data through. ii) Parametrize the direction of the data flow (src -> dst, or dst->src). iii) Parametrize the addition of a flop stage on the dst clock in case the data flow from dst->src. iv) Parametrize the data width.

Holding the data for N cycles after the dst req/ack as proposed by @mwbranstad to skip the flop stage in iii) is a good idea.

vogelpi avatar Dec 09 '20 08:12 vogelpi

@vogelpi yes you're right, but the point i was trying to make was...

the DV agent for push-pull immediately x's the data after the single cycle of dest_ack_i. Which means we would need to make the push-pull agent understand there are different behaviors on this interface. Some hold the data (like otp), some do not (like edn).

What i'm saying is that we should just generalize to one direction (for example the edn approach), and this will allow us to place the capture flops directly in prim_reqack and make the behavior consistent.

Does that make sense? As is right now, I don't need flops at the chip level sim, but i need them for the block level sim, because push-pull makes a different assumption at the moment.

tjaychen avatar Dec 09 '20 18:12 tjaychen

Standardizing the behavior sounds good to me.

Especially for the interfaces under consideration (e.g. the scrambling keys going to flash are 2x128bit wide) I think it would be great if we could omit adding more flops than absolutely necessary. Hence, changing the push-pull agent to hold the data for N cycles sounds like the right way to go.

Actually, wouldn't it be enough to require that the destination keeps the data signal stable until the next request shows up? I.e., the source anyway has to wait until it receives the acknowledgement through src_ack_o until it can launch the next request...

RE @vogelpi's point, I agree that it would be good to have such an extended primitive for the sake of CDC waiving later on, even if we do not instantiate the extra register.

msfschaffner avatar Dec 10 '20 00:12 msfschaffner

yes i think hold the data until the next request shows up is also a reasonable approach. If we go that route I think otp_ctrl would be fine as is, and edn would need to modify its pop condition.

So basically there are two routes

  1. if data is only valid during the ack, then we need to add flops in prim_reqack and blocks like otp_ctrl should remove its last layer flop
  2. if data is valid until the next request, then we need to change edn such that it pops differently and also add a feedthrough path prim_reqack

I'm fine with either, with the note that the push-pull agent currently behaves like 1. Any thoughts Mark?

On Wed, Dec 9, 2020 at 4:18 PM Michael Schaffner [email protected] wrote:

Standardizing the behavior sounds good to me.

Especially for the interfaces under consideration (e.g. the scrambling keys going to flash are 2x128bit wide) I think it would be great if we could omit adding more flops than absolutely necessary. Hence, changing the push-pull agent to hold the data for N cycles sounds like the right way to go.

Actually, wouldn't it be enough to require that the destination keeps the data signal stable until the next request shows up? I.e., the source anyway has to wait until it receives the acknowledgement through src_ack_o until it can launch the next request...

RE @vogelpi https://github.com/vogelpi's point, I agree that it would be good to have such an extended primitive for the sake of CDC waiving later on, even if we do not instantiate the extra register.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/4465#issuecomment-742146574, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH2RSTVLANOB2U5DPAECKDSUAHT5ANCNFSM4URNAQ6Q .

tjaychen avatar Dec 10 '20 00:12 tjaychen

I am assuming that edn will be changed to hold the data N cycles after the ack is returned. The reason it is N cycles versus until the next request (which it could - basically a fifo pop on subsequent req) is that I thought I was told by someone that this might present a security risk holding the data on the bus that long. Since I do not claim to be a security person, I rely on the experts, but not sure that an expert recommended this or not. Anyway, N cycles should cover the hold time yet drop it off the bus fairly quickly.

mwbranstad avatar Dec 10 '20 03:12 mwbranstad

hey @mwbranstad , N cycles honestly sounds fine to me. But I think unless we change all the users of this push-pull interface to N cycles, the DV would again probably need flags to know in which situation to use which.

If we all switched to change only on req for example (and I assume this means the req causes the pop, and then on the next cycle when the new data shows the ack will inform the other end) then I think it becomes consistent across. And we don't need to necessarily have the DV-if figure out for each interface what N should be.

Regarding holding the same data on the bus... from a side channel perspective, it's the change I believe that really matters. So if we are holding the same static value, that doesn't cause much extra leakage.

One could argue for probing security, leaving the value on the bus is more vulnerable to probing... but I think unless we continually popped (regardless of requests every N cycles), we will always have a period in between requests where the line is static right? (please correct me if I am wrong). So IMO we don't need to worry too much about this.

The physical probing thing however is real, but we need to address that in a more macro way and not at the moment place too much burden on the individual modules.

tjaychen avatar Dec 11 '20 20:12 tjaychen

hey @tjaychen I have just completed a new implementation for N cycles that is running CI checks now. Having said that, I think the design can easily be tweaked to hold data until the next request. Please take a moment for your preference based on the options, and then I can implement either flavor. I am pretty neutral on this one.

mwbranstad avatar Dec 11 '20 20:12 mwbranstad

One important note: if the requesting side has back to back requests, the acking side MUST wait N cycles before servicing the next request or we will have the same failing case. Because of this, I think we need to define N cycles for this protocol.

mwbranstad avatar Dec 11 '20 22:12 mwbranstad

@mwbranstad thanks! but wouldn't that be an argument FOR pop-on-req? Because the pop-on-req would be able to handle back to back fairly quickly right?

I feel like the main thing this boils down to is whether holding something on the bus for a long time is good / bad. If it's deemed neutral or don't care, I feel like pop-on-req might be cleaner. I can take an action to check on our end.

@udinator @weicaiyang @cindychip could you guys chime in regarding the N cycle?

tjaychen avatar Dec 11 '20 22:12 tjaychen

I was looking at the prim_sync_reqack picture. It could be that a new req to the destination device may not occur until the ack goes all the way back to the source device user logic. Without timing diagrams, I will just guess that the req will have guaranteed the N cycle hold time for the data. If this is true, then I could see a pop-on-next=req behavior as safe.

mwbranstad avatar Dec 11 '20 22:12 mwbranstad

o yes i think you're right. I do believe that was the intent of the design.

@vogelpi

tjaychen avatar Dec 11 '20 23:12 tjaychen

I am neutral to the two choices. I think either holding N cycle or holding until next data req is fine for DV.

cindychip avatar Dec 12 '20 01:12 cindychip

actually Mark based on your latest message, it sounds like we can just go with req-pop? if you can't tell, i definitely prefer that approach :)

let's give Pirmin a chance to chime in and confirm.

On Fri, Dec 11, 2020 at 6:00 PM cindychip [email protected] wrote:

I am neutral to the two choices. I think either holding N cycle or holding until next data req is fine for DV.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/4465#issuecomment-743637836, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAH2RSQ2VELR5D3OTNY4CV3SULFCPANCNFSM4URNAQ6Q .

tjaychen avatar Dec 12 '20 02:12 tjaychen

If I understand correctly, the req-pop doesn't violate req-ack protocol and we don't need to update current DV agent. Then LGTM

weicaiyang avatar Dec 12 '20 02:12 weicaiyang