@@ -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( 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
+
17
27
use std:: fmt:: { Debug , Formatter } ;
18
28
19
29
use log:: error;
30
+ #[ cfg( 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( 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
@@ -86,7 +102,24 @@ impl HypervLinuxDriver {
86
102
) -> Result < Self > {
87
103
let mshv = Mshv :: new ( ) ?;
88
104
let pr = Default :: default ( ) ;
105
+ #[ cfg( mshv2) ]
89
106
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
+
90
123
let mut vcpu_fd = vm_fd. create_vcpu ( 0 ) ?;
91
124
92
125
mem_regions. iter ( ) . try_for_each ( |region| {
@@ -280,8 +313,15 @@ impl Hypervisor for HypervLinuxDriver {
280
313
const UNMAPPED_GPA_MESSAGE : hv_message_type = hv_message_type_HVMSG_UNMAPPED_GPA;
281
314
const INVALID_GPA_ACCESS_MESSAGE : hv_message_type = hv_message_type_HVMSG_GPA_INTERCEPT;
282
315
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 {
285
325
Ok ( m) => match m. header . message_type {
286
326
HALT_MESSAGE => {
287
327
crate :: debug!( "mshv - Halt Details : {:#?}" , & self ) ;
0 commit comments