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

[sival,kmac] Add kmac_error_conditions_test #24765

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

Conversation

nasahlpa
Copy link
Member

@nasahlpa nasahlpa commented Oct 10, 2024

This adds the new kmac_error_conditions_test test that is defined in the chip_sw_kmac_error_conditions chip level test.

@nasahlpa nasahlpa force-pushed the chip_sw_kmac_error_conditions branch 2 times, most recently from e8c149d to 2f957c2 Compare October 10, 2024 15:56
@nasahlpa
Copy link
Member Author

@vogelpi the test for the ErrWaitTimerExpired and ErrIncorrectEntropyMode is not working on the CW310 FPGA as we turn by default the masks off. I've marked the test as broken and referenced to #15530. Is this OK for you?

@nasahlpa nasahlpa force-pushed the chip_sw_kmac_error_conditions branch 2 times, most recently from 281e16c to 0134925 Compare October 11, 2024 06:33
@nasahlpa nasahlpa marked this pull request as ready for review October 17, 2024 05:27
@nasahlpa nasahlpa requested a review from a team as a code owner October 17, 2024 05:27
@nasahlpa nasahlpa requested review from HU90m, vogelpi and engdoreis and removed request for a team and HU90m October 17, 2024 05:27
/*processed=*/NULL, /*capacity=*/NULL);

// It is OK to get kDifError at this point because of possible timeout.
CHECK(res == kDifOk || res == kDifError);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit.

Suggested change
CHECK(res == kDifOk || res == kDifError);
TRY_CHECK(res == kDifOk || res == kDifError);


