mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-10-23 20:59:45 +00:00
crosvm: Simplify MSR filter.
Don't use box and just use an array. BUG=b:229770963 TEST=build Change-Id: I8121e4809e418d7f3e1aa876d567e543ee50693c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3675887 Commit-Queue: Junichi Uekawa <uekawa@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
5d6d595116
commit
6d26fef1d6
1 changed files with 6 additions and 19 deletions
|
@ -360,10 +360,10 @@ impl KvmVm {
|
|||
pub fn set_msr_filter(&self, msr_list: (Vec<u32>, Vec<u32>)) -> Result<()> {
|
||||
let mut rd_nmsrs: u32 = 0;
|
||||
let mut wr_nmsrs: u32 = 0;
|
||||
let mut rd_msr_bitmap: Box<[u8; KVM_MSR_FILTER_RANGE_MAX_BYTES]> =
|
||||
Box::new([0xff; KVM_MSR_FILTER_RANGE_MAX_BYTES]);
|
||||
let mut wr_msr_bitmap: Box<[u8; KVM_MSR_FILTER_RANGE_MAX_BYTES]> =
|
||||
Box::new([0xff; KVM_MSR_FILTER_RANGE_MAX_BYTES]);
|
||||
let mut rd_msr_bitmap: [u8; KVM_MSR_FILTER_RANGE_MAX_BYTES] =
|
||||
[0xff; KVM_MSR_FILTER_RANGE_MAX_BYTES];
|
||||
let mut wr_msr_bitmap: [u8; KVM_MSR_FILTER_RANGE_MAX_BYTES] =
|
||||
[0xff; KVM_MSR_FILTER_RANGE_MAX_BYTES];
|
||||
let (rd_msrs, wr_msrs) = msr_list;
|
||||
|
||||
for index in rd_msrs {
|
||||
|
@ -395,18 +395,14 @@ impl KvmVm {
|
|||
msr_filter.ranges[count].flags = KVM_MSR_FILTER_READ;
|
||||
msr_filter.ranges[count].nmsrs = KVM_MSR_FILTER_RANGE_MAX_BITS as u32;
|
||||
msr_filter.ranges[count].base = 0x0;
|
||||
// The ownership of the box is moved to bitmap raw pointer,
|
||||
// it needs to be freed explicitly later
|
||||
msr_filter.ranges[count].bitmap = Box::into_raw(rd_msr_bitmap) as *mut u8;
|
||||
msr_filter.ranges[count].bitmap = rd_msr_bitmap.as_mut_ptr();
|
||||
count += 1;
|
||||
}
|
||||
if wr_nmsrs > 0 {
|
||||
msr_filter.ranges[count].flags = KVM_MSR_FILTER_WRITE;
|
||||
msr_filter.ranges[count].nmsrs = KVM_MSR_FILTER_RANGE_MAX_BITS as u32;
|
||||
msr_filter.ranges[count].base = 0x0;
|
||||
// The ownership of the box is moved to bitmap raw pointer,
|
||||
// it needs to be freed explicitly later
|
||||
msr_filter.ranges[count].bitmap = Box::into_raw(wr_msr_bitmap) as *mut u8;
|
||||
msr_filter.ranges[count].bitmap = wr_msr_bitmap.as_mut_ptr();
|
||||
count += 1;
|
||||
}
|
||||
|
||||
|
@ -418,15 +414,6 @@ impl KvmVm {
|
|||
ret = unsafe { ioctl_with_ref(self, KVM_X86_SET_MSR_FILTER(), &msr_filter) };
|
||||
}
|
||||
|
||||
// convert the raw pointer to a Box for automatic cleanup
|
||||
for index in 0..count {
|
||||
let _bitmap = unsafe {
|
||||
Box::from_raw(
|
||||
msr_filter.ranges[index].bitmap as *mut [u8; KVM_MSR_FILTER_RANGE_MAX_BYTES],
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
if ret < 0 {
|
||||
errno_result()
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue