Skip to content

pmp: do not suppress pmpcfg writes for OFF or empty-range TOR entries under MML - #2495

Open
devtyagi3909 wants to merge 1 commit into
lowRISC:masterfrom
devtyagi3909:fix-pmp-mml-off-tor-wr-suppress
Open

devtyagi3909 wants to merge 1 commit into
lowRISC:masterfrom
devtyagi3909:fix-pmp-mml-off-tor-wr-suppress

Conversation

@devtyagi3909

Copy link
Copy Markdown

Fixes #2491

Root cause

is_mml_m_exec_cfg checked only the L bit and the {R,W,X} permission bits, ignoring the address-matching field (A). pmp_cfg.mode was explicitly silenced with a parity reduction (logic unused_cfg = ^{pmp_cfg.mode}), making the suppression blind to whether the entry actually creates a PMP rule.

This caused three classes of writes to be incorrectly suppressed under MML=1, RLB=0:

Case Write Why wrong
1 A=OFF, L=1, X=1 OFF creates no rule; nothing to suppress
2 A=NA4, G=1, L=1, X=1 NA4→OFF when G>0; same as above
3 A=TOR, L=1, X=1, pmpaddr[i-1] >= pmpaddr[i] Empty range; no rule created

The Smepmp specification (section 3.1, v20260120) restricts writes only when the resulting entry produces a valid M-mode-only or Shared-Region rule. An entry with A=OFF or an empty TOR range matches no address in any privilege mode.

Fix

is_mml_m_exec_cfg: add pmp_cfg.mode != PMP_MODE_OFF to the guard. Removes the dummy unused_cfg parity assignment. Covers cases 1 and 2.

pmp_cfg_wr_suppress: add tor_range_nonempty per-region inside the existing genvar loop:

  • Region 0: implicit TOR base is 0, so non-empty iff pmpaddr[0] != 0
  • Region i > 0: non-empty iff pmpaddr[i-1] < pmpaddr[i]

Suppression is gated on tor_range_nonempty, covering case 3.

… under MML

With mseccfg.MML=1 and mseccfg.RLB=0, is_mml_m_exec_cfg checked only the L
bit and the {R,W,X} permission bits, ignoring the A (address-matching) field.
This caused three classes of writes to be incorrectly suppressed:

1. A=OFF, L=1, X=1 -- OFF creates no PMP rule; the write must not be blocked.
2. A=NA4, G=1, L=1, X=1 -- NA4 is converted to OFF when G>0, same as above.
3. A=TOR, L=1, X=1, pmpaddr[i-1] >= pmpaddr[i] -- empty range, no rule exists.

The Smepmp specification (v20260120, section 3.1) restricts writes only when
the resulting entry would produce a valid M-mode-only or Shared-Region rule.
An entry with A=OFF or an empty TOR range matches no address in any mode and
therefore cannot grant M-mode execute access.

Fix:

- is_mml_m_exec_cfg: add pmp_cfg.mode != PMP_MODE_OFF to the guard, covering
  cases 1 and 2. The previous code silenced the unused mode field with a
  parity reduction; that dummy assignment is removed.

- pmp_cfg_wr_suppress: add a tor_range_nonempty signal, generated per-region
  inside the existing genvar loop:
    * For region 0 the implicit TOR base is 0, so the range is non-empty iff
      pmpaddr[0] != 0.
    * For region i > 0, the range is non-empty iff pmpaddr[i-1] < pmpaddr[i].
  Suppression is gated on tor_range_nonempty, covering case 3.

Fixes lowRISC#2491

Signed-off-by: Dev Tyagi <devtyagi3909@gmail.com>
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.

[pmp]: MML incorrectly suppresses pmpcfg writes for OFF and invalid TOR entries

1 participant