Skip to content

PCI host bridge support #5215

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
merged 15 commits into from
May 29, 2025

Conversation

bchalios
Copy link
Contributor

@bchalios bchalios commented May 19, 2025

Changes

Add support for a root complex, aka root bridge.

Reason

The Root Complex is the owner of the Root bus, on which all virtio-pci devices will be attached.

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.

@bchalios bchalios force-pushed the pci_root_support branch 6 times, most recently from 49d90c8 to 3c12638 Compare May 19, 2025 15:39
Copy link

codecov bot commented May 19, 2025

Codecov Report

Attention: Patch coverage is 33.56371% with 1538 lines in your changes missing coverage. Please review.

Project coverage is 79.22%. Comparing base (2e774c0) to head (0f71857).
Report is 15 commits behind head on feature/pcie.

Files with missing lines Patch % Lines
src/pci/src/configuration.rs 18.06% 526 Missing ⚠️
src/pci/src/msix.rs 0.00% 349 Missing ⚠️
src/pci/src/bus.rs 13.24% 262 Missing ⚠️
src/pci/src/msi.rs 0.00% 154 Missing ⚠️
src/pci/src/lib.rs 0.00% 93 Missing ⚠️
src/vmm/src/devices/pci/pci_segment.rs 82.15% 58 Missing ⚠️
src/pci/src/device.rs 0.00% 39 Missing ⚠️
src/vmm/src/device_manager/resources.rs 67.92% 17 Missing ⚠️
src/firecracker/src/main.rs 0.00% 12 Missing ⚠️
src/vmm/src/arch/x86_64/mod.rs 86.74% 11 Missing ⚠️
... and 7 more

