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

[csrng/rtl] add reseed intervall sts err #22883

Merged

Conversation

h-filali
Copy link

@h-filali h-filali commented Apr 29, 2024

Please see the commit messages for info.

Resolves #16499

I still need to do some cleanup and debug the last part of the alert test vseq.
There seems to be an issue in DV where the wait for an acknowledgement doesn't behave as
expected.
I also need to rebase.
The first commit can be ignored since it is already merged.

@h-filali h-filali requested a review from vogelpi April 29, 2024 16:00
@h-filali h-filali force-pushed the csrng-add-reseed-intervall-sts-err branch 2 times, most recently from 156427c to 79f56a5 Compare April 30, 2024 13:05
@h-filali
Copy link
Author

@vogelpi I rebased now. I think this can be reviewed now, although I still get some failing tests. I'm working on resolving the failures.
I also removed part of the DV that doesn't need to be reviewed yet.

Copy link
Contributor

@vogelpi vogelpi 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 working on this @h-filali . There are a couple of issues in this PR I would like to discuss with you 1 by 1. Let's set up a meeting.

hw/ip/csrng/data/csrng.hjson Outdated Show resolved Hide resolved
hw/ip/csrng/data/csrng.hjson Outdated Show resolved Hide resolved
hw/ip/csrng/dv/env/csrng_scoreboard.sv Show resolved Hide resolved
hw/ip/edn/doc/registers.md Outdated Show resolved Hide resolved
Comment on lines 333 to 335
if (cmd_sts_err_q) begin
state_d = Idle;
cmd_sts_err_release = 1'b1;
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 you should only release the error when getting the ack. Right now you drop the error upon entering the CmdAck state. What's worse, cmd_sts_err_release doesn't seem to have an effect other than delaying the branch checking cmd_ack_i by one clock cycle. Does this make sense?

Copy link
Author

Choose a reason for hiding this comment

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

I changed it such that the check now happens directly in the cmd_stage. I think it should be better now.

