@@ -34,6 +34,7 @@ use hvdef::hypercall::AcceptMemoryType;
3434use hvdef:: hypercall:: HostVisibilityType ;
3535use hvdef:: hypercall:: HvInputVtl ;
3636use mapping:: GuestMemoryMapping ;
37+ use mapping:: GuestValidMemory ;
3738use memory_range:: MemoryRange ;
3839use parking_lot:: Mutex ;
3940use registrar:: RegisterMemory ;
@@ -382,7 +383,8 @@ struct HypercallOverlay {
382383}
383384
384385struct HardwareIsolatedMemoryProtectorInner {
385- shared : Arc < GuestMemoryMapping > ,
386+ valid_encrypted : Arc < GuestValidMemory > ,
387+ valid_shared : Arc < GuestValidMemory > ,
386388 encrypted : Arc < GuestMemoryMapping > ,
387389 default_vtl_permissions : DefaultVtlPermissions ,
388390 vtl1_protections_enabled : bool ,
@@ -394,14 +396,16 @@ impl HardwareIsolatedMemoryProtector {
394396 /// `shared` provides the mapping for shared memory. `vtl0` provides the
395397 /// mapping for encrypted memory.
396398 pub fn new (
397- shared : Arc < GuestMemoryMapping > ,
399+ valid_encrypted : Arc < GuestValidMemory > ,
400+ valid_shared : Arc < GuestValidMemory > ,
398401 encrypted : Arc < GuestMemoryMapping > ,
399402 layout : MemoryLayout ,
400403 acceptor : Arc < MemoryAcceptor > ,
401404 ) -> Self {
402405 Self {
403406 inner : Mutex :: new ( HardwareIsolatedMemoryProtectorInner {
404- shared,
407+ valid_encrypted,
408+ valid_shared,
405409 encrypted,
406410 // Grant only VTL 0 all permissions. This will be altered
407411 // later by VTL 1 enablement and by VTL 1 itself.
@@ -504,7 +508,7 @@ impl ProtectIsolatedMemory for HardwareIsolatedMemoryProtector {
504508 let gpns = gpns
505509 . iter ( )
506510 . copied ( )
507- . filter ( |& gpn| inner. shared . check_bitmap ( gpn) != shared)
511+ . filter ( |& gpn| inner. valid_shared . check_valid ( gpn) != shared)
508512 . collect :: < Vec < _ > > ( ) ;
509513
510514 tracing:: debug!(
@@ -524,12 +528,12 @@ impl ProtectIsolatedMemory for HardwareIsolatedMemoryProtector {
524528
525529 // Prevent accesses via the wrong address.
526530 let clear_bitmap = if shared {
527- & inner. encrypted
531+ & inner. valid_encrypted
528532 } else {
529- & inner. shared
533+ & inner. valid_shared
530534 } ;
531535 for & range in & ranges {
532- clear_bitmap. update_bitmap ( range, false ) ;
536+ clear_bitmap. update_valid ( range, false ) ;
533537 }
534538
535539 // There may be other threads concurrently accessing these pages. We
@@ -605,7 +609,7 @@ impl ProtectIsolatedMemory for HardwareIsolatedMemoryProtector {
605609 . expect ( "previous gpns was already checked" ) ;
606610
607611 for & range in & rollback_ranges {
608- clear_bitmap. update_bitmap ( range, true ) ;
612+ clear_bitmap. update_valid ( range, true ) ;
609613 }
610614
611615 // Figure out the index of the gpn that failed, in the
@@ -637,12 +641,12 @@ impl ProtectIsolatedMemory for HardwareIsolatedMemoryProtector {
637641
638642 // Allow accesses via the correct address.
639643 let set_bitmap = if shared {
640- & inner. shared
644+ & inner. valid_shared
641645 } else {
642- & inner. encrypted
646+ & inner. valid_encrypted
643647 } ;
644648 for & range in & ranges {
645- set_bitmap. update_bitmap ( range, true ) ;
649+ set_bitmap. update_valid ( range, true ) ;
646650 }
647651
648652 if !shared {
@@ -695,7 +699,7 @@ impl ProtectIsolatedMemory for HardwareIsolatedMemoryProtector {
695699
696700 // Set GPN sharing status in output.
697701 for ( gpn, host_vis) in gpns. iter ( ) . zip ( host_visibility. iter_mut ( ) ) {
698- * host_vis = if inner. shared . check_bitmap ( * gpn) {
702+ * host_vis = if inner. valid_shared . check_valid ( * gpn) {
699703 HostVisibilityType :: SHARED
700704 } else {
701705 HostVisibilityType :: PRIVATE
@@ -739,7 +743,7 @@ impl ProtectIsolatedMemory for HardwareIsolatedMemoryProtector {
739743 // find all accepted memory. When lazy acceptance exists,
740744 // this should track all pages that have been accepted and
741745 // should be used instead.
742- if !inner. encrypted . check_bitmap ( gpn) {
746+ if !inner. valid_encrypted . check_valid ( gpn) {
743747 if page_count > 0 {
744748 let end_address = protect_start + ( page_count * PAGE_SIZE as u64 ) ;
745749 ranges. push ( MemoryRange :: new ( protect_start..end_address) ) ;
@@ -793,7 +797,7 @@ impl ProtectIsolatedMemory for HardwareIsolatedMemoryProtector {
793797 let inner = self . inner . lock ( ) ;
794798
795799 // Protections cannot be applied to a host-visible page
796- if gpns. iter ( ) . any ( |& gpn| inner. shared . check_bitmap ( gpn) ) {
800+ if gpns. iter ( ) . any ( |& gpn| inner. valid_shared . check_valid ( gpn) ) {
797801 return Err ( ( HvError :: OperationDenied , 0 ) ) ;
798802 }
799803
0 commit comments