Skip to content

Commit

Permalink
fix(TLB): Should check vmid when s2xlate in wbhit (#3623)
Browse files Browse the repository at this point in the history
  • Loading branch information
good-circle authored Sep 23, 2024
1 parent 478bf92 commit d6b32cb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/main/scala/xiangshan/cache/mmu/MMUBundle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class TlbSectorEntry(pageNormal: Boolean, pageSuper: Boolean)(implicit p: Parame
asid_hit && level_matchs.asUInt.andR && addr_low_hit && vmid_hit && pteidx_hit
}

def wbhit(data: PtwRespS2, asid: UInt, nSets: Int = 1, ignoreAsid: Boolean = false, s2xlate: UInt): Bool = {
def wbhit(data: PtwRespS2, asid: UInt, vmid: UInt, nSets: Int = 1, ignoreAsid: Boolean = false, s2xlate: UInt): Bool = {
val s1vpn = data.s1.entry.tag
val s2vpn = data.s2.entry.tag(vpnLen - 1, sectortlbwidth)
val wb_vpn = Mux(s2xlate === onlyStage2, s2vpn, s1vpn)
Expand All @@ -248,6 +248,7 @@ class TlbSectorEntry(pageNormal: Boolean, pageSuper: Boolean)(implicit p: Parame
val hasS2xlate = this.s2xlate =/= noS2xlate
val onlyS1 = this.s2xlate === onlyStage1
val onlyS2 = this.s2xlate === onlyStage2
val vmid_hit = Mux(hasS2xlate, this.vmid === vmid, true.B)
val pteidx_hit = MuxCase(true.B, Seq(
onlyS2 -> (VecInit(UIntToOH(data.s2.entry.tag(sectortlbwidth - 1, 0))).asUInt === pteidx.asUInt),
hasS2xlate -> (pteidx.asUInt === data.s1.pteidx.asUInt)
Expand All @@ -267,7 +268,7 @@ class TlbSectorEntry(pageNormal: Boolean, pageSuper: Boolean)(implicit p: Parame
level_matchs(i) := tag_matchs(i) || tmp_level >= (i + 1).U
}
level_matchs(Level) := tag_matchs(Level)
vpn_hit := asid_hit && level_matchs.asUInt.andR
vpn_hit := asid_hit && vmid_hit && level_matchs.asUInt.andR

for (i <- 0 until tlbcontiguous) {
index_hit(i) := wb_valididx(i) && valididx(i)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/xiangshan/cache/mmu/TLBStorage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class TLBFA(
entries(io.w.bits.wayIdx).apply(io.w.bits.data)
}
// write assert, should not duplicate with the existing entries
val w_hit_vec = VecInit(entries.zip(v).map{case (e, vi) => e.wbhit(io.w.bits.data, Mux(io.w.bits.data.s2xlate =/= noS2xlate, io.csr.vsatp.asid, io.csr.satp.asid), s2xlate = io.w.bits.data.s2xlate) && vi })
val w_hit_vec = VecInit(entries.zip(v).map{case (e, vi) => e.wbhit(io.w.bits.data, Mux(io.w.bits.data.s2xlate =/= noS2xlate, io.csr.vsatp.asid, io.csr.satp.asid), io.csr.hgatp.vmid, s2xlate = io.w.bits.data.s2xlate) && vi })
XSError(io.w.valid && Cat(w_hit_vec).orR, s"${parentName} refill, duplicate with existing entries")

val refill_vpn_reg = RegEnable(io.w.bits.data.s1.entry.tag, io.w.valid)
Expand Down

0 comments on commit d6b32cb

Please sign in to comment.