diff --git a/CHANGELOG.md b/CHANGELOG.md index 61f0c26a66b4..ba0c744e512e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,10 @@ - Changed the dump feature of `cpu-template-helper` tool not to enumerate program counter (PC) on ARM because it is determined by the given kernel image and it is useless in the custom CPU template context. +- Deprecated `cpu_template` field in `PUT` and `PATCH` request of `/machine-config` + API, which is used to set static CPU templates. Users can use custom CPU templates + as an alternative. For more details, please refer here (link to GitHub discussion + to be added). ### Fixed diff --git a/docs/cpu_templates/cpu-templates.md b/docs/cpu_templates/cpu-templates.md index fdcea70be77e..f9c5521b7027 100644 --- a/docs/cpu_templates/cpu-templates.md +++ b/docs/cpu_templates/cpu-templates.md @@ -34,6 +34,12 @@ Firecracker supports two types of CPU templates: - Custom CPU templates - users can create their own CPU templates in json format and pass them to Firecracker +> **Note** +Staitc CPU templates are deprecated starting with v1.5.0. It will be removed in +accordance with our policy. Even after dropping the support, users can use +custom CPU templates as an alternative. For more details, please refer here ( +link to the GitHub discussion to be added). + > **Note** CPU templates for ARM (both static and custom) require the following patch to be available in the host kernel: [Support writable CPU ID registers from userspace](https://lore.kernel.org/kvm/20230212215830.2975485-1-jingzhangos@google.com/#t). diff --git a/src/api_server/src/request/machine_configuration.rs b/src/api_server/src/request/machine_configuration.rs index e1b86b026d84..6df8b6dcda71 100644 --- a/src/api_server/src/request/machine_configuration.rs +++ b/src/api_server/src/request/machine_configuration.rs @@ -20,11 +20,25 @@ pub(crate) fn parse_put_machine_config(body: &Body) -> Result Result { @@ -39,9 +53,22 @@ pub(crate) fn parse_patch_machine_config(body: &Body) -> Result assert_eq!(config, expected_config), + _ => panic!("Test failed."), + } + + let body = r#"{ + "vcpu_count": 8, + "mem_size_mib": 1024, + "cpu_template": "None" + }"#; let expected_config = MachineConfigUpdate { vcpu_count: Some(8), mem_size_mib: Some(1024), @@ -102,7 +147,7 @@ mod tests { vcpu_count: Some(8), mem_size_mib: Some(1024), smt: Some(false), - cpu_template: Some(StaticCpuTemplate::None), + cpu_template: None, track_dirty_pages: Some(true), }; @@ -155,7 +200,7 @@ mod tests { vcpu_count: Some(8), mem_size_mib: Some(1024), smt: Some(true), - cpu_template: Some(StaticCpuTemplate::None), + cpu_template: None, track_dirty_pages: Some(true), }; diff --git a/src/vmm/src/cpu_config/templates.rs b/src/vmm/src/cpu_config/templates.rs index e9bd7103cb10..1c8987129603 100644 --- a/src/vmm/src/cpu_config/templates.rs +++ b/src/vmm/src/cpu_config/templates.rs @@ -72,6 +72,15 @@ impl From<&Option> for StaticCpuTemplate { } } +impl From<&CpuTemplateType> for StaticCpuTemplate { + fn from(value: &CpuTemplateType) -> Self { + match value { + CpuTemplateType::Static(template) => *template, + CpuTemplateType::Custom(_) => StaticCpuTemplate::None, + } + } +} + impl<'a> TryFrom<&'a [u8]> for CustomCpuTemplate { type Error = serde_json::Error; diff --git a/src/vmm/src/vmm_config/machine_config.rs b/src/vmm/src/vmm_config/machine_config.rs index fcaded946365..1a4266053d6a 100644 --- a/src/vmm/src/vmm_config/machine_config.rs +++ b/src/vmm/src/vmm_config/machine_config.rs @@ -40,8 +40,8 @@ pub struct MachineConfig { #[serde(default, deserialize_with = "deserialize_smt")] pub smt: bool, /// A CPU template that it is used to filter the CPU features exposed to the guest. - #[serde(default, skip_serializing_if = "StaticCpuTemplate::is_none")] - pub cpu_template: StaticCpuTemplate, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub cpu_template: Option, /// Enables or disables dirty page tracking. Enabling allows incremental snapshots. #[serde(default)] pub track_dirty_pages: bool, @@ -122,7 +122,7 @@ impl From for MachineConfigUpdate { vcpu_count: Some(cfg.vcpu_count), mem_size_mib: Some(cfg.mem_size_mib), smt: Some(cfg.smt), - cpu_template: Some(cfg.cpu_template), + cpu_template: cfg.cpu_template, track_dirty_pages: Some(cfg.track_dirty_pages), } } @@ -212,7 +212,7 @@ impl From<&VmConfig> for MachineConfig { vcpu_count: value.vcpu_count, mem_size_mib: value.mem_size_mib, smt: value.smt, - cpu_template: (&value.cpu_template).into(), + cpu_template: value.cpu_template.as_ref().map(|template| template.into()), track_dirty_pages: value.track_dirty_pages, } }