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

[hmac] Code coverage exclusions #24692

Open
martin-velay opened this issue Sep 30, 2024 · 2 comments
Open

[hmac] Code coverage exclusions #24692

martin-velay opened this issue Sep 30, 2024 · 2 comments
Assignees
Labels

Comments

@martin-velay
Copy link
Contributor

Description

Some code coverage holes should be added to the exclusion file:

  • hmac_core.sv:
    • Branch line 192 → the default case cannot be reached as all the sel_rdata possible values are explicitly specified and covered. This should be excluded.
    • Branch line 209-225 → any other value than SHA2_256/384/512 is not supposed to be programmed, otherwise an interrupt is raised. This non-existing “else” should be excluded.
  • prim_sha2.sv:
    • Branch line 124-132 → any other value than SHA2_256/384/512 is not supposed to be programmed, otherwise an interrupt is raised. This non-existing “else” should be excluded.
  • prim_sha2_pad.sv:
    • Line 120 → any other value than SHA2_256/384/512 is not supposed to be programmed, otherwise an interrupt is raised. This should be excluded.
    • Line 206 → this requires to trigger hash_start or hash_continue while SHA core is disabled and also while the state machine is in Idle mode. This is outside the specification and won’t be easy to trigger, so we may as well exclude it.
    • Line 251 → any other value than SHA2_256/384/512 is not supposed to be programmed, otherwise an interrupt is raised. This should be excluded.
    • Line 251 and 257 when shaf_rready_i is equal to 0 → The StPad80 state gets entered through the StFifoReceive state, for which hash_start_i has to be 1. Outside of prim_sha2_pad, in prim_sha2, hash_start_i == 1 causes the FIFO FSM to enter the FifoLoadFromFifo state. In this state, prim_sha2 sets prim_sha2_pad’s shaf_rready_i input to 1 (through update_w_from_fifo) whenever shaf_rvalid is set. shaf_rvalid is driven by prim_sha2_pad to constant 1 in the StPad80 state. Thus shaf_rready_i == 1’b0 cannot occur and should be excluded.
    • Line 357 → any other value than SHA2_256/384/512 is not supposed to be programmed, otherwise an interrupt is raised. This should be excluded.
    • Branch line 101-148 → any other value than SHA2_256/384/512 is not supposed to be programmed, otherwise an interrupt is raised. This should be excluded.
    • Branch line 202-326
      • StPad80 → any other value than SHA2_256/384/512 is not supposed to be programmed, otherwise an interrupt is raised. This should be excluded.
      • StLenHi and StLenLo → For the reason described above, shaf_rready_i == 1’b0 cannot occur in the StLenHi and StLenLo states. This should be excluded.
    • Branch line 348-357 → any other value than SHA2_256/384/512 is not supposed to be programmed, otherwise an interrupt is raised. This should be excluded.
@martin-velay martin-velay added this to the Earlgrey-PROD.M7 milestone Sep 30, 2024
@martin-velay martin-velay self-assigned this Sep 30, 2024
andrea-caforio added a commit to andrea-caforio/opentitan that referenced this issue Dec 18, 2024
This commit removes the coverage exclusions that were introduced as
part of the padding cancellation bug lowRISC#23936 that was fixed in the
previous commit. New exclusions are added that cover some impossible
conditions and branches as identified in lowRISC#24692.

Signed-off-by: Andrea Caforio <andrea.caforio@lowrisc.org>
Co-authored-by: Martin Velay <mvelay@lowrisc.org>
andrea-caforio added a commit to andrea-caforio/opentitan that referenced this issue Dec 18, 2024
This commit removes the coverage exclusions that were introduced as
part of the padding cancellation bug lowRISC#23936 that was fixed in the
previous commit. New exclusions are added that cover some impossible
conditions and branches as identified in lowRISC#24692.

Signed-off-by: Andrea Caforio <andrea.caforio@lowrisc.org>
Co-authored-by: Martin Velay <mvelay@lowrisc.org>
@vogelpi
Copy link
Contributor

vogelpi commented Dec 20, 2024

Thanks @martin-velay for putting this together. I've started to review this when reviewing @andrea-caforio 's PR here: #25696

hmac_core.sv:

  • Branch line 192 → the default case cannot be reached as all the sel_rdata possible values are explicitly specified and covered. This should be excluded.

