Skip to content

Commit fe7aafc

Browse files
committed
UefiCpuPkg/BaseRiscVMmuLib: Unset the 'valid' bit when unmapping memory
Entries with the 'valid' bit set and RWX bits cleared are considered "table entries" (non-leaves). With the page table in this state, future map operations will trigger assertions when they reach the final level, and encounter what looks like a valid non-leaf entry. Signed-off-by: Benjamin Doron <benjamin.doron@9elements.com>
1 parent b7cf7e4 commit fe7aafc

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

UefiCpuPkg/Library/BaseRiscVMmuLib/BaseRiscVMmuLib.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,18 @@ UpdateRegionMappingRecursive (
440440
}
441441

442442
EntryValue = SetPpnToPte (EntryValue, RegionStart);
443-
EntryValue = SetValidPte (EntryValue);
443+
444+
//
445+
// Unmapped memory regions must have the 'valid' bit cleared.
446+
// This is because entries with 'valid' set and RWX clear are considered as "table entries"
447+
// (non-leaves), and trigger the ASSERT above for reaching the leaf-level with a non-leaf.
448+
//
449+
if ((AttributeClearMask == PTE_ATTRIBUTES_MASK) && (AttributeSetMask == 0)) {
450+
EntryValue &= ~RISCV_PG_V;
451+
} else {
452+
EntryValue = SetValidPte (EntryValue);
453+
}
454+
444455
ReplaceTableEntry (Entry, EntryValue, RegionStart, TableIsLive);
445456
}
446457
}

0 commit comments

Comments
 (0)