Skip to content

Add page attribute table support #548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

Freax13
Copy link
Member

@Freax13 Freax13 commented Apr 29, 2025

This adds support for the page attribute table MSR, and allows level 1 page table entries to have the HUGE_PAGE bit set. The HUGE_PAGE bit is used as the PAT bit to index the table for 4KiB pages.

This commit is based on #529. Following this PR, it was brought up that that PR was a breaking change because some users rely on FrameError::HugeFrame. This PR is still a breaking change, but it tries to make migrating easier for users that use this error variant.

I decided to go with Philipp's suggestion to add a is_level_1_entry parameter. I'll concede that this doesn't feel particularly clean, however callers usually already know the level of the page table entry (at least the was the case for all the callers in this crate) and having this function saves quite a lot of boilerplate (see #529 for how calling code needs to be changed without this function detecting huge pages). I tried looking through some projects on GitHub and it looks like most of them don't have support for huge pages and just panic if they encounter an error from this function. I think this is also another good reason to keep the FrameError::HugeFrame variant around because if a project ever starts to adopt huge pages, it will be very obvious where code is failing opposed to frame() silently returning a frame of the wrong size.

Cc @adavis628
Cc @ChocolateLoverRaj

Closes #538

This adds support for the page attribute table MSR, and allows level 1
page table entries to have the `HUGE_PAGE` bit set. The `HUGE_PAGE` bit
is used as the `PAT` bit to index the table for 4KiB pages.

This commit is based on rust-osdev#529. Following this PR, it was brought up that
that PR was a breaking change because some users rely on
FrameError::HugeFrame. This PR is still a breaking change, but it tries
to make migrating easier for users that use this error variant.

I decided to go with Philipp's suggestion to add a is_level_1_entry
parameter. I'll concede that this doesn't feel particularly clean,
however callers usually already know the level of the page table entry
(at least the was the case for all the callers in this crate) and
having this function saves quite a lot of boilerplate (see rust-osdev#529 for how
calling code needs to be changed without this function detecting huge
pages). I tried looking through some projects on GitHub and it looks
like most of them don't have support for huge pages and just panic if
they encounter an error from this function. I think this is also
another good reason to keep the FrameError::HugeFrame variant around
because if a project ever starts to adopt huge pages, it will be very
obvious where code is failing opposed to frame() silently returning a
frame of the wrong size.

Co-Authored-By: Alison Davis <[email protected]>
@Freax13 Freax13 requested review from phil-opp and josephlr April 29, 2025 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant