mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 20:48:55 +00:00
plugin: do not fail crosvm_vcpu_get_msrs() if we failed to fetch some
KVM_GET_MSRS may return less MSRs that were requested; do not fail but instead let callers to know how many were fetched. BUG=None TEST=cargo test --features plugin Change-Id: Ie14a3d38b66bfe34f5279543bea9c6c78423527e Signed-off-by: Dmitry Torokhov <dtor@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1192232 Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
This commit is contained in:
parent
9dec40e242
commit
caa2e5a4ac
3 changed files with 19 additions and 7 deletions
|
@ -509,7 +509,8 @@ int crosvm_vcpu_set_xcrs(struct crosvm_vcpu*, const struct kvm_xcrs*);
|
|||
|
||||
/* Gets the MSRs of the vcpu indicated by the index field of each entry. */
|
||||
int crosvm_vcpu_get_msrs(struct crosvm_vcpu*, uint32_t __msr_count,
|
||||
struct kvm_msr_entry *__msr_entries);
|
||||
struct kvm_msr_entry *__msr_entries,
|
||||
uint32_t *__out_count);
|
||||
/* Sets the MSRs of the vcpu indicated by the index field of each entry. */
|
||||
int crosvm_vcpu_set_msrs(struct crosvm_vcpu*, uint32_t __msr_count,
|
||||
const struct kvm_msr_entry *__msr_entries);
|
||||
|
|
|
@ -995,7 +995,9 @@ impl crosvm_vcpu {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn get_msrs(&mut self, msr_entries: &mut [kvm_msr_entry]) -> result::Result<(), c_int> {
|
||||
fn get_msrs(&mut self, msr_entries: &mut [kvm_msr_entry], msr_count: &mut usize)
|
||||
-> result::Result<(), c_int> {
|
||||
*msr_count = 0;
|
||||
let mut r = VcpuRequest::new();
|
||||
{
|
||||
let entry_indices: &mut Vec<u32> = r.mut_get_msrs().mut_entry_indices();
|
||||
|
@ -1008,8 +1010,9 @@ impl crosvm_vcpu {
|
|||
return Err(EPROTO);
|
||||
}
|
||||
let get_msrs: &VcpuResponse_GetMsrs = response.get_get_msrs();
|
||||
if get_msrs.get_entry_data().len() != msr_entries.len() {
|
||||
return Err(EPROTO);
|
||||
*msr_count = get_msrs.get_entry_data().len();
|
||||
if *msr_count > msr_entries.len() {
|
||||
return Err(E2BIG);
|
||||
}
|
||||
for (&msr_data, msr_entry) in
|
||||
get_msrs
|
||||
|
@ -1464,12 +1467,15 @@ pub unsafe extern "C" fn crosvm_vcpu_set_xcrs(this: *mut crosvm_vcpu,
|
|||
#[no_mangle]
|
||||
pub unsafe extern "C" fn crosvm_vcpu_get_msrs(this: *mut crosvm_vcpu,
|
||||
msr_count: u32,
|
||||
msr_entries: *mut kvm_msr_entry)
|
||||
msr_entries: *mut kvm_msr_entry,
|
||||
out_count: *mut u32)
|
||||
-> c_int {
|
||||
let _u = STATS.record(Stat::VcpuGetMsrs);
|
||||
let this = &mut *this;
|
||||
let msr_entries = from_raw_parts_mut(msr_entries, msr_count as usize);
|
||||
let ret = this.get_msrs(msr_entries);
|
||||
let mut count: usize = 0;
|
||||
let ret = this.get_msrs(msr_entries, &mut count);
|
||||
*out_count = count as u32;
|
||||
to_crosvm_rc(ret)
|
||||
}
|
||||
|
||||
|
|
|
@ -411,6 +411,7 @@ fn test_msrs() {
|
|||
#define KILL_ADDRESS 0x3000
|
||||
|
||||
int g_kill_evt;
|
||||
uint32_t g_msr2_count;
|
||||
struct kvm_msr_entry g_msr2;
|
||||
|
||||
int setup_vm(struct crosvm *crosvm, void *mem) {
|
||||
|
@ -445,7 +446,7 @@ fn test_msrs() {
|
|||
{
|
||||
uint64_t dummy = 1;
|
||||
g_msr2.index = MSR2_INDEX;
|
||||
crosvm_vcpu_get_msrs(vcpu, 1, &g_msr2);
|
||||
crosvm_vcpu_get_msrs(vcpu, 1, &g_msr2, &g_msr2_count);
|
||||
write(g_kill_evt, &dummy, sizeof(dummy));
|
||||
return 1;
|
||||
}
|
||||
|
@ -458,6 +459,10 @@ fn test_msrs() {
|
|||
fprintf(stderr, "msr1 has unexpected value: 0x%x\n", msr1_data);
|
||||
return 1;
|
||||
}
|
||||
if (g_msr2_count != 1) {
|
||||
fprintf(stderr, "incorrect number of returned MSRSs: %d\n", g_msr2_count);
|
||||
return 1;
|
||||
}
|
||||
if (g_msr2.data != MSR2_DATA) {
|
||||
fprintf(stderr, "msr2 has unexpected value: 0x%x\n", g_msr2.data);
|
||||
return 1;
|
||||
|
|
Loading…
Reference in a new issue