vmentry.rs0.00%
1
// Copyright 2024 Google LLC2
//3
// Licensed under the Apache License, Version 2.0 (the "License");4
// you may not use this file except in compliance with the License.5
// You may obtain a copy of the License at6
//7
// https://www.apache.org/licenses/LICENSE-2.08
//9
// Unless required by applicable law or agreed to in writing, software10
// distributed under the License is distributed on an "AS IS" BASIS,11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12
// See the License for the specific language governing permissions and13
// limitations under the License.14
15
#[cfg(target_arch = "x86_64")]16
use crate::hv::VmExit;17
use crate::hv::kvm::vcpu::KvmVcpu;18
#[cfg(target_arch = "x86_64")]19
use crate::sys::kvm::{KvmExit, KvmRunExitIo};20
21
impl KvmVcpu {22
#[cfg(target_endian = "little")]23
pub(super) fn entry_mmio(&mut self, data: u64) {24
use crate::sys::kvm::KvmExit;25
26
assert_eq!(self.kvm_run.exit_reason, KvmExit::MMIO);27
let kvm_mmio = unsafe { &mut self.kvm_run.exit.mmio };28
assert_eq!(kvm_mmio.is_write, 0);29
kvm_mmio.data = data.to_ne_bytes();30
}31
32
pub(super) fn set_immediate_exit(&mut self, enable: bool) {33
self.kvm_run.immediate_exit = enable as u8;34
}35
36
#[cfg(target_arch = "x86_64")]37
fn entry_io_in(&mut self, data: u32, kvm_io: KvmRunExitIo) {38
let offset = kvm_io.data_offset as usize;39
let count = kvm_io.count as usize;40
let index = self.arch.io_index;41
match kvm_io.size {42
1 => unsafe {43
self.kvm_run.data_slice_mut(offset, count)[index] = data as u8;44
},45
2 => unsafe {46
self.kvm_run.data_slice_mut(offset, count)[index] = data as u16;47
},48
4 => unsafe {49
self.kvm_run.data_slice_mut(offset, count)[index] = data;50
},51
_ => unreachable!("kvm_io.size = {}", kvm_io.size),52
}53
}54
55
#[cfg(target_arch = "x86_64")]56
pub(super) fn entry_io(&mut self, data: Option<u32>) -> Option<VmExit> {57
assert_eq!(self.kvm_run.exit_reason, KvmExit::IO);58
let kvm_io = unsafe { self.kvm_run.exit.io };59
if let Some(data) = data {60
self.entry_io_in(data, kvm_io);61
}62
self.arch.io_index += 1;63
if self.arch.io_index == kvm_io.count as usize {64
self.arch.io_index = 0;65
return None;66
}67
Some(self.handle_io())68
}69
}70