@@ -14,16 +14,32 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
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+
1727use std:: fmt:: { Debug , Formatter } ;
1828
1929use log:: error;
30+ #[ cfg( feature = "mshv2" ) ]
31+ use mshv_bindings:: hv_message;
2032use 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,
2435 hv_register_name_HV_X64_REGISTER_RIP, hv_register_value, mshv_user_mem_region,
2536 FloatingPointUnit , SegmentRegister , SpecialRegisters , StandardRegisters ,
2637} ;
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+ } ;
2743use mshv_ioctls:: { Mshv , VcpuFd , VmFd } ;
2844use tracing:: { instrument, Span } ;
2945
@@ -89,7 +105,19 @@ impl HypervLinuxDriver {
89105 }
90106 let mshv = Mshv :: new ( ) ?;
91107 let pr = Default :: default ( ) ;
108+ #[ cfg( feature = "mshv2" ) ]
92109 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+
93121 let mut vcpu_fd = vm_fd. create_vcpu ( 0 ) ?;
94122
95123 mem_regions. iter ( ) . try_for_each ( |region| {
@@ -283,8 +311,15 @@ impl Hypervisor for HypervLinuxDriver {
283311 const UNMAPPED_GPA_MESSAGE : hv_message_type = hv_message_type_HVMSG_UNMAPPED_GPA;
284312 const INVALID_GPA_ACCESS_MESSAGE : hv_message_type = hv_message_type_HVMSG_GPA_INTERCEPT;
285313
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 {
288323 Ok ( m) => match m. header . message_type {
289324 HALT_MESSAGE => {
290325 debug ! ( "mshv - Halt Details : {:#?}" , & self ) ;
0 commit comments