From 688ead51c6472c28f43dff5dbd1a0107dbbc70b5 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 9 Feb 2021 14:39:50 +0000 Subject: [PATCH] vmm, arch: Move CPU identification handling to shared CPUID code Move the code for populating the CPUID with details of the CPU identification from the per-vCPU CPUID handling code to the shared CPUID handling code. Signed-off-by: Rob Bradford --- arch/src/x86_64/mod.rs | 16 ---------------- vmm/src/cpu.rs | 20 ++++++++++++++++++-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/arch/src/x86_64/mod.rs b/arch/src/x86_64/mod.rs index 75486e8b2..de8e86c08 100644 --- a/arch/src/x86_64/mod.rs +++ b/arch/src/x86_64/mod.rs @@ -393,22 +393,6 @@ pub fn configure_vcpu( } } - // Copy CPU identification string - for i in 0x8000_0002..=0x8000_0004 { - cpuid.retain(|c| c.function != i); - let leaf = unsafe { x86_64::__cpuid(i) }; - cpuid - .push(CpuIdEntry { - function: i, - eax: leaf.eax, - ebx: leaf.ebx, - ecx: leaf.ecx, - edx: leaf.edx, - ..Default::default() - }) - .map_err(|_| Error::PopulatingCpuid)?; - } - fd.set_cpuid2(&cpuid) .map_err(|e| Error::SetSupportedCpusFailed(e.into()))?; diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index 5e8ea44f4..1de8e6065 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -31,9 +31,9 @@ use arch::EntryPoint; use devices::interrupt_controller::InterruptController; #[cfg(target_arch = "aarch64")] use hypervisor::kvm::kvm_bindings; -#[cfg(target_arch = "x86_64")] -use hypervisor::CpuId; use hypervisor::{vm::VmmOps, CpuState, HypervisorCpuError, VmExit}; +#[cfg(target_arch = "x86_64")] +use hypervisor::{CpuId, CpuIdEntry}; use libc::{c_void, siginfo_t}; use seccomp::{SeccompAction, SeccompFilter}; use std::os::unix::thread::JoinHandleExt; @@ -667,6 +667,22 @@ impl CpuManager { } } + // Copy CPU identification string + for i in 0x8000_0002..=0x8000_0004 { + cpuid.retain(|c| c.function != i); + let leaf = unsafe { std::arch::x86_64::__cpuid(i) }; + cpuid + .push(CpuIdEntry { + function: i, + eax: leaf.eax, + ebx: leaf.ebx, + ecx: leaf.ecx, + edx: leaf.edx, + ..Default::default() + }) + .unwrap(); + } + Ok(cpuid) }