// Check if there is a new error.
bool irq_err_pending;
CHECK_DIF_OK(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
CHECK_DIF_OK(
TRY(

if (irq_err_pending) {
dif_kmac_error_t err_status;
uint32_t err_info;
CHECK_DIF_OK(dif_kmac_get_error(&kmac, &err_status, &err_info));
Copy link
Contributor

Choose a reason for hiding this comment

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

This would apply to the others below.

Suggested change
CHECK_DIF_OK(dif_kmac_get_error(&kmac, &err_status, &err_info));
TRY(dif_kmac_get_error(&kmac, &err_status, &err_info));

@nasahlpa
Copy link
Member Author

Thanks for your review, @engdoreis! As suggested, I've changed CHECK_DIF_OK to TRY.

@nasahlpa nasahlpa force-pushed the chip_sw_kmac_error_conditions branch from 0134925 to a2882d9 Compare October 21, 2024 05:45
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 PR @nasahlpa !

The test implementation looks mostly good.

Can you please elaborate on

ErrSwIssuedCmdInAppActive could not be implemented in SW as triggering a SW command while the app interface is active is not possible.

There are two error codes which we can't test related to this limitation. It would be good understand what the underlying issue is. I we agree to not test this, we should update the testplan accordingly.

Checking kmac_pkg.sv I noted there are some other currently untested error codes that we should actually be able to test:

  • ErrSwHashingWithoutEntropyReady - triggering a hash operation without setting the entropy mode first. This probably doesn't work in ROM_EXT though.
  • ErrShadowRegUpdate - triggering a shadow register update error. This should be super straight forward.

The remaining three are related to FI countermeasures and escalations. We probably can't test this using this test anyway.

sw/device/tests/BUILD Outdated Show resolved Hide resolved
sw/device/tests/kmac_error_conditions_test.c Show resolved Hide resolved
Comment on lines +220 to +537
* the KMAC block. Note that this test is not exhaustive, i.e., the test does
* not trying to reach the ErrorSoftwareCommandSequence error state from each
* other state.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the comment, I think this is okay but maybe it would be good for someone from the SiVal team to confirm @luismarques , @engdoreis ?

sw/device/tests/kmac_error_conditions_test.c Outdated Show resolved Hide resolved
@nasahlpa nasahlpa force-pushed the chip_sw_kmac_error_conditions branch from a2882d9 to 3517dc9 Compare November 6, 2024 19:10
@nasahlpa nasahlpa marked this pull request as draft November 6, 2024 20:04
Copy link
Contributor

@engdoreis engdoreis left a comment

Choose a reason for hiding this comment

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

Thanks @nasahlpa for the PR, You are using the mmio API on the test code to change the registers directly, isn't it worth creating DIFs to abstracts these registers access

sw/device/tests/kmac_error_conditions_test.c Outdated Show resolved Hide resolved

// Check whether the KMAC ERR bit was set in the interrupt state register.
TRY(dif_kmac_has_error_occurred(kmac, &error));
CHECK(error, "No error was triggered.");
Copy link
Contributor

Choose a reason for hiding this comment

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

This applies throughout this file.

Suggested change
CHECK(error, "No error was triggered.");
TRY_CHECK(error, "No error was triggered.");

Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I see, the difference between CHECK and TRY_CHECK is that the former aborts the test and the latter continues but returns a status_t? Wouldn't it be better to abort the test (so using CHECK)?

sw/device/tests/kmac_error_conditions_test.c Outdated Show resolved Hide resolved
sw/device/tests/kmac_error_conditions_test.c Outdated Show resolved Hide resolved
sw/device/tests/kmac_error_conditions_test.c Outdated Show resolved Hide resolved
sw/device/tests/kmac_error_conditions_test.c Outdated Show resolved Hide resolved
sw/device/tests/kmac_error_conditions_test.c Outdated Show resolved Hide resolved
sw/device/tests/kmac_error_conditions_test.c Outdated Show resolved Hide resolved
sw/device/tests/kmac_error_conditions_test.c Outdated Show resolved Hide resolved
sw/device/tests/kmac_error_conditions_test.c Outdated Show resolved Hide resolved
@nasahlpa nasahlpa force-pushed the chip_sw_kmac_error_conditions branch 3 times, most recently from 0b55457 to ef9514c Compare November 7, 2024 13:53
This adds the new `kmac_error_conditions_test` test that is
defined in the `chip_sw_kmac_error_conditions` chip level test.

Signed-off-by: Pascal Nasahl <[email protected]>
@nasahlpa
Copy link
Member Author

nasahlpa commented Nov 7, 2024

Thanks for your review, @vogelpi and @engdoreis

I've made quite some significant changes to this PR to address your review, @vogelpi:

  • Executed the test on CW340 - this works now and the test also gets executed in CI. Thanks @jwnrt for setting this up.
  • Worked on testing ErrShadowRegUpdate. I've noticed that this ErrShadowRegUpdate (and the corresponding kDifErrorShadowRegisterUpdate) is never used in HW and SW. Instead, according to the documentation, a shadow register update error is indicated by a recoverable alert. I've added a test to test whether the HW complies to the documentation. Do we want to remove ErrShadowRegUpdate and kDifErrorShadowRegisterUpdate from the HW and software in a separate PR?
  • Implemented the ErrSwIssuedCmdInAppActive test.
  • Implemented the ErrSwPushedMsgFifo test according to the test plan.
  • Implemented the ErrSwHashingWithoutEntropyReady test.

@engdoreis I just have one question regarding the difference CHECK <-> TRY_CHECK (please see in the comment above). Regarding the DIFs, I don't think that we should add these register writes to the DIF as they are only required to trigger an error behavior. Adding them could cause some unintended misuse by others, hence, I prefer leaving it as it is.

@nasahlpa nasahlpa force-pushed the chip_sw_kmac_error_conditions branch from ef9514c to d18142a Compare November 7, 2024 13:59
@nasahlpa nasahlpa marked this pull request as ready for review November 7, 2024 13:59
@vogelpi
Copy link
Contributor

vogelpi commented Nov 7, 2024

This sounds all great, excellent work @nasahlpa !

About the ErrShadowRegUpdate error code: I see the corresponding alert condition is also signaled via STATUS register. So software will learn about having done something wrong, even if it's not via ERR_CODE register. And your test checks this which is very nice! I agree that we should remove ErrShadowRegUpdate and kDifErrorShadowRegisterUpdate from the HW and SW in a separate PR.

@vogelpi vogelpi added the CherryPick:earlgrey_1.0.0 This PR should be cherry-picked to earlgrey_1.0.0 label Nov 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CherryPick:earlgrey_1.0.0 This PR should be cherry-picked to earlgrey_1.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants