]> git.proxmox.com Git - mirror_edk2.git/commit
CpuPageTableLib: Fix a bug to avoid unnecessary changing to page table
authorRay Ni <ray.ni@intel.com>
Fri, 15 Jul 2022 12:40:29 +0000 (20:40 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 9 Aug 2022 07:08:05 +0000 (07:08 +0000)
commit9f53fd4ba7ac4abe82365f310e0a4bcccc4448b3
tree7d80278ed9c0a8d0db84ebc5784f8a6ec2b2d336
parentf4c845e46b3fb18a84c3f8ecfc6f2d4025c2ede1
CpuPageTableLib: Fix a bug to avoid unnecessary changing to page table

With the following paging structure that maps [0, 2G] with ReadWrite
bit set.
PML4[0] --> PDPTE[0] --> PDE[0-255]
              \-> PDPTE[1] --> PDE[0-255]

If ReadWrite bit is cleared in PML4[0] and PageTableMap() is called
to change [0, 2M] as read-only, today's logic unnecessarily changes
the paging structure in 2 aspects:
1. When setting PageTableBaseAddress in the entry, the code clears
    all attributes.
2. Even the ReadWrite bit in parent entry is not set, the code clears
    the ReadWrite bit in the leaf entry.

First change is wrong. It should not change other attributes when
setting the PA.
Second change is unnecessary. Because the parent entry already
declares the whole region as read-only, there is no need to clear
ReadWrite bit in the leaf entry again.

Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
Signed-off-by: Ray Ni <ray.ni@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
UefiCpuPkg/Library/CpuPageTableLib/CpuPageTableMap.c