hypervisor: kvm: verify get_all_msrs gets all the MSRs

`get_msrs` truncates the vector on partial success.

Haven't seen this fail. Adding the check as a precaution.

Change-Id: I7c3a4c2408daa9d7a00257ae758da45011a40311
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4515456
Reviewed-by: Elie Kheirallah <khei@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
This commit is contained in:
Frederick Mayle 2023-05-08 12:49:16 -07:00 committed by crosvm LUCI
parent 2d7bb01a4b
commit 6cc983d3f5

View file

@ -886,13 +886,22 @@ impl VcpuX86_64 for KvmVcpu {
}
fn get_all_msrs(&self) -> Result<Vec<Register>> {
let mut msrs = self
let mut msrs: Vec<_> = self
.kvm
.get_msr_index_list()?
.into_iter()
.map(|i| Register { id: i, value: 0 })
.collect();
let count = msrs.len();
self.get_msrs(&mut msrs)?;
if msrs.len() != count {
error!(
"failed to get all MSRs: requested {}, got {}",
count,
msrs.len()
);
return Err(base::Error::new(libc::EPERM));
}
Ok(msrs)
}