Skip to content

Commit 1648e44

Browse files
committed
temp remap at GPA 0 to let pvalidate succeed
1 parent 7a29da7 commit 1648e44

File tree

1 file changed

+24
-13
lines changed
  • openhcl/openhcl_boot/src/arch/x86_64

1 file changed

+24
-13
lines changed

openhcl/openhcl_boot/src/arch/x86_64/snp.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -510,24 +510,11 @@ impl Ghcb {
510510
Self::set_register(HvX64RegisterName::GuestOsId, guest_os_id.into_bits().into())
511511
.expect("failed to set guest OS ID");
512512

513-
Self::set_register(
514-
HvX64RegisterName::SevGhcbGpa,
515-
((ghcb_access::page_number() << X64_PAGE_SHIFT) | 0x1).into(),
516-
)
517-
.expect("GHCB: Failed to set GHCB GPA");
518-
519513
// SAFETY: Always safe to read the GHCB MSR, no concurrency issues.
520514
GHCB_PREVIOUS.replace(unsafe { read_msr(X86X_AMD_MSR_GHCB) });
521515
}
522516

523517
pub fn uninitialize() {
524-
// Needed so that the hypervisor unmaps the overlay page.
525-
Self::set_register(
526-
HvX64RegisterName::SevGhcbGpa,
527-
((ghcb_access::page_number() << X64_PAGE_SHIFT) | 0x0).into(),
528-
)
529-
.expect("GHCB: Failed to unset GHCB GPA");
530-
531518
// Unregister from issuing Hyper-V hypercalls.
532519
let guest_os_id = hvdef::hypercall::HvGuestOsMicrosoft::new();
533520
Self::set_register(HvX64RegisterName::GuestOsId, guest_os_id.into_bits().into())
@@ -542,6 +529,30 @@ impl Ghcb {
542529
== guest_os_id.into()
543530
);
544531

532+
// Tell the hypervisor that the GHCB page is at GPA 0 now.
533+
// That'll make it to unmap the overlay page and let the `pvalidate`
534+
// below to succeed.
535+
//
536+
// Soon after this, the GHCB page will be mapped by the kernel at the
537+
// GPA of its chhosing. The temporarily mapping at GPA 0 poses no
538+
// security risk as that page does not contain any sensitive data
539+
// in the IGVM file.
540+
//
541+
// Once support for unpamming the GHCB page from the latest SEV-ES
542+
// specification is added, this will be removed in favor of the standard
543+
// unmap operation.
544+
let resp = Self::ghcb_call(GhcbCall {
545+
extra_data: 0,
546+
page_number: 0,
547+
info: GhcbInfo::REGISTER_REQUEST,
548+
});
549+
assert!(
550+
resp.info() == GhcbInfo::REGISTER_RESPONSE.0
551+
&& resp.extra_data() == 0
552+
&& resp.pfn() == 0,
553+
"GhcbInfo::REGISTER_RESPONSE returned msr value {resp:x?}"
554+
);
555+
545556
// Map the GHCB page in the guest as confidential and accept it again
546557
// to return to the original state.
547558

0 commit comments

Comments
 (0)