Comment on lines -216 to +217
(cmdreq_ccmd == INS) ? {{(CtrLen-1){1'b0}},1'b1} :
(cmdreq_ccmd == RES) ? {{(CtrLen-1){1'b0}},1'b1} :
(cmdreq_ccmd == INS) ? {{(CtrLen-1){1'b0}},1'b0} :
(cmdreq_ccmd == RES) ? {{(CtrLen-1){1'b0}},1'b0} :
Copy link
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Author

Choose a reason for hiding this comment

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

As discussed in our 1:1 this is needed for the reseed_interval values to make any sense. Otherwise a value of 2 for reseed_interval would only allow 1 generate command between two reseeds (instead of two).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I agree that this makes sense.

hw/ip/csrng/rtl/csrng_pkg.sv Outdated Show resolved Hide resolved
@h-filali h-filali force-pushed the csrng-add-reseed-intervall-sts-err branch 3 times, most recently from edda763 to e2247c6 Compare April 30, 2024 19:34
Copy link
Contributor

@vogelpi vogelpi 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 the update @h-filali . This is going in the right direction but it's not yet working as expected. Please see my comments for details.

Comment on lines 879 to 885
// Set reseed_cnt_reached_d to true if the max number of generate requests between reseeds
// has been reached for the respective counter.
assign reseed_cnt_reached_d[ai] = (shid_q == ai) ?
(state_db_rd_rc == reg2hw.reseed_interval.q) :
reseed_cnt_reached_q[ai];

Copy link
Contributor

Choose a reason for hiding this comment

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

I fear this is not going to work properly when more than 1 instance is busy. Because:

  • shid_q always updates 1 cycle after acmd_sop which itself is high 1 cycle after the command stage of interest has won arbitration.
  • But inside the command stage we check reseed_cnt_reached before initiating arbitration.

As a result, the command stage might use reseed_cnt_reached of the wrong instance.

To solve this, I see the following two options:

  1. Feed the reseed counter values for all instances out of the state database to compare them to the limit "live" inside the command stage. This means you need 3 comparators instead of 1, but no muxes and no FFs. It's easy to do and will help us to with upcoming changes for M4.
  2. The check is performed upon writing to the state database instead. This has the same area requirements but there is a risk of the comparison getting out of sync when SW updates the reseed limit in the meantime.

I would go for Option 1.

Copy link
Author

Choose a reason for hiding this comment

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

There are 3 different reseed count reached values. One for each endpoint. They all start off at 0 and for them to be increased, a generate command must have been sent at some point, which means shid_q == ai must have been true at some point and the value must have been updated. I probably should have added a comment explaining this or maybe I'm missing something here. What do you think @vogelpi

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, yes thanks for clarifying. However, there is still an issue that the comparison can be out of date. What can happen:

  1. The last Generate command ends and the state database is updated.
  2. The next Generate is received, the command stage checks reseed_cnt_reached_q. It's showing value from when that reseed counter was last read, not when it was written.
  3. It's below the limit, so it's requesting arbitration.
  4. It wins arbitration, shid_q is updated and we read the state database and update reseed_cnt_reached_q.
  5. Now it reached the limit but the Generate is already in the pipeline and we will ack it at the end.

So we are doing one Generate more than we should.

Copy link
Author

Choose a reason for hiding this comment

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

I think an example for when the state is read, is for the error response or the acknowledgement. The command stage needs to read from the state db every time a command is acked, so the reseed_cnt_reached_d variables will be updated any time this happens. For a second generate to be processed, the previous one has to have read from state db first.

Copy link
Author

Choose a reason for hiding this comment

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

I'm now also convinced, that doing it on state_db writes instead of state_db reads is safer. I now changed it to writes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @h-filali !

@@ -433,13 +449,18 @@ module csrng_cmd_stage import csrng_pkg::*; #(

assign cmd_stage_ack_o = cmd_ack_q;
Copy link
Contributor

Choose a reason for hiding this comment

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

What's missing here is to also set cmd_stage_ack_o in case of cmd_err_ack. Right now, just the status is set but the ack is not going out. As a result CSRNG just sucks the command without doing anything. The app interface dies.

Copy link
Author

Choose a reason for hiding this comment

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

Ah yes totally missed that one. Let me fix that.

@h-filali h-filali force-pushed the csrng-add-reseed-intervall-sts-err branch from e2247c6 to 078f877 Compare April 30, 2024 20:39
@h-filali
Copy link
Author

@vogelpi Thanks for reviewing, I addressed your points. Hopefully this works now

@h-filali h-filali force-pushed the csrng-add-reseed-intervall-sts-err branch from 078f877 to 1ca97d0 Compare April 30, 2024 21:09
@vogelpi vogelpi self-requested a review April 30, 2024 21:12
Copy link
Contributor

@vogelpi vogelpi left a comment

Choose a reason for hiding this comment

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

This looks now good, thanks @h-filali ! Let's see what CI has to say to this :-)

@vogelpi vogelpi marked this pull request as ready for review April 30, 2024 21:18
@vogelpi vogelpi requested review from a team as code owners April 30, 2024 21:18
@vogelpi vogelpi requested review from marnovandermaas and pamaury and removed request for a team April 30, 2024 21:18
Copy link
Contributor

@marnovandermaas marnovandermaas left a comment

Choose a reason for hiding this comment

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

Looks very reasonable to me. Just a small question on the condition in which the exceeded reseed is triggered.

// has been reached for the respective counter.
assign reseed_cnt_reached_d[ai] =
state_db_wr_req && state_db_wr_req_rdy && (state_db_wr_inst_id == ai) ?
(state_db_wr_rc == reg2hw.reseed_interval.q) :
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want this to be >=? Maybe that case can be reached if we are reseeding based on a large reseed value and then when a lower reseed value is put in the reseed count is already beyond it.

Copy link
Author

@h-filali h-filali May 1, 2024

Choose a reason for hiding this comment

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

This count goes up for each generate command that is completed. When the reseed_interval is reached no further generates should be accepted. I guess we could add an assertion for that to make sure it doesn't happen. However, I already go another potential PR cooking that tests this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, it's not a huge deal. I was just thinking it might happen if your counter already has a higher value when you write your reseed interval. We can just put some text in the reseed interval register description saying you should reseed the block to guarantee the new reseed interval takes effect.

Copy link
Author

Choose a reason for hiding this comment

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

Ah now I see, thanks for clarifying. I guess I can do it in a follow up PR once this one is merged.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yup, that's fine!

@h-filali
Copy link
Author

h-filali commented May 1, 2024

Looks very reasonable to me. Just a small question on the condition in which the exceeded reseed is triggered.

Thanks @marnovandermaas for having a look!

@vogelpi
Copy link
Contributor

vogelpi commented May 2, 2024

clkmgr_jitter_test_fpga_cw310_sival_rom_ext seems to constantly and reliably timeout with this PR (but not with any others) we should probably investigate this before merging. The test itself is very simple and I suspect the test isn't even reached.

@h-filali h-filali force-pushed the csrng-add-reseed-intervall-sts-err branch from 0417776 to a9e28b6 Compare May 2, 2024 14:45
This commit adds a new status error response, that is triggered
whenever the number of generates between reseeds exceeds the
reseed_interval.

Signed-off-by: Hakim Filali <[email protected]>
@h-filali h-filali force-pushed the csrng-add-reseed-intervall-sts-err branch from a9e28b6 to 7b67a48 Compare May 2, 2024 15:00
@vogelpi vogelpi merged commit 7f84f7c into lowRISC:master May 2, 2024
32 checks passed
@vogelpi vogelpi mentioned this pull request Jun 25, 2024
@h-filali h-filali deleted the csrng-add-reseed-intervall-sts-err branch October 7, 2024 14:11
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.

[csrng] Investigate reseed interval
4 participants