diff options
author | Zhiguang Liu <zhiguang.liu@intel.com> | 2024-01-04 10:37:20 +0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2024-02-22 03:28:55 +0000 |
commit | 8ccd63d14da5678a4b95df0aa954a2378355af9b (patch) | |
tree | 4d524c18a21bd8971d664844465dbfe233c780e5 | |
parent | c10e5703fece76810cad7a5c27914b545def91ff (diff) | |
download | edk2-8ccd63d14da5678a4b95df0aa954a2378355af9b.zip edk2-8ccd63d14da5678a4b95df0aa954a2378355af9b.tar.gz edk2-8ccd63d14da5678a4b95df0aa954a2378355af9b.tar.bz2 |
UefiCpuPkg: Fix issue that IsModified is wrongly set in PageTableMap
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4614
About the IsModified, current function doesn't consider that hardware
also may change the pagetable. The issue is that in the first call of
internal function PageTableLibMapInLevel, the function assume page
table is not changed, and add ASSERT to check. But hardware may change
the page table, which cause the ASSERT happens.
Fix the issue by adding addtional condition to only check if the page
table is changed when the software want to modify the page table.
Also, add more comment to explain this behavior.
Reviewed-by: Ray Ni <ray.ni@intel.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Crystal Lee <CrystalLee@ami.com.tw>
Cc: Pedro Falcato <pedro.falcato@gmail.com>
Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
-rw-r--r-- | UefiCpuPkg/Include/Library/CpuPageTableLib.h | 4 | ||||
-rw-r--r-- | UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c | 18 |
2 files changed, 16 insertions, 6 deletions
diff --git a/UefiCpuPkg/Include/Library/CpuPageTableLib.h b/UefiCpuPkg/Include/Library/CpuPageTableLib.h index cd493ad..e09fa41 100644 --- a/UefiCpuPkg/Include/Library/CpuPageTableLib.h +++ b/UefiCpuPkg/Include/Library/CpuPageTableLib.h @@ -81,7 +81,9 @@ typedef enum { Page table entries that map the linear address range are reset to 0 before set to the new attribute
when a new physical base address is set.
@param[in] Mask The mask used for attribute. The corresponding field in Attribute is ignored if that in Mask is 0.
- @param[out] IsModified TRUE means page table is modified. FALSE means page table is not modified.
+ @param[out] IsModified TRUE means page table is modified by software or hardware. FALSE means page table is not modified by software.
+ If the output IsModified is FALSE, there is possibility that the page table is changed by hardware. It is ok
+ because page table can be changed by hardware anytime, and caller don't need to Flush TLB.
@retval RETURN_UNSUPPORTED PagingMode is not supported.
@retval RETURN_INVALID_PARAMETER PageTable, BufferSize, Attribute or Mask is NULL.
diff --git a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c index 7c2bd25..6a39ac3 100644 --- a/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c +++ b/UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c @@ -294,7 +294,7 @@ IsAttributesAndMaskValidForNonPresentEntry ( Page table entries that map the linear address range are reset to 0 before set to the new attribute
when a new physical base address is set.
@param[in] Mask The mask used for attribute. The corresponding field in Attribute is ignored if that in Mask is 0.
- @param[out] IsModified TRUE means page table is modified. FALSE means page table is not modified.
+ @param[in, out] IsModified Change IsModified to True if page table is modified and input parameter Modify is TRUE.
@retval RETURN_INVALID_PARAMETER For non-present range, Mask->Bits.Present is 0 but some other attributes are provided.
@retval RETURN_INVALID_PARAMETER For non-present range, Mask->Bits.Present is 1, Attribute->Bits.Present is 1 but some other attributes are not provided.
@@ -314,7 +314,7 @@ PageTableLibMapInLevel ( IN UINT64 Offset,
IN IA32_MAP_ATTRIBUTE *Attribute,
IN IA32_MAP_ATTRIBUTE *Mask,
- OUT BOOLEAN *IsModified
+ IN OUT BOOLEAN *IsModified
)
{
RETURN_STATUS Status;
@@ -587,7 +587,10 @@ PageTableLibMapInLevel ( OriginalCurrentPagingEntry.Uint64 = CurrentPagingEntry->Uint64;
PageTableLibSetPle (Level, CurrentPagingEntry, Offset, Attribute, &CurrentMask);
- if (OriginalCurrentPagingEntry.Uint64 != CurrentPagingEntry->Uint64) {
+ if (Modify && (OriginalCurrentPagingEntry.Uint64 != CurrentPagingEntry->Uint64)) {
+ //
+ // The page table entry can be changed by this function only when Modify is true.
+ //
*IsModified = TRUE;
}
}
@@ -629,7 +632,10 @@ PageTableLibMapInLevel ( // Check if ParentPagingEntry entry is modified here is enough. Except the changes happen in leaf PagingEntry during
// the while loop, if there is any other change happens in page table, the ParentPagingEntry must has been modified.
//
- if (OriginalParentPagingEntry.Uint64 != ParentPagingEntry->Uint64) {
+ if (Modify && (OriginalParentPagingEntry.Uint64 != ParentPagingEntry->Uint64)) {
+ //
+ // The page table entry can be changed by this function only when Modify is true.
+ //
*IsModified = TRUE;
}
@@ -654,7 +660,9 @@ PageTableLibMapInLevel ( Page table entries that map the linear address range are reset to 0 before set to the new attribute
when a new physical base address is set.
@param[in] Mask The mask used for attribute. The corresponding field in Attribute is ignored if that in Mask is 0.
- @param[out] IsModified TRUE means page table is modified. FALSE means page table is not modified.
+ @param[out] IsModified TRUE means page table is modified by software or hardware. FALSE means page table is not modified by software.
+ If the output IsModified is FALSE, there is possibility that the page table is changed by hardware. It is ok
+ because page table can be changed by hardware anytime, and caller don't need to Flush TLB.
@retval RETURN_UNSUPPORTED PagingMode is not supported.
@retval RETURN_INVALID_PARAMETER PageTable, BufferSize, Attribute or Mask is NULL.
|