Repository navigation
Description
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
mainat17e2ce1a. 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:
- Create a 64 KiB Svnapot NAPOT leaf in the negative canonical half.
SFENCE.VMAfor the 64 KiB base removes the entry (control).SFENCE.VMAfor a sub-page (base+0x1000) leaves the old translation in place.- 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..VPN0This only affects the NAPOT branch. Positive-half mappings keep vpn[3] = 0; non-RVH and SvnapotEn=0 builds are unaffected.
Relation to other issues
- [BUG] SFENCE.VMA selective flush appears to use a stale
vaddr/ASIDselector #3307: the 2-bit*_is0flags that previously made every fence a full flush. This report is the remaining stored-VPN truncation. - [BUG] Incorrect address translation for G-stage NAPOT. #3569 / [BUG] VS-stage 64 KiB NAPOT leaf: the G-stage walk translates GPA with PPN[3:0] = 1000 instead of GVA[15:12] #3727: G-stage NAPOT translation data path; this report is about invalidation coverage, not translation.
Reported by Ruak (https://github.com/Ruak).
Activity