Skip to content

Conversation

kalyazin
Copy link
Contributor

Changes

...

Reason

...

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

  • I have read and understand CONTRIBUTING.md.
  • I have run tools/devtool checkstyle to verify that the PR passes the
    automated style checks.
  • I have described what is done in these changes, why they are needed, and
    how they are solving the problem in a clear and encompassing way.
  • I have updated any relevant documentation (both in code and in the docs)
    in the PR.
  • I have mentioned all user-facing changes in CHANGELOG.md.
  • If a specific issue led to this PR, this PR closes the issue.
  • When making API changes, I have followed the
    Runbook for Firecracker API changes.
  • I have tested all new and changed functionalities in unit tests and/or
    integration tests.
  • I have linked an issue to every new TODO.

  • This functionality cannot be added in rust-vmm.

kalyazin added 6 commits June 16, 2025 11:36
This is needed because if guest_memfd is used to back guest memory, vCPU
fault notifications are delivered via the UFFD UDS socket.

Signed-off-by: Nikita Kalyazin <[email protected]>
Example UFFD handlers are now reading from the UDS socket in a buffered
way.  This is to make it possible to read messages of different types in
future commits to be able to handle fault request messages from
Firecracker if Secret Freedom is enabled.

Signed-off-by: Nikita Kalyazin <[email protected]>
It is used by Secret-Free-enabled UFFD handlers to disable vCPU fault
notifications from the kernel.

Signed-off-by: Nikita Kalyazin <[email protected]>
Accept receiving 3 fds instead of 1, where fds[1] is guest_memfd and
fds[2] is userfault bitmap memfd.

Also handle the FaultRequest message over the UDS socket by calling a
new callback in the Runtime and sending a FaultReply.

TODO: sob patrick

