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

Merge feature/uffd into main #2980

Merged
merged 22 commits into from
Apr 28, 2022
Merged

Merge feature/uffd into main #2980

merged 22 commits into from
Apr 28, 2022

Conversation

luminitavoicu
Copy link
Contributor

Reason for This PR

merge feature/uffd into main

  • This functionality can be added in rust-vmm.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license.

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The issue which led to this PR has a clear conclusion.
  • This PR follows the solution outlined in the related issue.
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any newly added unsafe code is properly documented.
  • Any API changes follow the Runbook for Firecracker API changes.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

acatangiu and others added 22 commits April 27, 2022 17:45
Memory::restore now takes an optional &File and creates
file-backed memory or anonymous memory depending on the option.

Signed-off-by: Adrian Catangiu <[email protected]>
Deprecate 'mem_file_path' field and add a new 'mem_backend'
optional object. At least one of 'mem_file_path' and `mem_backend`
fields are required and it is forbidden to specify both at the
same time.

`mem_backend` object contains:
- 'backend_type': required String parameter that can take either:
    - File
    - Uffd
as valid values.
- 'backend_path': required String parameter. Interpretation of
this field depends on the value of 'backend_type':
    - Path to file that contains the guest memory to be loaded
      if type is 'File',
    - Path to UDS where a custom page-fault handler process is
      listening and expecting a Uffd to be sent by Firecracker.
      The Uffd is used to handle Firecracker's guest memory page
      faults in this separate process.

If `mem_file_path` is specified instead of `mem_backend`, we
construct the `MemBackendConfig` object from the path specified,
through `mem_file_path`, with `File` as backend type.

Add plumbing for the new API, the Uffd path is only a stub for
now.

Signed-off-by: Adrian Catangiu <[email protected]>
Signed-off-by: Luminita Voicu <[email protected]>
When /snapshot/load specifies memory backend type as 'UffdOverUDS',
Firecracker doesn't handle the memory file itself anymore and expects
an external process to handle its guest memory page faults.

To do this, anonymous memory is mmapped as guest memory while keeping
the original memory regions shape. Then a Uffd is created and each
guest memory range is registered with the Uffd so that any page faults
won't be handled by the kernel, but will come up as events on the Uffd.

Firecracker then sends the memory ranges descriptions/mappings along
with the Uffd over a UnixDomainSocket specified in 'mem_backend_path'
parameter on the API call.

It is expected that on the other side there is already a process
listening for incoming connections. Once Firecracker's connection is
accepted, Firecracker sends the mappings and Uffd. The receiving
process is from now responsible for handling any pagefaults on the
Uffd.

The communication medium is a UDS, the protocol is SOCK_STREAM and the
encoding is JSON.

Signed-off-by: Adrian Catangiu <[email protected]>
Signed-off-by: Luminita Voicu <[email protected]>
Signed-off-by: Diana Popa <[email protected]>
Signed-off-by: Luminita Voicu <[email protected]>
The page fault handler process requires FC's PID in order
to be able to notify FC of any crashes/exists. The way
we initially intended to make the handler process aware
of FC's PID was to have FC sent its PID explicitly through
the UDS. But there is a problem with this approach:

Firecracker's PID depends on the way the process was started.
When normally started through the jailer, Firecracker will
see its global PID. However, if using `--new-pid-ns` flag
when running the jailer, the jailer will spawn FC in a new
PID namespace, which would cause Firecracker to not be
aware of its PID and see it as being 1.

Moreover, when not using `--new-pid-ns` flag, we recommend
to the users to spawn the jailer process into a new PID
namespace when starting it.

This is why sending FC's PID from whithin the FC process is
not reliable.

To tackle this, we no longer send FC's PID explicitly,
but advise the page fault handler process to use
`getsockopt` call with `SO_PEERCRED` option in order
to fetch the global Firecracker PID at the moment of
connecting.

Signed-off-by: Luminita Voicu <[email protected]>
The feature will get enabled only when the
microVM uses a balloon device.

Signed-off-by: Diana Popa <[email protected]>
Signed-off-by: Diana Popa <[email protected]>

CI: enable uffd testing when building from snapshot

Signed-off-by: Diana Popa <[email protected]>
Signed-off-by: Luminita Voicu <[email protected]>
Signed-off-by: Diana Popa <[email protected]>
Signed-off-by: Luminita Voicu <[email protected]>
Signed-off-by: Diana Popa <[email protected]>
Signed-off-by: Luminita Voicu <[email protected]>
Signed-off-by: Diana Popa <[email protected]>
Signed-off-by: Luminita Voicu <[email protected]>
Signed-off-by: Diana Popa <[email protected]>
Signed-off-by: Luminita Voicu <[email protected]>
Signed-off-by: Diana Popa <[email protected]>
Signed-off-by: Luminita Voicu <[email protected]>
The PUT snapshot/load `mem_file_path` field is under the
deprecation policy. Check for the presence of deprecation
header in the response when using it.

Signed-off-by: Luminita Voicu <[email protected]>
Signed-off-by: Luminita Voicu <[email protected]>
Signed-off-by: Luminita Voicu <[email protected]>
Signed-off-by: Luminita Voicu <[email protected]>
@luminitavoicu luminitavoicu self-assigned this Apr 28, 2022
@alindima alindima requested a review from dianpopa April 28, 2022 15:09
@dianpopa dianpopa merged commit b3cc331 into main Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants