@@ -14,16 +14,32 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
+ #[ cfg( feature = "mshv2" ) ]
18
+ extern crate mshv_bindings2 as mshv_bindings;
19
+ #[ cfg( feature = "mshv2" ) ]
20
+ extern crate mshv_ioctls2 as mshv_ioctls;
21
+
22
+ #[ cfg( feature = "mshv3" ) ]
23
+ extern crate mshv_bindings3 as mshv_bindings;
24
+ #[ cfg( feature = "mshv3" ) ]
25
+ extern crate mshv_ioctls3 as mshv_ioctls;
26
+
17
27
use std:: fmt:: { Debug , Formatter } ;
18
28
19
29
use log:: error;
30
+ #[ cfg( feature = "mshv2" ) ]
31
+ use mshv_bindings:: hv_message;
20
32
use mshv_bindings:: {
21
- hv_message, hv_message_type, hv_message_type_HVMSG_GPA_INTERCEPT,
22
- hv_message_type_HVMSG_UNMAPPED_GPA, hv_message_type_HVMSG_X64_HALT,
23
- hv_message_type_HVMSG_X64_IO_PORT_INTERCEPT, hv_register_assoc,
33
+ hv_message_type, hv_message_type_HVMSG_GPA_INTERCEPT, hv_message_type_HVMSG_UNMAPPED_GPA,
34
+ hv_message_type_HVMSG_X64_HALT, hv_message_type_HVMSG_X64_IO_PORT_INTERCEPT, hv_register_assoc,
24
35
hv_register_name_HV_X64_REGISTER_RIP, hv_register_value, mshv_user_mem_region,
25
36
FloatingPointUnit , SegmentRegister , SpecialRegisters , StandardRegisters ,
26
37
} ;
38
+ #[ cfg( feature = "mshv3" ) ]
39
+ use mshv_bindings:: {
40
+ hv_partition_property_code_HV_PARTITION_PROPERTY_SYNTHETIC_PROC_FEATURES,
41
+ hv_partition_synthetic_processor_features,
42
+ } ;
27
43
use mshv_ioctls:: { Mshv , VcpuFd , VmFd } ;
28
44
use tracing:: { instrument, Span } ;
29
45
@@ -89,7 +105,19 @@ impl HypervLinuxDriver {
89
105
}
90
106
let mshv = Mshv :: new ( ) ?;
91
107
let pr = Default :: default ( ) ;
108
+ #[ cfg( feature = "mshv2" ) ]
92
109
let vm_fd = mshv. create_vm_with_config ( & pr) ?;
110
+ #[ cfg( feature = "mshv3" ) ]
111
+ let vm_fd = {
112
+ let vm_fd = mshv. create_vm_with_args ( & pr) ?;
113
+ let features: hv_partition_synthetic_processor_features = Default :: default ( ) ;
114
+ vm_fd. hvcall_set_partition_property (
115
+ hv_partition_property_code_HV_PARTITION_PROPERTY_SYNTHETIC_PROC_FEATURES,
116
+ unsafe { features. as_uint64 [ 0 ] } ,
117
+ ) ?;
118
+ vm_fd
119
+ } ;
120
+
93
121
let mut vcpu_fd = vm_fd. create_vcpu ( 0 ) ?;
94
122
95
123
mem_regions. iter ( ) . try_for_each ( |region| {
@@ -283,8 +311,15 @@ impl Hypervisor for HypervLinuxDriver {
283
311
const UNMAPPED_GPA_MESSAGE : hv_message_type = hv_message_type_HVMSG_UNMAPPED_GPA;
284
312
const INVALID_GPA_ACCESS_MESSAGE : hv_message_type = hv_message_type_HVMSG_GPA_INTERCEPT;
285
313
286
- let hv_message: hv_message = Default :: default ( ) ;
287
- let result = match & self . vcpu_fd . run ( hv_message) {
314
+ #[ cfg( feature = "mshv2" ) ]
315
+ let run_result = {
316
+ let hv_message: hv_message = Default :: default ( ) ;
317
+ & self . vcpu_fd . run ( hv_message)
318
+ } ;
319
+ #[ cfg( feature = "mshv3" ) ]
320
+ let run_result = & self . vcpu_fd . run ( ) ;
321
+
322
+ let result = match run_result {
288
323
Ok ( m) => match m. header . message_type {
289
324
HALT_MESSAGE => {
290
325
debug ! ( "mshv - Halt Details : {:#?}" , & self ) ;
0 commit comments