@@ -13,12 +13,6 @@ use std::io;
13
13
14
14
use std:: os:: unix:: io:: RawFd ;
15
15
16
- #[ cfg( feature = "tee" ) ]
17
- use kvm_ioctls:: VcpuExit :: Unsupported ;
18
-
19
- use std:: sync:: Arc ;
20
- use std:: sync:: Mutex ;
21
-
22
16
use std:: result;
23
17
use std:: sync:: atomic:: { fence, Ordering } ;
24
18
#[ cfg( not( test) ) ]
@@ -45,18 +39,14 @@ use kvm_bindings::{
45
39
KVM_CLOCK_TSC_STABLE , KVM_IRQCHIP_IOAPIC , KVM_IRQCHIP_PIC_MASTER , KVM_IRQCHIP_PIC_SLAVE ,
46
40
KVM_MAX_CPUID_ENTRIES ,
47
41
} ;
48
- #[ cfg( feature = "tee" ) ]
49
42
use kvm_bindings:: {
50
- kvm_create_guest_memfd, kvm_memory_attributes, kvm_userspace_memory_region2 , KVM_API_VERSION ,
51
- KVM_EXIT_MEMORY_FAULT , KVM_MEMORY_ATTRIBUTE_PRIVATE , KVM_MEMORY_EXIT_FLAG_PRIVATE ,
52
- KVM_MEM_GUEST_MEMFD ,
43
+ kvm_create_guest_memfd, kvm_memory_attributes, kvm_userspace_memory_region ,
44
+ kvm_userspace_memory_region2 , KVM_API_VERSION , KVM_MEMORY_ATTRIBUTE_PRIVATE ,
45
+ KVM_MEM_GUEST_MEMFD , KVM_SYSTEM_EVENT_RESET , KVM_SYSTEM_EVENT_SHUTDOWN ,
53
46
} ;
54
- #[ cfg( not( feature = "tee" ) ) ]
55
- use kvm_bindings:: { kvm_userspace_memory_region, KVM_API_VERSION } ;
56
- use kvm_bindings:: {
57
- kvm_userspace_memory_region, KVM_API_VERSION , KVM_SYSTEM_EVENT_RESET , KVM_SYSTEM_EVENT_SHUTDOWN ,
58
- } ;
59
- use kvm_ioctls:: * ;
47
+ #[ cfg( feature = "tee" ) ]
48
+ use kvm_bindings:: { kvm_enable_cap, KVM_CAP_EXIT_HYPERCALL , KVM_MEMORY_EXIT_FLAG_PRIVATE } ;
49
+ use kvm_ioctls:: { Cap :: * , * } ;
60
50
use utils:: eventfd:: EventFd ;
61
51
use utils:: signal:: { register_signal_handler, sigrtmin, Killable } ;
62
52
use utils:: sm:: StateMachine ;
@@ -781,13 +771,6 @@ pub struct VcpuConfig {
781
771
pub cpu_template : Option < CpuFeaturesTemplate > ,
782
772
}
783
773
784
- #[ cfg( feature = "tee" ) ]
785
- pub struct MemProperties {
786
- pub addr : u64 ,
787
- pub size : u64 ,
788
- pub attributes : u32 ,
789
- }
790
-
791
774
// Using this for easier explicit type-casting to help IDEs interpret the code.
792
775
type VcpuCell = Cell < Option < * mut Vcpu > > ;
793
776
@@ -810,10 +793,6 @@ pub struct Vcpu {
810
793
#[ cfg( target_arch = "aarch64" ) ]
811
794
mpidr : u64 ,
812
795
813
- // The transmitting end of the events channel which will be given to the vcpu side
814
- #[ cfg( feature = "tee" ) ]
815
- sender_io : Sender < MemProperties > ,
816
-
817
796
// The receiving end of events channel owned by the vcpu side.
818
797
event_receiver : Receiver < VcpuEvent > ,
819
798
// The transmitting end of the events channel which will be given to the handler.
@@ -961,12 +940,7 @@ impl Vcpu {
961
940
/// * `exit_evt` - An `EventFd` that will be written into when this vcpu exits.
962
941
/// * `create_ts` - A timestamp used by the vcpu to calculate its lifetime.
963
942
#[ cfg( target_arch = "aarch64" ) ]
964
- pub fn new_aarch64 (
965
- id : u8 ,
966
- vm_fd : & VmFd ,
967
- exit_evt : EventFd ,
968
- #[ cfg( feature = "tee" ) ] sender_io : Sender < MemProperties > ,
969
- ) -> Result < Self > {
943
+ pub fn new_aarch64 ( id : u8 , vm_fd : & VmFd , exit_evt : EventFd ) -> Result < Self > {
970
944
let kvm_vcpu = vm_fd. create_vcpu ( id as u64 ) . map_err ( Error :: VcpuFd ) ?;
971
945
let ( event_sender, event_receiver) = unbounded ( ) ;
972
946
let ( response_sender, response_receiver) = unbounded ( ) ;
@@ -981,8 +955,6 @@ impl Vcpu {
981
955
event_sender : Some ( event_sender) ,
982
956
response_receiver : Some ( response_receiver) ,
983
957
response_sender,
984
- #[ cfg( feature = "tee" ) ]
985
- sender_io,
986
958
} )
987
959
}
988
960
@@ -1271,6 +1243,17 @@ impl Vcpu {
1271
1243
self . io_bus . write ( 0 , u64:: from ( addr) , data) ;
1272
1244
Ok ( VcpuEmulation :: Handled )
1273
1245
}
1246
+ #[ cfg( feature = "tee" ) ]
1247
+ VcpuExit :: MemoryFault { gpa, size, flags } => {
1248
+ let private = ( flags & ( KVM_MEMORY_EXIT_FLAG_PRIVATE as u64 ) ) != 0 ;
1249
+
1250
+ let mem_properties = MemoryProperties { gpa, size, private } ;
1251
+
1252
+ self . pm_sender . 0 . send ( mem_properties) . unwrap ( ) ;
1253
+ let _ = self . pm_sender . 1 . read ( ) . unwrap ( ) ;
1254
+
1255
+ Ok ( VcpuEmulation :: Handled )
1256
+ }
1274
1257
VcpuExit :: MmioRead ( addr, data) => {
1275
1258
if let Some ( ref mmio_bus) = self . mmio_bus {
1276
1259
mmio_bus. read ( 0 , addr, data) ;
@@ -1291,38 +1274,6 @@ impl Vcpu {
1291
1274
info ! ( "Received KVM_EXIT_SHUTDOWN signal" ) ;
1292
1275
Ok ( VcpuEmulation :: Stopped )
1293
1276
}
1294
- #[ cfg( feature = "tee" ) ]
1295
- VcpuExit :: MemoryFault { flags, gpa, size } => {
1296
- if flags & !KVM_MEMORY_EXIT_FLAG_PRIVATE as u64 != 0 {
1297
- error ! ( "KVM_EXIT_MEMORY_FAULT: Unknown flag {}" , flags) ;
1298
- Err ( Error :: VcpuUnhandledKvmExit )
1299
- } else {
1300
- // from private to shared
1301
- let mut attr = 0 ;
1302
- // from shared to private
1303
- if flags & KVM_MEMORY_EXIT_FLAG_PRIVATE as u64
1304
- == KVM_MEMORY_EXIT_FLAG_PRIVATE as u64
1305
- {
1306
- attr = KVM_MEMORY_ATTRIBUTE_PRIVATE ;
1307
- } ;
1308
-
1309
- let _ = self . sender_io . try_send ( MemProperties {
1310
- addr : gpa,
1311
- size,
1312
- attributes : attr,
1313
- } ) ;
1314
- Ok ( VcpuEmulation :: Handled )
1315
- }
1316
- }
1317
- // Documentation specifices that when KVM exists with KVM_EXIT_MEMORY_FAULT,
1318
- // userspace should assume kvm_run.exit_reason is stale/undefined for error numbers
1319
- // different than EFAULT or EHWPOISON
1320
- #[ cfg( feature = "tee" ) ]
1321
- Unsupported ( KVM_EXIT_MEMORY_FAULT ) => Ok ( VcpuEmulation :: Handled ) ,
1322
- VcpuExit :: InternalError => {
1323
- error ! ( "Received KVM_EXIT_INTERNAL_ERROR signal" ) ;
1324
- Err ( Error :: VcpuUnhandledKvmExit )
1325
- }
1326
1277
// Documentation specifies that below kvm exits are considered
1327
1278
// errors.
1328
1279
VcpuExit :: FailEntry ( reason, vcpu) => {
0 commit comments