Skip to content
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

platform: extend the way pages are identified for validation/invalidation #461

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

msft-jlange
Copy link
Contributor

SNP validates pages by virtual address while TDX validates pages by physical address. This PR makes it possible for code to request validation changes based on either. This ensures that virtual mappings are not created unnecessarily on platforms that do not require them, and ensures that it can be possible to correctly obtain the physical address for validation in those cases where the caller has only a virtual address.

@msft-jlange
Copy link
Contributor Author

@peterfang This should resolve the challenges you had in implementing validation for the TDP platform.

@peterfang
Copy link
Contributor

@peterfang This should resolve the challenges you had in implementing validation for the TDP platform.

Thanks! Will update my stage2 PR after this is merged.

kernel/src/mm/pagetable.rs Outdated Show resolved Hide resolved
kernel/src/mm/pagetable.rs Outdated Show resolved Hide resolved
kernel/src/mm/pagetable.rs Outdated Show resolved Hide resolved
kernel/src/mm/pagetable.rs Show resolved Hide resolved
kernel/src/platform/mod.rs Show resolved Hide resolved
kernel/src/stage2.rs Outdated Show resolved Hide resolved
In general, page validation should be performed by physical address,
which is required on certain platforms; platforms that require
validation by virtual address can create a temporary virtual mapping to
describe the physical page being validated.  However, in certain
contexts (like stage2), temporary mapping is not possible, and the pages
to be validate already have virtual mapping, so a mechanism to validate
by virtual address is retained solely for use in those limited cases
where a virtual mapping already exists in such a restricted context.

Signed-off-by: Jon Lange <[email protected]>
All processors that support virtualization also support NX.  Therefore,
there is no reason to detect NX via CPUID, and EFER.NXE can be enabled
very early in boot, unconditionally, for simplicity in managing page
tables.

Signed-off-by: Jon Lange <[email protected]>
kernel/src/mm/pagetable.rs Outdated Show resolved Hide resolved
@msft-jlange msft-jlange force-pushed the page_validate branch 2 times, most recently from 37a96b3 to 2b47b08 Compare September 23, 2024 16:48
It is possible to insert a reference to the current page table into the
page table itself, creating a recursive "self-map".  This permits access
to any PTE in the address space by taking advantage of the hierarchical
property of page tables, using the CPU's own page table walker to obtain
the PTE contents.  This change inserts a self-map entry into every page
table, and reimplements `virt_to_phys()` to use the self map so that it
is possible to translate any VA to a PA without requiring either the VA
or the PA to be within the bounds of any known address range.

Signed-off-by: Jon Lange <[email protected]>
Some platforms will require translation from virtual to physical address
in order to perform page validation by virtual address.  Therefore, on
other platforms, force a call to `virt_to_phys()` in debug builds to
increas the number of test environments that can detect possible
translation failures to add in debugging.

Signed-off-by: Jon Lange <[email protected]>
@joergroedel
Copy link
Member

These changes break boot for me, I need to investigate before this can be merged.

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.

4 participants