@@ -72,8 +72,6 @@ use std::collections::HashMap;
7272use std:: convert:: TryInto ;
7373use std:: fs:: { File , OpenOptions } ;
7474use std:: io:: { self , Seek , SeekFrom , Write } ;
75- #[ cfg( feature = "tdx" ) ]
76- use std:: mem;
7775#[ cfg( all( target_arch = "x86_64" , feature = "guest_debug" ) ) ]
7876use std:: mem:: size_of;
7977use std:: num:: Wrapping ;
@@ -86,8 +84,10 @@ use thiserror::Error;
8684use tracer:: trace_scoped;
8785use vm_device:: Bus ;
8886#[ cfg( feature = "tdx" ) ]
89- use vm_memory:: { Address , ByteValued , GuestMemory , GuestMemoryRegion } ;
90- use vm_memory:: { Bytes , GuestAddress , GuestAddressSpace , GuestMemoryAtomic } ;
87+ use vm_memory:: { Address , ByteValued , GuestMemoryRegion , ReadVolatile } ;
88+ use vm_memory:: {
89+ Bytes , GuestAddress , GuestAddressSpace , GuestMemory , GuestMemoryAtomic , WriteVolatile ,
90+ } ;
9191use vm_migration:: protocol:: { Request , Response , Status } ;
9292use vm_migration:: {
9393 protocol:: MemoryRangeTable , snapshot_from_id, Migratable , MigratableError , Pausable , Snapshot ,
@@ -884,7 +884,7 @@ impl Vm {
884884 }
885885
886886 fn load_initramfs ( & mut self , guest_mem : & GuestMemoryMmap ) -> Result < arch:: InitramfsConfig > {
887- let mut initramfs = self . initramfs . as_ref ( ) . unwrap ( ) ;
887+ let initramfs = self . initramfs . as_mut ( ) . unwrap ( ) ;
888888 let size: usize = initramfs
889889 . seek ( SeekFrom :: End ( 0 ) )
890890 . map_err ( |_| Error :: InitramfsLoad ) ?
@@ -897,7 +897,7 @@ impl Vm {
897897 let address = GuestAddress ( address) ;
898898
899899 guest_mem
900- . read_from ( address, & mut initramfs, size)
900+ . read_volatile_from ( address, initramfs, size)
901901 . map_err ( |_| Error :: InitramfsLoad ) ?;
902902
903903 info ! ( "Initramfs loaded: address = 0x{:x}" , address. 0 ) ;
@@ -1744,7 +1744,7 @@ impl Vm {
17441744 firmware_file
17451745 . seek ( SeekFrom :: Start ( section. data_offset as u64 ) )
17461746 . map_err ( Error :: LoadTdvf ) ?;
1747- mem. read_from (
1747+ mem. read_volatile_from (
17481748 GuestAddress ( section. address ) ,
17491749 & mut firmware_file,
17501750 section. data_size as usize ,
@@ -1766,13 +1766,8 @@ impl Vm {
17661766 . map_err ( Error :: LoadPayload ) ?;
17671767
17681768 let mut payload_header = linux_loader:: bootparam:: setup_header:: default ( ) ;
1769- payload_header
1770- . as_bytes ( )
1771- . read_from (
1772- 0 ,
1773- payload_file,
1774- mem:: size_of :: < linux_loader:: bootparam:: setup_header > ( ) ,
1775- )
1769+ payload_file
1770+ . read_volatile ( & mut payload_header. as_bytes ( ) )
17761771 . unwrap ( ) ;
17771772
17781773 if payload_header. header != 0x5372_6448 {
@@ -1786,7 +1781,7 @@ impl Vm {
17861781 }
17871782
17881783 payload_file. rewind ( ) . map_err ( Error :: LoadPayload ) ?;
1789- mem. read_from (
1784+ mem. read_volatile_from (
17901785 GuestAddress ( section. address ) ,
17911786 payload_file,
17921787 payload_size as usize ,
@@ -2129,7 +2124,7 @@ impl Vm {
21292124 fd : & mut F ,
21302125 ) -> std:: result:: Result < ( ) , MigratableError >
21312126 where
2132- F : Write ,
2127+ F : WriteVolatile ,
21332128 {
21342129 let guest_memory = self . memory_manager . lock ( ) . as_ref ( ) . unwrap ( ) . guest_memory ( ) ;
21352130 let mem = guest_memory. memory ( ) ;
@@ -2143,7 +2138,7 @@ impl Vm {
21432138 // see: https://github.com/rust-vmm/vm-memory/issues/174
21442139 loop {
21452140 let bytes_written = mem
2146- . write_to (
2141+ . write_volatile_to (
21472142 GuestAddress ( range. gpa + offset) ,
21482143 fd,
21492144 ( range. length - offset) as usize ,
0 commit comments