From 719cae217e215449057ffcd8ba325781f4f68254 Mon Sep 17 00:00:00 2001 From: Jinank Jain Date: Wed, 20 Mar 2024 08:54:06 +0530 Subject: [PATCH] hypervisor: mshv: Restrict MSR and CPUID visbility for MshvVcpu to x86 MSR and CPUID are limited to x86 architecture so, reduce the visbility of these two members inside struct MshvVcpu to just x86 architecture. Signed-off-by: Jinank Jain --- hypervisor/src/mshv/mod.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index 1984911b1..ac5792979 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -359,7 +359,9 @@ impl hypervisor::Hypervisor for MshvHypervisor { pub struct MshvVcpu { fd: VcpuFd, vp_index: u8, + #[cfg(target_arch = "x86_64")] cpuid: Vec, + #[cfg(target_arch = "x86_64")] msrs: Vec, vm_ops: Option>, vm_fd: Arc, @@ -1228,8 +1230,9 @@ impl cpu::Vcpu for MshvVcpu { Ok(()) } + #[cfg(target_arch = "x86_64")] /// - /// Set CPU state + /// Set CPU state for x86_64 guest. /// fn set_state(&self, state: &CpuState) -> cpu::Result<()> { let state: VcpuMshvState = state.clone().into(); @@ -1254,8 +1257,17 @@ impl cpu::Vcpu for MshvVcpu { Ok(()) } + #[cfg(target_arch = "aarch64")] /// - /// Get CPU State + /// Set CPU state for aarch64 guest. + /// + fn set_state(&self, state: &CpuState) -> cpu::Result<()> { + unimplemented!() + } + + #[cfg(target_arch = "x86_64")] + /// + /// Get CPU State for x86_64 guest /// fn state(&self) -> cpu::Result { let regs = self.get_regs()?; @@ -1291,6 +1303,14 @@ impl cpu::Vcpu for MshvVcpu { .into()) } + #[cfg(target_arch = "aarch64")] + /// + /// Get CPU state for aarch64 guest. + /// + fn state(&self) -> cpu::Result { + unimplemented!() + } + #[cfg(target_arch = "x86_64")] /// /// Translate guest virtual address to guest physical address @@ -1649,7 +1669,9 @@ impl vm::Vm for MshvVm { let vcpu = MshvVcpu { fd: vcpu_fd, vp_index: id, + #[cfg(target_arch = "x86_64")] cpuid: Vec::new(), + #[cfg(target_arch = "x86_64")] msrs: self.msrs.clone(), vm_ops, vm_fd: self.fd.clone(),