Skip to content

vmm: Deprecate static CPU templates #4126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
- Added support for the /dev/userfaultfd device available on linux kernels >=
6.1. This is the default for creating UFFD handlers on these kernel versions.
If it is unavailable, Firecracker falls back to the userfaultfd syscall.
- Deprecated `cpu_template` field in `PUT` and `PATCH` requests on `/machine-config`
API, which is used to set a static CPU template. Custom CPU templates added in
v1.4.0 are available as an improved iteration of the static CPU templates. For
more information about the transition from static CPU templates to custom CPU
templates, please refer to [this GitHub discussion](https://github.com/firecracker-microvm/firecracker/discussions/4135).

### Fixed

Expand Down
3 changes: 0 additions & 3 deletions docs/api-change-runbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,6 @@ Firecracker API.
* Update any relevant documentation.
* We update the python integration tests to reflect the change (reference
implementation in [this commit][4]).
* We find the relevant resource in `tests/framework/resources.py` and
update its API, in this case by making the `vsock_id` parameter optional
in `Vsock.create_json()`.
* We refactor the relevant
`tests/integration_tests/functional/test_api.py` test to use the artifact
model instead of the fixture one. If the test already uses the artifact
Expand Down
7 changes: 7 additions & 0 deletions docs/cpu_templates/cpu-templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ 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**
Static CPU templates are deprecated starting from v1.5.0 and will be removed in
accordance with our deprecation policy. Even after the removal, custom CPU
templates are available as an improved iteration of static CPU templates. For
more information about the transition from static CPU templates to custom CPU
templates, please refer to [this GitHub discussion](https://github.com/firecracker-microvm/firecracker/discussions/4135).

> **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).
Expand Down
24 changes: 12 additions & 12 deletions src/api_server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,21 +227,21 @@ mod tests {
/// test deserialization and logging.
#[cfg(target_arch = "x86_64")]
const TEST_UNESCAPED_JSON_TEMPLATE: &str = r#"{
"msr_modifiers": [
{
"addr": "0x0\n\n\n\nTEST\n\n\n\n",
"bitmap": "0b00"
}
]
"msr_modifiers": [
{
"addr": "0x0\n\n\n\nTEST\n\n\n\n",
"bitmap": "0b00"
}
]
}"#;
#[cfg(target_arch = "aarch64")]
pub const TEST_UNESCAPED_JSON_TEMPLATE: &str = r#"{
"reg_modifiers": [
{
"addr": "0x0\n\n\n\nTEST\n\n\n\n",
"bitmap": "0b00"
}
]
"reg_modifiers": [
{
"addr": "0x0\n\n\n\nTEST\n\n\n\n",
"bitmap": "0b00"
}
]
}"#;

#[test]
Expand Down
86 changes: 43 additions & 43 deletions src/api_server/src/request/balloon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,82 +69,82 @@ mod tests {

// PATCH with invalid fields.
let body = r#"{
"amount_mib": "bar",
"foo": "bar"
}"#;
"amount_mib": "bar",
"foo": "bar"
}"#;
assert!(parse_patch_balloon(&Body::new(body), None).is_err());

// PATCH with invalid types on fields. Adding a polling interval as string instead of bool.
let body = r#"{
"amount_mib": 1000,
"stats_polling_interval_s": "false"
}"#;
"amount_mib": 1000,
"stats_polling_interval_s": "false"
}"#;
let res = parse_patch_balloon(&Body::new(body), None);
assert!(res.is_err());

// PATCH with invalid types on fields. Adding a amount_mib as a negative number.
let body = r#"{
"amount_mib": -1000,
"stats_polling_interval_s": true
}"#;
"amount_mib": -1000,
"stats_polling_interval_s": true
}"#;
let res = parse_patch_balloon(&Body::new(body), None);
assert!(res.is_err());

// PATCH on statistics with missing ppolling interval field.
let body = r#"{
"amount_mib": 100
}"#;
"amount_mib": 100
}"#;
let res = parse_patch_balloon(&Body::new(body), Some("statistics"));
assert!(res.is_err());

// PATCH with missing amount_mib field.
let body = r#"{
"stats_polling_interval_s": 0
}"#;
"stats_polling_interval_s": 0
}"#;
let res = parse_patch_balloon(&Body::new(body), None);
assert!(res.is_err());

// PATCH that tries to update something else other than allowed fields.
let body = r#"{
"amount_mib": "dummy_id",
"stats_polling_interval_s": "dummy_host"
}"#;
"amount_mib": "dummy_id",
"stats_polling_interval_s": "dummy_host"
}"#;
let res = parse_patch_balloon(&Body::new(body), None);
assert!(res.is_err());

// PATCH with payload that is not a json.
let body = r#"{
"fields": "dummy_field"
}"#;
"fields": "dummy_field"
}"#;
assert!(parse_patch_balloon(&Body::new(body), None).is_err());

// PATCH on unrecognized path.
let body = r#"{
"fields": "dummy_field"
}"#;
}"#;
assert!(parse_patch_balloon(&Body::new(body), Some("config")).is_err());

let body = r#"{
"amount_mib": 1
}"#;
#[allow(clippy::match_wild_err_arm)]
match vmm_action_from_request(parse_patch_balloon(&Body::new(body), None).unwrap()) {
VmmAction::UpdateBalloon(balloon_cfg) => assert_eq!(balloon_cfg.amount_mib, 1),
_ => panic!("Test failed: Invalid parameters"),
};
"amount_mib": 1
}"#;
let expected_config = BalloonUpdateConfig { amount_mib: 1 };
assert_eq!(
vmm_action_from_request(parse_patch_balloon(&Body::new(body), None).unwrap()),
VmmAction::UpdateBalloon(expected_config)
);

let body = r#"{
"stats_polling_interval_s": 1
}"#;
#[allow(clippy::match_wild_err_arm)]
match vmm_action_from_request(
parse_patch_balloon(&Body::new(body), Some("statistics")).unwrap(),
) {
VmmAction::UpdateBalloonStatistics(balloon_cfg) => {
assert_eq!(balloon_cfg.stats_polling_interval_s, 1)
}
_ => panic!("Test failed: Invalid parameters"),
"stats_polling_interval_s": 1
}"#;
let expected_config = BalloonUpdateStatsConfig {
stats_polling_interval_s: 1,
};
assert_eq!(
vmm_action_from_request(
parse_patch_balloon(&Body::new(body), Some("statistics")).unwrap()
),
VmmAction::UpdateBalloonStatistics(expected_config)
);
}

#[test]
Expand All @@ -153,17 +153,17 @@ mod tests {

// PUT with invalid fields.
let body = r#"{
"amount_mib": "bar",
"is_read_only": false
}"#;
"amount_mib": "bar",
"is_read_only": false
}"#;
assert!(parse_put_balloon(&Body::new(body)).is_err());

// PUT with valid input fields.
let body = r#"{
"amount_mib": 1000,
"deflate_on_oom": true,
"stats_polling_interval_s": 0
}"#;
"amount_mib": 1000,
"deflate_on_oom": true,
"stats_polling_interval_s": 0
}"#;
assert!(parse_put_balloon(&Body::new(body)).is_ok());
}
}
8 changes: 4 additions & 4 deletions src/api_server/src/request/boot_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ mod tests {
assert!(parse_put_boot_source(&Body::new("invalid_payload")).is_err());

let body = r#"{
"kernel_image_path": "/foo/bar",
"initrd_path": "/bar/foo",
"boot_args": "foobar"
}"#;
"kernel_image_path": "/foo/bar",
"initrd_path": "/bar/foo",
"boot_args": "foobar"
}"#;
let same_body = BootSourceConfig {
kernel_image_path: String::from("/foo/bar"),
initrd_path: Some(String::from("/bar/foo")),
Expand Down
20 changes: 8 additions & 12 deletions src/api_server/src/request/cpu_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,14 @@ mod tests {
);
let cpu_template_json = cpu_config_json_result.unwrap();

{
match vmm_action_from_request(
parse_put_cpu_config(&Body::new(cpu_template_json.as_bytes())).unwrap(),
) {
VmmAction::PutCpuConfiguration(received_cpu_template) => {
// Test that the CPU config to be used for KVM config is the
// the same that was read in from a test file.
assert_eq!(cpu_template, received_cpu_template);
}
_ => panic!("Test failed - Expected VmmAction::PutCpuConfiguration() call"),
}
}
// Test that the CPU config to be used for KVM config is the same that
// was read in from a test file.
assert_eq!(
vmm_action_from_request(
parse_put_cpu_config(&Body::new(cpu_template_json.as_bytes())).unwrap()
),
VmmAction::PutCpuConfiguration(cpu_template)
);

// Test empty request succeeds
let parse_cpu_config_result = parse_put_cpu_config(&Body::new(r#"{ }"#));
Expand Down
Loading