@@ -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,19 @@ impl Ghcb {
542529 == guest_os_id. into( )
543530 ) ;
544531
532+ // A silly trick to unmap the GHCB overlay page.
533+ let resp = Self :: ghcb_call ( GhcbCall {
534+ extra_data : 0 ,
535+ page_number : 0 ,
536+ info : GhcbInfo :: REGISTER_REQUEST ,
537+ } ) ;
538+ assert ! (
539+ resp. info( ) == GhcbInfo :: REGISTER_RESPONSE . 0
540+ && resp. extra_data( ) == 0
541+ && resp. pfn( ) == 0 ,
542+ "GhcbInfo::REGISTER_RESPONSE returned msr value {resp:x?}"
543+ ) ;
544+
545545 // Map the GHCB page in the guest as confidential and accept it again
546546 // to return to the original state.
547547
0 commit comments