@@ -14,16 +14,32 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17+ #[ cfg( mshv2) ]
18+ extern crate mshv_bindings2 as mshv_bindings;
19+ #[ cfg( mshv2) ]
20+ extern crate mshv_ioctls2 as mshv_ioctls;
21+
22+ #[ cfg( mshv3) ]
23+ extern crate mshv_bindings3 as mshv_bindings;
24+ #[ cfg( mshv3) ]
25+ extern crate mshv_ioctls3 as mshv_ioctls;
26+
1727use std:: fmt:: { Debug , Formatter } ;
1828
1929use log:: error;
30+ #[ cfg( 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( 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
@@ -86,7 +102,24 @@ impl HypervLinuxDriver {
86102 ) -> Result < Self > {
87103 let mshv = Mshv :: new ( ) ?;
88104 let pr = Default :: default ( ) ;
105+ #[ cfg( mshv2) ]
89106 let vm_fd = mshv. create_vm_with_config ( & pr) ?;
107+ #[ cfg( mshv3) ]
108+ let vm_fd = {
109+ // It's important to avoid create_vm() and explicitly use
110+ // create_vm_with_args() with an empty arguments structure
111+ // here, because otherwise the partition is set up with a SynIC.
112+
113+ let vm_fd = mshv. create_vm_with_args ( & pr) ?;
114+ let features: hv_partition_synthetic_processor_features = Default :: default ( ) ;
115+ vm_fd. hvcall_set_partition_property (
116+ hv_partition_property_code_HV_PARTITION_PROPERTY_SYNTHETIC_PROC_FEATURES,
117+ unsafe { features. as_uint64 [ 0 ] } ,
118+ ) ?;
119+ vm_fd. initialize ( ) ?;
120+ vm_fd
121+ } ;
122+
90123 let mut vcpu_fd = vm_fd. create_vcpu ( 0 ) ?;
91124
92125 mem_regions. iter ( ) . try_for_each ( |region| {
@@ -280,8 +313,15 @@ impl Hypervisor for HypervLinuxDriver {
280313 const UNMAPPED_GPA_MESSAGE : hv_message_type = hv_message_type_HVMSG_UNMAPPED_GPA;
281314 const INVALID_GPA_ACCESS_MESSAGE : hv_message_type = hv_message_type_HVMSG_GPA_INTERCEPT;
282315
283- let hv_message: hv_message = Default :: default ( ) ;
284- let result = match & self . vcpu_fd . run ( hv_message) {
316+ #[ cfg( mshv2) ]
317+ let run_result = {
318+ let hv_message: hv_message = Default :: default ( ) ;
319+ & self . vcpu_fd . run ( hv_message)
320+ } ;
321+ #[ cfg( mshv3) ]
322+ let run_result = & self . vcpu_fd . run ( ) ;
323+
324+ let result = match run_result {
285325 Ok ( m) => match m. header . message_type {
286326 HALT_MESSAGE => {
287327 crate :: debug!( "mshv - Halt Details : {:#?}" , & self ) ;
0 commit comments