This one is also related to sel_rdata being a 2-bit signal (4 options) with only 3 values being defined. The default cannot be reached in simulation but synthesis won't understand this and generate the default assignment which is another, unused mux input. We should change the RTL here. And use another mux input for the default case for synthesis OR make the last statement the default (sel_rdata == SelFifo).

  • Branch line 209-225 → any other value than SHA2_256/384/512 is not supposed to be programmed, otherwise an interrupt is raised. This non-existing “else” should be excluded.

Please note that the non-existing else here is not referring to the digest size but to the hmac_en_i and sel_msglen. I agree it cannot be covered but how we usually handle this is to modify the RTL accordingly instead of adding a coverage waiver.

prim_sha2.sv:

  • Branch line 124-132 → any other value than SHA2_256/384/512 is not supposed to be programmed, otherwise an interrupt is raised. This non-existing “else” should be excluded.

I don't see an a non-existing else here. Can you please clarify what is meant?

I'll need to go through the other exclusions later.

@vogelpi
Copy link
Contributor

vogelpi commented Dec 20, 2024

prim_sha2_pad.sv

  • Line 120 → any other value than SHA2_256/384/512 is not supposed to be programmed, otherwise an interrupt is raised. This should be excluded.

This can easily be reformulated in the RTL without making anything less clear:

end else if ((digest_mode_flag_q == SHA2_384) || (digest_mode_flag_q == SHA2_512)) begin

to

end else begin // SHA2_384/SHA2_512
  • Line 206 → this requires to trigger hash_start or hash_continue while SHA core is disabled and also while the state machine is in Idle mode. This is outside the specification and won’t be easy to trigger, so we may as well exclude it.

I think I agree on that one.

Line 251 → any other value than SHA2_256/384/512 is not supposed to be programmed, otherwise an interrupt is raised. This should be excluded.

Reformulate RTL to just check for SHA2_256.

Line 251 and 257 when shaf_rready_i is equal to 0 → The StPad80 state gets entered through the StFifoReceive state, for which hash_start_i has to be 1. Outside of prim_sha2_pad, in prim_sha2, hash_start_i == 1 causes the FIFO FSM to enter the FifoLoadFromFifo state. In this state, prim_sha2 sets prim_sha2_pad’s shaf_rready_i input to 1 (through update_w_from_fifo) whenever shaf_rvalid is set. shaf_rvalid is driven by prim_sha2_pad to constant 1 in the StPad80 state. Thus shaf_rready_i == 1’b0 cannot occur and should be excluded.

I agree on that one.

  • Line 357 → any other value than SHA2_256/384/512 is not supposed to be programmed, otherwise an interrupt is raised. This should be excluded.

Reformulate RTL to just check for SHA2_256.

* Branch line 101-148  → any other value than SHA2_256/384/512 is not supposed to be programmed, otherwise an interrupt is raised. This should be excluded.

Reformulate RTL to just check for SHA2_256. Remove the default all-zero mux input for LenHi, LenLo. For Pad80 use a default which is equal to the branches above, i.e.:

          unique case (message_length_i[4:3])
            2'b 00:  shaf_rdata_o = 64'h 0000_0000_8000_0000;
            2'b 01:  shaf_rdata_o = {32'h 0000_0000, fifo_rdata_i.data[31:24], 24'h 8000_00};
            2'b 10:  shaf_rdata_o = {32'h 0000_0000, fifo_rdata_i.data[31:16], 16'h 8000};
            2'b 11:  shaf_rdata_o = {32'h 0000_0000, fifo_rdata_i.data[31: 8],  8'h 80};
            default: shaf_rdata_o = 64'h 0000_0000_8000_0000;
* Branch line 202-326
  
  * StPad80 →  any other value than SHA2_256/384/512 is not supposed to be programmed, otherwise an interrupt is raised. This should be excluded.
  * StLenHi and StLenLo → For the reason described above, shaf_rready_i == 1’b0 cannot occur in the StLenHi and StLenLo states. This should be excluded.

Agreed!

* Branch line 348-357 → any other value than SHA2_256/384/512 is not supposed to be programmed, otherwise an interrupt is raised. This should be excluded.

Reformulate RTL to just check for SHA2_256 and MultimodeEn. Actually, I don't understand how this is not covered currently. Is the case 1 || 1 for (digest_mode_flag_q == SHA2_384) || (digest_mode_flag_q == SHA2_512) not covered or which case isn't covered?

