Skip to content

hptw: don't set A/D on leaf PTEs with reserved PBMT, NAPOT or bits 60:54 - #1938

Closed
davidharrishmc wants to merge 2 commits into
openhwfoundation:mainfrom
davidharrishmc:dh/hptw-reserved-pte-ad
Closed

davidharrishmc wants to merge 2 commits into
openhwfoundation:mainfrom
davidharrishmc:dh/hptw-reserved-pte-ad

Conversation

@davidharrishmc

Copy link
Copy Markdown
Contributor

With menvcfg.ADUE=1, the page-table walker decided whether to update A/D with its own copy of the leaf checks (OtherPageFault in hptw.sv). That copy lacked tlbcontrol's BadPBMT, BadNAPOT and BadReserved. A store through a leaf PTE with any of these therefore had A and D written to the PTE before the store page fault:

  • PBMT=3;
  • PBMT≠0 while menvcfg.PBMTE=0;
  • N=1 with a reserved NAPOT encoding;
  • any of bits 60:54 set.

The privileged spec stops translation with a page fault at step 3 for these encodings, before the A/D update, and D updates must be exact.

This adds the three checks to the walker. They are computed from its PTE and only gate HPTWUpdateDA. A module shared with tlbcontrol was deferred, because tlbcontrol works on the TLB's compressed entry bits on the hit path.

The new self-checking test hptwReservedAD checks:

  • each reserved case takes a store page fault with the right mtval and leaves the PTE unchanged;
  • legal PTEs, including PBMT=NC with PBMTE=1, still get A and D.

It fails on main, and ImperasDV flags the PTE readback there; with the fix it passes with 0 mismatches.

Found while reviewing #1924/#1931/#1932, which share the root cause: the walker's checks and controls drift from the TLB's. Related to #1921.

🤖 Generated with Claude Code

With menvcfg.ADUE=1 the walker decided whether to update A/D from its own
copy of the leaf checks, which lacked tlbcontrol's BadPBMT, BadNAPOT and
BadReserved.  A store through a leaf with PBMT=3, PBMT!=0 while
menvcfg.PBMTE=0, N=1 with a reserved napot encoding, or a bit in 60:54
set therefore had A and D written to the PTE before tlbcontrol raised the
store page fault.  The translation algorithm stops at step 3 for these
encodings, before the A/D update in step 9, and D updates must be exact.

Add the three checks to the walker's OtherPageFault, using the PTE it
read.  The remaining leaf page-fault conditions in tlbcontrol (V, R/W
reserved encoding, U/SUM privilege, R/W/X permission, misaligned
superpage, non-canonical VA) were already checked by the walker.

A module shared by tlbcontrol and hptw is deferred: tlbcontrol sees the
compressed TLB entry bits (one OR of bits 60:54) on the TLB-hit path and
is parameterized for ITLB/DTLB, so sharing more than these three lines
would mean restructuring both.  This is a targeted fix.

hptwReservedAD checks that each reserved case takes a store page fault
and leaves the PTE unchanged, and that legal PTEs (including PBMT=NC with
PBMTE=1) still get A and D.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: David Harris <David_Harris@hmc.edu>
testbench/tests.vh was removed by openhwfoundation#1895; hptwReservedAD now runs from tests/coverage.

Signed-off-by: David Harris <David_Harris@hmc.edu>
@rosethompson

Copy link
Copy Markdown
Contributor

Is this PR no longer needed after the merge of PR #1916?

@davidharrishmc

Copy link
Copy Markdown
Contributor Author

Redundant after 1916.

rosethompson pushed a commit that referenced this pull request Oct 19, 2026
#1916 stopped the page table walker from setting A/D on leaf PTEs with
reserved encodings, but added no test.  hptwReservedAD (from the closed
#1938) stores through leaves with PBMT=3, PBMT!=0 while menvcfg.PBMTE=0,
a reserved NAPOT encoding and bit 54 set, and checks each takes a store
page fault with the PTE unchanged, while legal PTEs still get A and D.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: David Harris <David_Harris@hmc.edu>
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.

2 participants