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

Memfd backed memory #4138

Merged
merged 14 commits into from
Oct 17, 2023
Merged

Conversation

ShadowCurse
Copy link
Contributor

@ShadowCurse ShadowCurse commented Sep 27, 2023

Changes

Moved all memory related code into vstate/memory.rs module.
Added ability to create memfd file to back guest memory.

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.

@ShadowCurse ShadowCurse force-pushed the mem_refactor branch 3 times, most recently from 0eb43ad to 6855b36 Compare September 28, 2023 08:28
@codecov
Copy link

codecov bot commented Sep 28, 2023

Codecov Report

Attention: 30 lines in your changes are missing coverage. Please review.

Comparison is base (da660d3) 82.95% compared to head (ef94eaf) 82.99%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4138      +/-   ##
==========================================
+ Coverage   82.95%   82.99%   +0.03%     
==========================================
  Files         221      221              
  Lines       28501    28568      +67     
==========================================
+ Hits        23643    23709      +66     
- Misses       4858     4859       +1     
Flag Coverage Δ
4.14-c7g.metal 78.54% <92.47%> (+0.03%) ⬆️
4.14-m5d.metal 80.34% <92.74%> (+0.03%) ⬆️
4.14-m6a.metal 79.47% <92.74%> (+0.02%) ⬆️
4.14-m6g.metal 78.54% <92.47%> (+0.03%) ⬆️
4.14-m6i.metal 80.32% <92.74%> (+0.02%) ⬆️
5.10-c7g.metal 81.46% <92.70%> (+0.02%) ⬆️
5.10-m5d.metal 83.01% <92.97%> (+0.02%) ⬆️
5.10-m6a.metal 82.25% <92.97%> (+0.01%) ⬆️
5.10-m6g.metal 81.46% <92.70%> (+0.02%) ⬆️
5.10-m6i.metal 83.00% <92.97%> (+0.02%) ⬆️
6.1-c7g.metal 81.46% <92.70%> (+0.02%) ⬆️
6.1-m5d.metal 83.00% <92.97%> (+0.01%) ⬆️
6.1-m6a.metal 82.25% <92.97%> (+0.01%) ⬆️
6.1-m6g.metal 81.46% <92.70%> (+0.02%) ⬆️
6.1-m6i.metal 83.00% <92.97%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/utils/src/lib.rs 92.30% <ø> (ø)
src/vmm/src/arch/aarch64/fdt.rs 97.69% <ø> (ø)
src/vmm/src/arch/aarch64/mod.rs 94.59% <ø> (ø)
src/vmm/src/arch/aarch64/regs.rs 87.83% <ø> (ø)
src/vmm/src/arch/aarch64/vcpu.rs 95.65% <ø> (ø)
src/vmm/src/arch/mod.rs 80.00% <ø> (ø)
src/vmm/src/arch/x86_64/mod.rs 97.34% <ø> (ø)
src/vmm/src/arch/x86_64/mptable.rs 99.42% <ø> (ø)
src/vmm/src/arch/x86_64/regs.rs 96.52% <ø> (ø)
src/vmm/src/builder.rs 93.04% <100.00%> (-0.16%) ⬇️
... and 47 more

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ShadowCurse ShadowCurse force-pushed the mem_refactor branch 7 times, most recently from 61a7c2f to e60e35d Compare September 29, 2023 10:55
@ShadowCurse ShadowCurse self-assigned this Sep 29, 2023
@ShadowCurse ShadowCurse marked this pull request as ready for review September 29, 2023 10:59
@ShadowCurse ShadowCurse added Status: Awaiting review Indicates that a pull request is ready to be reviewed Type: Enhancement Indicates new feature requests labels Sep 29, 2023
src/vmm/Cargo.toml Show resolved Hide resolved
src/vmm/src/volotile.rs Outdated Show resolved Hide resolved
src/vmm/src/builder.rs Outdated Show resolved Hide resolved
src/vmm/src/vstate/memory.rs Show resolved Hide resolved
src/vmm/src/vstate/memory.rs Outdated Show resolved Hide resolved
src/vmm/src/vstate/memory.rs Show resolved Hide resolved
src/vmm/src/vstate/memory.rs Show resolved Hide resolved
src/vmm/src/vstate/memory.rs Outdated Show resolved Hide resolved
tests/integration_tests/functional/test_api.py Outdated Show resolved Hide resolved
src/vmm/src/vstate/memory.rs Outdated Show resolved Hide resolved
@ShadowCurse ShadowCurse force-pushed the mem_refactor branch 2 times, most recently from 2ddd564 to 4193777 Compare September 29, 2023 12:30
@ShadowCurse ShadowCurse added the Status: Blocked Indicates that an issue or pull request cannot currently be worked on label Oct 2, 2023
@ShadowCurse ShadowCurse force-pushed the mem_refactor branch 4 times, most recently from ad7471d to c75284a Compare October 10, 2023 09:42
Copy link
Contributor

