Skip to content

Commit a9ad576

Browse files
committed
refactor(vmm): Print MSR index on failure
`KVM_GET_MSRS` fails in the middle when the given MSR list contains undumpable MSR indices. Printing the undumpable MSR index would be helpful for debugging. Signed-off-by: Takahiro Itazuri <[email protected]>
1 parent 0f22644 commit a9ad576

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/vmm/src/vstate/vcpu/x86_64.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ pub enum KvmVcpuError {
5757
VcpuGetLapic(kvm_ioctls::Error),
5858
/// Failed to get KVM vcpu mp state: {0}
5959
VcpuGetMpState(kvm_ioctls::Error),
60-
/// Unexpected number of MSRS reported by the kernel
61-
VcpuGetMsrsIncomplete,
60+
/// Failed to get KVM vcpu msr: 0x{0:x}
61+
VcpuGetMsr(u32),
6262
/// Failed to get KVM vcpu msrs: {0}
6363
VcpuGetMsrs(kvm_ioctls::Error),
6464
/// Failed to get KVM vcpu regs: {0}
@@ -321,7 +321,7 @@ impl KvmVcpu {
321321
.get_msrs(&mut msrs)
322322
.map_err(KvmVcpuError::VcpuGetMsrs)?;
323323
if nmsrs != expected_nmsrs {
324-
return Err(KvmVcpuError::VcpuGetMsrsIncomplete);
324+
return Err(KvmVcpuError::VcpuGetMsr(msr_index_chunk[nmsrs]));
325325
}
326326

327327
msr_chunks.push(msrs);
@@ -928,18 +928,17 @@ mod tests {
928928

929929
#[test]
930930
fn test_get_msrs_with_invalid_msr_index() {
931-
// Test `get_msrs()` with unsupported MSR indices. This should return
932-
// `VcpuGetMsrsIncomplete` error that happens when `KVM_GET_MSRS` fails to populdate
933-
// MSR value in the middle and exits. Currently, MSR indices 2..=4 are not listed as
934-
// supported MSRs.
931+
// Test `get_msrs()` with unsupported MSR indices. This should return `VcpuGetMsr` error
932+
// that happens when `KVM_GET_MSRS` fails to populate MSR values in the middle and exits.
933+
// Currently, MSR indices 2..=4 are not listed as supported MSRs.
935934
let (_, vcpu, _) = setup_vcpu(0x1000);
936935
let msr_index_list: Vec<u32> = vec![2, 3, 4];
937936
match vcpu.get_msrs(&msr_index_list) {
938-
Err(KvmVcpuError::VcpuGetMsrsIncomplete) => (),
937+
Err(KvmVcpuError::VcpuGetMsr(_)) => (),
939938
Err(err) => panic!("Unexpected error: {err}"),
940-
Ok(_) => panic!(
941-
"KvmVcpu::get_msrs() for unsupported MSRs should fail with VcpuGetMsrsIncomplete."
942-
),
939+
Ok(_) => {
940+
panic!("KvmVcpu::get_msrs() for unsupported MSRs should fail with VcpuGetMsr.")
941+
}
943942
}
944943
}
945944
}

0 commit comments

Comments
 (0)