Skip to content

Commit

Permalink
change filter_cpuid method signature
Browse files Browse the repository at this point in the history
Signed-off-by: Serban Iorga <[email protected]>
  • Loading branch information
Serban Iorga authored and andreeaflorescu committed Jul 2, 2019
1 parent 148f774 commit 302f3bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
22 changes: 8 additions & 14 deletions cpuid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,38 @@ pub use template::t2;
mod cpu_leaf;

mod transformer;
pub use transformer::Error;
use transformer::*;
pub use transformer::{Error, VmSpec};

mod brand_string;

/// Sets up the CPUID entries for the given vcpu.
///
/// # Arguments
///
/// * `cpu_id` - The index of the VCPU for which the CPUID entries are configured.
/// * `cpu_count` - The total number of present VCPUs.
/// * `ht_enabled` - Whether or not to enable HT.
/// * `kvm_cpuid` - KVM related structure holding the relevant CPUID info.
/// * `vm_spec` - The specifications of the VM.
///
/// # Example
/// ```
/// extern crate cpuid;
/// extern crate kvm_ioctls;
///
/// use cpuid::filter_cpuid;
/// use cpuid::{filter_cpuid, VmSpec};
/// use kvm_ioctls::{CpuId, Kvm, MAX_KVM_CPUID_ENTRIES};
///
/// let kvm = Kvm::new().unwrap();
/// let mut kvm_cpuid: CpuId = kvm.get_supported_cpuid(MAX_KVM_CPUID_ENTRIES).unwrap();
/// filter_cpuid(0, 1, true, &mut kvm_cpuid).unwrap();
///
/// let vm_spec = VmSpec::new(0, 1, true).unwrap();
///
/// filter_cpuid(&mut kvm_cpuid, &vm_spec).unwrap();
///
/// // Get expected `kvm_cpuid` entries.
/// let entries = kvm_cpuid.mut_entries_slice();
/// ```
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub fn filter_cpuid(
cpu_id: u8,
cpu_count: u8,
ht_enabled: bool,
kvm_cpuid: &mut CpuId,
) -> Result<(), Error> {
let vm_spec = VmSpec::new(cpu_id, cpu_count, ht_enabled)?;

pub fn filter_cpuid(kvm_cpuid: &mut CpuId, vm_spec: &VmSpec) -> Result<(), Error> {
let maybe_cpuid_transformer: Option<&dyn CpuidTransformer> = match vm_spec.cpu_vendor_id() {
VENDOR_ID_INTEL => Some(&intel::IntelCpuidTransformer {}),
VENDOR_ID_AMD => Some(&amd::AmdCpuidTransformer {}),
Expand Down
8 changes: 4 additions & 4 deletions vmm/src/vstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::sync::{Arc, Barrier};
use super::{KvmContext, TimestampUs};
use arch;
#[cfg(target_arch = "x86_64")]
use cpuid::{c3, filter_cpuid, t2};
use cpuid::{c3, filter_cpuid, t2, VmSpec};
use default_syscalls;
use kvm_bindings::{kvm_pit_config, kvm_userspace_memory_region, KVM_PIT_SPEAKER_DUMMY};
use kvm_ioctls::*;
Expand Down Expand Up @@ -253,17 +253,17 @@ impl Vcpu {
kernel_start_addr: GuestAddress,
vm: &Vm,
) -> Result<()> {
// the MachineConfiguration has defaults for ht_enabled and vcpu_count hence it is safe to unwrap
filter_cpuid(
let cpuid_vm_spec = VmSpec::new(
self.id,
machine_config
.vcpu_count
.ok_or(Error::VcpuCountNotInitialized)?,
machine_config.ht_enabled.ok_or(Error::HTNotInitialized)?,
&mut self.cpuid,
)
.map_err(Error::CpuId)?;

filter_cpuid(&mut self.cpuid, &cpuid_vm_spec).map_err(Error::CpuId)?;

if let Some(template) = machine_config.cpu_template {
match template {
CpuFeaturesTemplate::T2 => t2::set_cpuid_entries(self.cpuid.mut_entries_slice()),
Expand Down

0 comments on commit 302f3bc

Please sign in to comment.