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

Open
wants to merge 15 commits into
base: feature/pcie
Choose a base branch
from

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 32.96089% with 1560 lines in your changes missing coverage. Please review.

Project coverage is 79.14%. Comparing base (55a2026) to head (c8b4863).

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 78.88% 72 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 84.50% 11 Missing ⚠️
... and 7 more

❌ Your project check has failed because the head coverage (79.14%) 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.23%   79.14%   -4.10%     
================================================
  Files               253      262       +9     
  Lines             27171    29334    +2163     
================================================
+ Hits              22617    23216     +599     
- Misses             4554     6118    +1564     
Flag Coverage Δ
5.10-c5n.metal 78.95% <30.22%> (-4.60%) ⬇️
5.10-m5n.metal 78.94% <30.22%> (-4.61%) ⬇️
5.10-m6a.metal 78.06% <30.22%> (-4.71%) ⬇️
5.10-m6g.metal 74.45% <19.02%> (-5.31%) ⬇️
5.10-m6i.metal 78.94% <30.22%> (-4.61%) ⬇️
5.10-m7a.metal-48xl 78.04% <30.22%> (-4.72%) ⬇️
5.10-m7g.metal 74.45% <19.02%> (-5.31%) ⬇️
5.10-m7i.metal-24xl 78.91% <30.22%> (-4.60%) ⬇️
5.10-m7i.metal-48xl 78.91% <30.22%> (-4.60%) ⬇️
5.10-m8g.metal-24xl 74.44% <19.02%> (-5.31%) ⬇️
5.10-m8g.metal-48xl 74.44% <19.02%> (-5.31%) ⬇️
6.1-c5n.metal 78.99% <30.22%> (-4.61%) ⬇️
6.1-m5n.metal 78.98% <30.22%> (-4.62%) ⬇️
6.1-m6a.metal 78.10% <30.22%> (-4.73%) ⬇️
6.1-m6g.metal 74.44% <19.02%> (-5.32%) ⬇️
6.1-m6i.metal 78.98% <30.22%> (-4.61%) ⬇️
6.1-m7a.metal-48xl 78.09% <30.22%> (-4.72%) ⬇️
6.1-m7g.metal 74.45% <19.02%> (-5.31%) ⬇️
6.1-m7i.metal-24xl 78.99% <30.22%> (-4.61%) ⬇️
6.1-m7i.metal-48xl 79.00% <30.22%> (-4.61%) ⬇️
6.1-m8g.metal-24xl 74.44% <19.02%> (-5.31%) ⬇️
6.1-m8g.metal-48xl 74.44% <19.02%> (-5.32%) ⬇️

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 4 times, most recently from 6daba40 to ba6063f Compare May 22, 2025 08:31
bchalios and others added 14 commits May 22, 2025 10:33
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 <bchalios@amazon.es>
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 <bchalios@amazon.es>
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 <bchalios@amazon.es>
Add a PCIe segment which includes a single PCIe root port and a bus.
At the moment, we always enabled it.

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 <bchalios@amazon.es>
So that we can declare which memory region is used by PCIe devices for
MMCONFIG.

Signed-off-by: Babis Chalios <bchalios@amazon.es>
Write the PCI root bridge in FDT when PCI is enabled.

Signed-off-by: Babis Chalios <bchalios@amazon.es>
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 <bchalios@amazon.es>
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 <bchalios@amazon.es>
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 <bchalios@amazon.es>
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 <bchalios@amazon.es>
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 <bchalios@amazon.es>
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 <bchalios@amazon.es>
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 <mancio@amazon.com>
Signed-off-by: Babis Chalios <bchalios@amazon.es>
I've rebuilt the CI artifacts for the new development version.

Signed-off-by: Riccardo Mancini <mancio@amazon.com>
Signed-off-by: Babis Chalios <bchalios@amazon.es>
@bchalios bchalios force-pushed the pci_root_support branch from ba6063f to 1574ef7 Compare May 22, 2025 08:56
@bchalios bchalios added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label May 22, 2025
@bchalios bchalios marked this pull request as ready for review May 22, 2025 14:01
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 <bchalios@amazon.es>
@bchalios bchalios force-pushed the pci_root_support branch from 0b03ab7 to c8b4863 Compare May 22, 2025 14:28
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.

2 participants