❌ Your project status has failed because the head coverage (79.22%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@               Coverage Diff                @@
##           feature/pcie    #5215      +/-   ##
================================================
- Coverage         83.25%   79.22%   -4.03%     
================================================
  Files               253      262       +9     
  Lines             27200    29349    +2149     
================================================
+ Hits              22645    23253     +608     
- Misses             4555     6096    +1541     
Flag Coverage Δ
5.10-c5n.metal 79.03% <30.69%> (-4.53%) ⬇️
5.10-m5n.metal 79.03% <30.69%> (-4.54%) ⬇️
5.10-m6a.metal 78.15% <30.69%> (-4.65%) ⬇️
5.10-m6g.metal 75.17% <21.21%> (-4.62%) ⬇️
5.10-m6i.metal 79.03% <30.69%> (-4.53%) ⬇️
5.10-m7a.metal-48xl 78.14% <30.69%> (-4.64%) ⬇️
5.10-m7g.metal 75.17% <21.21%> (-4.62%) ⬇️
5.10-m7i.metal-24xl 78.99% <30.69%> (-4.54%) ⬇️
5.10-m7i.metal-48xl 79.00% <30.69%> (-4.53%) ⬇️
5.10-m8g.metal-24xl 75.16% <21.21%> (-4.62%) ⬇️
5.10-m8g.metal-48xl 75.16% <21.21%> (-4.62%) ⬇️
6.1-c5n.metal 79.07% <30.69%> (-4.55%) ⬇️
6.1-m5n.metal 79.07% <30.69%> (-4.54%) ⬇️
6.1-m6a.metal 78.20% <30.69%> (-4.65%) ⬇️
6.1-m6g.metal 75.17% <21.21%> (-4.62%) ⬇️
6.1-m6i.metal 79.07% <30.69%> (-4.54%) ⬇️
6.1-m7a.metal-48xl 78.18% <30.69%> (-4.65%) ⬇️
6.1-m7g.metal 75.17% <21.21%> (-4.62%) ⬇️
6.1-m7i.metal-24xl 79.09% <30.69%> (-4.54%) ⬇️
6.1-m7i.metal-48xl 79.08% <30.69%> (-4.54%) ⬇️
6.1-m8g.metal-24xl 75.16% <21.21%> (-4.62%) ⬇️
6.1-m8g.metal-48xl 75.16% <21.21%> (-4.62%) ⬇️

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.

@bchalios bchalios force-pushed the pci_root_support branch 23 times, most recently from 4d735d9 to ee81ac6 Compare May 21, 2025 16:12
@bchalios bchalios force-pushed the pci_root_support branch 5 times, most recently from 4e781f5 to ec5c423 Compare May 29, 2025 13:28
@bchalios bchalios enabled auto-merge (rebase) May 29, 2025 14:02
@bchalios bchalios force-pushed the pci_root_support branch 4 times, most recently from f09c57d to ac67603 Compare May 29, 2025 16:07
bchalios and others added 15 commits May 29, 2025 18:08
Bring in pci crate from cloud hypervisor with a few modifications.
We use the rust-vmm vm-allocator crate instead of Cloud Hypervisor's
downstream one. For the time being, rust-vmm's implementation should
include all we need for supporting the devices we care about. If we need
more functionality from our allocators, we will implement the logic
directly in the rust-vmm vm-allocator crate.

Signed-off-by: Babis Chalios <[email protected]>
PCIe distinguishes MMIO regions between 32bit and 64bit, caring for
devices that can't deal with 64-bit addresses. This commit defines the
appropriate regions for both x86 and aarch64 architectures, extends the
resource allocator to handle allocations for both of these regions and
adjusts the logic that calculates the memory regions for the
architecture.

Also, un-do the change that added an `offset` argument
`arch_memory_regions` function. We won't be using this for "secret
hiding" so it just made the logic (especially for kani proofs) too
convoluted.

Signed-off-by: Babis Chalios <[email protected]>
PCIe devices need some times to relocate themselves in memory. To do so,
they need to keep an (atomic) reference to a type that implements
`DeviceRelocation` trait. The logic for relocation involves removing the
device from the bus it has been registered to, allocate a new address
range for it and reinsert it.

Instead of creating a new type for it, reuse `ResourceAllocator`. This
means that we need to move the buses from the `DeviceManager` inside
`ResourceAllocator`.

Signed-off-by: Babis Chalios <[email protected]>
Add a PCIe segment which includes a single PCIe root port and a bus.

At the moment, the PCIe segment is always enabled. Later commit will
make it optional and enable it only when a command line argument flag is
passed to Firecracker binary.

Signed-off-by: Babis Chalios <[email protected]>
So that we can declare which memory region is used by PCIe devices for
MMCONFIG.

Signed-off-by: Babis Chalios <[email protected]>
Write the PCI root bridge in FDT when PCI is enabled.

Signed-off-by: Babis Chalios <[email protected]>
Add a command line argument to enable PCIe support. By default, PCIe
is disabled. The reason for making PCIe off by default is that users
need to explicitly enable PCI support in their kernels. Requiring users
to explicitly enable it, does not break existing deployments, i.e. users
can upgrade Firecracker within their existing environments without
breaking any deployment.

Signed-off-by: Babis Chalios <[email protected]>
At the moment, the logic just restores the device manager and add the
PCIe root complex if PCI is enabled.

Signed-off-by: Babis Chalios <[email protected]>
Add an integration test that checks that `lspci` correctly locates the
PCIe root complex if PCI is enabled for the microVM. Also, add a
negative test that checks that PCIe root complex doesn't exist when PCI
is not enabled.

Also, extend coverage of, at least some of, the tests to ensure that
they run with and without PCI configuration enabled. Do that by
extending the `uvm_any*` fixtures to yield both variants.

Signed-off-by: Babis Chalios <[email protected]>
PCI-enabled guest kernels enable the `extd_apicid` CPU feature for AMD
CPU families after 16h. Our supported AMD families (Milan & Genoa) are
both 19h. This is irrespective of whether PCI is enabled in Firecracker.

Do not mark this as host-only when running with PCI enabled kernels,
i.e. all kernels that support ACPI.

Signed-off-by: Babis Chalios <[email protected]>
We have some Rust integration tests that check building and
booting of microVMs works correctly. Add variants for PCI-enabled
microVMs.

Signed-off-by: Babis Chalios <[email protected]>
Tests test_spectre_meltdown_checker_on_guest and
test_check_vulnerability_files_ab run A/B tests between the HEAD of the
target branch and the tip of a PR branch. This will currently fail,
because Firecracker builds from the HEAD of the target branch know
nothing about the `--enable-pci` command line flag, so launching
the Firecracker binary for revision A will fail.

Only run these tests for non-PCI uVMs for now. Once this commit gets
merged we will re-enable and make sure that everything works as
expected.

Signed-off-by: Babis Chalios <[email protected]>
1. build the kernel with PCI/e support.
2. fix a race condition between udev renaming the network devices and
   fcnet setting up the network interfaces
3. install pciutils on the image

Signed-off-by: Riccardo Mancini <[email protected]>
Signed-off-by: Babis Chalios <[email protected]>
I've rebuilt the CI artifacts for the new development version.

Signed-off-by: Riccardo Mancini <[email protected]>
Signed-off-by: Babis Chalios <[email protected]>
The memory monitor was only assuming a single MMIO gap on x86_64 when
calculating the memory regions that corresponded to guest memory. Now we
need to account for two MMIO gaps in x86 and one in ARM.

Signed-off-by: Babis Chalios <[email protected]>
@bchalios bchalios force-pushed the pci_root_support branch from ac67603 to 0f71857 Compare May 29, 2025 16:14
Copy link
Contributor

@Manciukic Manciukic left a comment

Choose a reason for hiding this comment

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

well done! Looking forward to the integration of virtio-pci!

@bchalios bchalios merged commit be5a600 into firecracker-microvm:feature/pcie May 29, 2025
4 of 7 checks passed
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants