Skip to content

Commit

Permalink
refactor(vmm): replace static CPU templates for x86_64
Browse files Browse the repository at this point in the history
Replace the static CPU templates introduced in PR firecracker-microvm#3076 with ones that
are introduced in PR firecracker-microvm#3598, are compatibile with main branch and are
defined using `CustomCpuTemplate`.

Signed-off-by: Takahiro Itazuri <[email protected]>
  • Loading branch information
zulinx86 committed Apr 17, 2023
1 parent be8a45e commit 86d7e69
Show file tree
Hide file tree
Showing 13 changed files with 584 additions and 4,325 deletions.
2 changes: 1 addition & 1 deletion src/vmm/src/guest_config/templates/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::{CpuTemplateType, GetCpuTemplate, GetCpuTemplateError, StaticCpuTempl
use crate::guest_config::cpuid::common::get_vendor_id_from_host;
use crate::guest_config::cpuid::cpuid_ffi::KvmCpuidFlags;
use crate::guest_config::cpuid::{VENDOR_ID_AMD, VENDOR_ID_INTEL};
use crate::guest_config::x86_64::static_cpu_templates_new::{c3, t2, t2a, t2cl, t2s};
use crate::guest_config::x86_64::static_cpu_templates::{c3, t2, t2a, t2cl, t2s};

impl GetCpuTemplate for Option<CpuTemplateType> {
fn get_cpu_template(&self) -> Result<Cow<CustomCpuTemplate>, GetCpuTemplateError> {
Expand Down
21 changes: 14 additions & 7 deletions src/vmm/src/guest_config/x86_64/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// Copyright 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

/// Module with CPU templates for x86_64
pub mod static_cpu_templates;

/// Module for static CPU templates for x86_64
pub mod static_cpu_templates_new;
pub mod static_cpu_templates;

use std::collections::HashMap;

Expand Down Expand Up @@ -115,7 +112,7 @@ mod tests {
use kvm_bindings::KVM_CPUID_FLAG_STATEFUL_FUNC;

use super::*;
use crate::guest_config::cpuid::{IntelCpuid, KvmCpuidFlags};
use crate::guest_config::cpuid::{CpuidEntry, IntelCpuid, KvmCpuidFlags};
use crate::guest_config::templates::x86_64::{
CpuidLeafModifier, CpuidRegisterModifier, RegisterModifier, RegisterValueFilter,
};
Expand Down Expand Up @@ -176,6 +173,16 @@ mod tests {
}
}

fn build_supported_cpuid() -> Cpuid {
Cpuid::Intel(IntelCpuid(BTreeMap::from([(
CpuidKey {
leaf: 0x3,
subleaf: 0x0,
},
CpuidEntry::default(),
)])))
}

fn empty_cpu_config() -> CpuConfiguration {
CpuConfiguration {
cpuid: Cpuid::Intel(IntelCpuid(BTreeMap::new())),
Expand All @@ -185,14 +192,14 @@ mod tests {

fn supported_cpu_config() -> CpuConfiguration {
CpuConfiguration {
cpuid: static_cpu_templates::t2::t2(),
cpuid: build_supported_cpuid(),
msrs: HashMap::from([(0x8000, 0b1000), (0x9999, 0b1010)]),
}
}

fn unsupported_cpu_config() -> CpuConfiguration {
CpuConfiguration {
cpuid: static_cpu_templates::t2::t2(),
cpuid: build_supported_cpuid(),
msrs: HashMap::from([(0x8000, 0b1000), (0x8001, 0b1010)]),
}
}
Expand Down
Loading

0 comments on commit 86d7e69

Please sign in to comment.