Skip to content

Commit bc66980

Browse files
ppennaCopilot
andcommitted
virt: adapt upstream saved-state tests to the microVM chain
Upstream #5274 added fake VM and VP implementations and XSAVE fixtures. Preserve their assertions with the expanded state accessors, activity and capabilities, typed access errors and fallible XSAVE writes. Run the SYSENTER name test now that the chain fixes its register order; reuse the upstream topology imports. At the next reorganization fold these changes into positions 258, 261, 272, 277, 278, 283, 287, 290, 291, 295, 303 and 304, with each accessor, capability, and assertion alongside its API change. This fixup changes tests only. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 30f1851 commit bc66980

3 files changed

Lines changed: 27 additions & 38 deletions

File tree

‎vmm_core/virt/src/x86/mod.rs‎

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,9 +1160,7 @@ pub(crate) mod tests {
11601160
components: &[(u32, u32, bool)],
11611161
xsave_len: u32,
11621162
) -> Result<X86PartitionCapabilities, X86PartitionCapabilitiesError> {
1163-
let topology = vm_topology::processor::TopologyBuilder::new_x86()
1164-
.build(1)
1165-
.unwrap();
1163+
let topology = TopologyBuilder::new_x86().build(1).unwrap();
11661164
let x2apic = topology.apic_mode() != ApicMode::XApic;
11671165
X86PartitionCapabilities::from_cpuid(
11681166
&topology,
@@ -1363,9 +1361,7 @@ pub(crate) mod tests {
13631361
/// the highest leaves `max_function` and `max_extended`, include the
13641362
/// SPEC_CTRL state.
13651363
fn has_spec_ctrl(max_function: u32, max_extended: u32, leaf7_edx: u32, ext8_ebx: u32) -> bool {
1366-
let topology = vm_topology::processor::TopologyBuilder::new_x86()
1367-
.build(1)
1368-
.unwrap();
1364+
let topology = TopologyBuilder::new_x86().build(1).unwrap();
13691365
let x2apic = topology.apic_mode() != ApicMode::XApic;
13701366
X86PartitionCapabilities::from_cpuid(
13711367
&topology,
@@ -1400,9 +1396,9 @@ pub(crate) mod tests {
14001396
// The time ABI's CPUID helpers exist only for x86-64 guests.
14011397
#[cfg(guest_arch = "x86_64")]
14021398
fn pinned_profile_capabilities() -> Vec<(&'static str, X86PartitionCapabilities)> {
1403-
let topology = vm_topology::processor::TopologyBuilder::new_x86()
1399+
let topology = TopologyBuilder::new_x86()
14041400
.vps_per_socket(2)
1405-
.x2apic(vm_topology::processor::x86::X2ApicState::Supported)
1401+
.x2apic(X2ApicState::Supported)
14061402
.build(2)
14071403
.unwrap();
14081404
cpu_profile::pinned_profiles()
@@ -1452,9 +1448,7 @@ pub(crate) mod tests {
14521448
/// Returns the partition capabilities of a CPU whose highest basic leaf is
14531449
/// `max_function` and whose `CPUID.(7,0):ECX` is `leaf7_ecx`.
14541450
fn capabilities_with_leaf7_ecx(max_function: u32, leaf7_ecx: u32) -> X86PartitionCapabilities {
1455-
let topology = vm_topology::processor::TopologyBuilder::new_x86()
1456-
.build(1)
1457-
.unwrap();
1451+
let topology = TopologyBuilder::new_x86().build(1).unwrap();
14581452
let x2apic = topology.apic_mode() != ApicMode::XApic;
14591453
X86PartitionCapabilities::from_cpuid(
14601454
&topology,
@@ -1504,9 +1498,7 @@ pub(crate) mod tests {
15041498
assert!(!caps.machine_check);
15051499
// KVM on an AMD host takes a guest's writes of VM_CR and VM_HSAVE_PA
15061500
// whether or not its CPUID enumerates SVM.
1507-
let topology = vm_topology::processor::TopologyBuilder::new_x86()
1508-
.build(1)
1509-
.unwrap();
1501+
let topology = TopologyBuilder::new_x86().build(1).unwrap();
15101502
let x2apic = topology.apic_mode() != ApicMode::XApic;
15111503
let with_svm = X86PartitionCapabilities::from_cpuid(
15121504
&topology,
@@ -1539,9 +1531,7 @@ pub(crate) mod tests {
15391531
fn bndcfgs_state_needs_mpx_in_a_leaf_that_the_cpu_has() {
15401532
const MPX: u32 = 1 << 14;
15411533
let has_bndcfgs = |max_function, leaf7_ebx| {
1542-
let topology = vm_topology::processor::TopologyBuilder::new_x86()
1543-
.build(1)
1544-
.unwrap();
1534+
let topology = TopologyBuilder::new_x86().build(1).unwrap();
15451535
let x2apic = topology.apic_mode() != ApicMode::XApic;
15461536
X86PartitionCapabilities::from_cpuid(&topology, &mut |leaf, subleaf| match (
15471537
leaf, subleaf,
@@ -1588,9 +1578,7 @@ pub(crate) mod tests {
15881578
fn osvw_state_needs_osvw_in_a_leaf_that_the_cpu_has() {
15891579
const OSVW: u32 = 1 << 9;
15901580
let has_osvw = |max_extended, ext1_ecx| {
1591-
let topology = vm_topology::processor::TopologyBuilder::new_x86()
1592-
.build(1)
1593-
.unwrap();
1581+
let topology = TopologyBuilder::new_x86().build(1).unwrap();
15941582
let x2apic = topology.apic_mode() != ApicMode::XApic;
15951583
X86PartitionCapabilities::from_cpuid(&topology, &mut |leaf, subleaf| match (
15961584
leaf, subleaf,

‎vmm_core/virt/src/x86/vm.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,10 @@ mod tests {
342342
let phase = |failing, op: fn(&mut FakeVm) -> Result<(), StateError<FakeError>>| {
343343
let mut vm = FakeVm::new(true, false, true);
344344
vm.failing = Some(failing);
345-
op(&mut vm).unwrap_err().phase
345+
match op(&mut vm).unwrap_err() {
346+
StateError::Access { phase, .. } => phase,
347+
err => panic!("expected an access failure, got {err}"),
348+
}
346349
};
347350

348351
assert_eq!(

‎vmm_core/virt/src/x86/vp.rs‎

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3024,6 +3024,7 @@ mod tests {
30243024
parameter: 0xdead_b000,
30253025
}),
30263026
pending_interruption: Some(PendingInterruption::Interrupt { vector: 0x30 }),
3027+
..Default::default()
30273028
},
30283029
Activity {
30293030
mp_state: MpState::WaitForSipi,
@@ -3032,6 +3033,7 @@ mod tests {
30323033
interrupt_shadow: true,
30333034
pending_event: Some(PendingEvent::ExtInt { vector: 0x21 }),
30343035
pending_interruption: Some(PendingInterruption::Nmi),
3036+
..Default::default()
30353037
},
30363038
Activity {
30373039
mp_state: MpState::Idle,
@@ -3047,6 +3049,7 @@ mod tests {
30473049
vector: 13,
30483050
error_code: Some(0),
30493051
}),
3052+
..Default::default()
30503053
},
30513054
Activity {
30523055
mp_state: MpState::Running,
@@ -3058,6 +3061,7 @@ mod tests {
30583061
vector: 6,
30593062
error_code: None,
30603063
}),
3064+
..Default::default()
30613065
},
30623066
] {
30633067
assert_eq!(round_trip(&activity), activity);
@@ -3090,26 +3094,11 @@ mod tests {
30903094
assert_u64_state_round_trips::<SyntheticMsrs, 20>();
30913095
}
30923096

3093-
// IGNORED: this test fails because of a known bug. VirtualMsrs::names() lists
3094-
// SysenterEsp before SysenterEip, but get_values()/set_values() use sysenter_eip
3095-
// before sysenter_esp, so backends that move this state by register name (KVM,
3096-
// mshv, WHP, OpenHCL non-isolated) store the hypervisor's SYSENTER_ESP in the
3097-
// sysenter_eip field and vice versa. Backends that build VirtualMsrs by field
3098-
// (OpenHCL TDX/SNP, KVM SNP) use the correct meaning.
3099-
//
3100-
// Fixing this is a trap: VirtualMsrs is saved by field, so state saved today by
3101-
// a name-based backend already has the two values swapped. Simply reordering
3102-
// names() or get/set would make state saved before the fix restore with EIP and
3103-
// ESP swapped, faulting 32-bit guests on their next SYSENTER. A fix needs
3104-
// saved-state compatibility handling (for example, swapping old saved values on
3105-
// restore). Re-enable this test (remove #[ignore]) together with that fix.
3106-
//
31073097
// Test: Look up each virtual MSR by name, where a consistent swap of two
31083098
// fields between the names list and get/set would still round-trip.
31093099
// Expected: Each named register reports its own field (for example,
31103100
// SysenterEip reports sysenter_eip).
31113101
#[test]
3112-
#[ignore = "known bug: SysenterEip/SysenterEsp names are swapped (see comment)"]
31133102
fn virtual_msrs_report_fields_under_their_names() {
31143103
let msrs = VirtualMsrs {
31153104
kernel_gs_base: 1,
@@ -3239,6 +3228,7 @@ mod tests {
32393228
dr6_tsx_broken: false,
32403229
nxe_forced_on: false,
32413230
nested_virt: false,
3231+
..crate::x86::tests::basic_caps()
32423232
}
32433233
}
32443234

@@ -3299,7 +3289,7 @@ mod tests {
32993289

33003290
let xsave = Xsave::from_standard(&standard, &caps);
33013291
let mut out = vec![0; standard.len()];
3302-
xsave.write_standard(&mut out, &caps);
3292+
xsave.write_standard(&mut out, &caps).unwrap();
33033293

33043294
assert!(out == standard, "standard format did not round-trip");
33053295
let compact = xsave.compact();
@@ -3342,7 +3332,7 @@ mod tests {
33423332

33433333
let xsave = Xsave::from_standard(&standard, &caps);
33443334
let mut out = vec![0; standard.len()];
3345-
xsave.write_standard(&mut out, &caps);
3335+
xsave.write_standard(&mut out, &caps).unwrap();
33463336

33473337
let compact = xsave.compact();
33483338
assert!(
@@ -3887,6 +3877,14 @@ mod tests {
38873877
mtrrs set_mtrrs Mtrrs,
38883878
pat set_pat Pat,
38893879
virtual_msrs set_virtual_msrs VirtualMsrs,
3880+
spec_ctrl set_spec_ctrl SpecCtrl,
3881+
umwait_control set_umwait_control UmwaitControl,
3882+
debug_ctl set_debug_ctl DebugCtl,
3883+
misc_msrs set_misc_msrs MiscMsrs,
3884+
machine_check set_machine_check MachineCheck,
3885+
bndcfgs set_bndcfgs Bndcfgs,
3886+
svm_msrs set_svm_msrs SvmMsrs,
3887+
osvw set_osvw Osvw,
38903888
tsc set_tsc Tsc,
38913889
cet set_cet Cet,
38923890
cet_ss set_cet_ss CetSs,

0 commit comments

Comments
 (0)