@bchalios bchalios left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit comment: Could you please format the commit messages? They include random new lines:

For example:

refactor(memory): moved vm_memory from utils

Moved `utils/vm_memory` crate into
`vmm/vstate/memory`.
Removed `utils/vm_memory`.

This module contains `vmm` specific code
and it make sense to have it in `vmm`.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>

should read:

refactor(memory): moved vm_memory from utils

Moved `utils/vm_memory` crate into `vmm/vstate/memory`. Removed
`utils/vm_memory`.

This module contains `vmm` specific codeand it make sense to have it in
`vmm`.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>

Copy link
Contributor

@bchalios bchalios left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why move volatile types to a separate module not under memory?

@ShadowCurse
Copy link
Contributor Author

@bchalios updated the commit messages.
I moved volatile into a separate module, because it is not really memory related thing. I am not exactly sure about the module placement itself. But considering we will remove volatile after updating vm_memory to new version.

@roypat
Copy link
Contributor

roypat commented Oct 16, 2023

But considering we will remove volatile after updating vm_memory to new version.

What's blocking us from doing it already?

I opened #6763 for it, but its running into kani timeouts 😒

@ShadowCurse ShadowCurse force-pushed the mem_refactor branch 2 times, most recently from bc8c007 to 61e8321 Compare October 16, 2023 13:11
@ShadowCurse ShadowCurse force-pushed the mem_refactor branch 2 times, most recently from b3c224f to 9a33723 Compare October 16, 2023 18:58
Moved `utils/vm_memory` crate into `vmm/vstate/memory`.
Removed `utils/vm_memory`.

This module contains `vmm` specific code
and it make sense to have it in `vmm`.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
Moved all volatile related things into separate module.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
Renamed `Error` into `VmMemoryError`

We try to avoid usind `Error` word for errors.
Renaming it make is clearer what type of error this is.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
Changed names of some variables and used tuple unpacking.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
Moved all content of `memory_snapshot` module into `vstate/memory`
module. Now all memory related code is in one place.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
Removed reexports of `vm_memory` error types from `vstate/memory.rs`
Renamed `SnapshotMemoryError` into `MemoryError`.

Now `memory` only has 1 error type it exposes.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
Changed `SnapshotMemory` trait to `GuestMemoryExtension`
and moved all public methods that create GuestMemoryMmap into it.
This removed a need for a public `test_utils` module and it makes
all methods that directly act on `GuestMemoryMmap` to be associated
with it.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
Added method to create `memfd` file with needed size and seals.
Added an ability to construct `GuestMemoryMmap` backed by a file.
Changed expected error message for failed memory creation
in `test_api` test

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
Added `from_raw_regions_file` method to the `GuestMemoryExtension`
trait to remove duplicated code that creates file backed
`GuestMemoryMap`.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
Added missing unit tests for memory creation methods.
Split some unit tests into multiple for better
readability.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
Updated `test_negative_file_size_limit` to check file size limit
by simply starting a uVM, because now FC creates a memfd file
for guest memory.
Added positive test to verify that vm starts if limit is not hit.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
@ShadowCurse ShadowCurse force-pushed the mem_refactor branch 3 times, most recently from d0fea7f to 995ed7d Compare October 16, 2023 19:10
Updated testing for read/write of guard pages.
This testing is only possible with gnu target, so
all tests that verify guard pages are marked to be
compiled only for gnu target.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
Now when memory is backed by the file we store `FileOffset`
inside each region. This information will be used to set up
vhost-user shared memory.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
Now unit tests are run for musl and gnu targets.
This is done, because we have some tests that
only work with gnu.

Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
@ShadowCurse ShadowCurse merged commit e71046f into firecracker-microvm:main Oct 17, 2023
5 of 7 checks passed
@ShadowCurse ShadowCurse deleted the mem_refactor branch October 17, 2023 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Awaiting review Indicates that a pull request is ready to be reviewed Status: Blocked Indicates that an issue or pull request cannot currently be worked on Type: Enhancement Indicates new feature requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants