mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
hypervisor x86: provide a generic LapicState structure
This requires making get/set_lapic_reg part of the type. For the moment we cannot provide a default variant for the new type, because picking one will be wrong for the other hypervisor, so I just drop the test cases that requires LapicState::default(). Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
@@ -47,7 +47,7 @@ use vmm_sys_util::eventfd::EventFd;
|
||||
pub mod x86_64;
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use crate::arch::x86::{
|
||||
CpuIdEntry, FpuState, SpecialRegisters, StandardRegisters, NUM_IOAPIC_PINS,
|
||||
CpuIdEntry, FpuState, LapicState, SpecialRegisters, StandardRegisters, NUM_IOAPIC_PINS,
|
||||
};
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use crate::ClockData;
|
||||
@@ -65,7 +65,7 @@ use kvm_bindings::{
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use x86_64::check_required_kvm_extensions;
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub use x86_64::{CpuId, ExtendedControlRegisters, LapicState, MsrEntries, VcpuKvmState, Xsave};
|
||||
pub use x86_64::{CpuId, ExtendedControlRegisters, MsrEntries, VcpuKvmState, Xsave};
|
||||
// aarch64 dependencies
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
pub mod aarch64;
|
||||
@@ -1374,17 +1374,20 @@ impl cpu::Vcpu for KvmVcpu {
|
||||
/// Returns the state of the LAPIC (Local Advanced Programmable Interrupt Controller).
|
||||
///
|
||||
fn get_lapic(&self) -> cpu::Result<LapicState> {
|
||||
self.fd
|
||||
Ok(self
|
||||
.fd
|
||||
.get_lapic()
|
||||
.map_err(|e| cpu::HypervisorCpuError::GetlapicState(e.into()))
|
||||
.map_err(|e| cpu::HypervisorCpuError::GetlapicState(e.into()))?
|
||||
.into())
|
||||
}
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
///
|
||||
/// Sets the state of the LAPIC (Local Advanced Programmable Interrupt Controller).
|
||||
///
|
||||
fn set_lapic(&self, klapic: &LapicState) -> cpu::Result<()> {
|
||||
let klapic: kvm_bindings::kvm_lapic_state = (*klapic).clone().into();
|
||||
self.fd
|
||||
.set_lapic(klapic)
|
||||
.set_lapic(&klapic)
|
||||
.map_err(|e| cpu::HypervisorCpuError::SetLapicState(e.into()))
|
||||
}
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
//
|
||||
|
||||
use crate::arch::x86::{
|
||||
CpuIdEntry, DescriptorTable, FpuState, SegmentRegister, SpecialRegisters, StandardRegisters,
|
||||
CPUID_FLAG_VALID_INDEX,
|
||||
CpuIdEntry, DescriptorTable, FpuState, LapicState, SegmentRegister, SpecialRegisters,
|
||||
StandardRegisters, CPUID_FLAG_VALID_INDEX,
|
||||
};
|
||||
use crate::kvm::{Cap, Kvm, KvmError, KvmResult};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -20,7 +20,7 @@ use serde::{Deserialize, Serialize};
|
||||
///
|
||||
pub use {
|
||||
kvm_bindings::kvm_cpuid_entry2, kvm_bindings::kvm_dtable, kvm_bindings::kvm_fpu,
|
||||
kvm_bindings::kvm_lapic_state as LapicState, kvm_bindings::kvm_mp_state as MpState,
|
||||
kvm_bindings::kvm_lapic_state, kvm_bindings::kvm_mp_state as MpState,
|
||||
kvm_bindings::kvm_msr_entry as MsrEntry, kvm_bindings::kvm_regs, kvm_bindings::kvm_segment,
|
||||
kvm_bindings::kvm_sregs, kvm_bindings::kvm_vcpu_events as VcpuEvents,
|
||||
kvm_bindings::kvm_xcrs as ExtendedControlRegisters, kvm_bindings::kvm_xsave as Xsave,
|
||||
@@ -295,3 +295,20 @@ impl From<FpuState> for kvm_fpu {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<LapicState> for kvm_lapic_state {
|
||||
fn from(s: LapicState) -> Self {
|
||||
match s {
|
||||
LapicState::Kvm(s) => s,
|
||||
/* Needed in case other hypervisors are enabled */
|
||||
#[allow(unreachable_patterns)]
|
||||
_ => panic!("LapicState is not valid"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<kvm_lapic_state> for LapicState {
|
||||
fn from(s: kvm_lapic_state) -> Self {
|
||||
LapicState::Kvm(s)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user