Skip to content
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

Refactoring + Unifying CPU template handling #3610

Merged
merged 21 commits into from
Apr 18, 2023

Conversation

zulinx86
Copy link
Contributor

@zulinx86 zulinx86 commented Apr 13, 2023

Major Changes

  • Unify CPU template handling between static and custom CPU templates.
  • Unify CPU template handling partially between x86_64 and aarch64.

For more details, please see the commit messages!

Reason

Previously static and custom CPU templates are handled in different ways and CpuConfiguration provides different interfaces between architectures. Unifying them as much as possible introduces simplicity, resulting in maintainability.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following
Developer Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • [ ] If a specific issue led to this PR, this PR closes the issue.
  • The description of changes is clear and encompassing.
  • [ ] Any required documentation changes (code and docs) are included in this PR.
  • [ ] API changes follow the Runbook for Firecracker API changes.
  • [ ] User-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.
  • [ ] New TODOs link to an issue.
  • Commits meet contribution quality standards.

  • [ ] This functionality cannot be added in rust-vmm.

@zulinx86 zulinx86 self-assigned this Apr 13, 2023
@zulinx86 zulinx86 added the Type: Enhancement Indicates new feature requests label Apr 13, 2023
Update error items to use upper camel case for consistency.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
@zulinx86 zulinx86 force-pushed the refactor branch 26 times, most recently from f8041bb to 20b6429 Compare April 16, 2023 18:10
zulinx86 and others added 4 commits April 17, 2023 19:34
Just move static CPU templates defined with internal data structures
used in custom CPU template into a temporal directory inside vmm crate
with no functional changes, in order to wire up them in successive
commits.

The moved static CPU templates were added in PR firecracker-microvm#3598 in
static_templates crate temporarily to check that they are compatible
with static CPU templates in the main branch.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
Wire static_cpu_templates_new module up to vmm crate.

The module was moved in the directory in the previous commit, but had
not yet to be wired up.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
Add and implement `GetCpuTemplate` trait for x86_64 and aarch64 to get
the wrapped internal `CustomCpuTemplate` from `Option<CpuTemplateType>`.

The implemented trait has not been used in this commit, but will be
consumed in successive commits to refactor CPU template application.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
Co-authored-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
Move the code to get MSR values into `KvmVcpu::get_msrs()`.

This method will be consumed in multiple places by successive commits.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
Co-authored-by: Nikita Kalyazin <kalyazin@amazon.com>
@zulinx86 zulinx86 force-pushed the refactor branch 6 times, most recently from 5211eea to bae04e4 Compare April 17, 2023 20:58
kalyazin
kalyazin previously approved these changes Apr 18, 2023
zulinx86 and others added 7 commits April 18, 2023 08:22
Check whether the vendor is matched between the static CPU template
and the actual CPU.

Static CPU templates for x86-64 are specific to vendor (Intel or AMD).
`include_leaves_from()` method does this check now, but will be removed
in a successive commit. Instead of this method, we do this check in
`get_cpu_template()`.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
Build a custom `CpuConfiguration` with 2 steps:
1. Construct a base `CpuConfiguration`.
2. Apply CPU template to the default `CpuConfiguration`.

Previously, all these processes were done in `CpuConfiguration::new()`,
but this approach is a bit complex in the test perspective. In addition,
we will be able to unify `CpuConfiguration` interface between x86_64 and
aarch64 and simplify `configure_system_for_boot()` function in
successive commits.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
Add `KvmVcpu::get_regs()` to retrieve values for the given register IDs
through `KVM_GET_ONE_REG`. This will be consumed in a successive commit.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
As done in x86_64, build a custom `CpuConfiguration` with 2 steps:
1. Construct a base `CpuConfiguration`.
2. Apply CPU template to the default `CpuConfiguration`.

By providing the same interface between x86_64 and aarch64, it becomes
possible to unify some operations.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
Co-authored-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
Move out arch-agnostic operations from arch-specific operations.

Thanks to the previous commits, now it is possible to do this.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
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 <itazur@amazon.com>
Remove include_leaves_from() that is no longer used.

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
The CPU model check of T2CL template was added in PR firecracker-microvm#3480, but was
removed in commit 8f5feb0 ("feat: Updated CPUID").

Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
Signed-off-by: Takahiro Itazuri <itazur@amazon.com>
@zulinx86 zulinx86 merged commit 57ffe50 into firecracker-microvm:feature/cpu-templates Apr 18, 2023
@zulinx86 zulinx86 deleted the refactor branch April 18, 2023 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Indicates new feature requests Type: Fix Indicates a fix to existing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants