hypervisor: Implement StandardRegisters as union of KVM & MSHV

Currently we are redefining StandardRegisters instead of using the ones
coming from bindings. With this we can remove the unnecessary
construction of global structure which contains fields from different
hypervisor dependent structs.

Signed-off-by: Jinank Jain <jinankjain@microsoft.com>
This commit is contained in:
Jinank Jain 2024-08-01 12:00:59 +00:00 committed by Bo Chen
parent 3645654c39
commit feb0a36067
3 changed files with 42 additions and 0 deletions

View File

@ -337,6 +337,23 @@ impl From<ClockData> for kvm_clock_data {
}
}
impl From<kvm_bindings::kvm_regs> for crate::StandardRegisters {
fn from(s: kvm_bindings::kvm_regs) -> Self {
crate::StandardRegisters::Kvm(s)
}
}
impl From<crate::StandardRegisters> for kvm_bindings::kvm_regs {
fn from(e: crate::StandardRegisters) -> Self {
match e {
crate::StandardRegisters::Kvm(e) => e,
/* Needed in case other hypervisors are enabled */
#[allow(unreachable_patterns)]
_ => panic!("StandardRegisters are not valid"),
}
}
}
impl From<kvm_irq_routing_entry> for IrqRoutingEntry {
fn from(s: kvm_irq_routing_entry) -> Self {
IrqRoutingEntry::Kvm(s)

View File

@ -187,3 +187,11 @@ pub enum IrqRoutingEntry {
#[cfg(feature = "mshv")]
Mshv(mshv_bindings::mshv_msi_routing_entry),
}
#[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum StandardRegisters {
#[cfg(feature = "kvm")]
Kvm(kvm_bindings::kvm_regs),
#[cfg(all(feature = "mshv", target_arch = "x86_64"))]
Mshv(mshv_bindings::StandardRegisters),
}

View File

@ -165,6 +165,23 @@ impl From<CpuState> for VcpuMshvState {
}
}
impl From<mshv_bindings::StandardRegisters> for crate::StandardRegisters {
fn from(s: mshv_bindings::StandardRegisters) -> Self {
crate::StandardRegisters::Mshv(s)
}
}
impl From<crate::StandardRegisters> for mshv_bindings::StandardRegisters {
fn from(e: crate::StandardRegisters) -> Self {
match e {
crate::StandardRegisters::Mshv(e) => e,
/* Needed in case other hypervisors are enabled */
#[allow(unreachable_patterns)]
_ => panic!("StandardRegisters are not valid"),
}
}
}
impl From<mshv_msi_routing_entry> for IrqRoutingEntry {
fn from(s: mshv_msi_routing_entry) -> Self {
IrqRoutingEntry::Mshv(s)