@@ -15,7 +15,9 @@ use libc::{fallocate, madvise, FALLOC_FL_KEEP_SIZE, FALLOC_FL_PUNCH_HOLE, MADV_D
15
15
#[ cfg( feature = "tee" ) ]
16
16
use std:: ffi:: c_void;
17
17
#[ cfg( feature = "tee" ) ]
18
- use vm_memory:: { guest_memory:: GuestMemory , GuestAddress , GuestMemoryRegion , MemoryRegionAddress } ;
18
+ use vm_memory:: {
19
+ guest_memory:: GuestMemory , Address , GuestAddress , GuestMemoryRegion , MemoryRegionAddress ,
20
+ } ;
19
21
20
22
pub fn start_worker_thread (
21
23
vmm : Arc < Mutex < super :: Vmm > > ,
@@ -67,15 +69,15 @@ impl super::Vmm {
67
69
68
70
#[ cfg( feature = "tee" ) ]
69
71
fn convert_memory ( & self , sender : Sender < bool > , properties : MemoryProperties ) {
70
- let ( guest_memfd, region_start) = self
71
- . kvm_vm ( )
72
- . guest_memfd_get ( properties . gpa )
73
- . unwrap_or_else ( || {
74
- panic ! (
75
- "unable to find KVM guest_memfd for memory region corresponding to GPA 0x{:x}" ,
76
- properties . gpa
77
- )
78
- } ) ;
72
+ let Some ( ( guest_memfd, region_start) ) = self . kvm_vm ( ) . guest_memfd_get ( properties . gpa )
73
+ else {
74
+ error ! (
75
+ "unable to find KVM guest_memfd for memory region corresponding to GPA 0x{:x}" ,
76
+ properties . gpa
77
+ ) ;
78
+ sender . send ( false ) . unwrap ( ) ;
79
+ return ;
80
+ } ;
79
81
80
82
let attributes: u64 = if properties. private {
81
83
KVM_MEMORY_ATTRIBUTE_PRIVATE as u64
@@ -90,10 +92,11 @@ impl super::Vmm {
90
92
flags : 0 ,
91
93
} ;
92
94
93
- self . kvm_vm ( )
94
- . fd ( )
95
- . set_memory_attributes ( attr)
96
- . unwrap_or_else ( |_| panic ! ( "unable to set memory attributes for memory region corresponding to guest address 0x{:x}" , properties. gpa) ) ;
95
+ if self . kvm_vm ( ) . fd ( ) . set_memory_attributes ( attr) . is_err ( ) {
96
+ error ! ( "unable to set memory attributes for memory region corresponding to guest address 0x{:x}" , properties. gpa) ;
97
+ sender. send ( false ) . unwrap ( ) ;
98
+ return ;
99
+ }
97
100
98
101
let region = self
99
102
. guest_memory ( )
@@ -112,10 +115,14 @@ impl super::Vmm {
112
115
if properties. private {
113
116
let region_addr = MemoryRegionAddress ( offset) ;
114
117
115
- let host_startaddr = region
116
- . unwrap ( )
117
- . get_host_address ( region_addr)
118
- . expect ( "host address corresponding to memory region address 0x{:x} not found" ) ;
118
+ let Ok ( host_startaddr) = region. unwrap ( ) . get_host_address ( region_addr) else {
119
+ error ! (
120
+ "host address corresponding to memory region address 0x{:x} not found" ,
121
+ region_addr. raw_value( )
122
+ ) ;
123
+ sender. send ( false ) . unwrap ( ) ;
124
+ return ;
125
+ } ;
119
126
120
127
let ret = unsafe {
121
128
madvise (
0 commit comments