[CI Check] ArmPkg: CpuDxe: Sync GCD Capabilities With Page Table Attributes #4311
+49
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When ArmPkg's CpuDxe driver initializes, it attempts to sync the GCD with the page table. However, unlike when the UefiCpuPkg's CpuDxe initializes, the Arm version does not update the GCD capabilities with EFI_MEMORY_[RO|RP|XP] (this could also set the capabilities to be the existing page table attributes for this range, but the UefiCpuPkg CpuDxe sets the above attributes as they are software constructs, possible to set for any memory hardware).
As a result, when the GCD attributes are attempted to be set against the old GCD capabilities, attributes that are set in the page table can get lost because the new attributes are not in the old GCD capabilities (and yet they are already set in the page table) meaning that the attempted sync between the GCD and the page table was a failure and drivers querying one vs the other will see different state. This can lead to RWX memory regions even with the no-execute policy set, because core drivers (such as NonDiscoverablePciDeviceIo, to be fixed up in a later patchset) allocate pages, query the GCD attributes, attempt to set a new cache attribute and end up clearing the XP bit in the page table because the GCD attributes do not have XP set.
This patch follows the UefiCpuPkg pattern and adds EFI_MEMORY_[RO|RP|XP] to the GCD capabilities during CpuDxe initialization. This ensures that memory regions which already have these attributes set get them set in the GCD attributes, properly syncing between the GCD and the page table.
This mitigates the issue seen, however, additional investigations into setting the GCD attributes earlier and maintaining a better sync between the GCD and the page table are being done.
Feedback on this proposal is greatly appreciated, particularly any pitfalls or more architectural solutions to issues seen with syncing the GCD and the page table.
Cc: Leif Lindholm quic_llindhol@quicinc.com
Cc: Ard Biesheuvel ardb+tianocore@kernel.org
Cc: Sami Mujawar sami.mujawar@arm.com
Cc: Michael Kubacki mikuback@linux.microsoft.com
Cc: Sean Brogan sean.brogan@microsoft.com