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

openhcl/loader: move snp specific pages to new vtl2 reserved region #304

Merged
merged 3 commits into from
Nov 13, 2024

Conversation

chris-oo
Copy link
Member

@chris-oo chris-oo commented Nov 12, 2024

Previously, we put some SNP specific pages into the same VTL2 config region. #265 broke SNP, because this region contains pages that cannot be zeroed, like the VMSA, CPUID pages and secrets pages.

Move those to a new region, that is marked as persisted to both kernelmode and usermode. It is unclear to me if the kernel requires that the CPUID page and secrets page are persisted, but treat them like the VMSA for now.

Fixes #295

@chris-oo chris-oo requested a review from a team as a code owner November 12, 2024 23:27
// Page indices for reserved vtl2 ranges, ranges that are marked as reserved to
// both the kernel and usermode. Today, these are SNP specific pages.
//
// TODO SNP: Does the kernel require that the CPUID and secrets pages are
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO tracked by #305.

@@ -321,6 +321,13 @@ where

offset += HV_PAGE_SIZE;

// Reserve space for the VTL2 reserved region.
let reserved_region_size = PARAVISOR_RESERVED_VTL2_PAGE_COUNT_MAX * HV_PAGE_SIZE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're reserving space on all architectures even though only SNP uses it? Is that just for simplicity?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On x64 only. But yes, it makes things simpler. I'm not too concerned about a losing a few pages, but if need be we could modify the loader so that we get these pages back, if we need to.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it just makes layout calculation more complicated. Maybe I'll fix all of it again later, but I don't think it's worth doing now.

Note that these pages were already reserved everywhere before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were they? I thought for "VSM" we didn't include the secrets page, vmsa, or cpuid pages:

pub const PARAVISOR_UNMEASURED_VTL2_CONFIG_REGION_PAGE_COUNT_VSM: u64 =
    PARAVISOR_UNMEASURED_VTL2_CONFIG_REGION_PAGE_COUNT_COMMON;
/// Size in pages for AMD SEV-SNP isolation.
pub const PARAVISOR_UNMEASURED_VTL2_CONFIG_REGION_PAGE_COUNT_SNP: u64 =
    PARAVISOR_UNMEASURED_VTL2_CONFIG_REGION_PAGE_COUNT_COMMON
        + PARAVISOR_CONFIG_SECRETS_SIZE_PAGES
        + PARAVISOR_CONFIG_CPUID_SIZE_PAGES
        + PARAVISOR_CONFIG_VMSA_SIZE_PAGES;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we used max always, not VSM.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    let parameter_region_size = PARAVISOR_VTL2_CONFIG_REGION_PAGE_COUNT_MAX * HV_PAGE_SIZE;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably file an issue to track making all of these calculations work per-isolation type so we don't waste pages.

@chris-oo chris-oo enabled auto-merge (squash) November 13, 2024 00:45
@chris-oo chris-oo merged commit dcce648 into microsoft:main Nov 13, 2024
24 checks passed
@chris-oo chris-oo deleted the snp-reserved-pages branch November 14, 2024 06:06
@chris-oo chris-oo added the backport_2411 Change should be backported to the release/2411 branch label Nov 14, 2024
chris-oo added a commit to chris-oo/openvmm that referenced this pull request Nov 14, 2024
…icrosoft#304)

Previously, we put some SNP specific pages into the same VTL2 config
region. microsoft#265 broke SNP, because this region contains pages that _cannot
be_ zeroed, like the VMSA, CPUID pages and secrets pages.

Move those to a new region, that is marked as persisted to both
kernelmode and usermode. It is unclear to me if the kernel requires that
the CPUID page and secrets page are persisted, but treat them like the
VMSA for now.

Fixes microsoft#295
chris-oo added a commit that referenced this pull request Nov 14, 2024
…334)

Cherry pick of #304 to release/2411

Previously, we put some SNP specific pages into the same VTL2 config
region. #265 broke SNP, because this region contains pages that _cannot
be_ zeroed, like the VMSA, CPUID pages and secrets pages.

Move those to a new region, that is marked as persisted to both
kernelmode and usermode. It is unclear to me if the kernel requires that
the CPUID page and secrets page are persisted, but treat them like the
VMSA for now.

Fixes #295
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport_2411 Change should be backported to the release/2411 branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zeroing VTL 2 Params map via dev/mem on SNP fails
3 participants