andrea-caforio added a commit to andrea-caforio/opentitan that referenced this issue Jan 3, 2025
In light of the V3 signoff, this commits adapts certain RTL parts that
induced uncoverable coverage holes. There are two types of changes:

  1. Removal of dangling else branches that are impossible to cover.
  2. Removal of uncoverable FSM default state assignments.

Both changes have no functional impact and are only cosmetic in nature
in order to attain the demanded coverage thresholds. See lowRISC#24692, for a
detailed discussion of these changes.

Signed-off-by: Andrea Caforio <andrea.caforio@lowrisc.org>
andrea-caforio added a commit to andrea-caforio/opentitan that referenced this issue Jan 3, 2025
In light of the V3 signoff, this commits adapts certain RTL parts that
induced uncoverable coverage holes. There are two types of changes:

  1. Removal of dangling else branches that are impossible to cover.
  2. Removal of uncoverable FSM default state assignments.

Both changes have no functional impact and are only cosmetic in nature
in order to attain the demanded coverage thresholds. See lowRISC#24692, for a
detailed discussion of these changes.

Signed-off-by: Andrea Caforio <andrea.caforio@lowrisc.org>
andrea-caforio added a commit to andrea-caforio/opentitan that referenced this issue Jan 3, 2025
Remove obsolete exclusions (see lowRISC#25590) and add two new exclusions
regarding uncoverable "missing else" branches (see lowRISC#24692).

Signed-off-by: Andrea Caforio <andrea.caforio@lowrisc.org>
andrea-caforio added a commit to andrea-caforio/opentitan that referenced this issue Jan 14, 2025
In light of the V3 signoff, this commits adapts certain RTL parts that
induced uncoverable coverage holes. There are two types of changes:

  1. Removal of dangling else branches that are impossible to cover.
  2. Removal of uncoverable FSM default state assignments.

Both changes have no functional impact and are only cosmetic in nature
in order to attain the demanded coverage thresholds. See lowRISC#24692, for a
detailed discussion of these changes.

Signed-off-by: Andrea Caforio <andrea.caforio@lowrisc.org>
andrea-caforio added a commit to andrea-caforio/opentitan that referenced this issue Jan 15, 2025
In light of the V3 signoff, this commits adapts certain RTL parts that
induced uncoverable coverage holes. There are two types of changes:

  1. Removal of dangling else branches that are impossible to cover.
  2. Removal of uncoverable FSM default state assignments.

Both changes have no functional impact and are only cosmetic in nature
in order to attain the demanded coverage thresholds. See lowRISC#24692, for a
detailed discussion of these changes.

Signed-off-by: Andrea Caforio <andrea.caforio@lowrisc.org>
andrea-caforio added a commit to andrea-caforio/opentitan that referenced this issue Jan 17, 2025
In light of the V3 signoff, this commits adapts certain RTL parts that
induced uncoverable coverage holes. There are two types of changes:

  1. Removal of dangling else branches that are impossible to cover.
  2. Removal of uncoverable FSM default state assignments.

Both changes have no functional impact and are only cosmetic in nature
in order to attain the demanded coverage thresholds. See lowRISC#24692, for a
detailed discussion of these changes.

Signed-off-by: Andrea Caforio <andrea.caforio@lowrisc.org>
andrea-caforio added a commit to andrea-caforio/opentitan that referenced this issue Jan 20, 2025
In light of the V3 signoff, this commits adapts certain RTL parts that
induced uncoverable coverage holes. There are two types of changes:

  1. Removal of dangling else branches that are impossible to cover.
  2. Removal of uncoverable FSM default state assignments.

Both changes have no functional impact and are only cosmetic in nature
in order to attain the demanded coverage thresholds. See lowRISC#24692, for a
detailed discussion of these changes.

Signed-off-by: Andrea Caforio <andrea.caforio@lowrisc.org>
vogelpi pushed a commit that referenced this issue Jan 24, 2025
In light of the V3 signoff, this commits adapts certain RTL parts that
induced uncoverable coverage holes. There are two types of changes:

  1. Removal of dangling else branches that are impossible to cover.
  2. Removal of uncoverable FSM default state assignments.

Both changes have no functional impact and are only cosmetic in nature
in order to attain the demanded coverage thresholds. See #24692, for a
detailed discussion of these changes.

Signed-off-by: Andrea Caforio <andrea.caforio@lowrisc.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants