Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Backport tests and documentation for PCI devices #5402

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

Conversation

Copy link
Contributor

@bchalios bchalios commented Aug 25, 2025
edited
Loading

Changes

Backporting #5393, #5399, #5403 and #5404 to v1.13 release branch.

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 checkbuild --all to verify that the PR passes
    build checks on all supported architectures.
  • 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.

@bchalios bchalios force-pushed the backport_pci_tests branch 2 times, most recently from aba84e4 to d63713c Compare August 25, 2025 10:03
Copy link

codecov bot commented Aug 25, 2025
edited
Loading

Codecov Report

❌ Patch coverage is 67.70186% with 52 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.23%. Comparing base (c7c8cb0) to head (853577a).
⚠️ Report is 18 commits behind head on firecracker-v1.13.

Files with missing lines Patch % Lines
src/vmm/src/lib.rs 0.00% 27 Missing ⚠️
src/vmm/src/device_manager/mod.rs 0.00% 14 Missing ⚠️
.../src/devices/virtio/transport/pci/common_config.rs 91.11% 4 Missing ⚠️
src/vmm/src/rpc_interface.rs 0.00% 4 Missing ⚠️
src/vmm/src/devices/virtio/balloon/device.rs 83.33% 2 Missing ⚠️
src/vmm/src/builder.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@ Coverage Diff @@
## firecracker-v1.13 #5402 +/- ##
=====================================================
+ Coverage 82.35% 83.23% +0.88% 
=====================================================
 Files 265 265 
 Lines 30640 30563 -77 
=====================================================
+ Hits 25233 25440 +207 
+ Misses 5407 5123 -284 
Flag Coverage Δ
5.10-c5n.metal 83.30% <67.70%> (+0.98%) ⬆️
5.10-m5n.metal 83.31% <67.70%> (+0.98%) ⬆️
5.10-m6a.metal 82.62% <67.70%> (+1.01%) ⬆️
5.10-m6g.metal 79.93% <67.70%> (+1.01%) ⬆️
5.10-m6i.metal 83.30% <67.70%> (+0.97%) ⬆️
5.10-m7a.metal-48xl 82.61% <67.70%> (+1.02%) ⬆️
5.10-m7g.metal 79.93% <67.70%> (+1.01%) ⬆️
5.10-m7i.metal-24xl 83.27% <67.70%> (+0.98%) ⬆️
5.10-m7i.metal-48xl 83.27% <67.70%> (+0.98%) ⬆️
5.10-m8g.metal-24xl 79.93% <67.70%> (+1.01%) ⬆️
5.10-m8g.metal-48xl 79.93% <67.70%> (+1.01%) ⬆️
6.1-c5n.metal 83.34% <67.70%> (+0.98%) ⬆️
6.1-m5n.metal 83.35% <67.70%> (+0.98%) ⬆️
6.1-m6a.metal 82.66% <67.70%> (+1.01%) ⬆️
6.1-m6g.metal 79.93% <67.70%> (+1.01%) ⬆️
6.1-m6i.metal 83.34% <67.70%> (+0.98%) ⬆️
6.1-m7a.metal-48xl 82.65% <67.70%> (+1.01%) ⬆️
6.1-m7g.metal 79.93% <67.70%> (+1.01%) ⬆️
6.1-m7i.metal-24xl 83.36% <67.70%> (+0.98%) ⬆️
6.1-m7i.metal-48xl 83.35% <67.70%> (+0.98%) ⬆️
6.1-m8g.metal-24xl 79.93% <67.70%> (+1.01%) ⬆️
6.1-m8g.metal-48xl 79.93% <67.70%> (+1.01%) ⬆️

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.

Manciukic and others added 14 commits August 25, 2025 12:54
Currently, the device ids (TYPE_*) are hardcoded in various places. With
this change, they are generated from linux headers.
(cherry picked from commit ad58102)
Signed-off-by: Riccardo Mancini <mancio@amazon.com>
Signed-off-by: Babis Chalios <bchalios@amazon.es>
Make the with_virtio_device_with_id function more generic and introduce
its variant with error handling try_with_virtio_device_with_id. Then use
these new functions in vmm.rs whenever we need to perform an action on a
device.
To simplify the code, I also moved some balloon device error handling
back to the balloon device code and refactored it a little bit.
(cherry picked from commit c6987de)
Signed-off-by: Riccardo Mancini <mancio@amazon.com>
Signed-off-by: Babis Chalios <bchalios@amazon.es>
Remove some error variants that were not used in the code.
(cherry picked from commit 3b10bf2)
Signed-off-by: Riccardo Mancini <mancio@amazon.com>
Signed-off-by: Babis Chalios <bchalios@amazon.es>
The balloon device always returns "Amount of pages requested cannot fit
in u32" even if it fails due to the guest memory check.
Reword the error to make it more clear.
(cherry picked from commit f36767e)
Signed-off-by: Riccardo Mancini <mancio@amazon.com>
Signed-off-by: Babis Chalios <bchalios@amazon.es>
As the caller of latest_stats() always clones the object, just derive
Copy on it and return the copy rather than a reference.
(cherry picked from commit 26fd798)
Signed-off-by: Riccardo Mancini <mancio@amazon.com>
Signed-off-by: Babis Chalios <bchalios@amazon.es>
By defining an associated function to the trait, we can simplify the
logic to execute code on a specific device from the VMM, while also
statically guaranteeing we are passing the right constant.
The downside is that we need both a sized and a dyn implementation for
the function. To ensure devices implement them correctly, a utility
macro is provided. We cannot do it as a default trait impl as the const_
variant is only defined on Sized.
(cherry picked from commit acb79a2)
Signed-off-by: Riccardo Mancini <mancio@amazon.com>
Signed-off-by: Babis Chalios <bchalios@amazon.es>
Add unit tests that ensure our logic for handling the interaction with
guest VirtIO drivers over the PCI transport is correct. Also, drop some
dead code and fix some of the handling of various fields.
A list of logic fixes we found while writing the tests:
* We found some effectively dead code. As VirtIO stipulates that
 accesses to 64bit configuration fields MUST happen with two individual
 32bit reads, so drop the code that was actually handling the 64bit
 accesses.
* There were fields that the code was handling as write-only, when the
 specification declares them read-write. This was not an issue, since
 the Linux driver apparently never reads them, but add the read
 handling, so that we are spec compliant.
* The specification mentions that the driver MUST NOT write a value of 0
 in the queue_enable field. Enforce it.
(cherry picked from commit c91b8a4)
Signed-off-by: Babis Chalios <bchalios@amazon.es>
Remove dead code from the logic that handles setting up a PCI VirtIO
device transport. This was either code that we pulled from Cloud
Hypervisor and we don't need here or code that we are not currently
using.
(cherry picked from commit 6323d07)
Signed-off-by: Babis Chalios <bchalios@amazon.es>
The VirtioPciCap type had the wrong structure. This wasn't a problem,
because the wrong field was actually operating as part of the padding
of which it was taking away the space.
Also, fix the initialization of the VirtioPciCfgCap so that it reports
the correct length for the capability.
(cherry picked from commit 8ee3af1)
Signed-off-by: Babis Chalios <bchalios@amazon.es>
Add more unit tests in for VirtIO PCI capabilities other than the common
configuration capability.
(cherry picked from commit 2540713)
Signed-off-by: Babis Chalios <bchalios@amazon.es>
The PCI configuration capability gives a way to the guest to access
BAR memory for a device without actually mapping the BAR in guest
memory.
The way this works is that the guest accesses the capability directly
(in PCI configuration space) and it programs reads/writes from/to BAR
memory.
When such an access is detected we redirect certain PCI configuration
space access to VirtIO BAR accesses. These accesses happen in chunks of
4 bytes, however the code that handles BAR accesses expects the length
of an access to match exactly the length of the field we are accessing,
e.g. accessing a u8 field needs a &[u8] slice with length of 1. The
emulation logic was not taking that into account so the mechanism wasn't
effectively working. Fix that and also get rid off an unsafe `transmute`
in favour of an Le32::into<u32>().
Finally, add unit tests that ensure everything works as expected.
(cherry picked from commit 54eb06d)
Signed-off-by: Babis Chalios <bchalios@amazon.es>
We always enable MSI-X interrupts for VirtIO devices when using the PCI
transport. Currently, we don't offer a fallback if the driver doesn't
want to use MSI-X, but VirtIO drivers we are working with always support
that. So this should not be a problem for our use-cases in the kernels
we support at the moment.
On the other hand, despite not supporting legacy interrupts, we still
did some maintenance for the ISR status byte which is not used by MSI-X
interrupts at all. Drop all this handling, ensure that reads always
return 0 and writes have no effect in the state of the device. Also, add
warning messages for the cases where the guest tries to access the ISR
parts of the BAR.
(cherry picked from commit 1dee309)
Signed-off-by: Babis Chalios <bchalios@amazon.es>
Add a unit test that ensures that the Notification VirtIO capability is
specification compliant.
(cherry picked from commit 0ca3666)
Signed-off-by: Babis Chalios <bchalios@amazon.es>
Add a unit test that ensures the device initialization process works
properly.
(cherry picked from commit 031fb88)
Signed-off-by: Babis Chalios <bchalios@amazon.es>
@bchalios bchalios enabled auto-merge (rebase) August 25, 2025 11:09
@bchalios bchalios added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label Aug 25, 2025
@bchalios bchalios self-assigned this Aug 25, 2025
PCI configuration capability allows a driver to access a BAR without
mapping it in virtual address space. The driver issues reads/writes
directly within the PCI configuration space (which should always be
addressable either via MMIO or Port IO) which the device translates
corresponding BAR accesses.
The way this works is that the guests writes the offset and length of a
BAR access within the capability structure and then reads/writes data
using a 4-bytes dedicated array that also lives in the capability
address space.
We had a bug in the logic that handles writes where a guest would
program a write of a certain length (L) and then try to perform a write
using a buffer where buffer.len() < L. Our logic would then try to
perform a write using the slice buffer[..L] which would cause Rust to
panic with an out of range exception.
Fix this by taking into account the buffer's length and using a slice
with length min(L, buffer.len()).
(cherry picked from commit af1d121)
Signed-off-by: Babis Chalios <bchalios@amazon.es>
Add information in our Documentation regarding how users can enable PCI
support for Firecracker microVMs and mention requirements for building
the guest kernel, as well as the requirements for kernel command line
parameters.
Also, add an entry in the CHANGELOG mentioning the addition of PCI
support.
(cherry picked from commit 431d77e)
Signed-off-by: Babis Chalios <bchalios@amazon.es>
We have a single lock for all devices on the PCI bus that serializes
reads and writes on the devices' PCI configuration space and BARs.
This should not be a problem at the moment. It should be out of any hot
path and only up until we are setting up devices. However, add a comment
that mentions the existence of the contention so that we keep it in mind
for the futuer (and maybe perform some profiling).
(cherry picked from commit 6169ec3)
Signed-off-by: Babis Chalios <bchalios@amazon.es>
@bchalios bchalios changed the title (削除) Backport tests for PCI devices (削除ここまで) (追記) Backport tests and documentation for PCI devices (追記ここまで) Aug 26, 2025
@bchalios bchalios merged commit fa02b45 into firecracker-microvm:firecracker-v1.13 Aug 26, 2025
6 of 7 checks passed
@bchalios bchalios deleted the backport_pci_tests branch August 26, 2025 16:17
@bchalios bchalios restored the backport_pci_tests branch August 27, 2025 08:04
@bchalios bchalios deleted the backport_pci_tests branch August 27, 2025 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@Manciukic Manciukic Manciukic approved these changes

@ShadowCurse ShadowCurse ShadowCurse approved these changes

@roypat roypat roypat approved these changes

@xmarcalx xmarcalx Awaiting requested review from xmarcalx xmarcalx is a code owner

@kalyazin kalyazin Awaiting requested review from kalyazin kalyazin is a code owner

@pb8o pb8o Awaiting requested review from pb8o pb8o is a code owner

Labels
Status: Awaiting review Indicates that a pull request is ready to be reviewed
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /