Skip to content

Commit ef9ac03

Browse files
authored
virt_mshv: configure partition properties explicitly (#3270)
The MSHV backend was calling mshv.create_vm(), which delegates to the mshv-ioctls crate's internal make_partition_create_arg helper. That helper hardcodes a limited set of processor features and always enables both LAPIC and X2APIC, ignoring the partition configuration entirely. Replace this with create_vm_with_args using an explicitly constructed mshv_create_partition_v2. The partition flags now respect the topology's APIC mode, and the processor feature and XSAVE feature masks match what WHP enables by default--querying the host at runtime is unnecessary since the hypervisor intersects whatever we request with host capabilities anyway. Synthetic processor features are now gated on hv_config being present, so they are only set when the guest is configured with a Hyper-V interface. To avoid using the awkward bindgen union types from mshv-bindings for feature masks, this change introduces proper bitfield types in hvdef: HvX64PartitionProcessorFeatures, HvX64PartitionProcessorFeatures1, HvX64PartitionProcessorXsaveFeatures, and the arch-neutral HvPartitionSyntheticProcessorFeatures. The x64 types are named with an X64 prefix since ARM64 has an entirely different set of processor features; the synthetic features type is arch-neutral. All definitions were verified against the hypervisor source.
1 parent c692863 commit ef9ac03

5 files changed

Lines changed: 473 additions & 15 deletions

File tree

Cargo.lock

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4436,9 +4436,9 @@ dependencies = [
44364436

44374437
[[package]]
44384438
name = "mshv-bindings"
4439-
version = "0.6.0"
4439+
version = "0.6.8"
44404440
source = "registry+https://github.com/rust-lang/crates.io-index"
4441-
checksum = "805cf329582f770f62cc612716a04c14815276ae266b6298375a672d3c5a5184"
4441+
checksum = "a94fc3871dd23738188e5bc76a1d1a5930ebcaf9308c560a7274aa62b1770594"
44424442
dependencies = [
44434443
"libc",
44444444
"num_enum",
@@ -4450,9 +4450,9 @@ dependencies = [
44504450

44514451
[[package]]
44524452
name = "mshv-ioctls"
4453-
version = "0.6.0"
4453+
version = "0.6.8"
44544454
source = "registry+https://github.com/rust-lang/crates.io-index"
4455-
checksum = "aefaab4c067cf5226a917227640d835327b25b71a8d465f815f74f490344e10a"
4455+
checksum = "1339723fe3a26baf4041459de20ad923e89d312c3bb25dbf9f60738c22a47f5e"
44564456
dependencies = [
44574457
"libc",
44584458
"mshv-bindings",
@@ -8944,6 +8944,7 @@ dependencies = [
89448944
"tracing",
89458945
"virt",
89468946
"virt_support_x86emu",
8947+
"vm_topology",
89478948
"vmcore",
89488949
"x86defs",
89498950
"x86emu",

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,8 @@ log = "0.4"
514514
loom = "0.7.2"
515515
mimalloc = { version = "0.1.39", default-features = false }
516516
ms-tpm-20-ref = { version = "0.1", git = "https://github.com/microsoft/ms-tpm-20-ref-rs.git", branch = "main" }
517-
mshv-bindings = "0.6.0"
518-
mshv-ioctls = "0.6.0"
517+
mshv-bindings = "0.6.8"
518+
mshv-ioctls = "0.6.8"
519519
nix = { version = "0.30.1", default-features = false }
520520
ntapi = "0.4"
521521
object = { version = "0.37.3", default-features = false }

vm/hv1/hvdef/src/lib.rs

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,245 @@ pub struct HvPartitionPrivilege {
106106
_reserved3: u64,
107107
}
108108

109+
/// Partition processor features (bank 0).
110+
///
111+
/// Each bit indicates whether the corresponding processor feature is enabled
112+
/// for a partition. When used in `mshv_create_partition_v2.pt_cpu_fbanks`,
113+
/// the sense is *inverted*: a set bit means the feature is **disabled**.
114+
#[bitfield(u64)]
115+
pub struct HvX64PartitionProcessorFeatures {
116+
pub sse3_support: bool,
117+
pub lahf_sahf_support: bool,
118+
pub ssse3_support: bool,
119+
pub sse4_1_support: bool,
120+
pub sse4_2_support: bool,
121+
pub sse4a_support: bool,
122+
pub xop_support: bool,
123+
pub pop_cnt_support: bool,
124+
pub cmpxchg16b_support: bool,
125+
pub altmovcr8_support: bool,
126+
pub lzcnt_support: bool,
127+
pub mis_align_sse_support: bool,
128+
pub mmx_ext_support: bool,
129+
pub amd3d_now_support: bool,
130+
pub extended_amd3d_now_support: bool,
131+
pub page_1gb_support: bool,
132+
pub aes_support: bool,
133+
pub pclmulqdq_support: bool,
134+
pub pcid_support: bool,
135+
pub fma4_support: bool,
136+
pub f16c_support: bool,
137+
pub rd_rand_support: bool,
138+
pub rd_wr_fs_gs_support: bool,
139+
pub smep_support: bool,
140+
pub enhanced_fast_string_support: bool,
141+
pub bmi1_support: bool,
142+
pub bmi2_support: bool,
143+
pub hle_support_deprecated: bool,
144+
pub rtm_support_deprecated: bool,
145+
pub movbe_support: bool,
146+
pub npiep1_support: bool,
147+
pub dep_x87_fpu_save_support: bool,
148+
pub rd_seed_support: bool,
149+
pub adx_support: bool,
150+
pub intel_prefetch_support: bool,
151+
pub smap_support: bool,
152+
pub hle_support: bool,
153+
pub rtm_support: bool,
154+
pub rdtscp_support: bool,
155+
pub clflushopt_support: bool,
156+
pub clwb_support: bool,
157+
pub sha_support: bool,
158+
pub x87_pointers_saved_support: bool,
159+
pub invpcid_support: bool,
160+
pub ibrs_support: bool,
161+
pub stibp_support: bool,
162+
pub ibpb_support: bool,
163+
pub unrestricted_guest_support: bool,
164+
pub mdd_support: bool,
165+
pub fast_short_rep_mov_support: bool,
166+
pub l1d_cache_flush_support: bool,
167+
pub rdcl_no_support: bool,
168+
pub ibrs_all_support: bool,
169+
pub skip_l1df_support: bool,
170+
pub ssb_no_support: bool,
171+
pub rsb_a_no_support: bool,
172+
pub virt_spec_ctrl_support: bool,
173+
pub rd_pid_support: bool,
174+
pub umip_support: bool,
175+
pub mbs_no_support: bool,
176+
pub mb_clear_support: bool,
177+
pub taa_no_support: bool,
178+
pub tsx_ctrl_support: bool,
179+
_reserved_bank0: bool,
180+
}
181+
182+
/// Partition processor features (bank 1).
183+
#[bitfield(u64)]
184+
pub struct HvX64PartitionProcessorFeatures1 {
185+
pub a_count_m_count_support: bool,
186+
pub tsc_invariant_support: bool,
187+
pub cl_zero_support: bool,
188+
pub rdpru_support: bool,
189+
pub la57_support: bool,
190+
pub mbec_support: bool,
191+
pub nested_virt_support: bool,
192+
pub psfd_support: bool,
193+
pub cet_ss_support: bool,
194+
pub cet_ibt_support: bool,
195+
pub vmx_exception_inject_support: bool,
196+
pub enqcmd_support: bool,
197+
pub umwait_tpause_support: bool,
198+
pub movdiri_support: bool,
199+
pub movdir64b_support: bool,
200+
pub cldemote_support: bool,
201+
pub serialize_support: bool,
202+
pub tsc_deadline_tmr_support: bool,
203+
pub tsc_adjust_support: bool,
204+
pub fz_l_rep_movsb: bool,
205+
pub fs_rep_stosb: bool,
206+
pub fs_rep_cmpsb: bool,
207+
pub tsx_ld_trk_support: bool,
208+
pub vmx_ins_outs_exit_info_support: bool,
209+
pub hlat_support: bool,
210+
pub sbdr_ssdp_no_support: bool,
211+
pub fbsdp_no_support: bool,
212+
pub psdp_no_support: bool,
213+
pub fb_clear_support: bool,
214+
pub btc_no_support: bool,
215+
pub ibpb_rsb_flush_support: bool,
216+
pub stibp_always_on_support: bool,
217+
pub perf_global_ctrl_support: bool,
218+
pub npt_execute_only_support: bool,
219+
pub npt_ad_flags_support: bool,
220+
pub npt_1gb_page_support: bool,
221+
pub amd_processor_topology_node_id_support: bool,
222+
pub local_machine_check_support: bool,
223+
pub extended_topology_leaf_fp256_amd_support: bool,
224+
pub gds_no_support: bool,
225+
pub cmpccxadd_support: bool,
226+
pub tsc_aux_virtualization_support: bool,
227+
pub rmp_query_support: bool,
228+
pub bhi_no_support: bool,
229+
pub bhi_dis_support: bool,
230+
pub prefetch_i_support: bool,
231+
pub sha512_support: bool,
232+
pub mitigation_ctrl_support: bool,
233+
pub rfds_no_support: bool,
234+
pub rfds_clear_support: bool,
235+
pub sm3_support: bool,
236+
pub sm4_support: bool,
237+
pub secure_avic_support: bool,
238+
pub guest_intercept_ctrl_support: bool,
239+
pub sbpb_support: bool,
240+
pub ibpb_br_type_support: bool,
241+
pub srso_no_support: bool,
242+
pub srso_user_kernel_no_support: bool,
243+
pub vrew_clear_support: bool,
244+
pub tsa_l1_no_support: bool,
245+
pub tsa_sq_no_support: bool,
246+
pub lass_support: bool,
247+
#[bits(2)]
248+
_reserved_bank1: u8,
249+
}
250+
251+
/// Partition processor XSAVE features.
252+
#[bitfield(u64)]
253+
pub struct HvX64PartitionProcessorXsaveFeatures {
254+
pub xsave_support: bool,
255+
pub xsaveopt_support: bool,
256+
pub avx_support: bool,
257+
pub avx2_support: bool,
258+
pub fma_support: bool,
259+
pub mpx_support: bool,
260+
pub avx512_support: bool,
261+
pub avx512_dq_support: bool,
262+
pub avx512_cd_support: bool,
263+
pub avx512_bw_support: bool,
264+
pub avx512_vl_support: bool,
265+
pub xsave_comp_support: bool,
266+
pub xsave_supervisor_support: bool,
267+
pub xcr1_support: bool,
268+
pub avx512_bitalg_support: bool,
269+
pub avx512_ifma_support: bool,
270+
pub avx512_vbmi_support: bool,
271+
pub avx512_vbmi2_support: bool,
272+
pub avx512_vnni_support: bool,
273+
pub gfni_support: bool,
274+
pub vaes_support: bool,
275+
pub avx512_vpopcntdq_support: bool,
276+
pub vpclmulqdq_support: bool,
277+
pub avx512_bf16_support: bool,
278+
pub avx512_vp2_intersect_support: bool,
279+
pub avx512_fp16_support: bool,
280+
pub xfd_support: bool,
281+
pub amx_tile_support: bool,
282+
pub amx_bf16_support: bool,
283+
pub amx_int8_support: bool,
284+
pub avx_vnni_support: bool,
285+
pub avx_ifma_support: bool,
286+
pub avx_ne_convert_support: bool,
287+
pub avx_vnni_int8_support: bool,
288+
pub avx_vnni_int16_support: bool,
289+
pub avx10_1_256_support: bool,
290+
pub avx10_1_512_support: bool,
291+
pub amx_fp16_support: bool,
292+
#[bits(26)]
293+
_reserved: u64,
294+
}
295+
296+
/// Synthetic processor features that control which Hyper-V enlightenments
297+
/// are exposed to a guest partition.
298+
#[bitfield(u64)]
299+
pub struct HvPartitionSyntheticProcessorFeatures {
300+
pub hypervisor_present: bool,
301+
pub hv1: bool,
302+
pub access_vp_run_time_reg: bool,
303+
pub access_partition_reference_counter: bool,
304+
pub access_synic_regs: bool,
305+
pub access_synthetic_timer_regs: bool,
306+
pub access_intr_ctrl_regs: bool,
307+
pub access_hypercall_regs: bool,
308+
pub access_vp_index: bool,
309+
pub access_partition_reference_tsc: bool,
310+
pub access_guest_idle_reg: bool,
311+
pub access_frequency_regs: bool,
312+
_reserved_z12: bool,
313+
_reserved_z13: bool,
314+
_reserved_z14: bool,
315+
pub enable_extended_gva_ranges_for_flush_virtual_address_list: bool,
316+
_reserved_z16: bool,
317+
_reserved_z17: bool,
318+
pub fast_hypercall_output: bool,
319+
_reserved_z19: bool,
320+
pub start_virtual_processor: bool,
321+
_reserved_z21: bool,
322+
pub direct_synthetic_timers: bool,
323+
_reserved_z23: bool,
324+
pub extended_processor_masks: bool,
325+
pub tb_flush_hypercalls: bool,
326+
pub synthetic_cluster_ipi: bool,
327+
pub notify_long_spin_wait: bool,
328+
pub query_numa_distance: bool,
329+
pub signal_events: bool,
330+
pub retarget_device_interrupt: bool,
331+
pub restore_time: bool,
332+
pub enlightened_vmcs: bool,
333+
pub nested_debug_ctl: bool,
334+
pub synthetic_time_unhalted_timer: bool,
335+
pub idle_spec_ctrl: bool,
336+
_reserved_z36: bool,
337+
pub wake_vps: bool,
338+
pub access_vp_regs: bool,
339+
_reserved_z39: bool,
340+
pub management_vtl_synic_support: bool,
341+
pub proxy_interrupt_doorbell_support: bool,
342+
_reserved_z42: bool,
343+
pub mmio_hypercalls: bool,
344+
#[bits(20)]
345+
_reserved: u64,
346+
}
347+
109348
open_enum! {
110349
#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
111350
pub enum HvPartitionIsolationType: u8 {

vmm_core/virt_mshv/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ hv1_hypercall.workspace = true
1313
hvdef.workspace = true
1414
virt.workspace = true
1515
virt_support_x86emu.workspace = true
16+
vm_topology.workspace = true
1617
guestmem.workspace = true
1718
pci_core.workspace = true
1819
vmcore.workspace = true

0 commit comments

Comments
 (0)