From c8d9a43072161fd0b14ae624f23c9e9f829381bc Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Fri, 15 Jul 2022 16:53:34 +0000 Subject: [PATCH] hypervisor: x86: drop get/set Xsave from Vcpu trait They are only needed internally within the hypervisor crate. Signed-off-by: Wei Liu --- hypervisor/src/cpu.rs | 12 ------------ hypervisor/src/kvm/mod.rs | 39 ++++++++++++++++++++------------------ hypervisor/src/mshv/mod.rs | 39 ++++++++++++++++++++------------------ 3 files changed, 42 insertions(+), 48 deletions(-) diff --git a/hypervisor/src/cpu.rs b/hypervisor/src/cpu.rs index 251a2bc46..2c27b62f0 100644 --- a/hypervisor/src/cpu.rs +++ b/hypervisor/src/cpu.rs @@ -19,8 +19,6 @@ use crate::kvm::{TdxExitDetails, TdxExitStatus}; #[cfg(target_arch = "x86_64")] use crate::x86_64::LapicState; #[cfg(target_arch = "x86_64")] -use crate::x86_64::Xsave; -#[cfg(target_arch = "x86_64")] use crate::x86_64::{ExtendedControlRegisters, MsrEntries, VcpuEvents}; use crate::CpuState; #[cfg(target_arch = "aarch64")] @@ -353,16 +351,6 @@ pub trait Vcpu: Send + Sync { fn set_mp_state(&self, mp_state: MpState) -> Result<()>; #[cfg(target_arch = "x86_64")] /// - /// X86 specific call that returns the vcpu's current "xsave struct". - /// - fn get_xsave(&self) -> Result; - #[cfg(target_arch = "x86_64")] - /// - /// X86 specific call that sets the vcpu's current "xsave struct". - /// - fn set_xsave(&self, xsave: &Xsave) -> Result<()>; - #[cfg(target_arch = "x86_64")] - /// /// X86 specific call that returns the vcpu's current "xcrs". /// fn get_xcrs(&self) -> Result; diff --git a/hypervisor/src/kvm/mod.rs b/hypervisor/src/kvm/mod.rs index 19c328456..4129d4b68 100644 --- a/hypervisor/src/kvm/mod.rs +++ b/hypervisor/src/kvm/mod.rs @@ -1426,24 +1426,6 @@ impl cpu::Vcpu for KvmVcpu { } #[cfg(target_arch = "x86_64")] /// - /// X86 specific call that returns the vcpu's current "xsave struct". - /// - fn get_xsave(&self) -> cpu::Result { - self.fd - .get_xsave() - .map_err(|e| cpu::HypervisorCpuError::GetXsaveState(e.into())) - } - #[cfg(target_arch = "x86_64")] - /// - /// X86 specific call that sets the vcpu's current "xsave struct". - /// - fn set_xsave(&self, xsave: &Xsave) -> cpu::Result<()> { - self.fd - .set_xsave(xsave) - .map_err(|e| cpu::HypervisorCpuError::SetXsaveState(e.into())) - } - #[cfg(target_arch = "x86_64")] - /// /// X86 specific call that returns the vcpu's current "xcrs". /// fn get_xcrs(&self) -> cpu::Result { @@ -2105,6 +2087,27 @@ impl cpu::Vcpu for KvmVcpu { } } +impl KvmVcpu { + #[cfg(target_arch = "x86_64")] + /// + /// X86 specific call that returns the vcpu's current "xsave struct". + /// + fn get_xsave(&self) -> cpu::Result { + self.fd + .get_xsave() + .map_err(|e| cpu::HypervisorCpuError::GetXsaveState(e.into())) + } + #[cfg(target_arch = "x86_64")] + /// + /// X86 specific call that sets the vcpu's current "xsave struct". + /// + fn set_xsave(&self, xsave: &Xsave) -> cpu::Result<()> { + self.fd + .set_xsave(xsave) + .map_err(|e| cpu::HypervisorCpuError::SetXsaveState(e.into())) + } +} + /// Device struct for KVM pub type KvmDevice = DeviceFd; diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index 84d48f6c8..83ee51dfc 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -606,24 +606,6 @@ impl cpu::Vcpu for MshvVcpu { fn set_mp_state(&self, _mp_state: MpState) -> cpu::Result<()> { Ok(()) } - #[cfg(target_arch = "x86_64")] - /// - /// X86 specific call that returns the vcpu's current "xsave struct". - /// - fn get_xsave(&self) -> cpu::Result { - self.fd - .get_xsave() - .map_err(|e| cpu::HypervisorCpuError::GetXsaveState(e.into())) - } - #[cfg(target_arch = "x86_64")] - /// - /// X86 specific call that sets the vcpu's current "xsave struct". - /// - fn set_xsave(&self, xsave: &Xsave) -> cpu::Result<()> { - self.fd - .set_xsave(xsave) - .map_err(|e| cpu::HypervisorCpuError::SetXsaveState(e.into())) - } /// /// Set CPU state /// @@ -724,6 +706,27 @@ impl cpu::Vcpu for MshvVcpu { } } +impl MshvVcpu { + #[cfg(target_arch = "x86_64")] + /// + /// X86 specific call that returns the vcpu's current "xsave struct". + /// + fn get_xsave(&self) -> cpu::Result { + self.fd + .get_xsave() + .map_err(|e| cpu::HypervisorCpuError::GetXsaveState(e.into())) + } + #[cfg(target_arch = "x86_64")] + /// + /// X86 specific call that sets the vcpu's current "xsave struct". + /// + fn set_xsave(&self, xsave: &Xsave) -> cpu::Result<()> { + self.fd + .set_xsave(xsave) + .map_err(|e| cpu::HypervisorCpuError::SetXsaveState(e.into())) + } +} + /// Device struct for MSHV pub type MshvDevice = DeviceFd;