Skip to content

patina_internal_cpu: Update Paging API to Always Return Cache Attrs - #984

Merged
os-d merged 1 commit into
OpenDevicePartnership:mainfrom
os-d:mtrr_fix
Oct 31, 2025
Merged

os-d merged 1 commit into
OpenDevicePartnership:mainfrom
os-d:mtrr_fix

Conversation

@os-d

@os-d os-d commented Oct 29, 2025

Copy link
Copy Markdown
Contributor

Description

Currently patina_internal_cpu will not return MTRR cache attributes if a page is unmapped; it will simply return an error. However, the GCD code needs to send the cache attribute changed event to MpDxe to wake up the APs and sync MTRRs whenever the cache attributes change. The GCD took the approach of always sending the event when a page was unmapped and is getting mapped; that resulted in large numbers of the event getting fired, each having to wake up the APs.

This changes the patina_internal_cpu API to return the cache attributes if covered by MTRRs even when the page is unmapped. For ARM64, where the cache attributes are entirely contained within the page table and the MP code starts cores fresh every time with the BSP page table, so syncing is not required, cache attributes will never be returned if the page is unmapped.

This greatly reduces the number of times the event is fired to only the times it needs to.

This PR also updates to paging v10, which just included a breaking change to update the API to not use a custom Result type.

Closes #899 .

  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

How This Was Tested

Tested booting Q35, SBSA, and a physical Intel platform to Windows and observing the number of cache attribute change events decreasing (on Q35 from 403 -> 2).

Integration Instructions

N/A.

@os-d

os-d commented Oct 29, 2025

Copy link
Copy Markdown
Contributor Author

Note, CI will fail until OpenDevicePartnership/patina-paging#137 is merged and released.

@makubacki makubacki added the type:bug Something isn't working label Oct 30, 2025
@codecov

codecov Bot commented Oct 30, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 13.04348% with 40 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
patina_dxe_core/src/gcd/spin_locked_gcd.rs 0.00% 28 Missing ⚠️
core/patina_internal_cpu/src/paging/x64.rs 33.33% 12 Missing ⚠️

📢 Thoughts on this report? Let us know!

@os-d

os-d commented Oct 30, 2025

Copy link
Copy Markdown
Contributor Author

@cfernald @makubacki @Javagedes do you want to take one more look? I realized that on ARM64, where the paging attributes are always controlled by the page table (and where this event is not needed at all) we would fire the event every time we map a page because we would see unmapped and None for cache attributes.

So, I refactored the return type to be a CacheAttributeValue enum that tells us whether the attributes are Valid (and what they are), Unmapped, or NotSupported. In the case of NotSupported, we won't needlessly fire the event.

Comment thread core/patina_internal_cpu/src/paging.rs Resolved
Currently patina_internal_cpu will not return MTRR cache attributes
if a page is unmapped; it will simply return an error. However,
the GCD code needs to send the cache attribute changed event to
MpDxe to wake up the APs and sync MTRRs whenever the cache attributes
change. The GCD took the approach of always sending the event when
a page was unmapped and is getting mapped; that resulted in large
numbers of the event getting fired, each having to wake up the APs.

This changes the patina_internal_cpu API to return the cache attributes
if covered by MTRRs even when the page is unmapped. For ARM64, where
the cache attributes are entirely contained within the page table and
the MP code starts cores fresh every time with the BSP page table, so
syncing is not required, cache attributes will never be returned if the
page is unmapped.

This greatly reduces the number of times the event is fired to only the
times it needs to.

This PR also updates to paging v10, which just included a breaking
change to update the API to not use a custom Result type.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
@os-d
os-d enabled auto-merge (rebase) October 31, 2025 16:40
@os-d
os-d merged commit 3d945bf into OpenDevicePartnership:main Oct 31, 2025
@os-d
os-d deleted the mtrr_fix branch October 31, 2025 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Frequent MTRR updates on QEMU Q35

4 participants