Signed-off-by: Nikita Kalyazin <[email protected]>
There are two ways a UFFD handler receives a fault notification if
Secret Fredom is enabled (which is inferred from 3 fds sent by
Firecracker instead of 1):
 - a VMM- or KVM-triggered fault is delivered via a minor UFFD fault
   event.   The handler is supposed to respond to it via memcpying the
   content of the page (if the page hasn't already been populated)
   followed by UFFDIO_CONTINUE call.
 - a vCPU-triggered fault is delievered via a FaultRequest message on
   the UDS socket.  The handler is supposed to reply with a pwrite64
   call on the guest_memfd to populate the page followed by a FaultReply
   message on the UDS socket.

In both cases, the handler also needs to clear the bit in the userfault
bitmap at the corresponding offset in order to stop fault notifications
for the same page.

UFFD handlers use the userfault bitmap for two purposes:
 - communicate to the kernel whether a fault at the corresponding
   guest_memfd offset will cause a VM exit
 - keep track of pages that have already been populated in order to
   avoid overwriting the content of the page that is already
initialised.

Signed-off-by: Nikita Kalyazin <[email protected]>
These are used for communication of page faults between Firecracker and
a UFFD handler.

Signed-off-by: Nikita Kalyazin <[email protected]>
Copy link

codecov bot commented Jun 18, 2025

Codecov Report

Attention: Patch coverage is 28.48485% with 354 lines in your changes missing coverage. Please review.

Project coverage is 81.66%. Comparing base (00ac2f3) to head (553464a).

Files with missing lines Patch % Lines
src/vmm/src/lib.rs 12.83% 129 Missing ⚠️
src/vmm/src/vstate/vm.rs 41.30% 81 Missing ⚠️
src/vmm/src/persist.rs 21.79% 61 Missing ⚠️
src/vmm/src/builder.rs 47.05% 36 Missing ⚠️
src/vmm/src/vstate/vcpu.rs 35.55% 29 Missing ⚠️
src/vmm/src/vstate/memory.rs 0.00% 18 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                    @@
##           feature/secret-hiding    #5270      +/-   ##
=========================================================
- Coverage                  82.52%   81.66%   -0.86%     
=========================================================
  Files                        250      250              
  Lines                      27386    27795     +409     
=========================================================
+ Hits                       22599    22698      +99     
- Misses                      4787     5097     +310     
Flag Coverage Δ
5.10-c5n.metal 81.85% <23.63%> (-1.06%) ⬇️
5.10-m5n.metal 81.85% <23.63%> (-1.06%) ⬇️
5.10-m6a.metal 81.01% <23.63%> (-1.09%) ⬇️
5.10-m6g.metal 77.62% <20.12%> (-1.08%) ⬇️
5.10-m6i.metal 81.85% <23.63%> (-1.05%) ⬇️
5.10-m7a.metal-48xl 81.00% <23.63%> (-1.08%) ⬇️
5.10-m7g.metal 77.62% <20.12%> (-1.08%) ⬇️
5.10-m7i.metal-24xl 81.82% <23.63%> (-1.05%) ⬇️
5.10-m7i.metal-48xl 81.82% <23.63%> (-1.05%) ⬇️
5.10-m8g.metal-24xl 77.61% <20.12%> (-1.08%) ⬇️
5.10-m8g.metal-48xl 77.61% <20.12%> (-1.08%) ⬇️
6.1-c5n.metal 81.90% <23.63%> (-1.06%) ⬇️
6.1-m5n.metal 81.90% <23.63%> (-1.06%) ⬇️
6.1-m6a.metal 81.06% <23.63%> (-1.09%) ⬇️
6.1-m6g.metal 77.61% <20.12%> (-1.09%) ⬇️
6.1-m6i.metal 81.89% <23.63%> (-1.06%) ⬇️
6.1-m7a.metal-48xl 81.04% <23.63%> (-1.09%) ⬇️
6.1-m7g.metal 77.61% <20.12%> (-1.09%) ⬇️
6.1-m7i.metal-24xl 81.91% <23.63%> (-1.06%) ⬇️
6.1-m7i.metal-48xl 81.91% <23.63%> (-1.05%) ⬇️
6.1-m8g.metal-24xl 77.61% <20.12%> (-1.08%) ⬇️
6.1-m8g.metal-48xl 77.60% <20.12%> (-1.09%) ⬇️
6.14-c5n.metal 81.95% <28.48%> (-0.97%) ⬇️
6.14-m5n.metal 81.95% <28.48%> (-0.98%) ⬇️
6.14-m6a.metal 81.12% <28.48%> (-1.00%) ⬇️
6.14-m6g.metal 77.66% <25.00%> (-1.00%) ⬇️
6.14-m6i.metal 81.94% <28.48%> (-0.97%) ⬇️
6.14-m7a.metal-48xl 81.10% <28.48%> (-1.00%) ⬇️
6.14-m7g.metal 77.67% <25.00%> (-1.00%) ⬇️
6.14-m7i.metal-24xl 81.96% <28.48%> (-0.97%) ⬇️
6.14-m7i.metal-48xl 81.97% <28.48%> (-0.96%) ⬇️
6.14-m8g.metal-24xl 77.65% <25.00%> (-1.00%) ⬇️
6.14-m8g.metal-48xl 77.66% <25.00%> (-1.00%) ⬇️

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

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kalyazin kalyazin force-pushed the sh_uf_dbg branch 7 times, most recently from 5967151 to fc21497 Compare June 18, 2025 16:42
kalyazin added 7 commits June 18, 2025 17:15
If configured, userfault bitmap is registered with KVM and controls
whether KVM will exit to userspace on a fault of the corresponding page.

Signed-off-by: Nikita Kalyazin <[email protected]>
This us needed to instruct the kernel to exit to userspace when a vCPU
fault occurs and the corresponding bit in the userfault bitmap is set.

This also sends 3 fds to the UFFD handler in the handshake:
 - UFFD (original)
 - guest_memfd: for the handler to be able to populate guest memory
 - userfault bitmap memfd: for the handler to be able to disable exits
   to userspace for the pages that have already been populated

Signed-off-by: Nikita Kalyazin <[email protected]>
These will be used to communicate vCPU faults between vCPUs and the VM
if secret freedom is enabled.

Signed-off-by: Nikita Kalyazin <[email protected]>
This is because vCPUs reason in GPAs while the secret-free UFFD
protocol is guest_memfd-offset-based.

TODO: sob patrick

Signed-off-by: Nikita Kalyazin <[email protected]>
It contains two parts:
 - external: between the VMM thread and the UFFD handler
 - internal: between vCPUs and the VMM thread

Signed-off-by: Nikita Kalyazin <[email protected]>
This is required by Secret Freedom to implement the userfault protocol.

Signed-off-by: Nikita Kalyazin <[email protected]>
kvmclock is currently not supported by Secret Freedom and will always
fail.

Signed-off-by: Nikita Kalyazin <[email protected]>
@kalyazin kalyazin force-pushed the sh_uf_dbg branch 2 times, most recently from f142f00 to 76620a7 Compare June 18, 2025 17:39
kalyazin added 3 commits June 19, 2025 06:47
This combination makes little sense.

Signed-off-by: Nikita Kalyazin <[email protected]>
It is not supported by Secret Freedom.

Signed-off-by: Nikita Kalyazin <[email protected]>
This includes both functional and performance.

Signed-off-by: Nikita Kalyazin <[email protected]>
kalyazin added 3 commits June 19, 2025 11:12
Do not add a balloon device to a Secret Free VM as it is not currently
supported.

Signed-off-by: Nikita Kalyazin <[email protected]>
When taking a snapshot from a Secret Free VM, we create a bounce buffer
to be able to pass it to the host kernel.  Exclude it from the memory
monitor calcluation.

Signed-off-by: Nikita Kalyazin <[email protected]>
This is because the error type has changed.

Signed-off-by: Nikita Kalyazin <[email protected]>
@kalyazin
Copy link
Contributor Author

Used for testing. Superseded by #5261 .

@kalyazin kalyazin closed this Jun 19, 2025
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.

1 participant