Skip to content

[BUG] cva6_tlb: negative-half Svnapot NAPOT VPN truncation leaves stale entries #3799

Backlog

Description

@Ruak

Code of Conduct

  • I have searched the existing bug issues.
  • I am a human engaging in an interpersonal interaction. During this interaction, my words are my own and are not generated. If relevant, I provide links to my sources.

CVA6 commit affected

17e2ce1a1edbcf5f5d057b0cf108bdc19e998fbd

Bug Description

A 64 KiB Svnapot NAPOT leaf mapped in the negative canonical half can remain valid after an address-domain SFENCE.VMA / HFENCE.VVMA that targets a sub-page of the same 64 KiB region.

The stored-side VPN is truncated to VpnLen'(tags_q[i].vpn[PtLevels-1:0]) in core/cva6_mmu/cva6_tlb.sv:338, which drops vpn[3] (VA[40:39]). The flush-side comparison at :340 uses the 29-bit VA[40:12]. For VA[40:39] = 2'b11 the stored side becomes 2'b00, so only the 64 KiB base sub-page compares equal; the other 15 sub-pages do not invalidate the entry.

This follows from the masking change in #3307: the selective branch is now reachable, while the stored VPN still drops the upper two bits.

Steps to reproduce

Configuration:

  • CVA6 main at 17e2ce1a.
  • config/target/profile_rva23s64: RVH=1, SvnapotEn=1, UseSharedTlb=0.
  • Verilator 5.050 full-core testbench; a directed TLB unit test is also available.

A directed TLB test:

  1. Create a 64 KiB Svnapot NAPOT leaf in the negative canonical half.
  2. SFENCE.VMA for the 64 KiB base removes the entry (control).
  3. SFENCE.VMA for a sub-page (base+0x1000) leaves the old translation in place.
  4. With the one-line cast change, the sub-page fence removes the entry.

The same sequence reproduces in a full-core Verilator simulation (HS+VS): the VS read returns the old value after the sub-page fence, with a stale translation and tohost=1 after 35,134 cycles.

Expected behavior

The base-address fence and the sub-page fence both invalidate the NAPOT entry. After the sub-page fence, the new mapping is visible.

Observed behavior

The base-address fence is the control and passes. The sub-page fence leaves the old translation valid, so the VS read still returns the old value.

Suggested fix

-        temp_stored_vpn = CVA6Cfg.VpnLen'(tags_q[i].vpn[CVA6Cfg.PtLevels-1:0]);  // VPN2..VPN0
+        // Keep the supplementary VPN bits (VA[40:39]) on the stored side.
+        temp_stored_vpn = CVA6Cfg.VpnLen'(tags_q[i].vpn);  // VPN3..VPN0

This only affects the NAPOT branch. Positive-half mappings keep vpn[3] = 0; non-RVH and SvnapotEn=0 builds are unaffected.

Relation to other issues

Reported by Ruak (https://github.com/Ruak).

Activity

  1. added
    Component:RTL
    Type:Bug
    Status:New
    PARAM:MMU
    on Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component:RTLPARAM:MMUStatus:NewType:Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions