@@ -510,24 +510,11 @@ impl Ghcb {
510
510
Self :: set_register ( HvX64RegisterName :: GuestOsId , guest_os_id. into_bits ( ) . into ( ) )
511
511
. expect ( "failed to set guest OS ID" ) ;
512
512
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
-
519
513
// SAFETY: Always safe to read the GHCB MSR, no concurrency issues.
520
514
GHCB_PREVIOUS . replace ( unsafe { read_msr ( X86X_AMD_MSR_GHCB ) } ) ;
521
515
}
522
516
523
517
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
-
531
518
// Unregister from issuing Hyper-V hypercalls.
532
519
let guest_os_id = hvdef:: hypercall:: HvGuestOsMicrosoft :: new ( ) ;
533
520
Self :: set_register ( HvX64RegisterName :: GuestOsId , guest_os_id. into_bits ( ) . into ( ) )
@@ -542,6 +529,30 @@ impl Ghcb {
542
529
== guest_os_id. into( )
543
530
) ;
544
531
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
+
545
556
// Map the GHCB page in the guest as confidential and accept it again
546
557
// to return to the original state.
547
558
0 commit comments